Skip to content

Commit 3e7d636

Browse files
committed
Support packaging an extension
1 parent fb9f909 commit 3e7d636

File tree

6 files changed

+763
-9
lines changed

6 files changed

+763
-9
lines changed

_extension/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.vsix
22
dist/
3+
bin/

_extension/.vscodeignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Workaround for https://github.com/microsoft/vscode-vsce/issues/580
2+
../

_extension/esbuild.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const esbuild = require('esbuild');
2+
3+
const production = process.argv.includes('--production');
4+
const watch = process.argv.includes('--watch');
5+
6+
async function main() {
7+
const ctx = await esbuild.context({
8+
entryPoints: ['src/extension.ts'],
9+
bundle: true,
10+
format: 'cjs',
11+
minify: production,
12+
sourcemap: !production,
13+
sourcesContent: false,
14+
platform: 'node',
15+
outfile: 'dist/extension.js',
16+
external: ['vscode'],
17+
logLevel: 'warning',
18+
plugins: [
19+
/* add to the end of plugins array */
20+
esbuildProblemMatcherPlugin
21+
]
22+
});
23+
if (watch) {
24+
await ctx.watch();
25+
} else {
26+
await ctx.rebuild();
27+
await ctx.dispose();
28+
}
29+
}
30+
31+
/**
32+
* @type {import('esbuild').Plugin}
33+
*/
34+
const esbuildProblemMatcherPlugin = {
35+
name: 'esbuild-problem-matcher',
36+
37+
setup(build) {
38+
build.onStart(() => {
39+
console.log('[watch] build started');
40+
});
41+
build.onEnd(result => {
42+
result.errors.forEach(({ text, location }) => {
43+
console.error(`✘ [ERROR] ${text}`);
44+
if (location == null) return;
45+
console.error(` ${location.file}:${location.line}:${location.column}:`);
46+
});
47+
console.log('[watch] build finished');
48+
});
49+
}
50+
};
51+
52+
main().catch(e => {
53+
console.error(e);
54+
process.exit(1);
55+
});

_extension/package.json

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"version": "0.0.0",
99
"type": "commonjs",
1010
"engines": {
11-
"vscode": "^1.91.0"
11+
"vscode": "^1.96.0"
1212
},
1313
"activationEvents": [
1414
"onLanguage:javascript",
@@ -54,13 +54,19 @@
5454
},
5555
"main": "./dist/extension.js",
5656
"scripts": {
57-
"build": "tsc",
58-
"watch": "tsc --watch"
57+
"compile": "npm run check-types && node esbuild.js",
58+
"check-types": "tsc --noEmit",
59+
"watch": "npm-run-all -p watch:*",
60+
"watch:esbuild": "node esbuild.js --watch",
61+
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
62+
"vscode:prepublish": "npm run package",
63+
"package": "npm run check-types && node esbuild.js --production"
5964
},
6065
"dependencies": {
6166
"vscode-languageclient": "^9.0.1"
6267
},
6368
"devDependencies": {
64-
"@types/vscode": "^1.96.0"
69+
"@types/vscode": "^1.96.0",
70+
"esbuild": "^0.25.2"
6571
}
6672
}

_extension/src/extension.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,23 @@ export function activate(context: vscode.ExtensionContext) {
2020
const output = vscode.window.createOutputChannel("typescript-go", "log");
2121
const traceOutput = vscode.window.createOutputChannel("typescript-go (LSP)");
2222

23-
const exe = context.asAbsolutePath(
24-
path.join("../", "built", "local", `tsgo${process.platform === "win32" ? ".exe" : ""}`),
25-
);
23+
let exe;
24+
if (process.env.NODE_ENV === "development") {
25+
output.appendLine("Development mode detected, using local tsgo binary.");
26+
exe = context.asAbsolutePath(
27+
path.join(
28+
"../",
29+
"built",
30+
"local",
31+
`tsgo${process.platform === "win32" ? ".exe" : ""}`,
32+
),
33+
);
34+
}
35+
else {
36+
exe = context.asAbsolutePath(
37+
path.join("bin", `tsgo${process.platform === "win32" ? ".exe" : ""}`),
38+
);
39+
}
2640

2741
output.appendLine(`Resolved to ${exe}`);
2842

0 commit comments

Comments
 (0)