Skip to content

Commit 529f154

Browse files
authored
Add esbuild to bundle and package the extension (#467)
* Add initial esbuild setup tested the follow areas: 1) vsce package (installed and confirmed it can display coverage) 2) npm run test 3) npm run build * Add lint step to test.yml * Update tsconfig to exclude esbuild * Use build again * Test improvements * revert package -> main change * Fix more tests * Add new test runner for ci / local * Adjust CI workflow for ubuntu latest * Run all workflows, even on sibling failure * Adjust testing and ci actions * Try headless for all * Add back shell consideration * More adjustments * More adjustments v2 * Add more considerations v3 * Try an older test electron package * Properly update lock file
1 parent 970aa60 commit 529f154

File tree

10 files changed

+6183
-740
lines changed

10 files changed

+6183
-740
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,20 @@ on:
99
jobs:
1010
build:
1111
strategy:
12+
fail-fast: false
1213
matrix:
13-
include:
14-
- os: macos-latest
15-
test: test
16-
- os: windows-latest
17-
test: test
18-
- os: ubuntu-latest
19-
test: test-headless
14+
os: [macos-latest, ubuntu-latest, windows-latest]
2015
runs-on: ${{ matrix.os }}
21-
env:
22-
CI: true
2316
steps:
24-
- uses: actions/checkout@v1
25-
- uses: actions/setup-node@v1
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Install Node.js
20+
uses: actions/setup-node@v4
2621
with:
27-
node-version: 18
28-
- run: npm ci
22+
node-version: 22.x
23+
- run: npm install
2924
- run: npm run build
30-
- run: npm run ${{ matrix.test }}
25+
- run: xvfb-run -a npm test
26+
if: runner.os == 'Linux'
27+
- run: npm test
28+
if: runner.os != 'Linux'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
dist
12
out
23
node_modules
34
.vscode-test

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"${workspaceFolder}/example/example.code-workspace",
1515
"--extensionDevelopmentPath=${workspaceFolder}"
1616
],
17-
"outFiles": ["${workspaceFolder}/out/**/*.js"],
17+
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
1818
"preLaunchTask": "npm: watch"
1919
},
2020
{
@@ -28,7 +28,7 @@
2828
"--extensionTestsPath=${workspaceFolder}/out/test/index"
2929
],
3030
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
31-
"preLaunchTask": "npm: watch"
31+
"preLaunchTask": "npm: compile-tests"
3232
}
3333
]
3434
}

.vscodeignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Remove some folders from the output
2-
out/test/**
3-
out/example/**
1+
# Remove some folders from the build output
2+
out/**
3+
node_modules/**
44

55
# Codebase files
66
src/**
@@ -20,6 +20,7 @@ promo_images/**
2020
.gitignore
2121
.vscode/**
2222
.vscode-test/**
23+
esbuild.js
2324

2425
# Typescript files
2526
@types

esbuild.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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: 'silent',
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+
console.error(` ${location.file}:${location.line}:${location.column}:`);
45+
});
46+
console.log('[watch] build finished');
47+
});
48+
}
49+
};
50+
51+
main().catch(e => {
52+
console.error(e);
53+
process.exit(1);
54+
});

0 commit comments

Comments
 (0)