rollup-plugin-stats
Advanced tools
| const e=require(`./extract2.cjs`);module.exports=e.t; |
| import { a as ModuleStats, c as StatsOptions, i as ChunkStatsOptionalProperties, l as extractRollupStats, n as AssetStatsOptionalProperties, o as ModuleStatsOptionalProperties, r as ChunkStats, s as Stats, t as AssetStats } from "./extract2.cjs"; | ||
| export { AssetStats, AssetStatsOptionalProperties, ChunkStats, ChunkStatsOptionalProperties, ModuleStats, ModuleStatsOptionalProperties, Stats, StatsOptions, extractRollupStats as default }; |
| function e(e,t){let n={};return Object.keys(e).forEach(r=>{t.includes(r)||(n[r]=e[r])}),n}function t(e,n){if(!n)return!1;if(Array.isArray(n)){let r=!1;for(let i=0;i<=n.length-1&&r===!1;i++)r=t(e,n[i]);return r}return typeof n==`function`?n(e):typeof n==`string`?!!e.match(n):`test`in n?n.test(e):!1}function n(n,r={}){let{source:i=!1,map:a=!1,excludeAssets:o,excludeModules:s}=r,c={};return Object.entries(n).forEach(([n,r])=>{if(!t(n,o)){if(r.type===`asset`){let t=[];i||t.push(`source`),c[n]=e(r,t);return}if(r.type===`chunk`){let o=[];i||o.push(`code`),a||o.push(`map`);let l=e(r,o),u={};Object.entries(l.modules).forEach(([n,r])=>{if(t(n,s))return;let a=[];i||a.push(`code`),u[n]=e(r,a)}),l.modules=u,c[n]=l;return}}}),c}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n}}); | ||
| //# sourceMappingURL=extract2.cjs.map |
| {"version":3,"file":"extract2.cjs","names":["output: Stats","assetStatsOmitKeys: Array<keyof AssetStatsOptionalProperties>","chunkStatsOmitKeys: Array<keyof ChunkStatsOptionalProperties>","chunkModulesStats: ChunkStats['modules']","moduleStatsOmitKeys: Array<keyof ModuleStatsOptionalProperties>"],"sources":["../../src/utils/omit.ts","../../src/utils/check-exclude-filepath.ts","../../src/extract.ts"],"sourcesContent":["export function omit<D extends object, K extends keyof D = keyof D>(\n data: D,\n keys: K[],\n): Omit<D, K> {\n const result = {} as D;\n const objectKeys = Object.keys(data) as Array<K>;\n\n objectKeys.forEach((key) => {\n if (!keys.includes(key)) {\n result[key] = data[key];\n }\n });\n\n return result;\n}\n","type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);\n\nexport type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>;\n\n/**\n * Check if filepath should be excluded based on patterns\n */\nexport function checkExcludeFilepath(\n filepath: string,\n patterns?: ExcludeFilepathPatterns,\n): boolean {\n if (!patterns) {\n return false;\n }\n\n if (Array.isArray(patterns)) {\n let res = false;\n\n for (let i = 0; i <= patterns.length - 1 && res === false; i++) {\n res = checkExcludeFilepath(filepath, patterns[i]);\n }\n\n return res;\n }\n\n if (typeof patterns === 'function') {\n return patterns(filepath);\n }\n\n if (typeof patterns === 'string') {\n return Boolean(filepath.match(patterns));\n }\n\n if ('test' in patterns) {\n return patterns.test(filepath);\n }\n\n return false;\n}\n","import type { OutputAsset, OutputBundle, OutputChunk, RenderedModule } from 'rollup';\nimport { omit } from './utils/omit';\nimport { type ExcludeFilepathPatterns, checkExcludeFilepath } from './utils/check-exclude-filepath';\n\nexport type AssetStatsOptionalProperties = {\n source?: OutputAsset['source'];\n};\n\nexport type AssetStats = Omit<OutputAsset, keyof AssetStatsOptionalProperties> & AssetStatsOptionalProperties;\n\nexport type ModuleStatsOptionalProperties = {\n code?: RenderedModule['code'] | null;\n};\n\nexport type ModuleStats = Omit<RenderedModule, keyof ModuleStatsOptionalProperties> & ModuleStatsOptionalProperties;\n\nexport type ChunkStatsOptionalProperties = {\n code?: OutputChunk['code'];\n map?: OutputChunk['map']; \n};\n\nexport type ChunkStats = Omit<OutputChunk, keyof ChunkStatsOptionalProperties | 'modules'> & {\n modules: Record<string, ModuleStats>;\n} & ChunkStatsOptionalProperties;\n\nexport type Stats = Record<string, AssetStats | ChunkStats>;\n\nexport type StatsOptions = {\n /**\n * Output asset/module sources\n * @default false \n */\n source?: boolean;\n /**\n * Output chunk map\n * @default false \n */\n map?: boolean;\n /**\n * Exclude matching assets\n */\n excludeAssets?: ExcludeFilepathPatterns;\n /**\n * Exclude matching modules\n */\n excludeModules?: ExcludeFilepathPatterns;\n}\n\n/**\n * Extract bundler stats\n *\n * Shallow clone stats object before any processing using `omit` to\n * 1. resolve getters\n * 2. prevent changes to the stats object\n *\n * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128\n */\nexport default function extractRollupStats(bundle: OutputBundle, options: StatsOptions = {}): Stats {\n const { source = false, map = false, excludeAssets, excludeModules } = options;\n\n const output: Stats = {};\n\n Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {\n // Skip extraction if the entry filepath matches the exclude assets pattern\n if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {\n return;\n }\n\n if (bundleEntryStats.type === \"asset\") {\n const assetStatsOmitKeys: Array<keyof AssetStatsOptionalProperties> = [];\n\n // Skip asset source if options.source is false\n if (!source) {\n assetStatsOmitKeys.push('source'); \n }\n\n output[bundleEntryFilepath] = omit(\n bundleEntryStats,\n assetStatsOmitKeys,\n ) as AssetStats;\n\n return;\n }\n\n if (bundleEntryStats.type === \"chunk\") {\n const chunkStatsOmitKeys: Array<keyof ChunkStatsOptionalProperties> = [];\n\n // Skip chunk source if options.source is false\n if (!source) {\n chunkStatsOmitKeys.push('code');\n }\n\n // Skip chunk map if options.map is false\n if (!map) {\n chunkStatsOmitKeys.push('map');\n }\n\n const chunkStats = omit(bundleEntryStats, chunkStatsOmitKeys) as ChunkStats;\n\n\n // Extract chunk modules stats\n const chunkModulesStats: ChunkStats['modules'] = {};\n\n Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {\n // Skip module extraction if the filepath matches the exclude modules pattern\n if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {\n return;\n }\n\n const moduleStatsOmitKeys: Array<keyof ModuleStatsOptionalProperties> = [];\n\n // Skip module source if options.source is false\n if (!source) {\n moduleStatsOmitKeys.push('code');\n }\n\n chunkModulesStats[bundleModuleFilepath] = omit(\n bundleModuleStats,\n moduleStatsOmitKeys,\n ) as ModuleStats;\n });\n\n chunkStats.modules = chunkModulesStats;\n\n output[bundleEntryFilepath] = chunkStats;\n\n return;\n }\n });\n \n return output;\n}\n"],"mappings":"AAAA,SAAgB,EACd,EACA,EACY,CACZ,IAAM,EAAS,EAAE,CASjB,OARmB,OAAO,KAAK,EAAK,CAEzB,QAAS,GAAQ,CACrB,EAAK,SAAS,EAAI,GACrB,EAAO,GAAO,EAAK,KAErB,CAEK,ECNT,SAAgB,EACd,EACA,EACS,CACT,GAAI,CAAC,EACH,MAAO,GAGT,GAAI,MAAM,QAAQ,EAAS,CAAE,CAC3B,IAAI,EAAM,GAEV,IAAK,IAAI,EAAI,EAAG,GAAK,EAAS,OAAS,GAAK,IAAQ,GAAO,IACzD,EAAM,EAAqB,EAAU,EAAS,GAAG,CAGnD,OAAO,EAeT,OAZI,OAAO,GAAa,WACf,EAAS,EAAS,CAGvB,OAAO,GAAa,SACf,EAAQ,EAAS,MAAM,EAAS,CAGrC,SAAU,EACL,EAAS,KAAK,EAAS,CAGzB,GCoBT,SAAwB,EAAmB,EAAsB,EAAwB,EAAE,CAAS,CAClG,GAAM,CAAE,SAAS,GAAO,MAAM,GAAO,gBAAe,kBAAmB,EAEjEA,EAAgB,EAAE,CAsExB,OApEA,OAAO,QAAQ,EAAO,CAAC,SAAS,CAAC,EAAqB,KAAsB,CAEtE,MAAqB,EAAqB,EAAc,CAI5D,IAAI,EAAiB,OAAS,QAAS,CACrC,IAAMC,EAAgE,EAAE,CAGnE,GACH,EAAmB,KAAK,SAAS,CAGnC,EAAO,GAAuB,EAC5B,EACA,EACD,CAED,OAGF,GAAI,EAAiB,OAAS,QAAS,CACrC,IAAMC,EAAgE,EAAE,CAGnE,GACH,EAAmB,KAAK,OAAO,CAI5B,GACH,EAAmB,KAAK,MAAM,CAGhC,IAAM,EAAa,EAAK,EAAkB,EAAmB,CAIvDC,EAA2C,EAAE,CAEnD,OAAO,QAAQ,EAAW,QAAQ,CAAC,SAAS,CAAC,EAAsB,KAAuB,CAExF,GAAI,EAAqB,EAAsB,EAAe,CAC5D,OAGF,IAAMC,EAAkE,EAAE,CAGrE,GACH,EAAoB,KAAK,OAAO,CAGlC,EAAkB,GAAwB,EACxC,EACA,EACD,EACD,CAEF,EAAW,QAAU,EAErB,EAAO,GAAuB,EAE9B,UAEF,CAEK"} |
| import { OutputAsset, OutputBundle, OutputChunk, RenderedModule } from "rollup"; | ||
| //#region src/utils/check-exclude-filepath.d.ts | ||
| type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean); | ||
| type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>; | ||
| //#endregion | ||
| //#region src/extract.d.ts | ||
| type AssetStatsOptionalProperties = { | ||
| source?: OutputAsset['source']; | ||
| }; | ||
| type AssetStats = Omit<OutputAsset, keyof AssetStatsOptionalProperties> & AssetStatsOptionalProperties; | ||
| type ModuleStatsOptionalProperties = { | ||
| code?: RenderedModule['code'] | null; | ||
| }; | ||
| type ModuleStats = Omit<RenderedModule, keyof ModuleStatsOptionalProperties> & ModuleStatsOptionalProperties; | ||
| type ChunkStatsOptionalProperties = { | ||
| code?: OutputChunk['code']; | ||
| map?: OutputChunk['map']; | ||
| }; | ||
| type ChunkStats = Omit<OutputChunk, keyof ChunkStatsOptionalProperties | 'modules'> & { | ||
| modules: Record<string, ModuleStats>; | ||
| } & ChunkStatsOptionalProperties; | ||
| type Stats = Record<string, AssetStats | ChunkStats>; | ||
| type StatsOptions = { | ||
| /** | ||
| * Output asset/module sources | ||
| * @default false | ||
| */ | ||
| source?: boolean; | ||
| /** | ||
| * Output chunk map | ||
| * @default false | ||
| */ | ||
| map?: boolean; | ||
| /** | ||
| * Exclude matching assets | ||
| */ | ||
| excludeAssets?: ExcludeFilepathPatterns; | ||
| /** | ||
| * Exclude matching modules | ||
| */ | ||
| excludeModules?: ExcludeFilepathPatterns; | ||
| }; | ||
| /** | ||
| * Extract bundler stats | ||
| * | ||
| * Shallow clone stats object before any processing using `omit` to | ||
| * 1. resolve getters | ||
| * 2. prevent changes to the stats object | ||
| * | ||
| * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128 | ||
| */ | ||
| declare function extractRollupStats(bundle: OutputBundle, options?: StatsOptions): Stats; | ||
| //#endregion | ||
| export { ModuleStats as a, StatsOptions as c, ChunkStatsOptionalProperties as i, extractRollupStats as l, AssetStatsOptionalProperties as n, ModuleStatsOptionalProperties as o, ChunkStats as r, Stats as s, AssetStats as t }; | ||
| //# sourceMappingURL=extract2.d.cts.map |
| var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));const c=require(`./extract2.cjs`);let l=require(`node:path`);l=s(l);let u=require(`node:process`);u=s(u);let d=require(`node:fs/promises`);d=s(d);async function f(e,t){let n=JSON.stringify(t,null,2);return await d.default.mkdir(l.default.dirname(e),{recursive:!0}),await d.default.writeFile(e,n),{filepath:e,content:n}}function p(e,t=2){let n=10^t;return Math.round(e*n)/n}const m={BYTE:{symbol:`B`,multiplier:1},KILO:{symbol:`KiB`,multiplier:1024},MEGA:{symbol:`MiB`,multiplier:1024*1024}};function h(e){let t=m.BYTE;return typeof e==`number`?(t=e<m.KILO.multiplier?m.BYTE:e<m.MEGA.multiplier?m.KILO:m.MEGA,`${p(e/t.multiplier,2)}${t.symbol}`):`0${t.symbol}`}const g=`rollupStats`,_=`stats.json`;function v(e={}){return{name:`rollupStats`,async generateBundle(t,n){let{fileName:r,stats:i,write:a=f}=(typeof e==`function`?e(t):e)||{},o=r||`stats.json`,s=l.default.isAbsolute(o)?o:l.default.join(t.dir||u.default.cwd(),o),d=c.t(n,i);try{let e=await a(s,d),t=Buffer.byteLength(e.content,`utf-8`);this.info(`Stats saved to ${e.filepath} (${h(t)})`)}catch(e){this.warn(e)}}}}var y=v;module.exports=y; | ||
| //# sourceMappingURL=index.cjs.map |
| {"version":3,"file":"index.cjs","names":["fs","path","path","process","extractRollupStats","error: any"],"sources":["../../src/write.ts","../../src/utils/round.ts","../../src/utils/format-file-size.ts","../../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs/promises';\n\nexport type RollupStatsWriteResponse = {\n filepath: string;\n content: string;\n};\n\nexport type RollupStatsWrite = (\n filepath: string,\n stats: Record<string, unknown>\n) => RollupStatsWriteResponse;\n\nexport async function rollupStatsWrite<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(filepath: string, stats: T): Promise<RollupStatsWriteResponse> {\n const content = JSON.stringify(stats, null, 2);\n\n // Create base directory if it does not exist\n await fs.mkdir(path.dirname(filepath), { recursive: true });\n\n await fs.writeFile(filepath, content);\n\n return {\n filepath,\n content,\n };\n}\n","export function round(value: number, precision = 2) {\n const multiplier = 10 ^ precision;\n return Math.round(value * multiplier) / multiplier; \n}\n","import { round } from './round';\n\nconst FILE_SIZE = {\n BYTE: {\n symbol: 'B',\n multiplier: 1,\n },\n KILO: {\n symbol: 'KiB',\n multiplier: 1024,\n },\n MEGA: {\n symbol: 'MiB',\n multiplier: 1024 * 1024,\n },\n}\n\nexport function formatFileSize(value?: number | null): string {\n let unit = FILE_SIZE.BYTE;\n\n if (typeof value !== 'number') {\n return `0${unit.symbol}`;\n }\n\n if (value < FILE_SIZE.KILO.multiplier) {\n unit = FILE_SIZE.BYTE;\n } else if (value < FILE_SIZE.MEGA.multiplier) {\n unit = FILE_SIZE.KILO;\n } else {\n unit = FILE_SIZE.MEGA;\n }\n\n return `${round(value / unit.multiplier, 2)}${unit.symbol}`;\n}\n","import path from 'node:path';\nimport process from 'node:process';\nimport type { Plugin, OutputOptions } from 'rollup';\n\nimport extractRollupStats, { type StatsOptions } from './extract';\nimport { type RollupStatsWrite, rollupStatsWrite } from './write';\nimport { formatFileSize } from './utils/format-file-size';\n\nconst PLUGIN_NAME = 'rollupStats';\nconst DEFAULT_FILE_NAME = 'stats.json';\n\nexport type RollupStatsOptions = {\n /**\n * Output filename relative to Rollup output directory or absolute\n * @default: stats.json\n */\n fileName?: string;\n /**\n * Rollup stats options\n */\n stats?: StatsOptions;\n /**\n * Custom file writer\n * @default - fs.write(FILENAME, JSON.stringify(STATS, null, 2));\n */\n write?: RollupStatsWrite;\n};\n\ntype RollupStatsOptionsOrOutputOptions =\n | RollupStatsOptions\n | ((outputOptions: OutputOptions) => RollupStatsOptions);\n\n\nfunction rollupStats(options: RollupStatsOptionsOrOutputOptions = {}): Plugin {\n return {\n name: PLUGIN_NAME,\n async generateBundle(context, bundle) {\n const resolvedOptions = typeof options === 'function' ? options(context) : options;\n const { fileName, stats: statsOptions, write = rollupStatsWrite } = resolvedOptions || {};\n\n const resolvedFileName = fileName || DEFAULT_FILE_NAME;\n const filepath = path.isAbsolute(resolvedFileName)\n ? resolvedFileName\n : path.join(context.dir || process.cwd(), resolvedFileName);\n\n const stats = extractRollupStats(bundle, statsOptions);\n\n try {\n const res = await write(filepath, stats);\n const outputSize = Buffer.byteLength(res.content, 'utf-8');\n\n this.info(`Stats saved to ${res.filepath} (${formatFileSize(outputSize)})`);\n } catch (error: any) { // eslint-disable-line\n // Log error, but do not throw to allow the compilation to continue\n this.warn(error);\n }\n },\n } satisfies Plugin;\n}\n\nexport default rollupStats;\n\n"],"mappings":"gnBAaA,eAAsB,EAEpB,EAAkB,EAA6C,CAC/D,IAAM,EAAU,KAAK,UAAU,EAAO,KAAM,EAAE,CAO9C,OAJA,MAAMA,EAAAA,QAAG,MAAMC,EAAAA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K,EAAM,GAGrB,CAGH,IAAA,EAAe"} |
| import { c as StatsOptions } from "./extract2.cjs"; | ||
| import { OutputOptions, Plugin } from "rollup"; | ||
| //#region src/write.d.ts | ||
| type RollupStatsWriteResponse = { | ||
| filepath: string; | ||
| content: string; | ||
| }; | ||
| type RollupStatsWrite = (filepath: string, stats: Record<string, unknown>) => RollupStatsWriteResponse; | ||
| //#endregion | ||
| //#region src/index.d.ts | ||
| type RollupStatsOptions = { | ||
| /** | ||
| * Output filename relative to Rollup output directory or absolute | ||
| * @default: stats.json | ||
| */ | ||
| fileName?: string; | ||
| /** | ||
| * Rollup stats options | ||
| */ | ||
| stats?: StatsOptions; | ||
| /** | ||
| * Custom file writer | ||
| * @default - fs.write(FILENAME, JSON.stringify(STATS, null, 2)); | ||
| */ | ||
| write?: RollupStatsWrite; | ||
| }; | ||
| type RollupStatsOptionsOrOutputOptions = RollupStatsOptions | ((outputOptions: OutputOptions) => RollupStatsOptions); | ||
| declare function rollupStats(options?: RollupStatsOptionsOrOutputOptions): Plugin; | ||
| //#endregion | ||
| export { RollupStatsOptions, rollupStats as default }; | ||
| //# sourceMappingURL=index.d.cts.map |
| import { a as ModuleStats, c as StatsOptions, i as ChunkStatsOptionalProperties, l as extractRollupStats, n as AssetStatsOptionalProperties, o as ModuleStatsOptionalProperties, r as ChunkStats, s as Stats, t as AssetStats } from "./extract2.mjs"; | ||
| export { AssetStats, AssetStatsOptionalProperties, ChunkStats, ChunkStatsOptionalProperties, ModuleStats, ModuleStatsOptionalProperties, Stats, StatsOptions, extractRollupStats as default }; |
| import{t as e}from"./extract2.mjs";export{e as default}; |
| import { OutputAsset, OutputBundle, OutputChunk, RenderedModule } from "rollup"; | ||
| //#region src/utils/check-exclude-filepath.d.ts | ||
| type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean); | ||
| type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>; | ||
| //#endregion | ||
| //#region src/extract.d.ts | ||
| type AssetStatsOptionalProperties = { | ||
| source?: OutputAsset['source']; | ||
| }; | ||
| type AssetStats = Omit<OutputAsset, keyof AssetStatsOptionalProperties> & AssetStatsOptionalProperties; | ||
| type ModuleStatsOptionalProperties = { | ||
| code?: RenderedModule['code'] | null; | ||
| }; | ||
| type ModuleStats = Omit<RenderedModule, keyof ModuleStatsOptionalProperties> & ModuleStatsOptionalProperties; | ||
| type ChunkStatsOptionalProperties = { | ||
| code?: OutputChunk['code']; | ||
| map?: OutputChunk['map']; | ||
| }; | ||
| type ChunkStats = Omit<OutputChunk, keyof ChunkStatsOptionalProperties | 'modules'> & { | ||
| modules: Record<string, ModuleStats>; | ||
| } & ChunkStatsOptionalProperties; | ||
| type Stats = Record<string, AssetStats | ChunkStats>; | ||
| type StatsOptions = { | ||
| /** | ||
| * Output asset/module sources | ||
| * @default false | ||
| */ | ||
| source?: boolean; | ||
| /** | ||
| * Output chunk map | ||
| * @default false | ||
| */ | ||
| map?: boolean; | ||
| /** | ||
| * Exclude matching assets | ||
| */ | ||
| excludeAssets?: ExcludeFilepathPatterns; | ||
| /** | ||
| * Exclude matching modules | ||
| */ | ||
| excludeModules?: ExcludeFilepathPatterns; | ||
| }; | ||
| /** | ||
| * Extract bundler stats | ||
| * | ||
| * Shallow clone stats object before any processing using `omit` to | ||
| * 1. resolve getters | ||
| * 2. prevent changes to the stats object | ||
| * | ||
| * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128 | ||
| */ | ||
| declare function extractRollupStats(bundle: OutputBundle, options?: StatsOptions): Stats; | ||
| //#endregion | ||
| export { ModuleStats as a, StatsOptions as c, ChunkStatsOptionalProperties as i, extractRollupStats as l, AssetStatsOptionalProperties as n, ModuleStatsOptionalProperties as o, ChunkStats as r, Stats as s, AssetStats as t }; | ||
| //# sourceMappingURL=extract2.d.mts.map |
| function e(e,t){let n={};return Object.keys(e).forEach(r=>{t.includes(r)||(n[r]=e[r])}),n}function t(e,n){if(!n)return!1;if(Array.isArray(n)){let r=!1;for(let i=0;i<=n.length-1&&r===!1;i++)r=t(e,n[i]);return r}return typeof n==`function`?n(e):typeof n==`string`?!!e.match(n):`test`in n?n.test(e):!1}function n(n,r={}){let{source:i=!1,map:a=!1,excludeAssets:o,excludeModules:s}=r,c={};return Object.entries(n).forEach(([n,r])=>{if(!t(n,o)){if(r.type===`asset`){let t=[];i||t.push(`source`),c[n]=e(r,t);return}if(r.type===`chunk`){let o=[];i||o.push(`code`),a||o.push(`map`);let l=e(r,o),u={};Object.entries(l.modules).forEach(([n,r])=>{if(t(n,s))return;let a=[];i||a.push(`code`),u[n]=e(r,a)}),l.modules=u,c[n]=l;return}}}),c}export{n as t}; | ||
| //# sourceMappingURL=extract2.mjs.map |
| {"version":3,"file":"extract2.mjs","names":["output: Stats","assetStatsOmitKeys: Array<keyof AssetStatsOptionalProperties>","chunkStatsOmitKeys: Array<keyof ChunkStatsOptionalProperties>","chunkModulesStats: ChunkStats['modules']","moduleStatsOmitKeys: Array<keyof ModuleStatsOptionalProperties>"],"sources":["../../src/utils/omit.ts","../../src/utils/check-exclude-filepath.ts","../../src/extract.ts"],"sourcesContent":["export function omit<D extends object, K extends keyof D = keyof D>(\n data: D,\n keys: K[],\n): Omit<D, K> {\n const result = {} as D;\n const objectKeys = Object.keys(data) as Array<K>;\n\n objectKeys.forEach((key) => {\n if (!keys.includes(key)) {\n result[key] = data[key];\n }\n });\n\n return result;\n}\n","type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean);\n\nexport type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>;\n\n/**\n * Check if filepath should be excluded based on patterns\n */\nexport function checkExcludeFilepath(\n filepath: string,\n patterns?: ExcludeFilepathPatterns,\n): boolean {\n if (!patterns) {\n return false;\n }\n\n if (Array.isArray(patterns)) {\n let res = false;\n\n for (let i = 0; i <= patterns.length - 1 && res === false; i++) {\n res = checkExcludeFilepath(filepath, patterns[i]);\n }\n\n return res;\n }\n\n if (typeof patterns === 'function') {\n return patterns(filepath);\n }\n\n if (typeof patterns === 'string') {\n return Boolean(filepath.match(patterns));\n }\n\n if ('test' in patterns) {\n return patterns.test(filepath);\n }\n\n return false;\n}\n","import type { OutputAsset, OutputBundle, OutputChunk, RenderedModule } from 'rollup';\nimport { omit } from './utils/omit';\nimport { type ExcludeFilepathPatterns, checkExcludeFilepath } from './utils/check-exclude-filepath';\n\nexport type AssetStatsOptionalProperties = {\n source?: OutputAsset['source'];\n};\n\nexport type AssetStats = Omit<OutputAsset, keyof AssetStatsOptionalProperties> & AssetStatsOptionalProperties;\n\nexport type ModuleStatsOptionalProperties = {\n code?: RenderedModule['code'] | null;\n};\n\nexport type ModuleStats = Omit<RenderedModule, keyof ModuleStatsOptionalProperties> & ModuleStatsOptionalProperties;\n\nexport type ChunkStatsOptionalProperties = {\n code?: OutputChunk['code'];\n map?: OutputChunk['map']; \n};\n\nexport type ChunkStats = Omit<OutputChunk, keyof ChunkStatsOptionalProperties | 'modules'> & {\n modules: Record<string, ModuleStats>;\n} & ChunkStatsOptionalProperties;\n\nexport type Stats = Record<string, AssetStats | ChunkStats>;\n\nexport type StatsOptions = {\n /**\n * Output asset/module sources\n * @default false \n */\n source?: boolean;\n /**\n * Output chunk map\n * @default false \n */\n map?: boolean;\n /**\n * Exclude matching assets\n */\n excludeAssets?: ExcludeFilepathPatterns;\n /**\n * Exclude matching modules\n */\n excludeModules?: ExcludeFilepathPatterns;\n}\n\n/**\n * Extract bundler stats\n *\n * Shallow clone stats object before any processing using `omit` to\n * 1. resolve getters\n * 2. prevent changes to the stats object\n *\n * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128\n */\nexport default function extractRollupStats(bundle: OutputBundle, options: StatsOptions = {}): Stats {\n const { source = false, map = false, excludeAssets, excludeModules } = options;\n\n const output: Stats = {};\n\n Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => {\n // Skip extraction if the entry filepath matches the exclude assets pattern\n if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) {\n return;\n }\n\n if (bundleEntryStats.type === \"asset\") {\n const assetStatsOmitKeys: Array<keyof AssetStatsOptionalProperties> = [];\n\n // Skip asset source if options.source is false\n if (!source) {\n assetStatsOmitKeys.push('source'); \n }\n\n output[bundleEntryFilepath] = omit(\n bundleEntryStats,\n assetStatsOmitKeys,\n ) as AssetStats;\n\n return;\n }\n\n if (bundleEntryStats.type === \"chunk\") {\n const chunkStatsOmitKeys: Array<keyof ChunkStatsOptionalProperties> = [];\n\n // Skip chunk source if options.source is false\n if (!source) {\n chunkStatsOmitKeys.push('code');\n }\n\n // Skip chunk map if options.map is false\n if (!map) {\n chunkStatsOmitKeys.push('map');\n }\n\n const chunkStats = omit(bundleEntryStats, chunkStatsOmitKeys) as ChunkStats;\n\n\n // Extract chunk modules stats\n const chunkModulesStats: ChunkStats['modules'] = {};\n\n Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => {\n // Skip module extraction if the filepath matches the exclude modules pattern\n if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) {\n return;\n }\n\n const moduleStatsOmitKeys: Array<keyof ModuleStatsOptionalProperties> = [];\n\n // Skip module source if options.source is false\n if (!source) {\n moduleStatsOmitKeys.push('code');\n }\n\n chunkModulesStats[bundleModuleFilepath] = omit(\n bundleModuleStats,\n moduleStatsOmitKeys,\n ) as ModuleStats;\n });\n\n chunkStats.modules = chunkModulesStats;\n\n output[bundleEntryFilepath] = chunkStats;\n\n return;\n }\n });\n \n return output;\n}\n"],"mappings":"AAAA,SAAgB,EACd,EACA,EACY,CACZ,IAAM,EAAS,EAAE,CASjB,OARmB,OAAO,KAAK,EAAK,CAEzB,QAAS,GAAQ,CACrB,EAAK,SAAS,EAAI,GACrB,EAAO,GAAO,EAAK,KAErB,CAEK,ECNT,SAAgB,EACd,EACA,EACS,CACT,GAAI,CAAC,EACH,MAAO,GAGT,GAAI,MAAM,QAAQ,EAAS,CAAE,CAC3B,IAAI,EAAM,GAEV,IAAK,IAAI,EAAI,EAAG,GAAK,EAAS,OAAS,GAAK,IAAQ,GAAO,IACzD,EAAM,EAAqB,EAAU,EAAS,GAAG,CAGnD,OAAO,EAeT,OAZI,OAAO,GAAa,WACf,EAAS,EAAS,CAGvB,OAAO,GAAa,SACf,EAAQ,EAAS,MAAM,EAAS,CAGrC,SAAU,EACL,EAAS,KAAK,EAAS,CAGzB,GCoBT,SAAwB,EAAmB,EAAsB,EAAwB,EAAE,CAAS,CAClG,GAAM,CAAE,SAAS,GAAO,MAAM,GAAO,gBAAe,kBAAmB,EAEjEA,EAAgB,EAAE,CAsExB,OApEA,OAAO,QAAQ,EAAO,CAAC,SAAS,CAAC,EAAqB,KAAsB,CAEtE,MAAqB,EAAqB,EAAc,CAI5D,IAAI,EAAiB,OAAS,QAAS,CACrC,IAAMC,EAAgE,EAAE,CAGnE,GACH,EAAmB,KAAK,SAAS,CAGnC,EAAO,GAAuB,EAC5B,EACA,EACD,CAED,OAGF,GAAI,EAAiB,OAAS,QAAS,CACrC,IAAMC,EAAgE,EAAE,CAGnE,GACH,EAAmB,KAAK,OAAO,CAI5B,GACH,EAAmB,KAAK,MAAM,CAGhC,IAAM,EAAa,EAAK,EAAkB,EAAmB,CAIvDC,EAA2C,EAAE,CAEnD,OAAO,QAAQ,EAAW,QAAQ,CAAC,SAAS,CAAC,EAAsB,KAAuB,CAExF,GAAI,EAAqB,EAAsB,EAAe,CAC5D,OAGF,IAAMC,EAAkE,EAAE,CAGrE,GACH,EAAoB,KAAK,OAAO,CAGlC,EAAkB,GAAwB,EACxC,EACA,EACD,EACD,CAEF,EAAW,QAAU,EAErB,EAAO,GAAuB,EAE9B,UAEF,CAEK"} |
| import { c as StatsOptions } from "./extract2.mjs"; | ||
| import { OutputOptions, Plugin } from "rollup"; | ||
| //#region src/write.d.ts | ||
| type RollupStatsWriteResponse = { | ||
| filepath: string; | ||
| content: string; | ||
| }; | ||
| type RollupStatsWrite = (filepath: string, stats: Record<string, unknown>) => RollupStatsWriteResponse; | ||
| //#endregion | ||
| //#region src/index.d.ts | ||
| type RollupStatsOptions = { | ||
| /** | ||
| * Output filename relative to Rollup output directory or absolute | ||
| * @default: stats.json | ||
| */ | ||
| fileName?: string; | ||
| /** | ||
| * Rollup stats options | ||
| */ | ||
| stats?: StatsOptions; | ||
| /** | ||
| * Custom file writer | ||
| * @default - fs.write(FILENAME, JSON.stringify(STATS, null, 2)); | ||
| */ | ||
| write?: RollupStatsWrite; | ||
| }; | ||
| type RollupStatsOptionsOrOutputOptions = RollupStatsOptions | ((outputOptions: OutputOptions) => RollupStatsOptions); | ||
| declare function rollupStats(options?: RollupStatsOptionsOrOutputOptions): Plugin; | ||
| //#endregion | ||
| export { RollupStatsOptions, rollupStats as default }; | ||
| //# sourceMappingURL=index.d.mts.map |
| import{t as e}from"./extract2.mjs";import t from"node:path";import n from"node:process";import r from"node:fs/promises";async function i(e,n){let i=JSON.stringify(n,null,2);return await r.mkdir(t.dirname(e),{recursive:!0}),await r.writeFile(e,i),{filepath:e,content:i}}function a(e,t=2){let n=10^t;return Math.round(e*n)/n}const o={BYTE:{symbol:`B`,multiplier:1},KILO:{symbol:`KiB`,multiplier:1024},MEGA:{symbol:`MiB`,multiplier:1024*1024}};function s(e){let t=o.BYTE;return typeof e==`number`?(t=e<o.KILO.multiplier?o.BYTE:e<o.MEGA.multiplier?o.KILO:o.MEGA,`${a(e/t.multiplier,2)}${t.symbol}`):`0${t.symbol}`}function c(r={}){return{name:`rollupStats`,async generateBundle(a,o){let{fileName:c,stats:l,write:u=i}=(typeof r==`function`?r(a):r)||{},d=c||`stats.json`,f=t.isAbsolute(d)?d:t.join(a.dir||n.cwd(),d),p=e(o,l);try{let e=await u(f,p),t=Buffer.byteLength(e.content,`utf-8`);this.info(`Stats saved to ${e.filepath} (${s(t)})`)}catch(e){this.warn(e)}}}}var l=c;export{l as default}; | ||
| //# sourceMappingURL=index.mjs.map |
| {"version":3,"file":"index.mjs","names":["error: any"],"sources":["../../src/write.ts","../../src/utils/round.ts","../../src/utils/format-file-size.ts","../../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport fs from 'node:fs/promises';\n\nexport type RollupStatsWriteResponse = {\n filepath: string;\n content: string;\n};\n\nexport type RollupStatsWrite = (\n filepath: string,\n stats: Record<string, unknown>\n) => RollupStatsWriteResponse;\n\nexport async function rollupStatsWrite<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(filepath: string, stats: T): Promise<RollupStatsWriteResponse> {\n const content = JSON.stringify(stats, null, 2);\n\n // Create base directory if it does not exist\n await fs.mkdir(path.dirname(filepath), { recursive: true });\n\n await fs.writeFile(filepath, content);\n\n return {\n filepath,\n content,\n };\n}\n","export function round(value: number, precision = 2) {\n const multiplier = 10 ^ precision;\n return Math.round(value * multiplier) / multiplier; \n}\n","import { round } from './round';\n\nconst FILE_SIZE = {\n BYTE: {\n symbol: 'B',\n multiplier: 1,\n },\n KILO: {\n symbol: 'KiB',\n multiplier: 1024,\n },\n MEGA: {\n symbol: 'MiB',\n multiplier: 1024 * 1024,\n },\n}\n\nexport function formatFileSize(value?: number | null): string {\n let unit = FILE_SIZE.BYTE;\n\n if (typeof value !== 'number') {\n return `0${unit.symbol}`;\n }\n\n if (value < FILE_SIZE.KILO.multiplier) {\n unit = FILE_SIZE.BYTE;\n } else if (value < FILE_SIZE.MEGA.multiplier) {\n unit = FILE_SIZE.KILO;\n } else {\n unit = FILE_SIZE.MEGA;\n }\n\n return `${round(value / unit.multiplier, 2)}${unit.symbol}`;\n}\n","import path from 'node:path';\nimport process from 'node:process';\nimport type { Plugin, OutputOptions } from 'rollup';\n\nimport extractRollupStats, { type StatsOptions } from './extract';\nimport { type RollupStatsWrite, rollupStatsWrite } from './write';\nimport { formatFileSize } from './utils/format-file-size';\n\nconst PLUGIN_NAME = 'rollupStats';\nconst DEFAULT_FILE_NAME = 'stats.json';\n\nexport type RollupStatsOptions = {\n /**\n * Output filename relative to Rollup output directory or absolute\n * @default: stats.json\n */\n fileName?: string;\n /**\n * Rollup stats options\n */\n stats?: StatsOptions;\n /**\n * Custom file writer\n * @default - fs.write(FILENAME, JSON.stringify(STATS, null, 2));\n */\n write?: RollupStatsWrite;\n};\n\ntype RollupStatsOptionsOrOutputOptions =\n | RollupStatsOptions\n | ((outputOptions: OutputOptions) => RollupStatsOptions);\n\n\nfunction rollupStats(options: RollupStatsOptionsOrOutputOptions = {}): Plugin {\n return {\n name: PLUGIN_NAME,\n async generateBundle(context, bundle) {\n const resolvedOptions = typeof options === 'function' ? options(context) : options;\n const { fileName, stats: statsOptions, write = rollupStatsWrite } = resolvedOptions || {};\n\n const resolvedFileName = fileName || DEFAULT_FILE_NAME;\n const filepath = path.isAbsolute(resolvedFileName)\n ? resolvedFileName\n : path.join(context.dir || process.cwd(), resolvedFileName);\n\n const stats = extractRollupStats(bundle, statsOptions);\n\n try {\n const res = await write(filepath, stats);\n const outputSize = Buffer.byteLength(res.content, 'utf-8');\n\n this.info(`Stats saved to ${res.filepath} (${formatFileSize(outputSize)})`);\n } catch (error: any) { // eslint-disable-line\n // Log error, but do not throw to allow the compilation to continue\n this.warn(error);\n }\n },\n } satisfies Plugin;\n}\n\nexport default rollupStats;\n\n"],"mappings":"wHAaA,eAAsB,EAEpB,EAAkB,EAA6C,CAC/D,IAAM,EAAU,KAAK,UAAU,EAAO,KAAM,EAAE,CAO9C,OAJA,MAAM,EAAG,MAAM,EAAK,QAAQ,EAAS,CAAE,CAAE,UAAW,GAAM,CAAC,CAE3D,MAAM,EAAG,UAAU,EAAU,EAAQ,CAE9B,CACL,WACA,UACD,CC1BH,SAAgB,EAAM,EAAe,EAAY,EAAG,CAClD,IAAM,EAAa,GAAK,EACxB,OAAO,KAAK,MAAM,EAAQ,EAAW,CAAG,ECA1C,MAAM,EAAY,CAChB,KAAM,CACJ,OAAQ,IACR,WAAY,EACb,CACD,KAAM,CACJ,OAAQ,MACR,WAAY,KACb,CACD,KAAM,CACJ,OAAQ,MACR,WAAY,KAAO,KACpB,CACF,CAED,SAAgB,EAAe,EAA+B,CAC5D,IAAI,EAAO,EAAU,KAcrB,OAZI,OAAO,GAAU,UAIrB,AAKE,EALE,EAAQ,EAAU,KAAK,WAClB,EAAU,KACR,EAAQ,EAAU,KAAK,WACzB,EAAU,KAEV,EAAU,KAGZ,GAAG,EAAM,EAAQ,EAAK,WAAY,EAAE,GAAG,EAAK,UAX1C,IAAI,EAAK,SCYpB,SAAS,EAAY,EAA6C,EAAE,CAAU,CAC5E,MAAO,CACL,KAAM,cACN,MAAM,eAAe,EAAS,EAAQ,CAEpC,GAAM,CAAE,WAAU,MAAO,EAAc,QAAQ,IADvB,OAAO,GAAY,WAAa,EAAQ,EAAQ,CAAG,IACY,EAAE,CAEnF,EAAmB,GAAY,aAC/B,EAAW,EAAK,WAAW,EAAiB,CAC9C,EACA,EAAK,KAAK,EAAQ,KAAO,EAAQ,KAAK,CAAE,EAAiB,CAEvD,EAAQ,EAAmB,EAAQ,EAAa,CAEtD,GAAI,CACF,IAAM,EAAM,MAAM,EAAM,EAAU,EAAM,CAClC,EAAa,OAAO,WAAW,EAAI,QAAS,QAAQ,CAE1D,KAAK,KAAK,kBAAkB,EAAI,SAAS,IAAI,EAAe,EAAW,CAAC,GAAG,OACpEA,EAAY,CAEnB,KAAK,KAAK,EAAM,GAGrB,CAGH,IAAA,EAAe"} |
+12
-13
| { | ||
| "name": "rollup-plugin-stats", | ||
| "description": "Output Rollup stats", | ||
| "version": "1.5.4", | ||
| "version": "1.6.0-beta.0", | ||
| "license": "MIT", | ||
@@ -27,5 +27,5 @@ "private": false, | ||
| ], | ||
| "main": "dist/index.cjs", | ||
| "module": "dist/index.mjs", | ||
| "typings": "dist/index.d.ts", | ||
| "main": "dist/cjs/index.js", | ||
| "module": "dist/esm/index.mjs", | ||
| "typings": "dist/esm/index.d.ts", | ||
| "files": [ | ||
@@ -36,10 +36,10 @@ "dist" | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/index.mjs", | ||
| "require": "./dist/index.cjs" | ||
| "types": "./dist/esm/index.d.ts", | ||
| "import": "./dist/esm/index.mjs", | ||
| "require": "./dist/cjs/index.js" | ||
| }, | ||
| "./extract": { | ||
| "types": "./dist/extract.d.ts", | ||
| "import": "./dist/extract.mjs", | ||
| "require": "./dist/extract.cjs" | ||
| "types": "./dist/esm/extract.d.ts", | ||
| "import": "./dist/esm/extract.mjs", | ||
| "require": "./dist/cjs/extract.js" | ||
| } | ||
@@ -51,3 +51,3 @@ }, | ||
| "scripts": { | ||
| "build": "rollup -c rollup.config.mjs", | ||
| "build": "tsdown", | ||
| "lint": "eslint .", | ||
@@ -71,3 +71,2 @@ "format": "prettier --write .", | ||
| "@release-it/conventional-changelog": "10.0.4", | ||
| "@rollup/plugin-typescript": "12.3.0", | ||
| "@tsconfig/node18": "18.2.6", | ||
@@ -82,3 +81,3 @@ "@types/node": "25.0.3", | ||
| "release-it": "19.2.2", | ||
| "rollup": "4.54.0", | ||
| "tsdown": "0.18.4", | ||
| "typescript": "5.9.3", | ||
@@ -85,0 +84,0 @@ "typescript-eslint": "8.51.0", |
-100
| 'use strict'; | ||
| function omit(data, keys) { | ||
| const result = {}; | ||
| const objectKeys = Object.keys(data); | ||
| objectKeys.forEach((key) => { | ||
| if (!keys.includes(key)) { | ||
| result[key] = data[key]; | ||
| } | ||
| }); | ||
| return result; | ||
| } | ||
| /** | ||
| * Check if filepath should be excluded based on patterns | ||
| */ | ||
| function checkExcludeFilepath(filepath, patterns) { | ||
| if (!patterns) { | ||
| return false; | ||
| } | ||
| if (Array.isArray(patterns)) { | ||
| let res = false; | ||
| for (let i = 0; i <= patterns.length - 1 && res === false; i++) { | ||
| res = checkExcludeFilepath(filepath, patterns[i]); | ||
| } | ||
| return res; | ||
| } | ||
| if (typeof patterns === 'function') { | ||
| return patterns(filepath); | ||
| } | ||
| if (typeof patterns === 'string') { | ||
| return Boolean(filepath.match(patterns)); | ||
| } | ||
| if ('test' in patterns) { | ||
| return patterns.test(filepath); | ||
| } | ||
| return false; | ||
| } | ||
| /** | ||
| * Extract bundler stats | ||
| * | ||
| * Shallow clone stats object before any processing using `omit` to | ||
| * 1. resolve getters | ||
| * 2. prevent changes to the stats object | ||
| * | ||
| * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128 | ||
| */ | ||
| function extractRollupStats(bundle, options = {}) { | ||
| const { source = false, map = false, excludeAssets, excludeModules } = options; | ||
| const output = {}; | ||
| Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => { | ||
| // Skip extraction if the entry filepath matches the exclude assets pattern | ||
| if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) { | ||
| return; | ||
| } | ||
| if (bundleEntryStats.type === "asset") { | ||
| const assetStatsOmitKeys = []; | ||
| // Skip asset source if options.source is false | ||
| if (!source) { | ||
| assetStatsOmitKeys.push('source'); | ||
| } | ||
| output[bundleEntryFilepath] = omit(bundleEntryStats, assetStatsOmitKeys); | ||
| return; | ||
| } | ||
| if (bundleEntryStats.type === "chunk") { | ||
| const chunkStatsOmitKeys = []; | ||
| // Skip chunk source if options.source is false | ||
| if (!source) { | ||
| chunkStatsOmitKeys.push('code'); | ||
| } | ||
| // Skip chunk map if options.map is false | ||
| if (!map) { | ||
| chunkStatsOmitKeys.push('map'); | ||
| } | ||
| const chunkStats = omit(bundleEntryStats, chunkStatsOmitKeys); | ||
| // Extract chunk modules stats | ||
| const chunkModulesStats = {}; | ||
| Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => { | ||
| // Skip module extraction if the filepath matches the exclude modules pattern | ||
| if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) { | ||
| return; | ||
| } | ||
| const moduleStatsOmitKeys = []; | ||
| // Skip module source if options.source is false | ||
| if (!source) { | ||
| moduleStatsOmitKeys.push('code'); | ||
| } | ||
| chunkModulesStats[bundleModuleFilepath] = omit(bundleModuleStats, moduleStatsOmitKeys); | ||
| }); | ||
| chunkStats.modules = chunkModulesStats; | ||
| output[bundleEntryFilepath] = chunkStats; | ||
| return; | ||
| } | ||
| }); | ||
| return output; | ||
| } | ||
| module.exports = extractRollupStats; | ||
| //# sourceMappingURL=extract.cjs.map |
| {"version":3,"file":"extract.cjs","sources":["../src/utils/omit.ts","../src/utils/check-exclude-filepath.ts","../src/extract.ts"],"sourcesContent":[null,null,null],"names":[],"mappings":";;AAAM,SAAU,IAAI,CAClB,IAAO,EACP,IAAS,EAAA;IAET,MAAM,MAAM,GAAG,EAAO;IACtB,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAa;AAEhD,IAAA,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACvB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC;QACzB;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;;ACVA;;AAEG;AACG,SAAU,oBAAoB,CAClC,QAAgB,EAChB,QAAkC,EAAA;IAElC,IAAI,CAAC,QAAQ,EAAE;AACb,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,IAAI,GAAG,GAAG,KAAK;QAEf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC,EAAE,EAAE;YAC9D,GAAG,GAAG,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;QACnD;AAEA,QAAA,OAAO,GAAG;IACZ;AAEA,IAAA,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AAClC,QAAA,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B;AAEA,IAAA,IAAI,OAAO,QAAQ,KAAK,QAA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;;YAI3E,MAAM,iBAAiB,GAA0B,EAAE;AAEnD,YAAA,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,oBAAoB,EAAE,iBAAiB,CAAC,KAAI;;AAEvF,gBAAA,IAAI,oBAAoB,CAAC,oBAAoB,EAAE,cAAc,CAAC,EAAE;oBAC9D;gBACF;gBAEA,MAAM,mBAAmB,GAA+C,EAAE;;gBAG1E,IAAI,CAAC,MAAM,EAAE;AACX,oBAAA,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC;gBAClC;gBAEA,iBAAiB,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAC5C,iBAAiB,EACjB,mBAAmB,CACL;AAClB,YAAA,CAAC,CAAC;AAEF,YAAA,UAAU,CAAC,OAAO,GAAG,iBAAiB;AAEtC,YAAA,MAAM,CAAC,mBAAmB,CAAC,GAAG,UAAU;YAExC;QACF;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;;;;"} |
| import type { OutputAsset, OutputBundle, OutputChunk, RenderedModule } from 'rollup'; | ||
| import { type ExcludeFilepathPatterns } from './utils/check-exclude-filepath'; | ||
| export type AssetStatsOptionalProperties = { | ||
| source?: OutputAsset['source']; | ||
| }; | ||
| export type AssetStats = Omit<OutputAsset, keyof AssetStatsOptionalProperties> & AssetStatsOptionalProperties; | ||
| export type ModuleStatsOptionalProperties = { | ||
| code?: RenderedModule['code'] | null; | ||
| }; | ||
| export type ModuleStats = Omit<RenderedModule, keyof ModuleStatsOptionalProperties> & ModuleStatsOptionalProperties; | ||
| export type ChunkStatsOptionalProperties = { | ||
| code?: OutputChunk['code']; | ||
| map?: OutputChunk['map']; | ||
| }; | ||
| export type ChunkStats = Omit<OutputChunk, keyof ChunkStatsOptionalProperties | 'modules'> & { | ||
| modules: Record<string, ModuleStats>; | ||
| } & ChunkStatsOptionalProperties; | ||
| export type Stats = Record<string, AssetStats | ChunkStats>; | ||
| export type StatsOptions = { | ||
| /** | ||
| * Output asset/module sources | ||
| * @default false | ||
| */ | ||
| source?: boolean; | ||
| /** | ||
| * Output chunk map | ||
| * @default false | ||
| */ | ||
| map?: boolean; | ||
| /** | ||
| * Exclude matching assets | ||
| */ | ||
| excludeAssets?: ExcludeFilepathPatterns; | ||
| /** | ||
| * Exclude matching modules | ||
| */ | ||
| excludeModules?: ExcludeFilepathPatterns; | ||
| }; | ||
| /** | ||
| * Extract bundler stats | ||
| * | ||
| * Shallow clone stats object before any processing using `omit` to | ||
| * 1. resolve getters | ||
| * 2. prevent changes to the stats object | ||
| * | ||
| * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128 | ||
| */ | ||
| export default function extractRollupStats(bundle: OutputBundle, options?: StatsOptions): Stats; |
| function omit(data, keys) { | ||
| const result = {}; | ||
| const objectKeys = Object.keys(data); | ||
| objectKeys.forEach((key) => { | ||
| if (!keys.includes(key)) { | ||
| result[key] = data[key]; | ||
| } | ||
| }); | ||
| return result; | ||
| } | ||
| /** | ||
| * Check if filepath should be excluded based on patterns | ||
| */ | ||
| function checkExcludeFilepath(filepath, patterns) { | ||
| if (!patterns) { | ||
| return false; | ||
| } | ||
| if (Array.isArray(patterns)) { | ||
| let res = false; | ||
| for (let i = 0; i <= patterns.length - 1 && res === false; i++) { | ||
| res = checkExcludeFilepath(filepath, patterns[i]); | ||
| } | ||
| return res; | ||
| } | ||
| if (typeof patterns === 'function') { | ||
| return patterns(filepath); | ||
| } | ||
| if (typeof patterns === 'string') { | ||
| return Boolean(filepath.match(patterns)); | ||
| } | ||
| if ('test' in patterns) { | ||
| return patterns.test(filepath); | ||
| } | ||
| return false; | ||
| } | ||
| /** | ||
| * Extract bundler stats | ||
| * | ||
| * Shallow clone stats object before any processing using `omit` to | ||
| * 1. resolve getters | ||
| * 2. prevent changes to the stats object | ||
| * | ||
| * @NOTE structuredClone is not supported by rolldown-vite: https://github.com/vitejs/rolldown-vite/issues/128 | ||
| */ | ||
| function extractRollupStats(bundle, options = {}) { | ||
| const { source = false, map = false, excludeAssets, excludeModules } = options; | ||
| const output = {}; | ||
| Object.entries(bundle).forEach(([bundleEntryFilepath, bundleEntryStats]) => { | ||
| // Skip extraction if the entry filepath matches the exclude assets pattern | ||
| if (checkExcludeFilepath(bundleEntryFilepath, excludeAssets)) { | ||
| return; | ||
| } | ||
| if (bundleEntryStats.type === "asset") { | ||
| const assetStatsOmitKeys = []; | ||
| // Skip asset source if options.source is false | ||
| if (!source) { | ||
| assetStatsOmitKeys.push('source'); | ||
| } | ||
| output[bundleEntryFilepath] = omit(bundleEntryStats, assetStatsOmitKeys); | ||
| return; | ||
| } | ||
| if (bundleEntryStats.type === "chunk") { | ||
| const chunkStatsOmitKeys = []; | ||
| // Skip chunk source if options.source is false | ||
| if (!source) { | ||
| chunkStatsOmitKeys.push('code'); | ||
| } | ||
| // Skip chunk map if options.map is false | ||
| if (!map) { | ||
| chunkStatsOmitKeys.push('map'); | ||
| } | ||
| const chunkStats = omit(bundleEntryStats, chunkStatsOmitKeys); | ||
| // Extract chunk modules stats | ||
| const chunkModulesStats = {}; | ||
| Object.entries(chunkStats.modules).forEach(([bundleModuleFilepath, bundleModuleStats]) => { | ||
| // Skip module extraction if the filepath matches the exclude modules pattern | ||
| if (checkExcludeFilepath(bundleModuleFilepath, excludeModules)) { | ||
| return; | ||
| } | ||
| const moduleStatsOmitKeys = []; | ||
| // Skip module source if options.source is false | ||
| if (!source) { | ||
| moduleStatsOmitKeys.push('code'); | ||
| } | ||
| chunkModulesStats[bundleModuleFilepath] = omit(bundleModuleStats, moduleStatsOmitKeys); | ||
| }); | ||
| chunkStats.modules = chunkModulesStats; | ||
| output[bundleEntryFilepath] = chunkStats; | ||
| return; | ||
| } | ||
| }); | ||
| return output; | ||
| } | ||
| export { extractRollupStats as default }; | ||
| //# sourceMappingURL=extract.mjs.map |
| {"version":3,"file":"extract.mjs","sources":["../src/utils/omit.ts","../src/utils/check-exclude-filepath.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EAAE,cAAc,CAAC,EAAE;oBAC9D;gBACF;gBAEA,MAAM,mBAAmB,GAA+C,EAAE;;gBAG1E,IAAI,CAAC,MAAM,EAAE;AACX,oBAAA,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC;gBAClC;gBAEA,iBAAiB,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAC5C,iBAAiB,EACjB,mBAAmB,CACL;AAClB,YAAA,CAAC,CAAC;AAEF,YAAA,UAAU,CAAC,OAAO,GAAG,iBAAiB;AAEtC,YAAA,MAAM,CAAC,mBAAmB,CAAC,GAAG,UAAU;YAExC;QACF;AACF,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,MAAM;AACf;;;;"} |
| 'use strict'; | ||
| var path = require('node:path'); | ||
| var process = require('node:process'); | ||
| var extract = require('./extract.cjs'); | ||
| var fs = require('node:fs/promises'); | ||
| async function rollupStatsWrite(filepath, stats) { | ||
| const content = JSON.stringify(stats, null, 2); | ||
| // Create base directory if it does not exist | ||
| await fs.mkdir(path.dirname(filepath), { recursive: true }); | ||
| await fs.writeFile(filepath, content); | ||
| return { | ||
| filepath, | ||
| content, | ||
| }; | ||
| } | ||
| function round(value, precision = 2) { | ||
| const multiplier = 10 ^ precision; | ||
| return Math.round(value * multiplier) / multiplier; | ||
| } | ||
| const FILE_SIZE = { | ||
| BYTE: { | ||
| symbol: 'B', | ||
| multiplier: 1, | ||
| }, | ||
| KILO: { | ||
| symbol: 'KiB', | ||
| multiplier: 1024, | ||
| }, | ||
| MEGA: { | ||
| symbol: 'MiB', | ||
| multiplier: 1024 * 1024, | ||
| }, | ||
| }; | ||
| function formatFileSize(value) { | ||
| let unit = FILE_SIZE.BYTE; | ||
| if (typeof value !== 'number') { | ||
| return `0${unit.symbol}`; | ||
| } | ||
| if (value < FILE_SIZE.KILO.multiplier) { | ||
| unit = FILE_SIZE.BYTE; | ||
| } | ||
| else if (value < FILE_SIZE.MEGA.multiplier) { | ||
| unit = FILE_SIZE.KILO; | ||
| } | ||
| else { | ||
| unit = FILE_SIZE.MEGA; | ||
| } | ||
| return `${round(value / unit.multiplier, 2)}${unit.symbol}`; | ||
| } | ||
| const PLUGIN_NAME = 'rollupStats'; | ||
| const DEFAULT_FILE_NAME = 'stats.json'; | ||
| function rollupStats(options = {}) { | ||
| return { | ||
| name: PLUGIN_NAME, | ||
| async generateBundle(context, bundle) { | ||
| const resolvedOptions = typeof options === 'function' ? options(context) : options; | ||
| const { fileName, stats: statsOptions, write = rollupStatsWrite } = resolvedOptions || {}; | ||
| const resolvedFileName = fileName || DEFAULT_FILE_NAME; | ||
| const filepath = path.isAbsolute(resolvedFileName) | ||
| ? resolvedFileName | ||
| : path.join(context.dir || process.cwd(), resolvedFileName); | ||
| const stats = extract(bundle, statsOptions); | ||
| try { | ||
| const res = await write(filepath, stats); | ||
| const outputSize = Buffer.byteLength(res.content, 'utf-8'); | ||
| this.info(`Stats saved to ${res.filepath} (${formatFileSize(outputSize)})`); | ||
| } | ||
| catch (error) { // eslint-disable-line | ||
| // Log error, but do not throw to allow the compilation to continue | ||
| this.warn(error); | ||
| } | ||
| }, | ||
| }; | ||
| } | ||
| module.exports = rollupStats; | ||
| //# sourceMappingURL=index.cjs.map |
| {"version":3,"file":"index.cjs","sources":["../src/write.ts","../src/utils/round.ts","../src/utils/format-file-size.ts","../src/index.ts"],"sourcesContent":[null,null,null,null],"names":["extractRollupStats"],"mappings":";;;;;;;AAaO,eAAe,gBAAgB,CAEpC,QAAgB,EAAE,KAAQ,EAAA;AAC1B,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;;AAG9C,IAAA,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAE3D,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC;IAErC,OAAO;QACL,QAAQ;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AE,EAAA;IAClE,OAAO;AACL,QAAA,IAAI,EAAE,WAAW;AACjB,QAAA,MAAM,cAAc,CAAC,OAAO,EAAE,MAAM,EAAA;AAClC,YAAA,MAAM,eAAe,GAAG,OAAO,OAAO,KAAK,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO;AAClF,YAAA,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,GAAG,gBAAgB,EAAE,GAAG,eAAe,IAAI,EAAE;AAEzF,YAAA,MAAM,gBAAgB,GAAG,QAAQ,IAAI,iBAAiB;AACtD,YAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,gBAAgB;AAC/C,kBAAE;AACF,kBAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,gBAAgB,CAAC;YAE7D,MAAM,KAAK,GAAGA,OAAkB,CAAC,MAAM,EAAE,YAAY,CAAC;AAEtD,YAAA,IAAI;gBACF,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC;AACxC,gBAAA,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC;AAE1D,gBAAA,IAAI,CAAC,IAAI,CAAC,CAAA,eAAA,EAAkB,GAAG,CAAC,QAAQ,CAAA,EAAA,EAAK,cAAc,CAAC,UAAU,CAAC,CAAA,CAAA,CAAG,CAAC;YAC7E;AAAE,YAAA,OAAO,KAAU,EAAE;;AAEnB,gBAAA,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;YAClB;QACF,CAAC;KACe;AACpB;;;;"} |
| import type { Plugin, OutputOptions } from 'rollup'; | ||
| import { type StatsOptions } from './extract'; | ||
| import { type RollupStatsWrite } from './write'; | ||
| export type RollupStatsOptions = { | ||
| /** | ||
| * Output filename relative to Rollup output directory or absolute | ||
| * @default: stats.json | ||
| */ | ||
| fileName?: string; | ||
| /** | ||
| * Rollup stats options | ||
| */ | ||
| stats?: StatsOptions; | ||
| /** | ||
| * Custom file writer | ||
| * @default - fs.write(FILENAME, JSON.stringify(STATS, null, 2)); | ||
| */ | ||
| write?: RollupStatsWrite; | ||
| }; | ||
| type RollupStatsOptionsOrOutputOptions = RollupStatsOptions | ((outputOptions: OutputOptions) => RollupStatsOptions); | ||
| declare function rollupStats(options?: RollupStatsOptionsOrOutputOptions): Plugin; | ||
| export default rollupStats; |
| import path from 'node:path'; | ||
| import process from 'node:process'; | ||
| import extractRollupStats from './extract.mjs'; | ||
| import fs from 'node:fs/promises'; | ||
| async function rollupStatsWrite(filepath, stats) { | ||
| const content = JSON.stringify(stats, null, 2); | ||
| // Create base directory if it does not exist | ||
| await fs.mkdir(path.dirname(filepath), { recursive: true }); | ||
| await fs.writeFile(filepath, content); | ||
| return { | ||
| filepath, | ||
| content, | ||
| }; | ||
| } | ||
| function round(value, precision = 2) { | ||
| const multiplier = 10 ^ precision; | ||
| return Math.round(value * multiplier) / multiplier; | ||
| } | ||
| const FILE_SIZE = { | ||
| BYTE: { | ||
| symbol: 'B', | ||
| multiplier: 1, | ||
| }, | ||
| KILO: { | ||
| symbol: 'KiB', | ||
| multiplier: 1024, | ||
| }, | ||
| MEGA: { | ||
| symbol: 'MiB', | ||
| multiplier: 1024 * 1024, | ||
| }, | ||
| }; | ||
| function formatFileSize(value) { | ||
| let unit = FILE_SIZE.BYTE; | ||
| if (typeof value !== 'number') { | ||
| return `0${unit.symbol}`; | ||
| } | ||
| if (value < FILE_SIZE.KILO.multiplier) { | ||
| unit = FILE_SIZE.BYTE; | ||
| } | ||
| else if (value < FILE_SIZE.MEGA.multiplier) { | ||
| unit = FILE_SIZE.KILO; | ||
| } | ||
| else { | ||
| unit = FILE_SIZE.MEGA; | ||
| } | ||
| return `${round(value / unit.multiplier, 2)}${unit.symbol}`; | ||
| } | ||
| const PLUGIN_NAME = 'rollupStats'; | ||
| const DEFAULT_FILE_NAME = 'stats.json'; | ||
| function rollupStats(options = {}) { | ||
| return { | ||
| name: PLUGIN_NAME, | ||
| async generateBundle(context, bundle) { | ||
| const resolvedOptions = typeof options === 'function' ? options(context) : options; | ||
| const { fileName, stats: statsOptions, write = rollupStatsWrite } = resolvedOptions || {}; | ||
| const resolvedFileName = fileName || DEFAULT_FILE_NAME; | ||
| const filepath = path.isAbsolute(resolvedFileName) | ||
| ? resolvedFileName | ||
| : path.join(context.dir || process.cwd(), resolvedFileName); | ||
| const stats = extractRollupStats(bundle, statsOptions); | ||
| try { | ||
| const res = await write(filepath, stats); | ||
| const outputSize = Buffer.byteLength(res.content, 'utf-8'); | ||
| this.info(`Stats saved to ${res.filepath} (${formatFileSize(outputSize)})`); | ||
| } | ||
| catch (error) { // eslint-disable-line | ||
| // Log error, but do not throw to allow the compilation to continue | ||
| this.warn(error); | ||
| } | ||
| }, | ||
| }; | ||
| } | ||
| export { rollupStats as default }; | ||
| //# sourceMappingURL=index.mjs.map |
| {"version":3,"file":"index.mjs","sources":["../src/write.ts","../src/utils/round.ts","../src/utils/format-file-size.ts","../src/index.ts"],"sourcesContent":[null,null,null,null],"names":[],"mappings":";;;;;AAaO,eAAe,gBAAgB,CAEpC,QAAgB,EAAE,KAAQ,EAAA;AAC1B,IAAA,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;;AAG9C,IAAA,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IAE3D,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC;IAErC,OAAO;QACL,QAAQ;QACR,OAAO;KACR;AACH;;SC3BgB,KAAK,CAAC,KAAa,EAAE,SAAS,GAAG,CAAC,EAAA;AAChD,IAAA,MAAM,UAAU,GAAG,EAAE,GAAG,SAAS;IACjC,OAAO,IAAI,CAA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AAK,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO;AAClF,YAAA,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,GAAG,gBAAgB,EAAE,GAAG,eAAe,IAAI,EAAE;AAEzF,YAAA,MAAM,gBAAgB,GAAG,QAAQ,IAAI,iBAAiB;AACtD,YAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,gBAAgB;AAC/C,kBAAE;AACF,kBAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,gBAAgB,CAAC;YAE7D,MAAM,KAAK,GAAG,kBAAkB,CAAC,MAAM,EAAE,YAAY,CAAC;AAEtD,YAAA,IAAI;gBACF,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC;AACxC,gBAAA,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC;AAE1D,gBAAA,IAAI,CAAC,IAAI,CAAC,CAAA,eAAA,EAAkB,GAAG,CAAC,QAAQ,CAAA,EAAA,EAAK,cAAc,CAAC,UAAU,CAAC,CAAA,CAAA,CAAG,CAAC;YAC7E;AAAE,YAAA,OAAO,KAAU,EAAE;;AAEnB,gBAAA,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;YAClB;QACF,CAAC;KACe;AACpB;;;;"} |
| type ExcludeFilepathParam = string | RegExp | ((filepath: string) => boolean); | ||
| export type ExcludeFilepathPatterns = ExcludeFilepathParam | Array<ExcludeFilepathParam>; | ||
| /** | ||
| * Check if filepath should be excluded based on patterns | ||
| */ | ||
| export declare function checkExcludeFilepath(filepath: string, patterns?: ExcludeFilepathPatterns): boolean; | ||
| export {}; |
| export declare function formatFileSize(value?: number | null): string; |
| export declare function omit<D extends object, K extends keyof D = keyof D>(data: D, keys: K[]): Omit<D, K>; |
| export declare function round(value: number, precision?: number): number; |
| export type RollupStatsWriteResponse = { | ||
| filepath: string; | ||
| content: string; | ||
| }; | ||
| export type RollupStatsWrite = (filepath: string, stats: Record<string, unknown>) => RollupStatsWriteResponse; | ||
| export declare function rollupStatsWrite<T extends Record<string, unknown> = Record<string, unknown>>(filepath: string, stats: T): Promise<RollupStatsWriteResponse>; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
42693
27.53%15
-6.25%19
5.56%18
-95.79%8
700%1
Infinity%