rollup-plugin-webpack-stats 0.1.0 → 0.2.1-beta.1

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.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { Plugin } from 'rollup';
2
- import { BundleTransformOptions } from './transform';
3
- interface WebpackStatsOptions extends BundleTransformOptions {
4
- /**
5
- * JSON file output fileName
6
- * default: webpack-stats.json
7
- */
8
- fileName?: string;
9
- }
10
- export declare const webpackStats: (options?: WebpackStatsOptions) => Plugin;
11
- export {};
1
+ import { Plugin } from 'rollup';
2
+ import { BundleTransformOptions } from './transform';
3
+ export { bundleToWebpackStats } from './transform';
4
+ interface WebpackStatsOptions extends BundleTransformOptions {
5
+ /**
6
+ * JSON file output fileName
7
+ * default: webpack-stats.json
8
+ */
9
+ fileName?: string;
10
+ }
11
+ export declare const webpackStats: (options?: WebpackStatsOptions) => Plugin;
package/dist/index.js CHANGED
@@ -1,8 +1,88 @@
1
+ 'use strict';
1
2
 
2
- 'use strict'
3
+ var path = require('path');
3
4
 
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./rollup-plugin-webpack-stats.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./rollup-plugin-webpack-stats.cjs.development.js')
8
- }
5
+ const getByteSize = (content) => {
6
+ if (typeof content === 'string') {
7
+ return Buffer.from(content).length;
8
+ }
9
+ return content?.length || 0;
10
+ };
11
+ const bundleToWebpackStats = (bundle, customOptions) => {
12
+ const options = {
13
+ moduleOriginalSize: false,
14
+ ...customOptions,
15
+ };
16
+ const items = Object.values(bundle);
17
+ const assets = [];
18
+ const chunks = [];
19
+ const moduleByFileName = {};
20
+ items.forEach(item => {
21
+ if (item.type === 'chunk') {
22
+ assets.push({
23
+ name: item.fileName,
24
+ size: getByteSize(item.code),
25
+ });
26
+ const chunkId = item.name;
27
+ chunks.push({
28
+ id: chunkId,
29
+ entry: item.isEntry,
30
+ initial: !item.isDynamicEntry,
31
+ files: [item.fileName],
32
+ names: [item.name],
33
+ });
34
+ Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {
35
+ // Remove unexpected rollup null prefix
36
+ const normalizedModulePath = modulePath.replace('\u0000', '');
37
+ const relativeModulePath = path.relative(process.cwd(), normalizedModulePath);
38
+ // Match webpack output - add current directory prefix for child modules
39
+ const relativeModulePathWithPrefix = relativeModulePath.match(/^\.\./)
40
+ ? relativeModulePath
41
+ : `.${path.sep}${relativeModulePath}`;
42
+ const moduleEntry = moduleByFileName[relativeModulePathWithPrefix];
43
+ if (moduleEntry) {
44
+ moduleEntry.chunks.push(chunkId);
45
+ }
46
+ else {
47
+ moduleByFileName[relativeModulePathWithPrefix] = {
48
+ name: relativeModulePathWithPrefix,
49
+ size: options.moduleOriginalSize
50
+ ? moduleInfo.originalLength
51
+ : moduleInfo.renderedLength,
52
+ chunks: [chunkId],
53
+ };
54
+ }
55
+ });
56
+ }
57
+ else if (item.type === 'asset') {
58
+ assets.push({
59
+ name: item.fileName,
60
+ size: getByteSize(item.source.toString()),
61
+ });
62
+ }
63
+ else ;
64
+ });
65
+ return {
66
+ builtAt: Date.now(),
67
+ assets,
68
+ chunks,
69
+ modules: Object.values(moduleByFileName),
70
+ };
71
+ };
72
+
73
+ const NAME = 'webpackStats';
74
+ const webpackStats = (options = {}) => ({
75
+ name: NAME,
76
+ generateBundle(_, bundle) {
77
+ const output = bundleToWebpackStats(bundle, options);
78
+ this.emitFile({
79
+ type: 'asset',
80
+ fileName: options?.fileName || 'webpack-stats.json',
81
+ source: JSON.stringify(output),
82
+ });
83
+ },
84
+ });
85
+
86
+ exports.bundleToWebpackStats = bundleToWebpackStats;
87
+ exports.webpackStats = webpackStats;
88
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from 'path';\nconst getByteSize = (content) => {\n if (typeof content === 'string') {\n return Buffer.from(content).length;\n }\n return content?.length || 0;\n};\nexport const bundleToWebpackStats = (bundle, customOptions) => {\n const options = {\n moduleOriginalSize: false,\n ...customOptions,\n };\n const items = Object.values(bundle);\n const assets = [];\n const chunks = [];\n const moduleByFileName = {};\n items.forEach(item => {\n if (item.type === 'chunk') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.code),\n });\n const chunkId = item.name;\n chunks.push({\n id: chunkId,\n entry: item.isEntry,\n initial: !item.isDynamicEntry,\n files: [item.fileName],\n names: [item.name],\n });\n Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {\n // Remove unexpected rollup null prefix\n const normalizedModulePath = modulePath.replace('\\u0000', '');\n const relativeModulePath = path.relative(process.cwd(), normalizedModulePath);\n // Match webpack output - add current directory prefix for child modules\n const relativeModulePathWithPrefix = relativeModulePath.match(/^\\.\\./)\n ? relativeModulePath\n : `.${path.sep}${relativeModulePath}`;\n const moduleEntry = moduleByFileName[relativeModulePathWithPrefix];\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n }\n else {\n moduleByFileName[relativeModulePathWithPrefix] = {\n name: relativeModulePathWithPrefix,\n size: options.moduleOriginalSize\n ? moduleInfo.originalLength\n : moduleInfo.renderedLength,\n chunks: [chunkId],\n };\n }\n });\n }\n else if (item.type === 'asset') {\n assets.push({\n name: item.fileName,\n size: getByteSize(item.source.toString()),\n });\n }\n else {\n // noop for unknown types\n }\n });\n return {\n builtAt: Date.now(),\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n};\n//# sourceMappingURL=transform.js.map","import { bundleToWebpackStats } from './transform';\nexport { bundleToWebpackStats } from './transform';\nconst NAME = 'webpackStats';\nexport const webpackStats = (options = {}) => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle, options);\n this.emitFile({\n type: 'asset',\n fileName: options?.fileName || 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;AACA,MAAM,WAAW,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,CAAC;AACzD,aAAa,CAAC,CAAC;AACf,SAAS;AACT,aAAa,CAEJ;AACT,KAAK,CAAC,CAAC;AACP,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;AAC3B,QAAQ,MAAM;AACd,QAAQ,MAAM;AACd,QAAQ,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;AAChD,KAAK,CAAC;AACN;;ACnEA,MAAM,IAAI,GAAG,cAAc,CAAC;AAChB,MAAC,YAAY,GAAG,CAAC,OAAO,GAAG,EAAE,MAAM;AAC/C,IAAI,IAAI,EAAE,IAAI;AACd,IAAI,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE;AAC9B,QAAQ,MAAM,MAAM,GAAG,oBAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC7D,QAAQ,IAAI,CAAC,QAAQ,CAAC;AACtB,YAAY,IAAI,EAAE,OAAO;AACzB,YAAY,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,oBAAoB;AAC/D,YAAY,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;AAC1C,SAAS,CAAC,CAAC;AACX,KAAK;AACL,CAAC;;;;;"}
@@ -1,39 +1,39 @@
1
- import { OutputBundle } from 'rollup';
2
- export declare type WebpackStatsFilteredAsset = {
3
- name: string;
4
- size?: number;
5
- };
6
- export interface WebpackStatsFilteredChunk {
7
- id: number | string;
8
- entry: boolean;
9
- initial: boolean;
10
- files?: Array<string>;
11
- names?: Array<string>;
12
- }
13
- export interface WebpackStatsFilteredModule {
14
- name: string;
15
- size?: number;
16
- chunks: Array<string | number>;
17
- }
18
- export interface WebpackStatsFilteredConcatenatedModule {
19
- name: string;
20
- size?: number;
21
- }
22
- export interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {
23
- modules?: Array<WebpackStatsFilteredConcatenatedModule>;
24
- }
25
- export interface WebpackStatsFiltered {
26
- builtAt?: number;
27
- hash?: string;
28
- assets?: Array<WebpackStatsFilteredAsset>;
29
- chunks?: Array<WebpackStatsFilteredChunk>;
30
- modules?: Array<WebpackStatsFilteredRootModule>;
31
- }
32
- export declare type BundleTransformOptions = {
33
- /**
34
- * Extract module original size or rendered size
35
- * default: false
36
- */
37
- moduleOriginalSize?: boolean;
38
- };
39
- export declare const bundleToWebpackStats: (bundle: OutputBundle, customOptions?: BundleTransformOptions | undefined) => WebpackStatsFiltered;
1
+ import { OutputBundle } from 'rollup';
2
+ export type WebpackStatsFilteredAsset = {
3
+ name: string;
4
+ size?: number;
5
+ };
6
+ export interface WebpackStatsFilteredChunk {
7
+ id: number | string;
8
+ entry: boolean;
9
+ initial: boolean;
10
+ files?: Array<string>;
11
+ names?: Array<string>;
12
+ }
13
+ export interface WebpackStatsFilteredModule {
14
+ name: string;
15
+ size?: number;
16
+ chunks: Array<string | number>;
17
+ }
18
+ export interface WebpackStatsFilteredConcatenatedModule {
19
+ name: string;
20
+ size?: number;
21
+ }
22
+ export interface WebpackStatsFilteredRootModule extends WebpackStatsFilteredModule {
23
+ modules?: Array<WebpackStatsFilteredConcatenatedModule>;
24
+ }
25
+ export interface WebpackStatsFiltered {
26
+ builtAt?: number;
27
+ hash?: string;
28
+ assets?: Array<WebpackStatsFilteredAsset>;
29
+ chunks?: Array<WebpackStatsFilteredChunk>;
30
+ modules?: Array<WebpackStatsFilteredRootModule>;
31
+ }
32
+ export type BundleTransformOptions = {
33
+ /**
34
+ * Extract module original size or rendered size
35
+ * default: false
36
+ */
37
+ moduleOriginalSize?: boolean;
38
+ };
39
+ export declare const bundleToWebpackStats: (bundle: OutputBundle, customOptions?: BundleTransformOptions) => WebpackStatsFiltered;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-webpack-stats",
3
- "version": "0.1.0",
3
+ "version": "0.2.1-beta.1",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -26,16 +26,16 @@
26
26
  "node": ">=14"
27
27
  },
28
28
  "scripts": {
29
- "start": "tsdx watch",
30
- "build": "tsdx build",
31
- "test": "tsdx test",
32
- "lint": "tsdx lint",
33
- "prepare": "tsdx build",
34
- "analyze": "size-limit --why"
29
+ "build": "rollup -c rollup.config.mjs",
30
+ "lint": "exit 0",
31
+ "test:unit": "vitest test/unit",
32
+ "test:package": "vitest test/package",
33
+ "bump": "./scripts/bump.sh",
34
+ "release": "./scripts/release.sh"
35
35
  },
36
36
  "husky": {
37
37
  "hooks": {
38
- "pre-commit": "tsdx lint"
38
+ "pre-commit": "npm run lint"
39
39
  }
40
40
  },
41
41
  "prettier": {
@@ -44,16 +44,20 @@
44
44
  "singleQuote": true,
45
45
  "trailingComma": "es5"
46
46
  },
47
- "module": "dist/rollup-plugin-webpack-stats.esm.js",
48
47
  "devDependencies": {
49
- "husky": "^8.0.3",
50
- "rollup": "^1.32.1",
51
- "size-limit": "^8.1.1",
52
- "tsdx": "^0.14.1",
53
- "tslib": "^2.4.1",
54
- "typescript": "^4.9.4"
48
+ "@release-it/conventional-changelog": "7.0.0",
49
+ "@rollup/plugin-typescript": "11.1.3",
50
+ "@tsconfig/node14": "14.1.0",
51
+ "@types/node": "20.5.6",
52
+ "dotenv": "16.3.1",
53
+ "husky": "8.0.3",
54
+ "release-it": "16.1.5",
55
+ "rollup": "3.28.1",
56
+ "tslib": "2.6.2",
57
+ "typescript": "5.2.2",
58
+ "vitest": "0.34.3"
55
59
  },
56
60
  "peerDependencies": {
57
- "rollup": "^1.0.0"
61
+ "rollup": "^3.0.0"
58
62
  }
59
63
  }
package/src/index.ts CHANGED
@@ -2,6 +2,8 @@ import { Plugin } from 'rollup';
2
2
 
3
3
  import { BundleTransformOptions, bundleToWebpackStats } from './transform';
4
4
 
5
+ export { bundleToWebpackStats } from './transform';
6
+
5
7
  const NAME = 'webpackStats';
6
8
 
7
9
  interface WebpackStatsOptions extends BundleTransformOptions {
package/src/transform.ts CHANGED
@@ -119,7 +119,7 @@ export const bundleToWebpackStats = (
119
119
  } else if (item.type === 'asset') {
120
120
  assets.push({
121
121
  name: item.fileName,
122
- size: getByteSize(item.source),
122
+ size: getByteSize(item.source.toString()),
123
123
  });
124
124
  } else {
125
125
  // noop for unknown types
@@ -1,106 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- var path = _interopDefault(require('path'));
8
-
9
- function _extends() {
10
- _extends = Object.assign ? Object.assign.bind() : function (target) {
11
- for (var i = 1; i < arguments.length; i++) {
12
- var source = arguments[i];
13
- for (var key in source) {
14
- if (Object.prototype.hasOwnProperty.call(source, key)) {
15
- target[key] = source[key];
16
- }
17
- }
18
- }
19
- return target;
20
- };
21
- return _extends.apply(this, arguments);
22
- }
23
-
24
- var getByteSize = function getByteSize(content) {
25
- if (typeof content === 'string') {
26
- return Buffer.from(content).length;
27
- }
28
- return (content == null ? void 0 : content.length) || 0;
29
- };
30
- var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions) {
31
- var options = _extends({
32
- moduleOriginalSize: false
33
- }, customOptions);
34
- var items = Object.values(bundle);
35
- var assets = [];
36
- var chunks = [];
37
- var moduleByFileName = {};
38
- items.forEach(function (item) {
39
- if (item.type === 'chunk') {
40
- assets.push({
41
- name: item.fileName,
42
- size: getByteSize(item.code)
43
- });
44
- var chunkId = item.name;
45
- chunks.push({
46
- id: chunkId,
47
- entry: item.isEntry,
48
- initial: !item.isDynamicEntry,
49
- files: [item.fileName],
50
- names: [item.name]
51
- });
52
- Object.entries(item.modules).forEach(function (_ref) {
53
- var modulePath = _ref[0],
54
- moduleInfo = _ref[1];
55
- // Remove unexpected rollup null prefix
56
- var normalizedModulePath = modulePath.replace("\0", '');
57
- var relativeModulePath = path.relative(process.cwd(), normalizedModulePath);
58
- // Match webpack output - add current directory prefix for child modules
59
- var relativeModulePathWithPrefix = relativeModulePath.match(/^\.\./) ? relativeModulePath : "." + path.sep + relativeModulePath;
60
- var moduleEntry = moduleByFileName[relativeModulePathWithPrefix];
61
- if (moduleEntry) {
62
- moduleEntry.chunks.push(chunkId);
63
- } else {
64
- moduleByFileName[relativeModulePathWithPrefix] = {
65
- name: relativeModulePathWithPrefix,
66
- size: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength,
67
- chunks: [chunkId]
68
- };
69
- }
70
- });
71
- } else if (item.type === 'asset') {
72
- assets.push({
73
- name: item.fileName,
74
- size: getByteSize(item.source)
75
- });
76
- }
77
- });
78
- return {
79
- builtAt: Date.now(),
80
- assets: assets,
81
- chunks: chunks,
82
- modules: Object.values(moduleByFileName)
83
- };
84
- };
85
-
86
- var NAME = 'webpackStats';
87
- var webpackStats = function webpackStats(options) {
88
- if (options === void 0) {
89
- options = {};
90
- }
91
- return {
92
- name: NAME,
93
- generateBundle: function generateBundle(_, bundle) {
94
- var _options;
95
- var output = bundleToWebpackStats(bundle, options);
96
- this.emitFile({
97
- type: 'asset',
98
- fileName: ((_options = options) == null ? void 0 : _options.fileName) || 'webpack-stats.json',
99
- source: JSON.stringify(output)
100
- });
101
- }
102
- };
103
- };
104
-
105
- exports.webpackStats = webpackStats;
106
- //# sourceMappingURL=rollup-plugin-webpack-stats.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rollup-plugin-webpack-stats.cjs.development.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from '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\n 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 type BundleTransformOptions = {\n /**\n * Extract module original size or rendered size\n * default: false\n */\n moduleOriginalSize?: boolean;\n};\n\nexport const bundleToWebpackStats = (\n bundle: OutputBundle,\n customOptions?: BundleTransformOptions\n): WebpackStatsFiltered => {\n const options = {\n moduleOriginalSize: false,\n ...customOptions,\n };\n\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.isDynamicEntry,\n files: [item.fileName],\n names: [item.name],\n });\n\n Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {\n // Remove unexpected rollup null prefix\n const normalizedModulePath = modulePath.replace('\\u0000', '');\n\n const relativeModulePath = path.relative(\n process.cwd(),\n normalizedModulePath\n );\n\n // Match webpack output - add current directory prefix for child modules\n const relativeModulePathWithPrefix = relativeModulePath.match(/^\\.\\./)\n ? relativeModulePath\n : `.${path.sep}${relativeModulePath}`;\n\n const moduleEntry = moduleByFileName[relativeModulePathWithPrefix];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePathWithPrefix] = {\n name: relativeModulePathWithPrefix,\n size: options.moduleOriginalSize\n ? moduleInfo.originalLength\n : moduleInfo.renderedLength,\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 return {\n builtAt: Date.now(),\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n};\n","import { Plugin } from 'rollup';\n\nimport { BundleTransformOptions, bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\ninterface WebpackStatsOptions extends BundleTransformOptions {\n /**\n * JSON file output fileName\n * default: webpack-stats.json\n */\n fileName?: string;\n}\n\nexport const webpackStats = (options: WebpackStatsOptions = {}): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle, options);\n\n this.emitFile({\n type: 'asset',\n fileName: options?.fileName || 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["getByteSize","content","Buffer","from","length","bundleToWebpackStats","bundle","customOptions","options","moduleOriginalSize","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","name","fileName","size","code","chunkId","id","entry","isEntry","initial","isDynamicEntry","files","names","entries","modules","modulePath","moduleInfo","normalizedModulePath","replace","relativeModulePath","path","relative","process","cwd","relativeModulePathWithPrefix","match","sep","moduleEntry","originalLength","renderedLength","source","builtAt","Date","now","NAME","webpackStats","generateBundle","_","output","emitFile","JSON","stringify"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyCA,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;AAUM,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAoB,CAC/BC,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value:!0});var e,t=(e=require("path"))&&"object"==typeof e&&"default"in e?e.default:e;function n(){return(n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}var i=function(e){return"string"==typeof e?Buffer.from(e).length:(null==e?void 0:e.length)||0};exports.webpackStats=function(e){return void 0===e&&(e={}),{name:"webpackStats",generateBundle:function(a,r){var s,u=function(e,a){var r=n({moduleOriginalSize:!1},a),s=Object.values(e),u=[],o=[],l={};return s.forEach((function(e){if("chunk"===e.type){u.push({name:e.fileName,size:i(e.code)});var n=e.name;o.push({id:n,entry:e.isEntry,initial:!e.isDynamicEntry,files:[e.fileName],names:[e.name]}),Object.entries(e.modules).forEach((function(e){var i=e[1],a=e[0].replace("\0",""),s=t.relative(process.cwd(),a),u=s.match(/^\.\./)?s:"."+t.sep+s,o=l[u];o?o.chunks.push(n):l[u]={name:u,size:r.moduleOriginalSize?i.originalLength:i.renderedLength,chunks:[n]}}))}else"asset"===e.type&&u.push({name:e.fileName,size:i(e.source)})})),{builtAt:Date.now(),assets:u,chunks:o,modules:Object.values(l)}}(r,e);this.emitFile({type:"asset",fileName:(null==(s=e)?void 0:s.fileName)||"webpack-stats.json",source:JSON.stringify(u)})}}};
2
- //# sourceMappingURL=rollup-plugin-webpack-stats.cjs.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rollup-plugin-webpack-stats.cjs.production.min.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from '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\n 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 type BundleTransformOptions = {\n /**\n * Extract module original size or rendered size\n * default: false\n */\n moduleOriginalSize?: boolean;\n};\n\nexport const bundleToWebpackStats = (\n bundle: OutputBundle,\n customOptions?: BundleTransformOptions\n): WebpackStatsFiltered => {\n const options = {\n moduleOriginalSize: false,\n ...customOptions,\n };\n\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.isDynamicEntry,\n files: [item.fileName],\n names: [item.name],\n });\n\n Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {\n // Remove unexpected rollup null prefix\n const normalizedModulePath = modulePath.replace('\\u0000', '');\n\n const relativeModulePath = path.relative(\n process.cwd(),\n normalizedModulePath\n );\n\n // Match webpack output - add current directory prefix for child modules\n const relativeModulePathWithPrefix = relativeModulePath.match(/^\\.\\./)\n ? relativeModulePath\n : `.${path.sep}${relativeModulePath}`;\n\n const moduleEntry = moduleByFileName[relativeModulePathWithPrefix];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePathWithPrefix] = {\n name: relativeModulePathWithPrefix,\n size: options.moduleOriginalSize\n ? moduleInfo.originalLength\n : moduleInfo.renderedLength,\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 return {\n builtAt: Date.now(),\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n};\n","import { Plugin } from 'rollup';\n\nimport { BundleTransformOptions, bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\ninterface WebpackStatsOptions extends BundleTransformOptions {\n /**\n * JSON file output fileName\n * default: webpack-stats.json\n */\n fileName?: string;\n}\n\nexport const webpackStats = (options: WebpackStatsOptions = {}): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle, options);\n\n this.emitFile({\n type: 'asset',\n fileName: options?.fileName || 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["getByteSize","content","Buffer","from","length","options","name","generateBundle","_","bundle","output","customOptions","moduleOriginalSize","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","fileName","size","code","chunkId","id","entry","isEntry","initial","isDynamicEntry","files","names","entries","modules","moduleInfo","normalizedModulePath","replace","relativeModulePath","path","relative","process","cwd","relativeModulePathWithPrefix","match","sep","moduleEntry","originalLength","renderedLength","source","builtAt","Date","now","bundleToWebpackStats","this","emitFile","_options","JSON","stringify"],"mappings":"kXAyCA,IAAMA,EAAc,SAACC,GACnB,MAAuB,iBAAZA,EACFC,OAAOC,KAAKF,GAASG,cAGvBH,SAAAA,EAASG,SAAU,wBChCA,SAACC,GAAiC,gBAAjCA,IAAAA,EAA+B,IAAgB,CAC1EC,KAXW,eAYXC,wBAAeC,EAAGC,SACVC,EDwC0B,SAClCD,EACAE,GAEA,IAAMN,KACJO,oBAAoB,GACjBD,GAGCE,EAAQC,OAAOC,OAAON,GAEtBO,EAA2C,GAC3CC,EAA2C,GAE3CC,EAA+D,GAyDrE,OAvDAL,EAAMM,SAAQ,SAAAC,GACZ,GAAkB,UAAdA,EAAKC,KAAkB,CACzBL,EAAOM,KAAK,CACVhB,KAAMc,EAAKG,SACXC,KAAMxB,EAAYoB,EAAKK,QAGzB,IAAMC,EAAUN,EAAKd,KAErBW,EAAOK,KAAK,CACVK,GAAID,EACJE,MAAOR,EAAKS,QACZC,SAAUV,EAAKW,eACfC,MAAO,CAACZ,EAAKG,UACbU,MAAO,CAACb,EAAKd,QAGfQ,OAAOoB,QAAQd,EAAKe,SAAShB,SAAQ,gBAAciB,OAE3CC,OAAkCC,QAAQ,KAAU,IAEpDC,EAAqBC,EAAKC,SAC9BC,QAAQC,MACRN,GAIIO,EAA+BL,EAAmBM,MAAM,SAC1DN,MACIC,EAAKM,IAAMP,EAEbQ,EAAc7B,EAAiB0B,GAEjCG,EACFA,EAAY9B,OAAOK,KAAKI,GAExBR,EAAiB0B,GAAgC,CAC/CtC,KAAMsC,EACNpB,KAAMnB,EAAQO,mBACVwB,EAAWY,eACXZ,EAAWa,eACfhC,OAAQ,CAACS,WAIQ,UAAdN,EAAKC,MACdL,EAAOM,KAAK,CACVhB,KAAMc,EAAKG,SACXC,KAAMxB,EAAYoB,EAAK8B,aAOtB,CACLC,QAASC,KAAKC,MACdrC,OAAAA,EACAC,OAAAA,EACAkB,QAASrB,OAAOC,OAAOG,ICnHRoC,CAAqB7C,EAAQJ,GAE5CkD,KAAKC,SAAS,CACZnC,KAAM,QACNE,mBAAUlB,UAAAoD,EAASlC,WAAY,qBAC/B2B,OAAQQ,KAAKC,UAAUjD"}
@@ -1,100 +0,0 @@
1
- import path from 'path';
2
-
3
- function _extends() {
4
- _extends = Object.assign ? Object.assign.bind() : function (target) {
5
- for (var i = 1; i < arguments.length; i++) {
6
- var source = arguments[i];
7
- for (var key in source) {
8
- if (Object.prototype.hasOwnProperty.call(source, key)) {
9
- target[key] = source[key];
10
- }
11
- }
12
- }
13
- return target;
14
- };
15
- return _extends.apply(this, arguments);
16
- }
17
-
18
- var getByteSize = function getByteSize(content) {
19
- if (typeof content === 'string') {
20
- return Buffer.from(content).length;
21
- }
22
- return (content == null ? void 0 : content.length) || 0;
23
- };
24
- var bundleToWebpackStats = function bundleToWebpackStats(bundle, customOptions) {
25
- var options = _extends({
26
- moduleOriginalSize: false
27
- }, customOptions);
28
- var items = Object.values(bundle);
29
- var assets = [];
30
- var chunks = [];
31
- var moduleByFileName = {};
32
- items.forEach(function (item) {
33
- if (item.type === 'chunk') {
34
- assets.push({
35
- name: item.fileName,
36
- size: getByteSize(item.code)
37
- });
38
- var chunkId = item.name;
39
- chunks.push({
40
- id: chunkId,
41
- entry: item.isEntry,
42
- initial: !item.isDynamicEntry,
43
- files: [item.fileName],
44
- names: [item.name]
45
- });
46
- Object.entries(item.modules).forEach(function (_ref) {
47
- var modulePath = _ref[0],
48
- moduleInfo = _ref[1];
49
- // Remove unexpected rollup null prefix
50
- var normalizedModulePath = modulePath.replace("\0", '');
51
- var relativeModulePath = path.relative(process.cwd(), normalizedModulePath);
52
- // Match webpack output - add current directory prefix for child modules
53
- var relativeModulePathWithPrefix = relativeModulePath.match(/^\.\./) ? relativeModulePath : "." + path.sep + relativeModulePath;
54
- var moduleEntry = moduleByFileName[relativeModulePathWithPrefix];
55
- if (moduleEntry) {
56
- moduleEntry.chunks.push(chunkId);
57
- } else {
58
- moduleByFileName[relativeModulePathWithPrefix] = {
59
- name: relativeModulePathWithPrefix,
60
- size: options.moduleOriginalSize ? moduleInfo.originalLength : moduleInfo.renderedLength,
61
- chunks: [chunkId]
62
- };
63
- }
64
- });
65
- } else if (item.type === 'asset') {
66
- assets.push({
67
- name: item.fileName,
68
- size: getByteSize(item.source)
69
- });
70
- }
71
- });
72
- return {
73
- builtAt: Date.now(),
74
- assets: assets,
75
- chunks: chunks,
76
- modules: Object.values(moduleByFileName)
77
- };
78
- };
79
-
80
- var NAME = 'webpackStats';
81
- var webpackStats = function webpackStats(options) {
82
- if (options === void 0) {
83
- options = {};
84
- }
85
- return {
86
- name: NAME,
87
- generateBundle: function generateBundle(_, bundle) {
88
- var _options;
89
- var output = bundleToWebpackStats(bundle, options);
90
- this.emitFile({
91
- type: 'asset',
92
- fileName: ((_options = options) == null ? void 0 : _options.fileName) || 'webpack-stats.json',
93
- source: JSON.stringify(output)
94
- });
95
- }
96
- };
97
- };
98
-
99
- export { webpackStats };
100
- //# sourceMappingURL=rollup-plugin-webpack-stats.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rollup-plugin-webpack-stats.esm.js","sources":["../src/transform.ts","../src/index.ts"],"sourcesContent":["import path from '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\n 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 type BundleTransformOptions = {\n /**\n * Extract module original size or rendered size\n * default: false\n */\n moduleOriginalSize?: boolean;\n};\n\nexport const bundleToWebpackStats = (\n bundle: OutputBundle,\n customOptions?: BundleTransformOptions\n): WebpackStatsFiltered => {\n const options = {\n moduleOriginalSize: false,\n ...customOptions,\n };\n\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.isDynamicEntry,\n files: [item.fileName],\n names: [item.name],\n });\n\n Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {\n // Remove unexpected rollup null prefix\n const normalizedModulePath = modulePath.replace('\\u0000', '');\n\n const relativeModulePath = path.relative(\n process.cwd(),\n normalizedModulePath\n );\n\n // Match webpack output - add current directory prefix for child modules\n const relativeModulePathWithPrefix = relativeModulePath.match(/^\\.\\./)\n ? relativeModulePath\n : `.${path.sep}${relativeModulePath}`;\n\n const moduleEntry = moduleByFileName[relativeModulePathWithPrefix];\n\n if (moduleEntry) {\n moduleEntry.chunks.push(chunkId);\n } else {\n moduleByFileName[relativeModulePathWithPrefix] = {\n name: relativeModulePathWithPrefix,\n size: options.moduleOriginalSize\n ? moduleInfo.originalLength\n : moduleInfo.renderedLength,\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 return {\n builtAt: Date.now(),\n assets,\n chunks,\n modules: Object.values(moduleByFileName),\n };\n};\n","import { Plugin } from 'rollup';\n\nimport { BundleTransformOptions, bundleToWebpackStats } from './transform';\n\nconst NAME = 'webpackStats';\n\ninterface WebpackStatsOptions extends BundleTransformOptions {\n /**\n * JSON file output fileName\n * default: webpack-stats.json\n */\n fileName?: string;\n}\n\nexport const webpackStats = (options: WebpackStatsOptions = {}): Plugin => ({\n name: NAME,\n generateBundle(_, bundle) {\n const output = bundleToWebpackStats(bundle, options);\n\n this.emitFile({\n type: 'asset',\n fileName: options?.fileName || 'webpack-stats.json',\n source: JSON.stringify(output),\n });\n },\n});\n"],"names":["getByteSize","content","Buffer","from","length","bundleToWebpackStats","bundle","customOptions","options","moduleOriginalSize","items","Object","values","assets","chunks","moduleByFileName","forEach","item","type","push","name","fileName","size","code","chunkId","id","entry","isEntry","initial","isDynamicEntry","files","names","entries","modules","modulePath","moduleInfo","normalizedModulePath","replace","relativeModulePath","path","relative","process","cwd","relativeModulePathWithPrefix","match","sep","moduleEntry","originalLength","renderedLength","source","builtAt","Date","now","NAME","webpackStats","generateBundle","_","output","emitFile","JSON","stringify"],"mappings":";;;;;;;;;;;;;;;;;AAyCA,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;AAUM,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAoB,CAC/BC,MAAoB,EACpBC,aAAsC;EAEtC,IAAMC,OAAO;IACXC,kBAAkB,EAAE;KACjBF,aAAa,CACjB;EAED,IAAMG,KAAK,GAAGC,MAAM,CAACC,MAAM,CAACN,MAAM,CAAC;EAEnC,IAAMO,MAAM,GAAqC,EAAE;EACnD,IAAMC,MAAM,GAAqC,EAAE;EAEnD,IAAMC,gBAAgB,GAA+C,EAAE;EAEvEL,KAAK,CAACM,OAAO,CAAC,UAAAC,IAAI;IAChB,IAAIA,IAAI,CAACC,IAAI,KAAK,OAAO,EAAE;MACzBL,MAAM,CAACM,IAAI,CAAC;QACVC,IAAI,EAAEH,IAAI,CAACI,QAAQ;QACnBC,IAAI,EAAEtB,WAAW,CAACiB,IAAI,CAACM,IAAI;OAC5B,CAAC;MAEF,IAAMC,OAAO,GAAGP,IAAI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