@rsdoctor/core 0.0.2-beta.0
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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/build-utils/build/chunks/assetsModules.d.ts +3 -0
- package/dist/build-utils/build/chunks/assetsModules.js +32 -0
- package/dist/build-utils/build/chunks/chunkTransform.d.ts +4 -0
- package/dist/build-utils/build/chunks/chunkTransform.js +31 -0
- package/dist/build-utils/build/chunks/generateTileGraph.d.ts +10 -0
- package/dist/build-utils/build/chunks/generateTileGraph.js +77 -0
- package/dist/build-utils/build/chunks/index.d.ts +3 -0
- package/dist/build-utils/build/chunks/index.js +26 -0
- package/dist/build-utils/build/index.d.ts +4 -0
- package/dist/build-utils/build/index.js +47 -0
- package/dist/build-utils/build/module-graph/index.d.ts +3 -0
- package/dist/build-utils/build/module-graph/index.js +26 -0
- package/dist/build-utils/build/module-graph/parser.d.ts +2 -0
- package/dist/build-utils/build/module-graph/parser.js +44 -0
- package/dist/build-utils/build/module-graph/transform.d.ts +4 -0
- package/dist/build-utils/build/module-graph/transform.js +37 -0
- package/dist/build-utils/build/module-graph/treeShaking.d.ts +3 -0
- package/dist/build-utils/build/module-graph/treeShaking.js +130 -0
- package/dist/build-utils/build/module-graph/utils.d.ts +3 -0
- package/dist/build-utils/build/module-graph/utils.js +113 -0
- package/dist/build-utils/build/module-graph/webpack/transform.d.ts +11 -0
- package/dist/build-utils/build/module-graph/webpack/transform.js +197 -0
- package/dist/build-utils/build/utils/index.d.ts +3 -0
- package/dist/build-utils/build/utils/index.js +26 -0
- package/dist/build-utils/build/utils/loader.d.ts +12 -0
- package/dist/build-utils/build/utils/loader.js +210 -0
- package/dist/build-utils/build/utils/parseBundle.d.ts +12 -0
- package/dist/build-utils/build/utils/parseBundle.js +277 -0
- package/dist/build-utils/build/utils/plugin.d.ts +5 -0
- package/dist/build-utils/build/utils/plugin.js +63 -0
- package/dist/build-utils/common/chunks/assetsContent.d.ts +4 -0
- package/dist/build-utils/common/chunks/assetsContent.js +34 -0
- package/dist/build-utils/common/chunks/assetsModules.d.ts +23 -0
- package/dist/build-utils/common/chunks/assetsModules.js +106 -0
- package/dist/build-utils/common/chunks/chunkTransform.d.ts +5 -0
- package/dist/build-utils/common/chunks/chunkTransform.js +73 -0
- package/dist/build-utils/common/chunks/index.d.ts +3 -0
- package/dist/build-utils/common/chunks/index.js +26 -0
- package/dist/build-utils/common/index.d.ts +5 -0
- package/dist/build-utils/common/index.js +50 -0
- package/dist/build-utils/common/module-graph/compatible.d.ts +9 -0
- package/dist/build-utils/common/module-graph/compatible.js +63 -0
- package/dist/build-utils/common/module-graph/index.d.ts +3 -0
- package/dist/build-utils/common/module-graph/index.js +26 -0
- package/dist/build-utils/common/module-graph/transform.d.ts +10 -0
- package/dist/build-utils/common/module-graph/transform.js +193 -0
- package/dist/build-utils/common/module-graph/utils.d.ts +17 -0
- package/dist/build-utils/common/module-graph/utils.js +62 -0
- package/dist/build-utils/common/trans-utils/index.d.ts +1 -0
- package/dist/build-utils/common/trans-utils/index.js +22 -0
- package/dist/build-utils/common/trans-utils/transStats.d.ts +6 -0
- package/dist/build-utils/common/trans-utils/transStats.js +35 -0
- package/dist/build-utils/common/webpack/compatible.d.ts +26 -0
- package/dist/build-utils/common/webpack/compatible.js +181 -0
- package/dist/build-utils/index.d.ts +2 -0
- package/dist/build-utils/index.js +41 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +43 -0
- package/dist/inner-plugins/constants.d.ts +6 -0
- package/dist/inner-plugins/constants.js +52 -0
- package/dist/inner-plugins/index.d.ts +2 -0
- package/dist/inner-plugins/index.js +24 -0
- package/dist/inner-plugins/loaders/proxy.d.ts +4 -0
- package/dist/inner-plugins/loaders/proxy.js +115 -0
- package/dist/inner-plugins/plugins/base.d.ts +13 -0
- package/dist/inner-plugins/plugins/base.js +45 -0
- package/dist/inner-plugins/plugins/errors.d.ts +11 -0
- package/dist/inner-plugins/plugins/errors.js +85 -0
- package/dist/inner-plugins/plugins/index.d.ts +6 -0
- package/dist/inner-plugins/plugins/index.js +32 -0
- package/dist/inner-plugins/plugins/loader.d.ts +11 -0
- package/dist/inner-plugins/plugins/loader.js +157 -0
- package/dist/inner-plugins/plugins/plugins.d.ts +8 -0
- package/dist/inner-plugins/plugins/plugins.js +60 -0
- package/dist/inner-plugins/plugins/progress.d.ts +8 -0
- package/dist/inner-plugins/plugins/progress.js +59 -0
- package/dist/inner-plugins/plugins/summary.d.ts +14 -0
- package/dist/inner-plugins/plugins/summary.js +115 -0
- package/dist/inner-plugins/utils/circleDetect.d.ts +4 -0
- package/dist/inner-plugins/utils/circleDetect.js +42 -0
- package/dist/inner-plugins/utils/config.d.ts +7 -0
- package/dist/inner-plugins/utils/config.js +145 -0
- package/dist/inner-plugins/utils/index.d.ts +5 -0
- package/dist/inner-plugins/utils/index.js +30 -0
- package/dist/inner-plugins/utils/loader.d.ts +11 -0
- package/dist/inner-plugins/utils/loader.js +201 -0
- package/dist/inner-plugins/utils/plugin.d.ts +5 -0
- package/dist/inner-plugins/utils/plugin.js +126 -0
- package/dist/inner-plugins/utils/sdk.d.ts +3 -0
- package/dist/inner-plugins/utils/sdk.js +36 -0
- package/dist/rules/index.d.ts +3 -0
- package/dist/rules/index.js +33 -0
- package/dist/rules/linter.d.ts +13 -0
- package/dist/rules/linter.js +74 -0
- package/dist/rules/rule.d.ts +31 -0
- package/dist/rules/rule.js +140 -0
- package/dist/rules/rules/default-import-check/index.d.ts +4 -0
- package/dist/rules/rules/default-import-check/index.js +124 -0
- package/dist/rules/rules/default-import-check/types.d.ts +4 -0
- package/dist/rules/rules/default-import-check/types.js +16 -0
- package/dist/rules/rules/default-import-check/utils.d.ts +10 -0
- package/dist/rules/rules/default-import-check/utils.js +93 -0
- package/dist/rules/rules/duplicate-package/index.d.ts +4 -0
- package/dist/rules/rules/duplicate-package/index.js +71 -0
- package/dist/rules/rules/duplicate-package/types.d.ts +24 -0
- package/dist/rules/rules/duplicate-package/types.js +51 -0
- package/dist/rules/rules/duplicate-package/utils.d.ts +3 -0
- package/dist/rules/rules/duplicate-package/utils.js +89 -0
- package/dist/rules/rules/ecma-version-check/index.d.ts +4 -0
- package/dist/rules/rules/ecma-version-check/index.js +82 -0
- package/dist/rules/rules/ecma-version-check/types.d.ts +7 -0
- package/dist/rules/rules/ecma-version-check/types.js +16 -0
- package/dist/rules/rules/ecma-version-check/utils.d.ts +2 -0
- package/dist/rules/rules/ecma-version-check/utils.js +31 -0
- package/dist/rules/rules/index.d.ts +1 -0
- package/dist/rules/rules/index.js +37 -0
- package/dist/rules/rules/loader-performance-optimization/index.d.ts +4 -0
- package/dist/rules/rules/loader-performance-optimization/index.js +121 -0
- package/dist/rules/rules/loader-performance-optimization/types.d.ts +22 -0
- package/dist/rules/rules/loader-performance-optimization/types.js +16 -0
- package/dist/rules/rules/loader-performance-optimization/utils.d.ts +1 -0
- package/dist/rules/rules/loader-performance-optimization/utils.js +38 -0
- package/dist/rules/utils.d.ts +3 -0
- package/dist/rules/utils.js +44 -0
- package/dist/types/chunks.d.ts +11 -0
- package/dist/types/chunks.js +16 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +30 -0
- package/dist/types/loader.d.ts +19 -0
- package/dist/types/loader.js +16 -0
- package/dist/types/plugin.d.ts +72 -0
- package/dist/types/plugin.js +16 -0
- package/dist/types/rules.d.ts +7 -0
- package/dist/types/rules.js +16 -0
- package/dist/types/webpack.d.ts +14 -0
- package/dist/types/webpack.js +16 -0
- package/package.json +87 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var common_exports = {};
|
|
30
|
+
__export(common_exports, {
|
|
31
|
+
Chunks: () => Chunks,
|
|
32
|
+
ModuleGraph: () => ModuleGraph,
|
|
33
|
+
TransUtils: () => TransUtils,
|
|
34
|
+
Types: () => Types,
|
|
35
|
+
Webpack: () => Webpack
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(common_exports);
|
|
38
|
+
var Chunks = __toESM(require("./chunks"));
|
|
39
|
+
var Types = __toESM(require("../../types"));
|
|
40
|
+
var ModuleGraph = __toESM(require("./module-graph"));
|
|
41
|
+
var TransUtils = __toESM(require("./trans-utils"));
|
|
42
|
+
var Webpack = __toESM(require("./webpack/compatible"));
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
Chunks,
|
|
46
|
+
ModuleGraph,
|
|
47
|
+
TransUtils,
|
|
48
|
+
Types,
|
|
49
|
+
Webpack
|
|
50
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Plugin, SDK } from '@rsdoctor/types';
|
|
2
|
+
/**
|
|
3
|
+
* Reverse decode the location (loc) information.
|
|
4
|
+
* baseon
|
|
5
|
+
* // TODO::
|
|
6
|
+
* @link https://github.com/webpack/webpack/blob/main/lib/formatLocation.js#L30-L66
|
|
7
|
+
*/
|
|
8
|
+
export declare function getPositionByStatsLocation(loc: string): SDK.SourceRange | undefined;
|
|
9
|
+
export declare function isWebpack5orRspack(compilation: Plugin.BaseCompilation): Boolean;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var compatible_exports = {};
|
|
20
|
+
__export(compatible_exports, {
|
|
21
|
+
getPositionByStatsLocation: () => getPositionByStatsLocation,
|
|
22
|
+
isWebpack5orRspack: () => isWebpack5orRspack
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(compatible_exports);
|
|
25
|
+
function getPositionByStatsLocation(loc) {
|
|
26
|
+
function formatPosition(loc2) {
|
|
27
|
+
const [line, column] = loc2.split(":");
|
|
28
|
+
return { line: Number(line), column: Number(column) };
|
|
29
|
+
}
|
|
30
|
+
if (loc.includes("-")) {
|
|
31
|
+
const positionString = loc.split("-");
|
|
32
|
+
const start = formatPosition(positionString[0]);
|
|
33
|
+
const end = formatPosition(positionString[1]);
|
|
34
|
+
return {
|
|
35
|
+
start,
|
|
36
|
+
end: Number.isNaN(end.column) ? {
|
|
37
|
+
line: start.line,
|
|
38
|
+
column: end.line
|
|
39
|
+
} : end
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (loc.includes(":")) {
|
|
43
|
+
return {
|
|
44
|
+
start: formatPosition(loc)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (loc.includes("[")) {
|
|
48
|
+
const result = loc.match(/\[(\d+)\]/);
|
|
49
|
+
return {
|
|
50
|
+
start: {
|
|
51
|
+
index: Number(result[1])
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function isWebpack5orRspack(compilation) {
|
|
57
|
+
return "moduleGraph" in compilation && Boolean(compilation.moduleGraph);
|
|
58
|
+
}
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
getPositionByStatsLocation,
|
|
62
|
+
isWebpack5orRspack
|
|
63
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var module_graph_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(module_graph_exports);
|
|
18
|
+
__reExport(module_graph_exports, require("./transform"), module.exports);
|
|
19
|
+
__reExport(module_graph_exports, require("./compatible"), module.exports);
|
|
20
|
+
__reExport(module_graph_exports, require("./utils"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("./transform"),
|
|
24
|
+
...require("./compatible"),
|
|
25
|
+
...require("./utils")
|
|
26
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from '@rsdoctor/types';
|
|
2
|
+
import { ModuleGraph, ChunkGraph } from '@rsdoctor/graph';
|
|
3
|
+
export declare function getModulesFromArray(modules: Plugin.StatsModule[], collectedModules: Plugin.StatsModule[]): void;
|
|
4
|
+
/**
|
|
5
|
+
* this function can run in browser & node.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getModuleGraphByStats({
|
|
8
|
+
modules,
|
|
9
|
+
chunks
|
|
10
|
+
}: Plugin.StatsCompilation, root: string, chunkGraph: ChunkGraph): ModuleGraph;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var transform_exports = {};
|
|
30
|
+
__export(transform_exports, {
|
|
31
|
+
getModuleGraphByStats: () => getModuleGraphByStats,
|
|
32
|
+
getModulesFromArray: () => getModulesFromArray
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(transform_exports);
|
|
35
|
+
var import_types = require("@rsdoctor/types");
|
|
36
|
+
var import_path_browserify = __toESM(require("path-browserify"));
|
|
37
|
+
var import_graph = require("@rsdoctor/graph");
|
|
38
|
+
var import_utils = require("./utils");
|
|
39
|
+
var import_compatible = require("./compatible");
|
|
40
|
+
function getCanSkip(data) {
|
|
41
|
+
if (!data.identifier || !(data?.nameForCondition || data.name) || data.identifier.startsWith("webpack/runtime") || data?.name?.startsWith("(webpack)")) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function getGetModuleName(root, data) {
|
|
46
|
+
if (data.nameForCondition) {
|
|
47
|
+
return data.nameForCondition.replace("\0", "");
|
|
48
|
+
}
|
|
49
|
+
const name = data.name.replace(/ ?\+ ?\d+ ?modules$/, "");
|
|
50
|
+
return import_path_browserify.default.isAbsolute(name) ? name : import_path_browserify.default.join(root, name);
|
|
51
|
+
}
|
|
52
|
+
function getModuleFromChildren(module2, collectedModules) {
|
|
53
|
+
if (module2.type === "module" || typeof module2.type === "undefined") {
|
|
54
|
+
collectedModules.push(module2);
|
|
55
|
+
} else if ("children" in module2 && module2.children) {
|
|
56
|
+
getModulesFromArray(
|
|
57
|
+
module2.children,
|
|
58
|
+
collectedModules
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function getModulesFromArray(modules, collectedModules) {
|
|
63
|
+
modules.forEach((module2) => {
|
|
64
|
+
getModuleFromChildren(module2, collectedModules);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function getModulesFromChunks(chunks, collectedModules) {
|
|
68
|
+
chunks?.forEach((chunk) => {
|
|
69
|
+
if (chunk.modules?.length) {
|
|
70
|
+
collectedModules.push(...chunk.modules);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function getModuleGraphByStats({ modules, chunks }, root, chunkGraph) {
|
|
75
|
+
import_graph.ModuleGraph.init();
|
|
76
|
+
const moduleGraph = new import_graph.ModuleGraph();
|
|
77
|
+
const allModules = [];
|
|
78
|
+
const collectedModules = [];
|
|
79
|
+
getModulesFromArray(modules ?? [], collectedModules);
|
|
80
|
+
getModulesFromChunks(chunks ?? [], collectedModules);
|
|
81
|
+
for (const data of collectedModules ?? []) {
|
|
82
|
+
if (getCanSkip(data)) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (moduleGraph.getModuleByWebpackId(data.identifier)) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
allModules.push(data);
|
|
89
|
+
const isConcatenated = Boolean(data.modules && data.modules.length > 0);
|
|
90
|
+
const concatenatedModule = new import_graph.Module(
|
|
91
|
+
data.identifier,
|
|
92
|
+
getGetModuleName(root, data),
|
|
93
|
+
data.depth === 0,
|
|
94
|
+
isConcatenated ? import_types.SDK.ModuleKind.Concatenation : import_types.SDK.ModuleKind.Normal
|
|
95
|
+
);
|
|
96
|
+
data.chunks?.forEach((_chunkId) => {
|
|
97
|
+
const chunk = chunkGraph.getChunkById(String(_chunkId));
|
|
98
|
+
chunk && concatenatedModule.addChunk(chunk);
|
|
99
|
+
});
|
|
100
|
+
moduleGraph.addModule(concatenatedModule);
|
|
101
|
+
if (data.source) {
|
|
102
|
+
concatenatedModule.setSource({
|
|
103
|
+
transformed: Buffer.isBuffer(data.source) ? data.source.toString() : data.source
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (typeof data.size === "number") {
|
|
107
|
+
concatenatedModule.setSize({
|
|
108
|
+
sourceSize: data.size,
|
|
109
|
+
transformedSize: data.size
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
for (const normal of data.modules ?? []) {
|
|
113
|
+
if (getCanSkip(normal)) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
allModules.push(normal);
|
|
117
|
+
const webpackId = normal.identifier;
|
|
118
|
+
const normalModule = moduleGraph.getModuleByWebpackId(webpackId) ?? new import_graph.Module(
|
|
119
|
+
webpackId,
|
|
120
|
+
getGetModuleName(root, normal),
|
|
121
|
+
normal.depth === 0,
|
|
122
|
+
import_types.SDK.ModuleKind.Normal
|
|
123
|
+
);
|
|
124
|
+
normal.chunks?.forEach((_chunkId) => {
|
|
125
|
+
const chunk = chunkGraph.getChunkById(String(_chunkId));
|
|
126
|
+
chunk && normalModule.addChunk(chunk);
|
|
127
|
+
});
|
|
128
|
+
if (normal.source) {
|
|
129
|
+
normalModule.setSource({
|
|
130
|
+
transformed: Buffer.isBuffer(normal.source) ? normal.source.toString() : normal.source
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (typeof normal.size === "number") {
|
|
134
|
+
normalModule.setSize({
|
|
135
|
+
sourceSize: normal.size,
|
|
136
|
+
transformedSize: normal.size
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
moduleGraph.addModule(normalModule);
|
|
140
|
+
concatenatedModule.addNormalModule(normalModule);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
for (const module2 of allModules) {
|
|
144
|
+
const currentModule = moduleGraph.getModuleByWebpackId(
|
|
145
|
+
module2.identifier ?? ""
|
|
146
|
+
);
|
|
147
|
+
if (!currentModule) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const dependencies = (module2.reasons ?? []).filter(import_utils.isImportDependency).filter((item) => Boolean(item.moduleIdentifier && item.userRequest));
|
|
151
|
+
(module2.reasons ?? []).filter((item) => item.type === "from origin").forEach(
|
|
152
|
+
(dep) => dep?.children?.forEach(
|
|
153
|
+
(_d) => dependencies.push({ ...dep, ..._d, children: void 0 })
|
|
154
|
+
)
|
|
155
|
+
);
|
|
156
|
+
for (const dep of dependencies) {
|
|
157
|
+
const rawRequest = dep.userRequest;
|
|
158
|
+
const requestModule = moduleGraph.getModuleByWebpackId(
|
|
159
|
+
dep.moduleIdentifier
|
|
160
|
+
);
|
|
161
|
+
if (!requestModule) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (!requestModule.getDependencyByRequest(rawRequest)) {
|
|
165
|
+
const data = requestModule.addDependency(
|
|
166
|
+
rawRequest,
|
|
167
|
+
currentModule,
|
|
168
|
+
(0, import_utils.getImportKind)(dep)
|
|
169
|
+
);
|
|
170
|
+
if (data) {
|
|
171
|
+
moduleGraph.addDependency(data);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const dependency = requestModule.getDependencyByRequest(rawRequest);
|
|
175
|
+
if (dependency && dep?.loc) {
|
|
176
|
+
const position = (0, import_compatible.getPositionByStatsLocation)(dep.loc);
|
|
177
|
+
if (position) {
|
|
178
|
+
dependency.addStatement(
|
|
179
|
+
new import_graph.Statement(requestModule, {
|
|
180
|
+
transformed: position
|
|
181
|
+
})
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return moduleGraph;
|
|
188
|
+
}
|
|
189
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
190
|
+
0 && (module.exports = {
|
|
191
|
+
getModuleGraphByStats,
|
|
192
|
+
getModulesFromArray
|
|
193
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SDK } from '@rsdoctor/types';
|
|
2
|
+
import type { ModuleGraph } from '@rsdoctor/graph';
|
|
3
|
+
interface DependencyData {
|
|
4
|
+
type?: string;
|
|
5
|
+
}
|
|
6
|
+
/** Determine whether it is the import statement itself */
|
|
7
|
+
export declare function isImportDependency({
|
|
8
|
+
type
|
|
9
|
+
}: DependencyData): boolean;
|
|
10
|
+
export declare function getImportKind(dep: DependencyData): SDK.DependencyKind;
|
|
11
|
+
/**
|
|
12
|
+
* Remove the css module without connection
|
|
13
|
+
* - This will happen when the user uses the mini-css plug-in.
|
|
14
|
+
*/
|
|
15
|
+
export declare function removeNoImportStyle(graph: ModuleGraph): void;
|
|
16
|
+
export declare function isStyleExt(path: string): boolean;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
getImportKind: () => getImportKind,
|
|
22
|
+
isImportDependency: () => isImportDependency,
|
|
23
|
+
isStyleExt: () => isStyleExt,
|
|
24
|
+
removeNoImportStyle: () => removeNoImportStyle
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(utils_exports);
|
|
27
|
+
var import_types = require("@rsdoctor/types");
|
|
28
|
+
function isImportDependency({ type }) {
|
|
29
|
+
return type === "harmony side effect evaluation" || type === "cjs require" || type === "cjs full require" || type === "cjs export require" || type === "provided" || type === "esm import";
|
|
30
|
+
}
|
|
31
|
+
function getImportKind(dep) {
|
|
32
|
+
const { type } = dep;
|
|
33
|
+
if (!type) {
|
|
34
|
+
return import_types.SDK.DependencyKind.Unknown;
|
|
35
|
+
}
|
|
36
|
+
if (type.includes("harmony")) {
|
|
37
|
+
return import_types.SDK.DependencyKind.ImportStatement;
|
|
38
|
+
}
|
|
39
|
+
if (type.includes("cjs")) {
|
|
40
|
+
return import_types.SDK.DependencyKind.RequireCall;
|
|
41
|
+
}
|
|
42
|
+
if (type.includes("import()")) {
|
|
43
|
+
return import_types.SDK.DependencyKind.DynamicImport;
|
|
44
|
+
}
|
|
45
|
+
if (type.includes("amd")) {
|
|
46
|
+
return import_types.SDK.DependencyKind.AMDRequire;
|
|
47
|
+
}
|
|
48
|
+
return import_types.SDK.DependencyKind.Unknown;
|
|
49
|
+
}
|
|
50
|
+
function removeNoImportStyle(graph) {
|
|
51
|
+
graph.getModules().filter((module2) => isStyleExt(module2.path)).filter((item) => item.getImported().length === 0).forEach((item) => graph.removeModule(item));
|
|
52
|
+
}
|
|
53
|
+
function isStyleExt(path) {
|
|
54
|
+
return /\.(c|le|sa|sc)ss(\?.*)?$/.test(path);
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
getImportKind,
|
|
59
|
+
isImportDependency,
|
|
60
|
+
isStyleExt,
|
|
61
|
+
removeNoImportStyle
|
|
62
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './transStats';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var trans_utils_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(trans_utils_exports);
|
|
18
|
+
__reExport(trans_utils_exports, require("./transStats"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./transStats")
|
|
22
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var transStats_exports = {};
|
|
20
|
+
__export(transStats_exports, {
|
|
21
|
+
transStats: () => transStats
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(transStats_exports);
|
|
24
|
+
var import__ = require("..");
|
|
25
|
+
async function transStats(json) {
|
|
26
|
+
const chunkGraph = import__.Chunks.chunkTransform(/* @__PURE__ */ new Map(), json);
|
|
27
|
+
const moduleGraph = import__.ModuleGraph.getModuleGraphByStats(json, ".", chunkGraph);
|
|
28
|
+
const assetsModuleMap = await import__.Chunks.getAssetsModulesData(json, json.outputPath || "", {}) || {};
|
|
29
|
+
import__.Chunks.transformAssetsModulesData(assetsModuleMap, moduleGraph);
|
|
30
|
+
return { chunkGraph, moduleGraph };
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
transStats
|
|
35
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SDK } from '@rsdoctor/types';
|
|
2
|
+
import { ModuleGraph as SdkModuleGraph, Module as SdkModule, Statement } from '@rsdoctor/graph';
|
|
3
|
+
import { Compilation, Dependency, ExternalModule, Module, ModuleGraph, NormalModule } from 'webpack';
|
|
4
|
+
import type { EntryPoint, ExportInfo } from "../../../types/index.d";
|
|
5
|
+
export declare function isNormalModule(mod: Module): mod is NormalModule;
|
|
6
|
+
export declare function getWebpackModuleId(mod: Module): string;
|
|
7
|
+
export declare function getWebpackModulePath(mod: NormalModule): string;
|
|
8
|
+
export declare function getWebpackDependencyRequest(dep: Dependency, module?: NormalModule): string;
|
|
9
|
+
export declare function getResolveRequest(dep: Dependency, graph: ModuleGraph): string;
|
|
10
|
+
export declare function isExternalModule(mod: Module): mod is ExternalModule;
|
|
11
|
+
export declare function getModuleSource(mod: NormalModule): string;
|
|
12
|
+
export declare function getResolveModule(dep: Dependency, graph?: ModuleGraph): Module | null;
|
|
13
|
+
export declare function getEntryModule(entryMap: Map<string, EntryPoint>): NormalModule[];
|
|
14
|
+
/**
|
|
15
|
+
* Get the type of dependencies between modules.
|
|
16
|
+
* This property can determine what runtime webpack has added to the modules.
|
|
17
|
+
* In webpack 5, it can be directly obtained using internal APIs.
|
|
18
|
+
* In webpack 4, manual conversion is required. Since webpack 4 is not as strict as webpack 5 in terms of compatibility, we can follow the logic of webpack 5 here.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getModuleExportsType(module: NormalModule, moduleGraph?: ModuleGraph, strict?: boolean): SDK.DependencyBuildMeta['exportsType'];
|
|
21
|
+
export declare function getDependencyPosition(dep: Dependency, module: SdkModule, getSource?: boolean): Statement | undefined;
|
|
22
|
+
export declare function getExportDependency(info: ExportInfo, module: NormalModule): Dependency | undefined;
|
|
23
|
+
export declare function getSdkDependencyByWebpackDependency(dep: Dependency, module: NormalModule, graph: SdkModuleGraph): import("@rsdoctor/graph").Dependency | undefined;
|
|
24
|
+
export declare function getExportStatement(info: ExportInfo, normalModule: NormalModule, graph: SdkModuleGraph): Statement | undefined;
|
|
25
|
+
export declare function getLastExportInfo(info: ExportInfo, webpackGraph: ModuleGraph): ExportInfo | undefined;
|
|
26
|
+
export declare function getAllModules(compilation: Compilation): NormalModule[];
|