forked from aergic-labs/artizo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.config.mjs
More file actions
158 lines (145 loc) · 4.54 KB
/
Copy pathesbuild.config.mjs
File metadata and controls
158 lines (145 loc) · 4.54 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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 flags = {
HAS_SECCOMP_UNCONFINED: target === "trae",
HAS_HOME_SYMLINK: target === "devin",
HAS_ARGV_PATCH: target !== "trae",
HAS_KIRO_ADAPTER: target === "kiro",
HAS_TRAE_ADAPTER: target === "trae",
HAS_DEVIN_ADAPTER: target === "devin",
HAS_VSCODIUM_ADAPTER: target === "vscodium",
};
/** @type {esbuild.BuildOptions} */
const buildOptions = {
entryPoints: ["src/extension.ts"],
bundle: true,
outfile: "dist/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"),
},
};
/**
* 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);
}
}
}
/**
* Copy @devcontainers/cli distribution files to the output directory.
*
* The CLI is built from the vendored source with:
* cd vendor/devcontainers-cli && npm install && npm run compile-prod
*
* Only the files needed by templates.ts (which spawns the CLI as a
* child process) are copied. The main API path (api.ts) imports vendored
* source directly; esbuild handles that bundling.
*/
function copyDevcontainersCli() {
const cliSource = path.resolve("vendor", "devcontainers-cli");
const cliEntry = path.join(
cliSource,
"dist",
"spec-node",
"devContainersSpecCLI.js",
);
if (!fs.existsSync(cliEntry)) {
console.error(
"Vendored CLI not built. Run: cd vendor/devcontainers-cli && npm install && npm run compile-prod",
);
process.exit(1);
}
const cliDest = path.resolve("dist", "node_modules", "@devcontainers", "cli");
// Clean previous build to avoid stale files
fs.rmSync(cliDest, { recursive: true, force: true });
fs.mkdirSync(path.join(cliDest, "dist", "spec-node"), { recursive: true });
// CLI entry point
fs.copyFileSync(
path.join(cliSource, "devcontainer.js"),
path.join(cliDest, "devcontainer.js"),
);
// Package metadata (for dependency resolution if spawned)
fs.copyFileSync(
path.join(cliSource, "package.json"),
path.join(cliDest, "package.json"),
);
// Compiled CLI (spawned by templates.ts)
fs.copyFileSync(
path.join(cliSource, "dist", "spec-node", "devContainersSpecCLI.js"),
path.join(cliDest, "dist", "spec-node", "devContainersSpecCLI.js"),
);
// Dockerfile used by the CLI for UID updates
const scriptsSource = path.join(cliSource, "scripts");
const scriptsDest = path.join(cliDest, "scripts");
fs.mkdirSync(scriptsDest, { recursive: true });
fs.copyFileSync(
path.join(scriptsSource, "updateUID.Dockerfile"),
path.join(scriptsDest, "updateUID.Dockerfile"),
);
}
async function main() {
if (isWatch) {
const ctx = await esbuild.context(buildOptions);
await ctx.watch();
copyDevcontainersCli();
console.log("Watching for changes...");
} else {
const result = await esbuild.build(buildOptions);
copyDevcontainersCli();
// Report bundle size
if (result.metafile) {
const output = result.metafile.outputs["dist/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);
});