mirror of
https://github.com/github/codeql-action.git
synced 2026-03-31 00:32:17 +00:00
- `package.json` is bundled by `esbuild` because we depend on it in `actions-util.ts` - That is so we can access the `version` property - We now use `build.mjs` to define a constant for it instead - We also set this constant in `ava.setup.mjs` for tests - This reduces the size of the generated `.js` files and avoids changing them entirely in some cases
81 lines
1.9 KiB
JavaScript
81 lines
1.9 KiB
JavaScript
import { copyFile, 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 pkg from "./package.json" with { type: "json" };
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
|
|
const SRC_DIR = join(__dirname, "src");
|
|
const OUT_DIR = join(__dirname, "lib");
|
|
|
|
/**
|
|
* Clean the output directory before building.
|
|
*
|
|
* @type {esbuild.Plugin}
|
|
*/
|
|
const cleanPlugin = {
|
|
name: "clean",
|
|
setup(build) {
|
|
build.onStart(async () => {
|
|
await rm(OUT_DIR, { recursive: true, force: true });
|
|
});
|
|
},
|
|
};
|
|
|
|
/**
|
|
* Copy defaults.json to the output directory since other projects depend on it.
|
|
*
|
|
* @type {esbuild.Plugin}
|
|
*/
|
|
const copyDefaultsPlugin = {
|
|
name: "copy-defaults",
|
|
setup(build) {
|
|
build.onEnd(async () => {
|
|
await rm(join(OUT_DIR, "defaults.json"), {
|
|
force: true,
|
|
});
|
|
await copyFile(
|
|
join(SRC_DIR, "defaults.json"),
|
|
join(OUT_DIR, "defaults.json"),
|
|
);
|
|
});
|
|
},
|
|
};
|
|
|
|
/**
|
|
* Log when the 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({
|
|
// Include upload-lib.ts as an entry point for use in testing environments.
|
|
entryPoints: globSync([`${SRC_DIR}/*-action.ts`, `${SRC_DIR}/*-action-post.ts`, "src/upload-lib.ts"]),
|
|
bundle: true,
|
|
format: "cjs",
|
|
outdir: OUT_DIR,
|
|
platform: "node",
|
|
plugins: [cleanPlugin, copyDefaultsPlugin, onEndPlugin],
|
|
target: ["node20"],
|
|
define: {
|
|
__CODEQL_ACTION_VERSION__: JSON.stringify(pkg.version),
|
|
},
|
|
});
|
|
|
|
await context.rebuild();
|
|
await context.dispose();
|