Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include JS files (js, mjs & cjs) in the analysis by default #3

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ If you have multiple meta files, you can specify them like this `"dist/meta1.jso
| Name | Default | Description |
|---------------------------|---------------------------------------|------------------------------------------------------------------------------------------------------------------|
| `metafiles` | - | A required comma-separated list of paths to [esbuild's meta file]([https://esbuild.github.io/api/#metafile]). |
| `name` | ${{ github.event.<br>repository.name }} | The name of your project. This will be used in the comment header. |
| `name` | ${{ github.event.<br>repository.name }} | The name of your project. This will be used in the comment header. |
| `analyze_directory` | `.analyzer` | A path to working directory where bundle analysis are stored. |
| `include_extensions` | `.js,.cjs,.mjs` | A comma-separated list of file extension to be included in the analysis table. |
| `percent_extra_attention` | `20` | If an out file size has increased more than this percent, display a "‼️" to draw extra attention to the change. |
| `show_details` | `true` | If `true`, a collapsed "details" section is rendered. It explains the details of the numbers provided and icons. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"out/meta.json -> out/no-change.js": {
"metafile": "out/meta.json",
"outfile": "out/no-change.js",
"bytes": 733152
"bytes": 733190
},
"out/meta.json -> out/decreased.js": {
"metafile": "out/meta.json",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { writeFileSync } from "node:fs";
import { build } from "esbuild";
import metaUrlPlugin from '@chialab/esbuild-plugin-meta-url';

const result = await build({
entryPoints: [
Expand All @@ -8,6 +9,7 @@ const result = await build({
`./src/much-increased.ts`,
`./src/decreased.ts`,
`./src/new-outfile.ts`,
`./src/file-imported.ts`,
],
outdir: `out`,
format: "esm",
Expand All @@ -16,7 +18,10 @@ const result = await build({
platform: "node",
target: "node20.9",
bundle: true,
plugins: [],
plugins: [
metaUrlPlugin(),
],
sourcemap: true,
});

writeFileSync(`out/meta.json`, JSON.stringify(result.metafile, null, 2));

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
"version": "1.0.0",
"description": "test",
"dependencies": {
"@jitl/quickjs-wasmfile-release-sync": "^0.29.1",
"quickjs-emscripten-core": "^0.29.1",
"hono": "4.2.7",
"@aws-sdk/client-s3": "3.556.0"
},
"devDependencies": {
"@chialab/esbuild-plugin-meta-url": "^0.18.2",
"esbuild": "0.20.2",
"typescript": "^5.4.5"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { newQuickJSWASMModuleFromVariant } from "quickjs-emscripten-core"
import releaseVariant from "@jitl/quickjs-wasmfile-release-sync"
export const QuickJS = await newQuickJSWASMModuleFromVariant(releaseVariant)
1 change: 1 addition & 0 deletions __tests__/no-base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe("examples w/o base analysis", () => {
const input: Options = {
analyzerDirectory: ".analyzer",
budgetPercentIncreaseRed: 20,
includeExtensions: [".js", ".mjs", ".cjs"],
metafiles: ["out/meta.json"],
name: "test",
showDetails: false,
Expand Down
4 changes: 4 additions & 0 deletions __tests__/with-base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("examples w/ base analysis", () => {
const input: Options = {
analyzerDirectory: ".analyzer",
budgetPercentIncreaseRed: 20,
includeExtensions: [".js", ".mjs", ".cjs"],
metafiles,
name: "test",
showDetails: false,
Expand All @@ -45,6 +46,9 @@ describe("examples w/ base analysis", () => {

const comment = readAnalysisComment(input.analyzerDirectory);
expect(comment).not.toMatch(/no changes to the esbuild bundle/i);
expect(comment).not.include(".js.map");
expect(comment).not.include(".wasm");
expect(comment).toMatch(/\.[cm]?js /i);
expect(comment).toMatch(/‼️ \+\d+/);
expect(comment).toMatch(/⚠️ \+\d+/);
expect(comment).toMatch(/✅ {2}-\d+/);
Expand Down
6 changes: 6 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ inputs:
default: ".analyzer"
description: |
A path to working directory where bundle analysis are stored.
include_extensions:
required: false
default: ".js,.cjs,.mjs"
description: |
A comma-separated list of file extension to be included in the analysis table.
percent_extra_attention:
required: false
default: "20"
Expand Down Expand Up @@ -67,6 +72,7 @@ runs:
INPUT_METAFILES: ${{ inputs.metafiles }}
INPUT_NAME: ${{ inputs.name }}
INPUT_ANALYZE_DIRECTORY: ${{ inputs.analyze_directory }}
INPUT_INCLUDE_EXTENSIONS: ${{ inputs.include_extensions }}
INPUT_PERCENT_EXTRA_ATTENTION: ${{ inputs.percent_extra_attention }}
INPUT_SHOW_DETAILS: ${{ inputs.show_details }}
run: |
Expand Down
8 changes: 7 additions & 1 deletion dist/index.mjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ function getOptions(): Options {
showDetails: ["true", "True", "TRUE"].includes(
getInput("show_details") || "true",
),
includeExtensions: (
getInput("include_extensions") || ".js,.mjs,.cjs"
).split(","),
name,
analyzerDirectory: getInput("analyze_directory") || ".analyzer",
metafiles: rawMetafiles.split(","),
Expand Down
7 changes: 7 additions & 0 deletions src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ function getAllPageSizes(input: Options): Report {
const metaFileJson = loadMetaFile(metaFilePath);
Object.entries(metaFileJson.outputs).reduce((acc, output) => {
const [outfile, buildMeta] = output;
if (
!input.includeExtensions.some((ext) =>
outfile.toLowerCase().endsWith(ext),
)
) {
return acc;
}
acc[`${metafile} -> ${outfile}`] = {
bytes: buildMeta.bytes,
metafile,
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface CompareResult {
export interface Options {
name: string;
metafiles: Array<string>;
includeExtensions: Array<string>;
analyzerDirectory: string;
budgetPercentIncreaseRed: number;
showDetails: boolean;
Expand Down