@rsdoctor/graph 1.5.3-alpha.0 → 1.5.4
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/graph/module-graph/dependency.d.ts +1 -0
- package/dist/graph/module-graph/graph.d.ts +5 -1
- package/dist/graph/module-graph/index.d.ts +1 -0
- package/dist/graph/module-graph/module.d.ts +8 -0
- package/dist/graph/module-graph/utils.d.ts +22 -0
- package/dist/index.cjs +103 -5
- package/dist/index.js +107 -28
- package/dist/rslib-runtime.js +24 -0
- package/package.json +5 -5
|
@@ -6,6 +6,7 @@ export declare class Dependency implements SDK.DependencyInstance {
|
|
|
6
6
|
readonly request: string;
|
|
7
7
|
readonly module: SDK.ModuleInstance;
|
|
8
8
|
readonly kind: SDK.DependencyKind;
|
|
9
|
+
typeString?: string;
|
|
9
10
|
readonly statements: SDK.StatementInstance[];
|
|
10
11
|
private _originDependency;
|
|
11
12
|
meta: SDK.DependencyBuildMeta;
|
|
@@ -3,6 +3,7 @@ export declare class ModuleGraph implements SDK.ModuleGraphInstance {
|
|
|
3
3
|
static init(): void;
|
|
4
4
|
static fromData(data: Partial<SDK.ModuleGraphData>): ModuleGraph;
|
|
5
5
|
private _dependenciesIdMap;
|
|
6
|
+
private _connectionsOnlyImports;
|
|
6
7
|
private _moduleWebpackIdMap;
|
|
7
8
|
private _moduleIdMap;
|
|
8
9
|
private _moduleGraphModules;
|
|
@@ -12,7 +13,7 @@ export declare class ModuleGraph implements SDK.ModuleGraphInstance {
|
|
|
12
13
|
private _layers;
|
|
13
14
|
clear(): void;
|
|
14
15
|
size(): number;
|
|
15
|
-
fromInstance(data:
|
|
16
|
+
fromInstance(data: SDK.ModuleGraphInstance): void;
|
|
16
17
|
getSubGraphByModule(module: SDK.ModuleInstance): SDK.ModuleInstance[];
|
|
17
18
|
getModules(): SDK.ModuleInstance[];
|
|
18
19
|
getDependencies(): SDK.DependencyInstance[];
|
|
@@ -34,7 +35,10 @@ export declare class ModuleGraph implements SDK.ModuleGraphInstance {
|
|
|
34
35
|
addLayer(layer: string): void;
|
|
35
36
|
getLayers(): Map<string, number>;
|
|
36
37
|
toData(configs?: SDK.ModuleGraphToDataArgs): SDK.ModuleGraphData;
|
|
38
|
+
toTreeShakingData(): SDK.TreeShakingData;
|
|
37
39
|
toCodeData(type?: SDK.ToDataType): SDK.ModuleCodeData;
|
|
38
40
|
setModules(modules: SDK.ModuleInstance[]): void;
|
|
39
41
|
setDependencies(dependencies: SDK.DependencyInstance[]): void;
|
|
42
|
+
setConnectionsOnlyImports(items: SDK.ConnectionsOnlyImportData[]): void;
|
|
43
|
+
getConnectionsOnlyImports(): SDK.ConnectionsOnlyImportData[];
|
|
40
44
|
}
|
|
@@ -10,6 +10,10 @@ export declare class Module implements SDK.ModuleInstance {
|
|
|
10
10
|
id: number;
|
|
11
11
|
renderId: string | undefined;
|
|
12
12
|
bailoutReason: string[];
|
|
13
|
+
/** Side effect location data from the bundler */
|
|
14
|
+
sideEffectLocations: SDK.SideEffectLocationData[];
|
|
15
|
+
/** Side effect code snippets */
|
|
16
|
+
private sideEffectCodes;
|
|
13
17
|
readonly webpackId: string;
|
|
14
18
|
readonly path: string;
|
|
15
19
|
readonly isEntry: boolean;
|
|
@@ -31,6 +35,10 @@ export declare class Module implements SDK.ModuleInstance {
|
|
|
31
35
|
get isPreferSource(): boolean;
|
|
32
36
|
addBailoutReason(reason: string): void;
|
|
33
37
|
getBailoutReason(): string[];
|
|
38
|
+
addSideEffectLocation(location: SDK.SideEffectLocationData): void;
|
|
39
|
+
getSideEffectLocations(): SDK.SideEffectLocationData[];
|
|
40
|
+
addSideEffectCode(codeData: SDK.SideEffectCodeData): void;
|
|
41
|
+
getSideEffectCodes(): SDK.SideEffectCodeData[];
|
|
34
42
|
getChunks(): SDK.ChunkInstance[];
|
|
35
43
|
addChunk(chunk: SDK.ChunkInstance): void;
|
|
36
44
|
removeChunk(chunk: SDK.ChunkInstance): void;
|
|
@@ -2,3 +2,25 @@ import type { SDK } from '@rsdoctor/types';
|
|
|
2
2
|
export declare function isSamePosition(po1: SDK.SourcePosition, po2: SDK.SourcePosition): boolean;
|
|
3
3
|
export declare function isSameRange(po1: SDK.SourceRange, po2: SDK.SourceRange): boolean;
|
|
4
4
|
export declare function getModuleName(name?: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Parse location string from Rspack side effect location
|
|
7
|
+
* Supports formats:
|
|
8
|
+
* - "line:column" -> { startLine, startColumn }
|
|
9
|
+
* - "startLine:startColumn-endLine:endColumn" -> full range (e.g. 3:1-7:2)
|
|
10
|
+
* - "line:startColumn-endColumn" -> single-line range (e.g. 11:72-285)
|
|
11
|
+
* - "startLine-endLine:endColumn" -> start column omitted (e.g. 1-7:2)
|
|
12
|
+
* - "startLine-endLine" -> line range only
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseLocation(location: string): {
|
|
15
|
+
startLine: number;
|
|
16
|
+
startColumn: number;
|
|
17
|
+
endLine?: number;
|
|
18
|
+
endColumn?: number;
|
|
19
|
+
} | null;
|
|
20
|
+
/**
|
|
21
|
+
* Extract code snippet from source based on location
|
|
22
|
+
* @param source The source code string
|
|
23
|
+
* @param location Parsed location object
|
|
24
|
+
* @returns Extracted code snippet
|
|
25
|
+
*/
|
|
26
|
+
export declare function extractCodeFromLocation(source: string, location: ReturnType<typeof parseLocation>): string;
|
package/dist/index.cjs
CHANGED
|
@@ -20,11 +20,14 @@ __webpack_require__.n = (module)=>{
|
|
|
20
20
|
};
|
|
21
21
|
var __webpack_exports__ = {};
|
|
22
22
|
__webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
|
|
23
|
+
isSamePosition: ()=>isSamePosition,
|
|
23
24
|
Dependency: ()=>Dependency,
|
|
24
25
|
ModuleGraphTrans: ()=>transform_module_graph_namespaceObject,
|
|
25
26
|
Asset: ()=>Asset,
|
|
27
|
+
isSameRange: ()=>isSameRange,
|
|
26
28
|
ExportInfo: ()=>ExportInfo,
|
|
27
29
|
ModuleGraphModule: ()=>ModuleGraphModule,
|
|
30
|
+
getModuleName: ()=>getModuleName,
|
|
28
31
|
readPackageJson: ()=>readPackageJson,
|
|
29
32
|
PackageDependency: ()=>PackageDependency,
|
|
30
33
|
Statement: ()=>Statement,
|
|
@@ -36,6 +39,8 @@ __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_expo
|
|
|
36
39
|
TransUtils: ()=>trans_utils_namespaceObject,
|
|
37
40
|
Webpack: ()=>webpack_compatible_namespaceObject,
|
|
38
41
|
Chunks: ()=>chunks_namespaceObject,
|
|
42
|
+
parseLocation: ()=>parseLocation,
|
|
43
|
+
extractCodeFromLocation: ()=>extractCodeFromLocation,
|
|
39
44
|
Variable: ()=>Variable,
|
|
40
45
|
PackageGraph: ()=>PackageGraph,
|
|
41
46
|
Chunk: ()=>Chunk,
|
|
@@ -333,6 +338,9 @@ class Dependency {
|
|
|
333
338
|
request: this.request,
|
|
334
339
|
resolvedRequest: this.resolvedRequest,
|
|
335
340
|
kind: this.kind,
|
|
341
|
+
...void 0 !== this.typeString && {
|
|
342
|
+
typeString: this.typeString
|
|
343
|
+
},
|
|
336
344
|
module: this.module.id,
|
|
337
345
|
dependency: this.dependency.id,
|
|
338
346
|
originDependency: this.originDependency.id,
|
|
@@ -361,6 +369,60 @@ function getModuleName(name) {
|
|
|
361
369
|
}
|
|
362
370
|
return NAME_WITH_MODULES.test(name) ? name.replace(NAME_WITH_MODULES, '') : INVALID_CSS_PREFIX.test(name) ? name.replace(INVALID_CSS_PREFIX, '') : name;
|
|
363
371
|
}
|
|
372
|
+
function parseLocation(location) {
|
|
373
|
+
if (!location || 'string' != typeof location) return null;
|
|
374
|
+
let s = location.trim();
|
|
375
|
+
if (!s) return null;
|
|
376
|
+
let fullRange = s.match(/^(\d+):(\d+)-(\d+):(\d+)$/);
|
|
377
|
+
if (fullRange) return {
|
|
378
|
+
startLine: parseInt(fullRange[1], 10),
|
|
379
|
+
startColumn: parseInt(fullRange[2], 10),
|
|
380
|
+
endLine: parseInt(fullRange[3], 10),
|
|
381
|
+
endColumn: parseInt(fullRange[4], 10)
|
|
382
|
+
};
|
|
383
|
+
let singleLineRange = s.match(/^(\d+):(\d+)-(\d+)$/);
|
|
384
|
+
if (singleLineRange) {
|
|
385
|
+
let startLine = parseInt(singleLineRange[1], 10);
|
|
386
|
+
return {
|
|
387
|
+
startLine,
|
|
388
|
+
startColumn: parseInt(singleLineRange[2], 10),
|
|
389
|
+
endLine: startLine,
|
|
390
|
+
endColumn: parseInt(singleLineRange[3], 10)
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
let endColOnly = s.match(/^(\d+)-(\d+):(\d+)$/);
|
|
394
|
+
if (endColOnly) return {
|
|
395
|
+
startLine: parseInt(endColOnly[1], 10),
|
|
396
|
+
startColumn: 0,
|
|
397
|
+
endLine: parseInt(endColOnly[2], 10),
|
|
398
|
+
endColumn: parseInt(endColOnly[3], 10)
|
|
399
|
+
};
|
|
400
|
+
let lineRange = s.match(/^(\d+)-(\d+)$/);
|
|
401
|
+
if (lineRange) return {
|
|
402
|
+
startLine: parseInt(lineRange[1], 10),
|
|
403
|
+
startColumn: 0,
|
|
404
|
+
endLine: parseInt(lineRange[2], 10)
|
|
405
|
+
};
|
|
406
|
+
let point = s.match(/^(\d+):(\d+)$/);
|
|
407
|
+
return point ? {
|
|
408
|
+
startLine: parseInt(point[1], 10),
|
|
409
|
+
startColumn: parseInt(point[2], 10)
|
|
410
|
+
} : null;
|
|
411
|
+
}
|
|
412
|
+
function extractCodeFromLocation(source, location) {
|
|
413
|
+
if (!source || !location) return '';
|
|
414
|
+
let lines = source.split('\n'), { startLine, startColumn: OriginalStartColumn, endLine, endColumn } = location, startColumn = OriginalStartColumn;
|
|
415
|
+
if (OriginalStartColumn && (startColumn = OriginalStartColumn - 1), !endLine || startLine === endLine) {
|
|
416
|
+
let line = lines[startLine - 1];
|
|
417
|
+
return line ? void 0 !== endColumn ? line.substring(startColumn, endColumn) : line.substring(startColumn) : '';
|
|
418
|
+
}
|
|
419
|
+
let result = [];
|
|
420
|
+
for(let i = startLine - 1; i < Math.min(endLine, lines.length); i++){
|
|
421
|
+
let line = lines[i];
|
|
422
|
+
i === startLine - 1 ? result.push(line.substring(startColumn)) : i === endLine - 1 ? result.push(void 0 !== endColumn ? line.substring(0, endColumn) : line) : result.push(line);
|
|
423
|
+
}
|
|
424
|
+
return result.join('\n');
|
|
425
|
+
}
|
|
364
426
|
class Statement {
|
|
365
427
|
static getDefaultStatement(module) {
|
|
366
428
|
let defaultPosition = {
|
|
@@ -416,7 +478,7 @@ class Module {
|
|
|
416
478
|
module_id = 1;
|
|
417
479
|
}
|
|
418
480
|
constructor(webpackId, path, isEntry = !1, kind = types_namespaceObject.SDK.ModuleKind.Normal, renderId, layer = ''){
|
|
419
|
-
this.issuerPath = [], this.bailoutReason = [], this.source = {
|
|
481
|
+
this.issuerPath = [], this.bailoutReason = [], this.sideEffectLocations = [], this.sideEffectCodes = [], this.source = {
|
|
420
482
|
source: '',
|
|
421
483
|
transformed: '',
|
|
422
484
|
parsedSource: ''
|
|
@@ -444,6 +506,18 @@ class Module {
|
|
|
444
506
|
getBailoutReason() {
|
|
445
507
|
return this.bailoutReason;
|
|
446
508
|
}
|
|
509
|
+
addSideEffectLocation(location) {
|
|
510
|
+
this.sideEffectLocations.push(location);
|
|
511
|
+
}
|
|
512
|
+
getSideEffectLocations() {
|
|
513
|
+
return this.sideEffectLocations.slice();
|
|
514
|
+
}
|
|
515
|
+
addSideEffectCode(codeData) {
|
|
516
|
+
this.sideEffectCodes.push(codeData);
|
|
517
|
+
}
|
|
518
|
+
getSideEffectCodes() {
|
|
519
|
+
return this.sideEffectCodes.slice();
|
|
520
|
+
}
|
|
447
521
|
getChunks() {
|
|
448
522
|
return this.chunks.slice();
|
|
449
523
|
}
|
|
@@ -608,7 +682,10 @@ class Module {
|
|
|
608
682
|
layer: this.layer
|
|
609
683
|
} : {},
|
|
610
684
|
issuerPath: isBrief ? void 0 : this.issuerPath?.filter((issuer)=>issuer.moduleId).map((issuer)=>issuer.moduleId) || [],
|
|
611
|
-
bailoutReason: this.bailoutReason
|
|
685
|
+
bailoutReason: this.bailoutReason,
|
|
686
|
+
...this.sideEffectLocations.length > 0 ? {
|
|
687
|
+
sideEffectLocations: this.sideEffectLocations
|
|
688
|
+
} : {}
|
|
612
689
|
};
|
|
613
690
|
return (this.meta.hasSetEsModuleStatement || this.meta.strictHarmonyModule) && (data.meta = {}, this.meta.hasSetEsModuleStatement && (data.meta.hasSetEsModuleStatement = !0), this.meta.strictHarmonyModule && (data.meta.strictHarmonyModule = !0)), this.isEntry && (data.isEntry = this.isEntry), this.modules.length > 0 && (data.modules = this.modules.map((item)=>item.id)), this.rootModule && (data.rootModule = this.rootModule.id), this.concatenationModules.length > 0 && (data.concatenationModules = this.concatenationModules.map((data)=>data.id)), data;
|
|
614
691
|
}
|
|
@@ -898,7 +975,7 @@ class ModuleGraph {
|
|
|
898
975
|
return this._moduleIdMap.size;
|
|
899
976
|
}
|
|
900
977
|
fromInstance(data) {
|
|
901
|
-
this.
|
|
978
|
+
this.setModules(data.getModules()), this.setDependencies(data.getDependencies()), this.setConnectionsOnlyImports(data.getConnectionsOnlyImports()), data instanceof ModuleGraph && (this._moduleGraphModules = new Map(data._moduleGraphModules), this._exportIdMap = new Map(data._exportIdMap), this._sideEffectIdMap = new Map(data._sideEffectIdMap), this._varIdMap = new Map(data._varIdMap), this._layers = new Map(data._layers));
|
|
902
979
|
}
|
|
903
980
|
getSubGraphByModule(module) {
|
|
904
981
|
let map = new Set(), result = [
|
|
@@ -978,6 +1055,16 @@ class ModuleGraph {
|
|
|
978
1055
|
layers: Array.from(this._layers.keys())
|
|
979
1056
|
};
|
|
980
1057
|
}
|
|
1058
|
+
toTreeShakingData() {
|
|
1059
|
+
let sideEffectCodes = {};
|
|
1060
|
+
for (let module of this.getModules()){
|
|
1061
|
+
let codes = module.getSideEffectCodes();
|
|
1062
|
+
codes.length > 0 && (sideEffectCodes[codes[0].moduleId] = codes);
|
|
1063
|
+
}
|
|
1064
|
+
return {
|
|
1065
|
+
sideEffectCodes
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
981
1068
|
toCodeData(type = types_namespaceObject.SDK.ToDataType.Normal) {
|
|
982
1069
|
let codeMap = {};
|
|
983
1070
|
return this.getModules().forEach((item)=>{
|
|
@@ -1002,8 +1089,14 @@ class ModuleGraph {
|
|
|
1002
1089
|
d
|
|
1003
1090
|
]));
|
|
1004
1091
|
}
|
|
1092
|
+
setConnectionsOnlyImports(items) {
|
|
1093
|
+
this._connectionsOnlyImports = items;
|
|
1094
|
+
}
|
|
1095
|
+
getConnectionsOnlyImports() {
|
|
1096
|
+
return this._connectionsOnlyImports;
|
|
1097
|
+
}
|
|
1005
1098
|
constructor(){
|
|
1006
|
-
this._dependenciesIdMap = new Map(), this._moduleWebpackIdMap = new Map(), this._moduleIdMap = new Map(), this._moduleGraphModules = new Map(), this._exportIdMap = new Map(), this._sideEffectIdMap = new Map(), this._varIdMap = new Map(), this._layers = new Map();
|
|
1099
|
+
this._dependenciesIdMap = new Map(), this._connectionsOnlyImports = [], this._moduleWebpackIdMap = new Map(), this._moduleIdMap = new Map(), this._moduleGraphModules = new Map(), this._exportIdMap = new Map(), this._sideEffectIdMap = new Map(), this._varIdMap = new Map(), this._layers = new Map();
|
|
1007
1100
|
}
|
|
1008
1101
|
}
|
|
1009
1102
|
let package_graph_dependency_id = 1;
|
|
@@ -1523,7 +1616,7 @@ function getAllModules(compilation) {
|
|
|
1523
1616
|
for (let mod of compilation.modules)modules.push(...mod.modules ?? []), modules.push(mod);
|
|
1524
1617
|
return (0, compat_namespaceObject.unionBy)(modules.filter((mod)=>!getWebpackModuleId(mod).startsWith('webpack/runtime')), (mod)=>getWebpackModuleId(mod));
|
|
1525
1618
|
}
|
|
1526
|
-
for(var __rspack_i in exports.Asset = __webpack_exports__.Asset, exports.Chunk = __webpack_exports__.Chunk, exports.ChunkGraph = __webpack_exports__.ChunkGraph, exports.Chunks = __webpack_exports__.Chunks, exports.Dependency = __webpack_exports__.Dependency, exports.EntryPoint = __webpack_exports__.EntryPoint, exports.ExportInfo = __webpack_exports__.ExportInfo, exports.Module = __webpack_exports__.Module, exports.ModuleGraph = __webpack_exports__.ModuleGraph, exports.ModuleGraphModule = __webpack_exports__.ModuleGraphModule, exports.ModuleGraphTrans = __webpack_exports__.ModuleGraphTrans, exports.Package = __webpack_exports__.Package, exports.PackageDependency = __webpack_exports__.PackageDependency, exports.PackageGraph = __webpack_exports__.PackageGraph, exports.SideEffect = __webpack_exports__.SideEffect, exports.Statement = __webpack_exports__.Statement, exports.TransUtils = __webpack_exports__.TransUtils, exports.Variable = __webpack_exports__.Variable, exports.Webpack = __webpack_exports__.Webpack, exports.readPackageJson = __webpack_exports__.readPackageJson, __webpack_exports__)-1 === [
|
|
1619
|
+
for(var __rspack_i in exports.Asset = __webpack_exports__.Asset, exports.Chunk = __webpack_exports__.Chunk, exports.ChunkGraph = __webpack_exports__.ChunkGraph, exports.Chunks = __webpack_exports__.Chunks, exports.Dependency = __webpack_exports__.Dependency, exports.EntryPoint = __webpack_exports__.EntryPoint, exports.ExportInfo = __webpack_exports__.ExportInfo, exports.Module = __webpack_exports__.Module, exports.ModuleGraph = __webpack_exports__.ModuleGraph, exports.ModuleGraphModule = __webpack_exports__.ModuleGraphModule, exports.ModuleGraphTrans = __webpack_exports__.ModuleGraphTrans, exports.Package = __webpack_exports__.Package, exports.PackageDependency = __webpack_exports__.PackageDependency, exports.PackageGraph = __webpack_exports__.PackageGraph, exports.SideEffect = __webpack_exports__.SideEffect, exports.Statement = __webpack_exports__.Statement, exports.TransUtils = __webpack_exports__.TransUtils, exports.Variable = __webpack_exports__.Variable, exports.Webpack = __webpack_exports__.Webpack, exports.extractCodeFromLocation = __webpack_exports__.extractCodeFromLocation, exports.getModuleName = __webpack_exports__.getModuleName, exports.isSamePosition = __webpack_exports__.isSamePosition, exports.isSameRange = __webpack_exports__.isSameRange, exports.parseLocation = __webpack_exports__.parseLocation, exports.readPackageJson = __webpack_exports__.readPackageJson, __webpack_exports__)-1 === [
|
|
1527
1620
|
"Asset",
|
|
1528
1621
|
"Chunk",
|
|
1529
1622
|
"ChunkGraph",
|
|
@@ -1543,6 +1636,11 @@ for(var __rspack_i in exports.Asset = __webpack_exports__.Asset, exports.Chunk =
|
|
|
1543
1636
|
"TransUtils",
|
|
1544
1637
|
"Variable",
|
|
1545
1638
|
"Webpack",
|
|
1639
|
+
"extractCodeFromLocation",
|
|
1640
|
+
"getModuleName",
|
|
1641
|
+
"isSamePosition",
|
|
1642
|
+
"isSameRange",
|
|
1643
|
+
"parseLocation",
|
|
1546
1644
|
"readPackageJson"
|
|
1547
1645
|
].indexOf(__rspack_i) && (exports[__rspack_i] = __webpack_exports__[__rspack_i]);
|
|
1548
1646
|
Object.defineProperty(exports, '__esModule', {
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
1
2
|
import { SDK } from "@rsdoctor/types";
|
|
2
3
|
import { gzipSync } from "node:zlib";
|
|
3
4
|
import path_0, { dirname, join, relative, resolve } from "path";
|
|
@@ -5,19 +6,6 @@ import { File, Lodash, Package } from "@rsdoctor/utils/common";
|
|
|
5
6
|
import { unionBy } from "es-toolkit/compat";
|
|
6
7
|
import { logger, time, timeEnd } from "@rsdoctor/utils/logger";
|
|
7
8
|
import path_browserify from "path-browserify";
|
|
8
|
-
var __webpack_require__ = {};
|
|
9
|
-
__webpack_require__.d = (exports, definition)=>{
|
|
10
|
-
for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key) && Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: !0,
|
|
12
|
-
get: definition[key]
|
|
13
|
-
});
|
|
14
|
-
}, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports)=>{
|
|
15
|
-
"u" > typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports, Symbol.toStringTag, {
|
|
16
|
-
value: 'Module'
|
|
17
|
-
}), Object.defineProperty(exports, '__esModule', {
|
|
18
|
-
value: !0
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
9
|
var chunks_namespaceObject = {};
|
|
22
10
|
__webpack_require__.r(chunks_namespaceObject), __webpack_require__.d(chunks_namespaceObject, {
|
|
23
11
|
assetsContents: ()=>assetsContents,
|
|
@@ -309,6 +297,9 @@ class Dependency {
|
|
|
309
297
|
request: this.request,
|
|
310
298
|
resolvedRequest: this.resolvedRequest,
|
|
311
299
|
kind: this.kind,
|
|
300
|
+
...void 0 !== this.typeString && {
|
|
301
|
+
typeString: this.typeString
|
|
302
|
+
},
|
|
312
303
|
module: this.module.id,
|
|
313
304
|
dependency: this.dependency.id,
|
|
314
305
|
originDependency: this.originDependency.id,
|
|
@@ -322,7 +313,72 @@ class Dependency {
|
|
|
322
313
|
function isSamePosition(po1, po2) {
|
|
323
314
|
return po1.line === po2.line && po1.column === po2.column;
|
|
324
315
|
}
|
|
316
|
+
function isSameRange(po1, po2) {
|
|
317
|
+
return !!isSamePosition(po1.start, po2.start) && (Lodash.isNil(po1.end) || Lodash.isNil(po2.end) ? Lodash.isUndefined(po1.end) && Lodash.isUndefined(po2.end) : isSamePosition(po1.end, po2.end));
|
|
318
|
+
}
|
|
325
319
|
let NAME_WITH_LOADERS = /!/, NAME_WITH_MODULES = /\s\+\s\d*\smodules$/, INVALID_CSS_PREFIX = /^css\s.*node_modules(?!\/)/;
|
|
320
|
+
function getModuleName(name) {
|
|
321
|
+
if (!name) return '';
|
|
322
|
+
if (NAME_WITH_LOADERS.test(name)) {
|
|
323
|
+
let normalizedName = Lodash.last(name.split(NAME_WITH_LOADERS));
|
|
324
|
+
if (normalizedName?.trim()) return normalizedName;
|
|
325
|
+
}
|
|
326
|
+
return NAME_WITH_MODULES.test(name) ? name.replace(NAME_WITH_MODULES, '') : INVALID_CSS_PREFIX.test(name) ? name.replace(INVALID_CSS_PREFIX, '') : name;
|
|
327
|
+
}
|
|
328
|
+
function parseLocation(location) {
|
|
329
|
+
if (!location || 'string' != typeof location) return null;
|
|
330
|
+
let s = location.trim();
|
|
331
|
+
if (!s) return null;
|
|
332
|
+
let fullRange = s.match(/^(\d+):(\d+)-(\d+):(\d+)$/);
|
|
333
|
+
if (fullRange) return {
|
|
334
|
+
startLine: parseInt(fullRange[1], 10),
|
|
335
|
+
startColumn: parseInt(fullRange[2], 10),
|
|
336
|
+
endLine: parseInt(fullRange[3], 10),
|
|
337
|
+
endColumn: parseInt(fullRange[4], 10)
|
|
338
|
+
};
|
|
339
|
+
let singleLineRange = s.match(/^(\d+):(\d+)-(\d+)$/);
|
|
340
|
+
if (singleLineRange) {
|
|
341
|
+
let startLine = parseInt(singleLineRange[1], 10);
|
|
342
|
+
return {
|
|
343
|
+
startLine,
|
|
344
|
+
startColumn: parseInt(singleLineRange[2], 10),
|
|
345
|
+
endLine: startLine,
|
|
346
|
+
endColumn: parseInt(singleLineRange[3], 10)
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
let endColOnly = s.match(/^(\d+)-(\d+):(\d+)$/);
|
|
350
|
+
if (endColOnly) return {
|
|
351
|
+
startLine: parseInt(endColOnly[1], 10),
|
|
352
|
+
startColumn: 0,
|
|
353
|
+
endLine: parseInt(endColOnly[2], 10),
|
|
354
|
+
endColumn: parseInt(endColOnly[3], 10)
|
|
355
|
+
};
|
|
356
|
+
let lineRange = s.match(/^(\d+)-(\d+)$/);
|
|
357
|
+
if (lineRange) return {
|
|
358
|
+
startLine: parseInt(lineRange[1], 10),
|
|
359
|
+
startColumn: 0,
|
|
360
|
+
endLine: parseInt(lineRange[2], 10)
|
|
361
|
+
};
|
|
362
|
+
let point = s.match(/^(\d+):(\d+)$/);
|
|
363
|
+
return point ? {
|
|
364
|
+
startLine: parseInt(point[1], 10),
|
|
365
|
+
startColumn: parseInt(point[2], 10)
|
|
366
|
+
} : null;
|
|
367
|
+
}
|
|
368
|
+
function extractCodeFromLocation(source, location) {
|
|
369
|
+
if (!source || !location) return '';
|
|
370
|
+
let lines = source.split('\n'), { startLine, startColumn: OriginalStartColumn, endLine, endColumn } = location, startColumn = OriginalStartColumn;
|
|
371
|
+
if (OriginalStartColumn && (startColumn = OriginalStartColumn - 1), !endLine || startLine === endLine) {
|
|
372
|
+
let line = lines[startLine - 1];
|
|
373
|
+
return line ? void 0 !== endColumn ? line.substring(startColumn, endColumn) : line.substring(startColumn) : '';
|
|
374
|
+
}
|
|
375
|
+
let result = [];
|
|
376
|
+
for(let i = startLine - 1; i < Math.min(endLine, lines.length); i++){
|
|
377
|
+
let line = lines[i];
|
|
378
|
+
i === startLine - 1 ? result.push(line.substring(startColumn)) : i === endLine - 1 ? result.push(void 0 !== endColumn ? line.substring(0, endColumn) : line) : result.push(line);
|
|
379
|
+
}
|
|
380
|
+
return result.join('\n');
|
|
381
|
+
}
|
|
326
382
|
class Statement {
|
|
327
383
|
static getDefaultStatement(module) {
|
|
328
384
|
let defaultPosition = {
|
|
@@ -349,8 +405,7 @@ class Statement {
|
|
|
349
405
|
this.module = module, this.position = position;
|
|
350
406
|
}
|
|
351
407
|
isSame(statement) {
|
|
352
|
-
|
|
353
|
-
return this.module.id === statement.module.id && (po1 = this.position.transformed, po2 = statement.position.transformed, !!isSamePosition(po1.start, po2.start) && (Lodash.isNil(po1.end) || Lodash.isNil(po2.end) ? Lodash.isUndefined(po1.end) && Lodash.isUndefined(po2.end) : isSamePosition(po1.end, po2.end)));
|
|
408
|
+
return this.module.id === statement.module.id && isSameRange(this.position.transformed, statement.position.transformed);
|
|
354
409
|
}
|
|
355
410
|
getSourcePosition() {
|
|
356
411
|
let { module, position } = this;
|
|
@@ -379,7 +434,7 @@ class Module {
|
|
|
379
434
|
module_id = 1;
|
|
380
435
|
}
|
|
381
436
|
constructor(webpackId, path, isEntry = !1, kind = SDK.ModuleKind.Normal, renderId, layer = ''){
|
|
382
|
-
this.issuerPath = [], this.bailoutReason = [], this.source = {
|
|
437
|
+
this.issuerPath = [], this.bailoutReason = [], this.sideEffectLocations = [], this.sideEffectCodes = [], this.source = {
|
|
383
438
|
source: '',
|
|
384
439
|
transformed: '',
|
|
385
440
|
parsedSource: ''
|
|
@@ -407,6 +462,18 @@ class Module {
|
|
|
407
462
|
getBailoutReason() {
|
|
408
463
|
return this.bailoutReason;
|
|
409
464
|
}
|
|
465
|
+
addSideEffectLocation(location) {
|
|
466
|
+
this.sideEffectLocations.push(location);
|
|
467
|
+
}
|
|
468
|
+
getSideEffectLocations() {
|
|
469
|
+
return this.sideEffectLocations.slice();
|
|
470
|
+
}
|
|
471
|
+
addSideEffectCode(codeData) {
|
|
472
|
+
this.sideEffectCodes.push(codeData);
|
|
473
|
+
}
|
|
474
|
+
getSideEffectCodes() {
|
|
475
|
+
return this.sideEffectCodes.slice();
|
|
476
|
+
}
|
|
410
477
|
getChunks() {
|
|
411
478
|
return this.chunks.slice();
|
|
412
479
|
}
|
|
@@ -556,14 +623,7 @@ class Module {
|
|
|
556
623
|
return this.concatenationModules.slice();
|
|
557
624
|
}
|
|
558
625
|
toData(contextPath, isBrief) {
|
|
559
|
-
let { isPreferSource } = this, moduleName =
|
|
560
|
-
if (!name) return '';
|
|
561
|
-
if (NAME_WITH_LOADERS.test(name)) {
|
|
562
|
-
let normalizedName = Lodash.last(name.split(NAME_WITH_LOADERS));
|
|
563
|
-
if (normalizedName?.trim()) return normalizedName;
|
|
564
|
-
}
|
|
565
|
-
return NAME_WITH_MODULES.test(name) ? name.replace(NAME_WITH_MODULES, '') : INVALID_CSS_PREFIX.test(name) ? name.replace(INVALID_CSS_PREFIX, '') : name;
|
|
566
|
-
}(this.webpackId), data = {
|
|
626
|
+
let { isPreferSource } = this, moduleName = getModuleName(this.webpackId), data = {
|
|
567
627
|
id: this.id,
|
|
568
628
|
renderId: this.renderId,
|
|
569
629
|
webpackId: contextPath && moduleName.indexOf('.') > 0 ? path_0.relative(contextPath, moduleName) : this.webpackId,
|
|
@@ -578,7 +638,10 @@ class Module {
|
|
|
578
638
|
layer: this.layer
|
|
579
639
|
} : {},
|
|
580
640
|
issuerPath: isBrief ? void 0 : this.issuerPath?.filter((issuer)=>issuer.moduleId).map((issuer)=>issuer.moduleId) || [],
|
|
581
|
-
bailoutReason: this.bailoutReason
|
|
641
|
+
bailoutReason: this.bailoutReason,
|
|
642
|
+
...this.sideEffectLocations.length > 0 ? {
|
|
643
|
+
sideEffectLocations: this.sideEffectLocations
|
|
644
|
+
} : {}
|
|
582
645
|
};
|
|
583
646
|
return (this.meta.hasSetEsModuleStatement || this.meta.strictHarmonyModule) && (data.meta = {}, this.meta.hasSetEsModuleStatement && (data.meta.hasSetEsModuleStatement = !0), this.meta.strictHarmonyModule && (data.meta.strictHarmonyModule = !0)), this.isEntry && (data.isEntry = this.isEntry), this.modules.length > 0 && (data.modules = this.modules.map((item)=>item.id)), this.rootModule && (data.rootModule = this.rootModule.id), this.concatenationModules.length > 0 && (data.concatenationModules = this.concatenationModules.map((data)=>data.id)), data;
|
|
584
647
|
}
|
|
@@ -868,7 +931,7 @@ class ModuleGraph {
|
|
|
868
931
|
return this._moduleIdMap.size;
|
|
869
932
|
}
|
|
870
933
|
fromInstance(data) {
|
|
871
|
-
this.
|
|
934
|
+
this.setModules(data.getModules()), this.setDependencies(data.getDependencies()), this.setConnectionsOnlyImports(data.getConnectionsOnlyImports()), data instanceof ModuleGraph && (this._moduleGraphModules = new Map(data._moduleGraphModules), this._exportIdMap = new Map(data._exportIdMap), this._sideEffectIdMap = new Map(data._sideEffectIdMap), this._varIdMap = new Map(data._varIdMap), this._layers = new Map(data._layers));
|
|
872
935
|
}
|
|
873
936
|
getSubGraphByModule(module) {
|
|
874
937
|
let map = new Set(), result = [
|
|
@@ -948,6 +1011,16 @@ class ModuleGraph {
|
|
|
948
1011
|
layers: Array.from(this._layers.keys())
|
|
949
1012
|
};
|
|
950
1013
|
}
|
|
1014
|
+
toTreeShakingData() {
|
|
1015
|
+
let sideEffectCodes = {};
|
|
1016
|
+
for (let module of this.getModules()){
|
|
1017
|
+
let codes = module.getSideEffectCodes();
|
|
1018
|
+
codes.length > 0 && (sideEffectCodes[codes[0].moduleId] = codes);
|
|
1019
|
+
}
|
|
1020
|
+
return {
|
|
1021
|
+
sideEffectCodes
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
951
1024
|
toCodeData(type = SDK.ToDataType.Normal) {
|
|
952
1025
|
let codeMap = {};
|
|
953
1026
|
return this.getModules().forEach((item)=>{
|
|
@@ -972,8 +1045,14 @@ class ModuleGraph {
|
|
|
972
1045
|
d
|
|
973
1046
|
]));
|
|
974
1047
|
}
|
|
1048
|
+
setConnectionsOnlyImports(items) {
|
|
1049
|
+
this._connectionsOnlyImports = items;
|
|
1050
|
+
}
|
|
1051
|
+
getConnectionsOnlyImports() {
|
|
1052
|
+
return this._connectionsOnlyImports;
|
|
1053
|
+
}
|
|
975
1054
|
constructor(){
|
|
976
|
-
this._dependenciesIdMap = new Map(), this._moduleWebpackIdMap = new Map(), this._moduleIdMap = new Map(), this._moduleGraphModules = new Map(), this._exportIdMap = new Map(), this._sideEffectIdMap = new Map(), this._varIdMap = new Map(), this._layers = new Map();
|
|
1055
|
+
this._dependenciesIdMap = new Map(), this._connectionsOnlyImports = [], this._moduleWebpackIdMap = new Map(), this._moduleIdMap = new Map(), this._moduleGraphModules = new Map(), this._exportIdMap = new Map(), this._sideEffectIdMap = new Map(), this._varIdMap = new Map(), this._layers = new Map();
|
|
977
1056
|
}
|
|
978
1057
|
}
|
|
979
1058
|
let package_graph_dependency_id = 1;
|
|
@@ -1481,4 +1560,4 @@ function getAllModules(compilation) {
|
|
|
1481
1560
|
for (let mod of compilation.modules)modules.push(...mod.modules ?? []), modules.push(mod);
|
|
1482
1561
|
return unionBy(modules.filter((mod)=>!getWebpackModuleId(mod).startsWith('webpack/runtime')), (mod)=>getWebpackModuleId(mod));
|
|
1483
1562
|
}
|
|
1484
|
-
export { Asset, Chunk, ChunkGraph,
|
|
1563
|
+
export { Asset, Chunk, ChunkGraph, Dependency, EntryPoint, ExportInfo, Module, ModuleGraph, ModuleGraphModule, PackageDependency, PackageGraph, SideEffect, Statement, Variable, chunks_namespaceObject as Chunks, extractCodeFromLocation, getModuleName, isSamePosition, isSameRange, package_Package as Package, parseLocation, readPackageJson, trans_utils_namespaceObject as TransUtils, transform_module_graph_namespaceObject as ModuleGraphTrans, webpack_compatible_namespaceObject as Webpack };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __webpack_module_cache__ = {};
|
|
2
|
+
function __webpack_require__(moduleId) {
|
|
3
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
4
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
5
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
6
|
+
exports: {}
|
|
7
|
+
};
|
|
8
|
+
return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
|
|
9
|
+
}
|
|
10
|
+
__webpack_require__.d = (exports, definition)=>{
|
|
11
|
+
for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key) && Object.defineProperty(exports, key, {
|
|
12
|
+
enumerable: !0,
|
|
13
|
+
get: definition[key]
|
|
14
|
+
});
|
|
15
|
+
}, __webpack_require__.add = function(modules) {
|
|
16
|
+
Object.assign(__webpack_require__.m, modules);
|
|
17
|
+
}, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports)=>{
|
|
18
|
+
"u" > typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports, Symbol.toStringTag, {
|
|
19
|
+
value: 'Module'
|
|
20
|
+
}), Object.defineProperty(exports, '__esModule', {
|
|
21
|
+
value: !0
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
export { __webpack_require__ };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdoctor/graph",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/web-infra-dev/rsdoctor",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"es-toolkit": "^1.
|
|
25
|
+
"es-toolkit": "^1.45.1",
|
|
26
26
|
"path-browserify": "1.0.1",
|
|
27
27
|
"source-map": "^0.7.6",
|
|
28
|
-
"@rsdoctor/
|
|
29
|
-
"@rsdoctor/
|
|
28
|
+
"@rsdoctor/types": "1.5.4",
|
|
29
|
+
"@rsdoctor/utils": "1.5.4"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/body-parser": "1.19.6",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"fs-extra": "^11.1.1",
|
|
37
37
|
"tslib": "2.8.1",
|
|
38
38
|
"typescript": "^5.9.2",
|
|
39
|
-
"webpack": "^5.
|
|
39
|
+
"webpack": "^5.105.4"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public",
|