Repository navigation
Expand file tree
/
Copy pathesbuild.js
More file actions
76 lines (68 loc) · 2.48 KB
/
Copy pathesbuild.js
File metadata and controls
76 lines (68 loc) · 2.48 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
// @ts-check
const esbuild = require('esbuild');
const fs = require('fs');
const minify = process.argv.indexOf('--production') !== -1;
const watch = process.argv.indexOf('--watch') !== -1;
(async () => {
/** @type esbuild.Plugin */
const plugin = {
name: 'patch up',
setup(build) {
// pac-proxy-agent reads quickjs.wasm from its package folder, which is not part of the bundle. Inline it instead.
build.onLoad({ filter: /node_modules[\/\\]pac-proxy-agent[\/\\]dist[\/\\]index\.js$/ }, async (args) => {
const text = await fs.promises.readFile(args.path, 'utf8');
const wasmRead = `readFile(new URL(import.meta.resolve('quickjs-wasi/quickjs.wasm')))`;
if (!text.includes(wasmRead)) {
throw new Error(`Could not patch quickjs.wasm loading in ${args.path}.`);
}
return {
contents: `import quickjsWasmBinary from 'quickjs-wasi/quickjs.wasm';\n${text.replace(wasmRead, 'Promise.resolve(quickjsWasmBinary)')}`,
loader: 'js',
};
});
},
};
/** @type {import('esbuild').BuildOptions} */
const options = {
bundle: true,
sourcemap: true,
minify,
platform: 'node',
target: 'node14.17.0',
mainFields: ['module', 'main'],
outdir: 'dist',
plugins: [plugin],
loader: {
'.wasm': 'binary',
},
// The bundle is CommonJS, map import.meta of bundled ES modules to the bundle file.
define: {
'import.meta.url': '__importMetaUrl',
'import.meta.resolve': '__importMetaResolve',
},
banner: {
js: `
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const __importMetaUrl = require('url').pathToFileURL(__filename).href;
const __importMetaResolve = (specifier) => require('url').pathToFileURL(require.resolve(specifier)).href;
`.trimStart()
},
entryPoints: [
'./src/spec-node/devContainersSpecCLI.ts',
],
tsconfig: 'tsconfig.json',
outbase: 'src',
};
if (watch) {
(await esbuild.context(options))
.watch();
} else {
await esbuild.build(options);
}
})().catch(() => process.exit(1));