rollup-plugin-stats 2.1.2 → 2.1.3-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 +6 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.d.cts +10 -8
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts +10 -8
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
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
|
+
[](https://npmx.dev/package/rollup-plugin-stats)
|
|
10
|
+
[](https://npmx.dev/package/rollup-plugin-stats)
|
|
11
|
+
[](https://npmx.dev/package/rollup-plugin-stats)
|
|
12
|
+
|
|
9
13
|
Vite/Rolldown/Rollup plugin to generate bundle stats JSON file
|
|
10
14
|
|
|
11
15
|
## Install
|
|
@@ -93,7 +97,7 @@ export default defineConfig({
|
|
|
93
97
|
- `map` - output chunk map property (default: `false`)
|
|
94
98
|
- `excludeAssets` - exclude matching assets: `string | RegExp | ((filepath: string) => boolean) | Array<string | RegExp | ((filepath: string) => boolean)>`
|
|
95
99
|
- `excludeModules` - exclude matching modules: `string | RegExp | ((filepath: string) => boolean) | Array<string | RegExp | ((filepath: string) => boolean)>`
|
|
96
|
-
|
|
100
|
+
|
|
97
101
|
## Development setup
|
|
98
102
|
|
|
99
103
|
### Use the project node version
|
|
@@ -108,7 +112,7 @@ nvm use
|
|
|
108
112
|
npm install
|
|
109
113
|
```
|
|
110
114
|
|
|
111
|
-
### Prepare
|
|
115
|
+
### Prepare
|
|
112
116
|
|
|
113
117
|
```shell
|
|
114
118
|
npm run prepare
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["rollupStats"],"sources":["../src/index.ts"],"sourcesContent":["import { rollupStats } from './plugin';\n\nexport type {\n RollupStatsOptions,\n RollupStatsOptionsOrOutputOptions,\n} from './plugin';\n\nexport type {\n OutputAsset,\n OutputBundle,\n OutputChunk,\n RenderedModule,\n SourceMap,\n} from './types';\n\nexport default rollupStats;\n"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["rollupStats"],"sources":["../src/index.ts"],"sourcesContent":["import { rollupStats } from './plugin';\n\nexport type {\n RollupStatsPlugin,\n RollupStatsPluginContext,\n RollupStatsOptions,\n RollupStatsOutputOptions,\n RollupStatsOptionsOrOutputOptions,\n} from './plugin';\n\nexport type {\n OutputAsset,\n OutputBundle,\n OutputChunk,\n RenderedModule,\n SourceMap,\n} from './types';\n\nexport default rollupStats;\n"],"mappings":";;;AAkBA,kBAAeA"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { OutputAsset, OutputBundle, OutputChunk, RenderedModule, SourceMap } from "./types.cjs";
|
|
2
|
-
import { RollupStatsOptions, RollupStatsOptionsOrOutputOptions, rollupStats } from "./plugin.cjs";
|
|
3
|
-
export { type OutputAsset, type OutputBundle, type OutputChunk, type RenderedModule, type RollupStatsOptions, type RollupStatsOptionsOrOutputOptions, type SourceMap, rollupStats as default };
|
|
2
|
+
import { RollupStatsOptions, RollupStatsOptionsOrOutputOptions, RollupStatsOutputOptions, RollupStatsPlugin, RollupStatsPluginContext, rollupStats } from "./plugin.cjs";
|
|
3
|
+
export { type OutputAsset, type OutputBundle, type OutputChunk, type RenderedModule, type RollupStatsOptions, type RollupStatsOptionsOrOutputOptions, type RollupStatsOutputOptions, type RollupStatsPlugin, type RollupStatsPluginContext, type SourceMap, rollupStats as default };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { OutputAsset, OutputBundle, OutputChunk, RenderedModule, SourceMap } from "./types.mjs";
|
|
2
|
-
import { RollupStatsOptions, RollupStatsOptionsOrOutputOptions, rollupStats } from "./plugin.mjs";
|
|
3
|
-
export { type OutputAsset, type OutputBundle, type OutputChunk, type RenderedModule, type RollupStatsOptions, type RollupStatsOptionsOrOutputOptions, type SourceMap, rollupStats as default };
|
|
2
|
+
import { RollupStatsOptions, RollupStatsOptionsOrOutputOptions, RollupStatsOutputOptions, RollupStatsPlugin, RollupStatsPluginContext, rollupStats } from "./plugin.mjs";
|
|
3
|
+
export { type OutputAsset, type OutputBundle, type OutputChunk, type RenderedModule, type RollupStatsOptions, type RollupStatsOptionsOrOutputOptions, type RollupStatsOutputOptions, type RollupStatsPlugin, type RollupStatsPluginContext, type SourceMap, rollupStats as default };
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { rollupStats } from './plugin';\n\nexport type {\n RollupStatsOptions,\n RollupStatsOptionsOrOutputOptions,\n} from './plugin';\n\nexport type {\n OutputAsset,\n OutputBundle,\n OutputChunk,\n RenderedModule,\n SourceMap,\n} from './types';\n\nexport default rollupStats;\n"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { rollupStats } from './plugin';\n\nexport type {\n RollupStatsPlugin,\n RollupStatsPluginContext,\n RollupStatsOptions,\n RollupStatsOutputOptions,\n RollupStatsOptionsOrOutputOptions,\n} from './plugin';\n\nexport type {\n OutputAsset,\n OutputBundle,\n OutputChunk,\n RenderedModule,\n SourceMap,\n} from './types';\n\nexport default rollupStats;\n"],"mappings":";;;AAkBA,kBAAe"}
|
package/dist/plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","names":["rollupStatsWrite","path","process","extractRollupStats","formatFileSize"],"sources":["../src/plugin.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 { OutputBundle } from './types';\n\nconst PLUGIN_NAME = 'rollupStats';\nconst DEFAULT_FILE_NAME = 'stats.json';\n\n/**\n * A subset of resolved output options provided to the `generateBundle` hook by Vite/Rolldown/Rollup,\n * containing only the fields this plugin uses to generate a stats file for a specific output.\n */\nexport type
|
|
1
|
+
{"version":3,"file":"plugin.cjs","names":["rollupStatsWrite","path","process","extractRollupStats","formatFileSize"],"sources":["../src/plugin.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 { OutputBundle } from './types';\n\nconst PLUGIN_NAME = 'rollupStats';\nconst DEFAULT_FILE_NAME = 'stats.json';\n\n/**\n * A subset of resolved output options provided to the `generateBundle` hook by Vite/Rolldown/Rollup,\n * containing only the fields this plugin uses to generate a stats file for a specific output.\n */\nexport type RollupStatsOutputOptions = {\n /** Output directory for the generated files. */\n dir?: string | undefined;\n\n /** Output format */\n format?:\n | 'es'\n | 'esm'\n | 'module'\n | 'cjs'\n | 'commonjs'\n | 'iife'\n | 'umd'\n | 'amd'\n | 'system'\n | 'systemjs'\n | undefined;\n};\n\n/**\n * Subset of the Vite/Rolldown/Rollup plugin hook context (`this`) used by this plugin.\n */\nexport type RollupStatsPluginContext = {\n info: (message: string) => void;\n warn: (message: string) => void;\n error: (message: string) => void;\n debug: (message: string) => void;\n};\n\n/**\n * Minimum plugin interface compatible with Vite/Rolldown/Rollup.\n *\n * @example\n * {\n * name: 'rollupStats',\n * async generateBundle(outputOptions, bundle) { ... },\n * }\n */\nexport type RollupStatsPlugin = {\n /** Unique identifier for the plugin, used in error messages and logs. */\n name: string;\n\n /**\n * Hook called after the bundle has been fully generated but before it is\n * written to disk. Receives the resolved output options and the complete\n * output bundle map.\n */\n generateBundle?: (\n this: RollupStatsPluginContext,\n outputOptions: RollupStatsOutputOptions,\n bundle: OutputBundle,\n isWrite: boolean\n ) => void | Promise<void>;\n};\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\nexport type RollupStatsOptionsOrOutputOptions =\n | RollupStatsOptions\n | ((outputOptions: RollupStatsOutputOptions) => RollupStatsOptions);\n\nexport function rollupStats(\n options: RollupStatsOptionsOrOutputOptions = {}\n): RollupStatsPlugin {\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 RollupStatsPlugin;\n}\n"],"mappings":";;;;;;;;;;AAQA,MAAM,cAAc;AACpB,MAAM,oBAAoB;AAkF1B,SAAgB,YACd,UAA6C,EAAE,EAC5B;AACnB,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"}
|
package/dist/plugin.d.cts
CHANGED
|
@@ -7,16 +7,18 @@ import { RollupStatsWrite } from "./write.cjs";
|
|
|
7
7
|
* A subset of resolved output options provided to the `generateBundle` hook by Vite/Rolldown/Rollup,
|
|
8
8
|
* containing only the fields this plugin uses to generate a stats file for a specific output.
|
|
9
9
|
*/
|
|
10
|
-
type
|
|
10
|
+
type RollupStatsOutputOptions = {
|
|
11
11
|
/** Output directory for the generated files. */dir?: string | undefined; /** Output format */
|
|
12
12
|
format?: 'es' | 'esm' | 'module' | 'cjs' | 'commonjs' | 'iife' | 'umd' | 'amd' | 'system' | 'systemjs' | undefined;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Subset of the Vite/Rolldown/Rollup plugin hook context (`this`) used by this plugin.
|
|
16
16
|
*/
|
|
17
|
-
type
|
|
18
|
-
|
|
17
|
+
type RollupStatsPluginContext = {
|
|
18
|
+
info: (message: string) => void;
|
|
19
19
|
warn: (message: string) => void;
|
|
20
|
+
error: (message: string) => void;
|
|
21
|
+
debug: (message: string) => void;
|
|
20
22
|
};
|
|
21
23
|
/**
|
|
22
24
|
* Minimum plugin interface compatible with Vite/Rolldown/Rollup.
|
|
@@ -27,14 +29,14 @@ type PluginContext = {
|
|
|
27
29
|
* async generateBundle(outputOptions, bundle) { ... },
|
|
28
30
|
* }
|
|
29
31
|
*/
|
|
30
|
-
type
|
|
32
|
+
type RollupStatsPlugin = {
|
|
31
33
|
/** Unique identifier for the plugin, used in error messages and logs. */name: string;
|
|
32
34
|
/**
|
|
33
35
|
* Hook called after the bundle has been fully generated but before it is
|
|
34
36
|
* written to disk. Receives the resolved output options and the complete
|
|
35
37
|
* output bundle map.
|
|
36
38
|
*/
|
|
37
|
-
generateBundle?: (this:
|
|
39
|
+
generateBundle?: (this: RollupStatsPluginContext, outputOptions: RollupStatsOutputOptions, bundle: OutputBundle, isWrite: boolean) => void | Promise<void>;
|
|
38
40
|
};
|
|
39
41
|
type RollupStatsOptions = {
|
|
40
42
|
/**
|
|
@@ -52,8 +54,8 @@ type RollupStatsOptions = {
|
|
|
52
54
|
*/
|
|
53
55
|
write?: RollupStatsWrite;
|
|
54
56
|
};
|
|
55
|
-
type RollupStatsOptionsOrOutputOptions = RollupStatsOptions | ((outputOptions:
|
|
56
|
-
declare function rollupStats(options?: RollupStatsOptionsOrOutputOptions):
|
|
57
|
+
type RollupStatsOptionsOrOutputOptions = RollupStatsOptions | ((outputOptions: RollupStatsOutputOptions) => RollupStatsOptions);
|
|
58
|
+
declare function rollupStats(options?: RollupStatsOptionsOrOutputOptions): RollupStatsPlugin;
|
|
57
59
|
//#endregion
|
|
58
|
-
export { RollupStatsOptions, RollupStatsOptionsOrOutputOptions, rollupStats };
|
|
60
|
+
export { RollupStatsOptions, RollupStatsOptionsOrOutputOptions, RollupStatsOutputOptions, RollupStatsPlugin, RollupStatsPluginContext, rollupStats };
|
|
59
61
|
//# sourceMappingURL=plugin.d.cts.map
|
package/dist/plugin.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;;;AAeA;;KAAY,
|
|
1
|
+
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;;;AAeA;;KAAY,wBAAA;EAEV,gDAAA,GAAA,uBAoBU;EAjBV,MAAA;AAAA;;;;KAiBU,wBAAA;EACV,IAAA,GAAO,OAAA;EACP,IAAA,GAAO,OAAA;EACP,KAAA,GAAQ,OAAA;EACR,KAAA,GAAQ,OAAA;AAAA;;;AAYV;;;;;;;KAAY,iBAAA;EAcS,yEAZnB,IAAA;EAOA;;;;;EAAA,cAAA,IACE,IAAA,EAAM,wBAAA,EACN,aAAA,EAAe,wBAAA,EACf,MAAA,EAAQ,YAAA,EACR,OAAA,qBACU,OAAA;AAAA;AAAA,KAGF,kBAAA;EAHE;;;AAGd;EAKE,QAAA;;;;EAIA,KAAA,GAAQ,YAAA;EAAA;;;;EAKR,KAAA,GAAQ,gBAAA;AAAA;AAAA,KAGE,iCAAA,GACR,kBAAA,KACE,aAAA,EAAe,wBAAA,KAA6B,kBAAA;AAAA,iBAElC,WAAA,CACd,OAAA,GAAS,iCAAA,GACR,iBAAA"}
|
package/dist/plugin.d.mts
CHANGED
|
@@ -7,16 +7,18 @@ import { RollupStatsWrite } from "./write.mjs";
|
|
|
7
7
|
* A subset of resolved output options provided to the `generateBundle` hook by Vite/Rolldown/Rollup,
|
|
8
8
|
* containing only the fields this plugin uses to generate a stats file for a specific output.
|
|
9
9
|
*/
|
|
10
|
-
type
|
|
10
|
+
type RollupStatsOutputOptions = {
|
|
11
11
|
/** Output directory for the generated files. */dir?: string | undefined; /** Output format */
|
|
12
12
|
format?: 'es' | 'esm' | 'module' | 'cjs' | 'commonjs' | 'iife' | 'umd' | 'amd' | 'system' | 'systemjs' | undefined;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Subset of the Vite/Rolldown/Rollup plugin hook context (`this`) used by this plugin.
|
|
16
16
|
*/
|
|
17
|
-
type
|
|
18
|
-
|
|
17
|
+
type RollupStatsPluginContext = {
|
|
18
|
+
info: (message: string) => void;
|
|
19
19
|
warn: (message: string) => void;
|
|
20
|
+
error: (message: string) => void;
|
|
21
|
+
debug: (message: string) => void;
|
|
20
22
|
};
|
|
21
23
|
/**
|
|
22
24
|
* Minimum plugin interface compatible with Vite/Rolldown/Rollup.
|
|
@@ -27,14 +29,14 @@ type PluginContext = {
|
|
|
27
29
|
* async generateBundle(outputOptions, bundle) { ... },
|
|
28
30
|
* }
|
|
29
31
|
*/
|
|
30
|
-
type
|
|
32
|
+
type RollupStatsPlugin = {
|
|
31
33
|
/** Unique identifier for the plugin, used in error messages and logs. */name: string;
|
|
32
34
|
/**
|
|
33
35
|
* Hook called after the bundle has been fully generated but before it is
|
|
34
36
|
* written to disk. Receives the resolved output options and the complete
|
|
35
37
|
* output bundle map.
|
|
36
38
|
*/
|
|
37
|
-
generateBundle?: (this:
|
|
39
|
+
generateBundle?: (this: RollupStatsPluginContext, outputOptions: RollupStatsOutputOptions, bundle: OutputBundle, isWrite: boolean) => void | Promise<void>;
|
|
38
40
|
};
|
|
39
41
|
type RollupStatsOptions = {
|
|
40
42
|
/**
|
|
@@ -52,8 +54,8 @@ type RollupStatsOptions = {
|
|
|
52
54
|
*/
|
|
53
55
|
write?: RollupStatsWrite;
|
|
54
56
|
};
|
|
55
|
-
type RollupStatsOptionsOrOutputOptions = RollupStatsOptions | ((outputOptions:
|
|
56
|
-
declare function rollupStats(options?: RollupStatsOptionsOrOutputOptions):
|
|
57
|
+
type RollupStatsOptionsOrOutputOptions = RollupStatsOptions | ((outputOptions: RollupStatsOutputOptions) => RollupStatsOptions);
|
|
58
|
+
declare function rollupStats(options?: RollupStatsOptionsOrOutputOptions): RollupStatsPlugin;
|
|
57
59
|
//#endregion
|
|
58
|
-
export { RollupStatsOptions, RollupStatsOptionsOrOutputOptions, rollupStats };
|
|
60
|
+
export { RollupStatsOptions, RollupStatsOptionsOrOutputOptions, RollupStatsOutputOptions, RollupStatsPlugin, RollupStatsPluginContext, rollupStats };
|
|
59
61
|
//# sourceMappingURL=plugin.d.mts.map
|
package/dist/plugin.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;;;AAeA;;KAAY,
|
|
1
|
+
{"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;;;AAeA;;KAAY,wBAAA;EAEV,gDAAA,GAAA,uBAoBU;EAjBV,MAAA;AAAA;;;;KAiBU,wBAAA;EACV,IAAA,GAAO,OAAA;EACP,IAAA,GAAO,OAAA;EACP,KAAA,GAAQ,OAAA;EACR,KAAA,GAAQ,OAAA;AAAA;;;AAYV;;;;;;;KAAY,iBAAA;EAcS,yEAZnB,IAAA;EAOA;;;;;EAAA,cAAA,IACE,IAAA,EAAM,wBAAA,EACN,aAAA,EAAe,wBAAA,EACf,MAAA,EAAQ,YAAA,EACR,OAAA,qBACU,OAAA;AAAA;AAAA,KAGF,kBAAA;EAHE;;;AAGd;EAKE,QAAA;;;;EAIA,KAAA,GAAQ,YAAA;EAAA;;;;EAKR,KAAA,GAAQ,gBAAA;AAAA;AAAA,KAGE,iCAAA,GACR,kBAAA,KACE,aAAA,EAAe,wBAAA,KAA6B,kBAAA;AAAA,iBAElC,WAAA,CACd,OAAA,GAAS,iCAAA,GACR,iBAAA"}
|
package/dist/plugin.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.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 { OutputBundle } from './types';\n\nconst PLUGIN_NAME = 'rollupStats';\nconst DEFAULT_FILE_NAME = 'stats.json';\n\n/**\n * A subset of resolved output options provided to the `generateBundle` hook by Vite/Rolldown/Rollup,\n * containing only the fields this plugin uses to generate a stats file for a specific output.\n */\nexport type
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.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 { OutputBundle } from './types';\n\nconst PLUGIN_NAME = 'rollupStats';\nconst DEFAULT_FILE_NAME = 'stats.json';\n\n/**\n * A subset of resolved output options provided to the `generateBundle` hook by Vite/Rolldown/Rollup,\n * containing only the fields this plugin uses to generate a stats file for a specific output.\n */\nexport type RollupStatsOutputOptions = {\n /** Output directory for the generated files. */\n dir?: string | undefined;\n\n /** Output format */\n format?:\n | 'es'\n | 'esm'\n | 'module'\n | 'cjs'\n | 'commonjs'\n | 'iife'\n | 'umd'\n | 'amd'\n | 'system'\n | 'systemjs'\n | undefined;\n};\n\n/**\n * Subset of the Vite/Rolldown/Rollup plugin hook context (`this`) used by this plugin.\n */\nexport type RollupStatsPluginContext = {\n info: (message: string) => void;\n warn: (message: string) => void;\n error: (message: string) => void;\n debug: (message: string) => void;\n};\n\n/**\n * Minimum plugin interface compatible with Vite/Rolldown/Rollup.\n *\n * @example\n * {\n * name: 'rollupStats',\n * async generateBundle(outputOptions, bundle) { ... },\n * }\n */\nexport type RollupStatsPlugin = {\n /** Unique identifier for the plugin, used in error messages and logs. */\n name: string;\n\n /**\n * Hook called after the bundle has been fully generated but before it is\n * written to disk. Receives the resolved output options and the complete\n * output bundle map.\n */\n generateBundle?: (\n this: RollupStatsPluginContext,\n outputOptions: RollupStatsOutputOptions,\n bundle: OutputBundle,\n isWrite: boolean\n ) => void | Promise<void>;\n};\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\nexport type RollupStatsOptionsOrOutputOptions =\n | RollupStatsOptions\n | ((outputOptions: RollupStatsOutputOptions) => RollupStatsOptions);\n\nexport function rollupStats(\n options: RollupStatsOptionsOrOutputOptions = {}\n): RollupStatsPlugin {\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 RollupStatsPlugin;\n}\n"],"mappings":";;;;;;;AAQA,MAAM,cAAc;AACpB,MAAM,oBAAoB;AAkF1B,SAAgB,YACd,UAA6C,EAAE,EAC5B;AACnB,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"}
|