rollup-plugin-stats 1.6.0-beta.0 → 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.
- package/README.md +1 -1
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/extract.cjs +47 -0
- package/dist/extract.cjs.map +1 -0
- package/dist/{cjs/extract2.d.cts → extract.d.cts} +3 -6
- package/dist/{esm/extract2.d.mts → extract.d.mts} +3 -6
- package/dist/extract.mjs +47 -0
- package/dist/extract.mjs.map +1 -0
- package/dist/index.cjs +35 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{cjs/index.d.cts → index.d.cts} +3 -9
- package/dist/{esm/index.d.mts → index.d.mts} +3 -9
- package/dist/index.mjs +32 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.d.cts +9 -0
- package/dist/types.d.mts +9 -0
- package/dist/utils/check-exclude-filepath.cjs +21 -0
- package/dist/utils/check-exclude-filepath.cjs.map +1 -0
- package/dist/utils/check-exclude-filepath.d.cts +6 -0
- package/dist/utils/check-exclude-filepath.d.mts +6 -0
- package/dist/utils/check-exclude-filepath.mjs +20 -0
- package/dist/utils/check-exclude-filepath.mjs.map +1 -0
- package/dist/utils/format-file-size.cjs +29 -0
- package/dist/utils/format-file-size.cjs.map +1 -0
- package/dist/utils/format-file-size.mjs +29 -0
- package/dist/utils/format-file-size.mjs.map +1 -0
- package/dist/utils/omit.cjs +13 -0
- package/dist/utils/omit.cjs.map +1 -0
- package/dist/utils/omit.mjs +12 -0
- package/dist/utils/omit.mjs.map +1 -0
- package/dist/utils/round.cjs +10 -0
- package/dist/utils/round.cjs.map +1 -0
- package/dist/utils/round.mjs +9 -0
- package/dist/utils/round.mjs.map +1 -0
- package/dist/write.cjs +20 -0
- package/dist/write.cjs.map +1 -0
- package/dist/write.d.cts +9 -0
- package/dist/write.d.mts +9 -0
- package/dist/write.mjs +17 -0
- package/dist/write.mjs.map +1 -0
- package/package.json +44 -28
- package/dist/cjs/extract.cjs +0 -1
- package/dist/cjs/extract.d.cts +0 -2
- package/dist/cjs/extract2.cjs +0 -2
- package/dist/cjs/extract2.cjs.map +0 -1
- package/dist/cjs/index.cjs +0 -2
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/esm/extract.d.mts +0 -2
- package/dist/esm/extract.mjs +0 -1
- package/dist/esm/extract2.mjs +0 -2
- package/dist/esm/extract2.mjs.map +0 -1
- package/dist/esm/index.mjs +0 -2
- package/dist/esm/index.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://socket.dev/npm/package/rollup-plugin-stats)
|
|
7
7
|
[](https://github.com/relative-ci/rollup-plugin-stats/actions/workflows/ci.yml)
|
|
8
8
|
|
|
9
|
-
|
|
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
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const require_omit = require('./utils/omit.cjs');
|
|
2
|
+
const require_check_exclude_filepath = require('./utils/check-exclude-filepath.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/extract.ts
|
|
5
|
+
/**
|
|
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
|
+
*/
|
|
14
|
+
function extractRollupStats(bundle, options = {}) {
|
|
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;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
module.exports = extractRollupStats;
|
|
47
|
+
//# sourceMappingURL=extract.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract.cjs","names":["checkExcludeFilepath","omit"],"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,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"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import { ExcludeFilepathPatterns } from "./utils/check-exclude-filepath.cjs";
|
|
1
2
|
import { OutputAsset, OutputBundle, OutputChunk, RenderedModule } from "rollup";
|
|
2
3
|
|
|
3
|
-
//#region src/utils/check-exclude-filepath.d.ts
|
|
4
|
-
type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);
|
|
5
|
-
type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>;
|
|
6
|
-
//#endregion
|
|
7
4
|
//#region src/extract.d.ts
|
|
8
5
|
type AssetStatsOptionalProperties = {
|
|
9
6
|
source?: OutputAsset['source'];
|
|
@@ -52,5 +49,5 @@ type StatsOptions = {
|
|
|
52
49
|
*/
|
|
53
50
|
declare function extractRollupStats(bundle: OutputBundle, options?: StatsOptions): Stats;
|
|
54
51
|
//#endregion
|
|
55
|
-
export {
|
|
56
|
-
//# sourceMappingURL=
|
|
52
|
+
export { AssetStats, AssetStatsOptionalProperties, ChunkStats, ChunkStatsOptionalProperties, ModuleStats, ModuleStatsOptionalProperties, Stats, StatsOptions, extractRollupStats as default };
|
|
53
|
+
//# sourceMappingURL=extract.d.cts.map
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import { ExcludeFilepathPatterns } from "./utils/check-exclude-filepath.mjs";
|
|
1
2
|
import { OutputAsset, OutputBundle, OutputChunk, RenderedModule } from "rollup";
|
|
2
3
|
|
|
3
|
-
//#region src/utils/check-exclude-filepath.d.ts
|
|
4
|
-
type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);
|
|
5
|
-
type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>;
|
|
6
|
-
//#endregion
|
|
7
4
|
//#region src/extract.d.ts
|
|
8
5
|
type AssetStatsOptionalProperties = {
|
|
9
6
|
source?: OutputAsset['source'];
|
|
@@ -52,5 +49,5 @@ type StatsOptions = {
|
|
|
52
49
|
*/
|
|
53
50
|
declare function extractRollupStats(bundle: OutputBundle, options?: StatsOptions): Stats;
|
|
54
51
|
//#endregion
|
|
55
|
-
export {
|
|
56
|
-
//# sourceMappingURL=
|
|
52
|
+
export { AssetStats, AssetStatsOptionalProperties, ChunkStats, ChunkStatsOptionalProperties, ModuleStats, ModuleStatsOptionalProperties, Stats, StatsOptions, extractRollupStats as default };
|
|
53
|
+
//# sourceMappingURL=extract.d.mts.map
|
package/dist/extract.mjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { omit } from "./utils/omit.mjs";
|
|
2
|
+
import { checkExcludeFilepath } from "./utils/check-exclude-filepath.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/extract.ts
|
|
5
|
+
/**
|
|
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
|
+
*/
|
|
14
|
+
function extractRollupStats(bundle, options = {}) {
|
|
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;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { extractRollupStats as default };
|
|
47
|
+
//# sourceMappingURL=extract.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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);
|
|
9
|
+
|
|
10
|
+
//#region src/index.ts
|
|
11
|
+
const PLUGIN_NAME = "rollupStats";
|
|
12
|
+
const DEFAULT_FILE_NAME = "stats.json";
|
|
13
|
+
function rollupStats(options = {}) {
|
|
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
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
module.exports = rollupStats;
|
|
35
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { StatsOptions } from "./extract.cjs";
|
|
2
|
+
import { RollupStatsWrite } from "./write.cjs";
|
|
3
|
+
import { OutputOptions, Plugin } from "./types.cjs";
|
|
3
4
|
|
|
4
|
-
//#region src/write.d.ts
|
|
5
|
-
type RollupStatsWriteResponse = {
|
|
6
|
-
filepath: string;
|
|
7
|
-
content: string;
|
|
8
|
-
};
|
|
9
|
-
type RollupStatsWrite = (filepath: string, stats: Record<string, unknown>) => RollupStatsWriteResponse;
|
|
10
|
-
//#endregion
|
|
11
5
|
//#region src/index.d.ts
|
|
12
6
|
type RollupStatsOptions = {
|
|
13
7
|
/**
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { StatsOptions } from "./extract.mjs";
|
|
2
|
+
import { RollupStatsWrite } from "./write.mjs";
|
|
3
|
+
import { OutputOptions, Plugin } from "./types.mjs";
|
|
3
4
|
|
|
4
|
-
//#region src/write.d.ts
|
|
5
|
-
type RollupStatsWriteResponse = {
|
|
6
|
-
filepath: string;
|
|
7
|
-
content: string;
|
|
8
|
-
};
|
|
9
|
-
type RollupStatsWrite = (filepath: string, stats: Record<string, unknown>) => RollupStatsWriteResponse;
|
|
10
|
-
//#endregion
|
|
11
5
|
//#region src/index.d.ts
|
|
12
6
|
type RollupStatsOptions = {
|
|
13
7
|
/**
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import extractRollupStats from "./extract.mjs";
|
|
2
|
+
import { rollupStatsWrite } from "./write.mjs";
|
|
3
|
+
import { formatFileSize } from "./utils/format-file-size.mjs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
const PLUGIN_NAME = "rollupStats";
|
|
9
|
+
const DEFAULT_FILE_NAME = "stats.json";
|
|
10
|
+
function rollupStats(options = {}) {
|
|
11
|
+
return {
|
|
12
|
+
name: PLUGIN_NAME,
|
|
13
|
+
async generateBundle(context, bundle) {
|
|
14
|
+
const { fileName, stats: statsOptions, write = rollupStatsWrite } = (typeof options === "function" ? options(context) : options) || {};
|
|
15
|
+
const resolvedFileName = fileName || DEFAULT_FILE_NAME;
|
|
16
|
+
const filepath = path.isAbsolute(resolvedFileName) ? resolvedFileName : path.join(context.dir || process.cwd(), resolvedFileName);
|
|
17
|
+
const stats = extractRollupStats(bundle, statsOptions);
|
|
18
|
+
try {
|
|
19
|
+
const res = await write(filepath, stats);
|
|
20
|
+
const outputSize = Buffer.byteLength(res.content, "utf-8");
|
|
21
|
+
this.info(`Stats saved to ${res.filepath} (${formatFileSize(outputSize)})`);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
const message = error instanceof Error ? error.message : JSON.stringify(error);
|
|
24
|
+
this.warn(message);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { rollupStats as default };
|
|
32
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"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,QAAQ,sBAJR,OAAO,YAAY,aAAa,QAAQ,QAAQ,GAAG,YAK9B,EAAE;GAEzB,MAAM,mBAAmB,YAAY;GACrC,MAAM,WAAW,KAAK,WAAW,iBAAiB,GAC9C,mBACA,KAAK,KAAK,QAAQ,OAAO,QAAQ,KAAK,EAAE,iBAAiB;GAE7D,MAAM,QAAQ,mBAAmB,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,IAAI,eAAe,WAAW,CAAC,GAC/D;YACM,OAAgB;IACvB,MAAM,UACJ,iBAAiB,QAAQ,MAAM,UAAU,KAAK,UAAU,MAAM;AAGhE,SAAK,KAAK,QAAQ;;;EAGvB"}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OutputBundle, OutputOptions, Plugin } from "rollup";
|
|
2
|
+
import { Plugin as Plugin$1 } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type Plugin$2 = Plugin$1 & Plugin;
|
|
6
|
+
type OutputOptions$1 = OutputOptions;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { OutputOptions$1 as OutputOptions, Plugin$2 as Plugin };
|
|
9
|
+
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OutputBundle, OutputOptions, Plugin } from "rollup";
|
|
2
|
+
import { Plugin as Plugin$1 } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type Plugin$2 = Plugin$1 & Plugin;
|
|
6
|
+
type OutputOptions$1 = OutputOptions;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { OutputOptions$1 as OutputOptions, Plugin$2 as Plugin };
|
|
9
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/check-exclude-filepath.ts
|
|
3
|
+
/**
|
|
4
|
+
* Check if filepath should be excluded based on patterns
|
|
5
|
+
*/
|
|
6
|
+
function checkExcludeFilepath(filepath, patterns) {
|
|
7
|
+
if (!patterns) return false;
|
|
8
|
+
if (Array.isArray(patterns)) {
|
|
9
|
+
let res = false;
|
|
10
|
+
for (let i = 0; i <= patterns.length - 1 && res === false; i++) res = checkExcludeFilepath(filepath, patterns[i]);
|
|
11
|
+
return res;
|
|
12
|
+
}
|
|
13
|
+
if (typeof patterns === "function") return patterns(filepath);
|
|
14
|
+
if (typeof patterns === "string") return Boolean(filepath.match(patterns));
|
|
15
|
+
if ("test" in patterns) return patterns.test(filepath);
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.checkExcludeFilepath = checkExcludeFilepath;
|
|
21
|
+
//# sourceMappingURL=check-exclude-filepath.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-exclude-filepath.cjs","names":[],"sources":["../../src/utils/check-exclude-filepath.ts"],"sourcesContent":["type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);\n\nexport type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>;\n\n/**\n * Check if filepath should be excluded based on patterns\n */\nexport function checkExcludeFilepath(\n filepath: string,\n patterns?: ExcludeFilepathPatterns,\n): boolean {\n if (!patterns) {\n return false;\n }\n\n if (Array.isArray(patterns)) {\n let res = false;\n\n for (let i = 0; i <= patterns.length - 1 && res === false; i++) {\n res = checkExcludeFilepath(filepath, patterns[i]);\n }\n\n return res;\n }\n\n if (typeof patterns === 'function') {\n return patterns(filepath);\n }\n\n if (typeof patterns === 'string') {\n return Boolean(filepath.match(patterns));\n }\n\n if ('test' in patterns) {\n return patterns.test(filepath);\n }\n\n return false;\n}\n"],"mappings":";;;;;AAOA,SAAgB,qBACd,UACA,UACS;AACT,KAAI,CAAC,SACH,QAAO;AAGT,KAAI,MAAM,QAAQ,SAAS,EAAE;EAC3B,IAAI,MAAM;AAEV,OAAK,IAAI,IAAI,GAAG,KAAK,SAAS,SAAS,KAAK,QAAQ,OAAO,IACzD,OAAM,qBAAqB,UAAU,SAAS,GAAG;AAGnD,SAAO;;AAGT,KAAI,OAAO,aAAa,WACtB,QAAO,SAAS,SAAS;AAG3B,KAAI,OAAO,aAAa,SACtB,QAAO,QAAQ,SAAS,MAAM,SAAS,CAAC;AAG1C,KAAI,UAAU,SACZ,QAAO,SAAS,KAAK,SAAS;AAGhC,QAAO"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/utils/check-exclude-filepath.d.ts
|
|
2
|
+
type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);
|
|
3
|
+
type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { ExcludeFilepathPatterns };
|
|
6
|
+
//# sourceMappingURL=check-exclude-filepath.d.cts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
//#region src/utils/check-exclude-filepath.d.ts
|
|
2
|
+
type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);
|
|
3
|
+
type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { ExcludeFilepathPatterns };
|
|
6
|
+
//# sourceMappingURL=check-exclude-filepath.d.mts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/utils/check-exclude-filepath.ts
|
|
2
|
+
/**
|
|
3
|
+
* Check if filepath should be excluded based on patterns
|
|
4
|
+
*/
|
|
5
|
+
function checkExcludeFilepath(filepath, patterns) {
|
|
6
|
+
if (!patterns) return false;
|
|
7
|
+
if (Array.isArray(patterns)) {
|
|
8
|
+
let res = false;
|
|
9
|
+
for (let i = 0; i <= patterns.length - 1 && res === false; i++) res = checkExcludeFilepath(filepath, patterns[i]);
|
|
10
|
+
return res;
|
|
11
|
+
}
|
|
12
|
+
if (typeof patterns === "function") return patterns(filepath);
|
|
13
|
+
if (typeof patterns === "string") return Boolean(filepath.match(patterns));
|
|
14
|
+
if ("test" in patterns) return patterns.test(filepath);
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { checkExcludeFilepath };
|
|
20
|
+
//# sourceMappingURL=check-exclude-filepath.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-exclude-filepath.mjs","names":[],"sources":["../../src/utils/check-exclude-filepath.ts"],"sourcesContent":["type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);\n\nexport type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>;\n\n/**\n * Check if filepath should be excluded based on patterns\n */\nexport function checkExcludeFilepath(\n filepath: string,\n patterns?: ExcludeFilepathPatterns,\n): boolean {\n if (!patterns) {\n return false;\n }\n\n if (Array.isArray(patterns)) {\n let res = false;\n\n for (let i = 0; i <= patterns.length - 1 && res === false; i++) {\n res = checkExcludeFilepath(filepath, patterns[i]);\n }\n\n return res;\n }\n\n if (typeof patterns === 'function') {\n return patterns(filepath);\n }\n\n if (typeof patterns === 'string') {\n return Boolean(filepath.match(patterns));\n }\n\n if ('test' in patterns) {\n return patterns.test(filepath);\n }\n\n return false;\n}\n"],"mappings":";;;;AAOA,SAAgB,qBACd,UACA,UACS;AACT,KAAI,CAAC,SACH,QAAO;AAGT,KAAI,MAAM,QAAQ,SAAS,EAAE;EAC3B,IAAI,MAAM;AAEV,OAAK,IAAI,IAAI,GAAG,KAAK,SAAS,SAAS,KAAK,QAAQ,OAAO,IACzD,OAAM,qBAAqB,UAAU,SAAS,GAAG;AAGnD,SAAO;;AAGT,KAAI,OAAO,aAAa,WACtB,QAAO,SAAS,SAAS;AAG3B,KAAI,OAAO,aAAa,SACtB,QAAO,QAAQ,SAAS,MAAM,SAAS,CAAC;AAG1C,KAAI,UAAU,SACZ,QAAO,SAAS,KAAK,SAAS;AAGhC,QAAO"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const require_round = require('./round.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/utils/format-file-size.ts
|
|
4
|
+
const FILE_SIZE = {
|
|
5
|
+
BYTE: {
|
|
6
|
+
symbol: "B",
|
|
7
|
+
multiplier: 1
|
|
8
|
+
},
|
|
9
|
+
KILO: {
|
|
10
|
+
symbol: "KiB",
|
|
11
|
+
multiplier: 1024
|
|
12
|
+
},
|
|
13
|
+
MEGA: {
|
|
14
|
+
symbol: "MiB",
|
|
15
|
+
multiplier: 1024 * 1024
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function formatFileSize(value) {
|
|
19
|
+
let unit = FILE_SIZE.BYTE;
|
|
20
|
+
if (typeof value !== "number") return `0${unit.symbol}`;
|
|
21
|
+
if (value < FILE_SIZE.KILO.multiplier) unit = FILE_SIZE.BYTE;
|
|
22
|
+
else if (value < FILE_SIZE.MEGA.multiplier) unit = FILE_SIZE.KILO;
|
|
23
|
+
else unit = FILE_SIZE.MEGA;
|
|
24
|
+
return `${require_round.round(value / unit.multiplier, 2)}${unit.symbol}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.formatFileSize = formatFileSize;
|
|
29
|
+
//# sourceMappingURL=format-file-size.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-file-size.cjs","names":["round"],"sources":["../../src/utils/format-file-size.ts"],"sourcesContent":["import { round } from './round';\n\nconst FILE_SIZE = {\n BYTE: {\n symbol: 'B',\n multiplier: 1,\n },\n KILO: {\n symbol: 'KiB',\n multiplier: 1024,\n },\n MEGA: {\n symbol: 'MiB',\n multiplier: 1024 * 1024,\n },\n}\n\nexport function formatFileSize(value?: number | null): string {\n let unit = FILE_SIZE.BYTE;\n\n if (typeof value !== 'number') {\n return `0${unit.symbol}`;\n }\n\n if (value < FILE_SIZE.KILO.multiplier) {\n unit = FILE_SIZE.BYTE;\n } else if (value < FILE_SIZE.MEGA.multiplier) {\n unit = FILE_SIZE.KILO;\n } else {\n unit = FILE_SIZE.MEGA;\n }\n\n return `${round(value / unit.multiplier, 2)}${unit.symbol}`;\n}\n"],"mappings":";;;AAEA,MAAM,YAAY;CAChB,MAAM;EACJ,QAAQ;EACR,YAAY;EACb;CACD,MAAM;EACJ,QAAQ;EACR,YAAY;EACb;CACD,MAAM;EACJ,QAAQ;EACR,YAAY,OAAO;EACpB;CACF;AAED,SAAgB,eAAe,OAA+B;CAC5D,IAAI,OAAO,UAAU;AAErB,KAAI,OAAO,UAAU,SACnB,QAAO,IAAI,KAAK;AAGlB,KAAI,QAAQ,UAAU,KAAK,WACzB,QAAO,UAAU;UACR,QAAQ,UAAU,KAAK,WAChC,QAAO,UAAU;KAEjB,QAAO,UAAU;AAGnB,QAAO,GAAGA,oBAAM,QAAQ,KAAK,YAAY,EAAE,GAAG,KAAK"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { round } from "./round.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/format-file-size.ts
|
|
4
|
+
const FILE_SIZE = {
|
|
5
|
+
BYTE: {
|
|
6
|
+
symbol: "B",
|
|
7
|
+
multiplier: 1
|
|
8
|
+
},
|
|
9
|
+
KILO: {
|
|
10
|
+
symbol: "KiB",
|
|
11
|
+
multiplier: 1024
|
|
12
|
+
},
|
|
13
|
+
MEGA: {
|
|
14
|
+
symbol: "MiB",
|
|
15
|
+
multiplier: 1024 * 1024
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function formatFileSize(value) {
|
|
19
|
+
let unit = FILE_SIZE.BYTE;
|
|
20
|
+
if (typeof value !== "number") return `0${unit.symbol}`;
|
|
21
|
+
if (value < FILE_SIZE.KILO.multiplier) unit = FILE_SIZE.BYTE;
|
|
22
|
+
else if (value < FILE_SIZE.MEGA.multiplier) unit = FILE_SIZE.KILO;
|
|
23
|
+
else unit = FILE_SIZE.MEGA;
|
|
24
|
+
return `${round(value / unit.multiplier, 2)}${unit.symbol}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { formatFileSize };
|
|
29
|
+
//# sourceMappingURL=format-file-size.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-file-size.mjs","names":[],"sources":["../../src/utils/format-file-size.ts"],"sourcesContent":["import { round } from './round';\n\nconst FILE_SIZE = {\n BYTE: {\n symbol: 'B',\n multiplier: 1,\n },\n KILO: {\n symbol: 'KiB',\n multiplier: 1024,\n },\n MEGA: {\n symbol: 'MiB',\n multiplier: 1024 * 1024,\n },\n}\n\nexport function formatFileSize(value?: number | null): string {\n let unit = FILE_SIZE.BYTE;\n\n if (typeof value !== 'number') {\n return `0${unit.symbol}`;\n }\n\n if (value < FILE_SIZE.KILO.multiplier) {\n unit = FILE_SIZE.BYTE;\n } else if (value < FILE_SIZE.MEGA.multiplier) {\n unit = FILE_SIZE.KILO;\n } else {\n unit = FILE_SIZE.MEGA;\n }\n\n return `${round(value / unit.multiplier, 2)}${unit.symbol}`;\n}\n"],"mappings":";;;AAEA,MAAM,YAAY;CAChB,MAAM;EACJ,QAAQ;EACR,YAAY;EACb;CACD,MAAM;EACJ,QAAQ;EACR,YAAY;EACb;CACD,MAAM;EACJ,QAAQ;EACR,YAAY,OAAO;EACpB;CACF;AAED,SAAgB,eAAe,OAA+B;CAC5D,IAAI,OAAO,UAAU;AAErB,KAAI,OAAO,UAAU,SACnB,QAAO,IAAI,KAAK;AAGlB,KAAI,QAAQ,UAAU,KAAK,WACzB,QAAO,UAAU;UACR,QAAQ,UAAU,KAAK,WAChC,QAAO,UAAU;KAEjB,QAAO,UAAU;AAGnB,QAAO,GAAG,MAAM,QAAQ,KAAK,YAAY,EAAE,GAAG,KAAK"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/omit.ts
|
|
3
|
+
function omit(data, keys) {
|
|
4
|
+
const result = {};
|
|
5
|
+
Object.keys(data).forEach((key) => {
|
|
6
|
+
if (!keys.includes(key)) result[key] = data[key];
|
|
7
|
+
});
|
|
8
|
+
return result;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.omit = omit;
|
|
13
|
+
//# sourceMappingURL=omit.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omit.cjs","names":[],"sources":["../../src/utils/omit.ts"],"sourcesContent":["export function omit<D extends object, K extends keyof D = keyof D>(\n data: D,\n keys: K[],\n): Omit<D, K> {\n const result = {} as D;\n const objectKeys = Object.keys(data) as Array<K>;\n\n objectKeys.forEach((key) => {\n if (!keys.includes(key)) {\n result[key] = data[key];\n }\n });\n\n return result;\n}\n"],"mappings":";;AAAA,SAAgB,KACd,MACA,MACY;CACZ,MAAM,SAAS,EAAE;AAGjB,CAFmB,OAAO,KAAK,KAAK,CAEzB,SAAS,QAAQ;AAC1B,MAAI,CAAC,KAAK,SAAS,IAAI,CACrB,QAAO,OAAO,KAAK;GAErB;AAEF,QAAO"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/utils/omit.ts
|
|
2
|
+
function omit(data, keys) {
|
|
3
|
+
const result = {};
|
|
4
|
+
Object.keys(data).forEach((key) => {
|
|
5
|
+
if (!keys.includes(key)) result[key] = data[key];
|
|
6
|
+
});
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { omit };
|
|
12
|
+
//# sourceMappingURL=omit.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omit.mjs","names":[],"sources":["../../src/utils/omit.ts"],"sourcesContent":["export function omit<D extends object, K extends keyof D = keyof D>(\n data: D,\n keys: K[],\n): Omit<D, K> {\n const result = {} as D;\n const objectKeys = Object.keys(data) as Array<K>;\n\n objectKeys.forEach((key) => {\n if (!keys.includes(key)) {\n result[key] = data[key];\n }\n });\n\n return result;\n}\n"],"mappings":";AAAA,SAAgB,KACd,MACA,MACY;CACZ,MAAM,SAAS,EAAE;AAGjB,CAFmB,OAAO,KAAK,KAAK,CAEzB,SAAS,QAAQ;AAC1B,MAAI,CAAC,KAAK,SAAS,IAAI,CACrB,QAAO,OAAO,KAAK;GAErB;AAEF,QAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"round.cjs","names":[],"sources":["../../src/utils/round.ts"],"sourcesContent":["export function round(value: number, precision = 2): number {\n const multiplier = 10 ** precision;\n return Math.round(value * multiplier) / multiplier; \n}\n"],"mappings":";;AAAA,SAAgB,MAAM,OAAe,YAAY,GAAW;CAC1D,MAAM,aAAa,MAAM;AACzB,QAAO,KAAK,MAAM,QAAQ,WAAW,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"round.mjs","names":[],"sources":["../../src/utils/round.ts"],"sourcesContent":["export function round(value: number, precision = 2): number {\n const multiplier = 10 ** precision;\n return Math.round(value * multiplier) / multiplier; \n}\n"],"mappings":";AAAA,SAAgB,MAAM,OAAe,YAAY,GAAW;CAC1D,MAAM,aAAa,MAAM;AACzB,QAAO,KAAK,MAAM,QAAQ,WAAW,GAAG"}
|
package/dist/write.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
node_path = require_runtime.__toESM(node_path);
|
|
4
|
+
let node_fs_promises = require("node:fs/promises");
|
|
5
|
+
node_fs_promises = require_runtime.__toESM(node_fs_promises);
|
|
6
|
+
|
|
7
|
+
//#region src/write.ts
|
|
8
|
+
async function rollupStatsWrite(filepath, stats) {
|
|
9
|
+
const content = JSON.stringify(stats, null, 2);
|
|
10
|
+
await node_fs_promises.default.mkdir(node_path.default.dirname(filepath), { recursive: true });
|
|
11
|
+
await node_fs_promises.default.writeFile(filepath, content);
|
|
12
|
+
return {
|
|
13
|
+
filepath,
|
|
14
|
+
content
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.rollupStatsWrite = rollupStatsWrite;
|
|
20
|
+
//# sourceMappingURL=write.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.cjs","names":["fs","path"],"sources":["../src/write.ts"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs/promises';\n\nexport type RollupStatsWriteResponse = {\n filepath: string;\n content: string;\n};\n\nexport type RollupStatsWrite = (\n filepath: string,\n stats: Record<string, unknown>\n) => RollupStatsWriteResponse;\n\nexport async function rollupStatsWrite<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(filepath: string, stats: T): Promise<RollupStatsWriteResponse> {\n const content = JSON.stringify(stats, null, 2);\n\n // Create base directory if it does not exist\n await fs.mkdir(path.dirname(filepath), { recursive: true });\n\n await fs.writeFile(filepath, content);\n\n return {\n filepath,\n content,\n };\n}\n"],"mappings":";;;;;;;AAaA,eAAsB,iBAEpB,UAAkB,OAA6C;CAC/D,MAAM,UAAU,KAAK,UAAU,OAAO,MAAM,EAAE;AAG9C,OAAMA,yBAAG,MAAMC,kBAAK,QAAQ,SAAS,EAAE,EAAE,WAAW,MAAM,CAAC;AAE3D,OAAMD,yBAAG,UAAU,UAAU,QAAQ;AAErC,QAAO;EACL;EACA;EACD"}
|
package/dist/write.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/write.d.ts
|
|
2
|
+
type RollupStatsWriteResponse = {
|
|
3
|
+
filepath: string;
|
|
4
|
+
content: string;
|
|
5
|
+
};
|
|
6
|
+
type RollupStatsWrite = (filepath: string, stats: Record<string, unknown>) => RollupStatsWriteResponse;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { RollupStatsWrite };
|
|
9
|
+
//# sourceMappingURL=write.d.cts.map
|
package/dist/write.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/write.d.ts
|
|
2
|
+
type RollupStatsWriteResponse = {
|
|
3
|
+
filepath: string;
|
|
4
|
+
content: string;
|
|
5
|
+
};
|
|
6
|
+
type RollupStatsWrite = (filepath: string, stats: Record<string, unknown>) => RollupStatsWriteResponse;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { RollupStatsWrite };
|
|
9
|
+
//# sourceMappingURL=write.d.mts.map
|
package/dist/write.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
//#region src/write.ts
|
|
5
|
+
async function rollupStatsWrite(filepath, stats) {
|
|
6
|
+
const content = JSON.stringify(stats, null, 2);
|
|
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
|
+
//#endregion
|
|
16
|
+
export { rollupStatsWrite };
|
|
17
|
+
//# sourceMappingURL=write.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.mjs","names":[],"sources":["../src/write.ts"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs/promises';\n\nexport type RollupStatsWriteResponse = {\n filepath: string;\n content: string;\n};\n\nexport type RollupStatsWrite = (\n filepath: string,\n stats: Record<string, unknown>\n) => RollupStatsWriteResponse;\n\nexport async function rollupStatsWrite<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(filepath: string, stats: T): Promise<RollupStatsWriteResponse> {\n const content = JSON.stringify(stats, null, 2);\n\n // Create base directory if it does not exist\n await fs.mkdir(path.dirname(filepath), { recursive: true });\n\n await fs.writeFile(filepath, content);\n\n return {\n filepath,\n content,\n };\n}\n"],"mappings":";;;;AAaA,eAAsB,iBAEpB,UAAkB,OAA6C;CAC/D,MAAM,UAAU,KAAK,UAAU,OAAO,MAAM,EAAE;AAG9C,OAAM,GAAG,MAAM,KAAK,QAAQ,SAAS,EAAE,EAAE,WAAW,MAAM,CAAC;AAE3D,OAAM,GAAG,UAAU,UAAU,QAAQ;AAErC,QAAO;EACL;EACA;EACD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rollup-plugin-stats",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "
|
|
3
|
+
"description": "Vite/Rolldown/Rollup plugin to generate bundle stats JSON file",
|
|
4
|
+
"version": "2.0.0-beta.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"repository": {
|
|
@@ -18,42 +18,55 @@
|
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
20
20
|
"vite",
|
|
21
|
-
"rollup",
|
|
22
21
|
"rolldown",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
22
|
+
"rollup",
|
|
23
|
+
"vite-plugin",
|
|
24
|
+
"rolldown-plugin",
|
|
25
|
+
"rollup-plugin",
|
|
25
26
|
"bundle-stats"
|
|
26
27
|
],
|
|
27
|
-
"main": "dist/cjs/index.js",
|
|
28
|
-
"module": "dist/esm/index.
|
|
29
|
-
"typings": "dist/
|
|
28
|
+
"main": "./dist/cjs/index.js",
|
|
29
|
+
"module": "./dist/esm/index.js",
|
|
30
|
+
"typings": "./dist/types/index.d.ts",
|
|
30
31
|
"files": [
|
|
31
32
|
"dist"
|
|
32
33
|
],
|
|
33
34
|
"exports": {
|
|
34
35
|
".": {
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./dist/index.d.mts",
|
|
38
|
+
"default": "./dist/index.mjs"
|
|
39
|
+
},
|
|
40
|
+
"require": {
|
|
41
|
+
"types": "./dist/index.d.cts",
|
|
42
|
+
"default": "./dist/index.cjs"
|
|
43
|
+
}
|
|
38
44
|
},
|
|
39
45
|
"./extract": {
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
"import": {
|
|
47
|
+
"types": "./dist/extract.d.mts",
|
|
48
|
+
"default": "./dist/extract.mjs"
|
|
49
|
+
},
|
|
50
|
+
"require": {
|
|
51
|
+
"types": "./dist/extract.d.cts",
|
|
52
|
+
"default": "./dist/extract.cjs"
|
|
53
|
+
}
|
|
43
54
|
}
|
|
44
55
|
},
|
|
45
56
|
"engines": {
|
|
46
57
|
"node": ">=18"
|
|
47
58
|
},
|
|
48
59
|
"scripts": {
|
|
49
|
-
"build": "tsdown",
|
|
60
|
+
"build": "npm run clean && npm run type-check && tsdown",
|
|
61
|
+
"clean": "rimraf ./dist",
|
|
62
|
+
"type-check": "tsc",
|
|
50
63
|
"lint": "eslint .",
|
|
51
64
|
"format": "prettier --write .",
|
|
52
65
|
"test:unit": "vitest test/unit",
|
|
53
66
|
"test:package": "npm run test:package:rolldown && npm run test:package:rollup && npm run test:package:vite",
|
|
54
|
-
"test:package:rolldown": "
|
|
55
|
-
"test:package:rollup": "
|
|
56
|
-
"test:package:vite": "
|
|
67
|
+
"test:package:rolldown": "cd test/package/rolldown && npm run test",
|
|
68
|
+
"test:package:rollup": "cd test/package/rollup && npm run test",
|
|
69
|
+
"test:package:vite": "cd test/package/vite && npm run test",
|
|
57
70
|
"bump": "./scripts/bump.sh",
|
|
58
71
|
"release": "./scripts/release.sh"
|
|
59
72
|
},
|
|
@@ -64,20 +77,23 @@
|
|
|
64
77
|
},
|
|
65
78
|
"devDependencies": {
|
|
66
79
|
"@eslint/js": "9.39.2",
|
|
67
|
-
"@release-it/conventional-changelog": "10.0.
|
|
68
|
-
"@
|
|
69
|
-
"@types/node": "25.
|
|
80
|
+
"@release-it/conventional-changelog": "10.0.5",
|
|
81
|
+
"@types/deep-freeze-strict": "1.1.2",
|
|
82
|
+
"@types/node": "^25.2.3",
|
|
70
83
|
"deep-freeze-strict": "1.1.1",
|
|
71
84
|
"eslint": "9.39.2",
|
|
72
|
-
"globals": "17.
|
|
85
|
+
"globals": "17.3.0",
|
|
73
86
|
"husky": "8.0.3",
|
|
74
|
-
"memfs": "4.
|
|
75
|
-
"prettier": "3.
|
|
76
|
-
"release-it": "19.2.
|
|
77
|
-
"
|
|
87
|
+
"memfs": "4.56.10",
|
|
88
|
+
"prettier": "3.8.1",
|
|
89
|
+
"release-it": "19.2.4",
|
|
90
|
+
"rimraf": "6.0.1",
|
|
91
|
+
"rollup": "4.57.1",
|
|
92
|
+
"tsdown": "0.20.3",
|
|
78
93
|
"typescript": "5.9.3",
|
|
79
|
-
"typescript-eslint": "8.
|
|
80
|
-
"
|
|
94
|
+
"typescript-eslint": "8.54.0",
|
|
95
|
+
"vite": "7.3.1",
|
|
96
|
+
"vitest": "4.0.18"
|
|
81
97
|
},
|
|
82
98
|
"peerDependencies": {
|
|
83
99
|
"rolldown": "^1.0.0-beta.0",
|
package/dist/cjs/extract.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require(`./extract2.cjs`);module.exports=e.t;
|
package/dist/cjs/extract.d.cts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { a as ModuleStats, c as StatsOptions, i as ChunkStatsOptionalProperties, l as extractRollupStats, n as AssetStatsOptionalProperties, o as ModuleStatsOptionalProperties, r as ChunkStats, s as Stats, t as AssetStats } from "./extract2.cjs";
|
|
2
|
-
export { AssetStats, AssetStatsOptionalProperties, ChunkStats, ChunkStatsOptionalProperties, ModuleStats, ModuleStatsOptionalProperties, Stats, StatsOptions, extractRollupStats as default };
|
package/dist/cjs/extract2.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function e(e,t){let n={};return Object.keys(e).forEach(r=>{t.includes(r)||(n[r]=e[r])}),n}function t(e,n){if(!n)return!1;if(Array.isArray(n)){let r=!1;for(let i=0;i<=n.length-1&&r===!1;i++)r=t(e,n[i]);return r}return typeof n==`function`?n(e):typeof n==`string`?!!e.match(n):`test`in n?n.test(e):!1}function n(n,r={}){let{source:i=!1,map:a=!1,excludeAssets:o,excludeModules:s}=r,c={};return Object.entries(n).forEach(([n,r])=>{if(!t(n,o)){if(r.type===`asset`){let t=[];i||t.push(`source`),c[n]=e(r,t);return}if(r.type===`chunk`){let o=[];i||o.push(`code`),a||o.push(`map`);let l=e(r,o),u={};Object.entries(l.modules).forEach(([n,r])=>{if(t(n,s))return;let a=[];i||a.push(`code`),u[n]=e(r,a)}),l.modules=u,c[n]=l;return}}}),c}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n}});
|
|
2
|
-
//# sourceMappingURL=extract2.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extract2.cjs","names":["output: Stats","assetStatsOmitKeys: Array<keyof AssetStatsOptionalProperties>","chunkStatsOmitKeys: Array<keyof ChunkStatsOptionalProperties>","chunkModulesStats: ChunkStats['modules']","moduleStatsOmitKeys: Array<keyof ModuleStatsOptionalProperties>"],"sources":["../../src/utils/omit.ts","../../src/utils/check-exclude-filepath.ts","../../src/extract.ts"],"sourcesContent":["export function omit<D extends object, K extends keyof D = keyof D>(\n data: D,\n keys: K[],\n): Omit<D, K> {\n const result = {} as D;\n const objectKeys = Object.keys(data) as Array<K>;\n\n objectKeys.forEach((key) => {\n if (!keys.includes(key)) {\n result[key] = data[key];\n }\n });\n\n return result;\n}\n","type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);\n\nexport type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>;\n\n/**\n * Check if filepath should be excluded based on patterns\n */\nexport function checkExcludeFilepath(\n filepath: string,\n patterns?: ExcludeFilepathPatterns,\n): boolean {\n if (!patterns) {\n return false;\n }\n\n if (Array.isArray(patterns)) {\n let res = false;\n\n for (let i = 0; i <= patterns.length - 1 && res === false; i++) {\n res = checkExcludeFilepath(filepath, patterns[i]);\n }\n\n return res;\n }\n\n if (typeof patterns === 'function') {\n return patterns(filepath);\n }\n\n if (typeof patterns === 'string') {\n return Boolean(filepath.match(patterns));\n }\n\n if ('test' in patterns) {\n return patterns.test(filepath);\n }\n\n return false;\n}\n","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":"AAAA,SAAgB,EACd,EACA,EACY,CACZ,IAAM,EAAS,EAAE,CASjB,OARmB,OAAO,KAAK,EAAK,CAEzB,QAAS,GAAQ,CACrB,EAAK,SAAS,EAAI,GACrB,EAAO,GAAO,EAAK,KAErB,CAEK,ECNT,SAAgB,EACd,EACA,EACS,CACT,GAAI,CAAC,EACH,MAAO,GAGT,GAAI,MAAM,QAAQ,EAAS,CAAE,CAC3B,IAAI,EAAM,GAEV,IAAK,IAAI,EAAI,EAAG,GAAK,EAAS,OAAS,GAAK,IAAQ,GAAO,IACzD,EAAM,EAAqB,EAAU,EAAS,GAAG,CAGnD,OAAO,EAeT,OAZI,OAAO,GAAa,WACf,EAAS,EAAS,CAGvB,OAAO,GAAa,SACf,EAAQ,EAAS,MAAM,EAAS,CAGrC,SAAU,EACL,EAAS,KAAK,EAAS,CAGzB,GCoBT,SAAwB,EAAmB,EAAsB,EAAwB,EAAE,CAAS,CAClG,GAAM,CAAE,SAAS,GAAO,MAAM,GAAO,gBAAe,kBAAmB,EAEjEA,EAAgB,EAAE,CAsExB,OApEA,OAAO,QAAQ,EAAO,CAAC,SAAS,CAAC,EAAqB,KAAsB,CAEtE,MAAqB,EAAqB,EAAc,CAI5D,IAAI,EAAiB,OAAS,QAAS,CACrC,IAAMC,EAAgE,EAAE,CAGnE,GACH,EAAmB,KAAK,SAAS,CAGnC,EAAO,GAAuB,EAC5B,EACA,EACD,CAED,OAGF,GAAI,EAAiB,OAAS,QAAS,CACrC,IAAMC,EAAgE,EAAE,CAGnE,GACH,EAAmB,KAAK,OAAO,CAI5B,GACH,EAAmB,KAAK,MAAM,CAGhC,IAAM,EAAa,EAAK,EAAkB,EAAmB,CAIvDC,EAA2C,EAAE,CAEnD,OAAO,QAAQ,EAAW,QAAQ,CAAC,SAAS,CAAC,EAAsB,KAAuB,CAExF,GAAI,EAAqB,EAAsB,EAAe,CAC5D,OAGF,IAAMC,EAAkE,EAAE,CAGrE,GACH,EAAoB,KAAK,OAAO,CAGlC,EAAkB,GAAwB,EACxC,EACA,EACD,EACD,CAEF,EAAW,QAAU,EAErB,EAAO,GAAuB,EAE9B,UAEF,CAEK"}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=require(`./extract2.cjs`);let l=require(`node:path`);l=s(l);let u=require(`node:process`);u=s(u);let d=require(`node:fs/promises`);d=s(d);async function f(e,t){let n=JSON.stringify(t,null,2);return await d.default.mkdir(l.default.dirname(e),{recursive:!0}),await d.default.writeFile(e,n),{filepath:e,content:n}}function p(e,t=2){let n=10^t;return Math.round(e*n)/n}const m={BYTE:{symbol:`B`,multiplier:1},KILO:{symbol:`KiB`,multiplier:1024},MEGA:{symbol:`MiB`,multiplier:1024*1024}};function h(e){let t=m.BYTE;return typeof e==`number`?(t=e<m.KILO.multiplier?m.BYTE:e<m.MEGA.multiplier?m.KILO:m.MEGA,`${p(e/t.multiplier,2)}${t.symbol}`):`0${t.symbol}`}const g=`rollupStats`,_=`stats.json`;function v(e={}){return{name:`rollupStats`,async generateBundle(t,n){let{fileName:r,stats:i,write:a=f}=(typeof e==`function`?e(t):e)||{},o=r||`stats.json`,s=l.default.isAbsolute(o)?o:l.default.join(t.dir||u.default.cwd(),o),d=c.t(n,i);try{let e=await a(s,d),t=Buffer.byteLength(e.content,`utf-8`);this.info(`Stats saved to ${e.filepath} (${h(t)})`)}catch(e){this.warn(e)}}}}var y=v;module.exports=y;
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["fs","path","path","process","extractRollupStats","error: any"],"sources":["../../src/write.ts","../../src/utils/round.ts","../../src/utils/format-file-size.ts","../../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs/promises';\n\nexport type RollupStatsWriteResponse = {\n filepath: string;\n content: string;\n};\n\nexport type RollupStatsWrite = (\n filepath: string,\n stats: Record<string, unknown>\n) => RollupStatsWriteResponse;\n\nexport async function rollupStatsWrite<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(filepath: string, stats: T): Promise<RollupStatsWriteResponse> {\n const content = JSON.stringify(stats, null, 2);\n\n // Create base directory if it does not exist\n await fs.mkdir(path.dirname(filepath), { recursive: true });\n\n await fs.writeFile(filepath, content);\n\n return {\n filepath,\n content,\n };\n}\n","export function round(value: number, precision = 2) {\n const multiplier = 10 ^ precision;\n return Math.round(value * multiplier) / multiplier; \n}\n","import { round } from './round';\n\nconst FILE_SIZE = {\n BYTE: {\n symbol: 'B',\n multiplier: 1,\n },\n KILO: {\n symbol: 'KiB',\n multiplier: 1024,\n },\n MEGA: {\n symbol: 'MiB',\n multiplier: 1024 * 1024,\n },\n}\n\nexport function formatFileSize(value?: number | null): string {\n let unit = FILE_SIZE.BYTE;\n\n if (typeof value !== 'number') {\n return `0${unit.symbol}`;\n }\n\n if (value < FILE_SIZE.KILO.multiplier) {\n unit = FILE_SIZE.BYTE;\n } else if (value < FILE_SIZE.MEGA.multiplier) {\n unit = FILE_SIZE.KILO;\n } else {\n unit = FILE_SIZE.MEGA;\n }\n\n return `${round(value / unit.multiplier, 2)}${unit.symbol}`;\n}\n","import path from 'node:path';\nimport process from 'node:process';\nimport type { Plugin, OutputOptions } from 'rollup';\n\nimport extractRollupStats, { type StatsOptions } from './extract';\nimport { type RollupStatsWrite, rollupStatsWrite } from './write';\nimport { formatFileSize } from './utils/format-file-size';\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\n\nfunction rollupStats(options: RollupStatsOptionsOrOutputOptions = {}): Plugin {\n return {\n name: PLUGIN_NAME,\n async generateBundle(context, bundle) {\n const resolvedOptions = typeof options === 'function' ? options(context) : options;\n const { fileName, stats: statsOptions, write = rollupStatsWrite } = 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(`Stats saved to ${res.filepath} (${formatFileSize(outputSize)})`);\n } catch (error: any) { // eslint-disable-line\n // Log error, but do not throw to allow the compilation to continue\n this.warn(error);\n }\n },\n } satisfies Plugin;\n}\n\nexport default rollupStats;\n\n"],"mappings":"gnBAaA,eAAsB,EAEpB,EAAkB,EAA6C,CAC/D,IAAM,EAAU,KAAK,UAAU,EAAO,KAAM,EAAE,CAO9C,OAJA,MAAMA,EAAAA,QAAG,MAAMC,EAAAA,QAAK,QAAQ,EAAS,CAAE,CAAE,UAAW,GAAM,CAAC,CAE3D,MAAMD,EAAAA,QAAG,UAAU,EAAU,EAAQ,CAE9B,CACL,WACA,UACD,CC1BH,SAAgB,EAAM,EAAe,EAAY,EAAG,CAClD,IAAM,EAAa,GAAK,EACxB,OAAO,KAAK,MAAM,EAAQ,EAAW,CAAG,ECA1C,MAAM,EAAY,CAChB,KAAM,CACJ,OAAQ,IACR,WAAY,EACb,CACD,KAAM,CACJ,OAAQ,MACR,WAAY,KACb,CACD,KAAM,CACJ,OAAQ,MACR,WAAY,KAAO,KACpB,CACF,CAED,SAAgB,EAAe,EAA+B,CAC5D,IAAI,EAAO,EAAU,KAcrB,OAZI,OAAO,GAAU,UAIrB,AAKE,EALE,EAAQ,EAAU,KAAK,WAClB,EAAU,KACR,EAAQ,EAAU,KAAK,WACzB,EAAU,KAEV,EAAU,KAGZ,GAAG,EAAM,EAAQ,EAAK,WAAY,EAAE,GAAG,EAAK,UAX1C,IAAI,EAAK,SCbpB,MAAM,EAAc,cACd,EAAoB,aAwB1B,SAAS,EAAY,EAA6C,EAAE,CAAU,CAC5E,MAAO,CACL,KAAM,cACN,MAAM,eAAe,EAAS,EAAQ,CAEpC,GAAM,CAAE,WAAU,MAAO,EAAc,QAAQ,IADvB,OAAO,GAAY,WAAa,EAAQ,EAAQ,CAAG,IACY,EAAE,CAEnF,EAAmB,GAAY,aAC/B,EAAWE,EAAAA,QAAK,WAAW,EAAiB,CAC9C,EACAA,EAAAA,QAAK,KAAK,EAAQ,KAAOC,EAAAA,QAAQ,KAAK,CAAE,EAAiB,CAEvD,EAAQC,EAAAA,EAAmB,EAAQ,EAAa,CAEtD,GAAI,CACF,IAAM,EAAM,MAAM,EAAM,EAAU,EAAM,CAClC,EAAa,OAAO,WAAW,EAAI,QAAS,QAAQ,CAE1D,KAAK,KAAK,kBAAkB,EAAI,SAAS,IAAI,EAAe,EAAW,CAAC,GAAG,OACpEC,EAAY,CAEnB,KAAK,KAAK,EAAM,GAGrB,CAGH,IAAA,EAAe"}
|
package/dist/esm/extract.d.mts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { a as ModuleStats, c as StatsOptions, i as ChunkStatsOptionalProperties, l as extractRollupStats, n as AssetStatsOptionalProperties, o as ModuleStatsOptionalProperties, r as ChunkStats, s as Stats, t as AssetStats } from "./extract2.mjs";
|
|
2
|
-
export { AssetStats, AssetStatsOptionalProperties, ChunkStats, ChunkStatsOptionalProperties, ModuleStats, ModuleStatsOptionalProperties, Stats, StatsOptions, extractRollupStats as default };
|
package/dist/esm/extract.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./extract2.mjs";export{e as default};
|
package/dist/esm/extract2.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function e(e,t){let n={};return Object.keys(e).forEach(r=>{t.includes(r)||(n[r]=e[r])}),n}function t(e,n){if(!n)return!1;if(Array.isArray(n)){let r=!1;for(let i=0;i<=n.length-1&&r===!1;i++)r=t(e,n[i]);return r}return typeof n==`function`?n(e):typeof n==`string`?!!e.match(n):`test`in n?n.test(e):!1}function n(n,r={}){let{source:i=!1,map:a=!1,excludeAssets:o,excludeModules:s}=r,c={};return Object.entries(n).forEach(([n,r])=>{if(!t(n,o)){if(r.type===`asset`){let t=[];i||t.push(`source`),c[n]=e(r,t);return}if(r.type===`chunk`){let o=[];i||o.push(`code`),a||o.push(`map`);let l=e(r,o),u={};Object.entries(l.modules).forEach(([n,r])=>{if(t(n,s))return;let a=[];i||a.push(`code`),u[n]=e(r,a)}),l.modules=u,c[n]=l;return}}}),c}export{n as t};
|
|
2
|
-
//# sourceMappingURL=extract2.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extract2.mjs","names":["output: Stats","assetStatsOmitKeys: Array<keyof AssetStatsOptionalProperties>","chunkStatsOmitKeys: Array<keyof ChunkStatsOptionalProperties>","chunkModulesStats: ChunkStats['modules']","moduleStatsOmitKeys: Array<keyof ModuleStatsOptionalProperties>"],"sources":["../../src/utils/omit.ts","../../src/utils/check-exclude-filepath.ts","../../src/extract.ts"],"sourcesContent":["export function omit<D extends object, K extends keyof D = keyof D>(\n data: D,\n keys: K[],\n): Omit<D, K> {\n const result = {} as D;\n const objectKeys = Object.keys(data) as Array<K>;\n\n objectKeys.forEach((key) => {\n if (!keys.includes(key)) {\n result[key] = data[key];\n }\n });\n\n return result;\n}\n","type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);\n\nexport type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>;\n\n/**\n * Check if filepath should be excluded based on patterns\n */\nexport function checkExcludeFilepath(\n filepath: string,\n patterns?: ExcludeFilepathPatterns,\n): boolean {\n if (!patterns) {\n return false;\n }\n\n if (Array.isArray(patterns)) {\n let res = false;\n\n for (let i = 0; i <= patterns.length - 1 && res === false; i++) {\n res = checkExcludeFilepath(filepath, patterns[i]);\n }\n\n return res;\n }\n\n if (typeof patterns === 'function') {\n return patterns(filepath);\n }\n\n if (typeof patterns === 'string') {\n return Boolean(filepath.match(patterns));\n }\n\n if ('test' in patterns) {\n return patterns.test(filepath);\n }\n\n return false;\n}\n","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":"AAAA,SAAgB,EACd,EACA,EACY,CACZ,IAAM,EAAS,EAAE,CASjB,OARmB,OAAO,KAAK,EAAK,CAEzB,QAAS,GAAQ,CACrB,EAAK,SAAS,EAAI,GACrB,EAAO,GAAO,EAAK,KAErB,CAEK,ECNT,SAAgB,EACd,EACA,EACS,CACT,GAAI,CAAC,EACH,MAAO,GAGT,GAAI,MAAM,QAAQ,EAAS,CAAE,CAC3B,IAAI,EAAM,GAEV,IAAK,IAAI,EAAI,EAAG,GAAK,EAAS,OAAS,GAAK,IAAQ,GAAO,IACzD,EAAM,EAAqB,EAAU,EAAS,GAAG,CAGnD,OAAO,EAeT,OAZI,OAAO,GAAa,WACf,EAAS,EAAS,CAGvB,OAAO,GAAa,SACf,EAAQ,EAAS,MAAM,EAAS,CAGrC,SAAU,EACL,EAAS,KAAK,EAAS,CAGzB,GCoBT,SAAwB,EAAmB,EAAsB,EAAwB,EAAE,CAAS,CAClG,GAAM,CAAE,SAAS,GAAO,MAAM,GAAO,gBAAe,kBAAmB,EAEjEA,EAAgB,EAAE,CAsExB,OApEA,OAAO,QAAQ,EAAO,CAAC,SAAS,CAAC,EAAqB,KAAsB,CAEtE,MAAqB,EAAqB,EAAc,CAI5D,IAAI,EAAiB,OAAS,QAAS,CACrC,IAAMC,EAAgE,EAAE,CAGnE,GACH,EAAmB,KAAK,SAAS,CAGnC,EAAO,GAAuB,EAC5B,EACA,EACD,CAED,OAGF,GAAI,EAAiB,OAAS,QAAS,CACrC,IAAMC,EAAgE,EAAE,CAGnE,GACH,EAAmB,KAAK,OAAO,CAI5B,GACH,EAAmB,KAAK,MAAM,CAGhC,IAAM,EAAa,EAAK,EAAkB,EAAmB,CAIvDC,EAA2C,EAAE,CAEnD,OAAO,QAAQ,EAAW,QAAQ,CAAC,SAAS,CAAC,EAAsB,KAAuB,CAExF,GAAI,EAAqB,EAAsB,EAAe,CAC5D,OAGF,IAAMC,EAAkE,EAAE,CAGrE,GACH,EAAoB,KAAK,OAAO,CAGlC,EAAkB,GAAwB,EACxC,EACA,EACD,EACD,CAEF,EAAW,QAAU,EAErB,EAAO,GAAuB,EAE9B,UAEF,CAEK"}
|
package/dist/esm/index.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./extract2.mjs";import t from"node:path";import n from"node:process";import r from"node:fs/promises";async function i(e,n){let i=JSON.stringify(n,null,2);return await r.mkdir(t.dirname(e),{recursive:!0}),await r.writeFile(e,i),{filepath:e,content:i}}function a(e,t=2){let n=10^t;return Math.round(e*n)/n}const o={BYTE:{symbol:`B`,multiplier:1},KILO:{symbol:`KiB`,multiplier:1024},MEGA:{symbol:`MiB`,multiplier:1024*1024}};function s(e){let t=o.BYTE;return typeof e==`number`?(t=e<o.KILO.multiplier?o.BYTE:e<o.MEGA.multiplier?o.KILO:o.MEGA,`${a(e/t.multiplier,2)}${t.symbol}`):`0${t.symbol}`}function c(r={}){return{name:`rollupStats`,async generateBundle(a,o){let{fileName:c,stats:l,write:u=i}=(typeof r==`function`?r(a):r)||{},d=c||`stats.json`,f=t.isAbsolute(d)?d:t.join(a.dir||n.cwd(),d),p=e(o,l);try{let e=await u(f,p),t=Buffer.byteLength(e.content,`utf-8`);this.info(`Stats saved to ${e.filepath} (${s(t)})`)}catch(e){this.warn(e)}}}}var l=c;export{l as default};
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["error: any"],"sources":["../../src/write.ts","../../src/utils/round.ts","../../src/utils/format-file-size.ts","../../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs/promises';\n\nexport type RollupStatsWriteResponse = {\n filepath: string;\n content: string;\n};\n\nexport type RollupStatsWrite = (\n filepath: string,\n stats: Record<string, unknown>\n) => RollupStatsWriteResponse;\n\nexport async function rollupStatsWrite<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(filepath: string, stats: T): Promise<RollupStatsWriteResponse> {\n const content = JSON.stringify(stats, null, 2);\n\n // Create base directory if it does not exist\n await fs.mkdir(path.dirname(filepath), { recursive: true });\n\n await fs.writeFile(filepath, content);\n\n return {\n filepath,\n content,\n };\n}\n","export function round(value: number, precision = 2) {\n const multiplier = 10 ^ precision;\n return Math.round(value * multiplier) / multiplier; \n}\n","import { round } from './round';\n\nconst FILE_SIZE = {\n BYTE: {\n symbol: 'B',\n multiplier: 1,\n },\n KILO: {\n symbol: 'KiB',\n multiplier: 1024,\n },\n MEGA: {\n symbol: 'MiB',\n multiplier: 1024 * 1024,\n },\n}\n\nexport function formatFileSize(value?: number | null): string {\n let unit = FILE_SIZE.BYTE;\n\n if (typeof value !== 'number') {\n return `0${unit.symbol}`;\n }\n\n if (value < FILE_SIZE.KILO.multiplier) {\n unit = FILE_SIZE.BYTE;\n } else if (value < FILE_SIZE.MEGA.multiplier) {\n unit = FILE_SIZE.KILO;\n } else {\n unit = FILE_SIZE.MEGA;\n }\n\n return `${round(value / unit.multiplier, 2)}${unit.symbol}`;\n}\n","import path from 'node:path';\nimport process from 'node:process';\nimport type { Plugin, OutputOptions } from 'rollup';\n\nimport extractRollupStats, { type StatsOptions } from './extract';\nimport { type RollupStatsWrite, rollupStatsWrite } from './write';\nimport { formatFileSize } from './utils/format-file-size';\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\n\nfunction rollupStats(options: RollupStatsOptionsOrOutputOptions = {}): Plugin {\n return {\n name: PLUGIN_NAME,\n async generateBundle(context, bundle) {\n const resolvedOptions = typeof options === 'function' ? options(context) : options;\n const { fileName, stats: statsOptions, write = rollupStatsWrite } = 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(`Stats saved to ${res.filepath} (${formatFileSize(outputSize)})`);\n } catch (error: any) { // eslint-disable-line\n // Log error, but do not throw to allow the compilation to continue\n this.warn(error);\n }\n },\n } satisfies Plugin;\n}\n\nexport default rollupStats;\n\n"],"mappings":"wHAaA,eAAsB,EAEpB,EAAkB,EAA6C,CAC/D,IAAM,EAAU,KAAK,UAAU,EAAO,KAAM,EAAE,CAO9C,OAJA,MAAM,EAAG,MAAM,EAAK,QAAQ,EAAS,CAAE,CAAE,UAAW,GAAM,CAAC,CAE3D,MAAM,EAAG,UAAU,EAAU,EAAQ,CAE9B,CACL,WACA,UACD,CC1BH,SAAgB,EAAM,EAAe,EAAY,EAAG,CAClD,IAAM,EAAa,GAAK,EACxB,OAAO,KAAK,MAAM,EAAQ,EAAW,CAAG,ECA1C,MAAM,EAAY,CAChB,KAAM,CACJ,OAAQ,IACR,WAAY,EACb,CACD,KAAM,CACJ,OAAQ,MACR,WAAY,KACb,CACD,KAAM,CACJ,OAAQ,MACR,WAAY,KAAO,KACpB,CACF,CAED,SAAgB,EAAe,EAA+B,CAC5D,IAAI,EAAO,EAAU,KAcrB,OAZI,OAAO,GAAU,UAIrB,AAKE,EALE,EAAQ,EAAU,KAAK,WAClB,EAAU,KACR,EAAQ,EAAU,KAAK,WACzB,EAAU,KAEV,EAAU,KAGZ,GAAG,EAAM,EAAQ,EAAK,WAAY,EAAE,GAAG,EAAK,UAX1C,IAAI,EAAK,SCYpB,SAAS,EAAY,EAA6C,EAAE,CAAU,CAC5E,MAAO,CACL,KAAM,cACN,MAAM,eAAe,EAAS,EAAQ,CAEpC,GAAM,CAAE,WAAU,MAAO,EAAc,QAAQ,IADvB,OAAO,GAAY,WAAa,EAAQ,EAAQ,CAAG,IACY,EAAE,CAEnF,EAAmB,GAAY,aAC/B,EAAW,EAAK,WAAW,EAAiB,CAC9C,EACA,EAAK,KAAK,EAAQ,KAAO,EAAQ,KAAK,CAAE,EAAiB,CAEvD,EAAQ,EAAmB,EAAQ,EAAa,CAEtD,GAAI,CACF,IAAM,EAAM,MAAM,EAAM,EAAU,EAAM,CAClC,EAAa,OAAO,WAAW,EAAI,QAAS,QAAQ,CAE1D,KAAK,KAAK,kBAAkB,EAAI,SAAS,IAAI,EAAe,EAAW,CAAC,GAAG,OACpEA,EAAY,CAEnB,KAAK,KAAK,EAAM,GAGrB,CAGH,IAAA,EAAe"}
|