-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.mjs
More file actions
264 lines (251 loc) · 7.91 KB
/
Copy pathesbuild.mjs
File metadata and controls
264 lines (251 loc) · 7.91 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import esbuild from 'esbuild';
import fs from 'node:fs';
import path from 'node:path';
import { createRequire } from 'node:module';
const watch = process.argv.includes('--watch');
const smoke = process.argv.includes('--smoke');
const smokePinels = process.argv.includes('--smoke-pinels');
const smokePyright = process.argv.includes('--smoke-pyright');
const smokeChecker = process.argv.includes('--smoke-checker');
const smokeEdgeCorpus = process.argv.includes('--smoke-edge-corpus');
const smokeBridgeViz = process.argv.includes('--smoke-bridge-viz');
const smokeChartBreakpoints = process.argv.includes('--smoke-chart-breakpoints');
const smokeLibraryImports = process.argv.includes('--smoke-library-imports');
const smokeBridgeSecurity = process.argv.includes('--smoke-bridge-security');
const smokeSymbolMap = process.argv.includes('--smoke-symbol-map');
const smokeReport = process.argv.includes('--smoke-report');
const smokePlugins = process.argv.includes('--smoke-plugins');
const common = {
bundle: true,
format: 'cjs',
platform: 'node',
target: 'node20',
sourcemap: true,
};
/**
* Ship the pyright language server inside the VSIX: node_modules is
* .vscodeignore'd, so the needed runtime files are copied under dist/pyright
* (the CLI bundle and source maps are left out). Skipped when dist already
* holds the same pyright version.
*/
function copyPyright() {
const require = createRequire(import.meta.url);
const srcRoot = path.dirname(require.resolve('pyright/package.json'));
const outRoot = path.resolve('dist/pyright');
const version = JSON.parse(fs.readFileSync(path.join(srcRoot, 'package.json'), 'utf8')).version;
try {
const existing = JSON.parse(fs.readFileSync(path.join(outRoot, 'package.json'), 'utf8'));
if (existing.version === version) return;
} catch {
// Missing or unreadable — copy below.
}
fs.rmSync(outRoot, { recursive: true, force: true });
for (const entry of ['package.json', 'LICENSE.txt', 'langserver.index.js']) {
fs.cpSync(path.join(srcRoot, entry), path.join(outRoot, entry));
}
fs.cpSync(path.join(srcRoot, 'dist'), path.join(outRoot, 'dist'), {
recursive: true,
filter: (src) => !src.endsWith('.map') && !src.endsWith(`${path.sep}pyright.js`),
});
console.log(`esbuild: bundled pyright ${version} into dist/pyright`);
}
const watchMarkerPlugin = {
name: 'watch-marker',
setup(build) {
build.onStart(() => console.log('[watch] build started'));
build.onEnd((result) => {
for (const { text, location } of result.errors) {
console.error(`[ERROR] ${text}`);
if (location) console.error(` ${location.file}:${location.line}:${location.column}:`);
}
console.log('[watch] build finished');
});
},
};
if (smoke) {
await esbuild.build({
...common,
entryPoints: ['test/smoke/envSmoke.ts'],
outfile: 'dist/env-smoke.js',
minify: false,
});
} else if (smokePinels) {
await esbuild.build({
...common,
entryPoints: ['test/smoke/pineLsSmoke.ts'],
outfile: 'dist/pinels-smoke.js',
minify: false,
});
} else if (smokePyright) {
copyPyright();
await esbuild.build({
...common,
entryPoints: ['test/smoke/pyrightSmoke.ts'],
outfile: 'dist/pyright-smoke.js',
minify: false,
});
} else if (smokeChecker) {
await esbuild.build({
...common,
entryPoints: ['test/smoke/checkerSmoke.ts'],
outfile: 'dist/checker-smoke.js',
minify: false,
});
} else if (smokeEdgeCorpus) {
await esbuild.build({
...common,
entryPoints: ['test/smoke/edgeCorpusSmoke.ts'],
outfile: 'dist/edge-corpus-smoke.js',
minify: false,
});
} else if (smokeBridgeViz) {
await esbuild.build({
...common,
entryPoints: ['test/smoke/bridgeVizSmoke.ts'],
outfile: 'dist/bridge-viz-smoke.js',
minify: false,
});
} else if (smokeChartBreakpoints) {
await esbuild.build({
...common,
entryPoints: ['test/smoke/chartBreakpointConditionSmoke.ts'],
outfile: 'dist/chart-breakpoint-condition-smoke.js',
minify: false,
});
} else if (smokeLibraryImports) {
await esbuild.build({
...common,
entryPoints: ['test/smoke/libraryImportsSmoke.ts'],
outfile: 'dist/library-imports-smoke.js',
minify: false,
});
} else if (smokeBridgeSecurity) {
await esbuild.build({
...common,
entryPoints: ['test/smoke/securitySmoke.ts'],
outfile: 'dist/bridge-security-smoke.js',
minify: false,
});
} else if (smokeReport) {
await esbuild.build({
...common,
entryPoints: ['test/smoke/reportSmoke.ts'],
outfile: 'dist/report-smoke.js',
minify: false,
});
} else if (smokeSymbolMap) {
await esbuild.build({
...common,
entryPoints: ['test/smoke/symbolMapSmoke.ts'],
outfile: 'dist/symbol-map-smoke.js',
minify: false,
});
} else if (smokePlugins) {
await esbuild.build({
...common,
entryPoints: ['test/smoke/pluginsSmoke.ts'],
outfile: 'dist/plugins-smoke.js',
minify: false,
});
} else {
copyPyright();
const ctx = await esbuild.context({
...common,
entryPoints: ['src/extension.ts'],
outfile: 'dist/extension.js',
external: ['vscode'],
minify: !watch,
plugins: watch ? [watchMarkerPlugin] : [],
});
// Chart webview bundle: browser code (klinecharts inlined), no vscode API.
const webviewCtx = await esbuild.context({
...common,
entryPoints: ['src/chart/webview/main.ts'],
outfile: 'dist/chart-webview.js',
format: 'iife',
platform: 'browser',
target: 'es2020',
minify: !watch,
plugins: watch ? [watchMarkerPlugin] : [],
});
// OHLCV table webview bundle: browser code, no vscode API.
const tableCtx = await esbuild.context({
...common,
entryPoints: ['src/data/webview/table.ts'],
outfile: 'dist/ohlcv-table.js',
format: 'iife',
platform: 'browser',
target: 'es2020',
minify: !watch,
plugins: watch ? [watchMarkerPlugin] : [],
});
// Input-form webview bundle: browser code, no vscode API.
const inputsCtx = await esbuild.context({
...common,
entryPoints: ['src/workspace/webview/inputsForm.ts'],
outfile: 'dist/inputs-form.js',
format: 'iife',
platform: 'browser',
target: 'es2020',
minify: !watch,
plugins: watch ? [watchMarkerPlugin] : [],
});
// Symbol-browser webview bundle: browser code, no vscode API.
const symbolBrowserCtx = await esbuild.context({
...common,
entryPoints: ['src/data/webview/symbolBrowser.ts'],
outfile: 'dist/symbol-browser.js',
format: 'iife',
platform: 'browser',
target: 'es2020',
minify: !watch,
plugins: watch ? [watchMarkerPlugin] : [],
});
// Symbol-map webview bundle: browser code, no vscode API.
const symbolMapCtx = await esbuild.context({
...common,
entryPoints: ['src/data/webview/symbolMap.ts'],
outfile: 'dist/symbol-map.js',
format: 'iife',
platform: 'browser',
target: 'es2020',
minify: !watch,
plugins: watch ? [watchMarkerPlugin] : [],
});
// Plugins webview bundle: browser code, no vscode API.
const pluginsCtx = await esbuild.context({
...common,
entryPoints: ['src/plugins/webview/plugins.ts'],
outfile: 'dist/plugins.js',
format: 'iife',
platform: 'browser',
target: 'es2020',
minify: !watch,
plugins: watch ? [watchMarkerPlugin] : [],
});
if (watch) {
await ctx.watch();
await webviewCtx.watch();
await tableCtx.watch();
await inputsCtx.watch();
await symbolBrowserCtx.watch();
await symbolMapCtx.watch();
await pluginsCtx.watch();
console.log('esbuild: watching...');
} else {
await ctx.rebuild();
await webviewCtx.rebuild();
await tableCtx.rebuild();
await inputsCtx.rebuild();
await symbolBrowserCtx.rebuild();
await symbolMapCtx.rebuild();
await pluginsCtx.rebuild();
await ctx.dispose();
await webviewCtx.dispose();
await tableCtx.dispose();
await inputsCtx.dispose();
await symbolBrowserCtx.dispose();
await symbolMapCtx.dispose();
await pluginsCtx.dispose();
}
}