@rsdoctor/graph 1.5.2 → 1.5.3
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.
|
@@ -34,6 +34,7 @@ export declare class ModuleGraph implements SDK.ModuleGraphInstance {
|
|
|
34
34
|
addLayer(layer: string): void;
|
|
35
35
|
getLayers(): Map<string, number>;
|
|
36
36
|
toData(configs?: SDK.ModuleGraphToDataArgs): SDK.ModuleGraphData;
|
|
37
|
+
toTreeShakingData(): SDK.TreeShakingData;
|
|
37
38
|
toCodeData(type?: SDK.ToDataType): SDK.ModuleCodeData;
|
|
38
39
|
setModules(modules: SDK.ModuleInstance[]): void;
|
|
39
40
|
setDependencies(dependencies: SDK.DependencyInstance[]): void;
|
|
@@ -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,
|
|
@@ -361,6 +366,60 @@ function getModuleName(name) {
|
|
|
361
366
|
}
|
|
362
367
|
return NAME_WITH_MODULES.test(name) ? name.replace(NAME_WITH_MODULES, '') : INVALID_CSS_PREFIX.test(name) ? name.replace(INVALID_CSS_PREFIX, '') : name;
|
|
363
368
|
}
|
|
369
|
+
function parseLocation(location) {
|
|
370
|
+
if (!location || 'string' != typeof location) return null;
|
|
371
|
+
let s = location.trim();
|
|
372
|
+
if (!s) return null;
|
|
373
|
+
let fullRange = s.match(/^(\d+):(\d+)-(\d+):(\d+)$/);
|
|
374
|
+
if (fullRange) return {
|
|
375
|
+
startLine: parseInt(fullRange[1], 10),
|
|
376
|
+
startColumn: parseInt(fullRange[2], 10),
|
|
377
|
+
endLine: parseInt(fullRange[3], 10),
|
|
378
|
+
endColumn: parseInt(fullRange[4], 10)
|
|
379
|
+
};
|
|
380
|
+
let singleLineRange = s.match(/^(\d+):(\d+)-(\d+)$/);
|
|
381
|
+
if (singleLineRange) {
|
|
382
|
+
let startLine = parseInt(singleLineRange[1], 10);
|
|
383
|
+
return {
|
|
384
|
+
startLine,
|
|
385
|
+
startColumn: parseInt(singleLineRange[2], 10),
|
|
386
|
+
endLine: startLine,
|
|
387
|
+
endColumn: parseInt(singleLineRange[3], 10)
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
let endColOnly = s.match(/^(\d+)-(\d+):(\d+)$/);
|
|
391
|
+
if (endColOnly) return {
|
|
392
|
+
startLine: parseInt(endColOnly[1], 10),
|
|
393
|
+
startColumn: 0,
|
|
394
|
+
endLine: parseInt(endColOnly[2], 10),
|
|
395
|
+
endColumn: parseInt(endColOnly[3], 10)
|
|
396
|
+
};
|
|
397
|
+
let lineRange = s.match(/^(\d+)-(\d+)$/);
|
|
398
|
+
if (lineRange) return {
|
|
399
|
+
startLine: parseInt(lineRange[1], 10),
|
|
400
|
+
startColumn: 0,
|
|
401
|
+
endLine: parseInt(lineRange[2], 10)
|
|
402
|
+
};
|
|
403
|
+
let point = s.match(/^(\d+):(\d+)$/);
|
|
404
|
+
return point ? {
|
|
405
|
+
startLine: parseInt(point[1], 10),
|
|
406
|
+
startColumn: parseInt(point[2], 10)
|
|
407
|
+
} : null;
|
|
408
|
+
}
|
|
409
|
+
function extractCodeFromLocation(source, location) {
|
|
410
|
+
if (!source || !location) return '';
|
|
411
|
+
let lines = source.split('\n'), { startLine, startColumn: OriginalStartColumn, endLine, endColumn } = location, startColumn = OriginalStartColumn;
|
|
412
|
+
if (OriginalStartColumn && (startColumn = OriginalStartColumn - 1), !endLine || startLine === endLine) {
|
|
413
|
+
let line = lines[startLine - 1];
|
|
414
|
+
return line ? void 0 !== endColumn ? line.substring(startColumn, endColumn) : line.substring(startColumn) : '';
|
|
415
|
+
}
|
|
416
|
+
let result = [];
|
|
417
|
+
for(let i = startLine - 1; i < Math.min(endLine, lines.length); i++){
|
|
418
|
+
let line = lines[i];
|
|
419
|
+
i === startLine - 1 ? result.push(line.substring(startColumn)) : i === endLine - 1 ? result.push(void 0 !== endColumn ? line.substring(0, endColumn) : line) : result.push(line);
|
|
420
|
+
}
|
|
421
|
+
return result.join('\n');
|
|
422
|
+
}
|
|
364
423
|
class Statement {
|
|
365
424
|
static getDefaultStatement(module) {
|
|
366
425
|
let defaultPosition = {
|
|
@@ -416,7 +475,7 @@ class Module {
|
|
|
416
475
|
module_id = 1;
|
|
417
476
|
}
|
|
418
477
|
constructor(webpackId, path, isEntry = !1, kind = types_namespaceObject.SDK.ModuleKind.Normal, renderId, layer = ''){
|
|
419
|
-
this.issuerPath = [], this.bailoutReason = [], this.source = {
|
|
478
|
+
this.issuerPath = [], this.bailoutReason = [], this.sideEffectLocations = [], this.sideEffectCodes = [], this.source = {
|
|
420
479
|
source: '',
|
|
421
480
|
transformed: '',
|
|
422
481
|
parsedSource: ''
|
|
@@ -444,6 +503,18 @@ class Module {
|
|
|
444
503
|
getBailoutReason() {
|
|
445
504
|
return this.bailoutReason;
|
|
446
505
|
}
|
|
506
|
+
addSideEffectLocation(location) {
|
|
507
|
+
this.sideEffectLocations.push(location);
|
|
508
|
+
}
|
|
509
|
+
getSideEffectLocations() {
|
|
510
|
+
return this.sideEffectLocations.slice();
|
|
511
|
+
}
|
|
512
|
+
addSideEffectCode(codeData) {
|
|
513
|
+
this.sideEffectCodes.push(codeData);
|
|
514
|
+
}
|
|
515
|
+
getSideEffectCodes() {
|
|
516
|
+
return this.sideEffectCodes.slice();
|
|
517
|
+
}
|
|
447
518
|
getChunks() {
|
|
448
519
|
return this.chunks.slice();
|
|
449
520
|
}
|
|
@@ -608,7 +679,10 @@ class Module {
|
|
|
608
679
|
layer: this.layer
|
|
609
680
|
} : {},
|
|
610
681
|
issuerPath: isBrief ? void 0 : this.issuerPath?.filter((issuer)=>issuer.moduleId).map((issuer)=>issuer.moduleId) || [],
|
|
611
|
-
bailoutReason: this.bailoutReason
|
|
682
|
+
bailoutReason: this.bailoutReason,
|
|
683
|
+
...this.sideEffectLocations.length > 0 ? {
|
|
684
|
+
sideEffectLocations: this.sideEffectLocations
|
|
685
|
+
} : {}
|
|
612
686
|
};
|
|
613
687
|
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
688
|
}
|
|
@@ -978,6 +1052,16 @@ class ModuleGraph {
|
|
|
978
1052
|
layers: Array.from(this._layers.keys())
|
|
979
1053
|
};
|
|
980
1054
|
}
|
|
1055
|
+
toTreeShakingData() {
|
|
1056
|
+
let sideEffectCodes = {};
|
|
1057
|
+
for (let module of this.getModules()){
|
|
1058
|
+
let codes = module.getSideEffectCodes();
|
|
1059
|
+
codes.length > 0 && (sideEffectCodes[codes[0].moduleId] = codes);
|
|
1060
|
+
}
|
|
1061
|
+
return {
|
|
1062
|
+
sideEffectCodes
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
981
1065
|
toCodeData(type = types_namespaceObject.SDK.ToDataType.Normal) {
|
|
982
1066
|
let codeMap = {};
|
|
983
1067
|
return this.getModules().forEach((item)=>{
|
|
@@ -1523,7 +1607,7 @@ function getAllModules(compilation) {
|
|
|
1523
1607
|
for (let mod of compilation.modules)modules.push(...mod.modules ?? []), modules.push(mod);
|
|
1524
1608
|
return (0, compat_namespaceObject.unionBy)(modules.filter((mod)=>!getWebpackModuleId(mod).startsWith('webpack/runtime')), (mod)=>getWebpackModuleId(mod));
|
|
1525
1609
|
}
|
|
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 === [
|
|
1610
|
+
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
1611
|
"Asset",
|
|
1528
1612
|
"Chunk",
|
|
1529
1613
|
"ChunkGraph",
|
|
@@ -1543,6 +1627,11 @@ for(var __rspack_i in exports.Asset = __webpack_exports__.Asset, exports.Chunk =
|
|
|
1543
1627
|
"TransUtils",
|
|
1544
1628
|
"Variable",
|
|
1545
1629
|
"Webpack",
|
|
1630
|
+
"extractCodeFromLocation",
|
|
1631
|
+
"getModuleName",
|
|
1632
|
+
"isSamePosition",
|
|
1633
|
+
"isSameRange",
|
|
1634
|
+
"parseLocation",
|
|
1546
1635
|
"readPackageJson"
|
|
1547
1636
|
].indexOf(__rspack_i) && (exports[__rspack_i] = __webpack_exports__[__rspack_i]);
|
|
1548
1637
|
Object.defineProperty(exports, '__esModule', {
|
package/dist/index.js
CHANGED
|
@@ -322,7 +322,72 @@ class Dependency {
|
|
|
322
322
|
function isSamePosition(po1, po2) {
|
|
323
323
|
return po1.line === po2.line && po1.column === po2.column;
|
|
324
324
|
}
|
|
325
|
+
function isSameRange(po1, po2) {
|
|
326
|
+
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));
|
|
327
|
+
}
|
|
325
328
|
let NAME_WITH_LOADERS = /!/, NAME_WITH_MODULES = /\s\+\s\d*\smodules$/, INVALID_CSS_PREFIX = /^css\s.*node_modules(?!\/)/;
|
|
329
|
+
function getModuleName(name) {
|
|
330
|
+
if (!name) return '';
|
|
331
|
+
if (NAME_WITH_LOADERS.test(name)) {
|
|
332
|
+
let normalizedName = Lodash.last(name.split(NAME_WITH_LOADERS));
|
|
333
|
+
if (normalizedName?.trim()) return normalizedName;
|
|
334
|
+
}
|
|
335
|
+
return NAME_WITH_MODULES.test(name) ? name.replace(NAME_WITH_MODULES, '') : INVALID_CSS_PREFIX.test(name) ? name.replace(INVALID_CSS_PREFIX, '') : name;
|
|
336
|
+
}
|
|
337
|
+
function parseLocation(location) {
|
|
338
|
+
if (!location || 'string' != typeof location) return null;
|
|
339
|
+
let s = location.trim();
|
|
340
|
+
if (!s) return null;
|
|
341
|
+
let fullRange = s.match(/^(\d+):(\d+)-(\d+):(\d+)$/);
|
|
342
|
+
if (fullRange) return {
|
|
343
|
+
startLine: parseInt(fullRange[1], 10),
|
|
344
|
+
startColumn: parseInt(fullRange[2], 10),
|
|
345
|
+
endLine: parseInt(fullRange[3], 10),
|
|
346
|
+
endColumn: parseInt(fullRange[4], 10)
|
|
347
|
+
};
|
|
348
|
+
let singleLineRange = s.match(/^(\d+):(\d+)-(\d+)$/);
|
|
349
|
+
if (singleLineRange) {
|
|
350
|
+
let startLine = parseInt(singleLineRange[1], 10);
|
|
351
|
+
return {
|
|
352
|
+
startLine,
|
|
353
|
+
startColumn: parseInt(singleLineRange[2], 10),
|
|
354
|
+
endLine: startLine,
|
|
355
|
+
endColumn: parseInt(singleLineRange[3], 10)
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
let endColOnly = s.match(/^(\d+)-(\d+):(\d+)$/);
|
|
359
|
+
if (endColOnly) return {
|
|
360
|
+
startLine: parseInt(endColOnly[1], 10),
|
|
361
|
+
startColumn: 0,
|
|
362
|
+
endLine: parseInt(endColOnly[2], 10),
|
|
363
|
+
endColumn: parseInt(endColOnly[3], 10)
|
|
364
|
+
};
|
|
365
|
+
let lineRange = s.match(/^(\d+)-(\d+)$/);
|
|
366
|
+
if (lineRange) return {
|
|
367
|
+
startLine: parseInt(lineRange[1], 10),
|
|
368
|
+
startColumn: 0,
|
|
369
|
+
endLine: parseInt(lineRange[2], 10)
|
|
370
|
+
};
|
|
371
|
+
let point = s.match(/^(\d+):(\d+)$/);
|
|
372
|
+
return point ? {
|
|
373
|
+
startLine: parseInt(point[1], 10),
|
|
374
|
+
startColumn: parseInt(point[2], 10)
|
|
375
|
+
} : null;
|
|
376
|
+
}
|
|
377
|
+
function extractCodeFromLocation(source, location) {
|
|
378
|
+
if (!source || !location) return '';
|
|
379
|
+
let lines = source.split('\n'), { startLine, startColumn: OriginalStartColumn, endLine, endColumn } = location, startColumn = OriginalStartColumn;
|
|
380
|
+
if (OriginalStartColumn && (startColumn = OriginalStartColumn - 1), !endLine || startLine === endLine) {
|
|
381
|
+
let line = lines[startLine - 1];
|
|
382
|
+
return line ? void 0 !== endColumn ? line.substring(startColumn, endColumn) : line.substring(startColumn) : '';
|
|
383
|
+
}
|
|
384
|
+
let result = [];
|
|
385
|
+
for(let i = startLine - 1; i < Math.min(endLine, lines.length); i++){
|
|
386
|
+
let line = lines[i];
|
|
387
|
+
i === startLine - 1 ? result.push(line.substring(startColumn)) : i === endLine - 1 ? result.push(void 0 !== endColumn ? line.substring(0, endColumn) : line) : result.push(line);
|
|
388
|
+
}
|
|
389
|
+
return result.join('\n');
|
|
390
|
+
}
|
|
326
391
|
class Statement {
|
|
327
392
|
static getDefaultStatement(module) {
|
|
328
393
|
let defaultPosition = {
|
|
@@ -349,8 +414,7 @@ class Statement {
|
|
|
349
414
|
this.module = module, this.position = position;
|
|
350
415
|
}
|
|
351
416
|
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)));
|
|
417
|
+
return this.module.id === statement.module.id && isSameRange(this.position.transformed, statement.position.transformed);
|
|
354
418
|
}
|
|
355
419
|
getSourcePosition() {
|
|
356
420
|
let { module, position } = this;
|
|
@@ -379,7 +443,7 @@ class Module {
|
|
|
379
443
|
module_id = 1;
|
|
380
444
|
}
|
|
381
445
|
constructor(webpackId, path, isEntry = !1, kind = SDK.ModuleKind.Normal, renderId, layer = ''){
|
|
382
|
-
this.issuerPath = [], this.bailoutReason = [], this.source = {
|
|
446
|
+
this.issuerPath = [], this.bailoutReason = [], this.sideEffectLocations = [], this.sideEffectCodes = [], this.source = {
|
|
383
447
|
source: '',
|
|
384
448
|
transformed: '',
|
|
385
449
|
parsedSource: ''
|
|
@@ -407,6 +471,18 @@ class Module {
|
|
|
407
471
|
getBailoutReason() {
|
|
408
472
|
return this.bailoutReason;
|
|
409
473
|
}
|
|
474
|
+
addSideEffectLocation(location) {
|
|
475
|
+
this.sideEffectLocations.push(location);
|
|
476
|
+
}
|
|
477
|
+
getSideEffectLocations() {
|
|
478
|
+
return this.sideEffectLocations.slice();
|
|
479
|
+
}
|
|
480
|
+
addSideEffectCode(codeData) {
|
|
481
|
+
this.sideEffectCodes.push(codeData);
|
|
482
|
+
}
|
|
483
|
+
getSideEffectCodes() {
|
|
484
|
+
return this.sideEffectCodes.slice();
|
|
485
|
+
}
|
|
410
486
|
getChunks() {
|
|
411
487
|
return this.chunks.slice();
|
|
412
488
|
}
|
|
@@ -556,14 +632,7 @@ class Module {
|
|
|
556
632
|
return this.concatenationModules.slice();
|
|
557
633
|
}
|
|
558
634
|
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 = {
|
|
635
|
+
let { isPreferSource } = this, moduleName = getModuleName(this.webpackId), data = {
|
|
567
636
|
id: this.id,
|
|
568
637
|
renderId: this.renderId,
|
|
569
638
|
webpackId: contextPath && moduleName.indexOf('.') > 0 ? path_0.relative(contextPath, moduleName) : this.webpackId,
|
|
@@ -578,7 +647,10 @@ class Module {
|
|
|
578
647
|
layer: this.layer
|
|
579
648
|
} : {},
|
|
580
649
|
issuerPath: isBrief ? void 0 : this.issuerPath?.filter((issuer)=>issuer.moduleId).map((issuer)=>issuer.moduleId) || [],
|
|
581
|
-
bailoutReason: this.bailoutReason
|
|
650
|
+
bailoutReason: this.bailoutReason,
|
|
651
|
+
...this.sideEffectLocations.length > 0 ? {
|
|
652
|
+
sideEffectLocations: this.sideEffectLocations
|
|
653
|
+
} : {}
|
|
582
654
|
};
|
|
583
655
|
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
656
|
}
|
|
@@ -948,6 +1020,16 @@ class ModuleGraph {
|
|
|
948
1020
|
layers: Array.from(this._layers.keys())
|
|
949
1021
|
};
|
|
950
1022
|
}
|
|
1023
|
+
toTreeShakingData() {
|
|
1024
|
+
let sideEffectCodes = {};
|
|
1025
|
+
for (let module of this.getModules()){
|
|
1026
|
+
let codes = module.getSideEffectCodes();
|
|
1027
|
+
codes.length > 0 && (sideEffectCodes[codes[0].moduleId] = codes);
|
|
1028
|
+
}
|
|
1029
|
+
return {
|
|
1030
|
+
sideEffectCodes
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
951
1033
|
toCodeData(type = SDK.ToDataType.Normal) {
|
|
952
1034
|
let codeMap = {};
|
|
953
1035
|
return this.getModules().forEach((item)=>{
|
|
@@ -1481,4 +1563,4 @@ function getAllModules(compilation) {
|
|
|
1481
1563
|
for (let mod of compilation.modules)modules.push(...mod.modules ?? []), modules.push(mod);
|
|
1482
1564
|
return unionBy(modules.filter((mod)=>!getWebpackModuleId(mod).startsWith('webpack/runtime')), (mod)=>getWebpackModuleId(mod));
|
|
1483
1565
|
}
|
|
1484
|
-
export { Asset, Chunk, ChunkGraph, chunks_namespaceObject as Chunks, Dependency, EntryPoint, ExportInfo, Module, ModuleGraph, ModuleGraphModule, transform_module_graph_namespaceObject as ModuleGraphTrans, package_Package as Package, PackageDependency, PackageGraph, SideEffect, Statement, trans_utils_namespaceObject as TransUtils, Variable, webpack_compatible_namespaceObject as Webpack, readPackageJson };
|
|
1566
|
+
export { Asset, Chunk, ChunkGraph, chunks_namespaceObject as Chunks, Dependency, EntryPoint, ExportInfo, Module, ModuleGraph, ModuleGraphModule, transform_module_graph_namespaceObject as ModuleGraphTrans, package_Package as Package, PackageDependency, PackageGraph, SideEffect, Statement, trans_utils_namespaceObject as TransUtils, Variable, webpack_compatible_namespaceObject as Webpack, extractCodeFromLocation, getModuleName, isSamePosition, isSameRange, parseLocation, readPackageJson };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdoctor/graph",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
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.44.0",
|
|
26
26
|
"path-browserify": "1.0.1",
|
|
27
27
|
"source-map": "^0.7.6",
|
|
28
|
-
"@rsdoctor/types": "1.5.
|
|
29
|
-
"@rsdoctor/utils": "1.5.
|
|
28
|
+
"@rsdoctor/types": "1.5.3",
|
|
29
|
+
"@rsdoctor/utils": "1.5.3"
|
|
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.3"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public",
|