@rsdoctor/graph 1.3.14 → 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.
package/dist/index.cjs CHANGED
@@ -1200,13 +1200,32 @@ class PackageGraph {
1200
1200
  }
1201
1201
  }
1202
1202
  const logger_namespaceObject = require("@rsdoctor/utils/logger");
1203
- async function getAssetsModulesData(moduleGraph, chunkGraph, bundleDir, opts, sourceMapSets = new Map()) {
1204
- if (opts.parseBundle && sourceMapSets.size < 1) {
1203
+ async function getAssetsModulesData(moduleGraph, chunkGraph, bundleDir, opts, sourceMapSets = new Map(), assetsWithoutSourceMap) {
1204
+ if (sourceMapSets.size > 0) {
1205
+ for (let [modulePath, codes] of ((0, logger_namespaceObject.time)("Start Parse bundle by sourcemap."), sourceMapSets.entries())){
1206
+ let gzipSize, modules = moduleGraph.getModuleByFile(modulePath);
1207
+ try {
1208
+ codes && 'string' == typeof codes && codes.length > 0 && (gzipSize = (0, external_node_zlib_namespaceObject.gzipSync)(codes, {
1209
+ level: 9
1210
+ }).length);
1211
+ } catch {}
1212
+ for (let module of modules)module?.setSize({
1213
+ parsedSize: codes.length,
1214
+ gzipSize
1215
+ }), module?.setSource({
1216
+ parsedSource: codes
1217
+ });
1218
+ }
1219
+ (0, logger_namespaceObject.timeEnd)("Start Parse bundle by sourcemap.");
1220
+ }
1221
+ if (opts.parseBundle && (assetsWithoutSourceMap && assetsWithoutSourceMap.size > 0 || sourceMapSets.size < 1)) {
1205
1222
  (0, logger_namespaceObject.time)("Start Parse bundle by AST.");
1206
1223
  let { parseBundle = ()=>({}) } = opts || {}, assets = chunkGraph.getAssets(), modules = moduleGraph.getModules(), bundlesSources = null, parsedModules = null;
1207
1224
  if (bundleDir && assets.length) {
1208
1225
  for (let asset of (bundlesSources = {}, parsedModules = {}, assets)){
1209
- let bundleInfo, assetFile = external_path_default().join(bundleDir, asset.path);
1226
+ let bundleInfo;
1227
+ if (assetsWithoutSourceMap && assetsWithoutSourceMap.size > 0 && !assetsWithoutSourceMap.has(asset.path)) continue;
1228
+ let assetFile = external_path_default().join(bundleDir, asset.path);
1210
1229
  try {
1211
1230
  bundleInfo = parseBundle(assetFile, modules);
1212
1231
  } catch (err) {
@@ -1222,25 +1241,6 @@ async function getAssetsModulesData(moduleGraph, chunkGraph, bundleDir, opts, so
1222
1241
  common_namespaceObject.Lodash.isEmpty(bundlesSources) && (bundlesSources = null, parsedModules = null, process.env.DEVTOOLS_DEV && logger_namespaceObject.logger.warn('\nNo bundles were parsed. Analyzer will show only original module sizes from stats file.\n')), parsedModules && transformAssetsModulesData(parsedModules, moduleGraph);
1223
1242
  }
1224
1243
  (0, logger_namespaceObject.timeEnd)("Start Parse bundle by AST.");
1225
- } else {
1226
- for (let [modulePath, codes] of ((0, logger_namespaceObject.time)("Start Parse bundle by sourcemap."), sourceMapSets.entries())){
1227
- let gzipSize, modules = moduleGraph.getModuleByFile(modulePath);
1228
- try {
1229
- if (codes && 'string' == typeof codes && codes.length > 0) {
1230
- let { gzipSync } = await import("node:zlib");
1231
- gzipSize = gzipSync(codes, {
1232
- level: 9
1233
- }).length;
1234
- }
1235
- } catch {}
1236
- for (let module of modules)module?.setSize({
1237
- parsedSize: codes.length,
1238
- gzipSize
1239
- }), module?.setSource({
1240
- parsedSource: codes
1241
- });
1242
- }
1243
- (0, logger_namespaceObject.timeEnd)("Start Parse bundle by sourcemap.");
1244
1244
  }
1245
1245
  }
1246
1246
  function transformAssetsModulesData(parsedModulesData, moduleGraph) {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SDK } from "@rsdoctor/types";
2
- import { gzipSync as external_node_zlib_gzipSync } from "node:zlib";
2
+ import { gzipSync } from "node:zlib";
3
3
  import path_0, { dirname, join, relative, resolve } from "path";
4
4
  import { File, Lodash, Package } from "@rsdoctor/utils/common";
5
5
  import { unionBy } from "es-toolkit/compat";
@@ -222,7 +222,7 @@ class Asset {
222
222
  this.id = id;
223
223
  }
224
224
  setGzipSize(content) {
225
- this.gzipSize = external_node_zlib_gzipSync(content, {
225
+ this.gzipSize = gzipSync(content, {
226
226
  level: 9
227
227
  }).length;
228
228
  }
@@ -486,7 +486,7 @@ class Module {
486
486
  else {
487
487
  let code = this.source.parsedSource || this.source.source;
488
488
  if (code && 'string' == typeof code && code.length > 0) try {
489
- size.gzipSize = external_node_zlib_gzipSync(code, {
489
+ size.gzipSize = gzipSync(code, {
490
490
  level: 9
491
491
  }).length;
492
492
  } catch (e) {
@@ -1165,13 +1165,32 @@ class PackageGraph {
1165
1165
  };
1166
1166
  }
1167
1167
  }
1168
- async function getAssetsModulesData(moduleGraph, chunkGraph, bundleDir, opts, sourceMapSets = new Map()) {
1169
- if (opts.parseBundle && sourceMapSets.size < 1) {
1168
+ async function getAssetsModulesData(moduleGraph, chunkGraph, bundleDir, opts, sourceMapSets = new Map(), assetsWithoutSourceMap) {
1169
+ if (sourceMapSets.size > 0) {
1170
+ for (let [modulePath, codes] of (time("Start Parse bundle by sourcemap."), sourceMapSets.entries())){
1171
+ let gzipSize, modules = moduleGraph.getModuleByFile(modulePath);
1172
+ try {
1173
+ codes && 'string' == typeof codes && codes.length > 0 && (gzipSize = gzipSync(codes, {
1174
+ level: 9
1175
+ }).length);
1176
+ } catch {}
1177
+ for (let module of modules)module?.setSize({
1178
+ parsedSize: codes.length,
1179
+ gzipSize
1180
+ }), module?.setSource({
1181
+ parsedSource: codes
1182
+ });
1183
+ }
1184
+ timeEnd("Start Parse bundle by sourcemap.");
1185
+ }
1186
+ if (opts.parseBundle && (assetsWithoutSourceMap && assetsWithoutSourceMap.size > 0 || sourceMapSets.size < 1)) {
1170
1187
  time("Start Parse bundle by AST.");
1171
1188
  let { parseBundle = ()=>({}) } = opts || {}, assets = chunkGraph.getAssets(), modules = moduleGraph.getModules(), bundlesSources = null, parsedModules = null;
1172
1189
  if (bundleDir && assets.length) {
1173
1190
  for (let asset of (bundlesSources = {}, parsedModules = {}, assets)){
1174
- let bundleInfo, assetFile = path_0.join(bundleDir, asset.path);
1191
+ let bundleInfo;
1192
+ if (assetsWithoutSourceMap && assetsWithoutSourceMap.size > 0 && !assetsWithoutSourceMap.has(asset.path)) continue;
1193
+ let assetFile = path_0.join(bundleDir, asset.path);
1175
1194
  try {
1176
1195
  bundleInfo = parseBundle(assetFile, modules);
1177
1196
  } catch (err) {
@@ -1187,32 +1206,13 @@ async function getAssetsModulesData(moduleGraph, chunkGraph, bundleDir, opts, so
1187
1206
  Lodash.isEmpty(bundlesSources) && (bundlesSources = null, parsedModules = null, process.env.DEVTOOLS_DEV && logger.warn('\nNo bundles were parsed. Analyzer will show only original module sizes from stats file.\n')), parsedModules && transformAssetsModulesData(parsedModules, moduleGraph);
1188
1207
  }
1189
1208
  timeEnd("Start Parse bundle by AST.");
1190
- } else {
1191
- for (let [modulePath, codes] of (time("Start Parse bundle by sourcemap."), sourceMapSets.entries())){
1192
- let gzipSize, modules = moduleGraph.getModuleByFile(modulePath);
1193
- try {
1194
- if (codes && 'string' == typeof codes && codes.length > 0) {
1195
- let { gzipSync } = await import("node:zlib");
1196
- gzipSize = gzipSync(codes, {
1197
- level: 9
1198
- }).length;
1199
- }
1200
- } catch {}
1201
- for (let module of modules)module?.setSize({
1202
- parsedSize: codes.length,
1203
- gzipSize
1204
- }), module?.setSource({
1205
- parsedSource: codes
1206
- });
1207
- }
1208
- timeEnd("Start Parse bundle by sourcemap.");
1209
1209
  }
1210
1210
  }
1211
1211
  function transformAssetsModulesData(parsedModulesData, moduleGraph) {
1212
1212
  moduleGraph && Object.entries(parsedModulesData).forEach(([moduleId, parsedData])=>{
1213
1213
  let gzipSize, module = moduleGraph.getModuleByWebpackId(moduleId ?? '');
1214
1214
  try {
1215
- parsedData?.content && 'string' == typeof parsedData.content && parsedData.content.length > 0 && (gzipSize = external_node_zlib_gzipSync(parsedData.content, {
1215
+ parsedData?.content && 'string' == typeof parsedData.content && parsedData.content.length > 0 && (gzipSize = gzipSync(parsedData.content, {
1216
1216
  level: 9
1217
1217
  }).length);
1218
1218
  } catch {}
@@ -18,5 +18,5 @@ export type ParsedModuleSizeData = {
18
18
  */
19
19
  export declare function getAssetsModulesData(moduleGraph: SDK.ModuleGraphInstance, chunkGraph: SDK.ChunkGraphInstance, bundleDir: string, opts: {
20
20
  parseBundle?: ParseBundle;
21
- }, sourceMapSets?: Map<string, string>): Promise<void>;
21
+ }, sourceMapSets?: Map<string, string>, assetsWithoutSourceMap?: Set<string>): Promise<void>;
22
22
  export declare function transformAssetsModulesData(parsedModulesData: ParsedModuleSizeData, moduleGraph: SDK.ModuleGraphInstance): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/graph",
3
- "version": "1.3.14",
3
+ "version": "1.3.16",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -25,8 +25,8 @@
25
25
  "es-toolkit": "^1.41.0",
26
26
  "path-browserify": "1.0.1",
27
27
  "source-map": "^0.7.6",
28
- "@rsdoctor/types": "1.3.14",
29
- "@rsdoctor/utils": "1.3.14"
28
+ "@rsdoctor/types": "1.3.16",
29
+ "@rsdoctor/utils": "1.3.16"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/body-parser": "1.19.6",