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 CHANGED
@@ -6,6 +6,10 @@
6
6
  [![Socket Badge](https://socket.dev/api/badge/npm/package/rollup-plugin-stats)](https://socket.dev/npm/package/rollup-plugin-stats)
7
7
  [![ci](https://github.com/relative-ci/rollup-plugin-stats/actions/workflows/ci.yml/badge.svg)](https://github.com/relative-ci/rollup-plugin-stats/actions/workflows/ci.yml)
8
8
 
9
+ [![Vite compatibility](https://registry.vite.dev/api/badges?package=rollup-plugin-stats&tool=vite)](https://npmx.dev/package/rollup-plugin-stats)
10
+ [![Rolldown compatibility](https://registry.vite.dev/api/badges?package=rollup-plugin-stats&tool=rolldown)](https://npmx.dev/package/rollup-plugin-stats)
11
+ [![Rollup compatibility](https://registry.vite.dev/api/badges?package=rollup-plugin-stats&tool=rollup)](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
@@ -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":";;;AAeA,kBAAeA"}
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 };
@@ -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":";;;AAeA,kBAAe"}
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"}
@@ -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 OutputOptions = {\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 */\ntype PluginContext = {\n /** Log an informational message through Vite/Rolldown/Rollup's logging pipeline. */\n info: (message: string) => void;\n\n /** Log a warning through Vite/Rolldown/Rollup's logging pipeline without stopping the build. */\n warn: (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 Plugin = {\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: PluginContext,\n outputOptions: OutputOptions,\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: OutputOptions) => RollupStatsOptions);\n\nexport function rollupStats(\n options: RollupStatsOptionsOrOutputOptions = {}\n): 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"],"mappings":";;;;;;;;;;AAQA,MAAM,cAAc;AACpB,MAAM,oBAAoB;AAmF1B,SAAgB,YACd,UAA6C,EAAE,EACvC;AACR,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
+ {"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 OutputOptions = {
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 PluginContext = {
18
- /** Log an informational message through Vite/Rolldown/Rollup's logging pipeline. */info: (message: string) => void; /** Log a warning through Vite/Rolldown/Rollup's logging pipeline without stopping the build. */
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 Plugin = {
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: PluginContext, outputOptions: OutputOptions, bundle: OutputBundle, isWrite: boolean) => void | Promise<void>;
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: OutputOptions) => RollupStatsOptions);
56
- declare function rollupStats(options?: RollupStatsOptionsOrOutputOptions): Plugin;
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
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;;;AAeA;;KAAY,aAAA;EAEV,gDAAA,GAAA,uBAoBG;EAjBH,MAAA;AAAA;;;;KAiBG,aAAA;EAKI,oFAHP,IAAA,GAAO,OAAA,mBAGe;EAAtB,IAAA,GAAO,OAAA;AAAA;;;;;;;;;;KAYG,MAAA;EAUR,yEARF,IAAA;EASE;;;;;EAFF,cAAA,IACE,IAAA,EAAM,aAAA,EACN,aAAA,EAAe,aAAA,EACf,MAAA,EAAQ,YAAA,EACR,OAAA,qBACU,OAAA;AAAA;AAAA,KAGF,kBAAA;EAAkB;;;;EAK5B,QAAA;EAIQ;;;EAAR,KAAA,GAAQ,YAAA;EAKgB;AAG1B;;;EAHE,KAAA,GAAQ,gBAAA;AAAA;AAAA,KAGE,iCAAA,GACR,kBAAA,KACE,aAAA,EAAe,aAAA,KAAkB,kBAAA;AAAA,iBAEvB,WAAA,CACd,OAAA,GAAS,iCAAA,GACR,MAAA"}
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 OutputOptions = {
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 PluginContext = {
18
- /** Log an informational message through Vite/Rolldown/Rollup's logging pipeline. */info: (message: string) => void; /** Log a warning through Vite/Rolldown/Rollup's logging pipeline without stopping the build. */
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 Plugin = {
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: PluginContext, outputOptions: OutputOptions, bundle: OutputBundle, isWrite: boolean) => void | Promise<void>;
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: OutputOptions) => RollupStatsOptions);
56
- declare function rollupStats(options?: RollupStatsOptionsOrOutputOptions): Plugin;
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
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;;;AAeA;;KAAY,aAAA;EAEV,gDAAA,GAAA,uBAoBG;EAjBH,MAAA;AAAA;;;;KAiBG,aAAA;EAKI,oFAHP,IAAA,GAAO,OAAA,mBAGe;EAAtB,IAAA,GAAO,OAAA;AAAA;;;;;;;;;;KAYG,MAAA;EAUR,yEARF,IAAA;EASE;;;;;EAFF,cAAA,IACE,IAAA,EAAM,aAAA,EACN,aAAA,EAAe,aAAA,EACf,MAAA,EAAQ,YAAA,EACR,OAAA,qBACU,OAAA;AAAA;AAAA,KAGF,kBAAA;EAAkB;;;;EAK5B,QAAA;EAIQ;;;EAAR,KAAA,GAAQ,YAAA;EAKgB;AAG1B;;;EAHE,KAAA,GAAQ,gBAAA;AAAA;AAAA,KAGE,iCAAA,GACR,kBAAA,KACE,aAAA,EAAe,aAAA,KAAkB,kBAAA;AAAA,iBAEvB,WAAA,CACd,OAAA,GAAS,iCAAA,GACR,MAAA"}
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"}
@@ -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 OutputOptions = {\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 */\ntype PluginContext = {\n /** Log an informational message through Vite/Rolldown/Rollup's logging pipeline. */\n info: (message: string) => void;\n\n /** Log a warning through Vite/Rolldown/Rollup's logging pipeline without stopping the build. */\n warn: (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 Plugin = {\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: PluginContext,\n outputOptions: OutputOptions,\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: OutputOptions) => RollupStatsOptions);\n\nexport function rollupStats(\n options: RollupStatsOptionsOrOutputOptions = {}\n): 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"],"mappings":";;;;;;;AAQA,MAAM,cAAc;AACpB,MAAM,oBAAoB;AAmF1B,SAAgB,YACd,UAA6C,EAAE,EACvC;AACR,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"}
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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rollup-plugin-stats",
3
3
  "description": "Vite/Rolldown/Rollup plugin to generate bundle stats JSON file",
4
- "version": "2.1.2",
4
+ "version": "2.1.3-beta.0",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "repository": {