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

fix npm: watch problem matcher stalling default debug task #112

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": ["dbaeumer.vscode-eslint", "amodio.tsl-problem-matcher"]
"recommendations": [
"dbaeumer.vscode-eslint",
"amodio.tsl-problem-matcher",
"connor4312.esbuild-problem-matchers"
]
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"type": "npm",
"script": "watch",
"problemMatcher": "$ts-webpack-watch",
"problemMatcher": "$esbuild-watch",
"isBackground": true,
"presentation": {
"reveal": "never",
Expand Down
72 changes: 54 additions & 18 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
(async () => {
const production = process.argv.includes("--production");
const watch = process.argv.includes('--watch');

/**
* @see https://code.visualstudio.com/api/working-with-extensions/bundling-extension#using-esbuild
*/
async function main() {
const ctx = await require("esbuild").context({
entryPoints: {
extension: "./src/extension.ts",
Expand All @@ -9,30 +15,60 @@
format: "cjs",
inject: ["./scripts/process-shim.js"],
tsconfig: "./tsconfig.json",
define: process.argv.includes("--production")
define: production
? { "process.env.NODE_ENV": '"production"' }
: undefined,
minify: process.argv.includes("--production"),
sourcemap: !process.argv.includes("--production"),
minify: production,
sourcemap: !production,
plugins: [
{
name: "node-deps",
setup(build) {
build.onResolve({ filter: /^path$/ }, (args) => {
const path = require.resolve("../node_modules/path-browserify", {
paths: [__dirname],
});
return { path };
});
},
},
nodeDepsPlugin,
esbuildProblemMatcherPlugin,
],
});
if (process.argv.includes("--watch")) {
if (watch) {
await ctx.watch();
console.log("watching...");
} else {
await ctx.rebuild();
await ctx.dispose();
}
})();
}

/**
* @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');
});
}
};


/**
* @type {import('esbuild').Plugin}
*/
const nodeDepsPlugin = {
name: "node-deps",
setup(build) {
build.onResolve({ filter: /^path$/ }, (args) => {
const path = require.resolve("../node_modules/path-browserify", {
paths: [__dirname],
});
return { path };
});
},
};

main().catch(e => {
console.error(e);
process.exit(1);
});