@jsenv/file-size-impact 14.3.29 → 14.3.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -6
- package/readme.md +106 -333
- package/src/report_file_size_impact_in_github_pr.js +1 -1
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/file-size-impact",
|
|
3
|
-
"version": "14.3.
|
|
3
|
+
"version": "14.3.31",
|
|
4
4
|
"description": "Add files size impact into pull requests",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/jsenv/core",
|
|
9
|
-
"directory": "packages/
|
|
9
|
+
"directory": "packages/tooling/file-size-impact"
|
|
10
10
|
},
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=20.0.0"
|
|
@@ -34,9 +34,13 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@jsenv/dynamic-import-worker": "1.2.1",
|
|
37
|
-
"@jsenv/filesystem": "4.15.
|
|
38
|
-
"@jsenv/github-pull-request-impact": "1.8.
|
|
39
|
-
"@jsenv/urls": "2.
|
|
40
|
-
"@jsenv/humanize": "1.
|
|
37
|
+
"@jsenv/filesystem": "4.15.4",
|
|
38
|
+
"@jsenv/github-pull-request-impact": "1.8.31",
|
|
39
|
+
"@jsenv/urls": "2.9.0",
|
|
40
|
+
"@jsenv/humanize": "1.6.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@jsenv/assert": "../assert",
|
|
44
|
+
"@jsenv/file-size-impact": "./"
|
|
41
45
|
}
|
|
42
46
|
}
|
package/readme.md
CHANGED
|
@@ -1,17 +1,44 @@
|
|
|
1
|
-
# File
|
|
1
|
+
# File Size Impact
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@jsenv/file-size-impact)
|
|
4
4
|
|
|
5
|
-
`@jsenv/file-size-impact`
|
|
5
|
+
`@jsenv/file-size-impact` analyzes a pull request's impact on file sizes and posts the results as a comment in your GitHub PR.
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
- Create
|
|
10
|
-
-
|
|
7
|
+
- ✅ Catch size impacts before merging pull requests
|
|
8
|
+
- 📦 Track compressed file sizes (gzip, brotli)
|
|
9
|
+
- 📊 Create meaningful reports by grouping files
|
|
10
|
+
- 🔄 Integrate with any CI/CD platform (GitHub Actions, Jenkins, etc.)
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
## Quick Start
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
```console
|
|
15
|
+
npm install --save-dev @jsenv/file-size-impact
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
1. Create a file size tracking script
|
|
19
|
+
2. Set up your CI workflow
|
|
20
|
+
3. Get size impact comments on every PR!
|
|
21
|
+
|
|
22
|
+
## Table of Contents
|
|
23
|
+
|
|
24
|
+
- [File Size Impact](#file-size-impact)
|
|
25
|
+
- [Quick Start](#quick-start)
|
|
26
|
+
- [Table of Contents](#table-of-contents)
|
|
27
|
+
- [Pull Request Comment](#pull-request-comment)
|
|
28
|
+
- [Installation](#installation)
|
|
29
|
+
- [Step 1: Create a file size report script](#step-1-create-a-file-size-report-script)
|
|
30
|
+
- [Step 2: Create a report script](#step-2-create-a-report-script)
|
|
31
|
+
- [GitHub Workflow](#github-workflow)
|
|
32
|
+
- [Other Tools](#other-tools)
|
|
33
|
+
- [How it Works](#how-it-works)
|
|
34
|
+
- [API Reference](#api-reference)
|
|
35
|
+
- [generateFileSizeReport](#generatefilesizereport)
|
|
36
|
+
- [Options](#options)
|
|
37
|
+
- [reportFileSizeImpactInGitHubPullRequest](#reportfilesizeimpactingithubpullrequest)
|
|
38
|
+
|
|
39
|
+
## Pull Request Comment
|
|
40
|
+
|
|
41
|
+
Here's how the PR comments look with explanations:
|
|
15
42
|
|
|
16
43
|

|
|
17
44
|
|
|
@@ -22,17 +49,14 @@ Screenshot + explanation on pull request comment.
|
|
|
22
49
|
| "_Unmodified (4)_" | Sum of files in that group that are not impacted by the pull request. |
|
|
23
50
|
| _Total (5)_ | Sum of files in that group. |
|
|
24
51
|
|
|
25
|
-
|
|
52
|
+
## Installation
|
|
26
53
|
|
|
27
|
-
|
|
54
|
+
### Step 1: Create a file size report script
|
|
28
55
|
|
|
29
|
-
|
|
30
|
-
npm install --save-dev @jsenv/file-size-impact
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
_file_size.mjs_
|
|
56
|
+
First, create a script that generates your file size report:
|
|
34
57
|
|
|
35
58
|
```js
|
|
59
|
+
// file_size.mjs
|
|
36
60
|
import { generateFileSizeReport } from "@jsenv/file-size-impact";
|
|
37
61
|
|
|
38
62
|
export const fileSizeReport = await generateFileSizeReport({
|
|
@@ -47,28 +71,34 @@ export const fileSizeReport = await generateFileSizeReport({
|
|
|
47
71
|
});
|
|
48
72
|
```
|
|
49
73
|
|
|
50
|
-
|
|
74
|
+
Test it locally:
|
|
51
75
|
|
|
52
76
|
```console
|
|
53
77
|
node ./file_size.mjs --log
|
|
54
78
|
```
|
|
55
79
|
|
|
56
|
-
|
|
80
|
+
### Step 2: Create a report script
|
|
57
81
|
|
|
58
|
-
|
|
82
|
+
```js
|
|
83
|
+
// report_file_size_impact.mjs
|
|
84
|
+
import {
|
|
85
|
+
reportFileSizeImpactInGitHubPullRequest,
|
|
86
|
+
readGitHubWorkflowEnv,
|
|
87
|
+
} from "@jsenv/file-size-impact";
|
|
59
88
|
|
|
60
|
-
|
|
89
|
+
await reportFileSizeImpactInGitHubPullRequest({
|
|
90
|
+
...readGitHubWorkflowEnv(),
|
|
91
|
+
buildCommand: "npm run dist",
|
|
92
|
+
fileSizeReportUrl: new URL("./file_size.mjs#fileSizeReport", import.meta.url),
|
|
93
|
+
});
|
|
94
|
+
```
|
|
61
95
|
|
|
62
|
-
|
|
63
|
-
# This is a GitHub workflow YAML file
|
|
64
|
-
# see https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
|
|
65
|
-
#
|
|
66
|
-
# For every push on a pull request, it
|
|
67
|
-
# - starts a machine on ubuntu
|
|
68
|
-
# - clone the git repository
|
|
69
|
-
# - install node, install npm deps
|
|
70
|
-
# - Executes report_file_size_impact.mjs
|
|
96
|
+
### GitHub Workflow
|
|
71
97
|
|
|
98
|
+
Create a GitHub Actions workflow file:
|
|
99
|
+
|
|
100
|
+
```yml
|
|
101
|
+
# .github/workflows/file_size_impact.yml
|
|
72
102
|
name: file size impact
|
|
73
103
|
|
|
74
104
|
on: pull_request
|
|
@@ -92,45 +122,37 @@ jobs:
|
|
|
92
122
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
93
123
|
```
|
|
94
124
|
|
|
95
|
-
|
|
125
|
+
That's it! Now your PRs will automatically get file size impact comments.
|
|
96
126
|
|
|
97
|
-
|
|
98
|
-
/*
|
|
99
|
-
* This file is executed by file_size_impact.yml GitHub workflow.
|
|
100
|
-
* - it generates file size report before and after merging a pull request
|
|
101
|
-
* - Then, it creates or updates a comment in the pull request
|
|
102
|
-
* See https://github.com/jsenv/core/tree/main/packages/tooling/file-size-impact#how-it-works
|
|
103
|
-
*/
|
|
127
|
+
### Other Tools
|
|
104
128
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
129
|
+
If you want to use another CI tool like Jenkins:
|
|
130
|
+
|
|
131
|
+
1. **Create a GitHub token** with `repo` scope at https://github.com/settings/tokens/new
|
|
132
|
+
2. **Update your report script** to provide environment variables:
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
// report_file_size_impact.mjs for Jenkins
|
|
136
|
+
import { reportFileSizeImpactInGitHubPullRequest } from "@jsenv/file-size-impact";
|
|
109
137
|
|
|
110
138
|
await reportFileSizeImpactInGitHubPullRequest({
|
|
111
|
-
|
|
139
|
+
rootDirectoryUrl: process.env.WORKSPACE, // Jenkins workspace
|
|
140
|
+
repositoryOwner: process.env.GITHUB_REPO_OWNER,
|
|
141
|
+
repositoryName: process.env.GITHUB_REPO_NAME,
|
|
142
|
+
pullRequestNumber: process.env.PULL_REQUEST_NUMBER,
|
|
143
|
+
githubToken: process.env.GITHUB_TOKEN,
|
|
112
144
|
buildCommand: "npm run dist",
|
|
113
145
|
fileSizeReportUrl: new URL("./file_size.mjs#fileSizeReport", import.meta.url),
|
|
146
|
+
runLink: {
|
|
147
|
+
url: process.env.BUILD_URL,
|
|
148
|
+
text: `${process.env.JOB_NAME}#${process.env.BUILD_ID}`,
|
|
149
|
+
},
|
|
114
150
|
});
|
|
115
151
|
```
|
|
116
152
|
|
|
117
|
-
**
|
|
153
|
+
3. **Configure your CI job** to execute the necessary git commands:
|
|
118
154
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
## Other tools
|
|
122
|
-
|
|
123
|
-
If you want to use an other tool than GitHub worflow to run the pull request comparison, like Jenkins, there is a few things to do:
|
|
124
|
-
|
|
125
|
-
1. Replicate _file_size_impact.yml_
|
|
126
|
-
2. Adjust _report_file_size_impact.mjs_
|
|
127
|
-
3. Create a GitHub token (required to post comment on GitHub)
|
|
128
|
-
|
|
129
|
-
### 1. Replicate _file_size_impact.yml_
|
|
130
|
-
|
|
131
|
-
Your workflow must reproduce the state where your git repository has been cloned and you are currently on the pull request branch. Something like the commands below.
|
|
132
|
-
|
|
133
|
-
```console
|
|
155
|
+
```shell
|
|
134
156
|
git init
|
|
135
157
|
git remote add origin $GITHUB_REPOSITORY_URL
|
|
136
158
|
git fetch --no-tags --prune origin $PULL_REQUEST_HEAD_REF
|
|
@@ -139,74 +161,36 @@ npm install
|
|
|
139
161
|
node ./report_file_size_impact.mjs
|
|
140
162
|
```
|
|
141
163
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
When outside a GitHub workflow, you cannot use _readGitHubWorkflowEnv()_. It means you must pass several parameters to _reportFileSizeImpactInGitHubPullRequest_. The example below assume code is executed by Travis.
|
|
145
|
-
|
|
146
|
-
```diff
|
|
147
|
-
- import { reportFileSizeImpactInGitHubPullRequest, readGitHubWorkflowEnv } from "@jsenv/file-size-impact"
|
|
148
|
-
+ import { reportFileSizeImpactInGitHubPullRequest } from "@jsenv/file-size-impact"
|
|
149
|
-
|
|
150
|
-
reportFileSizeImpactInGitHubPullRequest({
|
|
151
|
-
- ...readGitHubWorkflowEnv(),
|
|
152
|
-
+ rootDirectoryUrl: process.env.TRAVIS_BUILD_DIR,
|
|
153
|
-
+ repositoryOwner: process.env.TRAVIS_REPO_SLUG.split("/")[0],
|
|
154
|
-
+ repositoryName: process.env.TRAVIS_REPO_SLUG.split("/")[1],
|
|
155
|
-
+ pullRequestNumber: process.env.TRAVIS_PULL_REQUEST,
|
|
156
|
-
+ githubToken: process.env.GITHUB_TOKEN, // see next step
|
|
157
|
-
buildCommand: "npm run dist",
|
|
158
|
-
})
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### 3. Create a GitHub token
|
|
164
|
+
## How it Works
|
|
162
165
|
|
|
163
|
-
The
|
|
164
|
-
|
|
165
|
-
# How it works
|
|
166
|
-
|
|
167
|
-
In order to analyse the impact of a pull request on file size the following steps are executed:
|
|
166
|
+
The file size impact analysis follows these steps:
|
|
168
167
|
|
|
169
168
|
1. Checkout pull request base branch
|
|
170
169
|
2. Execute an install command (_npm install_ by default)
|
|
171
|
-
3. Run a build command (
|
|
172
|
-
4.
|
|
170
|
+
3. Run a build command (_npm run-script build_ by default)
|
|
171
|
+
4. Generate a baseline file size report
|
|
173
172
|
5. Merge pull request into its base
|
|
174
|
-
6.
|
|
175
|
-
7.
|
|
176
|
-
8.
|
|
177
|
-
9. Post or update comment in the pull request
|
|
173
|
+
6. Rebuild files
|
|
174
|
+
7. Generate a second file size report
|
|
175
|
+
8. Analyze differences between the two reports
|
|
176
|
+
9. Post or update a comment in the pull request
|
|
178
177
|
|
|
179
|
-
|
|
178
|
+
## API Reference
|
|
180
179
|
|
|
181
|
-
|
|
180
|
+
### generateFileSizeReport
|
|
181
|
+
|
|
182
|
+
Scans the filesystem to compute file sizes with optional transformations:
|
|
182
183
|
|
|
183
184
|
```js
|
|
184
|
-
import {
|
|
185
|
+
import {
|
|
186
|
+
generateFileSizeReport,
|
|
187
|
+
raw,
|
|
188
|
+
gzip,
|
|
189
|
+
brotli,
|
|
190
|
+
} from "@jsenv/file-size-impact";
|
|
185
191
|
|
|
186
192
|
const fileSizeReport = await generateFileSizeReport({
|
|
187
193
|
rootDirectoryUrl: new URL("./", import.meta.url),
|
|
188
|
-
trackingConfig: {
|
|
189
|
-
dist: {
|
|
190
|
-
"./dist/**/*.js": true,
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
transformations: { raw, gzip },
|
|
194
|
-
});
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
## trackingConfig
|
|
198
|
-
|
|
199
|
-
_trackingConfig_ parameter is an object used to configure group of files you want to track. This parameter is optional with a default value exported in [src/jsenv_tracking_config.js](./src/jsenv_tracking_config.js)
|
|
200
|
-
|
|
201
|
-
_trackingConfig_ keys are group names that will appear in the generated comment.
|
|
202
|
-
_trackingConfig_ values are objects associating a pattern to a value.
|
|
203
|
-
|
|
204
|
-
For example you can create two groups named _"critical files"_ and _"remaining files"_ like this:
|
|
205
|
-
|
|
206
|
-
```js
|
|
207
|
-
import { generateFileSizeReport } from "@jsenv/file-size-impact";
|
|
208
|
-
|
|
209
|
-
await generateFileSizeReport({
|
|
210
194
|
trackingConfig: {
|
|
211
195
|
"critical files": {
|
|
212
196
|
"./dist/main.js": true,
|
|
@@ -215,246 +199,35 @@ await generateFileSizeReport({
|
|
|
215
199
|
"remaining files": {
|
|
216
200
|
"./dist/**/*.js": true,
|
|
217
201
|
"./dist/**/*.css": true,
|
|
218
|
-
"./dist/main.js": false,
|
|
219
|
-
"./dist/main.css": false,
|
|
202
|
+
"./dist/main.js": false, // Exclude files already in "critical files"
|
|
203
|
+
"./dist/main.css": false, // Exclude files already in "critical files"
|
|
220
204
|
},
|
|
221
205
|
},
|
|
222
|
-
});
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-

|
|
226
|
-
|
|
227
|
-
## transformations
|
|
228
|
-
|
|
229
|
-
_transformations_ parameter is an object used to transform files content before computing their size. This parameter is optional with a default tracking file size without transformation called _raw_.
|
|
230
|
-
|
|
231
|
-
You can use this parameter to track file size after gzip compression.
|
|
232
|
-
|
|
233
|
-
```js
|
|
234
|
-
import {
|
|
235
|
-
generateFileSizeReport,
|
|
236
|
-
raw,
|
|
237
|
-
gzip,
|
|
238
|
-
brotli,
|
|
239
|
-
} from "@jsenv/file-size-impact";
|
|
240
|
-
|
|
241
|
-
await generateFileSizeReport({
|
|
242
206
|
transformations: { raw, gzip, brotli },
|
|
243
207
|
});
|
|
244
208
|
```
|
|
245
209
|
|
|
246
|
-
|
|
210
|
+
#### Options
|
|
247
211
|
|
|
248
|
-
|
|
212
|
+
- **rootDirectoryUrl**: Project root directory (required)
|
|
213
|
+
- **trackingConfig**: File groups to track (optional)
|
|
214
|
+
- **transformations**: Size transformations, like compression (optional)
|
|
215
|
+
- **manifestConfig**: Configuration for files with dynamic names (optional)
|
|
249
216
|
|
|
250
|
-
|
|
217
|
+
### reportFileSizeImpactInGitHubPullRequest
|
|
251
218
|
|
|
252
|
-
|
|
253
|
-
import { generateFileSizeReport, raw, gzip } from "@jsenv/file-size-impact";
|
|
254
|
-
|
|
255
|
-
await generateFileSizeReport({
|
|
256
|
-
transformations: {
|
|
257
|
-
raw,
|
|
258
|
-
gzip7: (buffer) => gzip(buffer, { level: 7 }),
|
|
259
|
-
gzip9: (buffer) => gzip(buffer, { level: 9 }),
|
|
260
|
-
},
|
|
261
|
-
});
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
Finally _transformations_ can be used to add custom _transformations_.
|
|
265
|
-
|
|
266
|
-
```js
|
|
267
|
-
import {
|
|
268
|
-
generateFileSizeReport,
|
|
269
|
-
raw,
|
|
270
|
-
gzip,
|
|
271
|
-
brotli,
|
|
272
|
-
} from "@jsenv/file-size-impact";
|
|
273
|
-
|
|
274
|
-
await generateFileSizeReport({
|
|
275
|
-
transformations: {
|
|
276
|
-
raw,
|
|
277
|
-
trim: (buffer) => String(buffer).trim(),
|
|
278
|
-
},
|
|
279
|
-
});
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
## manifestConfig
|
|
283
|
-
|
|
284
|
-
_manifestConfig_ parameter is an object used to configure the location of an optional manifest file. It is used to compare [files with dynamic names](#File-with-dynamic-names). This parameter is optional with a default considering `"dist/**/manifest.json"` as manifest files.
|
|
285
|
-
|
|
286
|
-
This parameter reuses the shape of [trackingConfig](#trackingConfig) (associating pattern + value).
|
|
287
|
-
|
|
288
|
-
```js
|
|
289
|
-
import { reportFileSizeImpactInGitHubPullRequest } from "@jsenv/file-size-impact";
|
|
290
|
-
|
|
291
|
-
await reportFileSizeImpactInGitHubPullRequest({
|
|
292
|
-
manifestConfig: {
|
|
293
|
-
"./dist/**/manifest.json": true,
|
|
294
|
-
},
|
|
295
|
-
});
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
You can disable manifest files handling by passing `null`.
|
|
219
|
+
Analyzes PR impact and posts a comment with results:
|
|
299
220
|
|
|
300
221
|
```js
|
|
301
222
|
import { reportFileSizeImpactInGitHubPullRequest } from "@jsenv/file-size-impact";
|
|
302
223
|
|
|
303
|
-
await reportFileSizeImpactInGitHubPullRequest({
|
|
304
|
-
manifestConfig: {
|
|
305
|
-
"./dist/**/manifest.json": null,
|
|
306
|
-
},
|
|
307
|
-
});
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
In that case _manifest.json_ will be handled as a regular file.
|
|
311
|
-
|
|
312
|
-
# reportFileSizeImpactInGitHubPullRequest
|
|
313
|
-
|
|
314
|
-
_reportFileSizeImpactInGitHubPullRequest_ is an async function that will analyse a pull request file size impact and post a comment with the result of this analysis.
|
|
315
|
-
|
|
316
|
-
```js
|
|
317
|
-
import {
|
|
318
|
-
reportFileSizeImpactInGitHubPullRequest,
|
|
319
|
-
raw,
|
|
320
|
-
} from "@jsenv/file-size-impact";
|
|
321
|
-
|
|
322
224
|
await reportFileSizeImpactInGitHubPullRequest({
|
|
323
225
|
logLevel: "info",
|
|
324
|
-
|
|
325
226
|
rootDirectoryUrl: "file:///directory",
|
|
326
227
|
githubToken: "xxx",
|
|
327
228
|
repositoryOwner: "jsenv",
|
|
328
229
|
repositoryName: "file-size-impact",
|
|
329
230
|
pullRequestNumber: 10,
|
|
330
|
-
|
|
331
231
|
installCommand: "npm install",
|
|
332
232
|
buildCommand: "npm run build",
|
|
333
|
-
fileSizeReportUrl: new URL("./file_size.mjs#fileSizeReport", import.meta.url),
|
|
334
|
-
filesOrdering: "size_impact",
|
|
335
|
-
});
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
## logLevel
|
|
339
|
-
|
|
340
|
-
_logLevel_ parameter controls verbosity of logs during the function execution. This parameter is optional with a default value of `"info"`.
|
|
341
|
-
|
|
342
|
-
You likely don't need to modify this parameter except to get verbose logs using `"debug"`. The list of available values for _logLevel_ can be found on [@jsenv/logger documentation](https://github.com/jsenv/jsenv-logger#loglevel).
|
|
343
|
-
|
|
344
|
-
## rootDirectoryUrl
|
|
345
|
-
|
|
346
|
-
_rootDirectoryUrl_ parameter is a string leading to your project root directory. This parameter is **required**.
|
|
347
|
-
|
|
348
|
-
## installCommand
|
|
349
|
-
|
|
350
|
-
_installCommand_ parameter is a string representing the command to run in order to install things just after a switching to a git branch. This parameter is optional with a default value of `"npm install"`. You can pass `null` if you don't need to run an install command to run your project.
|
|
351
|
-
|
|
352
|
-
## buildCommand
|
|
353
|
-
|
|
354
|
-
_buildCommand_ parameter is a string representing the command to run in order to generate files. This parameter is optional with a default value of `"npm run-script build"`. You can pass `null` if you don't need to run a build command before computing file sizes.
|
|
355
|
-
|
|
356
|
-
## fileSizeReportUrl
|
|
357
|
-
|
|
358
|
-
_fileSizeReportUrl_ is a string or an url parameter representing an url leading a module file. This file must export a fileSizeReport produced by _generateFileSizeReport_.
|
|
359
|
-
|
|
360
|
-
## filesOrdering
|
|
361
|
-
|
|
362
|
-
_filesOrdering_ parameter is a string used to decide the order of the files displayed in the comment. This parameter is optional with a default value of `"size_impact"`.
|
|
363
|
-
|
|
364
|
-
| filesOrdering | Description |
|
|
365
|
-
| ------------- | -------------------------------------------------- |
|
|
366
|
-
| "size_impact" | Files are ordered by size impact |
|
|
367
|
-
| "filesystem" | Files are ordered as they appear on the filesystem |
|
|
368
|
-
|
|
369
|
-
## runLink
|
|
370
|
-
|
|
371
|
-
_runLink_ parameter allow to put a link to the workflow run in the generated comment body. It is used to indicates where file size impact was runned.
|
|
372
|
-
|
|
373
|
-

|
|
374
|
-
|
|
375
|
-
This parameter is returned by [readGitHubWorkflowEnv](#readGitHubWorkflowEnv) meaning it comes for free inside a GitHub workflow.
|
|
376
|
-
|
|
377
|
-
Inside an other workflow, you can pass your own _runLink_. As in the example below where it is assumed that script is runned by jenkins.
|
|
378
|
-
|
|
379
|
-
```js
|
|
380
|
-
import { reportFileSizeImpactInGitHubPullRequest } from "@jsenv/file-size-impact";
|
|
381
|
-
|
|
382
|
-
await reportFileSizeImpactInGitHubPullRequest({
|
|
383
|
-
runLink: {
|
|
384
|
-
url: process.env.BUILD_URL,
|
|
385
|
-
text: `${process.env.JOB_NAME}#${process.env.BUILD_ID}`,
|
|
386
|
-
},
|
|
387
|
-
});
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
# commitInGeneratedByInfo
|
|
391
|
-
|
|
392
|
-
_commitInGeneratedByInfo_ parameter is a boolean controlling if a link to the commit where size impact was performed appears in the comment. This parameter is optional and enabled by default.
|
|
393
|
-
|
|
394
|
-

|
|
395
|
-
|
|
396
|
-
# readGitHubWorkflowEnv
|
|
397
|
-
|
|
398
|
-
_readGitHubWorkflowEnv_ is a function meant to be runned inside a GitHub workflow. It returns an object meant to be forwarded to [reportFileSizeImpactInGitHubPullRequest](#reportFileSizeImpactInGitHubPullRequest).
|
|
399
|
-
|
|
400
|
-
```js
|
|
401
|
-
import {
|
|
402
|
-
reportFileSizeImpactInGitHubPullRequest,
|
|
403
|
-
readGitHubWorkflowEnv,
|
|
404
|
-
} from "@jsenv/file-size-impact";
|
|
405
|
-
|
|
406
|
-
const gitHubWorkflowEnv = readGitHubWorkflowEnv();
|
|
407
|
-
|
|
408
|
-
await reportFileSizeImpactInGitHubPullRequest({
|
|
409
|
-
...gitHubWorkflowEnv,
|
|
410
|
-
});
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
_gitHubWorkflowEnv_ object looks like this:
|
|
414
|
-
|
|
415
|
-
```js
|
|
416
|
-
const gitHubWorkflowEnv = {
|
|
417
|
-
rootDirectoryUrl: "/home/runner/work/repository-name",
|
|
418
|
-
githubToken: "xxx",
|
|
419
|
-
repositoryOwner: "jsenv",
|
|
420
|
-
repositoryName: "repository-name",
|
|
421
|
-
pullRequestNumber: 10,
|
|
422
|
-
runLink: {
|
|
423
|
-
url: "https://github.com/jsenv/repository-name/actions/runs/34",
|
|
424
|
-
text: "workflow-name#34",
|
|
425
|
-
},
|
|
426
|
-
};
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
# File with dynamic names
|
|
430
|
-
|
|
431
|
-
Manifest file allows to compare file with dynamic names. The content of a manifest file looks like this:
|
|
432
|
-
|
|
433
|
-
```json
|
|
434
|
-
{
|
|
435
|
-
"dist/file.js": "dist/file.4798774987w97er984798.js"
|
|
436
|
-
}
|
|
437
233
|
```
|
|
438
|
-
|
|
439
|
-
These files are generated by build tools. For example by [webpack-manifest-plugin](https://github.com/danethurber/webpack-manifest-plugin) or [rollup-plugin-output-manifest](https://github.com/shuizhongyueming/rollup-plugin-output-manifest/tree/master/packages/main).
|
|
440
|
-
|
|
441
|
-
Read more in [manifestConfig](#manifestConfig) parameter
|
|
442
|
-
|
|
443
|
-
# See also
|
|
444
|
-
|
|
445
|
-
- [@jsenv/performance-impact](../performance-impact): Monitor pull requests impacts but on performance metrics
|
|
446
|
-
- [@jsenv/lighthouse-impact](../lighthouse-impact): Monitor pull requests impacts but on lighthouse score
|
|
447
|
-
|
|
448
|
-
# Note about GitHub workflow paths
|
|
449
|
-
|
|
450
|
-
It would be more efficient to enable size impact workflow only if certain file changes (the one that could impact dist/ files). It could be done with `on` condition in a workflow.yml.
|
|
451
|
-
|
|
452
|
-
```yml
|
|
453
|
-
on:
|
|
454
|
-
pull_request:
|
|
455
|
-
paths:
|
|
456
|
-
- "index.js"
|
|
457
|
-
- "src/**"
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
But in practice humans will wonder why the workflow did not run and think something is wrong.
|
|
@@ -105,7 +105,7 @@ export const reportFileSizeImpactInGitHubPullRequest = async ({
|
|
|
105
105
|
});
|
|
106
106
|
},
|
|
107
107
|
generatedByLink: {
|
|
108
|
-
url: "https://github.com/jsenv/core/tree/main/packages/
|
|
108
|
+
url: "https://github.com/jsenv/core/tree/main/packages/tooling/file-size-impact",
|
|
109
109
|
text: "@jsenv/file-size-impact",
|
|
110
110
|
},
|
|
111
111
|
runLink,
|