// Bundles ../../daemon (and ../../shared) into dist/daemon so the extension can run // the daemon on VS Code's own Node runtime, with no separate install. import { build } from 'esbuild' import fs from 'node:fs' import { createRequire } from 'node:module' import path from 'node:path' // @vue/compiler-sfc lazily require()s ~40 optional template engines (pug, twig, …) that we never // use (we only call parse()). Leave anything unresolvable from inside it as a lazy external require. const optionalVueDeps = { name: 'optional-vue-deps', setup(b) { b.onResolve({ filter: /^[^./]/ }, args => { if (!args.importer.includes('@vue/compiler-sfc') && !args.importer.includes('consolidate')) return undefined try { createRequire(args.importer).resolve(args.path); return undefined } catch { return { path: args.path, external: true } } }) }, } const out = 'dist/daemon' fs.rmSync(out, { recursive: true, force: true }) const result = await build({ entryPoints: { acd: '../../daemon/src/main.ts', 'symbols-worker': '../../daemon/src/symbols-worker.ts' }, outdir: out, outExtension: { '.js': '.mjs' }, bundle: true, platform: 'node', format: 'esm', target: 'node18', minify: true, legalComments: 'external', logLevel: 'warning', metafile: true, plugins: [optionalVueDeps], // Bundled CJS deps (typescript) use require/__filename/__dirname; give the ESM output real ones. banner: { js: "import { createRequire as __cr } from 'node:module'; import { fileURLToPath as __fu } from 'node:url'; import { dirname as __dn } from 'node:path'; const require = __cr(import.meta.url); const __filename = __fu(import.meta.url); const __dirname = __dn(__filename);" }, }) fs.mkdirSync(`${out}/assets`, { recursive: true }) for (const f of ['qwen-tokenizer.json', 'qwen-tokenizer_config.json']) fs.copyFileSync(`../../daemon/assets/${f}`, `${out}/assets/${f}`) // TypeScript looks for its lib.*.d.ts next to the executing file (the bundled worker). const tsLib = path.dirname(createRequire(import.meta.url).resolve('../../shared/node_modules/typescript/lib/typescript.js')) for (const f of fs.readdirSync(tsLib)) if (/^lib\..*\.d\.ts$/.test(f)) fs.copyFileSync(path.join(tsLib, f), `${out}/${f}`) for (const [file, info] of Object.entries(result.metafile.outputs)) if (file.endsWith('.mjs')) console.log(file, (info.bytes / 1e6).toFixed(1) + ' MB')