@rsdoctor/core 1.3.15 → 1.3.16

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.
@@ -28,10 +28,10 @@ __webpack_require__.d(__webpack_exports__, {
28
28
  });
29
29
  const graph_namespaceObject = require("@rsdoctor/graph");
30
30
  const index_cjs_namespaceObject = require("../utils/index.cjs");
31
- async function getAssetsModulesData(moduleGraph, chunkGraph, bundleDir, sourceMapSets, hasParseBundle = true) {
31
+ async function getAssetsModulesData(moduleGraph, chunkGraph, bundleDir, sourceMapSets, hasParseBundle = true, assetsWithoutSourceMap) {
32
32
  return graph_namespaceObject.Chunks.getAssetsModulesData(moduleGraph, chunkGraph, bundleDir, hasParseBundle ? {
33
33
  parseBundle: index_cjs_namespaceObject.parseBundle
34
- } : {}, sourceMapSets);
34
+ } : {}, sourceMapSets, assetsWithoutSourceMap);
35
35
  }
36
36
  exports.getAssetsModulesData = __webpack_exports__.getAssetsModulesData;
37
37
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -1,2 +1,17 @@
1
1
  import { SDK } from '@rsdoctor/types';
2
- export declare function getAssetsModulesData(moduleGraph: SDK.ModuleGraphInstance, chunkGraph: SDK.ChunkGraphInstance, bundleDir: string, sourceMapSets: Map<string, string>, hasParseBundle?: boolean): Promise<void>;
2
+ /**
3
+ * Collects module size data from bundle assets, using source maps when available
4
+ * and falling back to AST parsing for assets without source maps.
5
+ *
6
+ * @param moduleGraph - The module graph instance
7
+ * @param chunkGraph - The chunk graph instance
8
+ * @param bundleDir - Directory containing the bundle assets
9
+ * @param sourceMapSets - Map of module paths to their source code (from source maps)
10
+ * @param hasParseBundle - Whether to enable AST parsing fallback
11
+ * @param assetsWithoutSourceMap - Optional set of asset paths that don't have source maps.
12
+ * When provided, these assets will be parsed using AST parsing instead of source map data.
13
+ * This is used as a fallback mechanism when source maps are unavailable for specific assets.
14
+ * If not provided and no source maps exist (sourceMapSets is empty), all assets will be parsed via AST.
15
+ * @returns Promise that resolves when module data collection is complete
16
+ */
17
+ export declare function getAssetsModulesData(moduleGraph: SDK.ModuleGraphInstance, chunkGraph: SDK.ChunkGraphInstance, bundleDir: string, sourceMapSets: Map<string, string>, hasParseBundle?: boolean, assetsWithoutSourceMap?: Set<string>): Promise<void>;
@@ -2,9 +2,9 @@ import 'module';
2
2
  /*#__PURE__*/ import.meta.url;
3
3
  import { Chunks } from "@rsdoctor/graph";
4
4
  import { parseBundle } from "../utils/index.js";
5
- async function getAssetsModulesData(moduleGraph, chunkGraph, bundleDir, sourceMapSets, hasParseBundle = true) {
5
+ async function getAssetsModulesData(moduleGraph, chunkGraph, bundleDir, sourceMapSets, hasParseBundle = true, assetsWithoutSourceMap) {
6
6
  return Chunks.getAssetsModulesData(moduleGraph, chunkGraph, bundleDir, hasParseBundle ? {
7
7
  parseBundle: parseBundle
8
- } : {}, sourceMapSets);
8
+ } : {}, sourceMapSets, assetsWithoutSourceMap);
9
9
  }
10
10
  export { getAssetsModulesData };
@@ -103,7 +103,7 @@ async function doneHandler(_stats, _this, context, compiler) {
103
103
  logger_namespaceObject.logger.debug(`${(build_namespaceObject.Process.getMemoryUsageMessage(), '[After AppendTreeShaking to ModuleGraph]')}`);
104
104
  }
105
105
  const shouldParseBundle = false !== _this.options.supports.parseBundle;
106
- await getModulesInfos(compiler, _this.modulesGraph, _this.chunkGraph, shouldParseBundle, _this.sourceMapSets);
106
+ await getModulesInfos(compiler, _this.modulesGraph, _this.chunkGraph, shouldParseBundle, _this.sourceMapSets, _this.assetsWithoutSourceMap);
107
107
  logger_namespaceObject.logger.debug(`${build_namespaceObject.Process.getMemoryUsageMessage()}, '[After Transform ModuleGraph]'`);
108
108
  _this.modulesGraph && await _this.sdk.reportModuleGraph(_this.modulesGraph);
109
109
  await _this.sdk.reportChunkGraph(_this.chunkGraph);
@@ -124,10 +124,10 @@ const ensureDevtools = (compiler)=>{
124
124
  }
125
125
  return true;
126
126
  };
127
- async function getModulesInfos(compiler, moduleGraph, chunkGraph, parseBundle, sourceMapSets) {
127
+ async function getModulesInfos(compiler, moduleGraph, chunkGraph, parseBundle, sourceMapSets, assetsWithoutSourceMap) {
128
128
  if (!moduleGraph) return;
129
129
  try {
130
- await index_cjs_namespaceObject.Chunks.getAssetsModulesData(moduleGraph, chunkGraph, compiler.outputPath, sourceMapSets, parseBundle);
130
+ await index_cjs_namespaceObject.Chunks.getAssetsModulesData(moduleGraph, chunkGraph, compiler.outputPath, sourceMapSets, parseBundle, assetsWithoutSourceMap);
131
131
  } catch (e) {}
132
132
  }
133
133
  function escapeRegExp(str) {
@@ -75,7 +75,7 @@ async function doneHandler(_stats, _this, context, compiler) {
75
75
  logger.debug(`${(Process.getMemoryUsageMessage(), '[After AppendTreeShaking to ModuleGraph]')}`);
76
76
  }
77
77
  const shouldParseBundle = false !== _this.options.supports.parseBundle;
78
- await getModulesInfos(compiler, _this.modulesGraph, _this.chunkGraph, shouldParseBundle, _this.sourceMapSets);
78
+ await getModulesInfos(compiler, _this.modulesGraph, _this.chunkGraph, shouldParseBundle, _this.sourceMapSets, _this.assetsWithoutSourceMap);
79
79
  logger.debug(`${Process.getMemoryUsageMessage()}, '[After Transform ModuleGraph]'`);
80
80
  _this.modulesGraph && await _this.sdk.reportModuleGraph(_this.modulesGraph);
81
81
  await _this.sdk.reportChunkGraph(_this.chunkGraph);
@@ -96,10 +96,10 @@ const ensureDevtools = (compiler)=>{
96
96
  }
97
97
  return true;
98
98
  };
99
- async function getModulesInfos(compiler, moduleGraph, chunkGraph, parseBundle, sourceMapSets) {
99
+ async function getModulesInfos(compiler, moduleGraph, chunkGraph, parseBundle, sourceMapSets, assetsWithoutSourceMap) {
100
100
  if (!moduleGraph) return;
101
101
  try {
102
- await Chunks.getAssetsModulesData(moduleGraph, chunkGraph, compiler.outputPath, sourceMapSets, parseBundle);
102
+ await Chunks.getAssetsModulesData(moduleGraph, chunkGraph, compiler.outputPath, sourceMapSets, parseBundle, assetsWithoutSourceMap);
103
103
  } catch (e) {}
104
104
  }
105
105
  function escapeRegExp(str) {
@@ -119,6 +119,8 @@ async function collectSourceMaps(map, assetLinesCodeList, _compilation, _this, s
119
119
  async function handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex, namespace) {
120
120
  if ('rspack' in compilation.compiler) {
121
121
  _this.sourceMapSets = new Map();
122
+ if (_this.assetsWithoutSourceMap) _this.assetsWithoutSourceMap.clear();
123
+ else _this.assetsWithoutSourceMap = new Set();
122
124
  (0, logger_namespaceObject.time)('ensureModulesChunkGraph.afterEmit.start');
123
125
  const assets = [
124
126
  ...compilation.getAssets()
@@ -137,8 +139,7 @@ async function handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex,
137
139
  } else {
138
140
  let sourceMapFile = asset.info.related?.sourceMap;
139
141
  let sourceMapFileAssetName = sourceMapFile?.replace(/(\.[^.]+)(\.[^.]+)?$/, '$1');
140
- if (!sourceMapFile) continue;
141
- {
142
+ if (sourceMapFile) {
142
143
  let sourceMapAsset = assets.find((asset)=>asset.name === sourceMapFile);
143
144
  if (!sourceMapAsset && sourceMapFileAssetName) {
144
145
  const baseNameWithoutHash = common_namespaceObject.Graph.formatAssetName(sourceMapFileAssetName, 'string' == typeof compilation.options.output.filename ? compilation.options.output.filename : void 0);
@@ -152,6 +153,9 @@ async function handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex,
152
153
  const outputPath = compilation.options.output?.path;
153
154
  if (outputPath && 'string' == typeof outputPath) sourceMapPath = (0, external_path_namespaceObject.resolve)(outputPath, sourceMapAsset.name);
154
155
  }
156
+ } else {
157
+ if (assetName && 'string' == typeof assetName && (assetName.endsWith('.js') || assetName.endsWith('.css'))) _this.assetsWithoutSourceMap.add(assetName);
158
+ continue;
155
159
  }
156
160
  }
157
161
  try {
@@ -89,6 +89,8 @@ async function collectSourceMaps(map, assetLinesCodeList, _compilation, _this, s
89
89
  async function handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex, namespace) {
90
90
  if ('rspack' in compilation.compiler) {
91
91
  _this.sourceMapSets = new Map();
92
+ if (_this.assetsWithoutSourceMap) _this.assetsWithoutSourceMap.clear();
93
+ else _this.assetsWithoutSourceMap = new Set();
92
94
  time('ensureModulesChunkGraph.afterEmit.start');
93
95
  const assets = [
94
96
  ...compilation.getAssets()
@@ -107,8 +109,7 @@ async function handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex,
107
109
  } else {
108
110
  let sourceMapFile = asset.info.related?.sourceMap;
109
111
  let sourceMapFileAssetName = sourceMapFile?.replace(/(\.[^.]+)(\.[^.]+)?$/, '$1');
110
- if (!sourceMapFile) continue;
111
- {
112
+ if (sourceMapFile) {
112
113
  let sourceMapAsset = assets.find((asset)=>asset.name === sourceMapFile);
113
114
  if (!sourceMapAsset && sourceMapFileAssetName) {
114
115
  const baseNameWithoutHash = Graph.formatAssetName(sourceMapFileAssetName, 'string' == typeof compilation.options.output.filename ? compilation.options.output.filename : void 0);
@@ -122,6 +123,9 @@ async function handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex,
122
123
  const outputPath = compilation.options.output?.path;
123
124
  if (outputPath && 'string' == typeof outputPath) sourceMapPath = resolve(outputPath, sourceMapAsset.name);
124
125
  }
126
+ } else {
127
+ if (assetName && 'string' == typeof assetName && (assetName.endsWith('.js') || assetName.endsWith('.css'))) _this.assetsWithoutSourceMap.add(assetName);
128
+ continue;
125
129
  }
126
130
  }
127
131
  try {
@@ -53,12 +53,20 @@ function processCompilerConfig(config) {
53
53
  plugins: plugins.map((e)=>e?.constructor.name)
54
54
  };
55
55
  }
56
- function handleBriefModeReport(sdk, options, disableClientServer) {
56
+ async function handleBriefModeReport(sdk, options, disableClientServer) {
57
57
  if (!disableClientServer && options.output.mode === types_namespaceObject.SDK.IMode[types_namespaceObject.SDK.IMode.brief]) {
58
- const htmlOptions = 'htmlOptions' in options.output.options && options.output.options.htmlOptions || void 0;
59
- const outputFilePath = external_path_default().resolve(sdk.outputDir, htmlOptions?.reportHtmlName || 'rsdoctor-report.html');
60
- console.log(`${logger_namespaceObject.chalk.green('[RSDOCTOR] generated brief report')}: ${outputFilePath}`);
61
- (0, sdk_namespaceObject.openBrowser)(`file:///${outputFilePath}`);
58
+ const outputTypes = options.output.options?.type || [];
59
+ const isJsonOnly = Array.isArray(outputTypes) && 1 === outputTypes.length && 'json' === outputTypes[0];
60
+ if (isJsonOnly) {
61
+ const jsonFileName = options.output.options?.jsonOptions?.fileName || 'rsdoctor-data.json';
62
+ const jsonFilePath = external_path_default().resolve(sdk.outputDir, jsonFileName);
63
+ console.log(`${logger_namespaceObject.chalk.green('[RSDOCTOR] generated JSON data')}: ${jsonFilePath}`);
64
+ } else {
65
+ const htmlOptions = 'htmlOptions' in options.output.options && options.output.options.htmlOptions || void 0;
66
+ const outputFilePath = external_path_default().resolve(sdk.outputDir, htmlOptions?.reportHtmlName || 'rsdoctor-report.html');
67
+ console.log(`${logger_namespaceObject.chalk.green('[RSDOCTOR] generated brief report')}: ${outputFilePath}`);
68
+ (0, sdk_namespaceObject.openBrowser)(`file:///${outputFilePath}`);
69
+ }
62
70
  }
63
71
  }
64
72
  exports.handleBriefModeReport = __webpack_exports__.handleBriefModeReport;
@@ -3,4 +3,4 @@ import type { Configuration } from '@rspack/core';
3
3
  * Process compiler configuration to make it serializable
4
4
  */
5
5
  export declare function processCompilerConfig(config: any): Configuration;
6
- export declare function handleBriefModeReport(sdk: any, options: any, disableClientServer: boolean): void;
6
+ export declare function handleBriefModeReport(sdk: any, options: any, disableClientServer: boolean): Promise<void>;
@@ -16,12 +16,20 @@ function processCompilerConfig(config) {
16
16
  plugins: plugins.map((e)=>e?.constructor.name)
17
17
  };
18
18
  }
19
- function handleBriefModeReport(sdk, options, disableClientServer) {
19
+ async function handleBriefModeReport(sdk, options, disableClientServer) {
20
20
  if (!disableClientServer && options.output.mode === SDK.IMode[SDK.IMode.brief]) {
21
- const htmlOptions = 'htmlOptions' in options.output.options && options.output.options.htmlOptions || void 0;
22
- const outputFilePath = path.resolve(sdk.outputDir, htmlOptions?.reportHtmlName || 'rsdoctor-report.html');
23
- console.log(`${chalk.green('[RSDOCTOR] generated brief report')}: ${outputFilePath}`);
24
- openBrowser(`file:///${outputFilePath}`);
21
+ const outputTypes = options.output.options?.type || [];
22
+ const isJsonOnly = Array.isArray(outputTypes) && 1 === outputTypes.length && 'json' === outputTypes[0];
23
+ if (isJsonOnly) {
24
+ const jsonFileName = options.output.options?.jsonOptions?.fileName || 'rsdoctor-data.json';
25
+ const jsonFilePath = path.resolve(sdk.outputDir, jsonFileName);
26
+ console.log(`${chalk.green('[RSDOCTOR] generated JSON data')}: ${jsonFilePath}`);
27
+ } else {
28
+ const htmlOptions = 'htmlOptions' in options.output.options && options.output.options.htmlOptions || void 0;
29
+ const outputFilePath = path.resolve(sdk.outputDir, htmlOptions?.reportHtmlName || 'rsdoctor-report.html');
30
+ console.log(`${chalk.green('[RSDOCTOR] generated brief report')}: ${outputFilePath}`);
31
+ openBrowser(`file:///${outputFilePath}`);
32
+ }
25
33
  }
26
34
  }
27
35
  export { handleBriefModeReport, processCompilerConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/core",
3
- "version": "1.3.15",
3
+ "version": "1.3.16",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -69,10 +69,10 @@
69
69
  "fs-extra": "^11.1.1",
70
70
  "semver": "^7.7.3",
71
71
  "source-map": "^0.7.6",
72
- "@rsdoctor/graph": "1.3.15",
73
- "@rsdoctor/sdk": "1.3.15",
74
- "@rsdoctor/types": "1.3.15",
75
- "@rsdoctor/utils": "1.3.15"
72
+ "@rsdoctor/sdk": "1.3.16",
73
+ "@rsdoctor/graph": "1.3.16",
74
+ "@rsdoctor/utils": "1.3.16",
75
+ "@rsdoctor/types": "1.3.16"
76
76
  },
77
77
  "devDependencies": {
78
78
  "axios": "^1.13.2",