rollup-plugin-webpack-stats 0.2.1-beta.1 → 0.2.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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  [![](https://img.shields.io/npm/v/rollup-plugin-webpack-stats.svg)](https://www.npmjs.com/package/rollup-plugin-webpack-stats)
7
7
  ![](https://img.shields.io/node/v/rollup-plugin-webpack-stats.svg)
8
- [![CI](https://github.com/vio/rollup-plugin-webpack-stats/actions/workflows/main.yml/badge.svg)](https://github.com/vio/rollup-plugin-webpack-stats/actions/workflows/main.yml)
8
+ [![ci](https://github.com/vio/rollup-plugin-webpack-stats/actions/workflows/ci.yml/badge.svg)](https://github.com/vio/rollup-plugin-webpack-stats/actions/workflows/ci.yml)
9
9
 
10
10
  Generate rollup stats JSON file with a [bundle-stats](https://github.com/relative-ci/bundle-stats/tree/master/packages/cli) webpack [supported structure](https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts).
11
11
 
package/package.json CHANGED
@@ -1,26 +1,25 @@
1
1
  {
2
2
  "name": "rollup-plugin-webpack-stats",
3
- "version": "0.2.1-beta.1",
3
+ "version": "0.2.1",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "typings": "dist/index.d.ts",
8
8
  "author": {
9
9
  "name": "Viorel Cojocaru",
10
- "email": "vio@beanon.com",
11
- "url": "https://beanon.com"
10
+ "email": "vio@relative-ci.com",
11
+ "url": "https://relative-ci.com"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "git+https://github.com/vio/rollup-plugin-webpack-stats.git"
15
+ "url": "git+https://github.com/relative-ci/rollup-plugin-webpack-stats.git"
16
16
  },
17
17
  "bugs": {
18
- "url": "https://github.com/vio/rollup-plugin-webpack-stats/issues"
18
+ "url": "https://github.com/relative-ci/rollup-plugin-webpack-stats/issues"
19
19
  },
20
- "homepage": "https://github.com/vio/rollup-plugin-webpack-stats/blob/master/#readme",
20
+ "homepage": "https://github.com/relative-ci/rollup-plugin-webpack-stats/blob/master/#readme",
21
21
  "files": [
22
- "dist",
23
- "src"
22
+ "dist"
24
23
  ],
25
24
  "engines": {
26
25
  "node": ">=14"
package/src/index.ts DELETED
@@ -1,28 +0,0 @@
1
- import { Plugin } from 'rollup';
2
-
3
- import { BundleTransformOptions, bundleToWebpackStats } from './transform';
4
-
5
- export { bundleToWebpackStats } from './transform';
6
-
7
- const NAME = 'webpackStats';
8
-
9
- interface WebpackStatsOptions extends BundleTransformOptions {
10
- /**
11
- * JSON file output fileName
12
- * default: webpack-stats.json
13
- */
14
- fileName?: string;
15
- }
16
-
17
- export const webpackStats = (options: WebpackStatsOptions = {}): Plugin => ({
18
- name: NAME,
19
- generateBundle(_, bundle) {
20
- const output = bundleToWebpackStats(bundle, options);
21
-
22
- this.emitFile({
23
- type: 'asset',
24
- fileName: options?.fileName || 'webpack-stats.json',
25
- source: JSON.stringify(output),
26
- });
27
- },
28
- });
package/src/transform.ts DELETED
@@ -1,135 +0,0 @@
1
- import path from 'path';
2
- import { OutputBundle } from 'rollup';
3
-
4
- // https://github.com/relative-ci/bundle-stats/blob/master/packages/plugin-webpack-filter/src/index.ts
5
- export type WebpackStatsFilteredAsset = {
6
- name: string;
7
- size?: number;
8
- };
9
-
10
- export interface WebpackStatsFilteredChunk {
11
- id: number | string;
12
- entry: boolean;
13
- initial: boolean;
14
- files?: Array<string>;
15
- names?: Array<string>;
16
- }
17
-
18
- export interface WebpackStatsFilteredModule {
19
- name: string;
20
- size?: number;
21
- chunks: Array<string | number>;
22
- }
23
-
24
- export interface WebpackStatsFilteredConcatenatedModule {
25
- name: string;
26
- size?: number;
27
- }
28
-
29
- export interface WebpackStatsFilteredRootModule
30
- extends WebpackStatsFilteredModule {
31
- modules?: Array<WebpackStatsFilteredConcatenatedModule>;
32
- }
33
-
34
- export interface WebpackStatsFiltered {
35
- builtAt?: number;
36
- hash?: string;
37
- assets?: Array<WebpackStatsFilteredAsset>;
38
- chunks?: Array<WebpackStatsFilteredChunk>;
39
- modules?: Array<WebpackStatsFilteredRootModule>;
40
- }
41
-
42
- const getByteSize = (content: string | Buffer): number => {
43
- if (typeof content === 'string') {
44
- return Buffer.from(content).length;
45
- }
46
-
47
- return content?.length || 0;
48
- };
49
-
50
- export type BundleTransformOptions = {
51
- /**
52
- * Extract module original size or rendered size
53
- * default: false
54
- */
55
- moduleOriginalSize?: boolean;
56
- };
57
-
58
- export const bundleToWebpackStats = (
59
- bundle: OutputBundle,
60
- customOptions?: BundleTransformOptions
61
- ): WebpackStatsFiltered => {
62
- const options = {
63
- moduleOriginalSize: false,
64
- ...customOptions,
65
- };
66
-
67
- const items = Object.values(bundle);
68
-
69
- const assets: Array<WebpackStatsFilteredAsset> = [];
70
- const chunks: Array<WebpackStatsFilteredChunk> = [];
71
-
72
- const moduleByFileName: Record<string, WebpackStatsFilteredModule> = {};
73
-
74
- items.forEach(item => {
75
- if (item.type === 'chunk') {
76
- assets.push({
77
- name: item.fileName,
78
- size: getByteSize(item.code),
79
- });
80
-
81
- const chunkId = item.name;
82
-
83
- chunks.push({
84
- id: chunkId,
85
- entry: item.isEntry,
86
- initial: !item.isDynamicEntry,
87
- files: [item.fileName],
88
- names: [item.name],
89
- });
90
-
91
- Object.entries(item.modules).forEach(([modulePath, moduleInfo]) => {
92
- // Remove unexpected rollup null prefix
93
- const normalizedModulePath = modulePath.replace('\u0000', '');
94
-
95
- const relativeModulePath = path.relative(
96
- process.cwd(),
97
- normalizedModulePath
98
- );
99
-
100
- // Match webpack output - add current directory prefix for child modules
101
- const relativeModulePathWithPrefix = relativeModulePath.match(/^\.\./)
102
- ? relativeModulePath
103
- : `.${path.sep}${relativeModulePath}`;
104
-
105
- const moduleEntry = moduleByFileName[relativeModulePathWithPrefix];
106
-
107
- if (moduleEntry) {
108
- moduleEntry.chunks.push(chunkId);
109
- } else {
110
- moduleByFileName[relativeModulePathWithPrefix] = {
111
- name: relativeModulePathWithPrefix,
112
- size: options.moduleOriginalSize
113
- ? moduleInfo.originalLength
114
- : moduleInfo.renderedLength,
115
- chunks: [chunkId],
116
- };
117
- }
118
- });
119
- } else if (item.type === 'asset') {
120
- assets.push({
121
- name: item.fileName,
122
- size: getByteSize(item.source.toString()),
123
- });
124
- } else {
125
- // noop for unknown types
126
- }
127
- });
128
-
129
- return {
130
- builtAt: Date.now(),
131
- assets,
132
- chunks,
133
- modules: Object.values(moduleByFileName),
134
- };
135
- };