@jsenv/file-size-impact 12.1.9 → 12.1.12
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 +4 -15
- package/readme.md +8 -8
- package/src/generateFileSizeReport.js +8 -12
- package/src/internal/applyTrackingConfig.js +5 -5
- package/src/internal/formatSize.js +1 -8
- package/src/internal/format_percentage.js +31 -0
- package/src/internal/jsenvCommentParameters.js +2 -8
- package/src/reportFileSizeImpact.js +8 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/file-size-impact",
|
|
3
|
-
"version": "12.1.
|
|
3
|
+
"version": "12.1.12",
|
|
4
4
|
"description": "Add files size impact into pull requests",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
],
|
|
30
30
|
"scripts": {
|
|
31
31
|
"eslint": "npx eslint . --ext=.js,.mjs",
|
|
32
|
-
"importmap": "node ./script/importmap/importmap.mjs",
|
|
33
32
|
"snapshot": "node ./test/comment/generate_comment_snapshot_file.mjs",
|
|
34
33
|
"test": "node ./script/test/test.mjs",
|
|
35
34
|
"test-with-coverage": "npm run test -- --coverage",
|
|
@@ -38,19 +37,9 @@
|
|
|
38
37
|
},
|
|
39
38
|
"dependencies": {
|
|
40
39
|
"@jsenv/dynamic-import-worker": "1.0.1",
|
|
41
|
-
"@jsenv/filesystem": "
|
|
42
|
-
"@jsenv/github-pull-request-impact": "1.6.
|
|
40
|
+
"@jsenv/filesystem": "3.1.0",
|
|
41
|
+
"@jsenv/github-pull-request-impact": "1.6.11",
|
|
43
42
|
"@jsenv/logger": "4.0.1",
|
|
44
|
-
"pretty-bytes": "
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@jsenv/assert": "2.4.1",
|
|
48
|
-
"@jsenv/core": "25.3.0",
|
|
49
|
-
"@jsenv/eslint-config": "16.0.9",
|
|
50
|
-
"@jsenv/importmap-eslint-resolver": "5.2.5",
|
|
51
|
-
"@jsenv/importmap-node-module": "5.1.3",
|
|
52
|
-
"eslint": "8.7.0",
|
|
53
|
-
"eslint-plugin-import": "2.25.4",
|
|
54
|
-
"prettier": "2.5.1"
|
|
43
|
+
"pretty-bytes": "6.0.0"
|
|
55
44
|
}
|
|
56
45
|
}
|
package/readme.md
CHANGED
|
@@ -35,7 +35,7 @@ import { generateFileSizeReport } from "@jsenv/file-size-impact"
|
|
|
35
35
|
|
|
36
36
|
export const fileSizeReport = await generateFileSizeReport({
|
|
37
37
|
log: process.argv.includes("--log"),
|
|
38
|
-
|
|
38
|
+
rootDirectoryUrl: new URL("./", import.meta.url),
|
|
39
39
|
trackingConfig: {
|
|
40
40
|
dist: {
|
|
41
41
|
"./dist/**/*": true,
|
|
@@ -145,7 +145,7 @@ When outside a GitHub workflow, you cannot use _readGitHubWorkflowEnv()_. It mea
|
|
|
145
145
|
|
|
146
146
|
reportFileSizeImpact({
|
|
147
147
|
- ...readGitHubWorkflowEnv(),
|
|
148
|
-
+
|
|
148
|
+
+ rootDirectoryUrl: process.env.TRAVIS_BUILD_DIR,
|
|
149
149
|
+ repositoryOwner: process.env.TRAVIS_REPO_SLUG.split("/")[0],
|
|
150
150
|
+ repositoryName: process.env.TRAVIS_REPO_SLUG.split("/")[1],
|
|
151
151
|
+ pullRequestNumber: process.env.TRAVIS_PULL_REQUEST,
|
|
@@ -179,7 +179,7 @@ _generateFileSizeReport_ is an async function scanning filesystem to compute a l
|
|
|
179
179
|
import { generateFileSizeReport, raw, gzip } from "@jsenv/file-size-impact"
|
|
180
180
|
|
|
181
181
|
const fileSizeReport = await generateFileSizeReport({
|
|
182
|
-
|
|
182
|
+
rootDirectoryUrl: new URL("./", import.meta.url),
|
|
183
183
|
trackingConfig: {
|
|
184
184
|
dist: {
|
|
185
185
|
"./dist/**/*.js": true,
|
|
@@ -314,7 +314,7 @@ import { reportFileSizeImpact, raw } from "@jsenv/file-size-impact"
|
|
|
314
314
|
await reportFileSizeImpact({
|
|
315
315
|
logLevel: "info",
|
|
316
316
|
|
|
317
|
-
|
|
317
|
+
rootDirectoryUrl: "file:///directory",
|
|
318
318
|
githubToken: "xxx",
|
|
319
319
|
repositoryOwner: "jsenv",
|
|
320
320
|
repositoryName: "file-size-impact",
|
|
@@ -334,9 +334,9 @@ _logLevel_ parameter controls verbosity of logs during the function execution. T
|
|
|
334
334
|
|
|
335
335
|
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).
|
|
336
336
|
|
|
337
|
-
##
|
|
337
|
+
## rootDirectoryUrl
|
|
338
338
|
|
|
339
|
-
|
|
339
|
+
_rootDirectoryUrl_ parameter is a string leading to your project root directory. This parameter is **required**.
|
|
340
340
|
|
|
341
341
|
## installCommand
|
|
342
342
|
|
|
@@ -348,7 +348,7 @@ _buildCommand_ parameter is a string representing the command to run in order to
|
|
|
348
348
|
|
|
349
349
|
## fileSizeModulePath
|
|
350
350
|
|
|
351
|
-
_fileSizeModulePath_ is a string parameter representing an url relative to [
|
|
351
|
+
_fileSizeModulePath_ is a string parameter representing an url relative to [rootDirectoryUrl](#rootDirectoryUrl) leading a module file. This file must contain a _generateFileSizeReport_ export.
|
|
352
352
|
|
|
353
353
|
## filesOrdering
|
|
354
354
|
|
|
@@ -407,7 +407,7 @@ _gitHubWorkflowEnv_ object looks like this:
|
|
|
407
407
|
|
|
408
408
|
```js
|
|
409
409
|
const gitHubWorkflowEnv = {
|
|
410
|
-
|
|
410
|
+
rootDirectoryUrl: "/home/runner/work/repository-name",
|
|
411
411
|
githubToken: "xxx",
|
|
412
412
|
repositoryOwner: "jsenv",
|
|
413
413
|
repositoryName: "repository-name",
|
|
@@ -16,14 +16,14 @@ export const generateFileSizeReport = async ({
|
|
|
16
16
|
cancellationToken,
|
|
17
17
|
log,
|
|
18
18
|
logLevel,
|
|
19
|
-
|
|
19
|
+
rootDirectoryUrl,
|
|
20
20
|
trackingConfig = jsenvTrackingConfig,
|
|
21
21
|
manifestConfig = {
|
|
22
22
|
"./dist/**/manifest.json": true,
|
|
23
23
|
},
|
|
24
24
|
transformations = { raw: rawTransform },
|
|
25
25
|
}) => {
|
|
26
|
-
|
|
26
|
+
rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
|
|
27
27
|
|
|
28
28
|
const logger = createLogger({ logLevel })
|
|
29
29
|
|
|
@@ -34,7 +34,7 @@ export const generateFileSizeReport = async ({
|
|
|
34
34
|
|
|
35
35
|
const groupTrackingResults = await applyTrackingConfig(trackingConfig, {
|
|
36
36
|
cancellationToken,
|
|
37
|
-
|
|
37
|
+
rootDirectoryUrl,
|
|
38
38
|
manifestConfig,
|
|
39
39
|
})
|
|
40
40
|
const groupNames = Object.keys(groupTrackingResults)
|
|
@@ -51,7 +51,7 @@ export const generateFileSizeReport = async ({
|
|
|
51
51
|
groupTrackingResult,
|
|
52
52
|
{
|
|
53
53
|
logger,
|
|
54
|
-
|
|
54
|
+
rootDirectoryUrl,
|
|
55
55
|
tracking: trackingConfig[groupName],
|
|
56
56
|
transformations,
|
|
57
57
|
},
|
|
@@ -74,17 +74,14 @@ export const generateFileSizeReport = async ({
|
|
|
74
74
|
|
|
75
75
|
const groupTrackingResultToGroupReport = async (
|
|
76
76
|
groupTrackingResult,
|
|
77
|
-
{ logger,
|
|
77
|
+
{ logger, rootDirectoryUrl, tracking, transformations },
|
|
78
78
|
) => {
|
|
79
79
|
const manifestMap = {}
|
|
80
80
|
const { manifestMetaMap } = groupTrackingResult
|
|
81
81
|
const manifestRelativeUrls = Object.keys(manifestMetaMap)
|
|
82
82
|
await Promise.all(
|
|
83
83
|
manifestRelativeUrls.map(async (manifestRelativeUrl) => {
|
|
84
|
-
const manifestFileUrl = resolveUrl(
|
|
85
|
-
manifestRelativeUrl,
|
|
86
|
-
projectDirectoryUrl,
|
|
87
|
-
)
|
|
84
|
+
const manifestFileUrl = resolveUrl(manifestRelativeUrl, rootDirectoryUrl)
|
|
88
85
|
const manifestFileContent = await readFile(manifestFileUrl, {
|
|
89
86
|
as: "string",
|
|
90
87
|
})
|
|
@@ -117,9 +114,8 @@ const groupTrackingResultToGroupReport = async (
|
|
|
117
114
|
// so we won't benefit from concurrency (it might even make things worse)
|
|
118
115
|
await trackedRelativeUrls.reduce(async (previous, fileRelativeUrl) => {
|
|
119
116
|
await previous
|
|
120
|
-
const fileUrl = resolveUrl(fileRelativeUrl,
|
|
121
|
-
const
|
|
122
|
-
const fileBuffer = Buffer.from(fileContent)
|
|
117
|
+
const fileUrl = resolveUrl(fileRelativeUrl, rootDirectoryUrl)
|
|
118
|
+
const fileBuffer = await readFile(fileUrl, { as: "buffer" })
|
|
123
119
|
const sizeMap = await getFileSizeMap(fileBuffer, {
|
|
124
120
|
transformations,
|
|
125
121
|
logger,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
|
|
6
6
|
export const applyTrackingConfig = async (
|
|
7
7
|
trackingConfig,
|
|
8
|
-
{
|
|
8
|
+
{ rootDirectoryUrl, manifestConfig },
|
|
9
9
|
) => {
|
|
10
10
|
const result = {}
|
|
11
11
|
const trackingNames = Object.keys(trackingConfig)
|
|
@@ -17,7 +17,7 @@ export const applyTrackingConfig = async (
|
|
|
17
17
|
trackingNames.map(async (trackingName) => {
|
|
18
18
|
const tracking = trackingConfig[trackingName]
|
|
19
19
|
const groupTrackingResult = await applyTracking(tracking, {
|
|
20
|
-
|
|
20
|
+
rootDirectoryUrl,
|
|
21
21
|
manifestConfig,
|
|
22
22
|
})
|
|
23
23
|
result[trackingName] = groupTrackingResult
|
|
@@ -28,7 +28,7 @@ export const applyTrackingConfig = async (
|
|
|
28
28
|
|
|
29
29
|
const applyTracking = async (
|
|
30
30
|
tracking,
|
|
31
|
-
{
|
|
31
|
+
{ rootDirectoryUrl, manifestConfig },
|
|
32
32
|
) => {
|
|
33
33
|
const structuredMetaMap = {
|
|
34
34
|
track: tracking,
|
|
@@ -39,12 +39,12 @@ const applyTracking = async (
|
|
|
39
39
|
|
|
40
40
|
try {
|
|
41
41
|
directoryMatchReport = await collectDirectoryMatchReport({
|
|
42
|
-
directoryUrl:
|
|
42
|
+
directoryUrl: rootDirectoryUrl,
|
|
43
43
|
structuredMetaMap,
|
|
44
44
|
predicate: (meta) => Boolean(meta.track) || Boolean(meta.manifest),
|
|
45
45
|
})
|
|
46
46
|
} catch (e) {
|
|
47
|
-
const directoryPath = urlToFileSystemPath(
|
|
47
|
+
const directoryPath = urlToFileSystemPath(rootDirectoryUrl)
|
|
48
48
|
if (e.code === "ENOENT" && e.path === directoryPath) {
|
|
49
49
|
console.warn(`${directoryPath} does not exists`)
|
|
50
50
|
return []
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const require = createRequire(import.meta.url)
|
|
4
|
-
|
|
5
|
-
const bytes = require("pretty-bytes")
|
|
1
|
+
import bytes from "pretty-bytes"
|
|
6
2
|
|
|
7
3
|
export const formatSize = (sizeNumber, { diff = false } = {}) => {
|
|
8
4
|
const sizeNumberAbsolute = Math.abs(sizeNumber)
|
|
9
|
-
|
|
10
5
|
let sizeString = bytes(sizeNumberAbsolute)
|
|
11
|
-
|
|
12
6
|
if (diff) {
|
|
13
7
|
if (sizeNumber < 0) {
|
|
14
8
|
sizeString = `-${sizeString}`
|
|
@@ -16,6 +10,5 @@ export const formatSize = (sizeNumber, { diff = false } = {}) => {
|
|
|
16
10
|
sizeString = `+${sizeString}`
|
|
17
11
|
}
|
|
18
12
|
}
|
|
19
|
-
|
|
20
13
|
return sizeString
|
|
21
14
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const formatPercentage = (number) => {
|
|
2
|
+
const absoluteValue = Math.abs(number)
|
|
3
|
+
const valueRounded = roundNumber(
|
|
4
|
+
absoluteValue,
|
|
5
|
+
determineDecimals(absoluteValue),
|
|
6
|
+
)
|
|
7
|
+
return `${number < 0 ? `-` : "+"}${valueRounded}%`
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const determineDecimals = (number) => {
|
|
11
|
+
if (number < 0.001) {
|
|
12
|
+
return 4
|
|
13
|
+
}
|
|
14
|
+
if (number < 0.01) {
|
|
15
|
+
return 3
|
|
16
|
+
}
|
|
17
|
+
if (number < 0.1) {
|
|
18
|
+
return 2
|
|
19
|
+
}
|
|
20
|
+
if (number < 1) {
|
|
21
|
+
return 1
|
|
22
|
+
}
|
|
23
|
+
return 0
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const roundNumber = (value, maxDecimals) => {
|
|
27
|
+
const expValue = Math.pow(10, maxDecimals)
|
|
28
|
+
const roundedValue = Math.round(expValue * value) / expValue
|
|
29
|
+
const valueAsString = roundedValue.toFixed(maxDecimals)
|
|
30
|
+
return parseFloat(valueAsString)
|
|
31
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { formatPercentage } from "./format_percentage.js"
|
|
1
2
|
import { formatSize } from "./formatSize.js"
|
|
2
3
|
|
|
3
4
|
const jsenvFormatGroupSummary = ({
|
|
@@ -116,13 +117,6 @@ const formatSizeImpactAsPercentage = ({ sizeBeforeMerge, sizeAfterMerge }) => {
|
|
|
116
117
|
? -1
|
|
117
118
|
: sizeDiff / sizeBeforeMerge
|
|
118
119
|
const sizeDiffAsPercentage = sizeDiffRatio * 100
|
|
119
|
-
const sizeDiffAsPercentageFormatted =
|
|
120
|
-
limitDecimals(sizeDiffAsPercentage, 2),
|
|
121
|
-
)}%`
|
|
120
|
+
const sizeDiffAsPercentageFormatted = formatPercentage(sizeDiffAsPercentage)
|
|
122
121
|
return sizeDiffAsPercentageFormatted
|
|
123
122
|
}
|
|
124
|
-
|
|
125
|
-
const limitDecimals = (number, decimalCount = 2) => {
|
|
126
|
-
const multiplier = Math.pow(10, decimalCount)
|
|
127
|
-
return Math.round(number * multiplier) / multiplier
|
|
128
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { commentGitHubPullRequestImpact } from "@jsenv/github-pull-request-impact"
|
|
2
2
|
import { assertAndNormalizeDirectoryUrl, resolveUrl } from "@jsenv/filesystem"
|
|
3
|
-
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"
|
|
4
3
|
|
|
4
|
+
import { importOneExportFromFile } from "@jsenv/dynamic-import-worker"
|
|
5
5
|
import { formatComment } from "./internal/formatComment.js"
|
|
6
6
|
import { jsenvCommentParameters } from "./internal/jsenvCommentParameters.js"
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ export const reportFileSizeImpact = async ({
|
|
|
10
10
|
commandLogs,
|
|
11
11
|
cancellationToken,
|
|
12
12
|
cancelOnSIGINT,
|
|
13
|
-
|
|
13
|
+
rootDirectoryUrl,
|
|
14
14
|
|
|
15
15
|
githubToken,
|
|
16
16
|
repositoryOwner,
|
|
@@ -57,10 +57,10 @@ export const reportFileSizeImpact = async ({
|
|
|
57
57
|
`fileSizeReportModulePath must be a string but received ${fileSizeReportModulePath}`,
|
|
58
58
|
)
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
|
|
61
61
|
const fileSizeReportModuleUrl = resolveUrl(
|
|
62
62
|
fileSizeReportModulePath,
|
|
63
|
-
|
|
63
|
+
rootDirectoryUrl,
|
|
64
64
|
)
|
|
65
65
|
|
|
66
66
|
return commentGitHubPullRequestImpact({
|
|
@@ -68,16 +68,16 @@ export const reportFileSizeImpact = async ({
|
|
|
68
68
|
commandLogs,
|
|
69
69
|
cancellationToken,
|
|
70
70
|
cancelOnSIGINT,
|
|
71
|
-
|
|
71
|
+
rootDirectoryUrl,
|
|
72
72
|
|
|
73
73
|
githubToken,
|
|
74
74
|
repositoryOwner,
|
|
75
75
|
repositoryName,
|
|
76
76
|
pullRequestNumber,
|
|
77
77
|
|
|
78
|
-
collectInfo: async ({
|
|
79
|
-
if (installCommand) await
|
|
80
|
-
if (buildCommand) await
|
|
78
|
+
collectInfo: async ({ execCommandInRootDirectory }) => {
|
|
79
|
+
if (installCommand) await execCommandInRootDirectory(installCommand)
|
|
80
|
+
if (buildCommand) await execCommandInRootDirectory(buildCommand)
|
|
81
81
|
const fileSizeReport = await importOneExportFromFile(
|
|
82
82
|
fileSizeReportModuleUrl,
|
|
83
83
|
)
|