Skip to content

Commit ea70366

Browse files
committed
Avoid bundling package.json
- `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
1 parent c183dca commit ea70366

17 files changed

+62
-1346
lines changed

ava.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export default {
55
},
66
compile: false,
77
},
8+
require: ["./ava.setup.mjs"],
89
};

ava.setup.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import pkg from "./package.json" with { type: "json" };
2+
3+
globalThis.__CODEQL_ACTION_VERSION__ = pkg.version;

build.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { fileURLToPath } from "node:url";
55
import * as esbuild from "esbuild";
66
import { globSync } from "glob";
77

8+
import pkg from "./package.json" with { type: "json" };
9+
810
const __filename = fileURLToPath(import.meta.url);
911
const __dirname = dirname(__filename);
1012

@@ -13,7 +15,7 @@ const OUT_DIR = join(__dirname, "lib");
1315

1416
/**
1517
* Clean the output directory before building.
16-
*
18+
*
1719
* @type {esbuild.Plugin}
1820
*/
1921
const cleanPlugin = {
@@ -27,7 +29,7 @@ const cleanPlugin = {
2729

2830
/**
2931
* Copy defaults.json to the output directory since other projects depend on it.
30-
*
32+
*
3133
* @type {esbuild.Plugin}
3234
*/
3335
const copyDefaultsPlugin = {
@@ -69,6 +71,9 @@ const context = await esbuild.context({
6971
platform: "node",
7072
plugins: [cleanPlugin, copyDefaultsPlugin, onEndPlugin],
7173
target: ["node20"],
74+
define: {
75+
__CODEQL_ACTION_VERSION__: JSON.stringify(pkg.version),
76+
},
7277
});
7378

7479
await context.rebuild();

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default [
2020
"tests/**/*",
2121
"build.mjs",
2222
"ava.config.mjs",
23+
"ava.setup.mjs",
2324
"eslint.config.mjs",
2425
".github/**/*",
2526
"pr-checks/**/*",

lib/analyze-action-post.js

Lines changed: 5 additions & 113 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/analyze-action.js

Lines changed: 3 additions & 111 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)