@node-cli/bundlesize 2.1.2 → 2.1.3
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/bundlesize.js +1 -1
- package/dist/bundlesize.js.map +1 -1
- package/package.json +2 -2
package/dist/bundlesize.js
CHANGED
|
@@ -31,7 +31,7 @@ try {
|
|
|
31
31
|
for (const artifact of configuration){
|
|
32
32
|
const rootPath = artifact.path.startsWith("/") ? "" : path.dirname(configurationFile);
|
|
33
33
|
const artifactPath = path.dirname(artifact.path);
|
|
34
|
-
const globReplace = "+([a-zA-Z0-
|
|
34
|
+
const globReplace = "+([a-zA-Z0-9_-])";
|
|
35
35
|
const hasHash = artifact.path.includes("<hash>");
|
|
36
36
|
/**
|
|
37
37
|
* if the artifact.path has the string <hash> in it,
|
package/dist/bundlesize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bundlesize.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { Logger } from \"@node-cli/logger\";\nimport bytes from \"bytes\";\nimport { config } from \"./parse.js\";\nimport fs from \"fs-extra\";\nimport { glob } from \"glob\";\nimport { gzipSizeFromFileSync } from \"gzip-size\";\nimport path from \"node:path\";\nimport { statSync } from \"node:fs\";\n\nconst STDOUT = \"stdout\";\nconst CWD = process.cwd();\n\nconst flags = config.flags;\nconst configurationFile = path.join(CWD, flags.configuration);\nconst outputFile =\n\tflags.output === \"\" || flags.output === undefined\n\t\t? STDOUT\n\t\t: path.join(CWD, flags.output);\nconst prefix = flags.prefix || Date.now().toString();\nconst currentResults = {};\nconst log = new Logger({\n\tboring: flags.boring,\n});\n\nlet failed = false;\n\nif (flags.configuration === \"\") {\n\tlog.error(\"Please provide a configuration file\");\n\tprocess.exit(0);\n}\n\nif (fs.existsSync(configurationFile) === false) {\n\tlog.error(\"Invalid or missing configuration file!\");\n\tprocess.exit(0);\n}\n\ntry {\n\tconst configuration = await import(configurationFile).then((m) => m.default);\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-
|
|
1
|
+
{"version":3,"sources":["../src/bundlesize.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { Logger } from \"@node-cli/logger\";\nimport bytes from \"bytes\";\nimport { config } from \"./parse.js\";\nimport fs from \"fs-extra\";\nimport { glob } from \"glob\";\nimport { gzipSizeFromFileSync } from \"gzip-size\";\nimport path from \"node:path\";\nimport { statSync } from \"node:fs\";\n\nconst STDOUT = \"stdout\";\nconst CWD = process.cwd();\n\nconst flags = config.flags;\nconst configurationFile = path.join(CWD, flags.configuration);\nconst outputFile =\n\tflags.output === \"\" || flags.output === undefined\n\t\t? STDOUT\n\t\t: path.join(CWD, flags.output);\nconst prefix = flags.prefix || Date.now().toString();\nconst currentResults = {};\nconst log = new Logger({\n\tboring: flags.boring,\n});\n\nlet failed = false;\n\nif (flags.configuration === \"\") {\n\tlog.error(\"Please provide a configuration file\");\n\tprocess.exit(0);\n}\n\nif (fs.existsSync(configurationFile) === false) {\n\tlog.error(\"Invalid or missing configuration file!\");\n\tprocess.exit(0);\n}\n\ntry {\n\tconst configuration = await import(configurationFile).then((m) => m.default);\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\tlog.error(`Invalid path: ${artifact.path}.`);\n\t\t\tlog.error(\n\t\t\t\t\"Single stars (*) are not allowed when using the special keyword <hash>\",\n\t\t\t);\n\t\t\tprocess.exit(1);\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\tlog.error(`File not found: ${fileGlob}`);\n\t\t\tprocess.exit(1);\n\t\t}\n\n\t\tif (files.length > 1 && hasHash) {\n\t\t\tlog.error(`Multiple files found for: ${artifact.path}.`);\n\t\t\tlog.error(\n\t\t\t\t\"Please use a more specific path when using the special keyword <hash>.\",\n\t\t\t);\n\t\t\tprocess.exit(1);\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\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// nothing to declare officer\n\t\t}\n\t}\n\texistingResults[prefix] = currentResults;\n\tif (outputFile !== STDOUT) {\n\t\tfs.outputJsonSync(outputFile, existingResults, { spaces: 2 });\n\t}\n\n\tif (outputFile === STDOUT) {\n\t\tlog.info(`Configuration: ${flags.configuration}`);\n\t\tlog.info(`Output: ${outputFile}`);\n\t\tlog.info(`Output prefix: ${prefix}`);\n\t\tlog.log(`\\n${JSON.stringify(currentResults, undefined, 2)}`);\n\t}\n} catch (error) {\n\tlog.error(error);\n\tprocess.exit(0);\n}\n\nif (failed && flags.silent === false) {\n\tprocess.exit(1);\n}\n"],"names":["Logger","bytes","config","fs","glob","gzipSizeFromFileSync","path","statSync","STDOUT","CWD","process","cwd","flags","configurationFile","join","configuration","outputFile","output","undefined","prefix","Date","now","toString","currentResults","log","boring","failed","error","exit","existsSync","then","m","default","artifact","rootPath","startsWith","dirname","artifactPath","globReplace","hasHash","includes","test","fileGlob","replace","files","sync","length","file","fileSize","size","fileSizeGzip","passed","limit","index","basename","existingResults","readJsonSync","outputJsonSync","spaces","info","JSON","stringify","silent"],"mappings":";AAEA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,WAAW,QAAQ;AAC1B,SAASC,MAAM,QAAQ,aAAa;AACpC,OAAOC,QAAQ,WAAW;AAC1B,SAASC,IAAI,QAAQ,OAAO;AAC5B,SAASC,oBAAoB,QAAQ,YAAY;AACjD,OAAOC,UAAU,YAAY;AAC7B,SAASC,QAAQ,QAAQ,UAAU;AAEnC,MAAMC,SAAS;AACf,MAAMC,MAAMC,QAAQC,GAAG;AAEvB,MAAMC,QAAQV,OAAOU,KAAK;AAC1B,MAAMC,oBAAoBP,KAAKQ,IAAI,CAACL,KAAKG,MAAMG,aAAa;AAC5D,MAAMC,aACLJ,MAAMK,MAAM,KAAK,MAAML,MAAMK,MAAM,KAAKC,YACrCV,SACAF,KAAKQ,IAAI,CAACL,KAAKG,MAAMK,MAAM;AAC/B,MAAME,SAASP,MAAMO,MAAM,IAAIC,KAAKC,GAAG,GAAGC,QAAQ;AAClD,MAAMC,iBAAiB,CAAC;AACxB,MAAMC,MAAM,IAAIxB,OAAO;IACtByB,QAAQb,MAAMa,MAAM;AACrB;AAEA,IAAIC,SAAS;AAEb,IAAId,MAAMG,aAAa,KAAK,IAAI;IAC/BS,IAAIG,KAAK,CAAC;IACVjB,QAAQkB,IAAI,CAAC;AACd;AAEA,IAAI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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",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "f06dabbcc61bc716bfe0a8d2cfd61e9412b0edae"
|
|
37
37
|
}
|