-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathesbuild.js
More file actions
115 lines (103 loc) · 3.24 KB
/
esbuild.js
File metadata and controls
115 lines (103 loc) · 3.24 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
/**
* Build script for React Compiler Marker
*
* Usage:
* node esbuild.js - Build VS Code (dev mode)
* node esbuild.js --production - Build VS Code (production)
* BUILD_TARGET=nvim node esbuild.js --production - Build for Neovim
* BUILD_TARGET=zed node esbuild.js --production - Build for Zed
* node esbuild.js --watch - Watch mode for VS Code
*/
const esbuild = require("esbuild");
const path = require("path");
const production = process.argv.includes("--production");
const watch = process.argv.includes("--watch");
const buildTarget = process.env.BUILD_TARGET || "vscode";
// Resolve paths relative to this file's location (repo root)
const rootDir = __dirname;
/**
* @type {import('esbuild').Plugin}
*/
const esbuildProblemMatcherPlugin = {
name: "esbuild-problem-matcher",
setup(build) {
build.onStart(() => {
console.log("[watch] build started");
});
build.onEnd((result) => {
result.errors.forEach(({ text, location }) => {
console.error(`✘ [ERROR] ${text}`);
if (location) {
console.error(
` ${location.file}:${location.line}:${location.column}:`
);
}
});
console.log("[watch] build finished");
});
},
};
/**
* Shared build options
*/
const sharedOptions = {
bundle: true,
format: "cjs",
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: "node",
logLevel: "silent",
plugins: [esbuildProblemMatcherPlugin],
};
async function main() {
console.log(`Building for ${buildTarget}...`);
const contexts = [];
// Build CLI
if (buildTarget === "cli") {
const cliCtx = await esbuild.context({
...sharedOptions,
entryPoints: [path.join(rootDir, "packages/cli/src/main.ts")],
outfile: path.join(rootDir, "packages/cli/out/main.js"),
external: [],
alias: {
"@react-compiler-marker/server": path.join(rootDir, "packages/server"),
},
});
contexts.push(cliCtx);
}
// Build the LSP server (all targets except cli)
if (buildTarget !== "cli") {
const serverCtx = await esbuild.context({
...sharedOptions,
entryPoints: [path.join(rootDir, "packages/server/src/server.ts")],
outfile: buildTarget === "zed"
? path.join(rootDir, "packages/zed-client/server/server.bundle.js")
: buildTarget === "nvim"
? path.join(rootDir, "packages/nvim-client/server/server.bundle.js")
: path.join(rootDir, "packages/vscode-client/dist/server.js"),
external: [],
});
contexts.push(serverCtx);
}
// Build VS Code client extension only for vscode target
if (buildTarget === "vscode") {
const clientCtx = await esbuild.context({
...sharedOptions,
entryPoints: [path.join(rootDir, "packages/vscode-client/src/extension.ts")],
outfile: path.join(rootDir, "packages/vscode-client/dist/extension.js"),
external: ["vscode"],
});
contexts.push(clientCtx);
}
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()));
}
}
main().catch((e) => {
console.error(e);
process.exit(1);
});