@jsenv/file-size-impact 10.0.1 → 11.0.0
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 +16 -14
- package/readme.md +40 -57
- package/src/getFileSizeReport.js +1 -1
- package/src/internal/applyTrackingConfig.js +1 -1
- package/src/internal/compareTwoFileSizeReports.js +2 -2
- package/src/internal/formatComment.js +105 -224
- package/src/internal/jsenvCommentParameters.js +73 -69
- package/src/internal/orderBySizeImpact.js +3 -14
- package/src/internal/renderImpactTable.js +158 -155
- package/src/internal/size_map.js +49 -0
- package/src/internal/worker_generating_file_size_report.js +17 -0
- package/src/logFileSizeReport.js +1 -1
- package/src/reportFileSizeImpact.js +30 -25
- package/src/internal/getSizeMaps.js +0 -43
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/file-size-impact",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "Add files size impact into pull requests",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -26,38 +26,40 @@
|
|
|
26
26
|
"/index.js"
|
|
27
27
|
],
|
|
28
28
|
"scripts": {
|
|
29
|
-
"eslint-check": "node ./node_modules/eslint/bin/eslint.js .",
|
|
29
|
+
"eslint-check": "node ./node_modules/eslint/bin/eslint.js . --ext=.js,.mjs",
|
|
30
30
|
"generate-importmap": "node ./script/importmap/generate_importmap.mjs",
|
|
31
|
-
"
|
|
32
|
-
"generate-comment-snapshot": "node ./test/comment/
|
|
31
|
+
"measure-file-sizes": "node ./script/file_size/generate_file_size_report.mjs --local",
|
|
32
|
+
"generate-comment-snapshot-file": "node ./test/comment/generate_comment_snapshot_file.mjs",
|
|
33
33
|
"test": "node ./script/test/test.mjs",
|
|
34
34
|
"test-with-coverage": "npm run test -- --coverage",
|
|
35
35
|
"prettier-format": "node ./script/prettier/prettier_format.mjs",
|
|
36
36
|
"prettier-format-stage": "npm run prettier-format -- --staged",
|
|
37
37
|
"prettier-check": "npm run prettier-format -- --dry-run",
|
|
38
|
-
"upload-coverage": "node ./script/test/upload_coverage.mjs",
|
|
39
38
|
"prepublishOnly": "node ./script/publish/remove_postinstall.mjs",
|
|
40
39
|
"postpublish": "node ./script/publish/restore_postinstall.mjs"
|
|
41
40
|
},
|
|
42
41
|
"dependencies": {
|
|
43
|
-
"@jsenv/github-pull-request-impact": "1.6.
|
|
42
|
+
"@jsenv/github-pull-request-impact": "1.6.4",
|
|
44
43
|
"@jsenv/logger": "4.0.1",
|
|
45
|
-
"@jsenv/
|
|
44
|
+
"@jsenv/filesystem": "2.2.0",
|
|
46
45
|
"pretty-bytes": "5.6.0"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
|
-
"@
|
|
48
|
+
"@babel/core": "7.15.8",
|
|
49
|
+
"@babel/eslint-parser": "7.15.8",
|
|
50
|
+
"@jsenv/assert": "2.3.2",
|
|
50
51
|
"@jsenv/cancellation": "3.0.0",
|
|
51
52
|
"@jsenv/codecov-upload": "3.5.0",
|
|
52
|
-
"@jsenv/core": "
|
|
53
|
-
"@jsenv/eslint-config": "
|
|
53
|
+
"@jsenv/core": "23.0.2",
|
|
54
|
+
"@jsenv/eslint-config": "16.0.8",
|
|
55
|
+
"@jsenv/filesystem": "2.2.0",
|
|
54
56
|
"@jsenv/github-release-package": "1.2.3",
|
|
55
|
-
"@jsenv/importmap-eslint-resolver": "5.1.
|
|
56
|
-
"@jsenv/importmap-node-module": "
|
|
57
|
+
"@jsenv/importmap-eslint-resolver": "5.1.2",
|
|
58
|
+
"@jsenv/importmap-node-module": "2.4.1",
|
|
57
59
|
"@jsenv/package-publish": "1.6.2",
|
|
58
60
|
"@jsenv/prettier-check-project": "5.6.1",
|
|
59
61
|
"eslint": "7.32.0",
|
|
60
|
-
"eslint-plugin-import": "2.
|
|
61
|
-
"prettier": "2.
|
|
62
|
+
"eslint-plugin-import": "2.25.2",
|
|
63
|
+
"prettier": "2.4.1"
|
|
62
64
|
}
|
|
63
65
|
}
|
package/readme.md
CHANGED
|
@@ -1,34 +1,16 @@
|
|
|
1
|
-
# File size impact
|
|
2
|
-
|
|
3
|
-
Report pull request impacts on specific files size.
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/@jsenv/file-size-impact)
|
|
6
|
-
[](https://github.com/jsenv/file-size-impact/actions?workflow=main)
|
|
7
|
-
[](https://codecov.io/gh/jsenv/file-size-impact)
|
|
8
|
-
|
|
9
|
-
# Presentation
|
|
1
|
+
# File size impact [](https://www.npmjs.com/package/@jsenv/file-size-impact) [](https://github.com/jsenv/file-size-impact/actions?workflow=main) [](https://codecov.io/gh/jsenv/file-size-impact)
|
|
10
2
|
|
|
11
3
|
`@jsenv/file-size-impact` analyses a pull request impact on specific files size. This analysis is posted in a comment of the pull request on GitHub.
|
|
12
4
|
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
- Can be added to any
|
|
5
|
+
- Helps you to catch size impacts before merging pull requests
|
|
6
|
+
- Can be configured to track compressed file size
|
|
7
|
+
- Create group of files to create meaningful reports
|
|
8
|
+
- Can be added to any automated process (GitHub workflow, Jenkins, ...)
|
|
17
9
|
|
|
18
10
|
# Pull request comment
|
|
19
11
|
|
|
20
12
|
This section shows pull request comment and how to read _group summary_ and _size impact_ sections.
|
|
21
13
|
|
|
22
|
-
_Screenshot of a pull request comment_
|
|
23
|
-
|
|
24
|
-

|
|
25
|
-
|
|
26
|
-
_Screenshot when comment is expanded_
|
|
27
|
-
|
|
28
|
-

|
|
29
|
-
|
|
30
|
-
## Pull request comment legend
|
|
31
|
-
|
|
32
14
|

|
|
33
15
|
|
|
34
16
|
"_critical files (1/2)_" is a group summary, it translates into the following sentence:
|
|
@@ -65,9 +47,11 @@ export const generateFileSizeReport = async () => {
|
|
|
65
47
|
}
|
|
66
48
|
```
|
|
67
49
|
|
|
68
|
-
At this stage, you could generate a file size report on your machine. For an example, see
|
|
50
|
+
At this stage, you could generate a file size report on your machine. For an example, see [script/file_size/generate_file_size_report.mjs#L14](./script/file_size/generate_file_size_report.mjs#L14).
|
|
51
|
+
|
|
52
|
+
Now it's time to configure a workflow to compare file size reports before and after merging a pull request.
|
|
69
53
|
|
|
70
|
-
|
|
54
|
+
## GitHub workflow
|
|
71
55
|
|
|
72
56
|
_.github/workflows/file_size_impact.yml_
|
|
73
57
|
|
|
@@ -116,24 +100,24 @@ _report_file_size_impact.mjs_
|
|
|
116
100
|
|
|
117
101
|
import { reportFileSizeImpact, readGitHubWorkflowEnv } from "@jsenv/file-size-impact"
|
|
118
102
|
|
|
119
|
-
reportFileSizeImpact({
|
|
103
|
+
await reportFileSizeImpact({
|
|
120
104
|
...readGitHubWorkflowEnv(),
|
|
121
105
|
buildCommand: "npm run dist",
|
|
122
|
-
|
|
106
|
+
fileSizeModulePath: "./generate_file_size_report.mjs",
|
|
123
107
|
})
|
|
124
108
|
```
|
|
125
109
|
|
|
126
|
-
## Other
|
|
110
|
+
## Other tools
|
|
127
111
|
|
|
128
|
-
|
|
112
|
+
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:
|
|
129
113
|
|
|
130
114
|
1. Replicate _file_size_impact.yml_
|
|
131
115
|
2. Adjust _report_file_size_impact.mjs_
|
|
132
|
-
3. Create a GitHub token
|
|
116
|
+
3. Create a GitHub token (required to post comment on GitHub)
|
|
133
117
|
|
|
134
118
|
### 1. Replicate _file_size_impact.yml_
|
|
135
119
|
|
|
136
|
-
Your workflow must reproduce the state where your git repository has been cloned and you are currently on the pull request branch.
|
|
120
|
+
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.
|
|
137
121
|
|
|
138
122
|
```console
|
|
139
123
|
git init
|
|
@@ -165,7 +149,20 @@ reportFileSizeImpact({
|
|
|
165
149
|
|
|
166
150
|
### 3. Create a GitHub token
|
|
167
151
|
|
|
168
|
-
|
|
152
|
+
The GitHub token is required to be able to post a commment in the pull request. You need to create a GitHub token with `repo` scope at https://github.com/settings/tokens/new. Finally you need to setup this environment variable. The exact way to do this is specific to the tools your are using.
|
|
153
|
+
|
|
154
|
+
# How it works
|
|
155
|
+
|
|
156
|
+
In order to analyse the impact of a pull request on file size the following steps are executed:
|
|
157
|
+
|
|
158
|
+
1. Checkout pull request base branch
|
|
159
|
+
2. Execute an install command (_npm install_ by default)
|
|
160
|
+
3. Get a file size report (dynamic import of a js module exporting `generateFileSizeReport`)
|
|
161
|
+
4. Merge pull request into its base
|
|
162
|
+
5. Execute command to generate files again
|
|
163
|
+
6. Get a second file size report
|
|
164
|
+
7. Analyse differences between the two file size reports
|
|
165
|
+
8. Post or update comment in the pull request
|
|
169
166
|
|
|
170
167
|
# getFileSizeReport
|
|
171
168
|
|
|
@@ -197,7 +194,7 @@ For example you can create two groups named _"critical files"_ and _"remaining f
|
|
|
197
194
|
```js
|
|
198
195
|
import { getFileSizeReport } from "@jsenv/file-size-impact"
|
|
199
196
|
|
|
200
|
-
getFileSizeReport({
|
|
197
|
+
await getFileSizeReport({
|
|
201
198
|
trackingConfig: {
|
|
202
199
|
"critical files": {
|
|
203
200
|
"./dist/main.js": true,
|
|
@@ -224,7 +221,7 @@ You can use this parameter to track file size after gzip compression.
|
|
|
224
221
|
```js
|
|
225
222
|
import { getFileSizeReport, raw, gzip, brotli } from "@jsenv/file-size-impact"
|
|
226
223
|
|
|
227
|
-
getFileSizeReport({
|
|
224
|
+
await getFileSizeReport({
|
|
228
225
|
transformations: { raw, gzip, brotli },
|
|
229
226
|
})
|
|
230
227
|
```
|
|
@@ -238,7 +235,7 @@ It's also possible to control compression level.
|
|
|
238
235
|
```js
|
|
239
236
|
import { getFileSizeReport, raw, gzip } from "@jsenv/file-size-impact"
|
|
240
237
|
|
|
241
|
-
getFileSizeReport({
|
|
238
|
+
await getFileSizeReport({
|
|
242
239
|
transformations: {
|
|
243
240
|
raw,
|
|
244
241
|
gzip7: (buffer) => gzip(buffer, { level: 7 }),
|
|
@@ -252,7 +249,7 @@ Finally _transformations_ can be used to add custom _transformations_.
|
|
|
252
249
|
```js
|
|
253
250
|
import { getFileSizeReport, raw, gzip, brotli } from "@jsenv/file-size-impact"
|
|
254
251
|
|
|
255
|
-
getFileSizeReport({
|
|
252
|
+
await getFileSizeReport({
|
|
256
253
|
transformations: {
|
|
257
254
|
raw,
|
|
258
255
|
trim: (buffer) => String(buffer).trim(),
|
|
@@ -269,7 +266,7 @@ This parameter reuses the shape of [trackingConfig](#trackingConfig) (associatin
|
|
|
269
266
|
```js
|
|
270
267
|
import { reportFileSizeImpact } from "@jsenv/file-size-impact"
|
|
271
268
|
|
|
272
|
-
reportFileSizeImpact({
|
|
269
|
+
await reportFileSizeImpact({
|
|
273
270
|
manifestConfig: {
|
|
274
271
|
"./dist/**/manifest.json": true,
|
|
275
272
|
},
|
|
@@ -281,7 +278,7 @@ You can disable manifest files handling by passing `null`.
|
|
|
281
278
|
```js
|
|
282
279
|
import { reportFileSizeImpact } from "@jsenv/file-size-impact"
|
|
283
280
|
|
|
284
|
-
reportFileSizeImpact({
|
|
281
|
+
await reportFileSizeImpact({
|
|
285
282
|
manifestConfig: {
|
|
286
283
|
"./dist/**/manifest.json": null,
|
|
287
284
|
},
|
|
@@ -308,7 +305,7 @@ await reportFileSizeImpact({
|
|
|
308
305
|
|
|
309
306
|
installCommand: "npm install",
|
|
310
307
|
buildCommand: "npm run build",
|
|
311
|
-
|
|
308
|
+
fileSizeModulePath: "./generate_file_size_report.mjs",
|
|
312
309
|
|
|
313
310
|
filesOrdering: "size_impact",
|
|
314
311
|
})
|
|
@@ -332,9 +329,9 @@ _installCommand_ parameter is a string representing the command to run in order
|
|
|
332
329
|
|
|
333
330
|
_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.
|
|
334
331
|
|
|
335
|
-
##
|
|
332
|
+
## fileSizeModulePath
|
|
336
333
|
|
|
337
|
-
|
|
334
|
+
_fileSizeModulePath_ is a string parameter representing an url relative to [projectDirectoryUrl](#projectDirectoryUrl) leading a module file. This file must contain a _generateFileSizeReport_ export.
|
|
338
335
|
|
|
339
336
|
## filesOrdering
|
|
340
337
|
|
|
@@ -358,7 +355,7 @@ Inside an other workflow, you can pass your own _runLink_. As in the example bel
|
|
|
358
355
|
```js
|
|
359
356
|
import { reportFileSizeImpact } from "@jsenv/file-size-impact"
|
|
360
357
|
|
|
361
|
-
reportFileSizeImpact({
|
|
358
|
+
await reportFileSizeImpact({
|
|
362
359
|
runLink: {
|
|
363
360
|
url: process.env.BUILD_URL,
|
|
364
361
|
text: `${process.env.JOB_NAME}#${process.env.BUILD_ID}`,
|
|
@@ -375,7 +372,7 @@ import { reportFileSizeImpact, readGitHubWorkflowEnv } from "@jsenv/file-size-im
|
|
|
375
372
|
|
|
376
373
|
const gitHubWorkflowEnv = readGitHubWorkflowEnv()
|
|
377
374
|
|
|
378
|
-
reportFileSizeImpact({
|
|
375
|
+
await reportFileSizeImpact({
|
|
379
376
|
...gitHubWorkflowEnv,
|
|
380
377
|
})
|
|
381
378
|
```
|
|
@@ -410,20 +407,6 @@ These files are generated by build tools. For example by [webpack-manifest-plugi
|
|
|
410
407
|
|
|
411
408
|
Read more in [manifestConfig](#manifestConfig) parameter
|
|
412
409
|
|
|
413
|
-
# How it works
|
|
414
|
-
|
|
415
|
-
In order to analyse the impact of a pull request on file size the following steps are executed:
|
|
416
|
-
|
|
417
|
-
1. Checkout pull request base branch
|
|
418
|
-
2. Execute an install command (_npm install_ by default)
|
|
419
|
-
3. Execute a build command to generate files (_npm run-script build_ by default)
|
|
420
|
-
4. Take a snapshot of generated files
|
|
421
|
-
5. Merge pull request into its base
|
|
422
|
-
6. Execute command to generate files again
|
|
423
|
-
7. Take a second snapshot of generated files
|
|
424
|
-
8. Analyse differences between the two snapshots
|
|
425
|
-
9. Post or update comment in the pull request
|
|
426
|
-
|
|
427
410
|
# See also
|
|
428
411
|
|
|
429
412
|
- [@jsenv/performance-impact](https://github.com/jsenv/performance-impact): Monitor pull requests impacts but on performance metrics
|
package/src/getFileSizeReport.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { urlToFileSystemPath, collectDirectoryMatchReport } from "@jsenv/
|
|
1
|
+
import { urlToFileSystemPath, collectDirectoryMatchReport } from "@jsenv/filesystem"
|
|
2
2
|
import { createCancellationToken } from "@jsenv/cancellation"
|
|
3
3
|
|
|
4
4
|
export const applyTrackingConfig = async (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolveUrl, comparePathnames, urlToRelativeUrl } from "@jsenv/
|
|
1
|
+
import { resolveUrl, comparePathnames, urlToRelativeUrl } from "@jsenv/filesystem"
|
|
2
2
|
|
|
3
3
|
export const compareTwoFileSizeReports = ({
|
|
4
4
|
afterMergeFileSizeReport,
|
|
@@ -49,7 +49,7 @@ const compareTwoGroups = (beforeMergeGroup, afterMergeGroup) => {
|
|
|
49
49
|
relativeUrl: beforeMergeRelativeUrl,
|
|
50
50
|
manifestKey:
|
|
51
51
|
manifestKeyFromRelativeUrl(beforeMergeRelativeUrl, beforeMergeMappings) || null,
|
|
52
|
-
...beforeMergeFileMap[
|
|
52
|
+
...beforeMergeFileMap[beforeMergeRelativeUrl],
|
|
53
53
|
},
|
|
54
54
|
afterMerge: {
|
|
55
55
|
relativeUrl: afterMergeRelativeUrl,
|