Skip to content

Commit fee3663

Browse files
committed
Bundle Actions using esbuild
1 parent 6dee5bc commit fee3663

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

build.mjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { rm } from "node:fs/promises";
2+
import { dirname, join } from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
5+
import * as esbuild from "esbuild";
6+
import { globSync } from "glob";
7+
import { typecheckPlugin } from "@jgoz/esbuild-plugin-typecheck";
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
const OUT_DIR = "lib";
13+
14+
await rm(join(__dirname, OUT_DIR), { recursive: true, force: true });
15+
16+
// This will just log when a build ends
17+
/** @type {esbuild.Plugin} */
18+
const onEndPlugin = {
19+
name: "on-end",
20+
setup(build) {
21+
build.onEnd((result) => {
22+
// eslint-disable-next-line no-console
23+
console.log(`Build ended with ${result.errors.length} errors`);
24+
});
25+
},
26+
};
27+
28+
const context = await esbuild.context({
29+
entryPoints: globSync(["src/*-action.ts", "src/*-action-post.ts"]),
30+
bundle: true,
31+
format: "cjs",
32+
outdir: OUT_DIR,
33+
platform: "node",
34+
plugins: [typecheckPlugin(), onEndPlugin],
35+
});
36+
37+
await context.rebuild();
38+
await context.dispose();

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default [
2929
"lib/**/*",
3030
"src/testdata/**/*",
3131
"tests/**/*",
32+
"build.mjs",
3233
"eslint.config.mjs",
3334
".github/**/*",
3435
],

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"description": "CodeQL action",
66
"scripts": {
7-
"build": "tsc --build",
7+
"build": "node build.mjs",
88
"test": "ava src/**.test.ts --serial --verbose",
99
"test-debug": "ava src/**.test.ts --serial --verbose --timeout=20m",
1010
"lint": "eslint --report-unused-disable-directives --max-warnings=0 .",
@@ -61,6 +61,7 @@
6161
"@eslint/compat": "^1.3.2",
6262
"@eslint/eslintrc": "^3.3.1",
6363
"@eslint/js": "^9.33.0",
64+
"@jgoz/esbuild-plugin-typecheck": "^4.0.3",
6465
"@microsoft/eslint-formatter-sarif": "^3.1.0",
6566
"@types/archiver": "^6.0.3",
6667
"@types/console-log-level": "^1.4.5",
@@ -73,12 +74,14 @@
7374
"@typescript-eslint/eslint-plugin": "^8.40.0",
7475
"@typescript-eslint/parser": "^8.40.0",
7576
"ava": "^6.4.1",
77+
"esbuild": "^0.25.9",
7678
"eslint": "^8.57.1",
7779
"eslint-import-resolver-typescript": "^3.8.7",
7880
"eslint-plugin-filenames": "^1.3.2",
7981
"eslint-plugin-github": "^5.1.8",
8082
"eslint-plugin-import": "2.29.1",
8183
"eslint-plugin-no-async-foreach": "^0.1.1",
84+
"glob": "^11.0.3",
8285
"nock": "^14.0.10",
8386
"removeNPMAbsolutePaths": "3.0.1",
8487
"sinon": "^21.0.0",

0 commit comments

Comments
 (0)