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 ctx = await esbuild.context({ ...common, entryPoints: ['src/extension.ts'], outfile: 'dist/extension.js', external: ['vscode'], }); if (watch) { await ctx.watch(); } else { await ctx.rebuild(); await ctx.dispose(); } }