Bundle Actions using esbuild

This commit is contained in:
Henry Mercer
2025-08-21 13:34:13 +01:00
parent 6dee5bc9c1
commit fee3663b18
3 changed files with 43 additions and 1 deletions
+38
View File
@@ -0,0 +1,38 @@
import { rm } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import * as esbuild from "esbuild";
import { globSync } from "glob";
import { typecheckPlugin } from "@jgoz/esbuild-plugin-typecheck";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const OUT_DIR = "lib";
await rm(join(__dirname, OUT_DIR), { recursive: true, force: true });
// This will just log when a build ends
/** @type {esbuild.Plugin} */
const onEndPlugin = {
name: "on-end",
setup(build) {
build.onEnd((result) => {
// eslint-disable-next-line no-console
console.log(`Build ended with ${result.errors.length} errors`);
});
},
};
const context = await esbuild.context({
entryPoints: globSync(["src/*-action.ts", "src/*-action-post.ts"]),
bundle: true,
format: "cjs",
outdir: OUT_DIR,
platform: "node",
plugins: [typecheckPlugin(), onEndPlugin],
});
await context.rebuild();
await context.dispose();
+1
View File
@@ -29,6 +29,7 @@ export default [
"lib/**/*",
"src/testdata/**/*",
"tests/**/*",
"build.mjs",
"eslint.config.mjs",
".github/**/*",
],
+4 -1
View File
@@ -4,7 +4,7 @@
"private": true,
"description": "CodeQL action",
"scripts": {
"build": "tsc --build",
"build": "node build.mjs",
"test": "ava src/**.test.ts --serial --verbose",
"test-debug": "ava src/**.test.ts --serial --verbose --timeout=20m",
"lint": "eslint --report-unused-disable-directives --max-warnings=0 .",
@@ -61,6 +61,7 @@
"@eslint/compat": "^1.3.2",
"@eslint/eslintrc": "^3.3.1",
"@eslint/js": "^9.33.0",
"@jgoz/esbuild-plugin-typecheck": "^4.0.3",
"@microsoft/eslint-formatter-sarif": "^3.1.0",
"@types/archiver": "^6.0.3",
"@types/console-log-level": "^1.4.5",
@@ -73,12 +74,14 @@
"@typescript-eslint/eslint-plugin": "^8.40.0",
"@typescript-eslint/parser": "^8.40.0",
"ava": "^6.4.1",
"esbuild": "^0.25.9",
"eslint": "^8.57.1",
"eslint-import-resolver-typescript": "^3.8.7",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-github": "^5.1.8",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-no-async-foreach": "^0.1.1",
"glob": "^11.0.3",
"nock": "^14.0.10",
"removeNPMAbsolutePaths": "3.0.1",
"sinon": "^21.0.0",