Skip to content

Commit f125348

Browse files
authored
Merge pull request ejgallego#1033 from ejgallego/bump_esbuild2
[build] [code] [wasm] Bump esbuild deps, make extension build less verbose
2 parents e1c1ad7 + 1ccbad1 commit f125348

File tree

8 files changed

+3641
-3307
lines changed

8 files changed

+3641
-3307
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# unreleased
2+
------------------------------
3+
4+
- [build] [wasm] [code] bump esbuild from 0.16 to 0.25, miscellaneous
5+
npm dependencies bump (@ejgallego, #1033)
6+
17
# coq-lsp 0.2.4: (W)Activation
28
------------------------------
39

Makefile

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ocaml-lsp-server
2929

3030
.PHONY: build
3131
build: coq_boot
32-
dune build $(DUNEOPT) $(PKG_SET)
32+
@dune build $(DUNEOPT) $(PKG_SET)
3333

3434
.PHONY: check
3535
check: coq_boot
@@ -159,26 +159,33 @@ OUTDIR_NODE=editor/code/wasm-bin/node_modules
159159

160160
ifdef ESBUILD_DEBUG
161161
NPM_TARGET=esbuild
162+
NPM_OPTS=
162163
else
163164
NPM_TARGET=vscode:prepublish
165+
NPM_OPTS=--silent
164166
endif
165167

166168
.PHONY: wasm-bin
167169
wasm-bin:
168-
dune build $(WAFILES)
169-
mkdir -p $(OUTDIR)
170-
cp -af _build/default/lsp-server/wasm/wacoq_worker.bc $(OUTDIR)
171-
cp -af _build/default/lsp-server/wasm/*.wasm $(OUTDIR)
172-
cd lsp-server/wasm/ && npm i && npm run $(NPM_TARGET)
173-
cp -af lsp-server/wasm/out/wacoq_worker.js $(OUTDIR)
174-
mkdir -p $(OUTDIR_NODE)/ocaml-wasm/ && cp -af $(WASM_NODE)/ocaml-wasm/bin/ $(OUTDIR_NODE)/ocaml-wasm/
175-
mkdir -p $(OUTDIR_NODE)/@ocaml-wasm/4.12--num/ && cp -af $(WASM_NODE)/@ocaml-wasm/4.12--num/bin/ $(OUTDIR_NODE)/@ocaml-wasm/4.12--num/
176-
mkdir -p $(OUTDIR_NODE)/@ocaml-wasm/4.12--zarith/ && cp -af $(WASM_NODE)/@ocaml-wasm/4.12--zarith/bin/ $(OUTDIR_NODE)/@ocaml-wasm/4.12--zarith/
177-
mkdir -p $(OUTDIR_NODE)/@ocaml-wasm/4.12--janestreet-base/ && cp -af $(WASM_NODE)/@ocaml-wasm/4.12--janestreet-base/bin/ $(OUTDIR_NODE)/@ocaml-wasm/4.12--janestreet-base/
170+
@dune build $(WAFILES)
171+
@mkdir -p $(OUTDIR)
172+
@cp -af _build/default/lsp-server/wasm/wacoq_worker.bc $(OUTDIR)
173+
@cp -af _build/default/lsp-server/wasm/*.wasm $(OUTDIR)
174+
@cd lsp-server/wasm/ && npm i $(NPM_OPTS) && npm run $(NPM_OPTS) $(NPM_TARGET)
175+
@cp -af lsp-server/wasm/out/wacoq_worker.js $(OUTDIR)
176+
@mkdir -p $(OUTDIR_NODE)/ocaml-wasm/ && cp -af $(WASM_NODE)/ocaml-wasm/bin/ $(OUTDIR_NODE)/ocaml-wasm/
177+
@mkdir -p $(OUTDIR_NODE)/@ocaml-wasm/4.12--num/ && cp -af $(WASM_NODE)/@ocaml-wasm/4.12--num/bin/ $(OUTDIR_NODE)/@ocaml-wasm/4.12--num/
178+
@mkdir -p $(OUTDIR_NODE)/@ocaml-wasm/4.12--zarith/ && cp -af $(WASM_NODE)/@ocaml-wasm/4.12--zarith/bin/ $(OUTDIR_NODE)/@ocaml-wasm/4.12--zarith/
179+
@mkdir -p $(OUTDIR_NODE)/@ocaml-wasm/4.12--janestreet-base/ && cp -af $(WASM_NODE)/@ocaml-wasm/4.12--janestreet-base/bin/ $(OUTDIR_NODE)/@ocaml-wasm/4.12--janestreet-base/
178180

179181
.PHONY: extension
180182
extension: wasm-bin
181-
cd editor/code && npm i && npm run $(NPM_TARGET)
183+
@cd editor/code && npm i $(NPM_OPTS) && npm run $(NPM_OPTS) $(NPM_TARGET)
184+
185+
# Without the wasm
186+
.PHONY: extension-code
187+
extension-code:
188+
@cd editor/code && npm i $(NPM_OPTS) && npm run $(NPM_OPTS) $(NPM_TARGET)
182189

183190
# Run prettier
184191
.PHONY: ts-fmt

editor/code/esbuild.mjs

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,58 @@
22
import process from "process";
33
import * as esbuild from "esbuild";
44

5-
let watchConfig = (entry) => {
6-
return {
7-
onRebuild(error, result) {
8-
console.log(`[watch] build started (rebuild for ${entry})`);
9-
if (error) {
10-
error.errors.forEach((error) =>
11-
console.error(
12-
`> ${error.location.file}:${error.location.line}:${error.location.column}: error: ${error.text}`
13-
)
14-
);
15-
} else console.log(`[watch] build finished (rebuild for ${entry}`);
16-
},
17-
};
18-
};
19-
20-
let watch = process.argv.includes("--watch") ? watchConfig : (entry) => false;
215
let minify = process.argv.includes("--minify");
226
let disable_sourcemap = process.argv.includes("--sourcemap=no");
237
let sourcemap_client = disable_sourcemap ? null : { sourcemap: true };
248
let sourcemap_view = disable_sourcemap ? null : { sourcemap: "inline" };
259

10+
let enableMeta = false;
11+
12+
const plugins = [
13+
{
14+
name: "esbuild-problem-matcher",
15+
setup(build) {
16+
let file = build.initialOptions.entryPoints[0];
17+
18+
build.onStart(() => {
19+
console.log(`[watch] build started for ${file}`);
20+
});
21+
22+
build.onEnd((result) => {
23+
if (result.errors.length > 0) {
24+
result.errors.forEach((e) =>
25+
console.error(
26+
`> ${e.location.file}:${e.location.line}:${e.location.column}: error: ${e.text}`
27+
)
28+
);
29+
} else {
30+
console.log(`[watch] build finished for ${file}`);
31+
if (enableMeta) {
32+
fs.writeFileSync(
33+
`${file}.json`,
34+
JSON.stringify(result.metafile, null, 2)
35+
);
36+
}
37+
}
38+
});
39+
},
40+
},
41+
];
42+
43+
const watchContext = async (ctxp) => {
44+
let ctx = await ctxp;
45+
46+
if (process.argv.includes("--watch")) {
47+
await ctx.watch();
48+
} else {
49+
await ctx.rebuild();
50+
await ctx.dispose();
51+
}
52+
};
53+
2654
// Build of the VS Code extension, for electron (hence cjs + node)
27-
var node = esbuild
28-
.build({
55+
var node = watchContext(
56+
esbuild.context({
2957
entryPoints: ["./src/node.ts"],
3058
bundle: true,
3159
...sourcemap_client,
@@ -34,15 +62,12 @@ var node = esbuild
3462
external: ["vscode"],
3563
outfile: "out/src/node.js",
3664
minify,
37-
watch: watch("./src/node.ts"),
65+
plugins,
3866
})
39-
.then(() => {
40-
console.log("[watch] build finished for ./src/node.ts");
41-
})
42-
.catch(() => process.exit(1));
67+
);
4368

44-
var browser = esbuild
45-
.build({
69+
var browser = watchContext(
70+
esbuild.context({
4671
entryPoints: ["./src/browser.ts"],
4772
bundle: true,
4873
...sourcemap_client,
@@ -51,30 +76,24 @@ var browser = esbuild
5176
external: ["vscode"],
5277
outfile: "out/src/browser.js",
5378
minify,
54-
watch: watch("./src/browser.ts"),
55-
})
56-
.then(() => {
57-
console.log("[watch] build finished for ./src/browser.ts");
79+
plugins,
5880
})
59-
.catch(() => process.exit(1));
81+
);
6082

6183
// Build of the VS Code view, for modern Chrome (webview)
6284
function viewBuild(file) {
63-
return esbuild
64-
.build({
85+
return watchContext(
86+
esbuild.context({
6587
entryPoints: [file],
6688
bundle: true,
6789
...sourcemap_view,
6890
platform: "browser",
6991
outdir: "out",
7092
outbase: ".",
7193
minify,
72-
watch: watch(file),
73-
})
74-
.then(() => {
75-
console.log(`[watch] build finished for ${file}`);
94+
plugins,
7695
})
77-
.catch(() => process.exit(1));
96+
);
7897
}
7998

8099
var infoView = viewBuild("./views/info/index.tsx");

0 commit comments

Comments
 (0)