Skip to content

Commit dc420f1

Browse files
authored
Bundle extension & add publish workflow (#124)
* Setup esbuild * Add more files to .vscodeignore * Set up esbuild & running built extension * Find more occurrences in logger method matching * Always ship sourcemaps to get readable logs from users * Use extension.js instead of extension * Improve run config & change entrypoint during `npm test` * Add way to package vsce * Init GitHub publish workflow * Update one npm package
1 parent 0de567b commit dc420f1

18 files changed

+4256
-1277
lines changed

.config/tsconfig.json

+5
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@
99
"strict": true,
1010
"noFallthroughCasesInSwitch": true,
1111
"removeComments": true,
12+
"outDir": "../out/",
13+
"rootDir": "../"
1214
},
15+
"include": [
16+
"../src/**/*.ts",
17+
],
1318
}

.config/tsconfig.paths.json

-16
This file was deleted.

.config/tsconfig.tests.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": [
4+
"../tests/**/*.ts",
5+
],
6+
}

.github/workflows/publish.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
on:
2+
release:
3+
types:
4+
- created
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
13+
- name: Install Node.js
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: 22
17+
18+
- name: Install dependencies
19+
run: npm install
20+
21+
- name: Package extension
22+
run: npm run package-vsce
23+
24+
- name: Upload VSIX artifact to
25+
if: startsWith(github.ref, 'refs/tags/')
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: manim-notebook.vsix
29+
path: manim-notebook-*.vsix
30+
if-no-files-found: error
31+
32+
- name: Publish
33+
if: startsWith(github.ref, 'refs/tags/')
34+
run: npm run deploy
35+
env:
36+
VSCE_PAT: ${{ secrets.VSCE_PAT }}

.github/workflows/tests.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ jobs:
102102
if [ "$RUNNER_OS" == "Linux" ]; then
103103
# Start an X virtual framebuffer (Xvfb) server, which emulates a
104104
# display server without requiring a physical display.
105-
xvfb-run -a npm run testInGithubActions
105+
xvfb-run -a npm run test-without-pre-or-posttest
106106
else
107-
npm run testInGithubActions
107+
npm run test-without-pre-or-posttest
108108
fi
109109
shell: bash
110+
111+
- name: Run posttest
112+
run: npm run posttest

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ tmp/
33
*.mp4
44
.DS_Store
55
out
6+
out-test
67
dist
78
node_modules
89
_debug_scenes/

.vscode/extensions.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// for the documentation about the extensions.json format
44
"recommendations": [
55
"dbaeumer.vscode-eslint",
6-
"streetsidesoftware.code-spell-checker"
6+
"streetsidesoftware.code-spell-checker",
7+
"connor4312.esbuild-problem-matchers"
78
]
89
}

.vscode/launch.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"--extensionDevelopmentPath=${workspaceFolder}"
1414
],
1515
"outFiles": [
16-
"${workspaceFolder}/out/src/**/*.js"
16+
"${workspaceFolder}/dist/**/*.js"
1717
],
18-
"preLaunchTask": "Watch Files",
18+
"preLaunchTask": "Watch (Default)",
1919
"sourceMaps": true
2020
},
2121
{
@@ -27,10 +27,10 @@
2727
"${workspaceFolder}/tests/fixtures",
2828
"--disable-extensions",
2929
"--extensionDevelopmentPath=${workspaceFolder}",
30-
"--extensionTestsPath=${workspaceFolder}/out/tests/utils/testRunner.js"
30+
"--extensionTestsPath=${workspaceFolder}/out-test/tests/utils/testRunner.js"
3131
],
3232
"outFiles": [
33-
"${workspaceFolder}/out/test/**/*.js"
33+
"${workspaceFolder}/out-test/tests/**/*.js"
3434
],
3535
"preLaunchTask": "Prepare For Tests",
3636
"sourceMaps": true,

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"nodenext",
109109
"opengl",
110110
"Pango",
111+
"posttest",
111112
"prerun",
112113
"pycache",
113114
"Pyglet",

.vscode/tasks.json

+53-9
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"version": "2.0.0",
55
"tasks": [
66
{
7-
"label": "Watch Files",
8-
"type": "npm",
9-
"script": "watch",
10-
"problemMatcher": "$tsc-watch",
11-
"isBackground": true,
7+
"label": "Watch (Default)",
8+
"dependsOn": [
9+
"npm: watch:tsc",
10+
"npm: watch:esbuild"
11+
],
1212
"presentation": {
1313
"reveal": "never"
1414
},
@@ -17,11 +17,46 @@
1717
"isDefault": true
1818
}
1919
},
20+
{
21+
"type": "npm",
22+
"script": "watch:tsc",
23+
"group": "build",
24+
"problemMatcher": "$tsc-watch",
25+
"isBackground": true,
26+
"label": "npm: watch:tsc",
27+
"presentation": {
28+
"group": "watch",
29+
"reveal": "never"
30+
}
31+
},
32+
{
33+
"type": "npm",
34+
"script": "watch:esbuild",
35+
"group": "build",
36+
"problemMatcher": "$esbuild-watch",
37+
"isBackground": true,
38+
"label": "npm: watch:esbuild",
39+
"presentation": {
40+
"group": "watch",
41+
"reveal": "never"
42+
}
43+
},
44+
{
45+
"type": "npm",
46+
"script": "watch:tests",
47+
"group": "build",
48+
"problemMatcher": "$tsc-watch",
49+
"isBackground": true,
50+
"label": "npm: watch:tests",
51+
"presentation": {
52+
"group": "watch",
53+
"reveal": "never"
54+
}
55+
},
2056
{
2157
"label": "Install Manim",
2258
"type": "npm",
2359
"script": "install-manim",
24-
"cwd": "${workspaceFolder}",
2560
"presentation": {
2661
"reveal": "always"
2762
},
@@ -33,9 +68,18 @@
3368
"label": "Prepare For Tests",
3469
"dependsOrder": "sequence",
3570
"dependsOn": [
36-
"Watch Files",
71+
"npm: watch:tsc",
72+
"npm: watch:esbuild",
73+
"npm: watch:tests",
3774
"Install Manim"
38-
]
39-
}
75+
],
76+
"presentation": {
77+
"reveal": "never"
78+
},
79+
"group": {
80+
"kind": "build",
81+
"isDefault": true
82+
}
83+
},
4084
]
4185
}

.vscodeignore

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
.github/**
12
.config/**
23
.vscode/**
34
.vscode-test/**
45
src/**
5-
scripts/**
6+
tests/**
7+
tmp/**
8+
out-test/**
69
.gitignore
7-
**/tsconfig.json
810
**/eslint.config.mjs
911
**/*.map
1012
**/*.ts
1113
**/.vscode-test.*
1214
CHANGELOG.md
1315
CONTRIBUTING.md
14-
out/tests/**
16+
.markdownlint.jsonc
17+
node_modules/**
18+
esbuild.js

esbuild.js

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

0 commit comments

Comments
 (0)