@node-cli/bundlesize 4.0.4 → 4.1.1
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/README.md +60 -62
- package/dist/bundlesize.js.map +1 -1
- package/dist/defaults.js.map +1 -1
- package/dist/getRawStats.js +2 -12
- package/dist/getRawStats.js.map +1 -1
- package/dist/parse.js.map +1 -1
- package/dist/reportStats.js.map +1 -1
- package/dist/utilities.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,12 +35,12 @@ For the report option, it must export an object named "report" which is an objec
|
|
|
35
35
|
|
|
36
36
|
```js
|
|
37
37
|
export default {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
sizes: [
|
|
39
|
+
{
|
|
40
|
+
path: "dist/some-bundle.js",
|
|
41
|
+
limit: "10 kB"
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
44
|
};
|
|
45
45
|
```
|
|
46
46
|
|
|
@@ -48,16 +48,16 @@ export default {
|
|
|
48
48
|
|
|
49
49
|
```js
|
|
50
50
|
export default {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
sizes: [
|
|
52
|
+
{
|
|
53
|
+
path: "dist/some-bundle.js",
|
|
54
|
+
limit: "10 kB"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
path: "dist/some-other-bundle.js",
|
|
58
|
+
limit: "100 kB"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
61
|
};
|
|
62
62
|
```
|
|
63
63
|
|
|
@@ -65,46 +65,44 @@ export default {
|
|
|
65
65
|
|
|
66
66
|
```js
|
|
67
67
|
export default {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
sizes: [
|
|
69
|
+
{
|
|
70
|
+
path: "dist/**/some-bundle.js",
|
|
71
|
+
limit: "10 kB"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
path: "dist/**/some-other-bundle-*.js",
|
|
75
|
+
limit: "100 kB"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
path: "dist/**/extra-+([a-zA-Z0-9]).js",
|
|
79
|
+
limit: "100 kB"
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
82
|
};
|
|
83
83
|
```
|
|
84
84
|
|
|
85
85
|
#### With a hash
|
|
86
86
|
|
|
87
|
-
The special keyword `<hash>` can be used to match a hash in the filename. It cannot
|
|
87
|
+
The special keyword `<hash>` can be used to match a hash in the filename. It cannot used if multiple files match the pattern.
|
|
88
88
|
|
|
89
89
|
**NOTE**: Using `<hash>` is equivalent to using `+([a-zA-Z0-9])` in the glob pattern. However, the result will be indexed with the `hash` key instead of the `match` key, so that subsequent scripts can use the hash value.
|
|
90
90
|
|
|
91
91
|
| Status | Pattern | Comment |
|
|
92
92
|
| ------ | ------------------------------- | ------------------------------------ |
|
|
93
93
|
| OK | `dist/**/some-bundle-<hash>.js` | If only one file matches the pattern |
|
|
94
|
-
| Not OK | `dist/**/
|
|
95
|
-
| Not OK | `dist/**/some-bundle-<hash>.*` | Cannot use `<hash>` with `*` |
|
|
94
|
+
| Not OK | `dist/**/same-prefix-<hash>.js` | If multiple files match the pattern |
|
|
96
95
|
|
|
97
96
|
#### With a version
|
|
98
97
|
|
|
99
|
-
The special keyword `<semver>` can be used to match a version in the filename. It cannot be used
|
|
98
|
+
The special keyword `<semver>` can be used to match a version in the filename. It cannot be used if multiple files match the pattern.
|
|
100
99
|
|
|
101
100
|
**NOTE**: Using `<semver>` is equivalent to using `*` in the glob pattern. However, the result will be indexed with the `semver` key instead of the `match` key, so that subsequent scripts can use the semver value.
|
|
102
101
|
|
|
103
102
|
| Status | Pattern | Comment |
|
|
104
103
|
| ------ | --------------------------------- | ------------------------------------ |
|
|
105
104
|
| OK | `dist/**/some-bundle-<semver>.js` | If only one file matches the pattern |
|
|
106
|
-
| Not OK | `dist/**/
|
|
107
|
-
| Not OK | `dist/**/some-bundle-<semver>.*` | Cannot use `<semver>` with `*` |
|
|
105
|
+
| Not OK | `dist/**/same-prefix-<semver>.js` | If multiple files match the pattern |
|
|
108
106
|
|
|
109
107
|
### Printing reports from stats
|
|
110
108
|
|
|
@@ -112,10 +110,10 @@ The special keyword `<semver>` can be used to match a version in the filename. I
|
|
|
112
110
|
|
|
113
111
|
```js
|
|
114
112
|
export default {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
113
|
+
report: {
|
|
114
|
+
prev: "stats/previous.json",
|
|
115
|
+
current: "stats/current.json"
|
|
116
|
+
}
|
|
119
117
|
};
|
|
120
118
|
```
|
|
121
119
|
|
|
@@ -123,11 +121,11 @@ export default {
|
|
|
123
121
|
|
|
124
122
|
```js
|
|
125
123
|
export default {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
report: {
|
|
125
|
+
header: "## My custom header",
|
|
126
|
+
prev: "stats/previous.json",
|
|
127
|
+
current: "stats/current.json"
|
|
128
|
+
}
|
|
131
129
|
};
|
|
132
130
|
```
|
|
133
131
|
|
|
@@ -135,13 +133,13 @@ export default {
|
|
|
135
133
|
|
|
136
134
|
```js
|
|
137
135
|
export default {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
136
|
+
report: {
|
|
137
|
+
footer: (limitReached, diff) => {
|
|
138
|
+
return `## My custom footer: ${limitReached} ${diff}`;
|
|
139
|
+
},
|
|
140
|
+
prev: "stats/previous.json",
|
|
141
|
+
current: "stats/current.json"
|
|
142
|
+
}
|
|
145
143
|
};
|
|
146
144
|
```
|
|
147
145
|
|
|
@@ -149,16 +147,16 @@ export default {
|
|
|
149
147
|
|
|
150
148
|
```js
|
|
151
149
|
export default {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
150
|
+
report: {
|
|
151
|
+
columns: [
|
|
152
|
+
{ status: "Status" },
|
|
153
|
+
{ file: "File" },
|
|
154
|
+
{ size: "Size" },
|
|
155
|
+
{ limits: "Limits" }
|
|
156
|
+
],
|
|
157
|
+
prev: "stats/previous.json",
|
|
158
|
+
current: "stats/current.json"
|
|
159
|
+
}
|
|
162
160
|
};
|
|
163
161
|
```
|
|
164
162
|
|
package/dist/bundlesize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bundlesize.ts"],"sourcesContent":["#!/usr/bin/env node\n/* istanbul ignore file */\n\nimport { IGNORE, STDOUT } from \"./utilities.js\";\n\nimport { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\nimport { getRawStats } from \"./getRawStats.js\";\nimport { config } from \"./parse.js\";\nimport { reportStats } from \"./reportStats.js\";\n\nconst flags = config.flags;\n\nconst log = new Logger({\n\tboring: flags.boring,\n});\n\nif (flags.type === \"size\") {\n\ttry {\n\t\tconst result = await getRawStats({ flags });\n\n\t\tif (result.outputFile === IGNORE) {\n\t\t\tprocess.exit(result.exitCode);\n\t\t}\n\n\t\tif (result.exitMessage !== \"\") {\n\t\t\tlog.error(result.exitMessage);\n\t\t\tprocess.exit(result.exitCode);\n\t\t}\n\n\t\tif (result.outputFile === STDOUT) {\n\t\t\tlog.info(`Configuration: ${flags.configuration}`);\n\t\t\tlog.info(`Output: ${result.outputFile}`);\n\t\t\tlog.info(`Output prefix: ${result.prefix}`);\n\t\t\tlog.log(result.data);\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tfs.outputJsonSync(result.outputFile, result.data, { spaces: 2 });\n\t\t\t} catch (error) {\n\t\t\t\tlog.error(`Failed to write to file: ${error.message}`);\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t}\n\t\tprocess.exit(result.exitCode);\n\t} catch (error) {\n\t\tlog.error(error);\n\t\tprocess.exit(1);\n\t}\n}\n\nif (flags.type === \"report\") {\n\ttry {\n\t\tconst result = await reportStats({ flags });\n\n\t\tif (result.exitMessage !== \"\") {\n\t\t\tlog.error(result.exitMessage);\n\t\t\tprocess.exit(result.exitCode);\n\t\t}\n\n\t\tif (result.outputFile === STDOUT) {\n\t\t\tlog.info(`Configuration: ${flags.configuration}`);\n\t\t\tlog.info(`Output: ${result.outputFile}`);\n\t\t\tlog.log(result.data);\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tfs.outputFileSync(result.outputFile, result.data);\n\t\t\t} catch (error) {\n\t\t\t\tlog.error(`Failed to write to file: ${error.message}`);\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t}\n\t\tprocess.exit(result.exitCode);\n\t} catch (error) {\n\t\tlog.error(error);\n\t\tprocess.exit(1);\n\t}\n}\n\nlog.error(\"Invalid type, please use 'size' or 'report'\");\nprocess.exit(1);\n"],"names":["IGNORE","STDOUT","Logger","fs","getRawStats","config","reportStats","flags","log","boring","type","result","outputFile","process","exit","exitCode","exitMessage","error","info","configuration","prefix","data","outputJsonSync","spaces","message","outputFileSync"],"
|
|
1
|
+
{"version":3,"sources":["../src/bundlesize.ts"],"sourcesContent":["#!/usr/bin/env node\n/* istanbul ignore file */\n\nimport { IGNORE, STDOUT } from \"./utilities.js\";\n\nimport { Logger } from \"@node-cli/logger\";\nimport fs from \"fs-extra\";\nimport { getRawStats } from \"./getRawStats.js\";\nimport { config } from \"./parse.js\";\nimport { reportStats } from \"./reportStats.js\";\n\nconst flags = config.flags;\n\nconst log = new Logger({\n\tboring: flags.boring,\n});\n\nif (flags.type === \"size\") {\n\ttry {\n\t\tconst result = await getRawStats({ flags });\n\n\t\tif (result.outputFile === IGNORE) {\n\t\t\tprocess.exit(result.exitCode);\n\t\t}\n\n\t\tif (result.exitMessage !== \"\") {\n\t\t\tlog.error(result.exitMessage);\n\t\t\tprocess.exit(result.exitCode);\n\t\t}\n\n\t\tif (result.outputFile === STDOUT) {\n\t\t\tlog.info(`Configuration: ${flags.configuration}`);\n\t\t\tlog.info(`Output: ${result.outputFile}`);\n\t\t\tlog.info(`Output prefix: ${result.prefix}`);\n\t\t\tlog.log(result.data);\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tfs.outputJsonSync(result.outputFile, result.data, { spaces: 2 });\n\t\t\t} catch (error) {\n\t\t\t\tlog.error(`Failed to write to file: ${error.message}`);\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t}\n\t\tprocess.exit(result.exitCode);\n\t} catch (error) {\n\t\tlog.error(error);\n\t\tprocess.exit(1);\n\t}\n}\n\nif (flags.type === \"report\") {\n\ttry {\n\t\tconst result = await reportStats({ flags });\n\n\t\tif (result.exitMessage !== \"\") {\n\t\t\tlog.error(result.exitMessage);\n\t\t\tprocess.exit(result.exitCode);\n\t\t}\n\n\t\tif (result.outputFile === STDOUT) {\n\t\t\tlog.info(`Configuration: ${flags.configuration}`);\n\t\t\tlog.info(`Output: ${result.outputFile}`);\n\t\t\tlog.log(result.data);\n\t\t} else {\n\t\t\ttry {\n\t\t\t\tfs.outputFileSync(result.outputFile, result.data);\n\t\t\t} catch (error) {\n\t\t\t\tlog.error(`Failed to write to file: ${error.message}`);\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t}\n\t\tprocess.exit(result.exitCode);\n\t} catch (error) {\n\t\tlog.error(error);\n\t\tprocess.exit(1);\n\t}\n}\n\nlog.error(\"Invalid type, please use 'size' or 'report'\");\nprocess.exit(1);\n"],"names":["IGNORE","STDOUT","Logger","fs","getRawStats","config","reportStats","flags","log","boring","type","result","outputFile","process","exit","exitCode","ex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CAAC;YACd;QACD;QACAD,QAAQC,IAAI,CAACH,OAAOI,QAAQ;IAC7B,EAAE,OAAOE,OAAO;QACfT,IAAIS,KAAK,CAACA;QACVJ,QAAQC,IAAI,CAAC;IACd;AACD;AAEA,IAAIP,MAAMG,IAAI,KAAK,UAAU;IAC5B,IAAI;QACH,MAAMC,SAAS,MAAML,YAAY;YAAEC;QAAM;QAEzC,IAAII,OAAOK,WAAW,KAAK,IAAI;YAC9BR,IAAIS,KAAK,CAACN,OAAOK,WAAW;YAC5BH,QAAQC,IAAI,CAACH,OAAOI,QAAQ;QAC7B;QAEA,IAAIJ,OAAOC,UAAU,KAAKX,QAAQ;YACjCO,IAAIU,IAAI,CAAC,CAAC,eAAe,EAAEX,MAAMY,aAAa,CAAC,CAAC;YAChDX,IAAIU,IAAI,CAAC,CAAC,QAAQ,EAAEP,OAAOC,UAAU,CAAC,CAAC;YACvCJ,IAAIA,GAAG,CAACG,OAAOU,IAAI;QACpB,OAAO;YACN,IAAI;gBACHlB,GAAGsB,cAAc,CAACd,OAAOC,UAAU,EAAED,OAAOU,IAAI;YACjD,EAAE,OAAOJ,OAAO;gBACfT,IAAIS,KAAK,CAAC,CAAC,yBAAyB,EAAEA,MAAMO,OAAO,CAAC,CAAC;gBACrDX,QAAQC,IAAI,CAAC;YACd;QACD;QACAD,QAAQC,IAAI,CAACH,OAAOI,QAAQ;IAC7B,EAAE,OAAOE,OAAO;QACfT,IAAIS,KAAK,CAACA;QACVJ,QAAQC,IAAI,CAAC;IACd;AACD;AAEAN,IAAIS,KAAK,CAAC;AACVJ,QAAQC,IAAI,CAAC"}
|
package/dist/defaults.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["/* istanbul ignore file */\n\nexport const defaultFlags = {\n\tboring: false,\n\tconfiguration: \"\",\n\tsilent: false,\n\ttype: \"size\",\n\tforce: false,\n};\n"],"names":["defaultFlags","boring","configuration","silent","type","force"],"
|
|
1
|
+
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["/* istanbul ignore file */\n\nexport const defaultFlags = {\n\tboring: false,\n\tconfiguration: \"\",\n\tsilent: false,\n\ttype: \"size\",\n\tforce: false,\n};\n"],"names":["defaultFlags","boring","configuration","silent","type","force"],"mappings":"AAAA,wBAAwB,GAExB,OAAO,MAAMA,eAAe;IAC3BC,QAAQ;IACRC,eAAe;IACfC,QAAQ;IACRC,MAAM;IACNC,OAAO;AACR,EAAE"}
|
package/dist/getRawStats.js
CHANGED
|
@@ -41,16 +41,6 @@ export const getRawStats = async ({ flags })=>{
|
|
|
41
41
|
result.exitMessage = `Invalid path: ${artifact.path}.\nCannot use ${HASH_KEY} and ${SEMVER_KEY} in the same path.`;
|
|
42
42
|
return result;
|
|
43
43
|
}
|
|
44
|
-
/**
|
|
45
|
-
* if the artifact.path has the string <hash> or <semver> in it,
|
|
46
|
-
* then we need to check for other characters:
|
|
47
|
-
* - Double stars ** are allowed.
|
|
48
|
-
* - Single stars * are not allowed.
|
|
49
|
-
*/ if ((hasHash || hasSemver) && /(?<!\*)\*(?!\*)/.test(artifact.path)) {
|
|
50
|
-
result.exitCode = 1;
|
|
51
|
-
result.exitMessage = `Invalid path: ${artifact.path}.\nSingle stars (*) are not allowed when using the special keyword ${hasHash ? HASH_KEY : SEMVER_KEY}`;
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
44
|
let location = artifact.path;
|
|
55
45
|
if (hasHash) {
|
|
56
46
|
location = artifact.path.replace(HASH_KEY, GLOB_HASH);
|
|
@@ -65,9 +55,9 @@ export const getRawStats = async ({ flags })=>{
|
|
|
65
55
|
result.exitMessage = `File not found: ${fileGlob}`;
|
|
66
56
|
return result;
|
|
67
57
|
}
|
|
68
|
-
if (files.length > 1
|
|
58
|
+
if (files.length > 1) {
|
|
69
59
|
result.exitCode = 1;
|
|
70
|
-
result.exitMessage = `Multiple files found for: ${artifact.path}.\nPlease use a more specific path
|
|
60
|
+
result.exitMessage = `Multiple files found for: ${artifact.path}.\nPlease use a more specific path.`;
|
|
71
61
|
return result;
|
|
72
62
|
}
|
|
73
63
|
for (const file of files){
|
package/dist/getRawStats.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/getRawStats.ts"],"sourcesContent":["import { basename, dirname, join } from \"node:path\";\nimport {\n\tGLOB_HASH,\n\tGLOB_SEMVER,\n\tHASH_KEY,\n\tIGNORE,\n\tSEMVER_KEY,\n\tSTDOUT,\n\tgetOutputFile,\n\tgzipSizeFromFileSync,\n\tvalidateConfigurationFile,\n} from \"./utilities.js\";\n\nimport { statSync } from \"node:fs\";\nimport bytes from \"bytes\";\nimport fs from \"fs-extra\";\nimport { glob } from \"glob\";\n\ntype SizesConfiguration = {\n\tlimit: string;\n\tpath: string;\n};\n\ntype ReportStats = {\n\tdata: Record<string, unknown>;\n\texitCode: number;\n\texitMessage: string;\n\toutputFile: string;\n\tpass: boolean;\n\tprefix: string;\n};\n\nexport const getRawStats = async ({ flags }): Promise<ReportStats> => {\n\tconst result: ReportStats = {\n\t\tpass: true,\n\t\texitCode: 0,\n\t\texitMessage: \"\",\n\t\toutputFile: \"\",\n\t\tprefix: \"\",\n\t\tdata: {},\n\t};\n\tlet failed = false;\n\tconst isValidConfigResult = validateConfigurationFile(flags.configuration);\n\tif (isValidConfigResult.exitMessage !== \"\") {\n\t\treturn {\n\t\t\t...result,\n\t\t\t...isValidConfigResult,\n\t\t};\n\t}\n\tconst configurationFile = isValidConfigResult.data;\n\tconst outputFile = getOutputFile(flags.output);\n\tconst prefix = flags.prefix || \"0.0.0\";\n\tconst currentResults = {};\n\n\tconst configuration: { sizes: SizesConfiguration[] } = await import(\n\t\tconfigurationFile\n\t).then((m) => m.default);\n\n\tif (configuration.sizes === undefined) {\n\t\tresult.exitMessage = \"Invalid configuration file: missing sizes object!\";\n\t\tresult.exitCode = 1;\n\t\treturn result;\n\t}\n\n\tfor (const artifact of configuration.sizes) {\n\t\tconst rootPath = artifact.path.startsWith(\"/\")\n\t\t\t? \"\"\n\t\t\t: dirname(configurationFile);\n\t\tconst artifactPath = dirname(artifact.path);\n\t\tconst hasHash = artifact.path.includes(HASH_KEY);\n\t\tconst hasSemver = artifact.path.includes(SEMVER_KEY);\n\n\t\tif (hasSemver && hasHash) {\n\t\t\tresult.exitCode = 1;\n\t\t\tresult.exitMessage = `Invalid path: ${artifact.path}.\\nCannot use ${HASH_KEY} and ${SEMVER_KEY} in the same path.`;\n\t\t\treturn result;\n\t\t}\n\n\t\
|
|
1
|
+
{"version":3,"sources":["../src/getRawStats.ts"],"sourcesContent":["import { basename, dirname, join } from \"node:path\";\nimport {\n\tGLOB_HASH,\n\tGLOB_SEMVER,\n\tHASH_KEY,\n\tIGNORE,\n\tSEMVER_KEY,\n\tSTDOUT,\n\tgetOutputFile,\n\tgzipSizeFromFileSync,\n\tvalidateConfigurationFile,\n} from \"./utilities.js\";\n\nimport { statSync } from \"node:fs\";\nimport bytes from \"bytes\";\nimport fs from \"fs-extra\";\nimport { glob } from \"glob\";\n\ntype SizesConfiguration = {\n\tlimit: string;\n\tpath: string;\n};\n\ntype ReportStats = {\n\tdata: Record<string, unknown>;\n\texitCode: number;\n\texitMessage: string;\n\toutputFile: string;\n\tpass: boolean;\n\tprefix: string;\n};\n\nexport const getRawStats = async ({ flags }): Promise<ReportStats> => {\n\tconst result: ReportStats = {\n\t\tpass: true,\n\t\texitCode: 0,\n\t\texitMessage: \"\",\n\t\toutputFile: \"\",\n\t\tprefix: \"\",\n\t\tdata: {},\n\t};\n\tlet failed = false;\n\tconst isValidConfigResult = validateConfigurationFile(flags.configuration);\n\tif (isValidConfigResult.exitMessage !== \"\") {\n\t\treturn {\n\t\t\t...result,\n\t\t\t...isValidConfigResult,\n\t\t};\n\t}\n\tconst configurationFile = isValidConfigResult.data;\n\tconst outputFile = getOutputFile(flags.output);\n\tconst prefix = flags.prefix || \"0.0.0\";\n\tconst currentResults = {};\n\n\tconst configuration: { sizes: SizesConfiguration[] } = await import(\n\t\tconfigurationFile\n\t).then((m) => m.default);\n\n\tif (configuration.sizes === undefined) {\n\t\tresult.exitMessage = \"Invalid configuration file: missing sizes object!\";\n\t\tresult.exitCode = 1;\n\t\treturn result;\n\t}\n\n\tfor (const artifact of configuration.sizes) {\n\t\tconst rootPath = artifact.path.startsWith(\"/\")\n\t\t\t? \"\"\n\t\t\t: dirname(configurationFile);\n\t\tconst artifactPath = dirname(artifact.path);\n\t\tconst hasHash = artifact.path.includes(HASH_KEY);\n\t\tconst hasSemver = artifact.path.includes(SEMVER_KEY);\n\n\t\tif (hasSemver && hasHash) {\n\t\t\tresult.exitCode = 1;\n\t\t\tresult.exitMessage = `Invalid path: ${artifact.path}.\\nCannot use ${HASH_KEY} and ${SEMVER_KEY} in the same path.`;\n\t\t\treturn result;\n\t\t}\n\n\t\tlet location = artifact.path;\n\t\tif (hasHash) {\n\t\t\tlocation = artifact.path.replace(HASH_KEY, GLOB_HASH);\n\t\t}\n\t\tif (hasSemver) {\n\t\t\tlocation = artifact.path.replace(SEMVER_KEY, GLOB_SEMVER);\n\t\t}\n\t\tconst fileGlob = join(rootPath, location);\n\t\tconst files = glob.sync(fileGlob);\n\n\t\tif (files.length === 0) {\n\t\t\tresult.exitCode = 1;\n\t\t\tresult.exitMessage = `File not found: ${fileGlob}`;\n\t\t\treturn result;\n\t\t}\n\n\t\tif (files.length > 1) {\n\t\t\tresult.exitCode = 1;\n\t\t\tresult.exitMessage = `Multiple files found for: ${artifact.path}.\\nPlease use a more specific path.`;\n\t\t\treturn result;\n\t\t}\n\n\t\tfor (const file of files) {\n\t\t\tconst fileSize = statSync(file).size;\n\t\t\tconst fileSizeGzip = gzipSizeFromFileSync(file);\n\t\t\tconst passed = fileSizeGzip < bytes(artifact.limit);\n\n\t\t\tif (passed === false) {\n\t\t\t\tresult.pass = false;\n\t\t\t\tfailed = true;\n\t\t\t}\n\t\t\tconst index =\n\t\t\t\thasHash || hasSemver\n\t\t\t\t\t? artifact.path\n\t\t\t\t\t: join(artifactPath, basename(file));\n\n\t\t\tcurrentResults[index] = {\n\t\t\t\tfileSize,\n\t\t\t\tfileSizeGzip,\n\t\t\t\tlimit: artifact.limit,\n\t\t\t\tpassed,\n\t\t\t};\n\t\t}\n\t}\n\n\tlet existingResults = {};\n\tif (outputFile !== STDOUT) {\n\t\ttry {\n\t\t\texistingResults = fs.readJsonSync(outputFile);\n\t\t} catch {\n\t\t\t/**\n\t\t\t * There are no existing results, so we can ignore this error,\n\t\t\t * and simply write the current results to the output file.\n\t\t\t */\n\t\t}\n\t}\n\n\t/**\n\t * If the prefix already exists in the output file,\n\t * - if --force flag is used, overwrite the existing results\n\t * - if --force flag is not used, ignore the new results and\n\t * keep the existing ones.\n\t */\n\tif (existingResults[prefix] !== undefined && flags.force === false) {\n\t\tresult.outputFile = IGNORE;\n\t} else {\n\t\tresult.outputFile = outputFile;\n\t\texistingResults[prefix] = currentResults;\n\t}\n\n\tresult.prefix = prefix;\n\tresult.exitCode = flags.silent === true ? 0 : Number(failed);\n\tresult.data = existingResults;\n\treturn result;\n};\n"],"names":["basename","dirname","join","GLOB_HASH","GLOB_SEMVER","HASH_KEY","IGNORE","SEMVER_KEY","STDOUT","getOutputFile","gzipSizeFromFileSync","validateConfigurationFile","statSync","bytes","fs","glob","getRawStats","flags","result","pass","exitCode","exitMessage","outputFile","prefix","data","failed","isValidConfigResult","configuration","configurationFile","output","currentResults","then","m","default","sizes","undefined","artifact","rootPath","path","startsWith","artifactPath","hasHash","includes","hasSemver","location","replace","fileGlob","files","sync","length","file","fileSize","size","fileSizeGzip","passed","limit","index","existingResults","readJsonSync","force","silent","Number"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,OAAO,EAAEC,IAAI,QAAQ,YAAY;AACpD,SACCC,SAAS,EACTC,WAAW,EACXC,QAAQ,EACRC,MAAM,EACNC,UAAU,EACVC,MAAM,EACNC,aAAa,EACbC,oBAAoB,EACpBC,yBAAyB,QACnB,iBAAiB;AAExB,S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,KAAK,OAAO;QACnEzC,OAAOI,UAAU,GAAGhB;IACrB,OAAO;QACNY,OAAOI,UAAU,GAAGA;QACpBmC,eAAe,CAAClC,OAAO,GAAGO;IAC3B;IAEAZ,OAAOK,MAAM,GAAGA;IAChBL,OAAOE,QAAQ,GAAGH,MAAM2C,MAAM,KAAK,OAAO,IAAIC,OAAOpC;IACrDP,OAAOM,IAAI,GAAGiC;IACd,OAAOvC;AACR,EAAE"}
|
package/dist/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["import { parser } from \"@node-cli/parser\";\nimport { defaultFlags } from \"./defaults.js\";\n\nexport type Flags = {\n\tboring?: boolean;\n\thelp?: boolean;\n\tversion?: boolean;\n\tconfiguration?: string;\n\toutput?: string;\n\tprefix?: string;\n\tsilent?: boolean;\n\ttype?: \"size\" | \"report\";\n\tforce?: boolean;\n};\n\nexport type Configuration = {\n\tflags?: Flags;\n\tusage?: boolean;\n\tshowHelp?: () => void;\n};\n\n/* istanbul ignore next */\nexport const config: Configuration = parser({\n\tmeta: import.meta,\n\texamples: [],\n\tflags: {\n\t\tforce: {\n\t\t\tshortFlag: \"f\",\n\t\t\tdescription: \"Overwrite existing results\",\n\t\t\ttype: \"boolean\",\n\t\t\tdefault: defaultFlags.force,\n\t\t},\n\t\ttype: {\n\t\t\tshortFlag: \"t\",\n\t\t\tdescription: \"Specify the type of output: size or report\",\n\t\t\ttype: \"string\",\n\t\t\tdefault: defaultFlags.type,\n\t\t},\n\t\tconfiguration: {\n\t\t\tshortFlag: \"c\",\n\t\t\tdescription: \"Specify a configuration file\",\n\t\t\ttype: \"string\",\n\t\t},\n\t\toutput: {\n\t\t\tshortFlag: \"o\",\n\t\t\tdescription: \"Specify the output file\",\n\t\t\ttype: \"string\",\n\t\t},\n\t\tprefix: {\n\t\t\tshortFlag: \"p\",\n\t\t\tdescription: \"Specify a prefix to use in the output file\",\n\t\t\ttype: \"string\",\n\t\t},\n\t\tsilent: {\n\t\t\tshortFlag: \"s\",\n\t\t\tdefault: defaultFlags.silent,\n\t\t\tdescription: \"Do not exit in error when a limit is exceeded\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tboring: {\n\t\t\tshortFlag: \"b\",\n\t\t\tdefault: defaultFlags.boring,\n\t\t\tdescription: \"Do not use color output\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\thelp: {\n\t\t\tshortFlag: \"h\",\n\t\t\tdescription: \"Display help instructions\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tversion: {\n\t\t\tshortFlag: \"v\",\n\t\t\tdescription: \"Output the current version\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t},\n\tusage: true,\n\tdefaultFlags,\n});\n"],"names":["parser","defaultFlags","config","meta","examples","flags","force","shortFlag","description","type","default","configuration","output","prefix","silent","boring","help","version","usage"],"
|
|
1
|
+
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["import { parser } from \"@node-cli/parser\";\nimport { defaultFlags } from \"./defaults.js\";\n\nexport type Flags = {\n\tboring?: boolean;\n\thelp?: boolean;\n\tversion?: boolean;\n\tconfiguration?: string;\n\toutput?: string;\n\tprefix?: string;\n\tsilent?: boolean;\n\ttype?: \"size\" | \"report\";\n\tforce?: boolean;\n};\n\nexport type Configuration = {\n\tflags?: Flags;\n\tusage?: boolean;\n\tshowHelp?: () => void;\n};\n\n/* istanbul ignore next */\nexport const config: Configuration = parser({\n\tmeta: import.meta,\n\texamples: [],\n\tflags: {\n\t\tforce: {\n\t\t\tshortFlag: \"f\",\n\t\t\tdescription: \"Overwrite existing results\",\n\t\t\ttype: \"boolean\",\n\t\t\tdefault: defaultFlags.force,\n\t\t},\n\t\ttype: {\n\t\t\tshortFlag: \"t\",\n\t\t\tdescription: \"Specify the type of output: size or report\",\n\t\t\ttype: \"string\",\n\t\t\tdefault: defaultFlags.type,\n\t\t},\n\t\tconfiguration: {\n\t\t\tshortFlag: \"c\",\n\t\t\tdescription: \"Specify a configuration file\",\n\t\t\ttype: \"string\",\n\t\t},\n\t\toutput: {\n\t\t\tshortFlag: \"o\",\n\t\t\tdescription: \"Specify the output file\",\n\t\t\ttype: \"string\",\n\t\t},\n\t\tprefix: {\n\t\t\tshortFlag: \"p\",\n\t\t\tdescription: \"Specify a prefix to use in the output file\",\n\t\t\ttype: \"string\",\n\t\t},\n\t\tsilent: {\n\t\t\tshortFlag: \"s\",\n\t\t\tdefault: defaultFlags.silent,\n\t\t\tdescription: \"Do not exit in error when a limit is exceeded\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tboring: {\n\t\t\tshortFlag: \"b\",\n\t\t\tdefault: defaultFlags.boring,\n\t\t\tdescription: \"Do not use color output\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\thelp: {\n\t\t\tshortFlag: \"h\",\n\t\t\tdescription: \"Display help instructions\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tversion: {\n\t\t\tshortFlag: \"v\",\n\t\t\tdescription: \"Output the current version\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t},\n\tusage: true,\n\tdefaultFlags,\n});\n"],"names":["parser","defaultFlags","config","meta","examples","flags","force","shortFlag","description","type","default","configuration","output","prefix","silent","boring","help","version","usage"],"mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,YAAY,QAAQ,gBAAgB;AAoB7C,wBAAwB,GACxB,OAAO,MAAMC,SAAwBF,OAAO;IAC3CG,MAAM;IACNC,UAAU,EAAE;IACZC,OAAO;QACNC,OAAO;YACNC,WAAW;YACXC,aAAa;YACbC,MAAM;YACNC,SAAST,aAAaK,KAAK;QAC5B;QACAG,MAAM;YACLF,WAAW;YACXC,aAAa;YACbC,MAAM;YACNC,SAAST,aAAaQ,IAAI;QAC3B;QACAE,eAAe;YACdJ,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;QACAG,QAAQ;YACPL,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;QACAI,QAAQ;YACPN,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;QACAK,QAAQ;YACPP,WAAW;YACXG,SAAST,aAAaa,MAAM;YAC5BN,aAAa;YACbC,MAAM;QACP;QACAM,QAAQ;YACPR,WAAW;YACXG,SAAST,aAAac,MAAM;YAC5BP,aAAa;YACbC,MAAM;QACP;QACAO,MAAM;YACLT,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;QACAQ,SAAS;YACRV,WAAW;YACXC,aAAa;YACbC,MAAM;QACP;IACD;IACAS,OAAO;IACPjB;AACD,GAAG"}
|
package/dist/reportStats.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/reportStats.ts"],"sourcesContent":["import { basename, dirname, join } from \"node:path\";\nimport {\n\taddMDrow,\n\tformatFooter,\n\tgetMostRecentVersion,\n\tgetOutputFile,\n\tpercentFormatter,\n\treadJSONFile,\n\tvalidateConfigurationFile,\n} from \"./utilities.js\";\n\nimport bytes from \"bytes\";\nimport type { FooterProperties } from \"./utilities.js\";\n\ntype ReportConfiguration = {\n\tcurrent: string;\n\tprevious: string;\n\n\theader?: string;\n\tfooter?: (arguments_: FooterProperties) => string;\n\tcolumns?: { [key: string]: string }[];\n};\n\ntype ReportCompare = {\n\tdata: string;\n\texitCode: number;\n\texitMessage: string;\n\toutputFile: string;\n};\n\nexport const reportStats = async ({ flags }): Promise<ReportCompare> => {\n\tconst result: ReportCompare = {\n\t\texitCode: 0,\n\t\texitMessage: \"\",\n\t\toutputFile: \"\",\n\t\tdata: \"\",\n\t};\n\tlet previousStats, previousVersion: string;\n\tconst isValidConfigResult = validateConfigurationFile(flags.configuration);\n\tif (isValidConfigResult.exitMessage !== \"\") {\n\t\treturn {\n\t\t\t...result,\n\t\t\t...isValidConfigResult,\n\t\t};\n\t}\n\tconst configurationFile = isValidConfigResult.data;\n\tconst outputFile = getOutputFile(flags.output);\n\tresult.outputFile = outputFile;\n\n\tconst configuration: { report: ReportConfiguration } = await import(\n\t\tconfigurationFile\n\t).then((m) => m.default);\n\n\tconst currentStats = readJSONFile(\n\t\tjoin(dirname(configurationFile), configuration.report.current),\n\t);\n\tif (currentStats.exitMessage !== \"\") {\n\t\treturn {\n\t\t\t...result,\n\t\t\t...currentStats,\n\t\t};\n\t}\n\n\ttry {\n\t\tpreviousStats = readJSONFile(\n\t\t\tjoin(dirname(configurationFile), configuration.report.previous),\n\t\t);\n\t\tif (previousStats.exitMessage !== \"\") {\n\t\t\treturn {\n\t\t\t\t...result,\n\t\t\t\t...previousStats,\n\t\t\t};\n\t\t}\n\t\tpreviousVersion = getMostRecentVersion(previousStats.data);\n\t} catch {\n\t\t// nothing to declare officer\n\t}\n\tconst currentVersion = getMostRecentVersion(currentStats.data);\n\n\tlet limitReached = false;\n\tlet overallDiff = 0;\n\tlet totalGzipSize = 0;\n\n\tconst headerString = configuration.report.header || \"## Bundle Size\";\n\tconst footerFormatter = configuration.report.footer || formatFooter;\n\tconst columns = configuration.report.columns || [\n\t\t{ status: \"Status\" },\n\t\t{ file: \"File\" },\n\t\t{ size: \"Size (Gzip)\" },\n\t\t{ limits: \"Limits\" },\n\t];\n\n\tconst rowsMD = [];\n\trowsMD.push(addMDrow({ type: \"header\", columns }));\n\n\tfor (const key of Object.keys(currentStats.data[currentVersion])) {\n\t\tconst item = currentStats.data[currentVersion][key];\n\t\tconst name = basename(key);\n\t\tif (!item.passed) {\n\t\t\tlimitReached = true;\n\t\t}\n\n\t\tlet diffString = \"\";\n\t\tif (previousStats && previousVersion) {\n\t\t\tconst previousFileStats =\n\t\t\t\tpreviousStats.data[previousVersion] &&\n\t\t\t\tpreviousStats.data[previousVersion][key];\n\t\t\tconst previousFileSizeGzip = previousFileStats?.fileSizeGzip || 0;\n\t\t\tconst diff = item.fileSizeGzip - previousFileSizeGzip;\n\n\t\t\toverallDiff += diff;\n\t\t\tdiffString =\n\t\t\t\tdiff === 0 || diff === item.fileSizeGzip\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: ` (${diff > 0 ? \"+\" : \"-\"}${bytes(Math.abs(diff), {\n\t\t\t\t\t\t\tunitSeparator: \" \",\n\t\t\t\t\t\t})} ${percentFormatter(diff / previousFileSizeGzip)})`;\n\t\t}\n\n\t\ttotalGzipSize += item.fileSizeGzip;\n\n\t\trowsMD.push(\n\t\t\taddMDrow({\n\t\t\t\ttype: \"row\",\n\t\t\t\tpassed: item.passed,\n\t\t\t\tname: name,\n\t\t\t\tsize: item.fileSizeGzip,\n\t\t\t\tdiff: diffString,\n\t\t\t\tlimit: item.limit,\n\t\t\t\tcolumns,\n\t\t\t}),\n\t\t);\n\t}\n\n\tconst template = `\n${headerString}\n${rowsMD.join(\"\\n\")}\n\n${footerFormatter({\n\tlimitReached,\n\toverallDiff,\n\ttotalGzipSize,\n})}\n`;\n\n\tif (limitReached) {\n\t\tresult.exitCode = 1;\n\t}\n\n\tresult.data = template;\n\n\treturn result;\n};\n"],"names":["basename","dirname","join","addMDrow","formatFooter","getMostRecentVersion","getOutputFile","percentFormatter","readJSONFile","validateConfigurationFile","bytes","reportStats","flags","result","exitCode","exitMessage","outputFile","data","previousStats","previousVersion","isValidConfigResult","configuration","configurationFile","output","then","m","default","currentStats","report","current","previous","currentVersion","limitReached","overallDiff","totalGzipSize","headerString","header","footerFormatter","footer","columns","status","file","size","limits","rowsMD","push","type","key","Object","keys","item","name","passed","diffString","previousFileStats","previousFileSizeGzip","fileSizeGzip","diff","Math","abs","unitSeparator","limit","template"],"
|
|
1
|
+
{"version":3,"sources":["../src/reportStats.ts"],"sourcesContent":["import { basename, dirname, join } from \"node:path\";\nimport {\n\taddMDrow,\n\tformatFooter,\n\tgetMostRecentVersion,\n\tgetOutputFile,\n\tpercentFormatter,\n\treadJSONFile,\n\tvalidateConfigurationFile,\n} from \"./utilities.js\";\n\nimport bytes from \"bytes\";\nimport type { FooterProperties } from \"./utilities.js\";\n\ntype ReportConfiguration = {\n\tcurrent: string;\n\tprevious: string;\n\n\theader?: string;\n\tfooter?: (arguments_: FooterProperties) => string;\n\tcolumns?: { [key: string]: string }[];\n};\n\ntype ReportCompare = {\n\tdata: string;\n\texitCode: number;\n\texitMessage: string;\n\toutputFile: string;\n};\n\nexport const reportStats = async ({ flags }): Promise<ReportCompare> => {\n\tconst result: ReportCompare = {\n\t\texitCode: 0,\n\t\texitMessage: \"\",\n\t\toutputFile: \"\",\n\t\tdata: \"\",\n\t};\n\tlet previousStats, previousVersion: string;\n\tconst isValidConfigResult = validateConfigurationFile(flags.configuration);\n\tif (isValidConfigResult.exitMessage !== \"\") {\n\t\treturn {\n\t\t\t...result,\n\t\t\t...isValidConfigResult,\n\t\t};\n\t}\n\tconst configurationFile = isValidConfigResult.data;\n\tconst outputFile = getOutputFile(flags.output);\n\tresult.outputFile = outputFile;\n\n\tconst configuration: { report: ReportConfiguration } = await import(\n\t\tconfigurationFile\n\t).then((m) => m.default);\n\n\tconst currentStats = readJSONFile(\n\t\tjoin(dirname(configurationFile), configuration.report.current),\n\t);\n\tif (currentStats.exitMessage !== \"\") {\n\t\treturn {\n\t\t\t...result,\n\t\t\t...currentStats,\n\t\t};\n\t}\n\n\ttry {\n\t\tpreviousStats = readJSONFile(\n\t\t\tjoin(dirname(configurationFile), configuration.report.previous),\n\t\t);\n\t\tif (previousStats.exitMessage !== \"\") {\n\t\t\treturn {\n\t\t\t\t...result,\n\t\t\t\t...previousStats,\n\t\t\t};\n\t\t}\n\t\tpreviousVersion = getMostRecentVersion(previousStats.data);\n\t} catch {\n\t\t// nothing to declare officer\n\t}\n\tconst currentVersion = getMostRecentVersion(currentStats.data);\n\n\tlet limitReached = false;\n\tlet overallDiff = 0;\n\tlet totalGzipSize = 0;\n\n\tconst headerString = configuration.report.header || \"## Bundle Size\";\n\tconst footerFormatter = configuration.report.footer || formatFooter;\n\tconst columns = configuration.report.columns || [\n\t\t{ status: \"Status\" },\n\t\t{ file: \"File\" },\n\t\t{ size: \"Size (Gzip)\" },\n\t\t{ limits: \"Limits\" },\n\t];\n\n\tconst rowsMD = [];\n\trowsMD.push(addMDrow({ type: \"header\", columns }));\n\n\tfor (const key of Object.keys(currentStats.data[currentVersion])) {\n\t\tconst item = currentStats.data[currentVersion][key];\n\t\tconst name = basename(key);\n\t\tif (!item.passed) {\n\t\t\tlimitReached = true;\n\t\t}\n\n\t\tlet diffString = \"\";\n\t\tif (previousStats && previousVersion) {\n\t\t\tconst previousFileStats =\n\t\t\t\tpreviousStats.data[previousVersion] &&\n\t\t\t\tpreviousStats.data[previousVersion][key];\n\t\t\tconst previousFileSizeGzip = previousFileStats?.fileSizeGzip || 0;\n\t\t\tconst diff = item.fileSizeGzip - previousFileSizeGzip;\n\n\t\t\toverallDiff += diff;\n\t\t\tdiffString =\n\t\t\t\tdiff === 0 || diff === item.fileSizeGzip\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: ` (${diff > 0 ? \"+\" : \"-\"}${bytes(Math.abs(diff), {\n\t\t\t\t\t\t\tunitSeparator: \" \",\n\t\t\t\t\t\t})} ${percentFormatter(diff / previousFileSizeGzip)})`;\n\t\t}\n\n\t\ttotalGzipSize += item.fileSizeGzip;\n\n\t\trowsMD.push(\n\t\t\taddMDrow({\n\t\t\t\ttype: \"row\",\n\t\t\t\tpassed: item.passed,\n\t\t\t\tname: name,\n\t\t\t\tsize: item.fileSizeGzip,\n\t\t\t\tdiff: diffString,\n\t\t\t\tlimit: item.limit,\n\t\t\t\tcolumns,\n\t\t\t}),\n\t\t);\n\t}\n\n\tconst template = `\n${headerString}\n${rowsMD.join(\"\\n\")}\n\n${footerFormatter({\n\tlimitReached,\n\toverallDiff,\n\ttotalGzipSize,\n})}\n`;\n\n\tif (limitReached) {\n\t\tresult.exitCode = 1;\n\t}\n\n\tresult.data = template;\n\n\treturn result;\n};\n"],"names":["basename","dirname","join","addMDrow","formatFooter","getMostRecentVersion","getOutputFile","percentFormatter","readJSONFile","validateConfigurationFile","bytes","reportStats","flags","result","exitCode","exitMessage","outputFile","data","previousStats","previousVersion","isValidConfigResult","configuration","configurationFile","output","then","m","default","currentStats","report","current","previous","currentVersion","limitReached","overallDiff","totalGzipSize","headerString","header","footerFormatter","footer","columns","status","file","size","limits","rowsMD","push","type","key","Object","keys","item","name","passed","diffString","previousFileStats","previousFileSizeGzip","fileSizeGzip","diff","Math","abs","unitSeparator","limit","template"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,OAAO,EAAEC,IAAI,QAAQ,YAAY;AACpD,SACCC,QAAQ,EACRC,YAAY,EACZC,oBAAoB,EACpBC,aAAa,EACbC,gBAAgB,EAChBC,YAAY,EACZC,yBAAyB,QACnB,iBAAiB;AAExB,OAAOC,WAAW,QAAQ;AAmB1B,OAAO,MAAMC,cAAc,OAAO,EAAEC,KAAK,EAAE;IAC1C,MAAMC,SAAwB;QAC7BC,UAAU;QACVC,aAAa;QACbC,YAAY;QACZC,MAAM;IACP;IACA,IAAIC,eAAeC;IACnB,MAAMC,sBAAsBX,0BAA0BG,MAAMS,aAAa;IACzE,IAAID,oBAAoBL,WAAW,KAAK,IAAI;QAC3C,OAAO;YACN,GAAGF,MAAM;YACT,GAAGO,mBAAmB;QACvB;IACD;IACA,MAAME,oBAAoBF,oBAAoBH,IAAI;IAClD,MAAMD,aAAaV,cAAcM,MAAMW,MAAM;IAC7CV,OAAOG,UAAU,GAAGA;IAEpB,MAAMK,gBAAiD,MAAM,MAAM,CAClEC,mBACCE,IAAI,CAAC,CAACC,IAAMA,EAAEC,OAAO;IAEvB,MAAMC,eAAenB,aACpBN,KAAKD,QAAQqB,oBAAoBD,cAAcO,MAAM,CAACC,OAAO;IAE9D,IAAIF,aAAaZ,WAAW,KAAK,IAAI;QACpC,OAAO;YACN,GAAGF,MAAM;YACT,GAAGc,YAAY;QAChB;IACD;IAEA,IAAI;QACHT,gBAAgBV,aACfN,KAAKD,QAAQqB,oBAAoBD,cAAcO,MAAM,CAACE,QAAQ;QAE/D,IAAIZ,cAAcH,WAAW,KAAK,IAAI;YACrC,OAAO;gBACN,GAAGF,MAAM;gBACT,GAAGK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AAiBkD,OAAOF,sBAAsB,CAAC,CAAC;QAC1D;QAEArB,iBAAiBgB,KAAKM,YAAY;QAElCZ,OAAOC,IAAI,CACV1C,SAAS;YACR2C,MAAM;YACNM,QAAQF,KAAKE,MAAM;YACnBD,MAAMA;YACNT,MAAMQ,KAAKM,YAAY;YACvBC,MAAMJ;YACNQ,OAAOX,KAAKW,KAAK;YACjBtB;QACD;IAEF;IAEA,MAAMuB,WAAW,CAAC;AACnB,EAAE3B,aAAa;AACf,EAAES,OAAO1C,IAAI,CAAC,MAAM;;AAEpB,EAAEmC,gBAAgB;QACjBL;QACAC;QACAC;IACD,GAAG;AACH,CAAC;IAEA,IAAIF,cAAc;QACjBnB,OAAOC,QAAQ,GAAG;IACnB;IAEAD,OAAOI,IAAI,GAAG6C;IAEd,OAAOjD;AACR,EAAE"}
|
package/dist/utilities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import { join } from \"node:path\";\nimport zlib from \"node:zlib\";\nimport bytes from \"bytes\";\nimport fs from \"fs-extra\";\nimport semver from \"semver\";\n\nexport const STDOUT = \"stdout\";\nexport const IGNORE = \"ignore\";\nexport const HASH_KEY = \"<hash>\";\nexport const SEMVER_KEY = \"<semver>\";\nexport const GLOB_HASH = \"+([a-zA-Z0-9_-])\";\nexport const GLOB_SEMVER = \"+([0-9]).+([0-9]).+([0-9])*([.a-zA-Z0-9_-])\";\n\nconst CWD = process.cwd();\n\nexport const gzipSizeFromFileSync = (file: string): number => {\n\treturn zlib.gzipSync(fs.readFileSync(file)).length;\n};\n\nexport const getOutputFile = (file: string): string => {\n\treturn file === \"\" || file === undefined ? STDOUT : join(CWD, file);\n};\n\nexport const validateConfigurationFile = (file: string): any => {\n\tconst result = {\n\t\texitCode: 0,\n\t\texitMessage: \"\",\n\t\tdata: {},\n\t};\n\tif (file === \"\") {\n\t\tresult.exitMessage = \"Please provide a configuration file\";\n\t\tresult.exitCode = 1;\n\t\treturn result;\n\t}\n\n\tconst configurationFile = file.startsWith(\"/\") ? file : join(CWD, file);\n\n\tif (fs.existsSync(configurationFile) === false) {\n\t\tresult.exitMessage = `Invalid or missing configuration file!\\n${configurationFile}`;\n\t\tresult.exitCode = 1;\n\t\treturn result;\n\t}\n\n\treturn {\n\t\t...result,\n\t\tdata: configurationFile,\n\t};\n};\n\nexport const readJSONFile = (file: string): any => {\n\ttry {\n\t\treturn {\n\t\t\texitCode: 0,\n\t\t\texitMessage: \"\",\n\t\t\tdata: fs.readJsonSync(file),\n\t\t};\n\t} catch (error) {\n\t\treturn {\n\t\t\texitCode: 1,\n\t\t\texitMessage: `Failed to read JSON file: ${error.message}`,\n\t\t};\n\t}\n};\n\nexport const getMostRecentVersion = (data: []) => {\n\tconst keys = [];\n\tfor (const key of Object.keys(data)) {\n\t\tkeys.push(key);\n\t}\n\tkeys.sort(semver.rcompare);\n\treturn keys[0];\n};\n\nexport const percentFormatter = (value: number) => {\n\tconst formatter = new Intl.NumberFormat(\"en\", {\n\t\tstyle: \"percent\",\n\t\tsignDisplay: \"exceptZero\",\n\t\tminimumFractionDigits: 2,\n\t\tmaximumFractionDigits: 2,\n\t});\n\treturn formatter.format(value);\n};\n\nexport type FooterProperties = {\n\tlimitReached: boolean;\n\toverallDiff: number;\n\ttotalGzipSize: number;\n};\nexport const formatFooter = ({\n\tlimitReached,\n\toverallDiff,\n\ttotalGzipSize,\n}: FooterProperties) => {\n\tlet percentageDiff = \"\";\n\tconst result = [];\n\n\tconst totalGzipSizeString = `${bytes(totalGzipSize || 0, {\n\t\tunitSeparator: \" \",\n\t})}`;\n\n\tpercentageDiff = percentFormatter(\n\t\toverallDiff / (totalGzipSize - overallDiff),\n\t);\n\tconst overallDiffString =\n\t\t!overallDiff || overallDiff === 0\n\t\t\t? \"\"\n\t\t\t: `(${overallDiff > 0 ? \"+\" : \"-\"}${bytes(Math.abs(overallDiff), {\n\t\t\t\t\tunitSeparator: \" \",\n\t\t\t\t})} ${percentageDiff})`;\n\n\tresult.push(\n\t\t`Overall bundle size: ${totalGzipSizeString} ${overallDiffString}`.trim(),\n\t\t`Overall status: ${limitReached ? \"🚫\" : \"✅\"}`,\n\t);\n\n\treturn `${result.join(\"\\n\")}`;\n};\n\nexport const addMDrow = ({\n\ttype,\n\tpassed = true,\n\tname = \"\",\n\tsize = 0,\n\tdiff = \"\",\n\tlimit = \"\",\n\tcolumns,\n}: {\n\tcolumns: any;\n\ttype: \"header\" | \"row\";\n\tpassed?: boolean;\n\tname?: string;\n\tsize?: number;\n\tdiff?: string;\n\tlimit?: string;\n}) => {\n\tconst totalColumns = columns.length;\n\n\tif (type === \"header\") {\n\t\tconst separator = \" --- |\".repeat(totalColumns);\n\t\tconst header = columns.map((column) => column[Object.keys(column)[0]]);\n\t\treturn `| ${header.join(\" | \")} |\\n|${separator}`;\n\t}\n\tif (type === \"row\") {\n\t\tconst row = columns\n\t\t\t.map((column: Record<string, any>) => {\n\t\t\t\tconst key = Object.keys(column)[0];\n\t\t\t\tif (key === \"status\") {\n\t\t\t\t\treturn passed ? \"✅\" : \"🚫\";\n\t\t\t\t}\n\t\t\t\tif (key === \"file\") {\n\t\t\t\t\treturn name.replaceAll(\"<\", \"[\").replaceAll(\">\", \"]\");\n\t\t\t\t}\n\t\t\t\tif (key === \"size\") {\n\t\t\t\t\treturn `${bytes(size, {\n\t\t\t\t\t\tunitSeparator: \" \",\n\t\t\t\t\t})}${diff}`;\n\t\t\t\t}\n\t\t\t\tif (key === \"limits\") {\n\t\t\t\t\treturn limit;\n\t\t\t\t}\n\t\t\t\treturn \"\";\n\t\t\t})\n\t\t\t.filter((item: string) => item !== \"\");\n\n\t\treturn `| ${row.join(\" | \")} |`;\n\t}\n};\n"],"names":["join","zlib","bytes","fs","semver","STDOUT","IGNORE","HASH_KEY","SEMVER_KEY","GLOB_HASH","GLOB_SEMVER","CWD","process","cwd","gzipSizeFromFileSync","file","gzipSync","readFileSync","length","getOutputFile","undefined","validateConfigurationFile","result","exitCode","exitMessage","data","configurationFile","startsWith","existsSync","readJSONFile","readJsonSync","error","message","getMostRecentVersion","keys","key","Object","push","sort","rcompare","percentFormatter","value","formatter","Intl","NumberFormat","style","signDisplay","minimumFractionDigits","maximumFractionDigits","format","formatFooter","limitReached","overallDiff","totalGzipSize","percentageDiff","totalGzipSizeString","unitSeparator","overallDiffString","Math","abs","trim","addMDrow","type","passed","name","size","diff","limit","columns","totalColumns","separator","repeat","header","map","column","row","replaceAll","filter","item"],"
|
|
1
|
+
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import { join } from \"node:path\";\nimport zlib from \"node:zlib\";\nimport bytes from \"bytes\";\nimport fs from \"fs-extra\";\nimport semver from \"semver\";\n\nexport const STDOUT = \"stdout\";\nexport const IGNORE = \"ignore\";\nexport const HASH_KEY = \"<hash>\";\nexport const SEMVER_KEY = \"<semver>\";\nexport const GLOB_HASH = \"+([a-zA-Z0-9_-])\";\nexport const GLOB_SEMVER = \"+([0-9]).+([0-9]).+([0-9])*([.a-zA-Z0-9_-])\";\n\nconst CWD = process.cwd();\n\nexport const gzipSizeFromFileSync = (file: string): number => {\n\treturn zlib.gzipSync(fs.readFileSync(file)).length;\n};\n\nexport const getOutputFile = (file: string): string => {\n\treturn file === \"\" || file === undefined ? STDOUT : join(CWD, file);\n};\n\nexport const validateConfigurationFile = (file: string): any => {\n\tconst result = {\n\t\texitCode: 0,\n\t\texitMessage: \"\",\n\t\tdata: {},\n\t};\n\tif (file === \"\") {\n\t\tresult.exitMessage = \"Please provide a configuration file\";\n\t\tresult.exitCode = 1;\n\t\treturn result;\n\t}\n\n\tconst configurationFile = file.startsWith(\"/\") ? file : join(CWD, file);\n\n\tif (fs.existsSync(configurationFile) === false) {\n\t\tresult.exitMessage = `Invalid or missing configuration file!\\n${configurationFile}`;\n\t\tresult.exitCode = 1;\n\t\treturn result;\n\t}\n\n\treturn {\n\t\t...result,\n\t\tdata: configurationFile,\n\t};\n};\n\nexport const readJSONFile = (file: string): any => {\n\ttry {\n\t\treturn {\n\t\t\texitCode: 0,\n\t\t\texitMessage: \"\",\n\t\t\tdata: fs.readJsonSync(file),\n\t\t};\n\t} catch (error) {\n\t\treturn {\n\t\t\texitCode: 1,\n\t\t\texitMessage: `Failed to read JSON file: ${error.message}`,\n\t\t};\n\t}\n};\n\nexport const getMostRecentVersion = (data: []) => {\n\tconst keys = [];\n\tfor (const key of Object.keys(data)) {\n\t\tkeys.push(key);\n\t}\n\tkeys.sort(semver.rcompare);\n\treturn keys[0];\n};\n\nexport const percentFormatter = (value: number) => {\n\tconst formatter = new Intl.NumberFormat(\"en\", {\n\t\tstyle: \"percent\",\n\t\tsignDisplay: \"exceptZero\",\n\t\tminimumFractionDigits: 2,\n\t\tmaximumFractionDigits: 2,\n\t});\n\treturn formatter.format(value);\n};\n\nexport type FooterProperties = {\n\tlimitReached: boolean;\n\toverallDiff: number;\n\ttotalGzipSize: number;\n};\nexport const formatFooter = ({\n\tlimitReached,\n\toverallDiff,\n\ttotalGzipSize,\n}: FooterProperties) => {\n\tlet percentageDiff = \"\";\n\tconst result = [];\n\n\tconst totalGzipSizeString = `${bytes(totalGzipSize || 0, {\n\t\tunitSeparator: \" \",\n\t})}`;\n\n\tpercentageDiff = percentFormatter(\n\t\toverallDiff / (totalGzipSize - overallDiff),\n\t);\n\tconst overallDiffString =\n\t\t!overallDiff || overallDiff === 0\n\t\t\t? \"\"\n\t\t\t: `(${overallDiff > 0 ? \"+\" : \"-\"}${bytes(Math.abs(overallDiff), {\n\t\t\t\t\tunitSeparator: \" \",\n\t\t\t\t})} ${percentageDiff})`;\n\n\tresult.push(\n\t\t`Overall bundle size: ${totalGzipSizeString} ${overallDiffString}`.trim(),\n\t\t`Overall status: ${limitReached ? \"🚫\" : \"✅\"}`,\n\t);\n\n\treturn `${result.join(\"\\n\")}`;\n};\n\nexport const addMDrow = ({\n\ttype,\n\tpassed = true,\n\tname = \"\",\n\tsize = 0,\n\tdiff = \"\",\n\tlimit = \"\",\n\tcolumns,\n}: {\n\tcolumns: any;\n\ttype: \"header\" | \"row\";\n\tpassed?: boolean;\n\tname?: string;\n\tsize?: number;\n\tdiff?: string;\n\tlimit?: string;\n}) => {\n\tconst totalColumns = columns.length;\n\n\tif (type === \"header\") {\n\t\tconst separator = \" --- |\".repeat(totalColumns);\n\t\tconst header = columns.map((column) => column[Object.keys(column)[0]]);\n\t\treturn `| ${header.join(\" | \")} |\\n|${separator}`;\n\t}\n\tif (type === \"row\") {\n\t\tconst row = columns\n\t\t\t.map((column: Record<string, any>) => {\n\t\t\t\tconst key = Object.keys(column)[0];\n\t\t\t\tif (key === \"status\") {\n\t\t\t\t\treturn passed ? \"✅\" : \"🚫\";\n\t\t\t\t}\n\t\t\t\tif (key === \"file\") {\n\t\t\t\t\treturn name.replaceAll(\"<\", \"[\").replaceAll(\">\", \"]\");\n\t\t\t\t}\n\t\t\t\tif (key === \"size\") {\n\t\t\t\t\treturn `${bytes(size, {\n\t\t\t\t\t\tunitSeparator: \" \",\n\t\t\t\t\t})}${diff}`;\n\t\t\t\t}\n\t\t\t\tif (key === \"limits\") {\n\t\t\t\t\treturn limit;\n\t\t\t\t}\n\t\t\t\treturn \"\";\n\t\t\t})\n\t\t\t.filter((item: string) => item !== \"\");\n\n\t\treturn `| ${row.join(\" | \")} |`;\n\t}\n};\n"],"names":["join","zlib","bytes","fs","semver","STDOUT","IGNORE","HASH_KEY","SEMVER_KEY","GLOB_HASH","GLOB_SEMVER","CWD","process","cwd","gzipSizeFromFileSync","file","gzipSync","readFileSync","length","getOutputFile","undefined","validateConfigurationFile","result","exitCode","exitMessage","data","configurationFile","startsWith","existsSync","readJSONFile","readJsonSync","error","message","getMostRecentVersion","keys","key","Object","push","sort","rcompare","percentFormatter","value","formatter","Intl","NumberFormat","style","signDisplay","minimumFractionDigits","maximumFractionDigits","format","formatFooter","limitReached","overallDiff","totalGzipSize","percentageDiff","totalGzipSizeString","unitSeparator","overallDiffString","Math","abs","trim","addMDrow","type","passed","name","size","diff","limit","columns","totalColumns","separator","repeat","header","map","column","row","replaceAll","filter","item"],"mappings":"AAAA,SAASA,IAAI,QAAQ,YAAY;AACjC,OAAOC,UAAU,YAAY;AAC7B,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,QAAQ,WAAW;AAC1B,OAAOC,YAAY,SAAS;AAE5B,OAAO,MAAMC,SAAS,SAAS;AAC/B,OAAO,MAAMC,SAAS,SAAS;AAC/B,OAAO,MAAMC,WAAW,SAAS;AACjC,OAAO,MAAMC,aAAa,WAAW;AACrC,OAAO,MAAMC,YAAY,mBAAmB;AAC5C,OAAO,MAAMC,cAAc,8CAA8C;AAEzE,MAAMC,MAAMC,QAAQC,GAAG;AAEvB,OAAO,MAAMC,uBAAuB,CAACC;IACpC,OAAOd,KAAKe,QAAQ,CAACb,GAAGc,YAAY,CAACF,OAAOG,MAAM;AACnD,EAAE;AAEF,OAAO,MAAMC,gBAAgB,CAACJ;IAC7B,OAAOA,SAAS,MAAMA,SAASK,YAAYf,SAASL,KAAKW,KAAKI;AAC/D,EAAE;AAEF,OAAO,MAAMM,4BAA4B,CAACN;IACzC,MAAMO,SAAS;QACdC,UAAU;QACVC,aAAa;QACbC,MAAM,CAAC;IACR;IACA,IAAIV,SAAS,IAAI;QAChBO,OAAOE,WAAW,GAAG;QACrBF,OAAOC,QAAQ,GAAG;QAClB,OAAOD;IACR;IAEA,MAAMI,oBAAoBX,KAAKY,UAAU,CAAC,OAAOZ,OAAOf,KAAKW,KAAKI;IAElE,IAAIZ,GAAGyB,UAAU,CAACF,uBAAuB,OAAO;QAC/CJ,OAAOE,WAAW,GAAG,CAAC,wCAAwC,EAAEE,kBAAkB,CAAC;QACnFJ,OAAOC,QAAQ,GAAG;QAClB,OAAOD;IACR;IAEA,OAAO;QACN,GAAGA,MAAM;QACTG,MAAMC;IACP;AACD,EAAE;AAEF,OAAO,MAAMG,eAAe,CAACd;IAC5B,IAAI;QACH,OAAO;YACNQ,UAAU;YACVC,aAAa;YACbC,MAAMtB,G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": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"description": "Simple CLI tool that checks file(s) size and report if limits have been reached",
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"@node-cli/parser": "2.3.4",
|
|
32
32
|
"bytes": "3.1.2",
|
|
33
33
|
"fs-extra": "11.2.0",
|
|
34
|
-
"glob": "10.3
|
|
34
|
+
"glob": "10.4.3",
|
|
35
35
|
"semver": "7.6.2"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "58234dbb1fc3092ca08e908ee2116a0eaeac84db"
|
|
41
41
|
}
|