rollup-plugin-webpack-stats 3.1.1-beta.1 → 3.1.1-beta.3

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/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_plugin = require('./src/plugin.cjs');
1
+ const require_plugin = require('./plugin.cjs');
2
2
 
3
3
  //#region src/index.ts
4
4
  var src_default = require_plugin.webpackStats;
package/dist/index.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { webpackStats } from "./src/plugin.cjs";
1
+ import { webpackStats } from "./plugin.cjs";
2
2
  export = webpackStats;
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { webpackStats } from "./src/plugin.mjs";
1
+ import { webpackStats } from "./plugin.mjs";
2
2
  export { webpackStats as default };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { webpackStats } from "./src/plugin.mjs";
1
+ import { webpackStats } from "./plugin.mjs";
2
2
 
3
3
  //#region src/index.ts
4
4
  var src_default = webpackStats;
@@ -1,6 +1,6 @@
1
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
2
  const require_utils = require('./utils.cjs');
3
- const require_transform = require('../transform.cjs');
3
+ const require_transform = require('./transform.cjs');
4
4
  const require_write = require('./write.cjs');
5
5
  let rollup_plugin_stats_extract = require("rollup-plugin-stats/extract");
6
6
  rollup_plugin_stats_extract = require_runtime.__toESM(rollup_plugin_stats_extract);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs","names":["statsWrite","bundleToWebpackStats","resolveFilepath","getByteSize","formatFileSize"],"sources":["../src/plugin.ts"],"sourcesContent":["import type { OutputBundle } from 'rollup-plugin-stats';\nimport extractStats, { type StatsOptions } from 'rollup-plugin-stats/extract';\n\nimport { type BundleTransformOptions, bundleToWebpackStats } from './transform';\nimport { type StatsWrite, statsWrite } from './write';\nimport { formatFileSize, getByteSize, resolveFilepath } from './utils';\n\nconst PLUGIN_NAME = 'webpackStats';\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 */\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\ntype WebpackStatsOptions = {\n /**\n * JSON file output fileName\n * default: webpack-stats.json\n */\n fileName?: string;\n /**\n * Custom file writer\n * @default - fs.write(FILENAME, JSON.stringify(STATS, null, 2));\n */\n write?: StatsWrite;\n} & Omit<StatsOptions, 'source' | 'map'> &\n BundleTransformOptions;\n\ntype WebpackStatsOptionsOrBuilder =\n | WebpackStatsOptions\n | ((outputOptions: OutputOptions) => WebpackStatsOptions);\n\nexport const webpackStats = (\n options: WebpackStatsOptionsOrBuilder = {}\n): Plugin => ({\n name: PLUGIN_NAME,\n async generateBundle(outputOptions, bundle) {\n const resolvedOptions =\n typeof options === 'function' ? options(outputOptions) : options;\n const {\n fileName,\n excludeAssets,\n excludeModules,\n write = statsWrite,\n ...transformOptions\n } = resolvedOptions;\n\n const rollupStats = extractStats(bundle, {\n excludeAssets,\n excludeModules,\n // Extract stats source to compute size\n source: true,\n });\n const stats = bundleToWebpackStats(rollupStats, transformOptions);\n const filepath = resolveFilepath(fileName, outputOptions.dir);\n\n try {\n const res = await write(\n filepath,\n stats as unknown as Record<string, unknown>\n );\n const outputSize = getByteSize(res.content);\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});\n"],"mappings":";;;;;;;;AAOA,MAAM,cAAc;AA0EpB,MAAa,gBACX,UAAwC,EAAE,MAC9B;CACZ,MAAM;CACN,MAAM,eAAe,eAAe,QAAQ;EAG1C,MAAM,EACJ,UACA,eACA,gBACA,QAAQA,0BACR,GAAG,qBANH,OAAO,YAAY,aAAa,QAAQ,cAAc,GAAG;EAe3D,MAAM,QAAQC,gFANmB,QAAQ;GACvC;GACA;GAEA,QAAQ;GACT,CAAC,EAC8C,iBAAiB;EACjE,MAAM,WAAWC,8BAAgB,UAAU,cAAc,IAAI;AAE7D,MAAI;GACF,MAAM,MAAM,MAAM,MAChB,UACA,MACD;GACD,MAAM,aAAaC,0BAAY,IAAI,QAAQ;AAE3C,QAAK,KACH,kBAAkB,IAAI,SAAS,IAAIC,6BAAe,WAAW,CAAC,GAC/D;WACM,OAAgB;GACvB,MAAM,UACJ,iBAAiB,QAAQ,MAAM,UAAU,KAAK,UAAU,MAAM;AAGhE,QAAK,KAAK,QAAQ;;;CAGvB"}
@@ -1,4 +1,4 @@
1
- import { BundleTransformOptions } from "../transform.cjs";
1
+ import { BundleTransformOptions } from "./transform.cjs";
2
2
  import { StatsWrite } from "./write.cjs";
3
3
  import { OutputBundle } from "rollup-plugin-stats";
4
4
  import { StatsOptions } from "rollup-plugin-stats/extract";
@@ -21,12 +21,6 @@ type PluginContext = {
21
21
  };
22
22
  /**
23
23
  * Minimum plugin interface compatible with Vite/Rolldown/Rollup.
24
- *
25
- * @example
26
- * {
27
- * name: 'rollupStats',
28
- * async generateBundle(outputOptions, bundle) { ... },
29
- * }
30
24
  */
31
25
  type Plugin = {
32
26
  /** Unique identifier for the plugin, used in error messages and logs. */name: string;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.cts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;;;;AAaA;;KAAY,aAAA;EAEV,gDAAA,GAAA,uBAoBG;EAjBH,MAAA;AAAA;;;;KAiBG,aAAA;EAKI,oFAHP,IAAA,GAAO,OAAA,mBAGe;EAAtB,IAAA,GAAO,OAAA;AAAA;;;;KAMG,MAAA;EAcE,yEAZZ,IAAA;EAYmB;;;;;EALnB,cAAA,IACE,IAAA,EAAM,aAAA,EACN,aAAA,EAAe,aAAA,EACf,MAAA,EAAQ,YAAA,EACR,OAAA,qBACU,OAAA;AAAA;AAAA,KAGT,mBAAA;EALD;;;;EAUF,QAAA;EALG;;;;EAUH,KAAA,GAAQ,UAAA;AAAA,IACN,IAAA,CAAK,YAAA,sBACP,sBAAA;AAAA,KAEG,4BAAA,GACD,mBAAA,KACE,aAAA,EAAe,aAAA,KAAkB,mBAAA;AAAA,cAE1B,YAAA,GACX,OAAA,GAAS,4BAAA,KACR,MAAA"}
@@ -1,4 +1,4 @@
1
- import { BundleTransformOptions } from "../transform.mjs";
1
+ import { BundleTransformOptions } from "./transform.mjs";
2
2
  import { StatsWrite } from "./write.mjs";
3
3
  import { StatsOptions } from "rollup-plugin-stats/extract";
4
4
  import { OutputBundle } from "rollup-plugin-stats";
@@ -21,12 +21,6 @@ type PluginContext = {
21
21
  };
22
22
  /**
23
23
  * Minimum plugin interface compatible with Vite/Rolldown/Rollup.
24
- *
25
- * @example
26
- * {
27
- * name: 'rollupStats',
28
- * async generateBundle(outputOptions, bundle) { ... },
29
- * }
30
24
  */
31
25
  type Plugin = {
32
26
  /** Unique identifier for the plugin, used in error messages and logs. */name: string;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;;;;AAaA;;KAAY,aAAA;EAEV,gDAAA,GAAA,uBAoBG;EAjBH,MAAA;AAAA;;;;KAiBG,aAAA;EAKI,oFAHP,IAAA,GAAO,OAAA,mBAGe;EAAtB,IAAA,GAAO,OAAA;AAAA;;;;KAMG,MAAA;EAcE,yEAZZ,IAAA;EAYmB;;;;;EALnB,cAAA,IACE,IAAA,EAAM,aAAA,EACN,aAAA,EAAe,aAAA,EACf,MAAA,EAAQ,YAAA,EACR,OAAA,qBACU,OAAA;AAAA;AAAA,KAGT,mBAAA;EALD;;;;EAUF,QAAA;EALG;;;;EAUH,KAAA,GAAQ,UAAA;AAAA,IACN,IAAA,CAAK,YAAA,sBACP,sBAAA;AAAA,KAEG,4BAAA,GACD,mBAAA,KACE,aAAA,EAAe,aAAA,KAAkB,mBAAA;AAAA,cAE1B,YAAA,GACX,OAAA,GAAS,4BAAA,KACR,MAAA"}
@@ -1,5 +1,5 @@
1
1
  import { formatFileSize, getByteSize, resolveFilepath } from "./utils.mjs";
2
- import { bundleToWebpackStats } from "../transform.mjs";
2
+ import { bundleToWebpackStats } from "./transform.mjs";
3
3
  import { statsWrite } from "./write.mjs";
4
4
  import extractStats from "rollup-plugin-stats/extract";
5
5
 
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { OutputBundle } from 'rollup-plugin-stats';\nimport extractStats, { type StatsOptions } from 'rollup-plugin-stats/extract';\n\nimport { type BundleTransformOptions, bundleToWebpackStats } from './transform';\nimport { type StatsWrite, statsWrite } from './write';\nimport { formatFileSize, getByteSize, resolveFilepath } from './utils';\n\nconst PLUGIN_NAME = 'webpackStats';\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 */\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\ntype WebpackStatsOptions = {\n /**\n * JSON file output fileName\n * default: webpack-stats.json\n */\n fileName?: string;\n /**\n * Custom file writer\n * @default - fs.write(FILENAME, JSON.stringify(STATS, null, 2));\n */\n write?: StatsWrite;\n} & Omit<StatsOptions, 'source' | 'map'> &\n BundleTransformOptions;\n\ntype WebpackStatsOptionsOrBuilder =\n | WebpackStatsOptions\n | ((outputOptions: OutputOptions) => WebpackStatsOptions);\n\nexport const webpackStats = (\n options: WebpackStatsOptionsOrBuilder = {}\n): Plugin => ({\n name: PLUGIN_NAME,\n async generateBundle(outputOptions, bundle) {\n const resolvedOptions =\n typeof options === 'function' ? options(outputOptions) : options;\n const {\n fileName,\n excludeAssets,\n excludeModules,\n write = statsWrite,\n ...transformOptions\n } = resolvedOptions;\n\n const rollupStats = extractStats(bundle, {\n excludeAssets,\n excludeModules,\n // Extract stats source to compute size\n source: true,\n });\n const stats = bundleToWebpackStats(rollupStats, transformOptions);\n const filepath = resolveFilepath(fileName, outputOptions.dir);\n\n try {\n const res = await write(\n filepath,\n stats as unknown as Record<string, unknown>\n );\n const outputSize = getByteSize(res.content);\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});\n"],"mappings":";;;;;;AAOA,MAAM,cAAc;AA0EpB,MAAa,gBACX,UAAwC,EAAE,MAC9B;CACZ,MAAM;CACN,MAAM,eAAe,eAAe,QAAQ;EAG1C,MAAM,EACJ,UACA,eACA,gBACA,QAAQ,YACR,GAAG,qBANH,OAAO,YAAY,aAAa,QAAQ,cAAc,GAAG;EAe3D,MAAM,QAAQ,qBANM,aAAa,QAAQ;GACvC;GACA;GAEA,QAAQ;GACT,CAAC,EAC8C,iBAAiB;EACjE,MAAM,WAAW,gBAAgB,UAAU,cAAc,IAAI;AAE7D,MAAI;GACF,MAAM,MAAM,MAAM,MAChB,UACA,MACD;GACD,MAAM,aAAa,YAAY,IAAI,QAAQ;AAE3C,QAAK,KACH,kBAAkB,IAAI,SAAS,IAAI,eAAe,WAAW,CAAC,GAC/D;WACM,OAAgB;GACvB,MAAM,UACJ,iBAAiB,QAAQ,MAAM,UAAU,KAAK,UAAU,MAAM;AAGhE,QAAK,KAAK,QAAQ;;;CAGvB"}
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
- const require_utils = require('./src/utils.cjs');
3
+ const require_utils = require('./utils.cjs');
4
4
  let path = require("path");
5
5
  path = require_runtime.__toESM(path);
6
6
 
@@ -1,4 +1,4 @@
1
- import { getByteSize, getChunkId } from "./src/utils.mjs";
1
+ import { getByteSize, getChunkId } from "./utils.mjs";
2
2
  import path from "path";
3
3
 
4
4
  //#region src/transform.ts
@@ -1,4 +1,4 @@
1
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
2
  let node_path = require("node:path");
3
3
  node_path = require_runtime.__toESM(node_path);
4
4
  let node_crypto = require("node:crypto");
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","names":["crypto","path"],"sources":["../src/utils.ts"],"sourcesContent":["import path from 'node:path';\nimport crypto from 'node:crypto';\nimport type { ChunkStats } from 'rollup-plugin-stats/extract';\n\nconst HASH_LENGTH = 7;\n\n/**\n * Get content byte size\n */\nexport function getByteSize(\n content?: string | Uint8Array<ArrayBufferLike>\n): number {\n if (!content) {\n return 0;\n }\n\n if (typeof content === 'string') {\n return Buffer.byteLength(content);\n }\n\n return content?.length || 0;\n}\n\n/**\n * Generate a 7 chars hash from a filepath\n */\nexport function getHash(filepath: string): string {\n const digest = crypto.createHash('sha256');\n return digest.update(filepath).digest('hex').substr(0, HASH_LENGTH);\n}\n\nexport function getChunkId(chunk: ChunkStats): string {\n let value = chunk.name;\n\n // Use entry module relative path\n if (chunk.moduleIds?.length > 0) {\n const absoluteModulePath = chunk.moduleIds[chunk.moduleIds.length - 1];\n value = path.relative(process.cwd(), absoluteModulePath);\n }\n\n return getHash([chunk, value].join('-'));\n}\n\ntype ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);\n\nexport type ExcludeFilepathOption =\n | ExcludeFilepathParam\n | Array<ExcludeFilepathParam>;\n\nexport function round(value: number, precision = 2) {\n const multiplier = 10 ^ precision;\n return Math.round(value * multiplier) / multiplier;\n}\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\nconst DEFAULT_FILE_NAME = 'webpack-stats.json';\n\nexport function resolveFilepath(\n fileName = DEFAULT_FILE_NAME,\n outputDir?: string\n): string {\n // Check if the fileName is an absolute path\n if (path.isAbsolute(fileName)) {\n return fileName;\n }\n\n // If the fileName is not an absolute path, join it with the output directory or the current working directory\n return path.join(outputDir || process.cwd(), fileName);\n}\n"],"mappings":";;;;;;;AAIA,MAAM,cAAc;;;;AAKpB,SAAgB,YACd,SACQ;AACR,KAAI,CAAC,QACH,QAAO;AAGT,KAAI,OAAO,YAAY,SACrB,QAAO,OAAO,WAAW,QAAQ;AAGnC,QAAO,SAAS,UAAU;;;;;AAM5B,SAAgB,QAAQ,UAA0B;AAEhD,QADeA,oBAAO,WAAW,SAAS,CAC5B,OAAO,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,GAAG,YAAY;;AAGrE,SAAgB,WAAW,OAA2B;CACpD,IAAI,QAAQ,MAAM;AAGlB,KAAI,MAAM,WAAW,SAAS,GAAG;EAC/B,MAAM,qBAAqB,MAAM,UAAU,MAAM,UAAU,SAAS;AACpE,UAAQC,kBAAK,SAAS,QAAQ,KAAK,EAAE,mBAAmB;;AAG1D,QAAO,QAAQ,CAAC,OAAO,MAAM,CAAC,KAAK,IAAI,CAAC;;AAS1C,SAAgB,MAAM,OAAe,YAAY,GAAG;CAClD,MAAM,aAAa,KAAK;AACxB,QAAO,KAAK,MAAM,QAAQ,WAAW,GAAG;;AAG1C,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;;AAGrD,MAAM,oBAAoB;AAE1B,SAAgB,gBACd,WAAW,mBACX,WACQ;AAER,KAAIA,kBAAK,WAAW,SAAS,CAC3B,QAAO;AAIT,QAAOA,kBAAK,KAAK,aAAa,QAAQ,KAAK,EAAE,SAAS"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import path from 'node:path';\nimport crypto from 'node:crypto';\nimport type { ChunkStats } from 'rollup-plugin-stats/extract';\n\nconst HASH_LENGTH = 7;\n\n/**\n * Get content byte size\n */\nexport function getByteSize(\n content?: string | Uint8Array<ArrayBufferLike>\n): number {\n if (!content) {\n return 0;\n }\n\n if (typeof content === 'string') {\n return Buffer.byteLength(content);\n }\n\n return content?.length || 0;\n}\n\n/**\n * Generate a 7 chars hash from a filepath\n */\nexport function getHash(filepath: string): string {\n const digest = crypto.createHash('sha256');\n return digest.update(filepath).digest('hex').substr(0, HASH_LENGTH);\n}\n\nexport function getChunkId(chunk: ChunkStats): string {\n let value = chunk.name;\n\n // Use entry module relative path\n if (chunk.moduleIds?.length > 0) {\n const absoluteModulePath = chunk.moduleIds[chunk.moduleIds.length - 1];\n value = path.relative(process.cwd(), absoluteModulePath);\n }\n\n return getHash([chunk, value].join('-'));\n}\n\ntype ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);\n\nexport type ExcludeFilepathOption =\n | ExcludeFilepathParam\n | Array<ExcludeFilepathParam>;\n\nexport function round(value: number, precision = 2) {\n const multiplier = 10 ^ precision;\n return Math.round(value * multiplier) / multiplier;\n}\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\nconst DEFAULT_FILE_NAME = 'webpack-stats.json';\n\nexport function resolveFilepath(\n fileName = DEFAULT_FILE_NAME,\n outputDir?: string\n): string {\n // Check if the fileName is an absolute path\n if (path.isAbsolute(fileName)) {\n return fileName;\n }\n\n // If the fileName is not an absolute path, join it with the output directory or the current working directory\n return path.join(outputDir || process.cwd(), fileName);\n}\n"],"mappings":";;;;AAIA,MAAM,cAAc;;;;AAKpB,SAAgB,YACd,SACQ;AACR,KAAI,CAAC,QACH,QAAO;AAGT,KAAI,OAAO,YAAY,SACrB,QAAO,OAAO,WAAW,QAAQ;AAGnC,QAAO,SAAS,UAAU;;;;;AAM5B,SAAgB,QAAQ,UAA0B;AAEhD,QADe,OAAO,WAAW,SAAS,CAC5B,OAAO,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,GAAG,YAAY;;AAGrE,SAAgB,WAAW,OAA2B;CACpD,IAAI,QAAQ,MAAM;AAGlB,KAAI,MAAM,WAAW,SAAS,GAAG;EAC/B,MAAM,qBAAqB,MAAM,UAAU,MAAM,UAAU,SAAS;AACpE,UAAQ,KAAK,SAAS,QAAQ,KAAK,EAAE,mBAAmB;;AAG1D,QAAO,QAAQ,CAAC,OAAO,MAAM,CAAC,KAAK,IAAI,CAAC;;AAS1C,SAAgB,MAAM,OAAe,YAAY,GAAG;CAClD,MAAM,aAAa,KAAK;AACxB,QAAO,KAAK,MAAM,QAAQ,WAAW,GAAG;;AAG1C,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;;AAGrD,MAAM,oBAAoB;AAE1B,SAAgB,gBACd,WAAW,mBACX,WACQ;AAER,KAAI,KAAK,WAAW,SAAS,CAC3B,QAAO;AAIT,QAAO,KAAK,KAAK,aAAa,QAAQ,KAAK,EAAE,SAAS"}
@@ -1,4 +1,4 @@
1
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
2
  let node_path = require("node:path");
3
3
  node_path = require_runtime.__toESM(node_path);
4
4
  let node_fs_promises = require("node:fs/promises");
@@ -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 StatsWriteResponse = {\n filepath: string;\n content: string;\n};\n\nexport type StatsWrite = (\n filepath: string,\n stats: Record<string, unknown>\n) => StatsWriteResponse;\n\nexport async function statsWrite<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(filepath: string, stats: T): Promise<StatsWriteResponse> {\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,WAEpB,UAAkB,OAAuC;CACzD,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"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.cts","names":[],"sources":["../src/write.ts"],"mappings":";KAGY,kBAAA;EACV,QAAA;EACA,OAAA;AAAA;AAAA,KAGU,UAAA,IACV,QAAA,UACA,KAAA,EAAO,MAAA,sBACJ,kBAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.mts","names":[],"sources":["../src/write.ts"],"mappings":";KAGY,kBAAA;EACV,QAAA;EACA,OAAA;AAAA;AAAA,KAGU,UAAA,IACV,QAAA,UACA,KAAA,EAAO,MAAA,sBACJ,kBAAA"}
@@ -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 StatsWriteResponse = {\n filepath: string;\n content: string;\n};\n\nexport type StatsWrite = (\n filepath: string,\n stats: Record<string, unknown>\n) => StatsWriteResponse;\n\nexport async function statsWrite<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(filepath: string, stats: T): Promise<StatsWriteResponse> {\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,WAEpB,UAAkB,OAAuC;CACzD,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-webpack-stats",
3
3
  "description": "Rollup/Vite/Rolldown plugin to generate a stats JSON file with a bundle-stats webpack-compatible structure",
4
- "version": "3.1.1-beta.1",
4
+ "version": "3.1.1-beta.3",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -75,23 +75,24 @@
75
75
  },
76
76
  "devDependencies": {
77
77
  "@release-it/conventional-changelog": "10.0.6",
78
- "@types/node": "25.5.0",
78
+ "@types/node": "25.6.0",
79
79
  "eslint": "9.39.2",
80
80
  "eslint-config-prettier": "10.1.8",
81
81
  "husky": "9.1.7",
82
- "lint-staged": "16.3.3",
83
- "memfs": "4.56.11",
82
+ "lint-staged": "16.4.0",
83
+ "memfs": "4.57.1",
84
84
  "prettier": "3.8.1",
85
85
  "release-it": "19.2.4",
86
86
  "rimraf": "6.1.3",
87
- "tsdown": "0.21.2",
87
+ "tsdown": "0.21.7",
88
88
  "tslib": "2.8.1",
89
- "typescript": "5.9.3",
90
- "typescript-eslint": "8.57.0",
91
- "vitest": "4.1.0"
89
+ "typescript": "6.0.2",
90
+ "typescript-eslint": "8.58.1",
91
+ "vite": "7.3.2",
92
+ "vitest": "4.1.4"
92
93
  },
93
94
  "dependencies": {
94
- "rollup-plugin-stats": "2.1.1-beta.3"
95
+ "rollup-plugin-stats": "2.1.1-beta.5"
95
96
  },
96
97
  "peerDependencies": {
97
98
  "rolldown": "^1.0.0-beta.0",
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.cjs","names":["statsWrite","bundleToWebpackStats","resolveFilepath","getByteSize","formatFileSize"],"sources":["../../src/plugin.ts"],"sourcesContent":["import type { OutputBundle } from 'rollup-plugin-stats';\nimport extractStats, { type StatsOptions } from 'rollup-plugin-stats/extract';\n\nimport { type BundleTransformOptions, bundleToWebpackStats } from './transform';\nimport { type StatsWrite, statsWrite } from './write';\nimport { formatFileSize, getByteSize, resolveFilepath } from './utils';\n\nconst PLUGIN_NAME = 'webpackStats';\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\ntype WebpackStatsOptions = {\n /**\n * JSON file output fileName\n * default: webpack-stats.json\n */\n fileName?: string;\n /**\n * Custom file writer\n * @default - fs.write(FILENAME, JSON.stringify(STATS, null, 2));\n */\n write?: StatsWrite;\n} & Omit<StatsOptions, 'source' | 'map'> &\n BundleTransformOptions;\n\ntype WebpackStatsOptionsOrBuilder =\n | WebpackStatsOptions\n | ((outputOptions: OutputOptions) => WebpackStatsOptions);\n\nexport const webpackStats = (\n options: WebpackStatsOptionsOrBuilder = {}\n): Plugin => ({\n name: PLUGIN_NAME,\n async generateBundle(outputOptions, bundle) {\n const resolvedOptions =\n typeof options === 'function' ? options(outputOptions) : options;\n const {\n fileName,\n excludeAssets,\n excludeModules,\n write = statsWrite,\n ...transformOptions\n } = resolvedOptions;\n\n const rollupStats = extractStats(bundle, {\n excludeAssets,\n excludeModules,\n // Extract stats source to compute size\n source: true,\n });\n const stats = bundleToWebpackStats(rollupStats, transformOptions);\n const filepath = resolveFilepath(fileName, outputOptions.dir);\n\n try {\n const res = await write(\n filepath,\n stats as unknown as Record<string, unknown>\n );\n const outputSize = getByteSize(res.content);\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});\n"],"mappings":";;;;;;;;AAOA,MAAM,cAAc;AAgFpB,MAAa,gBACX,UAAwC,EAAE,MAC9B;CACZ,MAAM;CACN,MAAM,eAAe,eAAe,QAAQ;EAG1C,MAAM,EACJ,UACA,eACA,gBACA,QAAQA,0BACR,GAAG,qBANH,OAAO,YAAY,aAAa,QAAQ,cAAc,GAAG;EAe3D,MAAM,QAAQC,gFANmB,QAAQ;GACvC;GACA;GAEA,QAAQ;GACT,CAAC,EAC8C,iBAAiB;EACjE,MAAM,WAAWC,8BAAgB,UAAU,cAAc,IAAI;AAE7D,MAAI;GACF,MAAM,MAAM,MAAM,MAChB,UACA,MACD;GACD,MAAM,aAAaC,0BAAY,IAAI,QAAQ;AAE3C,QAAK,KACH,kBAAkB,IAAI,SAAS,IAAIC,6BAAe,WAAW,CAAC,GAC/D;WACM,OAAgB;GACvB,MAAM,UACJ,iBAAiB,QAAQ,MAAM,UAAU,KAAK,UAAU,MAAM;AAGhE,QAAK,KAAK,QAAQ;;;CAGvB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.d.cts","names":[],"sources":["../../src/plugin.ts"],"mappings":";;;;;;;;AAaA;;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,KAGT,mBAAA;EAAmB;;;;EAKtB,QAAA;EAOA;;;;EAFA,KAAA,GAAQ,UAAA;AAAA,IACN,IAAA,CAAK,YAAA,sBACP,sBAAA;AAAA,KAEG,4BAAA,GACD,mBAAA,KACE,aAAA,EAAe,aAAA,KAAkB,mBAAA;AAAA,cAE1B,YAAA,GACX,OAAA,GAAS,4BAAA,KACR,MAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.d.mts","names":[],"sources":["../../src/plugin.ts"],"mappings":";;;;;;;;AAaA;;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,KAGT,mBAAA;EAAmB;;;;EAKtB,QAAA;EAOA;;;;EAFA,KAAA,GAAQ,UAAA;AAAA,IACN,IAAA,CAAK,YAAA,sBACP,sBAAA;AAAA,KAEG,4BAAA,GACD,mBAAA,KACE,aAAA,EAAe,aAAA,KAAkB,mBAAA;AAAA,cAE1B,YAAA,GACX,OAAA,GAAS,4BAAA,KACR,MAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.mjs","names":[],"sources":["../../src/plugin.ts"],"sourcesContent":["import type { OutputBundle } from 'rollup-plugin-stats';\nimport extractStats, { type StatsOptions } from 'rollup-plugin-stats/extract';\n\nimport { type BundleTransformOptions, bundleToWebpackStats } from './transform';\nimport { type StatsWrite, statsWrite } from './write';\nimport { formatFileSize, getByteSize, resolveFilepath } from './utils';\n\nconst PLUGIN_NAME = 'webpackStats';\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\ntype WebpackStatsOptions = {\n /**\n * JSON file output fileName\n * default: webpack-stats.json\n */\n fileName?: string;\n /**\n * Custom file writer\n * @default - fs.write(FILENAME, JSON.stringify(STATS, null, 2));\n */\n write?: StatsWrite;\n} & Omit<StatsOptions, 'source' | 'map'> &\n BundleTransformOptions;\n\ntype WebpackStatsOptionsOrBuilder =\n | WebpackStatsOptions\n | ((outputOptions: OutputOptions) => WebpackStatsOptions);\n\nexport const webpackStats = (\n options: WebpackStatsOptionsOrBuilder = {}\n): Plugin => ({\n name: PLUGIN_NAME,\n async generateBundle(outputOptions, bundle) {\n const resolvedOptions =\n typeof options === 'function' ? options(outputOptions) : options;\n const {\n fileName,\n excludeAssets,\n excludeModules,\n write = statsWrite,\n ...transformOptions\n } = resolvedOptions;\n\n const rollupStats = extractStats(bundle, {\n excludeAssets,\n excludeModules,\n // Extract stats source to compute size\n source: true,\n });\n const stats = bundleToWebpackStats(rollupStats, transformOptions);\n const filepath = resolveFilepath(fileName, outputOptions.dir);\n\n try {\n const res = await write(\n filepath,\n stats as unknown as Record<string, unknown>\n );\n const outputSize = getByteSize(res.content);\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});\n"],"mappings":";;;;;;AAOA,MAAM,cAAc;AAgFpB,MAAa,gBACX,UAAwC,EAAE,MAC9B;CACZ,MAAM;CACN,MAAM,eAAe,eAAe,QAAQ;EAG1C,MAAM,EACJ,UACA,eACA,gBACA,QAAQ,YACR,GAAG,qBANH,OAAO,YAAY,aAAa,QAAQ,cAAc,GAAG;EAe3D,MAAM,QAAQ,qBANM,aAAa,QAAQ;GACvC;GACA;GAEA,QAAQ;GACT,CAAC,EAC8C,iBAAiB;EACjE,MAAM,WAAW,gBAAgB,UAAU,cAAc,IAAI;AAE7D,MAAI;GACF,MAAM,MAAM,MAAM,MAChB,UACA,MACD;GACD,MAAM,aAAa,YAAY,IAAI,QAAQ;AAE3C,QAAK,KACH,kBAAkB,IAAI,SAAS,IAAI,eAAe,WAAW,CAAC,GAC/D;WACM,OAAgB;GACvB,MAAM,UACJ,iBAAiB,QAAQ,MAAM,UAAU,KAAK,UAAU,MAAM;AAGhE,QAAK,KAAK,QAAQ;;;CAGvB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.cjs","names":["crypto","path"],"sources":["../../src/utils.ts"],"sourcesContent":["import path from 'node:path';\nimport crypto from 'node:crypto';\nimport type { ChunkStats } from 'rollup-plugin-stats/extract';\n\nconst HASH_LENGTH = 7;\n\n/**\n * Get content byte size\n */\nexport function getByteSize(\n content?: string | Uint8Array<ArrayBufferLike>\n): number {\n if (!content) {\n return 0;\n }\n\n if (typeof content === 'string') {\n return Buffer.byteLength(content);\n }\n\n return content?.length || 0;\n}\n\n/**\n * Generate a 7 chars hash from a filepath\n */\nexport function getHash(filepath: string): string {\n const digest = crypto.createHash('sha256');\n return digest.update(filepath).digest('hex').substr(0, HASH_LENGTH);\n}\n\nexport function getChunkId(chunk: ChunkStats): string {\n let value = chunk.name;\n\n // Use entry module relative path\n if (chunk.moduleIds?.length > 0) {\n const absoluteModulePath = chunk.moduleIds[chunk.moduleIds.length - 1];\n value = path.relative(process.cwd(), absoluteModulePath);\n }\n\n return getHash([chunk, value].join('-'));\n}\n\ntype ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);\n\nexport type ExcludeFilepathOption =\n | ExcludeFilepathParam\n | Array<ExcludeFilepathParam>;\n\nexport function round(value: number, precision = 2) {\n const multiplier = 10 ^ precision;\n return Math.round(value * multiplier) / multiplier;\n}\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\nconst DEFAULT_FILE_NAME = 'webpack-stats.json';\n\nexport function resolveFilepath(\n fileName = DEFAULT_FILE_NAME,\n outputDir?: string\n): string {\n // Check if the fileName is an absolute path\n if (path.isAbsolute(fileName)) {\n return fileName;\n }\n\n // If the fileName is not an absolute path, join it with the output directory or the current working directory\n return path.join(outputDir || process.cwd(), fileName);\n}\n"],"mappings":";;;;;;;AAIA,MAAM,cAAc;;;;AAKpB,SAAgB,YACd,SACQ;AACR,KAAI,CAAC,QACH,QAAO;AAGT,KAAI,OAAO,YAAY,SACrB,QAAO,OAAO,WAAW,QAAQ;AAGnC,QAAO,SAAS,UAAU;;;;;AAM5B,SAAgB,QAAQ,UAA0B;AAEhD,QADeA,oBAAO,WAAW,SAAS,CAC5B,OAAO,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,GAAG,YAAY;;AAGrE,SAAgB,WAAW,OAA2B;CACpD,IAAI,QAAQ,MAAM;AAGlB,KAAI,MAAM,WAAW,SAAS,GAAG;EAC/B,MAAM,qBAAqB,MAAM,UAAU,MAAM,UAAU,SAAS;AACpE,UAAQC,kBAAK,SAAS,QAAQ,KAAK,EAAE,mBAAmB;;AAG1D,QAAO,QAAQ,CAAC,OAAO,MAAM,CAAC,KAAK,IAAI,CAAC;;AAS1C,SAAgB,MAAM,OAAe,YAAY,GAAG;CAClD,MAAM,aAAa,KAAK;AACxB,QAAO,KAAK,MAAM,QAAQ,WAAW,GAAG;;AAG1C,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;;AAGrD,MAAM,oBAAoB;AAE1B,SAAgB,gBACd,WAAW,mBACX,WACQ;AAER,KAAIA,kBAAK,WAAW,SAAS,CAC3B,QAAO;AAIT,QAAOA,kBAAK,KAAK,aAAa,QAAQ,KAAK,EAAE,SAAS"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.mjs","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["import path from 'node:path';\nimport crypto from 'node:crypto';\nimport type { ChunkStats } from 'rollup-plugin-stats/extract';\n\nconst HASH_LENGTH = 7;\n\n/**\n * Get content byte size\n */\nexport function getByteSize(\n content?: string | Uint8Array<ArrayBufferLike>\n): number {\n if (!content) {\n return 0;\n }\n\n if (typeof content === 'string') {\n return Buffer.byteLength(content);\n }\n\n return content?.length || 0;\n}\n\n/**\n * Generate a 7 chars hash from a filepath\n */\nexport function getHash(filepath: string): string {\n const digest = crypto.createHash('sha256');\n return digest.update(filepath).digest('hex').substr(0, HASH_LENGTH);\n}\n\nexport function getChunkId(chunk: ChunkStats): string {\n let value = chunk.name;\n\n // Use entry module relative path\n if (chunk.moduleIds?.length > 0) {\n const absoluteModulePath = chunk.moduleIds[chunk.moduleIds.length - 1];\n value = path.relative(process.cwd(), absoluteModulePath);\n }\n\n return getHash([chunk, value].join('-'));\n}\n\ntype ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);\n\nexport type ExcludeFilepathOption =\n | ExcludeFilepathParam\n | Array<ExcludeFilepathParam>;\n\nexport function round(value: number, precision = 2) {\n const multiplier = 10 ^ precision;\n return Math.round(value * multiplier) / multiplier;\n}\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\nconst DEFAULT_FILE_NAME = 'webpack-stats.json';\n\nexport function resolveFilepath(\n fileName = DEFAULT_FILE_NAME,\n outputDir?: string\n): string {\n // Check if the fileName is an absolute path\n if (path.isAbsolute(fileName)) {\n return fileName;\n }\n\n // If the fileName is not an absolute path, join it with the output directory or the current working directory\n return path.join(outputDir || process.cwd(), fileName);\n}\n"],"mappings":";;;;AAIA,MAAM,cAAc;;;;AAKpB,SAAgB,YACd,SACQ;AACR,KAAI,CAAC,QACH,QAAO;AAGT,KAAI,OAAO,YAAY,SACrB,QAAO,OAAO,WAAW,QAAQ;AAGnC,QAAO,SAAS,UAAU;;;;;AAM5B,SAAgB,QAAQ,UAA0B;AAEhD,QADe,OAAO,WAAW,SAAS,CAC5B,OAAO,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,GAAG,YAAY;;AAGrE,SAAgB,WAAW,OAA2B;CACpD,IAAI,QAAQ,MAAM;AAGlB,KAAI,MAAM,WAAW,SAAS,GAAG;EAC/B,MAAM,qBAAqB,MAAM,UAAU,MAAM,UAAU,SAAS;AACpE,UAAQ,KAAK,SAAS,QAAQ,KAAK,EAAE,mBAAmB;;AAG1D,QAAO,QAAQ,CAAC,OAAO,MAAM,CAAC,KAAK,IAAI,CAAC;;AAS1C,SAAgB,MAAM,OAAe,YAAY,GAAG;CAClD,MAAM,aAAa,KAAK;AACxB,QAAO,KAAK,MAAM,QAAQ,WAAW,GAAG;;AAG1C,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;;AAGrD,MAAM,oBAAoB;AAE1B,SAAgB,gBACd,WAAW,mBACX,WACQ;AAER,KAAI,KAAK,WAAW,SAAS,CAC3B,QAAO;AAIT,QAAO,KAAK,KAAK,aAAa,QAAQ,KAAK,EAAE,SAAS"}
@@ -1 +0,0 @@
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 StatsWriteResponse = {\n filepath: string;\n content: string;\n};\n\nexport type StatsWrite = (\n filepath: string,\n stats: Record<string, unknown>\n) => StatsWriteResponse;\n\nexport async function statsWrite<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(filepath: string, stats: T): Promise<StatsWriteResponse> {\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,WAEpB,UAAkB,OAAuC;CACzD,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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"write.d.cts","names":[],"sources":["../../src/write.ts"],"mappings":";KAGY,kBAAA;EACV,QAAA;EACA,OAAA;AAAA;AAAA,KAGU,UAAA,IACV,QAAA,UACA,KAAA,EAAO,MAAA,sBACJ,kBAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"write.d.mts","names":[],"sources":["../../src/write.ts"],"mappings":";KAGY,kBAAA;EACV,QAAA;EACA,OAAA;AAAA;AAAA,KAGU,UAAA,IACV,QAAA,UACA,KAAA,EAAO,MAAA,sBACJ,kBAAA"}
@@ -1 +0,0 @@
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 StatsWriteResponse = {\n filepath: string;\n content: string;\n};\n\nexport type StatsWrite = (\n filepath: string,\n stats: Record<string, unknown>\n) => StatsWriteResponse;\n\nexport async function statsWrite<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(filepath: string, stats: T): Promise<StatsWriteResponse> {\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,WAEpB,UAAkB,OAAuC;CACzD,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"}
File without changes
File without changes
File without changes
File without changes