Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Bundle the extension using esbuild #421

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workspaceRoot is now deprecated

"stopOnEntry": false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stopOnEntry is reported invalid entry in my vscode, thus removing it.

"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
"preLaunchTask": "npm"
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "npm: compile"
},
{
"name": "Launch Debug Server",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/src/debug-adapter/client.ts",
"program": "${workspaceFolder}/dist/debug-adapter-client.js",
"args": ["--server=4711"],
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/src/**/*.js"]
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
},
{
"name": "Launch Extension Tests",
"type": "extensionHost",
"request": "launch",
"testConfiguration": "${workspaceFolder}/.vscode-test.js",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"]
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"sourceMaps": true,
"outFiles": ["${workspaceFolder}/out/**/*.js"]
}
],
"compounds": [
Expand Down
10 changes: 10 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ignore all files by default.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found some examples and practices using .vscodeignore for white listing: so that we can invoke the vsce without changing the working directory or copying the included resources, and the layout for the resources should be the same no matter we minified or not.

**/*

!README.md
!LICENSE
!package.json
!dist/**/*.js
!icons/**/*.+(svg|license)
!media/**/*
!syntaxes/**/*.+(json|yaml|license)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yaml file shouldn't be included in the extension, only the form that's been compiled to json.

Suggested change
!syntaxes/**/*.+(json|yaml|license)
!syntaxes/**/*.+(json|license)

Do note that it was previously excluded.

56 changes: 56 additions & 0 deletions esbuild-debug-adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const esbuild = require("esbuild");

const production = process.argv.includes("--production");
const watch = process.argv.includes("--watch");

/**
* @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}`);
console.error(
` ${location.file}:${location.line}:${location.column}:`,
);
});
console.log("[watch] build finished");
});
},
};

async function main() {
const ctx = await esbuild.context({
entryPoints: ["src/debug-adapter/client.ts"],
bundle: true,
format: "cjs",
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: "node",
outfile: "dist/debug-adapter-client.js",
external: ["vscode"],
logLevel: "silent",
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
});
if (watch) {
await ctx.watch();
} else {
await ctx.rebuild();
await ctx.dispose();
}
}

main().catch((e) => {
console.error(e);
process.exit(1);
});
6 changes: 4 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ module.exports = tseslint.config(
eslintConfigPrettier,
{
ignores: [
"esbuild.js",
"out/",
".vscode-test/**",
"esbuild*.js",
"dist/**",
"out/**",
"src/protos/protos.js",
"src/protos/protos.d.ts",
],
Expand Down
Loading