@node-cli/bundlesize 4.2.1 → 4.2.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 +3 -3
- package/dist/bundlesize.js.map +1 -1
- package/dist/defaults.js +2 -2
- package/dist/defaults.js.map +1 -1
- package/dist/getRawStats.js +5 -5
- package/dist/getRawStats.js.map +1 -1
- package/dist/parse.js +3 -3
- package/dist/parse.js.map +1 -1
- package/dist/reportStats.js +2 -2
- package/dist/reportStats.js.map +1 -1
- package/dist/utilities.js.map +1 -1
- package/package.json +19 -11
package/dist/bundlesize.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/*
|
|
3
|
-
import { Logger } from "@node-cli/logger";
|
|
2
|
+
/* v8 ignore start */ import { Logger } from "@node-cli/logger";
|
|
4
3
|
import fs from "fs-extra";
|
|
5
4
|
import { getRawStats } from "./getRawStats.js";
|
|
6
5
|
import { config } from "./parse.js";
|
|
7
6
|
import { reportStats } from "./reportStats.js";
|
|
7
|
+
import { IGNORE, STDOUT } from "./utilities.js";
|
|
8
8
|
const flags = config.flags;
|
|
9
9
|
const log = new Logger({
|
|
10
10
|
boring: flags.boring
|
|
@@ -70,6 +70,6 @@ if (flags.type === "report") {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
log.error("Invalid type, please use 'size' or 'report'");
|
|
73
|
-
process.exit(1);
|
|
73
|
+
process.exit(1); /* v8 ignore stop */
|
|
74
74
|
|
|
75
75
|
//# sourceMappingURL=bundlesize.js.map
|
package/dist/bundlesize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bundlesize.ts"],"sourcesContent":["#!/usr/bin/env node\n/*
|
|
1
|
+
{"version":3,"sources":["../src/bundlesize.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/* v8 ignore start */\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\";\nimport { IGNORE, STDOUT } from \"./utilities.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/* v8 ignore stop */\n"],"names":["Logger","fs","getRawStats","config","reportStats","IGNORE","STDOUT","flags","log","boring","type","result","outputFile","process","exit","exitCode","exitMessage","error","info","configuration","prefix","data","outputJsonSync","spaces","message","outputFileSync"],"mappings":";AAEA,mBAAmB,GAEnB,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,QAAQ,WAAW;AAC1B,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,MAAM,EAAEC,MAAM,QAAQ,iBAAiB;AAEhD,MAAMC,QAAQJ,OAAOI,KAAK;AAE1B,MAAMC,MAAM,IAAIR,OAAO;IACtBS,QAAQF,MAAME,MAAM;AACrB;AAEA,IAAIF,MAAMG,IAAI,KAAK,QAAQ;IAC1B,IAAI;QACH,MAAMC,SAAS,MAAMT,YAAY;YAAEK;QAAM;QAEzC,IAAII,OAAOC,UAAU,KAAKP,QAAQ;YACjCQ,QAAQC,IAAI,CAACH,OAAOI,QAAQ;QAC7B;QAEA,IAAIJ,OAAOK,WAAW,KAAK,IAAI;YAC9BR,IAAIS,KAAK,CAACN,OAAOK,WAAW;YAC5BH,QAAQC,IAAI,CAACH,OAAOI,QAAQ;QAC7B;QAEA,IAAIJ,OAAOC,UAAU,KAAKN,QAAQ;YACjCE,IAAIU,IAAI,CAAC,CAAC,eAAe,EAAEX,MAAMY,aAAa,EAAE;YAChDX,IAAIU,IAAI,CAAC,CAAC,QAAQ,EAAEP,OAAOC,UAAU,EAAE;YACvCJ,IAAIU,IAAI,CAAC,CAAC,eAAe,EAAEP,OAAOS,MAAM,EAAE;YAC1CZ,IAAIA,GAAG,CAACG,OAAOU,IAAI;QACpB,OAAO;YACN,IAAI;gBACHpB,GAAGqB,cA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
|
-
/*
|
|
1
|
+
/* v8 ignore start */ export const defaultFlags = {
|
|
2
2
|
boring: false,
|
|
3
3
|
configuration: "",
|
|
4
4
|
silent: false,
|
|
5
5
|
type: "size",
|
|
6
6
|
force: false
|
|
7
|
-
};
|
|
7
|
+
}; /* v8 ignore stop */
|
|
8
8
|
|
|
9
9
|
//# sourceMappingURL=defaults.js.map
|
package/dist/defaults.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["/*
|
|
1
|
+
{"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["/* v8 ignore start */\n\nexport const defaultFlags = {\n\tboring: false,\n\tconfiguration: \"\",\n\tsilent: false,\n\ttype: \"size\",\n\tforce: false,\n};\n/* v8 ignore stop */\n"],"names":["defaultFlags","boring","configuration","silent","type","force"],"mappings":"AAAA,mBAAmB,GAEnB,OAAO,MAAMA,eAAe;IAC3BC,QAAQ;IACRC,eAAe;IACfC,QAAQ;IACRC,MAAM;IACNC,OAAO;AACR,EAAE,CACF,kBAAkB"}
|
package/dist/getRawStats.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { basename, dirname, join } from "node:path";
|
|
2
|
-
import { GLOB_HASH, GLOB_SEMVER, HASH_KEY, IGNORE, SEMVER_KEY, STDOUT, getOutputFile, gzipSizeFromFileSync, validateConfigurationFile } from "./utilities.js";
|
|
3
1
|
import { statSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
4
3
|
import bytes from "bytes";
|
|
5
4
|
import fs from "fs-extra";
|
|
6
5
|
import { glob } from "glob";
|
|
6
|
+
import { GLOB_HASH, GLOB_SEMVER, getOutputFile, gzipSizeFromFileSync, HASH_KEY, IGNORE, SEMVER_KEY, STDOUT, validateConfigurationFile } from "./utilities.js";
|
|
7
7
|
export const getRawStats = async ({ flags })=>{
|
|
8
8
|
const result = {
|
|
9
9
|
pass: true,
|
|
@@ -84,10 +84,10 @@ export const getRawStats = async ({ flags })=>{
|
|
|
84
84
|
if (outputFile !== STDOUT) {
|
|
85
85
|
try {
|
|
86
86
|
existingResults = fs.readJsonSync(outputFile);
|
|
87
|
-
} catch {
|
|
87
|
+
/* v8 ignore next 6 */ } catch {
|
|
88
88
|
/**
|
|
89
|
-
* There are no existing results, so we can ignore this error,
|
|
90
|
-
*
|
|
89
|
+
* There are no existing results, so we can ignore this error, and simply
|
|
90
|
+
* write the current results to the output file.
|
|
91
91
|
*/ }
|
|
92
92
|
}
|
|
93
93
|
/**
|
package/dist/getRawStats.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/getRawStats.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../src/getRawStats.ts"],"sourcesContent":["import { statSync } from \"node:fs\";\nimport { basename, dirname, join } from \"node:path\";\nimport bytes from \"bytes\";\nimport fs from \"fs-extra\";\nimport { glob } from \"glob\";\nimport {\n\tGLOB_HASH,\n\tGLOB_SEMVER,\n\tgetOutputFile,\n\tgzipSizeFromFileSync,\n\tHASH_KEY,\n\tIGNORE,\n\tSEMVER_KEY,\n\tSTDOUT,\n\tvalidateConfigurationFile,\n} from \"./utilities.js\";\n\ntype SizesConfiguration = {\n\tlimit: string;\n\tpath: string;\n\talias?: 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\n\t\t\tlet 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\t\t\tif (artifact.alias) {\n\t\t\t\tindex = artifact.alias;\n\t\t\t}\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\t/* v8 ignore next 6 */\n\t\t} catch {\n\t\t\t/**\n\t\t\t * There are no existing results, so we can ignore this error, and simply\n\t\t\t * 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":["statSync","basename","dirname","join","bytes","fs","glob","GLOB_HASH","GLOB_SEMVER","getOutputFile","gzipSizeFromFileSync","HASH_KEY","IGNORE","SEMVER_KEY","STDOUT","validateConfigurationFile","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","alias","existingResults","readJsonSync","force","silent","Number"],"mappings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,OAAOnB,SAASmB,KAAK;gBACrBD;YACD;QACD;IACD;IAEA,IAAII,kBAAkB,CAAC;IACvB,IAAIpC,eAAeR,QAAQ;QAC1B,IAAI;YACH4C,kBAAkBrD,GAAGsD,YAAY,CAACrC;QAClC,oBAAoB,GACrB,EAAE,OAAM;QACP;;;IAGC,GACF;IACD;IAEA;;;;;EAKC,GACD,IAAIoC,eAAe,CAACnC,OAAO,KAAKY,aAAalB,MAAM2C,KAAK,KAAK,OAAO;QACnE1C,OAAOI,UAAU,GAAGV;IACrB,OAAO;QACNM,OAAOI,UAAU,GAAGA;QACpBoC,eAAe,CAACnC,OAAO,GAAGO;IAC3B;IAEAZ,OAAOK,MAAM,GAAGA;IAChBL,OAAOE,QAAQ,GAAGH,MAAM4C,MAAM,KAAK,OAAO,IAAIC,OAAOrC;IACrDP,OAAOM,IAAI,GAAGkC;IACd,OAAOxC;AACR,EAAE"}
|
package/dist/parse.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { parser } from "@node-cli/parser";
|
|
1
|
+
/* v8 ignore start */ import { parser } from "@node-cli/parser";
|
|
2
2
|
import { defaultFlags } from "./defaults.js";
|
|
3
|
-
|
|
3
|
+
export const config = parser({
|
|
4
4
|
meta: import.meta,
|
|
5
5
|
examples: [],
|
|
6
6
|
flags: {
|
|
@@ -56,6 +56,6 @@ import { defaultFlags } from "./defaults.js";
|
|
|
56
56
|
},
|
|
57
57
|
usage: true,
|
|
58
58
|
defaultFlags
|
|
59
|
-
});
|
|
59
|
+
}); /* v8 ignore stop */
|
|
60
60
|
|
|
61
61
|
//# sourceMappingURL=parse.js.map
|
package/dist/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/parse.ts"],"sourcesContent":["/* v8 ignore start */\nimport { 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\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/* v8 ignore stop */\n"],"names":["parser","defaultFlags","config","meta","examples","flags","force","shortFlag","description","type","default","configuration","output","prefix","silent","boring","help","version","usage"],"mappings":"AAAA,mBAAmB,GACnB,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,YAAY,QAAQ,gBAAgB;AAoB7C,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,CACH,kBAAkB"}
|
package/dist/reportStats.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { basename, dirname, join } from "node:path";
|
|
2
|
-
import { addMDrow, formatFooter, getMostRecentVersion, getOutputFile, percentFormatter, readJSONFile, validateConfigurationFile } from "./utilities.js";
|
|
3
2
|
import bytes from "bytes";
|
|
3
|
+
import { addMDrow, formatFooter, getMostRecentVersion, getOutputFile, percentFormatter, readJSONFile, validateConfigurationFile } from "./utilities.js";
|
|
4
4
|
export const reportStats = async ({ flags })=>{
|
|
5
5
|
const result = {
|
|
6
6
|
exitCode: 0,
|
|
@@ -37,7 +37,7 @@ export const reportStats = async ({ flags })=>{
|
|
|
37
37
|
}
|
|
38
38
|
previousVersion = getMostRecentVersion(previousStats.data);
|
|
39
39
|
} catch {
|
|
40
|
-
// nothing to declare officer
|
|
40
|
+
// nothing to declare officer.
|
|
41
41
|
}
|
|
42
42
|
const currentVersion = getMostRecentVersion(currentStats.data);
|
|
43
43
|
let limitReached = false;
|
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\
|
|
1
|
+
{"version":3,"sources":["../src/reportStats.ts"],"sourcesContent":["import { basename, dirname, join } from \"node:path\";\nimport bytes from \"bytes\";\nimport type { FooterProperties } from \"./utilities.js\";\nimport {\n\taddMDrow,\n\tformatFooter,\n\tgetMostRecentVersion,\n\tgetOutputFile,\n\tpercentFormatter,\n\treadJSONFile,\n\tvalidateConfigurationFile,\n} 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","bytes","addMDrow","formatFooter","getMostRecentVersion","getOutputFile","percentFormatter","readJSONFile","validateConfigurationFile","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,OAAOC,WAAW,QAAQ;AAE1B,SACCC,QAAQ,EACRC,YAAY,EACZC,oBAAoB,EACpBC,aAAa,EACbC,gBAAg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,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"],"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,
|
|
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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AAI5B,QAAQ,QAAQ;gBACnB,OAAO6B,KAAKY,UAAU,CAAC,KAAK,KAAKA,UAAU,CAAC,KAAK;YAClD;YACA,IAAIzC,QAAQ,QAAQ;gBACnB,OAAO,GAAGjC,MAAM+D,MAAM;oBACrBT,eAAe;gBAChB,KAAKU,MAAM;YACZ;YACA,IAAI/B,QAAQ,UAAU;gBACrB,OAAOgC;YACR;YACA,OAAO;QACR,GACCU,MAAM,CAAC,CAACC,OAAiBA,SAAS;QAEpC,OAAO,CAAC,EAAE,EAAEH,IAAI3E,IAAI,CAAC,OAAO,EAAE,CAAC;IAChC;AACD,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-cli/bundlesize",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.3",
|
|
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",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"exports": "./dist/bundlesize.js",
|
|
10
10
|
"bin": "dist/bundlesize.js",
|
|
11
11
|
"files": [
|
|
12
|
-
"dist"
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md"
|
|
13
14
|
],
|
|
14
15
|
"node": ">=18",
|
|
15
16
|
"scripts": {
|
|
@@ -18,24 +19,31 @@
|
|
|
18
19
|
"build:js": "swc --strip-leading-paths --source-maps --out-dir dist src",
|
|
19
20
|
"build:types": "tsc",
|
|
20
21
|
"clean": "rimraf dist types coverage",
|
|
22
|
+
"comments:fix": "comments --merge-line-comments 'src/**/*.ts'",
|
|
21
23
|
"lint": "biome lint src",
|
|
24
|
+
"lint:fix": "biome check src --write --no-errors-on-unmatched",
|
|
22
25
|
"stats": "bundlesize -c bundlesize.config.js -p \"$npm_package_version\"",
|
|
23
26
|
"stats:diff": "bundlesize -t diff",
|
|
24
|
-
"test": "
|
|
25
|
-
"test:coverage": "
|
|
26
|
-
"test:watch": "
|
|
27
|
+
"test": "vitest run --globals",
|
|
28
|
+
"test:coverage": "vitest run --coverage --globals",
|
|
29
|
+
"test:watch": "vitest --globals",
|
|
27
30
|
"watch": "swc --strip-leading-paths --watch --out-dir dist src"
|
|
28
31
|
},
|
|
29
32
|
"dependencies": {
|
|
30
|
-
"@node-cli/logger": "
|
|
31
|
-
"@node-cli/parser": "
|
|
33
|
+
"@node-cli/logger": "../logger",
|
|
34
|
+
"@node-cli/parser": "../parser",
|
|
32
35
|
"bytes": "3.1.2",
|
|
33
|
-
"fs-extra": "11.
|
|
34
|
-
"glob": "
|
|
35
|
-
"semver": "7.
|
|
36
|
+
"fs-extra": "11.3.1",
|
|
37
|
+
"glob": "11.0.3",
|
|
38
|
+
"semver": "7.7.2"
|
|
36
39
|
},
|
|
37
40
|
"publishConfig": {
|
|
38
41
|
"access": "public"
|
|
39
42
|
},
|
|
40
|
-
"
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@node-cli/comments": "0.2.0",
|
|
45
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
46
|
+
"vitest": "3.2.4"
|
|
47
|
+
},
|
|
48
|
+
"gitHead": "d90392dcb766dd605bc3eeabc7c7a7ab0c8e6da6"
|
|
41
49
|
}
|