@node-cli/bundlesize 4.0.3 → 4.1.0

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 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
- sizes: [
39
- {
40
- path: "dist/some-bundle.js",
41
- limit: "10 kB",
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
- 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
- ],
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
- 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
- ],
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 be used in conjunction with the single star (\*) glob pattern, and it cannot be used if multiple files match the pattern.
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/**/some-bundle-<hash>.js` | If multiple files match the pattern |
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 in conjunction with the single star (\*) glob pattern, and it cannot be used if multiple files match the pattern.
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/**/some-bundle-<semver>.js` | If multiple files match the pattern |
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
- report: {
116
- prev: "stats/previous.json",
117
- current: "stats/current.json",
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
- report: {
127
- header: "## My custom header",
128
- prev: "stats/previous.json",
129
- current: "stats/current.json",
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
- report: {
139
- footer: (limitReached, diff) => {
140
- return `## My custom footer: ${limitReached} ${diff}`;
141
- },
142
- prev: "stats/previous.json",
143
- current: "stats/current.json",
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
- report: {
153
- columns: [
154
- { status: "Status" },
155
- { file: "File" },
156
- { size: "Size" },
157
- { limits: "Limits" },
158
- ],
159
- prev: "stats/previous.json",
160
- current: "stats/current.json",
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
 
@@ -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 && hasHash) {
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 when using the special keyword ${HASH_KEY}.`;
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){
@@ -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\t/**\n\t\t * if the artifact.path has the string <hash> or <semver> 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 || hasSemver) && /(?<!\\*)\\*(?!\\*)/.test(artifact.path)) {\n\t\t\tresult.exitCode = 1;\n\t\t\tresult.exitMessage = `Invalid path: ${\n\t\t\t\tartifact.path\n\t\t\t}.\\nSingle stars (*) are not allowed when using the special keyword ${\n\t\t\t\thasHash ? HASH_KEY : SEMVER_KEY\n\t\t\t}`;\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 && 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_KEY}.`;\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","test","location","replace","fileGlob","files","sync","length","file","fileSize","size","fileSizeGzip","passed","limit","index","existingResults","readJsonSync","force","silent","Number"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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,SAASC,QAAQ,QAAQ,UAAU;AACnC,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,QAAQ,WAAW;AAC1B,SAASC,IAAI,QAAQ,OAAO;AAgB5B,OAAO,MAAMC,cAAc,OAAO,EAAEC,KAAK,EAAE;IAC1C,MAAMC,SAAsB;QAC3BC,MAAM;QACNC,UAAU;QACVC,aAAa;QACbC,YAAY;QACZC,QAAQ;QACRC,MAAM,CAAC;IACR;IACA,IAAIC,SAAS;IACb,MAAMC,sBAAsBf,0BAA0BM,MAAMU,aAAa;IACzE,IAAID,oBAAoBL,WAAW,KAAK,IAAI;QAC3C,OAAO;YACN,GAAGH,MAAM;YACT,GAAGQ,mBAAmB;QACvB;IACD;IACA,MAAME,oBAAoBF,oBAAoBF,IAAI;IAClD,MAAMF,aAAab,cAAcQ,MAAMY,MAAM;I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,OAAOM,IAAI,GAAGkC;IACd,OAAOxC;AACR,EAAE"}
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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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,SAASC,QAAQ,QAAQ,UAAU;AACnC,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,QAAQ,WAAW;AAC1B,SAASC,IAAI,QAAQ,OAAO;AAgB5B,OAAO,MAAMC,cAAc,OAAO,EAAEC,KAA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BL,OAAOE,QAAQ,GAAGH,MAAM2C,MAAM,KAAK,OAAO,IAAIC,OAAOpC;IACrDP,OAAOM,IAAI,GAAGiC;IACd,OAAOvC;AACR,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-cli/bundlesize",
3
- "version": "4.0.3",
3
+ "version": "4.1.0",
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",
@@ -28,14 +28,14 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@node-cli/logger": "1.2.5",
31
- "@node-cli/parser": "2.3.3",
31
+ "@node-cli/parser": "2.3.4",
32
32
  "bytes": "3.1.2",
33
33
  "fs-extra": "11.2.0",
34
- "glob": "10.3.12",
35
- "semver": "7.6.0"
34
+ "glob": "10.3.15",
35
+ "semver": "7.6.2"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "d7d79f8f71fb3225e5a214aba3a42a89470d8340"
40
+ "gitHead": "4b5aa79113fcde92e5ad9d0dc8ebfaf9b703c2c9"
41
41
  }