rollup-plugin-stats 1.5.6 → 2.0.0-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 (49) hide show
  1. package/README.md +1 -1
  2. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  3. package/dist/extract.cjs +41 -94
  4. package/dist/extract.cjs.map +1 -1
  5. package/dist/extract.d.cts +53 -0
  6. package/dist/extract.d.mts +53 -0
  7. package/dist/extract.mjs +41 -92
  8. package/dist/extract.mjs.map +1 -1
  9. package/dist/index.cjs +30 -78
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +26 -0
  12. package/dist/index.d.mts +26 -0
  13. package/dist/index.mjs +27 -76
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/types.d.cts +9 -0
  16. package/dist/types.d.mts +9 -0
  17. package/dist/utils/check-exclude-filepath.cjs +21 -0
  18. package/dist/utils/check-exclude-filepath.cjs.map +1 -0
  19. package/dist/utils/check-exclude-filepath.d.cts +6 -0
  20. package/dist/utils/check-exclude-filepath.d.mts +6 -0
  21. package/dist/utils/check-exclude-filepath.mjs +20 -0
  22. package/dist/utils/check-exclude-filepath.mjs.map +1 -0
  23. package/dist/utils/format-file-size.cjs +29 -0
  24. package/dist/utils/format-file-size.cjs.map +1 -0
  25. package/dist/utils/format-file-size.mjs +29 -0
  26. package/dist/utils/format-file-size.mjs.map +1 -0
  27. package/dist/utils/omit.cjs +13 -0
  28. package/dist/utils/omit.cjs.map +1 -0
  29. package/dist/utils/omit.mjs +12 -0
  30. package/dist/utils/omit.mjs.map +1 -0
  31. package/dist/utils/round.cjs +10 -0
  32. package/dist/utils/round.cjs.map +1 -0
  33. package/dist/utils/round.mjs +9 -0
  34. package/dist/utils/round.mjs.map +1 -0
  35. package/dist/write.cjs +20 -0
  36. package/dist/write.cjs.map +1 -0
  37. package/dist/write.d.cts +9 -0
  38. package/dist/write.d.mts +9 -0
  39. package/dist/write.mjs +17 -0
  40. package/dist/write.mjs.map +1 -0
  41. package/package.json +35 -21
  42. package/dist/extract.d.ts +0 -48
  43. package/dist/index.d.ts +0 -22
  44. package/dist/types.d.ts +0 -4
  45. package/dist/utils/check-exclude-filepath.d.ts +0 -7
  46. package/dist/utils/format-file-size.d.ts +0 -1
  47. package/dist/utils/omit.d.ts +0 -1
  48. package/dist/utils/round.d.ts +0 -1
  49. package/dist/write.d.ts +0 -6
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![Socket Badge](https://socket.dev/api/badge/npm/package/rollup-plugin-stats)](https://socket.dev/npm/package/rollup-plugin-stats)
7
7
  [![ci](https://github.com/relative-ci/rollup-plugin-stats/actions/workflows/ci.yml/badge.svg)](https://github.com/relative-ci/rollup-plugin-stats/actions/workflows/ci.yml)
8
8
 
9
- Output Rollup stats JSON file
9
+ Vite/Rolldown/Rollup plugin to generate bundle stats JSON file
10
10
 
11
11
  ## Install
12
12
 
@@ -0,0 +1,29 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
package/dist/extract.cjs CHANGED
@@ -1,100 +1,47 @@
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
- }
1
+ const require_omit = require('./utils/omit.cjs');
2
+ const require_check_exclude_filepath = require('./utils/check-exclude-filepath.cjs');
39
3
 
4
+ //#region src/extract.ts
40
5
  /**
41
- * Extract bundler stats
42
- *
43
- * Shallow clone stats object before any processing using `omit` to
44
- * 1. resolve getters
45
- * 2. prevent changes to the stats object
46
- *
47
- * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128
48
- */
6
+ * Extract bundler stats
7
+ *
8
+ * Shallow clone stats object before any processing using `omit` to
9
+ * 1. resolve getters
10
+ * 2. prevent changes to the stats object
11
+ *
12
+ * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128
13
+ */
49
14
  function extractRollupStats(bundle, options = {}) {
50
- const { source = false, map = false, excludeAssets, excludeModules } = options;
51
- const output = {};
52
- Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {
53
- // Skip extraction if the entry filepath matches the exclude assets pattern
54
- if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {
55
- return;
56
- }
57
- if (bundleEntryStats.type === "asset") {
58
- const assetStatsOmitKeys = [];
59
- // Skip asset source if options.source is false
60
- if (!source) {
61
- assetStatsOmitKeys.push('source');
62
- }
63
- output[bundleEntryFilepath] = omit(bundleEntryStats, assetStatsOmitKeys);
64
- return;
65
- }
66
- if (bundleEntryStats.type === "chunk") {
67
- const chunkStatsOmitKeys = [];
68
- // Skip chunk source if options.source is false
69
- if (!source) {
70
- chunkStatsOmitKeys.push('code');
71
- }
72
- // Skip chunk map if options.map is false
73
- if (!map) {
74
- chunkStatsOmitKeys.push('map');
75
- }
76
- const chunkStats = omit(bundleEntryStats, chunkStatsOmitKeys);
77
- // Extract chunk modules stats
78
- const chunkModulesStats = {};
79
- Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {
80
- // Skip module extraction if the filepath matches the exclude modules pattern
81
- if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {
82
- return;
83
- }
84
- const moduleStatsOmitKeys = [];
85
- // Skip module source if options.source is false
86
- if (!source) {
87
- moduleStatsOmitKeys.push('code');
88
- }
89
- chunkModulesStats[bundleModuleFilepath] = omit(bundleModuleStats, moduleStatsOmitKeys);
90
- });
91
- chunkStats.modules = chunkModulesStats;
92
- output[bundleEntryFilepath] = chunkStats;
93
- return;
94
- }
95
- });
96
- return output;
15
+ const { source = false, map = false, excludeAssets, excludeModules } = options;
16
+ const output = {};
17
+ Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {
18
+ if (require_check_exclude_filepath.checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) return;
19
+ if (bundleEntryStats.type === "asset") {
20
+ const assetStatsOmitKeys = [];
21
+ if (!source) assetStatsOmitKeys.push("source");
22
+ output[bundleEntryFilepath] = require_omit.omit(bundleEntryStats, assetStatsOmitKeys);
23
+ return;
24
+ }
25
+ if (bundleEntryStats.type === "chunk") {
26
+ const chunkStatsOmitKeys = [];
27
+ if (!source) chunkStatsOmitKeys.push("code");
28
+ if (!map) chunkStatsOmitKeys.push("map");
29
+ const chunkStats = require_omit.omit(bundleEntryStats, chunkStatsOmitKeys);
30
+ const chunkModulesStats = {};
31
+ Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {
32
+ if (require_check_exclude_filepath.checkExcludeFilepath(bundleModuleFilepath, excludeModules)) return;
33
+ const moduleStatsOmitKeys = [];
34
+ if (!source) moduleStatsOmitKeys.push("code");
35
+ chunkModulesStats[bundleModuleFilepath] = require_omit.omit(bundleModuleStats, moduleStatsOmitKeys);
36
+ });
37
+ chunkStats.modules = chunkModulesStats;
38
+ output[bundleEntryFilepath] = chunkStats;
39
+ return;
40
+ }
41
+ });
42
+ return output;
97
43
  }
98
44
 
45
+ //#endregion
99
46
  module.exports = extractRollupStats;
100
- //# sourceMappingURL=extract.cjs.map
47
+ //# sourceMappingURL=extract.cjs.map
@@ -1 +1 @@
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,O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OutputBundle, OutputChunk, RenderedModule } from 'rollup';\nimport { omit } from './utils/omit';\nimport { type ExcludeFilepathPatterns, checkExcludeFilepath } from './utils/check-exclude-filepath';\n\nexport type AssetStatsOptionalProperties = {\n source?: OutputAsset['source'];\n};\n\nexport type AssetStats = Omit<OutputAsset, keyof AssetStatsOptionalProperties> & AssetStatsOptionalProperties;\n\nexport type ModuleStatsOptionalProperties = {\n code?: RenderedModule['code'] | null;\n};\n\nexport type ModuleStats = Omit<RenderedModule, keyof ModuleStatsOptionalProperties> & ModuleStatsOptionalProperties;\n\nexport type ChunkStatsOptionalProperties = {\n code?: OutputChunk['code'];\n map?: OutputChunk['map']; \n};\n\nexport type ChunkStats = Omit<OutputChunk, keyof ChunkStatsOptionalProperties | 'modules'> & {\n modules: Record<string, ModuleStats>;\n} & ChunkStatsOptionalProperties;\n\nexport type Stats = Record<string, AssetStats | ChunkStats>;\n\nexport type StatsOptions = {\n /**\n * Output asset/module sources\n * @default false \n */\n source?: boolean;\n /**\n * Output chunk map\n * @default false \n */\n map?: boolean;\n /**\n * Exclude matching assets\n */\n excludeAssets?: ExcludeFilepathPatterns;\n /**\n * Exclude matching modules\n */\n excludeModules?: ExcludeFilepathPatterns;\n}\n\n/**\n * Extract bundler stats\n *\n * Shallow clone stats object before any processing using `omit` to\n * 1. resolve getters\n * 2. prevent changes to the stats object\n *\n * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128\n */\nexport default function extractRollupStats(bundle: OutputBundle, options: StatsOptions = {}): Stats {\n const { source = false, map = false, excludeAssets, excludeModules } = options;\n\n const output: Stats = {};\n\n Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {\n // Skip extraction if the entry filepath matches the exclude assets pattern\n if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {\n return;\n }\n\n if (bundleEntryStats.type === \"asset\") {\n const assetStatsOmitKeys: Array<keyof AssetStatsOptionalProperties> = [];\n\n // Skip asset source if options.source is false\n if (!source) {\n assetStatsOmitKeys.push('source'); \n }\n\n output[bundleEntryFilepath] = omit(\n bundleEntryStats,\n assetStatsOmitKeys,\n ) as AssetStats;\n\n return;\n }\n\n if (bundleEntryStats.type === \"chunk\") {\n const chunkStatsOmitKeys: Array<keyof ChunkStatsOptionalProperties> = [];\n\n // Skip chunk source if options.source is false\n if (!source) {\n chunkStatsOmitKeys.push('code');\n }\n\n // Skip chunk map if options.map is false\n if (!map) {\n chunkStatsOmitKeys.push('map');\n }\n\n const chunkStats = omit(bundleEntryStats, chunkStatsOmitKeys) as ChunkStats;\n\n\n // Extract chunk modules stats\n const chunkModulesStats: ChunkStats['modules'] = {};\n\n Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {\n // Skip module extraction if the filepath matches the exclude modules pattern\n if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {\n return;\n }\n\n const moduleStatsOmitKeys: Array<keyof ModuleStatsOptionalProperties> = [];\n\n // Skip module source if options.source is false\n if (!source) {\n moduleStatsOmitKeys.push('code');\n }\n\n chunkModulesStats[bundleModuleFilepath] = omit(\n bundleModuleStats,\n moduleStatsOmitKeys,\n ) as ModuleStats;\n });\n\n chunkStats.modules = chunkModulesStats;\n\n output[bundleEntryFilepath] = chunkStats;\n\n return;\n }\n });\n \n return output;\n}\n"],"mappings":";;;;;;;;;;;;;AAyDA,SAAwB,mBAAmB,QAAsB,UAAwB,EAAE,EAAS;CAClG,MAAM,EAAE,SAAS,OAAO,MAAM,OAAO,eAAe,mBAAmB;CAEvE,MAAM,SAAgB,EAAE;AAExB,QAAO,QAAQ,OAAO,CAAC,SAAS,CAAC,qBAAqB,sBAAsB;AAE1E,MAAIA,oDAAqB,qBAAqB,cAAc,CAC1D;AAGF,MAAI,iBAAiB,SAAS,SAAS;GACrC,MAAM,qBAAgE,EAAE;AAGxE,OAAI,CAAC,OACH,oBAAmB,KAAK,SAAS;AAGnC,UAAO,uBAAuBC,kBAC5B,kBACA,mBACD;AAED;;AAGF,MAAI,iBAAiB,SAAS,SAAS;GACrC,MAAM,qBAAgE,EAAE;AAGxE,OAAI,CAAC,OACH,oBAAmB,KAAK,OAAO;AAIjC,OAAI,CAAC,IACH,oBAAmB,KAAK,MAAM;GAGhC,MAAM,aAAaA,kBAAK,kBAAkB,mBAAmB;GAI7D,MAAM,oBAA2C,EAAE;AAEnD,UAAO,QAAQ,WAAW,QAAQ,CAAC,SAAS,CAAC,sBAAsB,uBAAuB;AAExF,QAAID,oDAAqB,sBAAsB,eAAe,CAC5D;IAGF,MAAM,sBAAkE,EAAE;AAG1E,QAAI,CAAC,OACH,qBAAoB,KAAK,OAAO;AAGlC,sBAAkB,wBAAwBC,kBACxC,mBACA,oBACD;KACD;AAEF,cAAW,UAAU;AAErB,UAAO,uBAAuB;AAE9B;;GAEF;AAEF,QAAO"}
@@ -0,0 +1,53 @@
1
+ import { ExcludeFilepathPatterns } from "./utils/check-exclude-filepath.cjs";
2
+ import { OutputAsset, OutputBundle, OutputChunk, RenderedModule } from "rollup";
3
+
4
+ //#region src/extract.d.ts
5
+ type AssetStatsOptionalProperties = {
6
+ source?: OutputAsset['source'];
7
+ };
8
+ type AssetStats = Omit<OutputAsset, keyof AssetStatsOptionalProperties> & AssetStatsOptionalProperties;
9
+ type ModuleStatsOptionalProperties = {
10
+ code?: RenderedModule['code'] | null;
11
+ };
12
+ type ModuleStats = Omit<RenderedModule, keyof ModuleStatsOptionalProperties> & ModuleStatsOptionalProperties;
13
+ type ChunkStatsOptionalProperties = {
14
+ code?: OutputChunk['code'];
15
+ map?: OutputChunk['map'];
16
+ };
17
+ type ChunkStats = Omit<OutputChunk, keyof ChunkStatsOptionalProperties | 'modules'> & {
18
+ modules: Record<string, ModuleStats>;
19
+ } & ChunkStatsOptionalProperties;
20
+ type Stats = Record<string, AssetStats | ChunkStats>;
21
+ type StatsOptions = {
22
+ /**
23
+ * Output asset/module sources
24
+ * @default false
25
+ */
26
+ source?: boolean;
27
+ /**
28
+ * Output chunk map
29
+ * @default false
30
+ */
31
+ map?: boolean;
32
+ /**
33
+ * Exclude matching assets
34
+ */
35
+ excludeAssets?: ExcludeFilepathPatterns;
36
+ /**
37
+ * Exclude matching modules
38
+ */
39
+ excludeModules?: ExcludeFilepathPatterns;
40
+ };
41
+ /**
42
+ * Extract bundler stats
43
+ *
44
+ * Shallow clone stats object before any processing using `omit` to
45
+ * 1. resolve getters
46
+ * 2. prevent changes to the stats object
47
+ *
48
+ * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128
49
+ */
50
+ declare function extractRollupStats(bundle: OutputBundle, options?: StatsOptions): Stats;
51
+ //#endregion
52
+ export { AssetStats, AssetStatsOptionalProperties, ChunkStats, ChunkStatsOptionalProperties, ModuleStats, ModuleStatsOptionalProperties, Stats, StatsOptions, extractRollupStats as default };
53
+ //# sourceMappingURL=extract.d.cts.map
@@ -0,0 +1,53 @@
1
+ import { ExcludeFilepathPatterns } from "./utils/check-exclude-filepath.mjs";
2
+ import { OutputAsset, OutputBundle, OutputChunk, RenderedModule } from "rollup";
3
+
4
+ //#region src/extract.d.ts
5
+ type AssetStatsOptionalProperties = {
6
+ source?: OutputAsset['source'];
7
+ };
8
+ type AssetStats = Omit<OutputAsset, keyof AssetStatsOptionalProperties> & AssetStatsOptionalProperties;
9
+ type ModuleStatsOptionalProperties = {
10
+ code?: RenderedModule['code'] | null;
11
+ };
12
+ type ModuleStats = Omit<RenderedModule, keyof ModuleStatsOptionalProperties> & ModuleStatsOptionalProperties;
13
+ type ChunkStatsOptionalProperties = {
14
+ code?: OutputChunk['code'];
15
+ map?: OutputChunk['map'];
16
+ };
17
+ type ChunkStats = Omit<OutputChunk, keyof ChunkStatsOptionalProperties | 'modules'> & {
18
+ modules: Record<string, ModuleStats>;
19
+ } & ChunkStatsOptionalProperties;
20
+ type Stats = Record<string, AssetStats | ChunkStats>;
21
+ type StatsOptions = {
22
+ /**
23
+ * Output asset/module sources
24
+ * @default false
25
+ */
26
+ source?: boolean;
27
+ /**
28
+ * Output chunk map
29
+ * @default false
30
+ */
31
+ map?: boolean;
32
+ /**
33
+ * Exclude matching assets
34
+ */
35
+ excludeAssets?: ExcludeFilepathPatterns;
36
+ /**
37
+ * Exclude matching modules
38
+ */
39
+ excludeModules?: ExcludeFilepathPatterns;
40
+ };
41
+ /**
42
+ * Extract bundler stats
43
+ *
44
+ * Shallow clone stats object before any processing using `omit` to
45
+ * 1. resolve getters
46
+ * 2. prevent changes to the stats object
47
+ *
48
+ * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128
49
+ */
50
+ declare function extractRollupStats(bundle: OutputBundle, options?: StatsOptions): Stats;
51
+ //#endregion
52
+ export { AssetStats, AssetStatsOptionalProperties, ChunkStats, ChunkStatsOptionalProperties, ModuleStats, ModuleStatsOptionalProperties, Stats, StatsOptions, extractRollupStats as default };
53
+ //# sourceMappingURL=extract.d.mts.map
package/dist/extract.mjs CHANGED
@@ -1,98 +1,47 @@
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
- }
1
+ import { omit } from "./utils/omit.mjs";
2
+ import { checkExcludeFilepath } from "./utils/check-exclude-filepath.mjs";
37
3
 
4
+ //#region src/extract.ts
38
5
  /**
39
- * Extract bundler stats
40
- *
41
- * Shallow clone stats object before any processing using `omit` to
42
- * 1. resolve getters
43
- * 2. prevent changes to the stats object
44
- *
45
- * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128
46
- */
6
+ * Extract bundler stats
7
+ *
8
+ * Shallow clone stats object before any processing using `omit` to
9
+ * 1. resolve getters
10
+ * 2. prevent changes to the stats object
11
+ *
12
+ * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128
13
+ */
47
14
  function extractRollupStats(bundle, options = {}) {
48
- const { source = false, map = false, excludeAssets, excludeModules } = options;
49
- const output = {};
50
- Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {
51
- // Skip extraction if the entry filepath matches the exclude assets pattern
52
- if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {
53
- return;
54
- }
55
- if (bundleEntryStats.type === "asset") {
56
- const assetStatsOmitKeys = [];
57
- // Skip asset source if options.source is false
58
- if (!source) {
59
- assetStatsOmitKeys.push('source');
60
- }
61
- output[bundleEntryFilepath] = omit(bundleEntryStats, assetStatsOmitKeys);
62
- return;
63
- }
64
- if (bundleEntryStats.type === "chunk") {
65
- const chunkStatsOmitKeys = [];
66
- // Skip chunk source if options.source is false
67
- if (!source) {
68
- chunkStatsOmitKeys.push('code');
69
- }
70
- // Skip chunk map if options.map is false
71
- if (!map) {
72
- chunkStatsOmitKeys.push('map');
73
- }
74
- const chunkStats = omit(bundleEntryStats, chunkStatsOmitKeys);
75
- // Extract chunk modules stats
76
- const chunkModulesStats = {};
77
- Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {
78
- // Skip module extraction if the filepath matches the exclude modules pattern
79
- if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {
80
- return;
81
- }
82
- const moduleStatsOmitKeys = [];
83
- // Skip module source if options.source is false
84
- if (!source) {
85
- moduleStatsOmitKeys.push('code');
86
- }
87
- chunkModulesStats[bundleModuleFilepath] = omit(bundleModuleStats, moduleStatsOmitKeys);
88
- });
89
- chunkStats.modules = chunkModulesStats;
90
- output[bundleEntryFilepath] = chunkStats;
91
- return;
92
- }
93
- });
94
- return output;
15
+ const { source = false, map = false, excludeAssets, excludeModules } = options;
16
+ const output = {};
17
+ Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {
18
+ if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) return;
19
+ if (bundleEntryStats.type === "asset") {
20
+ const assetStatsOmitKeys = [];
21
+ if (!source) assetStatsOmitKeys.push("source");
22
+ output[bundleEntryFilepath] = omit(bundleEntryStats, assetStatsOmitKeys);
23
+ return;
24
+ }
25
+ if (bundleEntryStats.type === "chunk") {
26
+ const chunkStatsOmitKeys = [];
27
+ if (!source) chunkStatsOmitKeys.push("code");
28
+ if (!map) chunkStatsOmitKeys.push("map");
29
+ const chunkStats = omit(bundleEntryStats, chunkStatsOmitKeys);
30
+ const chunkModulesStats = {};
31
+ Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {
32
+ if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) return;
33
+ const moduleStatsOmitKeys = [];
34
+ if (!source) moduleStatsOmitKeys.push("code");
35
+ chunkModulesStats[bundleModuleFilepath] = omit(bundleModuleStats, moduleStatsOmitKeys);
36
+ });
37
+ chunkStats.modules = chunkModulesStats;
38
+ output[bundleEntryFilepath] = chunkStats;
39
+ return;
40
+ }
41
+ });
42
+ return output;
95
43
  }
96
44
 
45
+ //#endregion
97
46
  export { extractRollupStats as default };
98
- //# sourceMappingURL=extract.mjs.map
47
+ //# sourceMappingURL=extract.mjs.map
@@ -1 +1 @@
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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AI,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
+ {"version":3,"file":"extract.mjs","names":[],"sources":["../src/extract.ts"],"sourcesContent":["import type { OutputAsset, OutputBundle, OutputChunk, RenderedModule } from 'rollup';\nimport { omit } from './utils/omit';\nimport { type ExcludeFilepathPatterns, checkExcludeFilepath } from './utils/check-exclude-filepath';\n\nexport type AssetStatsOptionalProperties = {\n source?: OutputAsset['source'];\n};\n\nexport type AssetStats = Omit<OutputAsset, keyof AssetStatsOptionalProperties> & AssetStatsOptionalProperties;\n\nexport type ModuleStatsOptionalProperties = {\n code?: RenderedModule['code'] | null;\n};\n\nexport type ModuleStats = Omit<RenderedModule, keyof ModuleStatsOptionalProperties> & ModuleStatsOptionalProperties;\n\nexport type ChunkStatsOptionalProperties = {\n code?: OutputChunk['code'];\n map?: OutputChunk['map']; \n};\n\nexport type ChunkStats = Omit<OutputChunk, keyof ChunkStatsOptionalProperties | 'modules'> & {\n modules: Record<string, ModuleStats>;\n} & ChunkStatsOptionalProperties;\n\nexport type Stats = Record<string, AssetStats | ChunkStats>;\n\nexport type StatsOptions = {\n /**\n * Output asset/module sources\n * @default false \n */\n source?: boolean;\n /**\n * Output chunk map\n * @default false \n */\n map?: boolean;\n /**\n * Exclude matching assets\n */\n excludeAssets?: ExcludeFilepathPatterns;\n /**\n * Exclude matching modules\n */\n excludeModules?: ExcludeFilepathPatterns;\n}\n\n/**\n * Extract bundler stats\n *\n * Shallow clone stats object before any processing using `omit` to\n * 1. resolve getters\n * 2. prevent changes to the stats object\n *\n * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128\n */\nexport default function extractRollupStats(bundle: OutputBundle, options: StatsOptions = {}): Stats {\n const { source = false, map = false, excludeAssets, excludeModules } = options;\n\n const output: Stats = {};\n\n Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {\n // Skip extraction if the entry filepath matches the exclude assets pattern\n if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {\n return;\n }\n\n if (bundleEntryStats.type === \"asset\") {\n const assetStatsOmitKeys: Array<keyof AssetStatsOptionalProperties> = [];\n\n // Skip asset source if options.source is false\n if (!source) {\n assetStatsOmitKeys.push('source'); \n }\n\n output[bundleEntryFilepath] = omit(\n bundleEntryStats,\n assetStatsOmitKeys,\n ) as AssetStats;\n\n return;\n }\n\n if (bundleEntryStats.type === \"chunk\") {\n const chunkStatsOmitKeys: Array<keyof ChunkStatsOptionalProperties> = [];\n\n // Skip chunk source if options.source is false\n if (!source) {\n chunkStatsOmitKeys.push('code');\n }\n\n // Skip chunk map if options.map is false\n if (!map) {\n chunkStatsOmitKeys.push('map');\n }\n\n const chunkStats = omit(bundleEntryStats, chunkStatsOmitKeys) as ChunkStats;\n\n\n // Extract chunk modules stats\n const chunkModulesStats: ChunkStats['modules'] = {};\n\n Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {\n // Skip module extraction if the filepath matches the exclude modules pattern\n if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {\n return;\n }\n\n const moduleStatsOmitKeys: Array<keyof ModuleStatsOptionalProperties> = [];\n\n // Skip module source if options.source is false\n if (!source) {\n moduleStatsOmitKeys.push('code');\n }\n\n chunkModulesStats[bundleModuleFilepath] = omit(\n bundleModuleStats,\n moduleStatsOmitKeys,\n ) as ModuleStats;\n });\n\n chunkStats.modules = chunkModulesStats;\n\n output[bundleEntryFilepath] = chunkStats;\n\n return;\n }\n });\n \n return output;\n}\n"],"mappings":";;;;;;;;;;;;;AAyDA,SAAwB,mBAAmB,QAAsB,UAAwB,EAAE,EAAS;CAClG,MAAM,EAAE,SAAS,OAAO,MAAM,OAAO,eAAe,mBAAmB;CAEvE,MAAM,SAAgB,EAAE;AAExB,QAAO,QAAQ,OAAO,CAAC,SAAS,CAAC,qBAAqB,sBAAsB;AAE1E,MAAI,qBAAqB,qBAAqB,cAAc,CAC1D;AAGF,MAAI,iBAAiB,SAAS,SAAS;GACrC,MAAM,qBAAgE,EAAE;AAGxE,OAAI,CAAC,OACH,oBAAmB,KAAK,SAAS;AAGnC,UAAO,uBAAuB,KAC5B,kBACA,mBACD;AAED;;AAGF,MAAI,iBAAiB,SAAS,SAAS;GACrC,MAAM,qBAAgE,EAAE;AAGxE,OAAI,CAAC,OACH,oBAAmB,KAAK,OAAO;AAIjC,OAAI,CAAC,IACH,oBAAmB,KAAK,MAAM;GAGhC,MAAM,aAAa,KAAK,kBAAkB,mBAAmB;GAI7D,MAAM,oBAA2C,EAAE;AAEnD,UAAO,QAAQ,WAAW,QAAQ,CAAC,SAAS,CAAC,sBAAsB,uBAAuB;AAExF,QAAI,qBAAqB,sBAAsB,eAAe,CAC5D;IAGF,MAAM,sBAAkE,EAAE;AAG1E,QAAI,CAAC,OACH,qBAAoB,KAAK,OAAO;AAGlC,sBAAkB,wBAAwB,KACxC,mBACA,oBACD;KACD;AAEF,cAAW,UAAU;AAErB,UAAO,uBAAuB;AAE9B;;GAEF;AAEF,QAAO"}
package/dist/index.cjs CHANGED
@@ -1,83 +1,35 @@
1
- 'use strict';
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
+ const require_extract = require('./extract.cjs');
3
+ const require_write = require('./write.cjs');
4
+ const require_format_file_size = require('./utils/format-file-size.cjs');
5
+ let node_path = require("node:path");
6
+ node_path = require_runtime.__toESM(node_path);
7
+ let node_process = require("node:process");
8
+ node_process = require_runtime.__toESM(node_process);
2
9
 
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';
10
+ //#region src/index.ts
11
+ const PLUGIN_NAME = "rollupStats";
12
+ const DEFAULT_FILE_NAME = "stats.json";
57
13
  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) {
74
- const message = error instanceof Error ? error.message : JSON.stringify(error);
75
- // Log error, but do not throw to allow the compilation to continue
76
- this.warn(message);
77
- }
78
- },
79
- };
14
+ return {
15
+ name: PLUGIN_NAME,
16
+ async generateBundle(context, bundle) {
17
+ const { fileName, stats: statsOptions, write = require_write.rollupStatsWrite } = (typeof options === "function" ? options(context) : options) || {};
18
+ const resolvedFileName = fileName || DEFAULT_FILE_NAME;
19
+ const filepath = node_path.default.isAbsolute(resolvedFileName) ? resolvedFileName : node_path.default.join(context.dir || node_process.default.cwd(), resolvedFileName);
20
+ const stats = require_extract(bundle, statsOptions);
21
+ try {
22
+ const res = await write(filepath, stats);
23
+ const outputSize = Buffer.byteLength(res.content, "utf-8");
24
+ this.info(`Stats saved to ${res.filepath} (${require_format_file_size.formatFileSize(outputSize)})`);
25
+ } catch (error) {
26
+ const message = error instanceof Error ? error.message : JSON.stringify(error);
27
+ this.warn(message);
28
+ }
29
+ }
30
+ };
80
31
  }
81
32
 
33
+ //#endregion
82
34
  module.exports = rollupStats;
83
- //# sourceMappingURL=index.cjs.map
35
+ //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
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,SA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CAAC;YACpB;QACF,CAAC;KACe;AACpB;;;;"}
1
+ {"version":3,"file":"index.cjs","names":["rollupStatsWrite","path","process","extractRollupStats","formatFileSize"],"sources":["../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport process from 'node:process';\n\nimport extractRollupStats, { type StatsOptions } from './extract';\nimport { type RollupStatsWrite, rollupStatsWrite } from './write';\nimport { formatFileSize } from './utils/format-file-size';\nimport type { Plugin, OutputOptions } from './types';\n\nconst PLUGIN_NAME = 'rollupStats';\nconst DEFAULT_FILE_NAME = 'stats.json';\n\nexport type RollupStatsOptions = {\n /**\n * Output filename relative to Rollup output directory or absolute\n * @default: stats.json\n */\n fileName?: string;\n /**\n * Rollup stats options\n */\n stats?: StatsOptions;\n /**\n * Custom file writer\n * @default - fs.write(FILENAME, JSON.stringify(STATS, null, 2));\n */\n write?: RollupStatsWrite;\n};\n\ntype RollupStatsOptionsOrOutputOptions =\n | RollupStatsOptions\n | ((outputOptions: OutputOptions) => RollupStatsOptions);\n\nfunction rollupStats(options: RollupStatsOptionsOrOutputOptions = {}): Plugin {\n return {\n name: PLUGIN_NAME,\n async generateBundle(context, bundle) {\n const resolvedOptions =\n typeof options === 'function' ? options(context) : options;\n const {\n fileName,\n stats: statsOptions,\n write = rollupStatsWrite,\n } = resolvedOptions || {};\n\n const resolvedFileName = fileName || DEFAULT_FILE_NAME;\n const filepath = path.isAbsolute(resolvedFileName)\n ? resolvedFileName\n : path.join(context.dir || process.cwd(), resolvedFileName);\n\n const stats = extractRollupStats(bundle, statsOptions);\n\n try {\n const res = await write(filepath, stats);\n const outputSize = Buffer.byteLength(res.content, 'utf-8');\n\n this.info(\n `Stats saved to ${res.filepath} (${formatFileSize(outputSize)})`\n );\n } catch (error: unknown) {\n const message =\n error instanceof Error ? error.message : JSON.stringify(error);\n\n // Log error, but do not throw to allow the compilation to continue\n this.warn(message);\n }\n },\n } satisfies Plugin;\n}\n\nexport default rollupStats;\n"],"mappings":";;;;;;;;;;AAQA,MAAM,cAAc;AACpB,MAAM,oBAAoB;AAuB1B,SAAS,YAAY,UAA6C,EAAE,EAAU;AAC5E,QAAO;EACL,MAAM;EACN,MAAM,eAAe,SAAS,QAAQ;GAGpC,MAAM,EACJ,UACA,OAAO,cACP,QAAQA,oCAJR,OAAO,YAAY,aAAa,QAAQ,QAAQ,GAAG,YAK9B,EAAE;GAEzB,MAAM,mBAAmB,YAAY;GACrC,MAAM,WAAWC,kBAAK,WAAW,iBAAiB,GAC9C,mBACAA,kBAAK,KAAK,QAAQ,OAAOC,qBAAQ,KAAK,EAAE,iBAAiB;GAE7D,MAAM,QAAQC,gBAAmB,QAAQ,aAAa;AAEtD,OAAI;IACF,MAAM,MAAM,MAAM,MAAM,UAAU,MAAM;IACxC,MAAM,aAAa,OAAO,WAAW,IAAI,SAAS,QAAQ;AAE1D,SAAK,KACH,kBAAkB,IAAI,SAAS,IAAIC,wCAAe,WAAW,CAAC,GAC/D;YACM,OAAgB;IACvB,MAAM,UACJ,iBAAiB,QAAQ,MAAM,UAAU,KAAK,UAAU,MAAM;AAGhE,SAAK,KAAK,QAAQ;;;EAGvB"}
@@ -0,0 +1,26 @@
1
+ import { StatsOptions } from "./extract.cjs";
2
+ import { RollupStatsWrite } from "./write.cjs";
3
+ import { OutputOptions, Plugin } from "./types.cjs";
4
+
5
+ //#region src/index.d.ts
6
+ type RollupStatsOptions = {
7
+ /**
8
+ * Output filename relative to Rollup output directory or absolute
9
+ * @default: stats.json
10
+ */
11
+ fileName?: string;
12
+ /**
13
+ * Rollup stats options
14
+ */
15
+ stats?: StatsOptions;
16
+ /**
17
+ * Custom file writer
18
+ * @default - fs.write(FILENAME, JSON.stringify(STATS, null, 2));
19
+ */
20
+ write?: RollupStatsWrite;
21
+ };
22
+ type RollupStatsOptionsOrOutputOptions = RollupStatsOptions | ((outputOptions: OutputOptions) => RollupStatsOptions);
23
+ declare function rollupStats(options?: RollupStatsOptionsOrOutputOptions): Plugin;
24
+ //#endregion
25
+ export { RollupStatsOptions, rollupStats as default };
26
+ //# sourceMappingURL=index.d.cts.map