rollup-plugin-stats 1.4.3-beta.0 → 1.5.1-beta.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.
Files changed (47) hide show
  1. package/README.md +1 -0
  2. package/lib/cjs/extract.js +66 -0
  3. package/lib/cjs/extract.js.map +1 -0
  4. package/lib/cjs/index.js +41 -0
  5. package/lib/cjs/index.js.map +1 -0
  6. package/lib/cjs/package.json +1 -0
  7. package/lib/cjs/utils/check-exclude-filepath.js +30 -0
  8. package/lib/cjs/utils/check-exclude-filepath.js.map +1 -0
  9. package/lib/cjs/utils/format-file-size.js +37 -0
  10. package/lib/cjs/utils/format-file-size.js.map +1 -0
  11. package/lib/cjs/utils/omit.js +15 -0
  12. package/lib/cjs/utils/omit.js.map +1 -0
  13. package/lib/cjs/utils/round.js +9 -0
  14. package/lib/cjs/utils/round.js.map +1 -0
  15. package/lib/cjs/write.js +23 -0
  16. package/lib/cjs/write.js.map +1 -0
  17. package/lib/esm/extract.js +64 -0
  18. package/lib/esm/extract.js.map +1 -0
  19. package/{dist/index.mjs → lib/esm/index.js} +4 -50
  20. package/lib/esm/index.js.map +1 -0
  21. package/lib/esm/package.json +1 -0
  22. package/lib/esm/utils/check-exclude-filepath.js +28 -0
  23. package/lib/esm/utils/check-exclude-filepath.js.map +1 -0
  24. package/lib/esm/utils/format-file-size.js +35 -0
  25. package/lib/esm/utils/format-file-size.js.map +1 -0
  26. package/lib/esm/utils/omit.js +13 -0
  27. package/lib/esm/utils/omit.js.map +1 -0
  28. package/lib/esm/utils/round.js +7 -0
  29. package/lib/esm/utils/round.js.map +1 -0
  30. package/lib/esm/write.js +16 -0
  31. package/lib/esm/write.js.map +1 -0
  32. package/lib/types/extract.d.ts +48 -0
  33. package/{dist → lib/types}/utils/omit.d.ts +1 -1
  34. package/package.json +31 -25
  35. package/dist/extract.cjs +0 -96
  36. package/dist/extract.cjs.map +0 -1
  37. package/dist/extract.d.ts +0 -29
  38. package/dist/extract.mjs +0 -94
  39. package/dist/extract.mjs.map +0 -1
  40. package/dist/index.cjs +0 -82
  41. package/dist/index.cjs.map +0 -1
  42. package/dist/index.mjs.map +0 -1
  43. /package/{dist → lib/types}/index.d.ts +0 -0
  44. /package/{dist → lib/types}/utils/check-exclude-filepath.d.ts +0 -0
  45. /package/{dist → lib/types}/utils/format-file-size.d.ts +0 -0
  46. /package/{dist → lib/types}/utils/round.d.ts +0 -0
  47. /package/{dist → lib/types}/write.d.ts +0 -0
package/README.md CHANGED
@@ -90,6 +90,7 @@ export default defineConfig({
90
90
  - `write` - format and write the stats to disk(default: `fs.write(filename, JSON.stringify(stats, null, 2))`)
91
91
  - `stats`
92
92
  - `source` - output asset/chunk/module source (default `false`)
93
+ - `map` - output chunk map property (default: `false`)
93
94
  - `excludeAssets` - exclude matching assets: `string | RegExp | ((filepath: string) => boolean) | Array<string | RegExp | ((filepath: string) => boolean)>`
94
95
  - `excludeModules` - exclude matching modules: `string | RegExp | ((filepath: string) => boolean) | Array<string | RegExp | ((filepath: string) => boolean)>`
95
96
 
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ var omit = require('./utils/omit.js');
4
+ var checkExcludeFilepath = require('./utils/check-exclude-filepath.js');
5
+
6
+ /**
7
+ * Extract bundler stats
8
+ *
9
+ * Shallow clone stats object before any processing using `omit` to
10
+ * 1. resolve getters
11
+ * 2. prevent changes to the stats object
12
+ *
13
+ * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128
14
+ */
15
+ function extractRollupStats(bundle, options = {}) {
16
+ const { source = false, map = false, excludeAssets, excludeModules } = options;
17
+ const output = {};
18
+ Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {
19
+ // Skip extraction if the entry filepath matches the exclude assets pattern
20
+ if (checkExcludeFilepath.checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {
21
+ return;
22
+ }
23
+ if (bundleEntryStats.type === "asset") {
24
+ const assetStatsOmitKeys = [];
25
+ // Skip asset source if options.source is false
26
+ if (!source) {
27
+ assetStatsOmitKeys.push('source');
28
+ }
29
+ output[bundleEntryFilepath] = omit.omit(bundleEntryStats, assetStatsOmitKeys);
30
+ return;
31
+ }
32
+ if (bundleEntryStats.type === "chunk") {
33
+ const chunkStatsOmitKeys = [];
34
+ // Skip chunk source if options.source is false
35
+ if (!source) {
36
+ chunkStatsOmitKeys.push('code');
37
+ }
38
+ // Skip chunk map if options.map is false
39
+ if (!map) {
40
+ chunkStatsOmitKeys.push('map');
41
+ }
42
+ const chunkStats = omit.omit(bundleEntryStats, chunkStatsOmitKeys);
43
+ // Extract chunk modules stats
44
+ const chunkModulesStats = {};
45
+ Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {
46
+ // Skip module extraction if the filepath matches the exclude modules pattern
47
+ if (checkExcludeFilepath.checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {
48
+ return;
49
+ }
50
+ const moduleStatsOmitKeys = [];
51
+ // Skip module source if options.source is false
52
+ if (!source) {
53
+ moduleStatsOmitKeys.push('code');
54
+ }
55
+ chunkModulesStats[bundleModuleFilepath] = omit.omit(bundleModuleStats, moduleStatsOmitKeys);
56
+ });
57
+ chunkStats.modules = chunkModulesStats;
58
+ output[bundleEntryFilepath] = chunkStats;
59
+ return;
60
+ }
61
+ });
62
+ return output;
63
+ }
64
+
65
+ module.exports = extractRollupStats;
66
+ //# sourceMappingURL=extract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.js","sources":["../../../src/extract.ts"],"sourcesContent":[null],"names":["checkExcludeFilepath","omit"],"mappings":";;;;;AAgDA;;;;;;;;AAQG;AACW,SAAU,kBAAkB,CAAC,MAAoB,EAAE,UAAwB,EAAE,EAAA;AACzF,IAAA,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,GAAG,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,OAAO;IAE9E,MAAM,MAAM,GAAU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,iBAAiB,EACjB,mBAAmB,CACL;AAClB,YAAA,CAAC,CAAC;AAEF,YAAA,UAAU,CAAC,OAAO,GAAG,iBAAiB;AAEtC,YAAA,MAAM,CAAC,mBAAmB,CAAC,GAAG,UAAU;YAExC;QACF;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;;;;"}
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ var path = require('node:path');
4
+ var process = require('node:process');
5
+ var extract = require('./extract.js');
6
+ var write = require('./write.js');
7
+ var formatFileSize = require('./utils/format-file-size.js');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var path__default = /*#__PURE__*/_interopDefault(path);
12
+ var process__default = /*#__PURE__*/_interopDefault(process);
13
+
14
+ const PLUGIN_NAME = 'rollupStats';
15
+ const DEFAULT_FILE_NAME = 'stats.json';
16
+ function rollupStats(options = {}) {
17
+ return {
18
+ name: PLUGIN_NAME,
19
+ async generateBundle(context, bundle) {
20
+ const resolvedOptions = typeof options === 'function' ? options(context) : options;
21
+ const { fileName, stats: statsOptions, write: write$1 = write.rollupStatsWrite } = resolvedOptions || {};
22
+ const resolvedFileName = fileName || DEFAULT_FILE_NAME;
23
+ const filepath = path__default.default.isAbsolute(resolvedFileName)
24
+ ? resolvedFileName
25
+ : path__default.default.join(context.dir || process__default.default.cwd(), resolvedFileName);
26
+ const stats = extract(bundle, statsOptions);
27
+ try {
28
+ const res = await write$1(filepath, stats);
29
+ const outputSize = Buffer.byteLength(res.content, 'utf-8');
30
+ this.info(`Stats saved to ${res.filepath} (${formatFileSize.formatFileSize(outputSize)})`);
31
+ }
32
+ catch (error) { // eslint-disable-line
33
+ // Log error, but do not throw to allow the compilation to continue
34
+ this.warn(error);
35
+ }
36
+ },
37
+ };
38
+ }
39
+
40
+ module.exports = rollupStats;
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/index.ts"],"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CAAC;KACe;AACpB;;;;"}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Check if filepath should be excluded based on patterns
5
+ */
6
+ function checkExcludeFilepath(filepath, patterns) {
7
+ if (!patterns) {
8
+ return false;
9
+ }
10
+ if (Array.isArray(patterns)) {
11
+ let res = false;
12
+ for (let i = 0; i <= patterns.length - 1 && res === false; i++) {
13
+ res = checkExcludeFilepath(filepath, patterns[i]);
14
+ }
15
+ return res;
16
+ }
17
+ if (typeof patterns === 'function') {
18
+ return patterns(filepath);
19
+ }
20
+ if (typeof patterns === 'string') {
21
+ return Boolean(filepath.match(patterns));
22
+ }
23
+ if ('test' in patterns) {
24
+ return patterns.test(filepath);
25
+ }
26
+ return false;
27
+ }
28
+
29
+ exports.checkExcludeFilepath = checkExcludeFilepath;
30
+ //# sourceMappingURL=check-exclude-filepath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-exclude-filepath.js","sources":["../../../../src/utils/check-exclude-filepath.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAIA;;AAEG;AACG,SAAU,oBAAoB,CAClC,QAAgB,EAChB,QAAkC,EAAA;IAElC,IAAI,CAAC,QAAQ,EAAE;AACb,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,IAAI,GAAG,GAAG,KAAK;QAEf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC,EAAE,EAAE;YAC9D,GAAG,GAAG,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;QACnD;AAEA,QAAA,OAAO,GAAG;IACZ;AAEA,IAAA,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AAClC,QAAA,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B;AAEA,IAAA,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAChC,OAAO,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC1C;AAEA,IAAA,IAAI,MAAM,IAAI,QAAQ,EAAE;AACtB,QAAA,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;IAChC;AAEA,IAAA,OAAO,KAAK;AACd;;;;"}
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var round = require('./round.js');
4
+
5
+ const FILE_SIZE = {
6
+ BYTE: {
7
+ symbol: 'B',
8
+ multiplier: 1,
9
+ },
10
+ KILO: {
11
+ symbol: 'KiB',
12
+ multiplier: 1024,
13
+ },
14
+ MEGA: {
15
+ symbol: 'MiB',
16
+ multiplier: 1024 * 1024,
17
+ },
18
+ };
19
+ function formatFileSize(value) {
20
+ let unit = FILE_SIZE.BYTE;
21
+ if (typeof value !== 'number') {
22
+ return `0${unit.symbol}`;
23
+ }
24
+ if (value < FILE_SIZE.KILO.multiplier) {
25
+ unit = FILE_SIZE.BYTE;
26
+ }
27
+ else if (value < FILE_SIZE.MEGA.multiplier) {
28
+ unit = FILE_SIZE.KILO;
29
+ }
30
+ else {
31
+ unit = FILE_SIZE.MEGA;
32
+ }
33
+ return `${round.round(value / unit.multiplier, 2)}${unit.symbol}`;
34
+ }
35
+
36
+ exports.formatFileSize = formatFileSize;
37
+ //# sourceMappingURL=format-file-size.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-file-size.js","sources":["../../../../src/utils/format-file-size.ts"],"sourcesContent":[null],"names":["round"],"mappings":";;;;AAEA,MAAM,SAAS,GAAG;AAChB,IAAA,IAAI,EAAE;AACJ,QAAA,MAAM,EAAE,GAAG;AACX,QAAA,UAAU,EAAE,CAAC;AACd,KAAA;AACD,IAAA,IAAI,EAAE;AACJ,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,UAAU,EAAE,IAAI;AACjB,KAAA;AACD,IAAA,IAAI,EAAE;AACJ,QAAA,MAAM,EAAE,KAAK;QACb,UAAU,EAAE,IAAI,GAAG,IAAI;AACxB,KAAA;CACF;AAEK,SAAU,cAAc,CAAC,KAAqB,EAAA;AAClD,IAAA,IAAI,IAAI,GAAG,SAAS,CAAC,IAAI;AAEzB,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC7B,QAAA,OAAO,CAAA,CAAA,EAAI,IAAI,CAAC,MAAM,EAAE;IAC1B;IAEA,IAAI,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE;AACrC,QAAA,IAAI,GAAG,SAAS,CAAC,IAAI;IACvB;SAAO,IAAI,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE;AAC5C,QAAA,IAAI,GAAG,SAAS,CAAC,IAAI;IACvB;SAAO;AACL,QAAA,IAAI,GAAG,SAAS,CAAC,IAAI;IACvB;AAEA,IAAA,OAAO,GAAGA,WAAK,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA,EAAG,IAAI,CAAC,MAAM,EAAE;AAC7D;;;;"}
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ function omit(data, keys) {
4
+ const result = {};
5
+ const objectKeys = Object.keys(data);
6
+ objectKeys.forEach((key) => {
7
+ if (!keys.includes(key)) {
8
+ result[key] = data[key];
9
+ }
10
+ });
11
+ return result;
12
+ }
13
+
14
+ exports.omit = omit;
15
+ //# sourceMappingURL=omit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"omit.js","sources":["../../../../src/utils/omit.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAM,SAAU,IAAI,CAClB,IAAO,EACP,IAAS,EAAA;IAET,MAAM,MAAM,GAAG,EAAO;IACtB,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAa;AAEhD,IAAA,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACvB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC;QACzB;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;;;;"}
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ function round(value, precision = 2) {
4
+ const multiplier = 10 ^ precision;
5
+ return Math.round(value * multiplier) / multiplier;
6
+ }
7
+
8
+ exports.round = round;
9
+ //# sourceMappingURL=round.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"round.js","sources":["../../../../src/utils/round.ts"],"sourcesContent":[null],"names":[],"mappings":";;SAAgB,KAAK,CAAC,KAAa,EAAE,SAAS,GAAG,CAAC,EAAA;AAChD,IAAA,MAAM,UAAU,GAAG,EAAE,GAAG,SAAS;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,UAAU;AACpD;;;;"}
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ var path = require('node:path');
4
+ var fs = require('node:fs/promises');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var path__default = /*#__PURE__*/_interopDefault(path);
9
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
10
+
11
+ async function rollupStatsWrite(filepath, stats) {
12
+ const content = JSON.stringify(stats, null, 2);
13
+ // Create base directory if it does not exist
14
+ await fs__default.default.mkdir(path__default.default.dirname(filepath), { recursive: true });
15
+ await fs__default.default.writeFile(filepath, content);
16
+ return {
17
+ filepath,
18
+ content,
19
+ };
20
+ }
21
+
22
+ exports.rollupStatsWrite = rollupStatsWrite;
23
+ //# sourceMappingURL=write.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.js","sources":["../../../src/write.ts"],"sourcesContent":[null],"names":["fs","path"],"mappings":";;;;;;;;;;AAaO,eAAe,gBAAgB,CAEpC,QAAgB,EAAE,KAAQ,EAAA;AAC1B,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;;AAG9C,IAAA,MAAMA,mBAAE,CAAC,KAAK,CAACC,qBAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAE3D,MAAMD,mBAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC;IAErC,OAAO;QACL,QAAQ;QACR,OAAO;KACR;AACH;;;;"}
@@ -0,0 +1,64 @@
1
+ import { omit } from './utils/omit.js';
2
+ import { checkExcludeFilepath } from './utils/check-exclude-filepath.js';
3
+
4
+ /**
5
+ * Extract bundler stats
6
+ *
7
+ * Shallow clone stats object before any processing using `omit` to
8
+ * 1. resolve getters
9
+ * 2. prevent changes to the stats object
10
+ *
11
+ * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128
12
+ */
13
+ function extractRollupStats(bundle, options = {}) {
14
+ const { source = false, map = false, excludeAssets, excludeModules } = options;
15
+ const output = {};
16
+ Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {
17
+ // Skip extraction if the entry filepath matches the exclude assets pattern
18
+ if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {
19
+ return;
20
+ }
21
+ if (bundleEntryStats.type === "asset") {
22
+ const assetStatsOmitKeys = [];
23
+ // Skip asset source if options.source is false
24
+ if (!source) {
25
+ assetStatsOmitKeys.push('source');
26
+ }
27
+ output[bundleEntryFilepath] = omit(bundleEntryStats, assetStatsOmitKeys);
28
+ return;
29
+ }
30
+ if (bundleEntryStats.type === "chunk") {
31
+ const chunkStatsOmitKeys = [];
32
+ // Skip chunk source if options.source is false
33
+ if (!source) {
34
+ chunkStatsOmitKeys.push('code');
35
+ }
36
+ // Skip chunk map if options.map is false
37
+ if (!map) {
38
+ chunkStatsOmitKeys.push('map');
39
+ }
40
+ const chunkStats = omit(bundleEntryStats, chunkStatsOmitKeys);
41
+ // Extract chunk modules stats
42
+ const chunkModulesStats = {};
43
+ Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {
44
+ // Skip module extraction if the filepath matches the exclude modules pattern
45
+ if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {
46
+ return;
47
+ }
48
+ const moduleStatsOmitKeys = [];
49
+ // Skip module source if options.source is false
50
+ if (!source) {
51
+ moduleStatsOmitKeys.push('code');
52
+ }
53
+ chunkModulesStats[bundleModuleFilepath] = omit(bundleModuleStats, moduleStatsOmitKeys);
54
+ });
55
+ chunkStats.modules = chunkModulesStats;
56
+ output[bundleEntryFilepath] = chunkStats;
57
+ return;
58
+ }
59
+ });
60
+ return output;
61
+ }
62
+
63
+ export { extractRollupStats as default };
64
+ //# sourceMappingURL=extract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.js","sources":["../../../src/extract.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAgDA;;;;;;;;AAQG;AACW,SAAU,kBAAkB,CAAC,MAAoB,EAAE,UAAwB,EAAE,EAAA;AACzF,IAAA,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,GAAG,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,OAAO;IAE9E,MAAM,MAAM,GAAU,EAAE;AAExB,IAAA,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,KAAI;;AAEzE,QAAA,IAAI,oBAAoB,CAAC,mBAAmB,EAAE,aAAa,CAAC,EAAE;YAC5D;QACF;AAEA,QAAA,IAAI,gBAAgB,CAAC,IAAI,KAAK,OAAO,EAAE;YACrC,MAAM,kBAAkB,GAA8C,EAAE;;YAGxE,IAAI,CAAC,MAAM,EAAE;AACX,gBAAA,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC;YACnC;YAEA,MAAM,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAChC,gBAAgB,EAChB,kBAAkB,CACL;YAEf;QACF;AAEA,QAAA,IAAI,gBAAgB,CAAC,IAAI,KAAK,OAAO,EAAE;YACrC,MAAM,kBAAkB,GAA8C,EAAE;;YAGxE,IAAI,CAAC,MAAM,EAAE;AACX,gBAAA,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC;YACjC;;YAGA,IAAI,CAAC,GAAG,EAAE;AACR,gBAAA,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC;YAChC;YAEA,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB,EAAE,kBAAkB,CAAe;;YAI3E,MAAM,iBAAiB,GAA0B,EAAE;AAEnD,YAAA,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,oBAAoB,EAAE,iBAAiB,CAAC,KAAI;;AAEvF,gBAAA,IAAI,oBAAoB,CAAC,oBAAoB,EAAE,cAAc,CAAC,EAAE;oBAC9D;gBACF;gBAEA,MAAM,mBAAmB,GAA+C,EAAE;;gBAG1E,IAAI,CAAC,MAAM,EAAE;AACX,oBAAA,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC;gBAClC;gBAEA,iBAAiB,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAC5C,iBAAiB,EACjB,mBAAmB,CACL;AAClB,YAAA,CAAC,CAAC;AAEF,YAAA,UAAU,CAAC,OAAO,GAAG,iBAAiB;AAEtC,YAAA,MAAM,CAAC,mBAAmB,CAAC,GAAG,UAAU;YAExC;QACF;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;;;;"}
@@ -1,54 +1,8 @@
1
1
  import path from 'node:path';
2
2
  import process from 'node:process';
3
- import extractRollupStats from './extract.mjs';
4
- import fs from 'node:fs/promises';
5
-
6
- async function rollupStatsWrite(filepath, stats) {
7
- const content = JSON.stringify(stats, null, 2);
8
- // Create base directory if it does not exist
9
- await fs.mkdir(path.dirname(filepath), { recursive: true });
10
- await fs.writeFile(filepath, content);
11
- return {
12
- filepath,
13
- content,
14
- };
15
- }
16
-
17
- function round(value, precision = 2) {
18
- const multiplier = 10 ^ precision;
19
- return Math.round(value * multiplier) / multiplier;
20
- }
21
-
22
- const FILE_SIZE = {
23
- BYTE: {
24
- symbol: 'B',
25
- multiplier: 1,
26
- },
27
- KILO: {
28
- symbol: 'KiB',
29
- multiplier: 1024,
30
- },
31
- MEGA: {
32
- symbol: 'MiB',
33
- multiplier: 1024 * 1024,
34
- },
35
- };
36
- function formatFileSize(value) {
37
- let unit = FILE_SIZE.BYTE;
38
- if (typeof value !== 'number') {
39
- return `0${unit.symbol}`;
40
- }
41
- if (value < FILE_SIZE.KILO.multiplier) {
42
- unit = FILE_SIZE.BYTE;
43
- }
44
- else if (value < FILE_SIZE.MEGA.multiplier) {
45
- unit = FILE_SIZE.KILO;
46
- }
47
- else {
48
- unit = FILE_SIZE.MEGA;
49
- }
50
- return `${round(value / unit.multiplier, 2)}${unit.symbol}`;
51
- }
3
+ import extractRollupStats from './extract.js';
4
+ import { rollupStatsWrite } from './write.js';
5
+ import { formatFileSize } from './utils/format-file-size.js';
52
6
 
53
7
  const PLUGIN_NAME = 'rollupStats';
54
8
  const DEFAULT_FILE_NAME = 'stats.json';
@@ -77,4 +31,4 @@ function rollupStats(options = {}) {
77
31
  }
78
32
 
79
33
  export { rollupStats as default };
80
- //# sourceMappingURL=index.mjs.map
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAQA,MAAM,WAAW,GAAG,aAAa;AACjC,MAAM,iBAAiB,GAAG,YAAY;AAwBtC,SAAS,WAAW,CAAC,OAAA,GAA6C,EAAE,EAAA;IAClE,OAAO;AACL,QAAA,IAAI,EAAE,WAAW;AACjB,QAAA,MAAM,cAAc,CAAC,OAAO,EAAE,MAAM,EAAA;AAClC,YAAA,MAAM,eAAe,GAAG,OAAO,OAAO,KAAK,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO;AAClF,YAAA,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,GAAG,gBAAgB,EAAE,GAAG,eAAe,IAAI,EAAE;AAEzF,YAAA,MAAM,gBAAgB,GAAG,QAAQ,IAAI,iBAAiB;AACtD,YAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,gBAAgB;AAC/C,kBAAE;AACF,kBAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,gBAAgB,CAAC;YAE7D,MAAM,KAAK,GAAG,kBAAkB,CAAC,MAAM,EAAE,YAAY,CAAC;AAEtD,YAAA,IAAI;gBACF,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC;AACxC,gBAAA,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC;AAE1D,gBAAA,IAAI,CAAC,IAAI,CAAC,CAAA,eAAA,EAAkB,GAAG,CAAC,QAAQ,CAAA,EAAA,EAAK,cAAc,CAAC,UAAU,CAAC,CAAA,CAAA,CAAG,CAAC;YAC7E;AAAE,YAAA,OAAO,KAAU,EAAE;;AAEnB,gBAAA,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;YAClB;QACF,CAAC;KACe;AACpB;;;;"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Check if filepath should be excluded based on patterns
3
+ */
4
+ function checkExcludeFilepath(filepath, patterns) {
5
+ if (!patterns) {
6
+ return false;
7
+ }
8
+ if (Array.isArray(patterns)) {
9
+ let res = false;
10
+ for (let i = 0; i <= patterns.length - 1 && res === false; i++) {
11
+ res = checkExcludeFilepath(filepath, patterns[i]);
12
+ }
13
+ return res;
14
+ }
15
+ if (typeof patterns === 'function') {
16
+ return patterns(filepath);
17
+ }
18
+ if (typeof patterns === 'string') {
19
+ return Boolean(filepath.match(patterns));
20
+ }
21
+ if ('test' in patterns) {
22
+ return patterns.test(filepath);
23
+ }
24
+ return false;
25
+ }
26
+
27
+ export { checkExcludeFilepath };
28
+ //# sourceMappingURL=check-exclude-filepath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-exclude-filepath.js","sources":["../../../../src/utils/check-exclude-filepath.ts"],"sourcesContent":[null],"names":[],"mappings":"AAIA;;AAEG;AACG,SAAU,oBAAoB,CAClC,QAAgB,EAChB,QAAkC,EAAA;IAElC,IAAI,CAAC,QAAQ,EAAE;AACb,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,IAAI,GAAG,GAAG,KAAK;QAEf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC,EAAE,EAAE;YAC9D,GAAG,GAAG,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;QACnD;AAEA,QAAA,OAAO,GAAG;IACZ;AAEA,IAAA,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AAClC,QAAA,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B;AAEA,IAAA,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAChC,OAAO,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC1C;AAEA,IAAA,IAAI,MAAM,IAAI,QAAQ,EAAE;AACtB,QAAA,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC;IAChC;AAEA,IAAA,OAAO,KAAK;AACd;;;;"}
@@ -0,0 +1,35 @@
1
+ import { round } from './round.js';
2
+
3
+ const FILE_SIZE = {
4
+ BYTE: {
5
+ symbol: 'B',
6
+ multiplier: 1,
7
+ },
8
+ KILO: {
9
+ symbol: 'KiB',
10
+ multiplier: 1024,
11
+ },
12
+ MEGA: {
13
+ symbol: 'MiB',
14
+ multiplier: 1024 * 1024,
15
+ },
16
+ };
17
+ function formatFileSize(value) {
18
+ let unit = FILE_SIZE.BYTE;
19
+ if (typeof value !== 'number') {
20
+ return `0${unit.symbol}`;
21
+ }
22
+ if (value < FILE_SIZE.KILO.multiplier) {
23
+ unit = FILE_SIZE.BYTE;
24
+ }
25
+ else if (value < FILE_SIZE.MEGA.multiplier) {
26
+ unit = FILE_SIZE.KILO;
27
+ }
28
+ else {
29
+ unit = FILE_SIZE.MEGA;
30
+ }
31
+ return `${round(value / unit.multiplier, 2)}${unit.symbol}`;
32
+ }
33
+
34
+ export { formatFileSize };
35
+ //# sourceMappingURL=format-file-size.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-file-size.js","sources":["../../../../src/utils/format-file-size.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA,MAAM,SAAS,GAAG;AAChB,IAAA,IAAI,EAAE;AACJ,QAAA,MAAM,EAAE,GAAG;AACX,QAAA,UAAU,EAAE,CAAC;AACd,KAAA;AACD,IAAA,IAAI,EAAE;AACJ,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,UAAU,EAAE,IAAI;AACjB,KAAA;AACD,IAAA,IAAI,EAAE;AACJ,QAAA,MAAM,EAAE,KAAK;QACb,UAAU,EAAE,IAAI,GAAG,IAAI;AACxB,KAAA;CACF;AAEK,SAAU,cAAc,CAAC,KAAqB,EAAA;AAClD,IAAA,IAAI,IAAI,GAAG,SAAS,CAAC,IAAI;AAEzB,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC7B,QAAA,OAAO,CAAA,CAAA,EAAI,IAAI,CAAC,MAAM,EAAE;IAC1B;IAEA,IAAI,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE;AACrC,QAAA,IAAI,GAAG,SAAS,CAAC,IAAI;IACvB;SAAO,IAAI,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE;AAC5C,QAAA,IAAI,GAAG,SAAS,CAAC,IAAI;IACvB;SAAO;AACL,QAAA,IAAI,GAAG,SAAS,CAAC,IAAI;IACvB;AAEA,IAAA,OAAO,GAAG,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA,EAAG,IAAI,CAAC,MAAM,EAAE;AAC7D;;;;"}
@@ -0,0 +1,13 @@
1
+ function omit(data, keys) {
2
+ const result = {};
3
+ const objectKeys = Object.keys(data);
4
+ objectKeys.forEach((key) => {
5
+ if (!keys.includes(key)) {
6
+ result[key] = data[key];
7
+ }
8
+ });
9
+ return result;
10
+ }
11
+
12
+ export { omit };
13
+ //# sourceMappingURL=omit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"omit.js","sources":["../../../../src/utils/omit.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAM,SAAU,IAAI,CAClB,IAAO,EACP,IAAS,EAAA;IAET,MAAM,MAAM,GAAG,EAAO;IACtB,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAa;AAEhD,IAAA,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACvB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC;QACzB;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;;;;"}
@@ -0,0 +1,7 @@
1
+ function round(value, precision = 2) {
2
+ const multiplier = 10 ^ precision;
3
+ return Math.round(value * multiplier) / multiplier;
4
+ }
5
+
6
+ export { round };
7
+ //# sourceMappingURL=round.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"round.js","sources":["../../../../src/utils/round.ts"],"sourcesContent":[null],"names":[],"mappings":"SAAgB,KAAK,CAAC,KAAa,EAAE,SAAS,GAAG,CAAC,EAAA;AAChD,IAAA,MAAM,UAAU,GAAG,EAAE,GAAG,SAAS;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,UAAU;AACpD;;;;"}
@@ -0,0 +1,16 @@
1
+ import path from 'node:path';
2
+ import fs from 'node:fs/promises';
3
+
4
+ async function rollupStatsWrite(filepath, stats) {
5
+ const content = JSON.stringify(stats, null, 2);
6
+ // Create base directory if it does not exist
7
+ await fs.mkdir(path.dirname(filepath), { recursive: true });
8
+ await fs.writeFile(filepath, content);
9
+ return {
10
+ filepath,
11
+ content,
12
+ };
13
+ }
14
+
15
+ export { rollupStatsWrite };
16
+ //# sourceMappingURL=write.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.js","sources":["../../../src/write.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAaO,eAAe,gBAAgB,CAEpC,QAAgB,EAAE,KAAQ,EAAA;AAC1B,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;;AAG9C,IAAA,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAE3D,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC;IAErC,OAAO;QACL,QAAQ;QACR,OAAO;KACR;AACH;;;;"}
@@ -0,0 +1,48 @@
1
+ import type { OutputAsset, OutputBundle, OutputChunk, RenderedModule } from 'rollup';
2
+ import { type ExcludeFilepathPatterns } from './utils/check-exclude-filepath';
3
+ export type AssetStatsOptionalProperties = {
4
+ source?: OutputAsset['source'];
5
+ };
6
+ export type AssetStats = Omit<OutputAsset, keyof AssetStatsOptionalProperties> & AssetStatsOptionalProperties;
7
+ export type ModuleStatsOptionalProperties = {
8
+ code?: RenderedModule['code'] | null;
9
+ };
10
+ export type ModuleStats = Omit<RenderedModule, keyof ModuleStatsOptionalProperties> & ModuleStatsOptionalProperties;
11
+ export type ChunkStatsOptionalProperties = {
12
+ code?: OutputChunk['code'];
13
+ map?: OutputChunk['map'];
14
+ };
15
+ export type ChunkStats = Omit<OutputChunk, keyof ChunkStatsOptionalProperties | 'modules'> & {
16
+ modules: Record<string, ModuleStats>;
17
+ } & ChunkStatsOptionalProperties;
18
+ export type Stats = Record<string, AssetStats | ChunkStats>;
19
+ export type StatsOptions = {
20
+ /**
21
+ * Output asset/module sources
22
+ * @default false
23
+ */
24
+ source?: boolean;
25
+ /**
26
+ * Output chunk map
27
+ * @default false
28
+ */
29
+ map?: boolean;
30
+ /**
31
+ * Exclude matching assets
32
+ */
33
+ excludeAssets?: ExcludeFilepathPatterns;
34
+ /**
35
+ * Exclude matching modules
36
+ */
37
+ excludeModules?: ExcludeFilepathPatterns;
38
+ };
39
+ /**
40
+ * Extract bundler stats
41
+ *
42
+ * Shallow clone stats object before any processing using `omit` to
43
+ * 1. resolve getters
44
+ * 2. prevent changes to the stats object
45
+ *
46
+ * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128
47
+ */
48
+ export default function extractRollupStats(bundle: OutputBundle, options?: StatsOptions): Stats;
@@ -1 +1 @@
1
- export declare function omit<D extends object, K extends keyof D>(data: D, keys: K[]): Omit<D, K>;
1
+ export declare function omit<D extends object, K extends keyof D = keyof D>(data: D, keys: K[]): Omit<D, K>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rollup-plugin-stats",
3
3
  "description": "Output Rollup stats",
4
- "version": "1.4.3-beta.0",
4
+ "version": "1.5.1-beta.0",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "repository": {
@@ -24,36 +24,38 @@
24
24
  "stats",
25
25
  "bundle-stats"
26
26
  ],
27
- "main": "dist/index.cjs",
28
- "module": "dist/index.mjs",
29
- "typings": "dist/index.d.ts",
27
+ "main": "./lib/cjs/index.js",
28
+ "module": "./lib/esm/index.js",
29
+ "typings": "./lib/types/index.d.ts",
30
30
  "files": [
31
- "dist"
31
+ "lib"
32
32
  ],
33
33
  "exports": {
34
34
  ".": {
35
- "types": "./dist/index.d.ts",
36
- "import": "./dist/index.mjs",
37
- "require": "./dist/index.cjs"
35
+ "types": "./lib/types/index.d.ts",
36
+ "import": "./lib/esm/index.js",
37
+ "require": "./lib/cjs/index.js"
38
38
  },
39
39
  "./extract": {
40
- "types": "./dist/extract.d.ts",
41
- "import": "./dist/extract.mjs",
42
- "require": "./dist/extract.cjs"
40
+ "types": "./lib/types/extract.d.ts",
41
+ "import": "./lib/esm/extract.js",
42
+ "require": "./lib/cjs/extract.js"
43
43
  }
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=18"
47
47
  },
48
48
  "scripts": {
49
- "build": "rollup -c rollup.config.mjs",
49
+ "build": "npm run clean && rollup -c && npm run build-type",
50
+ "build-type": "echo '{\"type\":\"commonjs\"}' > lib/cjs/package.json && echo '{\"type\":\"module\"}' > lib/esm/package.json",
51
+ "clean": "rimraf ./lib",
50
52
  "lint": "eslint .",
51
53
  "format": "prettier --write .",
52
54
  "test:unit": "vitest test/unit",
53
55
  "test:package": "npm run test:package:rolldown && npm run test:package:rollup && npm run test:package:vite",
54
- "test:package:rolldown": "vitest test/package/rolldown",
55
- "test:package:rollup": "vitest test/package/rollup",
56
- "test:package:vite": "vitest test/package/vite",
56
+ "test:package:rolldown": "cd test/package/rolldown && npm run test",
57
+ "test:package:rollup": "cd test/package/rollup && npm run test",
58
+ "test:package:vite": "cd test/package/vite && npm run test",
57
59
  "bump": "./scripts/bump.sh",
58
60
  "release": "./scripts/release.sh"
59
61
  },
@@ -63,27 +65,31 @@
63
65
  }
64
66
  },
65
67
  "devDependencies": {
66
- "@eslint/js": "9.32.0",
68
+ "@eslint/js": "9.34.0",
67
69
  "@release-it/conventional-changelog": "10.0.1",
68
- "@rollup/plugin-typescript": "12.1.4",
70
+ "@rollup/plugin-commonjs": "^28.0.6",
71
+ "@rollup/plugin-node-resolve": "^16.0.1",
72
+ "@rollup/plugin-typescript": "^12.1.4",
69
73
  "@tsconfig/node18": "18.2.4",
70
- "@types/node": "24.1.0",
74
+ "@types/node": "24.3.0",
75
+ "deep-freeze-strict": "1.1.1",
71
76
  "dotenv": "17.2.1",
72
- "eslint": "9.32.0",
77
+ "eslint": "9.34.0",
73
78
  "globals": "16.3.0",
74
79
  "husky": "8.0.3",
75
- "memfs": "4.20.0",
80
+ "memfs": "4.38.2",
76
81
  "prettier": "3.6.2",
77
82
  "release-it": "19.0.4",
78
- "rollup": "4.45.1",
79
- "typescript": "5.8.3",
80
- "typescript-eslint": "8.38.0",
83
+ "rimraf": "6.0.1",
84
+ "rollup": "4.49.0",
85
+ "typescript": "5.9.2",
86
+ "typescript-eslint": "8.41.0",
81
87
  "vitest": "3.2.4"
82
88
  },
83
89
  "peerDependencies": {
84
- "vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
85
90
  "rolldown": "^1.0.0-beta.0",
86
- "rollup": "^3.0.0 || ^4.0.0"
91
+ "rollup": "^3.0.0 || ^4.0.0",
92
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
87
93
  },
88
94
  "peerDependenciesMeta": {
89
95
  "vite": {
package/dist/extract.cjs DELETED
@@ -1,96 +0,0 @@
1
- 'use strict';
2
-
3
- function omit(data, keys) {
4
- const result = {};
5
- const objectKeys = Object.keys(data);
6
- objectKeys.forEach((key) => {
7
- if (!keys.includes(key)) {
8
- result[key] = data[key];
9
- }
10
- });
11
- return result;
12
- }
13
-
14
- /**
15
- * Check if filepath should be excluded based on patterns
16
- */
17
- function checkExcludeFilepath(filepath, patterns) {
18
- if (!patterns) {
19
- return false;
20
- }
21
- if (Array.isArray(patterns)) {
22
- let res = false;
23
- for (let i = 0; i <= patterns.length - 1 && res === false; i++) {
24
- res = checkExcludeFilepath(filepath, patterns[i]);
25
- }
26
- return res;
27
- }
28
- if (typeof patterns === 'function') {
29
- return patterns(filepath);
30
- }
31
- if (typeof patterns === 'string') {
32
- return Boolean(filepath.match(patterns));
33
- }
34
- if ('test' in patterns) {
35
- return patterns.test(filepath);
36
- }
37
- return false;
38
- }
39
-
40
- function extractRollupStats(bundle, options = {}) {
41
- const { source = false, excludeAssets, excludeModules } = options;
42
- const output = {};
43
- Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {
44
- // Skip extraction if the entry filepath matches the exclude assets pattern
45
- if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {
46
- return;
47
- }
48
- if (bundleEntryStats.type === "asset") {
49
- let assetStats = shallowCloneStatsObject(bundleEntryStats);
50
- // Skip asset source if options.source is false
51
- if (!source) {
52
- assetStats = omit(assetStats, ['source']);
53
- }
54
- output[bundleEntryFilepath] = assetStats;
55
- return;
56
- }
57
- if (bundleEntryStats.type === "chunk") {
58
- let chunkStats = shallowCloneStatsObject(bundleEntryStats);
59
- // Skip chunk source if options.source is false
60
- if (!source) {
61
- chunkStats = omit(chunkStats, ['code']);
62
- }
63
- // Extract chunk modules stats
64
- const chunkModulesStats = {};
65
- Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {
66
- // Skip module extraction if the filepath matches the exclude modules pattern
67
- if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {
68
- return;
69
- }
70
- let moduleStats = shallowCloneStatsObject(bundleModuleStats);
71
- // Skip module source if options.source is false
72
- if (!source) {
73
- moduleStats = omit(moduleStats, ['code']);
74
- }
75
- chunkModulesStats[bundleModuleFilepath] = moduleStats;
76
- });
77
- chunkStats.modules = chunkModulesStats;
78
- output[bundleEntryFilepath] = chunkStats;
79
- return;
80
- }
81
- });
82
- return output;
83
- }
84
- /**
85
- * Shallow clone stats object before any processing to
86
- * 1. resolve getters
87
- * 2. prevent changes to the stats object
88
- *
89
- * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128
90
- */
91
- function shallowCloneStatsObject(data) {
92
- return { ...data };
93
- }
94
-
95
- module.exports = extractRollupStats;
96
- //# sourceMappingURL=extract.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extract.cjs","sources":["../src/utils/omit.ts","../src/utils/check-exclude-filepath.ts","../src/extract.ts"],"sourcesContent":[null,null,null],"names":[],"mappings":";;AAAM,SAAU,IAAI,CAClB,IAAO,EACP,IAAS,EAAA;IAET,MAAM,MAAM,GAAG,EAAO;IACtB,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAa;AAEhD,IAAA,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACvB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC;QACzB;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;;ACVA;;AAEG;AACG,SAAU,oBAAoB,CAClC,QAAgB,EAChB,QAAkC,EAAA;IAElC,IAAI,CAAC,QAAQ,EAAE;AACb,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,IAAI,GAAG,GAAG,KAAK;QAEf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC,EAAE,EAAE;YAC9D,GAAG,GAAG,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;QACnD;AAEA,QAAA,OAAO,GAAG;IACZ;AAEA,IAAA,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AAClC,QAAA,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC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,OAAO,CAAC,CAAC,CAAC,oBAAoB,EAAE,iBAAiB,CAAC,KAAI;;AAEvF,gBAAA,IAAI,oBAAoB,CAAC,oBAAoB,EAAE,cAAc,CAAC,EAAE;oBAC9D;gBACF;AAEA,gBAAA,IAAI,WAAW,GAAG,uBAAuB,CAAc,iBAAiB,CAAC;;gBAGzE,IAAI,CAAC,MAAM,EAAE;oBACX,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC;gBAC3C;AAEA,gBAAA,iBAAiB,CAAC,oBAAoB,CAAC,GAAG,WAAW;AACvD,YAAA,CAAC,CAAC;AAEF,YAAA,UAAU,CAAC,OAAO,GAAG,iBAAiB;AAEtC,YAAA,MAAM,CAAC,mBAAmB,CAAC,GAAG,UAAU;YAExC;QACF;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;AAEA;;;;;;AAMG;AACH,SAAS,uBAAuB,CAAU,IAAY,EAAA;AACpD,IAAA,OAAO,EAAC,GAAG,IAAI,EAAY;AAC7B;;;;"}
package/dist/extract.d.ts DELETED
@@ -1,29 +0,0 @@
1
- import type { OutputAsset, OutputBundle, OutputChunk, RenderedModule } from 'rollup';
2
- import { type ExcludeFilepathPatterns } from './utils/check-exclude-filepath';
3
- export type AssetStats = Omit<OutputAsset, 'source'> & {
4
- source?: OutputAsset['source'];
5
- };
6
- export type ModuleStats = Omit<RenderedModule, 'code'> & {
7
- code?: RenderedModule['code'] | null;
8
- };
9
- export type ChunkStats = Omit<OutputChunk, 'code' | 'modules'> & {
10
- code?: OutputChunk['code'];
11
- modules: Record<string, ModuleStats>;
12
- };
13
- export type Stats = Record<string, AssetStats | ChunkStats>;
14
- export type StatsOptions = {
15
- /**
16
- * Output asset/module sources
17
- * @default false
18
- */
19
- source?: boolean;
20
- /**
21
- * Exclude matching assets
22
- */
23
- excludeAssets?: ExcludeFilepathPatterns;
24
- /**
25
- * Exclude matching modules
26
- */
27
- excludeModules?: ExcludeFilepathPatterns;
28
- };
29
- export default function extractRollupStats(bundle: OutputBundle, options?: StatsOptions): Stats;
package/dist/extract.mjs DELETED
@@ -1,94 +0,0 @@
1
- function omit(data, keys) {
2
- const result = {};
3
- const objectKeys = Object.keys(data);
4
- objectKeys.forEach((key) => {
5
- if (!keys.includes(key)) {
6
- result[key] = data[key];
7
- }
8
- });
9
- return result;
10
- }
11
-
12
- /**
13
- * Check if filepath should be excluded based on patterns
14
- */
15
- function checkExcludeFilepath(filepath, patterns) {
16
- if (!patterns) {
17
- return false;
18
- }
19
- if (Array.isArray(patterns)) {
20
- let res = false;
21
- for (let i = 0; i <= patterns.length - 1 && res === false; i++) {
22
- res = checkExcludeFilepath(filepath, patterns[i]);
23
- }
24
- return res;
25
- }
26
- if (typeof patterns === 'function') {
27
- return patterns(filepath);
28
- }
29
- if (typeof patterns === 'string') {
30
- return Boolean(filepath.match(patterns));
31
- }
32
- if ('test' in patterns) {
33
- return patterns.test(filepath);
34
- }
35
- return false;
36
- }
37
-
38
- function extractRollupStats(bundle, options = {}) {
39
- const { source = false, excludeAssets, excludeModules } = options;
40
- const output = {};
41
- Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {
42
- // Skip extraction if the entry filepath matches the exclude assets pattern
43
- if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {
44
- return;
45
- }
46
- if (bundleEntryStats.type === "asset") {
47
- let assetStats = shallowCloneStatsObject(bundleEntryStats);
48
- // Skip asset source if options.source is false
49
- if (!source) {
50
- assetStats = omit(assetStats, ['source']);
51
- }
52
- output[bundleEntryFilepath] = assetStats;
53
- return;
54
- }
55
- if (bundleEntryStats.type === "chunk") {
56
- let chunkStats = shallowCloneStatsObject(bundleEntryStats);
57
- // Skip chunk source if options.source is false
58
- if (!source) {
59
- chunkStats = omit(chunkStats, ['code']);
60
- }
61
- // Extract chunk modules stats
62
- const chunkModulesStats = {};
63
- Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {
64
- // Skip module extraction if the filepath matches the exclude modules pattern
65
- if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {
66
- return;
67
- }
68
- let moduleStats = shallowCloneStatsObject(bundleModuleStats);
69
- // Skip module source if options.source is false
70
- if (!source) {
71
- moduleStats = omit(moduleStats, ['code']);
72
- }
73
- chunkModulesStats[bundleModuleFilepath] = moduleStats;
74
- });
75
- chunkStats.modules = chunkModulesStats;
76
- output[bundleEntryFilepath] = chunkStats;
77
- return;
78
- }
79
- });
80
- return output;
81
- }
82
- /**
83
- * Shallow clone stats object before any processing to
84
- * 1. resolve getters
85
- * 2. prevent changes to the stats object
86
- *
87
- * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128
88
- */
89
- function shallowCloneStatsObject(data) {
90
- return { ...data };
91
- }
92
-
93
- export { extractRollupStats as default };
94
- //# sourceMappingURL=extract.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extract.mjs","sources":["../src/utils/omit.ts","../src/utils/check-exclude-filepath.ts","../src/extract.ts"],"sourcesContent":[null,null,null],"names":[],"mappings":"AAAM,SAAU,IAAI,CAClB,IAAO,EACP,IAAS,EAAA;IAET,MAAM,MAAM,GAAG,EAAO;IACtB,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAa;AAEhD,IAAA,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACvB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC;QACzB;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;;ACVA;;AAEG;AACG,SAAU,oBAAoB,CAClC,QAAgB,EAChB,QAAkC,EAAA;IAElC,IAAI,CAAC,QAAQ,EAAE;AACb,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,QAA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C;YAC3C;AAEA,YAAA,MAAM,CAAC,mBAAmB,CAAC,GAAG,UAAU;YAExC;QACF;AAEA,QAAA,IAAI,gBAAgB,CAAC,IAAI,KAAK,OAAO,EAAE;AACrC,YAAA,IAAI,UAAU,GAAG,uBAAuB,CAAa,gBAAgB,CAAC;;YAGtE,IAAI,CAAC,MAAM,EAAE;gBACX,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,CAAC;YACzC;;YAGA,MAAM,iBAAiB,GAA0B,EAAE;AAEnD,YAAA,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,oBAAoB,EAAE,iBAAiB,CAAC,KAAI;;AAEvF,gBAAA,IAAI,oBAAoB,CAAC,oBAAoB,EAAE,cAAc,CAAC,EAAE;oBAC9D;gBACF;AAEA,gBAAA,IAAI,WAAW,GAAG,uBAAuB,CAAc,iBAAiB,CAAC;;gBAGzE,IAAI,CAAC,MAAM,EAAE;oBACX,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC;gBAC3C;AAEA,gBAAA,iBAAiB,CAAC,oBAAoB,CAAC,GAAG,WAAW;AACvD,YAAA,CAAC,CAAC;AAEF,YAAA,UAAU,CAAC,OAAO,GAAG,iBAAiB;AAEtC,YAAA,MAAM,CAAC,mBAAmB,CAAC,GAAG,UAAU;YAExC;QACF;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;AAEA;;;;;;AAMG;AACH,SAAS,uBAAuB,CAAU,IAAY,EAAA;AACpD,IAAA,OAAO,EAAC,GAAG,IAAI,EAAY;AAC7B;;;;"}
package/dist/index.cjs DELETED
@@ -1,82 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('node:path');
4
- var process = require('node:process');
5
- var extract = require('./extract.cjs');
6
- var fs = require('node:fs/promises');
7
-
8
- async function rollupStatsWrite(filepath, stats) {
9
- const content = JSON.stringify(stats, null, 2);
10
- // Create base directory if it does not exist
11
- await fs.mkdir(path.dirname(filepath), { recursive: true });
12
- await fs.writeFile(filepath, content);
13
- return {
14
- filepath,
15
- content,
16
- };
17
- }
18
-
19
- function round(value, precision = 2) {
20
- const multiplier = 10 ^ precision;
21
- return Math.round(value * multiplier) / multiplier;
22
- }
23
-
24
- const FILE_SIZE = {
25
- BYTE: {
26
- symbol: 'B',
27
- multiplier: 1,
28
- },
29
- KILO: {
30
- symbol: 'KiB',
31
- multiplier: 1024,
32
- },
33
- MEGA: {
34
- symbol: 'MiB',
35
- multiplier: 1024 * 1024,
36
- },
37
- };
38
- function formatFileSize(value) {
39
- let unit = FILE_SIZE.BYTE;
40
- if (typeof value !== 'number') {
41
- return `0${unit.symbol}`;
42
- }
43
- if (value < FILE_SIZE.KILO.multiplier) {
44
- unit = FILE_SIZE.BYTE;
45
- }
46
- else if (value < FILE_SIZE.MEGA.multiplier) {
47
- unit = FILE_SIZE.KILO;
48
- }
49
- else {
50
- unit = FILE_SIZE.MEGA;
51
- }
52
- return `${round(value / unit.multiplier, 2)}${unit.symbol}`;
53
- }
54
-
55
- const PLUGIN_NAME = 'rollupStats';
56
- const DEFAULT_FILE_NAME = 'stats.json';
57
- function rollupStats(options = {}) {
58
- return {
59
- name: PLUGIN_NAME,
60
- async generateBundle(context, bundle) {
61
- const resolvedOptions = typeof options === 'function' ? options(context) : options;
62
- const { fileName, stats: statsOptions, write = rollupStatsWrite } = resolvedOptions || {};
63
- const resolvedFileName = fileName || DEFAULT_FILE_NAME;
64
- const filepath = path.isAbsolute(resolvedFileName)
65
- ? resolvedFileName
66
- : path.join(context.dir || process.cwd(), resolvedFileName);
67
- const stats = extract(bundle, statsOptions);
68
- try {
69
- const res = await write(filepath, stats);
70
- const outputSize = Buffer.byteLength(res.content, 'utf-8');
71
- this.info(`Stats saved to ${res.filepath} (${formatFileSize(outputSize)})`);
72
- }
73
- catch (error) { // eslint-disable-line
74
- // Log error, but do not throw to allow the compilation to continue
75
- this.warn(error);
76
- }
77
- },
78
- };
79
- }
80
-
81
- module.exports = rollupStats;
82
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/write.ts","../src/utils/round.ts","../src/utils/format-file-size.ts","../src/index.ts"],"sourcesContent":[null,null,null,null],"names":["extractRollupStats"],"mappings":";;;;;;;AAaO,eAAe,gBAAgB,CAEpC,QAAgB,EAAE,KAAQ,EAAA;AAC1B,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;;AAG9C,IAAA,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAE3D,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC;IAErC,OAAO;QACL,QAAQ;QACR,OAAO;KACR;AACH;;SC3BgB,KAAK,CAAC,KAAa,EAAE,SAAS,GAAG,CAAC,EAAA;AAChD,IAAA,MAAM,UAAU,GAAG,EAAE,GAAG,SAAS;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,UAAU;AACpD;;ACDA,MAAM,SAAS,GAAG;AAChB,IAAA,IAAI,EAAE;AACJ,QAAA,MAAM,EAAE,GAAG;AACX,QAAA,UAAU,EAAE,CAAC;AACd,KAAA;AACD,IAAA,IAAI,EAAE;AACJ,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,UAAU,EAAE,IAAI;AACjB,KAAA;AACD,IAAA,IAAI,EAAE;AACJ,QAAA,MAAM,EAAE,KAAK;QACb,UAAU,EAAE,IAAI,GAAG,IAAI;AACxB,KAAA;CACF;AAEK,SAAU,cAAc,CAAC,KAAqB,EAAA;AAClD,IAAA,IAAI,IAAI,GAAG,SAAS,CAAC,IAAI;AAEzB,IAAA,IAAI,OAAO,KAAK,KAA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AM,GAAG,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC;AACxC,gBAAA,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC;AAE1D,gBAAA,IAAI,CAAC,IAAI,CAAC,CAAA,eAAA,EAAkB,GAAG,CAAC,QAAQ,CAAA,EAAA,EAAK,cAAc,CAAC,UAAU,CAAC,CAAA,CAAA,CAAG,CAAC;YAC7E;AAAE,YAAA,OAAO,KAAU,EAAE;;AAEnB,gBAAA,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;YAClB;QACF,CAAC;KACe;AACpB;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/write.ts","../src/utils/round.ts","../src/utils/format-file-size.ts","../src/index.ts"],"sourcesContent":[null,null,null,null],"names":[],"mappings":";;;;;AAaO,eAAe,gBAAgB,CAEpC,QAAgB,EAAE,KAAQ,EAAA;AAC1B,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;;AAG9C,IAAA,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAE3D,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC;IAErC,OAAO;QACL,QAAQ;QACR,OAAO;KACR;AACH;;SC3BgB,KAAK,CAAC,KAAa,EAAE,SAAS,GAAG,CAAC,EAAA;AAChD,IAAA,MAAM,UAAU,GAAG,EAAE,GAAG,SAAS;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,UAAU;AACpD;;ACDA,MAAM,SAAS,GAAG;AAChB,IAAA,IAAI,EAAE;AACJ,QAAA,MAAM,EAAE,GAAG;AACX,QAAA,UAAU,EAAE,CAAC;AACd,KAAA;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