Skip to content

Commit 878e2d8

Browse files
authored
build: bundle extension with esbuild (#55)
The extension shipped every tsc-emitted file plus the full `node_modules` tree in the `.vsix` (198 files, 361KB). Bundling `src/extension.ts` into a single minified `dist/extension.js` with esbuild inlines the runtime deps (all pure JS, `vscode` left external) and drops `node_modules` from the package entirely: | | Before (tsc) | After (esbuild) | |---|---|---| | `.vsix` (compressed) | 361 KB | 75 KB (**-79%**) | | Files | 198 | 7 | Faster activation too: the host resolves one module instead of ~190. `tsc` is kept for type-checking (`--noEmit`) and for compiling tests to `out/`, so test coverage is unaffected. Nix (`vsix.nix`) already derives deps via `importNpmLock`, so no hash to maintain; `vsce package` now runs the esbuild-based `vscode:prepublish`. Also fixes a pre-existing ordering-dependent flaky test in `highlighters` (`highlightLayer` relied on `extension.activate()` having run in another test file first, leaving `vulnTreeDataProvider` undefined otherwise) by stubbing it locally in setup. Note: the `pre-commit` lint hook also runs `npm audit`, which fails on a pre-existing `serialize-javascript` advisory pulled in via `@vscode/test-cli → mocha` (no fix available, unrelated to this change). esbuild itself has zero dependencies.
1 parent fff3693 commit 878e2d8

11 files changed

Lines changed: 669 additions & 81 deletions

File tree

.github/workflows/release.yml

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout code
13-
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
13+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
1414
with:
1515
fetch-depth: 2 # We only need the current and the previous commit
1616

@@ -30,33 +30,30 @@ jobs:
3030
runs-on: ubuntu-latest
3131
needs: check-changes
3232
if: needs.check-changes.outputs.changes == 'detected'
33+
defaults:
34+
run:
35+
shell: nix develop --command bash -e {0}
3336
steps:
3437
- name: Checkout code
35-
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
38+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
3639

37-
- name: Set up Node.js
38-
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
39-
with:
40-
node-version: 22
41-
42-
- name: Install dependencies
43-
run: |-
44-
npm install
45-
npm install -g vsce
40+
- uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 # v22
41+
- uses: DeterminateSystems/magic-nix-cache-action@908b263ff629f4cc17666315b7fd3ec127c6244d # v14
4642

4743
# - name: Run tests
48-
# run: npm test
44+
# run: just test
4945

5046
- name: Build VSIX file
51-
run: vsce package -o sysdig-vscode-ext.vsix
47+
run: just vsix
5248

5349
- name: Get current version
5450
id: version
55-
run: echo "version=$(jq -r '.version' package.json)" >> "$GITHUB_OUTPUT"
51+
shell: bash
52+
run: echo "version=$(jq --raw-output '.version' package.json)" >> "$GITHUB_OUTPUT"
5653

5754
- name: Create release
5855
id: create_release
59-
uses: actions/create-release@v1
56+
uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e # v1.1.4
6057
env:
6158
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6259
with:
@@ -66,7 +63,7 @@ jobs:
6663
prerelease: false
6764

6865
- name: Upload VSIX file
69-
uses: actions/upload-release-asset@v1
66+
uses: actions/upload-release-asset@e8f9f06c4b078e705bd2ea027f0926603fc9b4d5 # v1.0.2
7067
env:
7168
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7269
with:
@@ -76,11 +73,7 @@ jobs:
7673
asset_content_type: application/vsix
7774

7875
- name: Publish VSIX to the marketplace
79-
env:
80-
VSCE_PAT: ${{ secrets.AZURE_DEVOPS_PAT }}
81-
run: |
82-
vsce publish
76+
run: just publish-vscode-marketplace ${{ secrets.AZURE_DEVOPS_PAT }}
8377

8478
- name: Publish VSIX to Open VSX
85-
run: |
86-
npx ovsx publish ./sysdig-vscode-ext.vsix -p ${{ secrets.OVSX_PAT }}
79+
run: just publish-openvsx-registry ${{ secrets.OVSX_PAT }}

.github/workflows/test.yml

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,24 @@ jobs:
1111
matrix:
1212
os: [macos-latest, ubuntu-latest]
1313
runs-on: ${{ matrix.os }}
14+
defaults:
15+
run:
16+
shell: nix develop --command bash -e {0}
1417
steps:
1518
- name: Checkout
16-
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
17-
- name: Install Node.js
18-
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
19-
with:
20-
node-version: 18.x
21-
- run: npm ci --include=dev
22-
#- run: apt update && apt install -y libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfb
23-
# if: runner.os == 'Linux'
24-
#- run: service dbus start
25-
# if: runner.os == 'Linux'
26-
- run: xvfb-run -a npm test
27-
if: runner.os == 'Linux'
28-
- run: npm test
29-
if: runner.os != 'Linux'
19+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
20+
- uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 # v22
21+
- uses: DeterminateSystems/magic-nix-cache-action@908b263ff629f4cc17666315b7fd3ec127c6244d # v14
22+
- run: just test
3023

3124
test-nix:
3225
strategy:
3326
matrix:
3427
os: [macos-latest, ubuntu-latest]
3528
runs-on: ${{ matrix.os }}
3629
steps:
37-
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
38-
- uses: DeterminateSystems/nix-installer-action@v1
39-
- uses: DeterminateSystems/magic-nix-cache-action@v1
40-
- uses: DeterminateSystems/flake-checker-action@v1
41-
- run: nix build -L
30+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
31+
- uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 # v22
32+
- uses: DeterminateSystems/magic-nix-cache-action@908b263ff629f4cc17666315b7fd3ec127c6244d # v14
33+
- uses: DeterminateSystems/flake-checker-action@3164002371bc90729c68af0e24d5aacf20d7c9f6 # v12
34+
- run: nix build --print-build-logs

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"--extensionDevelopmentPath=${workspaceFolder}"
1414
],
1515
"outFiles": [
16-
"${workspaceFolder}/out/**/*.js"
16+
"${workspaceFolder}/dist/**/*.js"
1717
],
1818
"preLaunchTask": "${defaultBuildTask}",
1919
}

.vscodeignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
.vscode/**
22
.vscode-test/**
33
src/**
4+
out/**
5+
node_modules/**
6+
esbuild.js
47
.gitignore
58
.yarnrc
69
vsc-extension-quickstart.md
@@ -9,3 +12,13 @@ vsc-extension-quickstart.md
912
**/*.map
1013
**/*.ts
1114
**/.vscode-test.*
15+
.github/**
16+
.direnv/**
17+
.envrc
18+
.pre-commit-config.yaml
19+
justfile
20+
flake.nix
21+
flake.lock
22+
vsix.nix
23+
result
24+
*.vsix

Justfile

Lines changed: 0 additions & 32 deletions
This file was deleted.

esbuild.js

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

flake.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@
6969
mkShell {
7070
shellHook = ''
7171
npm ci
72-
pre-commit install
72+
prek install --overwrite
7373
'';
7474
packages = [
75+
prek
7576
just
7677
nodejs
7778
pinact

justfile

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
# Show available recipes
3+
[private]
4+
default:
5+
@just --list
6+
7+
# Run while debugging; wired as the preLaunchTask for F5
8+
watch:
9+
npm run watch
10+
11+
# Build an installable .vsix (VS Code: "Install from VSIX…") into the repo root
12+
vsix:
13+
nix build
14+
install --mode=644 result sysdig-vscode-ext.vsix
15+
rm result
16+
17+
# Publish the built .vsix to the VS Code Marketplace
18+
publish-vscode-marketplace token: vsix
19+
vsce publish --packagePath sysdig-vscode-ext.vsix --pat {{token}}
20+
21+
# Publish the built .vsix to the Open VSX registry
22+
publish-openvsx-registry token: vsix
23+
npx ovsx publish sysdig-vscode-ext.vsix --pat {{token}}
24+
25+
# Clean up
26+
clean:
27+
rm -f sysdig-vscode-ext.vsix
28+
rm -rf out
29+
rm -rf dist
30+
rm -rf node_modules
31+
rm -rf .vscode-test
32+
rm -f result
33+
34+
# Run tests
35+
[linux]
36+
test:
37+
xvfb-run --auto-display npm test
38+
39+
# Run tests
40+
[macos]
41+
test:
42+
npm test
43+
44+
# All static code checks, without running tests
45+
lint:
46+
#!/usr/bin/env bash
47+
set -o errexit -o nounset -o pipefail
48+
npm run check-types
49+
npm run lint
50+
# Audit fails only when at least one vulnerability has a fix available
51+
audit=$(npm audit --json) || true
52+
if node -e 'const v=Object.values(JSON.parse(require("fs").readFileSync(0,"utf8")).vulnerabilities||{}); process.exit(v.some(x=>x.fixAvailable!==false)?0:1)' <<<"$audit"; then
53+
npm audit
54+
exit 1
55+
fi
56+
57+
# Bump all pinned dependencies to their latest versions
58+
update:
59+
nix flake update
60+
nix develop --command pre-commit autoupdate
61+
nix develop --command npm update
62+
nix develop --command just update-scanner-version
63+
nix develop --command pinact run --update --diff
64+
65+
# Bump the inner sysdig-cli-scanner to the latest version
66+
update-scanner-version:
67+
#!/usr/bin/env bash
68+
set -o errexit -o nounset -o pipefail
69+
echo "Fetching latest sysdig-cli-scanner version…"
70+
latest=$(curl --silent --show-error --fail --location https://download.sysdig.com/scanning/sysdig-cli-scanner/latest_version.txt)
71+
echo "Latest: $latest"
72+
sd "(export const SCANNER_VERSION : string = ')[^']+(';)" "\${1}$latest\${2}" src/config/configScanner.ts
73+
echo "Version updated"

0 commit comments

Comments
 (0)