rollup-plugin-stats 1.0.0-beta.0 → 1.0.0

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,10 +1,8 @@
1
1
  # rollup-plugin-stats
2
2
 
3
- > **Warning**
4
- > Under active development
5
-
6
3
  [![](https://img.shields.io/npm/v/rollup-plugin-stats.svg)](https://www.npmjs.com/package/rollup-plugin-stats)
7
4
  ![](https://img.shields.io/node/v/rollup-plugin-stats.svg)
5
+ [![Socket Badge](https://socket.dev/api/badge/npm/package/rollup-plugin-stats)](https://socket.dev/npm/package/rollup-plugin-stats)
8
6
  [![CI](https://github.com/vio/rollup-plugin-stats/actions/workflows/main.yml/badge.svg)](https://github.com/vio/rollup-plugin-stats/actions/workflows/main.yml)
9
7
 
10
8
  Output Rollup stats JSON file
@@ -49,4 +47,6 @@ module.exports = {
49
47
 
50
48
  ### Options
51
49
 
52
- - `filename` - the JSON filename relative to the build folder, default: `stats.json`
50
+ - `fileName` - the JSON filename relative to the build folder, default: `stats.json`
51
+ - `stats`
52
+ - `source` - output asset/chunk/module source (default `false`)
@@ -0,0 +1,20 @@
1
+ import { OutputAsset, OutputBundle, OutputChunk, RenderedModule } from 'rollup';
2
+ export type AssetStats = Omit<OutputAsset, 'source'> & {
3
+ source?: OutputAsset['source'];
4
+ };
5
+ export type ModuleStats = Omit<RenderedModule, 'code'> & {
6
+ code?: RenderedModule['code'] | null;
7
+ };
8
+ export type ChunkStats = Omit<OutputChunk, 'code' | 'modules'> & {
9
+ code?: OutputChunk['code'];
10
+ modules: Record<string, ModuleStats>;
11
+ };
12
+ export type Stats = Record<string, AssetStats | ChunkStats>;
13
+ export type StatsOptions = {
14
+ /**
15
+ * Output asset/module sources
16
+ * @default false
17
+ */
18
+ source?: boolean;
19
+ };
20
+ export default function extractRollupStats(bundle: OutputBundle, options?: StatsOptions): Stats;
package/dist/index.cjs CHANGED
@@ -1,16 +1,59 @@
1
1
  'use strict';
2
2
 
3
- const NAME = 'rollupStats';
4
- const rollupStats = (options = {}) => ({
5
- name: NAME,
6
- generateBundle(_, bundle) {
7
- this.emitFile({
8
- type: 'asset',
9
- fileName: options?.fileName || 'stats.json',
10
- source: JSON.stringify(bundle, null, 2),
11
- });
12
- },
13
- });
3
+ var omit = require('lodash/omit.js');
4
+
5
+ function extractRollupStats(bundle, options = {}) {
6
+ const { source = false } = options;
7
+ const output = {};
8
+ Object.entries(bundle).forEach(([key, entry]) => {
9
+ if (entry.type === "asset") {
10
+ let entryAsset = structuredClone(entry);
11
+ // Skip asset source if options.source is false
12
+ if (!source) {
13
+ entryAsset = omit(entryAsset, 'source');
14
+ }
15
+ output[key] = entryAsset;
16
+ return;
17
+ }
18
+ if (entry.type === "chunk") {
19
+ let entryChunk = structuredClone(entry);
20
+ // Skip chunk code if options.source is false
21
+ if (!source) {
22
+ entryChunk = omit(entryChunk, 'code');
23
+ }
24
+ Object.entries(entryChunk.modules).forEach(([moduleKey, moduleEntry]) => {
25
+ let entryChunkModule = structuredClone(moduleEntry);
26
+ // Skip module source if source is false
27
+ if (!source) {
28
+ entryChunkModule = omit(entryChunkModule, 'code');
29
+ }
30
+ entryChunk.modules[moduleKey] = entryChunkModule;
31
+ });
32
+ output[key] = entryChunk;
33
+ return;
34
+ }
35
+ });
36
+ return output;
37
+ }
38
+
39
+ const PLUGIN_NAME = 'rollupStats';
40
+ const DEFAULT_FILE_NAME = 'stats.json';
41
+ function defaultFormatOutput(stats) {
42
+ return JSON.stringify(stats, null, 2);
43
+ }
44
+ function rollupStats(options = {}) {
45
+ const { fileName, stats } = options;
46
+ return {
47
+ name: PLUGIN_NAME,
48
+ generateBundle(_, bundle) {
49
+ this.emitFile({
50
+ type: 'asset',
51
+ fileName: fileName || DEFAULT_FILE_NAME,
52
+ source: defaultFormatOutput(extractRollupStats(bundle, stats)),
53
+ });
54
+ },
55
+ };
56
+ }
14
57
 
15
58
  module.exports = rollupStats;
16
59
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA,MAAM,IAAI,GAAG,aAAa;AAUpB,MAAA,WAAW,GAAG,CAAC,OAAA,GAA8B,EAAE,MAAc;AACjE,IAAA,IAAI,EAAE,IAAI;IACV,cAAc,CAAC,CAAC,EAAE,MAAM,EAAA;QACtB,IAAI,CAAC,QAAQ,CAAC;AACZ,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,YAAY;YAC3C,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AACxC,SAAA,CAAC;KACH;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/extract.ts","../src/index.ts"],"sourcesContent":[null,null],"names":[],"mappings":";;;;AA0BwB,SAAA,kBAAkB,CAAC,MAAoB,EAAE,UAAwB,EAAE,EAAA;AACzF,IAAA,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,OAAO;IAElC,MAAM,MAAM,GAAU,EAAE;AAExB,IAAA,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;AAC9C,QAAA,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;AAC1B,YAAA,IAAI,UAAU,GAAG,eAAe,CAAC,KAAK,CAAe;;YAGrD,IAAI,CAAC,MAAM,EAAE;AACX,gBAAA,UAAU,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC;;AAGzC,YAAA,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU;YAExB;;AAGF,QAAA,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;AAC1B,YAAA,IAAI,UAAU,GAAG,eAAe,CAAC,KAAK,CAAe;;YAGrD,IAAI,CAAC,MAAM,EAAE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'./extract';
3
+ export type RollupStatsOptions = {
3
4
  /**
4
5
  * JSON file output fileName
5
6
  * default: stats.json
6
7
  */
7
8
  fileName?: string;
8
- }
9
- declare const rollupStats: (options?: RollupStatsOptions) => Plugin;
9
+ stats?: StatsOptions;
10
+ };
11
+ declare function rollupStats(options?: RollupStatsOptions): Plugin;
10
12
  export default rollupStats;
package/dist/index.mjs CHANGED
@@ -1,14 +1,57 @@
1
- const NAME = 'rollupStats';
2
- const rollupStats = (options = {}) => ({
3
- name: NAME,
4
- generateBundle(_, bundle) {
5
- this.emitFile({
6
- type: 'asset',
7
- fileName: options?.fileName || 'stats.json',
8
- source: JSON.stringify(bundle, null, 2),
9
- });
10
- },
11
- });
1
+ import omit from 'lodash/omit.js';
2
+
3
+ function extractRollupStats(bundle, options = {}) {
4
+ const { source = false } = options;
5
+ const output = {};
6
+ Object.entries(bundle).forEach(([key, entry]) => {
7
+ if (entry.type === "asset") {
8
+ let entryAsset = structuredClone(entry);
9
+ // Skip asset source if options.source is false
10
+ if (!source) {
11
+ entryAsset = omit(entryAsset, 'source');
12
+ }
13
+ output[key] = entryAsset;
14
+ return;
15
+ }
16
+ if (entry.type === "chunk") {
17
+ let entryChunk = structuredClone(entry);
18
+ // Skip chunk code if options.source is false
19
+ if (!source) {
20
+ entryChunk = omit(entryChunk, 'code');
21
+ }
22
+ Object.entries(entryChunk.modules).forEach(([moduleKey, moduleEntry]) => {
23
+ let entryChunkModule = structuredClone(moduleEntry);
24
+ // Skip module source if source is false
25
+ if (!source) {
26
+ entryChunkModule = omit(entryChunkModule, 'code');
27
+ }
28
+ entryChunk.modules[moduleKey] = entryChunkModule;
29
+ });
30
+ output[key] = entryChunk;
31
+ return;
32
+ }
33
+ });
34
+ return output;
35
+ }
36
+
37
+ const PLUGIN_NAME = 'rollupStats';
38
+ const DEFAULT_FILE_NAME = 'stats.json';
39
+ function defaultFormatOutput(stats) {
40
+ return JSON.stringify(stats, null, 2);
41
+ }
42
+ function rollupStats(options = {}) {
43
+ const { fileName, stats } = options;
44
+ return {
45
+ name: PLUGIN_NAME,
46
+ generateBundle(_, bundle) {
47
+ this.emitFile({
48
+ type: 'asset',
49
+ fileName: fileName || DEFAULT_FILE_NAME,
50
+ source: defaultFormatOutput(extractRollupStats(bundle, stats)),
51
+ });
52
+ },
53
+ };
54
+ }
12
55
 
13
56
  export { rollupStats as default };
14
57
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEA,MAAM,IAAI,GAAG,aAAa;AAUpB,MAAA,WAAW,GAAG,CAAC,OAAA,GAA8B,EAAE,MAAc;AACjE,IAAA,IAAI,EAAE,IAAI;IACV,cAAc,CAAC,CAAC,EAAE,MAAM,EAAA;QACtB,IAAI,CAAC,QAAQ,CAAC;AACZ,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,QAAQ,EAAE,OAAO,EAAE,QAAQ,IAAI,YAAY;YAC3C,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AACxC,SAAA,CAAC;KACH;AACF,CAAA;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/extract.ts","../src/index.ts"],"sourcesContent":[null,null],"names":[],"mappings":";;AA0BwB,SAAA,kBAAkB,CAAC,MAAoB,EAAE,UAAwB,EAAE,EAAA;AACzF,IAAA,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,OAAO;IAElC,MAAM,MAAM,GAAU,EAAE;AAExB,IAAA,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;AAC9C,QAAA,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;AAC1B,YAAA,IAAI,UAAU,GAAG,eAAe,CAAC,KAAK,CAAe;;YAGrD,IAAI,CAAC,MAAM,EAAE;AACX,gBAAA,UAAU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QAAQ,IAAI,iBAAiB;gBACvC,MAAM,EAAE,mBAAmB,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC/D,aAAA,CAAC;SACH;KACe;AACpB;;;;"}
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "rollup-plugin-stats",
3
- "version": "1.0.0-beta.0",
3
+ "description": "Output Rollup stats",
4
+ "version": "1.0.0",
4
5
  "license": "MIT",
5
6
  "private": false,
6
7
  "author": {
@@ -37,7 +38,7 @@
37
38
  "build": "rollup -c rollup.config.mjs",
38
39
  "lint": "eslint .",
39
40
  "format": "prettier --write .",
40
- "test:unit": "echo \"No tests\" && exit 0",
41
+ "test:unit": "vitest test/unit",
41
42
  "test:package": "vitest test/package",
42
43
  "bump": "./scripts/bump.sh",
43
44
  "release": "./scripts/release.sh"
@@ -52,6 +53,8 @@
52
53
  "@release-it/conventional-changelog": "9.0.3",
53
54
  "@rollup/plugin-typescript": "^12.1.2",
54
55
  "@tsconfig/node18": "^18.2.4",
56
+ "@types/lodash": "^4.17.13",
57
+ "@types/node": "^18.19.68",
55
58
  "dotenv": "^16.4.7",
56
59
  "eslint": "^9.17.0",
57
60
  "globals": "^15.14.0",
@@ -62,5 +65,8 @@
62
65
  "typescript": "^5.7.2",
63
66
  "typescript-eslint": "^8.18.1",
64
67
  "vitest": "^2.1.8"
68
+ },
69
+ "dependencies": {
70
+ "lodash": "^4.17.21"
65
71
  }
66
72
  }