Skip to content

Commit

Permalink
vscode: Ensure extension.js is rebuilt when deleted
Browse files Browse the repository at this point in the history
Right now, the vscode-extension:continue-ui:build task
deletes extension.js as part of its prepackage.js script.

This wouldn't normally be a problem, because extension.js
is generated by the vscode-extension:esbuild, and
vscode-extension:continue-ui:build is a dependency of
vscode-extension:esbuild, implying it should always get run
first.

But, vscode-extension:esbuild is a background task, that stays
running after it's been started once. Future calls to run that
task become no-ops, because it's already active. This means running

vscode-extension:esbuild ->
  vscode-extension:continue-ui:build ->
    vscode-extension:esbuild

will lead to the last vscode-extension:esbuild not regenerating
extension.js.

In order to resolve that problem, this commit adds a new foreground
task into the build pipeline:

  vscode-extension:esbuild-notify

that tickles the watching background task to wake up and regenerate
extension.js
  • Loading branch information
halfline committed Dec 10, 2024
1 parent f08e501 commit 9660c7e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
"vscode-extension:continue-ui:build",
// // To bundle the code the same way we do for publishing
"vscode-extension:esbuild",
// To ensure extension.js is regenerated even if
// vscode-extension:esbuild was already running in background
"vscode-extension:esbuild-notify",
// Start the React app that is used in the extension
"gui:dev"
],
Expand All @@ -36,6 +39,13 @@
"isDefault": true
}
},
{
"label": "vscode-extension:esbuild-notify",
"dependsOn": ["vscode-extension:esbuild"],
"type": "npm",
"script": "esbuild-notify",
"path": "extensions/vscode"
},
{
"label": "vscode-extension:esbuild",
"dependsOn": ["vscode-extension:continue-ui:build"],
Expand Down
1 change: 1 addition & 0 deletions extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@
"vscode:prepublish": "npm run esbuild-base -- --minify",
"esbuild": "npm run esbuild-base -- --sourcemap",
"esbuild-watch": "npm run esbuild-base -- --sourcemap --watch",
"esbuild-notify": "npm run esbuild-base -- --sourcemap --notify",
"esbuild:visualize": "esbuild-visualizer --metadata ./build/meta.json --filename ./build/stats.html --open",
"tsc": "tsc -p ./",
"tsc:check": "tsc -p ./ --noEmit",
Expand Down
24 changes: 23 additions & 1 deletion extensions/vscode/scripts/esbuild.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const esbuild = require("esbuild");
const fs = require("fs");

const flags = process.argv.slice(2);

Expand Down Expand Up @@ -31,7 +32,6 @@ const esbuildConfig = {
throw new Error(result.errors);
} else {
try {
const fs = require("fs");
fs.writeFileSync(
"./build/meta.json",
JSON.stringify(result.metafile, null, 2),
Expand All @@ -52,6 +52,28 @@ const esbuildConfig = {
if (flags.includes("--watch")) {
const ctx = await esbuild.context(esbuildConfig);
await ctx.watch();
} else if (flags.includes("--notify")) {
const inFile = esbuildConfig.entryPoints[0];
const outFile = esbuildConfig.outfile;

// The watcher automatically notices changes to source files
// so the only thing it needs to be notified about is if the
// output file gets removed.
if (fs.existsSync (outFile)) {
console.log("VS Code Extension esbuild up to date");
return;
}

fs.watchFile(outFile, (current, previous) => {
if (current.size > 0) {
console.log("VS Code Extension esbuild rebuild complete");
fs.unwatchFile(outFile);
process.exit(0);
}
});

console.log("Triggering VS Code Extension esbuild rebuild...");
fs.utimesSync(inFile, new Date(), new Date());
} else {
await esbuild.build(esbuildConfig);
}
Expand Down

0 comments on commit 9660c7e

Please sign in to comment.