rollup-plugin-webpack-stats 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # rollup-plugin-webpack-stats
2
2
 
3
- > > **Warning**
4
- > Under active development
3
+ > **Warning**
4
+ Under active development
5
+
6
+ [![](https://img.shields.io/npm/v/rollup-plugin-webpack-stats.svg)](https://www.npmjs.com/package/rollup-plugin-webpack-stats)
7
+ ![](https://img.shields.io/node/v/rollup-plugin-webpack-stats.svg)
5
8
 
6
9
  Generate rollup stats JSON file with a [bundle-stats](https://github.com/relative-ci/bundle-stats/tree/master/packages/cli) webpack [supported sructure](https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts).
7
10
 
@@ -6,6 +6,12 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
6
6
 
7
7
  var path = _interopDefault(require('node:path'));
8
8
 
9
+ var getByteSize = function getByteSize(content) {
10
+ if (typeof content === 'string') {
11
+ return Buffer.from(content).length;
12
+ }
13
+ return (content == null ? void 0 : content.length) || 0;
14
+ };
9
15
  var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
10
16
  var items = Object.values(bundle);
11
17
  var assets = [];
@@ -13,16 +19,15 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
13
19
  var moduleByFileName = {};
14
20
  items.forEach(function (item) {
15
21
  if (item.type === 'chunk') {
16
- var _item$code;
17
22
  assets.push({
18
23
  name: item.fileName,
19
- size: (_item$code = item.code) == null ? void 0 : _item$code.length
24
+ size: getByteSize(item.code)
20
25
  });
21
26
  var chunkId = item.name;
22
27
  chunks.push({
23
28
  id: chunkId,
24
29
  entry: item.isEntry,
25
- initial: false,
30
+ initial: item.isEntry,
26
31
  files: [item.fileName],
27
32
  names: [item.name]
28
33
  });
@@ -41,11 +46,10 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
41
46
  };
42
47
  }
43
48
  });
44
- } else {
45
- var _item$source;
49
+ } else if (item.type === 'asset') {
46
50
  assets.push({
47
51
  name: item.fileName,
48
- size: (_item$source = item.source) == null ? void 0 : _item$source.length
52
+ size: getByteSize(item.source)
49
53
  });
50
54
  }
51
55
  });
@@ -1 +1 @@
1
- {"version":3,"file":"rollup-plugin-webpack-stats.cjs.development.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport { OutputBundle } from 'rollup';\n\n// https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts\nexport type WebpackStatsFilteredAsset = {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredChunk {\n id: number | string;\n entry: boolean;\n initial: boolean;\n files?: Array<string>;\n names?: Array<string>;\n}\n\nexport interface WebpackStatsFilteredModule {\n name: string;\n size?: number;\n chunks: Array<string | number>;\n}\n\nexport interface WebpackStatsFilteredConcatenatedModule {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {\n modules?: Array<WebpackStatsFilteredConcatenatedModule>;\n}\n\nexport interface WebpackStatsFiltered {\n builtAt?: number;\n hash?: string;\n assets?: Array<WebpackStatsFilteredAsset>;\n chunks?: Array<WebpackStatsFilteredChunk>;\n modules?: Array<WebpackStatsFilteredRootModule>;\n}\n\nexport const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {\n const items = Object.values(bundle);\n\n const assets: Array<WebpackStatsFilteredAsset> = [];\n const chunks: Array<WebpackStatsFilteredChunk> = [];\n\n const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};\n\n items.forEach((item) => {\n if (item.type === 'chunk') {\n assets.push({\n name: item.fileName,\n size: item.code?.length,\n });\n\n const chunkId = item.name;\n\n chunks.push({\n id: chunkId,\n entry: item.isEntry,\n initial: false,\n files: [item.fileName],\n names: [item.name]\n });\n\n Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {\n const relativeModulePath = path.relative(process.cwd(), modulePath.replace('\\u0000', ''));\n\n const moduleEntry = moduleByFileName[relativeModulePath];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePath] = {\n name: relativeModulePath,\n size: moduleInfo.originalLength,\n chunks: [chunkId],\n };\n }\n });\n } else {\n assets.push({\n name: item.fileName,\n size: item.source?.length,\n });\n }\n });\n\n const output = {\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n\n return output;\n};\n","import { Plugin } from 'rollup';\n\nimport { bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\nexport const webpackStats = (): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle);\n\n this.emitFile({\n type: 'asset',\n fileName: 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["bundleToWebpackStats","bundle","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","name","fileName","size","code","length","chunkId","id","entry","isEntry","initial","files","names","entries","modules","modulePath","moduleInfo","relativeModulePath","path","relative","process","cwd","replace","moduleEntry","originalLength","source","output","NAME","webpackStats","generateBundle","_","emitFile","JSON","stringify"],"mappings":";;;;;;;;AAwCO,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAoB,CAAIC,MAAoB;EACvD,IAAMC,KAAK,GAAGC,MAAM,CAACC,MAAM,CAACH,MAAM,CAAC;EAEnC,IAAMI,MAAM,GAAqC,EAAE;EACnD,IAAMC,MAAM,GAAqC,EAAE;EAEnD,IAAMC,gBAAgB,GAA+C,EAAE;EAEvEL,KAAK,CAACM,OAAO,CAAC,UAACC,IAAI;IACjB,IAAIA,IAAI,CAACC,IAAI,KAAK,OAAO,EAAE;MAAA;MACzBL,MAAM,CAACM,IAAI,CAAC;QACVC,IAAI,EAAEH,IAAI,CAACI,QAAQ;QACnBC,IAAI,gBAAEL,IAAI,CAACM,IAAI,qBAAT,WAAWC;OAClB,CAAC;MA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,YAAY;EAAA,OAAkB;IACzC3B,IAAI,EAAE0B,IAAI;IACVE,cAAc,0BAACC,CAAC,EAAExC,MAAM;MACtB,IAAMoC,MAAM,GAAGrC,oBAAoB,CAACC,MAAM,CAAC;MAE3C,IAAI,CAACyC,QAAQ,CAAC;QACZhC,IAAI,EAAE,OAAO;QACbG,QAAQ,EAAE,oBAAoB;QAC9BuB,MAAM,EAAEO,IAAI,CAACC,SAAS,CAACP,MAAM;OAC9B,CAAC;;GAEL;AAAA,CAAC;;;;"}
1
+ {"version":3,"file":"rollup-plugin-webpack-stats.cjs.development.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport { OutputBundle } from 'rollup';\n\n// https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts\nexport type WebpackStatsFilteredAsset = {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredChunk {\n id: number | string;\n entry: boolean;\n initial: boolean;\n files?: Array<string>;\n names?: Array<string>;\n}\n\nexport interface WebpackStatsFilteredModule {\n name: string;\n size?: number;\n chunks: Array<string | number>;\n}\n\nexport interface WebpackStatsFilteredConcatenatedModule {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {\n modules?: Array<WebpackStatsFilteredConcatenatedModule>;\n}\n\nexport interface WebpackStatsFiltered {\n builtAt?: number;\n hash?: string;\n assets?: Array<WebpackStatsFilteredAsset>;\n chunks?: Array<WebpackStatsFilteredChunk>;\n modules?: Array<WebpackStatsFilteredRootModule>;\n}\n\nconst getByteSize = (content: string | Buffer): number => {\n if (typeof content === 'string') {\n return Buffer.from(content).length;\n }\n\n return content?.length || 0;\n};\n\nexport const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {\n const items = Object.values(bundle);\n\n const assets: Array<WebpackStatsFilteredAsset> = [];\n const chunks: Array<WebpackStatsFilteredChunk> = [];\n\n const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};\n\n items.forEach((item) => {\n if (item.type === 'chunk') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.code),\n });\n\n const chunkId = item.name;\n\n chunks.push({\n id: chunkId,\n entry: item.isEntry,\n initial: item.isEntry,\n files: [item.fileName],\n names: [item.name]\n });\n\n Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {\n const relativeModulePath = path.relative(process.cwd(), modulePath.replace('\\u0000', ''));\n\n const moduleEntry = moduleByFileName[relativeModulePath];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePath] = {\n name: relativeModulePath,\n size: moduleInfo.originalLength,\n chunks: [chunkId],\n };\n }\n });\n } else if (item.type === 'asset') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.source),\n });\n } else {\n // noop for unknown types\n }\n });\n\n const output = {\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n\n return output;\n};\n","import { Plugin } from 'rollup';\n\nimport { bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\nexport const webpackStats = (): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle);\n\n this.emitFile({\n type: 'asset',\n fileName: 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["getByteSize","content","Buffer","from","length","bundleToWebpackStats","bundle","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","name","fileName","size","code","chunkId","id","entry","isEntry","initial","files","names","entries","modules","modulePath","moduleInfo","relativeModulePath","path","relative","process","cwd","replace","moduleEntry","originalLength","source","output","NAME","webpackStats","generateBundle","_","emitFile","JSON","stringify"],"mappings":";;;;;;;;AAwCA,IAAMA,WAAW,GAAG,SAAdA,WAAW,CAAIC,OAAwB;EAC3C,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;IAC/B,OAAOC,MAAM,CAACC,IAAI,CAACF,OAAO,CAAC,CAACG,MAAM;;EAGpC,OAAO,CAAAH,O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;YACrCf,IAAI,EAAEe,kBAAkB;YACxBb,IAAI,EAAEY,UAAU,CAACQ,cAAc;YAC/B5B,MAAM,EAAE,CAACU,OAAO;WACjB;;OAEJ,CAAC;KACH,MAAM,IAAIP,IAAI,CAACC,IAAI,KAAK,OAAO,EAAE;MAChCL,MAAM,CAACM,IAAI,CAAC;QACVC,IAAI,EAAEH,IAAI,CAACI,QAAQ;QACnBC,IAAI,EAAEnB,WAAW,CAACc,IAAI,CAAC0B,MAAM;OAC9B,CAAC;;GAIL,CAAC;EAEF,IAAMC,MAAM,GAAG;IACb/B,MAAM,EAANA,MAAM;IACNC,MAAM,EAANA,MAAM;IACNkB,OAAO,EAAErB,MAAM,CAACC,MAAM,CAACG,gBAAgB;GACxC;EAED,OAAO6B,MAAM;AACf,CAAC;;ACrGD,IAAMC,IAAI,GAAG,cAAc;AAE3B,IAAaC,YAAY,GAAG,SAAfA,YAAY;EAAA,OAAkB;IACzC1B,IAAI,EAAEyB,IAAI;IACVE,cAAc,0BAACC,CAAC,EAAEvC,MAAM;MACtB,IAAMmC,MAAM,GAAGpC,oBAAoB,CAACC,MAAM,CAAC;MAE3C,IAAI,CAACwC,QAAQ,CAAC;QACZ/B,IAAI,EAAE,OAAO;QACbG,QAAQ,EAAE,oBAAoB;QAC9BsB,MAAM,EAAEO,IAAI,CAACC,SAAS,CAACP,MAAM;OAC9B,CAAC;;GAEL;AAAA,CAAC;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("node:path"))&&"object"==typeof e&&"default"in e?e.default:e;exports.webpackStats=function(){return{name:"webpackStats",generateBundle:function(e,n){var s=function(e){var n=Object.values(e),s=[],a=[],i={};return n.forEach((function(e){if("chunk"===e.type){var n;s.push({name:e.fileName,size:null==(n=e.code)?void 0:n.length});var r=e.name;a.push({id:r,entry:e.isEntry,initial:!1,files:[e.fileName],names:[e.name]}),Object.entries(e.modules).forEach((function(e){var n=e[0],s=e[1],a=t.relative(process.cwd(),n.replace("\0","")),u=i[a];u?u.chunks.push(r):i[a]={name:a,size:s.originalLength,chunks:[r]}}))}else{var u;s.push({name:e.fileName,size:null==(u=e.source)?void 0:u.length})}})),{assets:s,chunks:a,modules:Object.values(i)}}(n);this.emitFile({type:"asset",fileName:"webpack-stats.json",source:JSON.stringify(s)})}}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("node:path"))&&"object"==typeof e&&"default"in e?e.default:e,n=function(e){return"string"==typeof e?Buffer.from(e).length:(null==e?void 0:e.length)||0};exports.webpackStats=function(){return{name:"webpackStats",generateBundle:function(e,s){var a=function(e){var s=Object.values(e),a=[],i=[],r={};return s.forEach((function(e){if("chunk"===e.type){a.push({name:e.fileName,size:n(e.code)});var s=e.name;i.push({id:s,entry:e.isEntry,initial:e.isEntry,files:[e.fileName],names:[e.name]}),Object.entries(e.modules).forEach((function(e){var n=e[0],a=e[1],i=t.relative(process.cwd(),n.replace("\0","")),u=r[i];u?u.chunks.push(s):r[i]={name:i,size:a.originalLength,chunks:[s]}}))}else"asset"===e.type&&a.push({name:e.fileName,size:n(e.source)})})),{assets:a,chunks:i,modules:Object.values(r)}}(s);this.emitFile({type:"asset",fileName:"webpack-stats.json",source:JSON.stringify(a)})}}};
2
2
  //# sourceMappingURL=rollup-plugin-webpack-stats.cjs.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rollup-plugin-webpack-stats.cjs.production.min.js","sources":["../src/index.ts","../src/transform.ts"],"sourcesContent":["import { Plugin } from 'rollup';\n\nimport { bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\nexport const webpackStats = (): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle);\n\n this.emitFile({\n type: 'asset',\n fileName: 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n","import path from 'node:path';\nimport { OutputBundle } from 'rollup';\n\n// https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts\nexport type WebpackStatsFilteredAsset = {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredChunk {\n id: number | string;\n entry: boolean;\n initial: boolean;\n files?: Array<string>;\n names?: Array<string>;\n}\n\nexport interface WebpackStatsFilteredModule {\n name: string;\n size?: number;\n chunks: Array<string | number>;\n}\n\nexport interface WebpackStatsFilteredConcatenatedModule {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {\n modules?: Array<WebpackStatsFilteredConcatenatedModule>;\n}\n\nexport interface WebpackStatsFiltered {\n builtAt?: number;\n hash?: string;\n assets?: Array<WebpackStatsFilteredAsset>;\n chunks?: Array<WebpackStatsFilteredChunk>;\n modules?: Array<WebpackStatsFilteredRootModule>;\n}\n\nexport const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {\n const items = Object.values(bundle);\n\n const assets: Array<WebpackStatsFilteredAsset> = [];\n const chunks: Array<WebpackStatsFilteredChunk> = [];\n\n const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};\n\n items.forEach((item) => {\n if (item.type === 'chunk') {\n assets.push({\n name: item.fileName,\n size: item.code?.length,\n });\n\n const chunkId = item.name;\n\n chunks.push({\n id: chunkId,\n entry: item.isEntry,\n initial: false,\n files: [item.fileName],\n names: [item.name]\n });\n\n Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {\n const relativeModulePath = path.relative(process.cwd(), modulePath.replace('\\u0000', ''));\n\n const moduleEntry = moduleByFileName[relativeModulePath];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePath] = {\n name: relativeModulePath,\n size: moduleInfo.originalLength,\n chunks: [chunkId],\n };\n }\n });\n } else {\n assets.push({\n name: item.fileName,\n size: item.source?.length,\n });\n }\n });\n\n const output = {\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n\n return output;\n};\n"],"names":["name","generateBundle","_","bundle","output","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","fileName","size","code","_item$code","length","chunkId","id","entry","isEntry","initial","files","names","entries","modules","modulePath","moduleInfo","relativeModulePath","path","relative","process","cwd","replace","moduleEntry","originalLength","source","_item$source","bundleToWebpackStats","this","emitFile","JSON","stringify"],"mappings":"yKAM4B,WAAH,MAAkB,CACzCA,KAHW,eAIXC,wBAAeC,EAAGC,GAChB,IAAMC,EC+B0B,SAACD,GACnC,IAAME,EAAQC,OAAOC,OAAOJ,GAEtBK,EAA2C,GAC3CC,EAA2C,GAE3CC,EAA+D,GAgDrE,OA9CAL,EAAMM,SAAQ,SAACC,GACb,GAAkB,UAAdA,EAAKC,KAAkB,CAAA,MACzBL,EAAOM,KAAK,CACVd,KAAMY,EAAKG,SACXC,cAAMJ,EAAKK,aAALC,EAAWC,SAGnB,IAAMC,EAAUR,EAAKZ,KAErBS,EAAOK,KAAK,CACVO,GAAID,EACJE,MAAOV,EAAKW,QACZC,SAAS,EACTC,MAAO,CAACb,EAAKG,UACbW,MAAO,CAACd,EAAKZ,QAGfM,OAAOqB,QAAQf,EAAKgB,SAASjB,SAAQ,gBAAEkB,OAAYC,OAC3CC,EAAqBC,EAAKC,SAASC,QAAQC,MAAON,EAAWO,QAAQ,KAAU,KAE/EC,EAAc3B,EAAiBqB,GAEjCM,EACFA,EAAY5B,OAAOK,KAAKM,GAExBV,EAAiBqB,GAAsB,CACrC/B,KAAM+B,EACNf,KAAMc,EAAWQ,eACjB7B,OAAQ,CAACW,WAIV,CAAA,MACLZ,EAAOM,KAAK,CACVd,KAAMY,EAAKG,SACXC,cAAMJ,EAAK2B,eAALC,EAAarB,aAKV,CACbX,OAAAA,EACAC,OAAAA,EACAmB,QAAStB,OAAOC,OAAOG,IDlFR+B,CAAqBtC,GAEpCuC,KAAKC,SAAS,CACZ9B,KAAM,QACNE,SAAU,qBACVwB,OAAQK,KAAKC,UAAUzC"}
1
+ {"version":3,"file":"rollup-plugin-webpack-stats.cjs.production.min.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport { OutputBundle } from 'rollup';\n\n// https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts\nexport type WebpackStatsFilteredAsset = {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredChunk {\n id: number | string;\n entry: boolean;\n initial: boolean;\n files?: Array<string>;\n names?: Array<string>;\n}\n\nexport interface WebpackStatsFilteredModule {\n name: string;\n size?: number;\n chunks: Array<string | number>;\n}\n\nexport interface WebpackStatsFilteredConcatenatedModule {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {\n modules?: Array<WebpackStatsFilteredConcatenatedModule>;\n}\n\nexport interface WebpackStatsFiltered {\n builtAt?: number;\n hash?: string;\n assets?: Array<WebpackStatsFilteredAsset>;\n chunks?: Array<WebpackStatsFilteredChunk>;\n modules?: Array<WebpackStatsFilteredRootModule>;\n}\n\nconst getByteSize = (content: string | Buffer): number => {\n if (typeof content === 'string') {\n return Buffer.from(content).length;\n }\n\n return content?.length || 0;\n};\n\nexport const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {\n const items = Object.values(bundle);\n\n const assets: Array<WebpackStatsFilteredAsset> = [];\n const chunks: Array<WebpackStatsFilteredChunk> = [];\n\n const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};\n\n items.forEach((item) => {\n if (item.type === 'chunk') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.code),\n });\n\n const chunkId = item.name;\n\n chunks.push({\n id: chunkId,\n entry: item.isEntry,\n initial: item.isEntry,\n files: [item.fileName],\n names: [item.name]\n });\n\n Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {\n const relativeModulePath = path.relative(process.cwd(), modulePath.replace('\\u0000', ''));\n\n const moduleEntry = moduleByFileName[relativeModulePath];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePath] = {\n name: relativeModulePath,\n size: moduleInfo.originalLength,\n chunks: [chunkId],\n };\n }\n });\n } else if (item.type === 'asset') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.source),\n });\n } else {\n // noop for unknown types\n }\n });\n\n const output = {\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n\n return output;\n};\n","import { Plugin } from 'rollup';\n\nimport { bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\nexport const webpackStats = (): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle);\n\n this.emitFile({\n type: 'asset',\n fileName: 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["getByteSize","content","Buffer","from","length","name","generateBundle","_","bundle","output","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","fileName","size","code","chunkId","id","entry","isEntry","initial","files","names","entries","modules","modulePath","moduleInfo","relativeModulePath","path","relative","process","cwd","replace","moduleEntry","originalLength","source","bundleToWebpackStats","this","emitFile","JSON","stringify"],"mappings":"oJAwCMA,EAAc,SAACC,GACnB,MAAuB,iBAAZA,EACFC,OAAOC,KAAKF,GAASG,cAGvBH,SAAAA,EAASG,SAAU,wBCvCA,WAAH,MAAkB,CACzCC,KAHW,eAIXC,wBAAeC,EAAGC,GAChB,IAAMC,EDuC0B,SAACD,GACnC,IAAME,EAAQC,OAAOC,OAAOJ,GAEtBK,EAA2C,GAC3CC,EAA2C,GAE3CC,EAA+D,GAkDrE,OAhDAL,EAAMM,SAAQ,SAACC,GACb,GAAkB,UAAdA,EAAKC,KAAkB,CACzBL,EAAOM,KAAK,CACVd,KAAMY,EAAKG,SACXC,KAAMrB,EAAYiB,EAAKK,QAGzB,IAAMC,EAAUN,EAAKZ,KAErBS,EAAOK,KAAK,CACVK,GAAID,EACJE,MAAOR,EAAKS,QACZC,QAASV,EAAKS,QACdE,MAAO,CAACX,EAAKG,UACbS,MAAO,CAACZ,EAAKZ,QAGfM,OAAOmB,QAAQb,EAAKc,SAASf,SAAQ,gBAAEgB,OAAYC,OAC3CC,EAAqBC,EAAKC,SAASC,QAAQC,MAAON,EAAWO,QAAQ,KAAU,KAE/EC,EAAczB,EAAiBmB,GAEjCM,EACFA,EAAY1B,OAAOK,KAAKI,GAExBR,EAAiBmB,GAAsB,CACrC7B,KAAM6B,EACNb,KAAMY,EAAWQ,eACjB3B,OAAQ,CAACS,WAIQ,UAAdN,EAAKC,MACdL,EAAOM,KAAK,CACVd,KAAMY,EAAKG,SACXC,KAAMrB,EAAYiB,EAAKyB,aAOd,CACb7B,OAAAA,EACAC,OAAAA,EACAiB,QAASpB,OAAOC,OAAOG,IC5FR4B,CAAqBnC,GAEpCoC,KAAKC,SAAS,CACZ3B,KAAM,QACNE,SAAU,qBACVsB,OAAQI,KAAKC,UAAUtC"}
@@ -1,5 +1,11 @@
1
1
  import path from 'node:path';
2
2
 
3
+ var getByteSize = function getByteSize(content) {
4
+ if (typeof content === 'string') {
5
+ return Buffer.from(content).length;
6
+ }
7
+ return (content == null ? void 0 : content.length) || 0;
8
+ };
3
9
  var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
4
10
  var items = Object.values(bundle);
5
11
  var assets = [];
@@ -7,16 +13,15 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
7
13
  var moduleByFileName = {};
8
14
  items.forEach(function (item) {
9
15
  if (item.type === 'chunk') {
10
- var _item$code;
11
16
  assets.push({
12
17
  name: item.fileName,
13
- size: (_item$code = item.code) == null ? void 0 : _item$code.length
18
+ size: getByteSize(item.code)
14
19
  });
15
20
  var chunkId = item.name;
16
21
  chunks.push({
17
22
  id: chunkId,
18
23
  entry: item.isEntry,
19
- initial: false,
24
+ initial: item.isEntry,
20
25
  files: [item.fileName],
21
26
  names: [item.name]
22
27
  });
@@ -35,11 +40,10 @@ var bundleToWebpackStats = function bundleToWebpackStats(bundle) {
35
40
  };
36
41
  }
37
42
  });
38
- } else {
39
- var _item$source;
43
+ } else if (item.type === 'asset') {
40
44
  assets.push({
41
45
  name: item.fileName,
42
- size: (_item$source = item.source) == null ? void 0 : _item$source.length
46
+ size: getByteSize(item.source)
43
47
  });
44
48
  }
45
49
  });
@@ -1 +1 @@
1
- {"version":3,"file":"rollup-plugin-webpack-stats.esm.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport { OutputBundle } from 'rollup';\n\n// https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts\nexport type WebpackStatsFilteredAsset = {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredChunk {\n id: number | string;\n entry: boolean;\n initial: boolean;\n files?: Array<string>;\n names?: Array<string>;\n}\n\nexport interface WebpackStatsFilteredModule {\n name: string;\n size?: number;\n chunks: Array<string | number>;\n}\n\nexport interface WebpackStatsFilteredConcatenatedModule {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {\n modules?: Array<WebpackStatsFilteredConcatenatedModule>;\n}\n\nexport interface WebpackStatsFiltered {\n builtAt?: number;\n hash?: string;\n assets?: Array<WebpackStatsFilteredAsset>;\n chunks?: Array<WebpackStatsFilteredChunk>;\n modules?: Array<WebpackStatsFilteredRootModule>;\n}\n\nexport const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {\n const items = Object.values(bundle);\n\n const assets: Array<WebpackStatsFilteredAsset> = [];\n const chunks: Array<WebpackStatsFilteredChunk> = [];\n\n const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};\n\n items.forEach((item) => {\n if (item.type === 'chunk') {\n assets.push({\n name: item.fileName,\n size: item.code?.length,\n });\n\n const chunkId = item.name;\n\n chunks.push({\n id: chunkId,\n entry: item.isEntry,\n initial: false,\n files: [item.fileName],\n names: [item.name]\n });\n\n Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {\n const relativeModulePath = path.relative(process.cwd(), modulePath.replace('\\u0000', ''));\n\n const moduleEntry = moduleByFileName[relativeModulePath];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePath] = {\n name: relativeModulePath,\n size: moduleInfo.originalLength,\n chunks: [chunkId],\n };\n }\n });\n } else {\n assets.push({\n name: item.fileName,\n size: item.source?.length,\n });\n }\n });\n\n const output = {\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n\n return output;\n};\n","import { Plugin } from 'rollup';\n\nimport { bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\nexport const webpackStats = (): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle);\n\n this.emitFile({\n type: 'asset',\n fileName: 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["bundleToWebpackStats","bundle","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","name","fileName","size","code","length","chunkId","id","entry","isEntry","initial","files","names","entries","modules","modulePath","moduleInfo","relativeModulePath","path","relative","process","cwd","replace","moduleEntry","originalLength","source","output","NAME","webpackStats","generateBundle","_","emitFile","JSON","stringify"],"mappings":";;AAwCO,IAAMA,oBAAoB,GAAG,SAAvBA,oBAAoB,CAAIC,MAAoB;EACvD,IAAMC,KAAK,GAAGC,MAAM,CAACC,MAAM,CAACH,MAAM,CAAC;EAEnC,IAAMI,MAAM,GAAqC,EAAE;EACnD,IAAMC,MAAM,GAAqC,EAAE;EAEnD,IAAMC,gBAAgB,GAA+C,EAAE;EAEvEL,KAAK,CAACM,OAAO,CAAC,UAACC,IAAI;IACjB,IAAIA,IAAI,CAACC,IAAI,KAAK,OAAO,EAAE;MAAA;MACzBL,MAAM,CAACM,IAAI,CAAC;QACVC,IAAI,EAAEH,IAAI,CAACI,QAAQ;QACnBC,IAAI,gBAAEL,IAAI,CAACM,IAAI,qBAAT,WAAWC;OAClB,CAAC;MAEF,IAAMC,OAAO,GAAGR,IAAI,CAACG,IAAI;MAEzBN,MAAM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cAAc,0BAACC,CAAC,EAAExC,MAAM;MACtB,IAAMoC,MAAM,GAAGrC,oBAAoB,CAACC,MAAM,CAAC;MAE3C,IAAI,CAACyC,QAAQ,CAAC;QACZhC,IAAI,EAAE,OAAO;QACbG,QAAQ,EAAE,oBAAoB;QAC9BuB,MAAM,EAAEO,IAAI,CAACC,SAAS,CAACP,MAAM;OAC9B,CAAC;;GAEL;AAAA,CAAC;;;;"}
1
+ {"version":3,"file":"rollup-plugin-webpack-stats.esm.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from 'node:path';\nimport { OutputBundle } from 'rollup';\n\n// https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts\nexport type WebpackStatsFilteredAsset = {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredChunk {\n id: number | string;\n entry: boolean;\n initial: boolean;\n files?: Array<string>;\n names?: Array<string>;\n}\n\nexport interface WebpackStatsFilteredModule {\n name: string;\n size?: number;\n chunks: Array<string | number>;\n}\n\nexport interface WebpackStatsFilteredConcatenatedModule {\n name: string;\n size?: number;\n}\n\nexport interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {\n modules?: Array<WebpackStatsFilteredConcatenatedModule>;\n}\n\nexport interface WebpackStatsFiltered {\n builtAt?: number;\n hash?: string;\n assets?: Array<WebpackStatsFilteredAsset>;\n chunks?: Array<WebpackStatsFilteredChunk>;\n modules?: Array<WebpackStatsFilteredRootModule>;\n}\n\nconst getByteSize = (content: string | Buffer): number => {\n if (typeof content === 'string') {\n return Buffer.from(content).length;\n }\n\n return content?.length || 0;\n};\n\nexport const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {\n const items = Object.values(bundle);\n\n const assets: Array<WebpackStatsFilteredAsset> = [];\n const chunks: Array<WebpackStatsFilteredChunk> = [];\n\n const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};\n\n items.forEach((item) => {\n if (item.type === 'chunk') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.code),\n });\n\n const chunkId = item.name;\n\n chunks.push({\n id: chunkId,\n entry: item.isEntry,\n initial: item.isEntry,\n files: [item.fileName],\n names: [item.name]\n });\n\n Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {\n const relativeModulePath = path.relative(process.cwd(), modulePath.replace('\\u0000', ''));\n\n const moduleEntry = moduleByFileName[relativeModulePath];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePath] = {\n name: relativeModulePath,\n size: moduleInfo.originalLength,\n chunks: [chunkId],\n };\n }\n });\n } else if (item.type === 'asset') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.source),\n });\n } else {\n // noop for unknown types\n }\n });\n\n const output = {\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n\n return output;\n};\n","import { Plugin } from 'rollup';\n\nimport { bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\nexport const webpackStats = (): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle);\n\n this.emitFile({\n type: 'asset',\n fileName: 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["getByteSize","content","Buffer","from","length","bundleToWebpackStats","bundle","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","name","fileName","size","code","chunkId","id","entry","isEntry","initial","files","names","entries","modules","modulePath","moduleInfo","relativeModulePath","path","relative","process","cwd","replace","moduleEntry","originalLength","source","output","NAME","webpackStats","generateBundle","_","emitFile","JSON","stringify"],"mappings":";;AAwCA,IAAMA,WAAW,GAAG,SAAdA,WAAW,CAAIC,OAAwB;EAC3C,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;IAC/B,OAAOC,MAAM,CAACC,IAAI,CAACF,OAAO,CAAC,CAACG,MAAM;;EAGpC,OAAO,CAAAH,OAAO,oBAAPA,OAAO,CAAEG,MAAM,KAAI,CAAC;AAC7B,CAAC;AAEM,IA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Ac;YAC/B5B,MAAM,EAAE,CAACU,OAAO;WACjB;;OAEJ,CAAC;KACH,MAAM,IAAIP,IAAI,CAACC,IAAI,KAAK,OAAO,EAAE;MAChCL,MAAM,CAACM,IAAI,CAAC;QACVC,IAAI,EAAEH,IAAI,CAACI,QAAQ;QACnBC,IAAI,EAAEnB,WAAW,CAACc,IAAI,CAAC0B,MAAM;OAC9B,CAAC;;GAIL,CAAC;EAEF,IAAMC,MAAM,GAAG;IACb/B,MAAM,EAANA,MAAM;IACNC,MAAM,EAANA,MAAM;IACNkB,OAAO,EAAErB,MAAM,CAACC,MAAM,CAACG,gBAAgB;GACxC;EAED,OAAO6B,MAAM;AACf,CAAC;;ACrGD,IAAMC,IAAI,GAAG,cAAc;AAE3B,IAAaC,YAAY,GAAG,SAAfA,YAAY;EAAA,OAAkB;IACzC1B,IAAI,EAAEyB,IAAI;IACVE,cAAc,0BAACC,CAAC,EAAEvC,MAAM;MACtB,IAAMmC,MAAM,GAAGpC,oBAAoB,CAACC,MAAM,CAAC;MAE3C,IAAI,CAACwC,QAAQ,CAAC;QACZ/B,IAAI,EAAE,OAAO;QACbG,QAAQ,EAAE,oBAAoB;QAC9BsB,MAAM,EAAEO,IAAI,CAACC,SAAS,CAACP,MAAM;OAC9B,CAAC;;GAEL;AAAA,CAAC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-webpack-stats",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
package/src/transform.ts CHANGED
@@ -38,6 +38,14 @@ export interface WebpackStatsFiltered {
38
38
  modules?: Array<WebpackStatsFilteredRootModule>;
39
39
  }
40
40
 
41
+ const getByteSize = (content: string | Buffer): number => {
42
+ if (typeof content === 'string') {
43
+ return Buffer.from(content).length;
44
+ }
45
+
46
+ return content?.length || 0;
47
+ };
48
+
41
49
  export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered => {
42
50
  const items = Object.values(bundle);
43
51
 
@@ -50,7 +58,7 @@ export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered
50
58
  if (item.type === 'chunk') {
51
59
  assets.push({
52
60
  name: item.fileName,
53
- size: item.code?.length,
61
+ size: getByteSize(item.code),
54
62
  });
55
63
 
56
64
  const chunkId = item.name;
@@ -58,7 +66,7 @@ export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered
58
66
  chunks.push({
59
67
  id: chunkId,
60
68
  entry: item.isEntry,
61
- initial: false,
69
+ initial: item.isEntry,
62
70
  files: [item.fileName],
63
71
  names: [item.name]
64
72
  });
@@ -78,11 +86,13 @@ export const bundleToWebpackStats = (bundle: OutputBundle): WebpackStatsFiltered
78
86
  };
79
87
  }
80
88
  });
81
- } else {
89
+ } else if (item.type === 'asset') {
82
90
  assets.push({
83
91
  name: item.fileName,
84
- size: item.source?.length,
92
+ size: getByteSize(item.source),
85
93
  });
94
+ } else {
95
+ // noop for unknown types
86
96
  }
87
97
  });
88
98