@rsdoctor/core 1.2.0-beta.1 → 1.2.0-beta.2

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.
@@ -25,4 +25,13 @@ export declare const ensureModulesChunksGraphFn: (compiler: Plugin.BaseCompiler,
25
25
  * @returns true if source maps are enabled and supported, false otherwise.
26
26
  */
27
27
  export declare const ensureDevtools: (compiler: Plugin.BaseCompiler) => boolean;
28
+ /**
29
+ * Calculates namespace and source map filename regex for source map resolution.
30
+ * @param compiler - The Webpack or Rspack compiler instance.
31
+ * @returns An object containing namespace and sourceMapFilenameRegex.
32
+ */
33
+ export declare function calculateNamespaceAndRegex(compiler: Plugin.BaseCompiler): {
34
+ namespace: string;
35
+ sourceMapFilenameRegex: RegExp;
36
+ };
28
37
  //# sourceMappingURL=ensureModulesChunkGraph.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ensureModulesChunkGraph.d.ts","sourceRoot":"","sources":["../../../src/inner-plugins/plugins/ensureModulesChunkGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAehE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAID;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,aAC3B,MAAM,CAAC,YAAY,SACtB,sBAAsB,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC,SA4D5E,CAAC;AAmHF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,aAAc,MAAM,CAAC,YAAY,YA0B3D,CAAC"}
1
+ {"version":3,"file":"ensureModulesChunkGraph.d.ts","sourceRoot":"","sources":["../../../src/inner-plugins/plugins/ensureModulesChunkGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAehE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAID;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,aAC3B,MAAM,CAAC,YAAY,SACtB,sBAAsB,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,cAAc,EAAE,CAAC,SAmE5E,CAAC;AAmHF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,aAAc,MAAM,CAAC,YAAY,YA0B3D,CAAC;AAyCF;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,MAAM,CAAC,YAAY;eAoB5C,MAAM;;EAGjC"}
@@ -24,8 +24,9 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
- ensureModulesChunksGraphFn: ()=>ensureModulesChunksGraphFn,
28
- ensureDevtools: ()=>ensureDevtools
27
+ calculateNamespaceAndRegex: ()=>calculateNamespaceAndRegex,
28
+ ensureDevtools: ()=>ensureDevtools,
29
+ ensureModulesChunksGraphFn: ()=>ensureModulesChunksGraphFn
29
30
  });
30
31
  const types_namespaceObject = require("@rsdoctor/types");
31
32
  const build_namespaceObject = require("@rsdoctor/utils/build");
@@ -55,7 +56,8 @@ const ensureModulesChunksGraphFn = (compiler, _this)=>{
55
56
  stage: external_constants_js_namespaceObject.pluginTapPostOptions.stage + 100
56
57
  }, async (compilation)=>{
57
58
  if (!ensureDevtools(compiler)) return;
58
- await (0, external_sourcemapTool_js_namespaceObject.handleAfterEmitAssets)(compilation, _this);
59
+ const { namespace, sourceMapFilenameRegex } = calculateNamespaceAndRegex(compiler);
60
+ await (0, external_sourcemapTool_js_namespaceObject.handleAfterEmitAssets)(compilation, _this, sourceMapFilenameRegex, namespace);
59
61
  });
60
62
  compiler.hooks.emit.tapAsync({
61
63
  ...external_constants_js_namespaceObject.pluginTapPostOptions,
@@ -118,25 +120,34 @@ async function getModulesInfos(compiler, moduleGraph, chunkGraph, parseBundle, s
118
120
  function escapeRegExp(str) {
119
121
  return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
120
122
  }
121
- async function emitHandler(_this, compiler, compilation, callback) {
123
+ function calculateNamespaceAndRegex(compiler) {
122
124
  var _compiler_options_output_library;
123
- if (!ensureDevtools(compiler)) return void callback();
124
125
  let namespace = compiler.options.output.devtoolNamespace || (null == (_compiler_options_output_library = compiler.options.output.library) ? void 0 : _compiler_options_output_library.name) || '[^/]+/';
125
126
  if (Array.isArray(namespace)) namespace = namespace[0];
126
127
  else if ('object' == typeof namespace && 'name' in namespace) namespace = namespace.name;
127
128
  const safeNamespace = escapeRegExp(namespace);
128
129
  const sourceMapFilenameRegex = new RegExp(`(?:webpack://)?(?:${safeNamespace})?([^?]*)`);
130
+ return {
131
+ namespace: namespace,
132
+ sourceMapFilenameRegex
133
+ };
134
+ }
135
+ async function emitHandler(_this, compiler, compilation, callback) {
136
+ if (!ensureDevtools(compiler)) return void callback();
137
+ const { namespace, sourceMapFilenameRegex } = calculateNamespaceAndRegex(compiler);
129
138
  await (0, external_sourcemapTool_js_namespaceObject.handleEmitAssets)({
130
139
  compilation,
131
140
  pluginInstance: _this,
132
141
  sourceMapFilenameRegex,
133
- namespace: namespace
142
+ namespace
134
143
  });
135
144
  callback();
136
145
  }
146
+ exports.calculateNamespaceAndRegex = __webpack_exports__.calculateNamespaceAndRegex;
137
147
  exports.ensureDevtools = __webpack_exports__.ensureDevtools;
138
148
  exports.ensureModulesChunksGraphFn = __webpack_exports__.ensureModulesChunksGraphFn;
139
149
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
150
+ "calculateNamespaceAndRegex",
140
151
  "ensureDevtools",
141
152
  "ensureModulesChunksGraphFn"
142
153
  ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
@@ -40,7 +40,7 @@ export declare function collectSourceMaps(map: any, assetLinesCodeList: string[]
40
40
  * @param _this - The Rsdoctor plugin instance.
41
41
  * @param sourceMapFilenameRegex - Regex to extract file paths from source map sources.
42
42
  */
43
- export declare function handleAfterEmitAssets(compilation: Plugin.BaseCompilation, _this: RsdoctorPluginInstance<Plugin.BaseCompiler, Linter.ExtendRuleData<any, string>[]>, sourceMapFilenameRegex?: RegExp): Promise<void>;
43
+ export declare function handleAfterEmitAssets(compilation: Plugin.BaseCompilation, _this: RsdoctorPluginInstance<Plugin.BaseCompiler, Linter.ExtendRuleData<any, string>[]>, sourceMapFilenameRegex?: RegExp, namespace?: string): Promise<void>;
44
44
  /**
45
45
  * Handles source map collection for Webpack assets (non-Rspack).
46
46
  * Iterates over all assets, parses them, and collects source maps.
@@ -1 +1 @@
1
- {"version":3,"file":"sourcemapTool.d.ts","sourceRoot":"","sources":["../../../src/inner-plugins/plugins/sourcemapTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAOjD,eAAO,MAAM,UAAU,iBAAiB,CAAC;AAEzC;;;;;;GAMG;AACH,UAAU,qBAAqB;IAC7B,WAAW,EAAE,MAAM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
31
31
  handleEmitAssets: ()=>handleEmitAssets
32
32
  });
33
+ const common_namespaceObject = require("@rsdoctor/utils/common");
33
34
  const logger_namespaceObject = require("@rsdoctor/utils/logger");
34
35
  const external_path_namespaceObject = require("path");
35
36
  const external_source_map_namespaceObject = require("source-map");
@@ -39,10 +40,11 @@ function bindContextCache(context, namespace, cache) {
39
40
  return (source, sourceMapFilenameRegex)=>{
40
41
  if (cache.has(source)) return cache.get(source);
41
42
  let resolved = UNASSIGNED;
42
- if (source.startsWith('webpack://')) {
43
+ if (source.startsWith('file://')) resolved = (0, external_path_namespaceObject.resolve)(context, source.replace(/^file:\/\//, ''));
44
+ else if (source.startsWith('webpack://')) {
43
45
  const match = source.match(sourceMapFilenameRegex);
44
46
  const filePath = null == match ? void 0 : match[1];
45
- const hasNamespace = namespace && source.startsWith(`webpack://${namespace}`);
47
+ const hasNamespace = namespace && source.startsWith(`webpack://${namespace}`) || namespace && source.startsWith(`file://${namespace}`);
46
48
  const baseDir = hasNamespace ? process.cwd() : context;
47
49
  resolved = filePath ? (0, external_path_namespaceObject.resolve)(baseDir, `./${filePath}`) : UNASSIGNED;
48
50
  } else resolved = (0, external_path_namespaceObject.resolve)(context, source);
@@ -68,7 +70,7 @@ async function collectSourceMaps(map, assetLinesCodeList, _compilation, _this, s
68
70
  const m = mappings[i];
69
71
  if (!m.source) continue;
70
72
  let realSource = m.source.split('!').pop();
71
- if ((null == realSource ? void 0 : realSource.startsWith('webpack://')) && sourceMapFilenameRegex) realSource = getRealSourcePath(realSource, sourceMapFilenameRegex);
73
+ if (((null == realSource ? void 0 : realSource.startsWith('webpack://')) || (null == realSource ? void 0 : realSource.startsWith('file://'))) && sourceMapFilenameRegex) realSource = getRealSourcePath(realSource, sourceMapFilenameRegex);
72
74
  if (!realSource) continue;
73
75
  const next = mappings[i + 1];
74
76
  const start = m.generatedColumn;
@@ -80,7 +82,7 @@ async function collectSourceMaps(map, assetLinesCodeList, _compilation, _this, s
80
82
  }
81
83
  }
82
84
  }
83
- async function handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex) {
85
+ async function handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex, namespace) {
84
86
  if ('rspack' in compilation.compiler) {
85
87
  _this.sourceMapSets = new Map();
86
88
  (0, logger_namespaceObject.time)('ensureModulesChunkGraph.afterEmit.start');
@@ -88,9 +90,27 @@ async function handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex)
88
90
  ...compilation.getAssets()
89
91
  ];
90
92
  for (const asset of assets){
91
- const { assetLinesCodeList, map } = parseAsset(asset, assets, 'js/css');
92
- if (map) try {
93
- await collectSourceMaps(map, assetLinesCodeList, compilation, _this, sourceMapFilenameRegex);
93
+ const { assetLinesCodeList, map: mapFromAsset } = parseAsset(asset, assets, 'js/css');
94
+ let map = mapFromAsset;
95
+ if (!map) {
96
+ var _asset_info_related;
97
+ let sourceMapFile = null == (_asset_info_related = asset.info.related) ? void 0 : _asset_info_related.sourceMap;
98
+ sourceMapFile = null == sourceMapFile ? void 0 : sourceMapFile.replace(/(\.[^.]+)(\.[^.]+)?$/, '$1');
99
+ if (!sourceMapFile) continue;
100
+ {
101
+ let sourceMapAsset = assets.find((asset)=>asset.name === sourceMapFile);
102
+ if (!sourceMapAsset) {
103
+ const baseNameWithoutHash = common_namespaceObject.Graph.formatAssetName(sourceMapFile, 'string' == typeof compilation.options.output.filename ? compilation.options.output.filename : void 0);
104
+ sourceMapAsset = assets.find((asset)=>{
105
+ const assetBaseName = common_namespaceObject.Graph.formatAssetName(asset.name, 'string' == typeof compilation.options.output.filename ? compilation.options.output.filename : void 0);
106
+ return assetBaseName.includes(baseNameWithoutHash) && asset.name.endsWith('.map');
107
+ });
108
+ }
109
+ if (sourceMapAsset) map = JSON.parse(sourceMapAsset.source.source().toString());
110
+ }
111
+ }
112
+ try {
113
+ await collectSourceMaps(map, assetLinesCodeList, compilation, _this, sourceMapFilenameRegex, namespace);
94
114
  } catch (e) {
95
115
  logger_namespaceObject.logger.error(e);
96
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/core",
3
- "version": "1.2.0-beta.1",
3
+ "version": "1.2.0-beta.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -73,14 +73,14 @@
73
73
  "semver": "^7.7.2",
74
74
  "source-map": "^0.7.4",
75
75
  "source-map-js": "^1.2.1",
76
- "@rsdoctor/graph": "1.2.0-beta.1",
77
- "@rsdoctor/sdk": "1.2.0-beta.1",
78
- "@rsdoctor/types": "1.2.0-beta.1",
79
- "@rsdoctor/utils": "1.2.0-beta.1"
76
+ "@rsdoctor/graph": "1.2.0-beta.2",
77
+ "@rsdoctor/sdk": "1.2.0-beta.2",
78
+ "@rsdoctor/types": "1.2.0-beta.2",
79
+ "@rsdoctor/utils": "1.2.0-beta.2"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@rslib/core": "^0.11.0",
83
- "@rspack/core": "1.4.8",
83
+ "@rspack/core": "1.4.11",
84
84
  "@types/fs-extra": "^11.0.4",
85
85
  "@types/lodash": "^4.17.20",
86
86
  "@types/node": "^22.8.1",
@@ -98,7 +98,6 @@
98
98
  },
99
99
  "publishConfig": {
100
100
  "access": "public",
101
- "provenance": true,
102
101
  "registry": "https://registry.npmjs.org/"
103
102
  },
104
103
  "scripts": {