import * as esbuild from 'esbuild'; import fs from 'node:fs'; import path from 'node:path'; const production = process.argv.includes('--production'); const watch = process.argv.includes('--watch'); const tests = process.argv.includes('--tests'); const common = { bundle: true, format: 'cjs', platform: 'node', target: 'node20', sourcemap: !production, minify: production, logLevel: 'info', // jsonc-parser's UMD entry uses dynamic requires esbuild cannot follow. mainFields: ['module', 'main'], }; if (tests) { // Unit tests cover the modules that do not import 'vscode'; the // integration suite runs inside VS Code, which provides it. const entryPoints = fs.readdirSync('test') .filter((file) => file.endsWith('.test.ts')) .map((file) => path.join('test', file)); await esbuild.build({ ...common, entryPoints, outdir: 'out/test', sourcemap: true }); await esbuild.build({ ...common, entryPoints: ['test/integration/suite.ts'], outfile: 'out/test/integration/suite.js', external: ['vscode'], sourcemap: true, }); } else { const contexts = await Promise.all([ esbuild.context({ ...common, entryPoints: ['src/extension.ts'], outfile: 'dist/extension.js', external: ['vscode'], }), // Runs inside the Archify page in the webview; three.js is bundled in. esbuild.context({ ...common, format: 'iife', platform: 'browser', target: 'es2022', entryPoints: ['src/viewer3d/index.ts'], outfile: 'dist/viewer3d.js', }), ]); if (watch) { await Promise.all(contexts.map((ctx) => ctx.watch())); } else { await Promise.all(contexts.map((ctx) => ctx.rebuild())); await Promise.all(contexts.map((ctx) => ctx.dispose())); } }