@node-cli/bundlesize 2.1.4 → 2.1.5
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/dist/utilities.js +4 -1
- package/dist/utilities.js.map +1 -1
- package/package.json +3 -4
package/dist/utilities.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import bytes from "bytes";
|
|
2
2
|
import fs from "fs-extra";
|
|
3
3
|
import { glob } from "glob";
|
|
4
|
-
import { gzipSizeFromFileSync } from "gzip-size";
|
|
5
4
|
import path from "node:path";
|
|
6
5
|
import { statSync } from "node:fs";
|
|
6
|
+
import zlib from "node:zlib";
|
|
7
7
|
export const STDOUT = "stdout";
|
|
8
8
|
const CWD = process.cwd();
|
|
9
|
+
const gzipSizeFromFileSync = (file)=>{
|
|
10
|
+
return zlib.gzipSync(fs.readFileSync(file)).length;
|
|
11
|
+
};
|
|
9
12
|
export const reportStats = async ({ flags })=>{
|
|
10
13
|
const result = {
|
|
11
14
|
pass: true,
|
package/dist/utilities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import bytes from \"bytes\";\nimport fs from \"fs-extra\";\nimport { glob } from \"glob\";\nimport
|
|
1
|
+
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import bytes from \"bytes\";\nimport fs from \"fs-extra\";\nimport { glob } from \"glob\";\nimport path from \"node:path\";\nimport { statSync } from \"node:fs\";\nimport zlib from \"node:zlib\";\n\ntype Artifact = {\n\tpath: string;\n\tlimit: string;\n};\n\ntype ReportStats = {\n\tpass: boolean;\n\texitCode: number;\n\texitMessage: string;\n\toutputFile: string;\n\tprefix: string;\n\tdata: Record<string, unknown>;\n};\n\nexport const STDOUT = \"stdout\";\nconst CWD = process.cwd();\n\nconst gzipSizeFromFileSync = (file: string): number => {\n\treturn zlib.gzipSync(fs.readFileSync(file)).length;\n};\n\nexport const reportStats = async ({ flags }): Promise<ReportStats> => {\n\tconst result = {\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 configurationFile = flags.configuration.startsWith(\"/\")\n\t\t? flags.configuration\n\t\t: path.join(CWD, flags.configuration);\n\n\tconst outputFile =\n\t\tflags.output === \"\" || flags.output === undefined\n\t\t\t? STDOUT\n\t\t\t: path.join(CWD, flags.output);\n\tconst prefix = flags.prefix || \"0.0.0\";\n\tconst currentResults = {};\n\n\tif (flags.configuration === \"\") {\n\t\tresult.exitMessage = \"Please provide a configuration file\";\n\t\tresult.exitCode = 1;\n\t\treturn result;\n\t}\n\n\tif (fs.existsSync(configurationFile) === false) {\n\t\tresult.exitMessage = \"Invalid or missing configuration file!\";\n\t\tresult.exitCode = 1;\n\t\treturn result;\n\t}\n\tconst configuration: Artifact[] = await import(configurationFile).then(\n\t\t(m) => m.default,\n\t);\n\n\tfor (const artifact of configuration) {\n\t\tconst rootPath = artifact.path.startsWith(\"/\")\n\t\t\t? \"\"\n\t\t\t: path.dirname(configurationFile);\n\t\tconst artifactPath = path.dirname(artifact.path);\n\t\tconst globReplace = \"+([a-zA-Z0-9_-])\";\n\t\tconst hasHash = artifact.path.includes(\"<hash>\");\n\n\t\t/**\n\t\t * if the artifact.path has the string <hash> in it,\n\t\t * then we need to check for other characters:\n\t\t * - Double stars ** are allowed.\n\t\t * - Single stars * are not allowed.\n\t\t */\n\t\tif (hasHash && /(?<!\\*)\\*(?!\\*)/.test(artifact.path)) {\n\t\t\tresult.exitCode = 1;\n\t\t\tresult.exitMessage = `Invalid path: ${artifact.path}.\\nSingle stars (*) are not allowed when using the special keyword <hash>`;\n\t\t\treturn result;\n\t\t}\n\n\t\tconst fileGlob = path.join(\n\t\t\trootPath,\n\t\t\tartifact.path.replace(\"<hash>\", globReplace),\n\t\t);\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 && hasHash) {\n\t\t\tresult.exitCode = 1;\n\t\t\tresult.exitMessage = `Multiple files found for: ${artifact.path}.\\nPlease use a more specific path when using the special keyword <hash>.`;\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\tlet index = hasHash\n\t\t\t\t? artifact.path\n\t\t\t\t: path.join(artifactPath, path.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\texistingResults[prefix] = currentResults;\n\n\tresult.prefix = prefix;\n\tresult.outputFile = outputFile;\n\tresult.exitCode = failed && flags.silent === false ? 1 : 0;\n\tresult.data = existingResults;\n\treturn result;\n};\n"],"names":["bytes","fs","glob","path","statSync","zlib","STDOUT","CWD","process","cwd","gzipSizeFromFileSync","file","gzipSync","readFileSync","length","reportStats","flags","result","pass","exitCode","exitMessage","outputFile","prefix","data","failed","configurationFile","configuration","startsWith","join","output","undefined","currentResults","existsSync","then","m","default","artifact","rootPath","dirname","artifactPath","globReplace","hasHash","includes","test","fileGlob","replace","files","sync","fileSize","size","fileSizeGzip","passed","limit","index","basename","exist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gBACAE;gBACAE,OAAOhB,SAASgB,KAAK;gBACrBD;YACD;QACD;IACD;IAEA,IAAII,kBAAkB,CAAC;IACvB,IAAIlC,eAAef,QAAQ;QAC1B,IAAI;YACHiD,kBAAkBtD,GAAGuD,YAAY,CAACnC;QACnC,EAAE,OAAM;QACP;;;IAGC,GACF;IACD;IACAkC,eAAe,CAACjC,OAAO,GAAGS;IAE1Bd,OAAOK,MAAM,GAAGA;IAChBL,OAAOI,UAAU,GAAGA;IACpBJ,OAAOE,QAAQ,GAAGK,UAAUR,MAAMyC,MAAM,KAAK,QAAQ,IAAI;IACzDxC,OAAOM,IAAI,GAAGgC;IACd,OAAOtC;AACR,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-cli/bundlesize",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"license": "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,10 @@
|
|
|
31
31
|
"@node-cli/parser": ">=2.2.1",
|
|
32
32
|
"bytes": "3.1.2",
|
|
33
33
|
"fs-extra": "11.2.0",
|
|
34
|
-
"glob": "10.3.10"
|
|
35
|
-
"gzip-size": "7.0.0"
|
|
34
|
+
"glob": "10.3.10"
|
|
36
35
|
},
|
|
37
36
|
"publishConfig": {
|
|
38
37
|
"access": "public"
|
|
39
38
|
},
|
|
40
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "dbdff4d71abb37521597d5c8eb2aecc63d4d0d66"
|
|
41
40
|
}
|