-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
132 lines (122 loc) · 3.64 KB
/
Copy pathesbuild.config.mjs
File metadata and controls
132 lines (122 loc) · 3.64 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
import * as esbuild from "esbuild";
import * as fs from "node:fs";
import * as path from "node:path";
const isWatch = process.argv.includes("--watch");
const target = process.env.TARGET || "kiro";
// Per-vendor feature flags; vendor names never ship in VSIX
const isTraeFamily = target === "trae";
const flags = {
HAS_SECCOMP_UNCONFINED: isTraeFamily,
HAS_HOME_SYMLINK: target === "devin",
HAS_ARGV_PATCH: !isTraeFamily,
HAS_KIRO_ADAPTER: target === "kiro",
HAS_TRAE_ADAPTER: isTraeFamily,
HAS_DEVIN_ADAPTER: target === "devin",
HAS_VSCODIUM_ADAPTER: target === "vscodium",
};
/** @type {esbuild.BuildOptions} */
const buildOptions = {
entryPoints: ["src/extension.ts"],
bundle: true,
outfile: "dist/extension/extension.js",
external: ["vscode"],
format: "cjs",
platform: "node",
target: "node18",
sourcemap: true,
minify: false,
minifySyntax: true,
treeShaking: true,
metafile: true,
mainFields: ["module", "main"],
banner: {
js: `/*
* Copyright (c) 2026 Aergic Labs, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/`,
},
define: {
__TARGET__: JSON.stringify(target),
...Object.fromEntries(
Object.entries(flags).map(([k, v]) => [k, JSON.stringify(v)]),
),
},
// Resolve vscode-uri from local node_modules (not vendored CLI's)
alias: {
"vscode-uri": path.resolve("node_modules/vscode-uri"),
"node-pty": path.resolve("stubs/node-pty.js"),
},
};
/**
* Build options for the standalone remote argv.json patch script. Bundled
* to a single self-contained CJS file (jsonc-parser inlined) that the apex
* pushes over ssh stdin to `node -` on the SSH remote. Minified + no legal
* comments to keep the pushed payload small (~17KB).
*/
/** @type {esbuild.BuildOptions} */
const remotePatchOptions = {
entryPoints: ["src/remote/argvPatchRemoteMain.ts"],
bundle: true,
outfile: "dist/argv-patch-remote.cjs",
format: "cjs",
platform: "node",
target: "node18",
minify: true,
legalComments: "none",
treeShaking: true,
// Prefer jsonc-parser's ESM build; the UMD build uses dynamic relative
// requires that esbuild can't statically bundle.
mainFields: ["module", "main"],
banner: {
js: `/*
* Copyright (c) 2026 Aergic Labs, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/`,
},
};
/**
* Recursively copy a directory from src to dest.
*/
function copyDirSync(src, dest) {
fs.mkdirSync(dest, { recursive: true });
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
copyDirSync(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}
async function main() {
if (isWatch) {
const ctx = await esbuild.context(buildOptions);
const remoteCtx = await esbuild.context(remotePatchOptions);
await ctx.watch();
await remoteCtx.watch();
console.log("Watching for changes...");
} else {
const result = await esbuild.build(buildOptions);
await esbuild.build(remotePatchOptions);
// Report bundle size
if (result.metafile) {
const output = result.metafile.outputs["dist/extension/extension.js"];
if (output) {
const sizeKB = (output.bytes / 1024).toFixed(1);
console.log(`Bundle size: ${sizeKB} KB`);
console.log(`Inputs: ${Object.keys(output.inputs).length} modules`);
}
// Write metafile for analysis (gitignored)
fs.writeFileSync(
"dist/meta.json",
JSON.stringify(result.metafile, null, 2),
);
}
console.log("Build complete.");
}
}
main().catch((err) => {
console.error(err);
process.exit(1);
});