@jsenv/file-size-impact 12.1.11 → 12.2.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 +1 -1
- package/readme.md +14 -7
- package/src/internal/jsenvCommentParameters.js +1 -1
- package/src/reportFileSizeImpact.js +19 -15
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -28,7 +28,7 @@ The first thing you need is a script capable to generate a file size report.
|
|
|
28
28
|
npm install --save-dev @jsenv/file-size-impact
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
_file_size.mjs_
|
|
32
32
|
|
|
33
33
|
```js
|
|
34
34
|
import { generateFileSizeReport } from "@jsenv/file-size-impact"
|
|
@@ -48,7 +48,7 @@ export const fileSizeReport = await generateFileSizeReport({
|
|
|
48
48
|
At this stage, you could generate a file size report on your machine with the following command.
|
|
49
49
|
|
|
50
50
|
```console
|
|
51
|
-
node ./
|
|
51
|
+
node ./_file_size.mjs --log
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
Now it's time to configure a workflow to compare file size reports before and after merging a pull request.
|
|
@@ -85,7 +85,7 @@ jobs:
|
|
|
85
85
|
- name: Setup npm
|
|
86
86
|
run: npm install
|
|
87
87
|
- name: Report file size impact
|
|
88
|
-
run: node ./
|
|
88
|
+
run: node ./file_size.mjs
|
|
89
89
|
env:
|
|
90
90
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
91
91
|
```
|
|
@@ -108,11 +108,16 @@ import {
|
|
|
108
108
|
await reportFileSizeImpact({
|
|
109
109
|
...readGitHubWorkflowEnv(),
|
|
110
110
|
buildCommand: "npm run dist",
|
|
111
|
-
fileSizeReportModulePath:
|
|
111
|
+
fileSizeReportModulePath: new URL(
|
|
112
|
+
"./file_size.mjs#fileSizeReport",
|
|
113
|
+
import.meta.url,
|
|
114
|
+
),
|
|
112
115
|
})
|
|
113
116
|
```
|
|
114
117
|
|
|
115
|
-
|
|
118
|
+
**Notes**:
|
|
119
|
+
|
|
120
|
+
- "#fileSizeReport" is the name of the export from _file_size.mjs_.
|
|
116
121
|
|
|
117
122
|
## Other tools
|
|
118
123
|
|
|
@@ -322,8 +327,10 @@ await reportFileSizeImpact({
|
|
|
322
327
|
|
|
323
328
|
installCommand: "npm install",
|
|
324
329
|
buildCommand: "npm run build",
|
|
325
|
-
fileSizeReportModulePath:
|
|
326
|
-
|
|
330
|
+
fileSizeReportModulePath: new URL(
|
|
331
|
+
"./file_size.mjs#fileSizeReport",
|
|
332
|
+
import.meta.url,
|
|
333
|
+
),
|
|
327
334
|
filesOrdering: "size_impact",
|
|
328
335
|
})
|
|
329
336
|
```
|
|
@@ -96,7 +96,7 @@ export const jsenvFormatEmojiCell = ({ sizeBeforeMerge, sizeAfterMerge }) => {
|
|
|
96
96
|
export const jsenvCommentParameters = {
|
|
97
97
|
filesOrdering: "size_impact",
|
|
98
98
|
maxFilesPerGroup: 600,
|
|
99
|
-
fileRelativeUrlMaxLength:
|
|
99
|
+
fileRelativeUrlMaxLength: 50,
|
|
100
100
|
formatGroupSummary: jsenvFormatGroupSummary,
|
|
101
101
|
formatFileRelativeUrl: jsenvFormatFileRelativeUrl,
|
|
102
102
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { commentGitHubPullRequestImpact } from "@jsenv/github-pull-request-impact"
|
|
2
|
-
import { assertAndNormalizeDirectoryUrl
|
|
2
|
+
import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
|
|
3
3
|
|
|
4
4
|
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"
|
|
5
5
|
import { formatComment } from "./internal/formatComment.js"
|
|
@@ -36,6 +36,21 @@ export const reportFileSizeImpact = async ({
|
|
|
36
36
|
runLink,
|
|
37
37
|
commitInGeneratedByInfo,
|
|
38
38
|
}) => {
|
|
39
|
+
rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
|
|
40
|
+
let fileSizeReportModuleUrl
|
|
41
|
+
if (fileSizeReportModulePath === "string") {
|
|
42
|
+
fileSizeReportModuleUrl = new URL(
|
|
43
|
+
fileSizeReportModulePath,
|
|
44
|
+
rootDirectoryUrl,
|
|
45
|
+
).href
|
|
46
|
+
} else if (fileSizeReportModulePath instanceof URL) {
|
|
47
|
+
fileSizeReportModuleUrl = fileSizeReportModulePath.href
|
|
48
|
+
} else {
|
|
49
|
+
throw new TypeError(
|
|
50
|
+
`fileSizeReportModulePath must be a string or an url but received ${fileSizeReportModulePath}`,
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
39
54
|
if (installCommand === null) {
|
|
40
55
|
// a null installCommand means there is no need to install anything
|
|
41
56
|
} else if (typeof installCommand !== "string") {
|
|
@@ -52,17 +67,6 @@ export const reportFileSizeImpact = async ({
|
|
|
52
67
|
)
|
|
53
68
|
}
|
|
54
69
|
|
|
55
|
-
if (typeof fileSizeReportModulePath !== "string") {
|
|
56
|
-
throw new TypeError(
|
|
57
|
-
`fileSizeReportModulePath must be a string but received ${fileSizeReportModulePath}`,
|
|
58
|
-
)
|
|
59
|
-
}
|
|
60
|
-
rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
|
|
61
|
-
const fileSizeReportModuleUrl = resolveUrl(
|
|
62
|
-
fileSizeReportModulePath,
|
|
63
|
-
rootDirectoryUrl,
|
|
64
|
-
)
|
|
65
|
-
|
|
66
70
|
return commentGitHubPullRequestImpact({
|
|
67
71
|
logLevel,
|
|
68
72
|
commandLogs,
|
|
@@ -75,9 +79,9 @@ export const reportFileSizeImpact = async ({
|
|
|
75
79
|
repositoryName,
|
|
76
80
|
pullRequestNumber,
|
|
77
81
|
|
|
78
|
-
collectInfo: async ({
|
|
79
|
-
if (installCommand) await
|
|
80
|
-
if (buildCommand) await
|
|
82
|
+
collectInfo: async ({ execCommandInRootDirectory }) => {
|
|
83
|
+
if (installCommand) await execCommandInRootDirectory(installCommand)
|
|
84
|
+
if (buildCommand) await execCommandInRootDirectory(buildCommand)
|
|
81
85
|
const fileSizeReport = await importOneExportFromFile(
|
|
82
86
|
fileSizeReportModuleUrl,
|
|
83
87
|
)
|