forked from anrgct/autodev-codebase
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.cjs
More file actions
193 lines (176 loc) · 6.49 KB
/
rollup.config.cjs
File metadata and controls
193 lines (176 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
const resolve = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const typescript = require('@rollup/plugin-typescript');
const json = require('@rollup/plugin-json');
const fs = require('fs')
const path = require('path')
function copyFilesPlugin() {
return {
name: 'copy-files-plugin',
buildStart() {
const srcDir = __dirname
const nodeModulesDir = path.join(srcDir, "node_modules")
const distDir = path.join(srcDir, "src/tree-sitter")
console.log(`[copyWasms] Copying WASM files to ${distDir}`)
// Copy language-specific WASM files.
const languageWasmDir = path.join(nodeModulesDir, "tree-sitter-wasms", "out")
if (!fs.existsSync(languageWasmDir)) {
throw new Error(`Directory does not exist: ${languageWasmDir}`)
}
// Dynamically read all WASM files from the directory
const wasmFiles = fs.readdirSync(languageWasmDir).filter((file) => file.endsWith(".wasm"))
wasmFiles.forEach((filename) => {
const srcPath = path.join(languageWasmDir, filename)
const destPath = path.join(distDir, filename)
fs.copyFileSync(srcPath, destPath)
})
console.log(`[copyWasms] Successfully copied ${wasmFiles.length} tree-sitter language WASMs to ${distDir}`)
},
generateBundle() {
// Copy yoga.wasm from Ink dependencies to dist
const srcDir = __dirname
const nodeModulesDir = path.join(srcDir, "node_modules")
const distDir = path.join(srcDir, "dist")
// Ensure dist directory exists
if (!fs.existsSync(distDir)) {
fs.mkdirSync(distDir, { recursive: true })
}
// Find yoga.wasm in Ink's dependencies
const yogaWasmPath = path.join(nodeModulesDir, "yoga-wasm-web", "dist", "yoga.wasm")
if (fs.existsSync(yogaWasmPath)) {
const destPath = path.join(distDir, "yoga.wasm")
fs.copyFileSync(yogaWasmPath, destPath)
console.log(`[copyWasms] Copied yoga.wasm to ${destPath}`)
} else {
console.warn(`[copyWasms] yoga.wasm not found at ${yogaWasmPath}`)
}
// Copy tree-sitter WASM files from src/tree-sitter to dist
const treeSitterSrcDir = path.join(srcDir, "src", "tree-sitter")
const treeSitterDistDir = path.join(distDir, "tree-sitter")
if (fs.existsSync(treeSitterSrcDir)) {
// Ensure tree-sitter directory exists in dist
if (!fs.existsSync(treeSitterDistDir)) {
fs.mkdirSync(treeSitterDistDir, { recursive: true })
}
// Copy all WASM files
const wasmFiles = fs.readdirSync(treeSitterSrcDir).filter(file => file.endsWith('.wasm'))
wasmFiles.forEach(filename => {
const srcPath = path.join(treeSitterSrcDir, filename)
const destPath = path.join(treeSitterDistDir, filename)
fs.copyFileSync(srcPath, destPath)
})
console.log(`[copyWasms] Copied ${wasmFiles.length} tree-sitter WASM files to ${treeSitterDistDir}`)
} else {
console.warn(`[copyWasms] tree-sitter source directory not found at ${treeSitterSrcDir}`)
}
// Copy core tree-sitter.wasm file from node_modules to dist root
const coreWasmSrc = path.join(nodeModulesDir, "web-tree-sitter", "tree-sitter.wasm")
if (fs.existsSync(coreWasmSrc)) {
const coreWasmDest = path.join(distDir, "tree-sitter.wasm")
fs.copyFileSync(coreWasmSrc, coreWasmDest)
console.log(`[copyWasms] Copied core tree-sitter.wasm to ${coreWasmDest}`)
} else {
console.warn(`[copyWasms] Core tree-sitter.wasm not found at ${coreWasmSrc}`)
}
}
};
}
module.exports = [
// Main library build
{
input: 'src/index.ts',
output: {
file: 'dist/index.js',
format: 'esm',
sourcemap: true,
inlineDynamicImports: true,
},
external: (id) => {
// Externalize vscode and its submodules
if (id === 'vscode' || id.startsWith('vscode/')) {
return true;
}
// Externalize React and related dependencies to prevent devtools issues
if (id === 'react' || id.startsWith('react/') || id === 'react-devtools-core' || id.includes('react-devtools-core')) {
return true;
}
// Externalize Ink to prevent devtools bundling issues
if (id === 'ink' || id.startsWith('ink/')) {
return true;
}
// Also externalize yoga-wasm-web to avoid bundling issues
if (id.includes('yoga-wasm-web')) {
return true;
}
// Externalize Node.js built-ins that shouldn't be bundled
if (['fs', 'path', 'child_process', 'readline', 'crypto', 'os', 'stream', 'util'].includes(id)) {
return true;
}
// Bundle everything else (including fzf, tslib, etc.)
return false;
},
plugins: [
copyFilesPlugin(),
json(),
resolve({
preferBuiltins: true,
ignoreMissing: ['react-devtools-core'],
}),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
rootDir: './src',
noEmitOnError: false,
}),
],
},
// CLI build
{
input: 'src/cli.ts',
output: {
file: 'dist/cli.js',
format: 'esm',
sourcemap: true,
inlineDynamicImports: true,
banner: '#!/usr/bin/env node',
},
external: (id) => {
// Externalize vscode and its submodules
if (id === 'vscode' || id.startsWith('vscode/')) {
return true;
}
// Externalize React and related dependencies to prevent devtools issues
if (id === 'react' || id.startsWith('react/') || id === 'react-devtools-core' || id.includes('react-devtools-core')) {
return true;
}
// Externalize Ink to prevent devtools bundling issues
if (id === 'ink' || id.startsWith('ink/')) {
return true;
}
// Also externalize yoga-wasm-web to avoid bundling issues
if (id.includes('yoga-wasm-web')) {
return true;
}
// Externalize Node.js built-ins that shouldn't be bundled
if (['fs', 'path', 'child_process', 'readline', 'crypto', 'os', 'stream', 'util'].includes(id)) {
return true;
}
// Bundle everything else (including fzf, tslib, etc.)
return false;
},
plugins: [
copyFilesPlugin(),
json(),
resolve({
preferBuiltins: true,
ignoreMissing: ['react-devtools-core'],
}),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
rootDir: './src',
noEmitOnError: false,
}),
],
},
];