@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Rsdoctor
|
|
2
|
+
|
|
3
|
+
Rsdoctor is a tool for diagnosing and analyzing the build process and build artifacts to help developers quickly identify and solve problems.
|
|
4
|
+
|
|
5
|
+
It also supports Webpack and Rspack builders, as well as various build frameworks, such as Rsbuild.
|
|
6
|
+
|
|
7
|
+
## Documentation
|
|
8
|
+
|
|
9
|
+
## Contributing
|
|
10
|
+
|
|
11
|
+
Please read the [Contributing Guide](https://github.com/web-infra-dev/rsdoctor/blob/main/CONTRIBUTING.md).
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
Rsdoctor is [MIT licensed](https://github.com/web-infra-dev/rsdoctor/blob/main/LICENSE).
|
|
@@ -0,0 +1,32 @@
|
|
|
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 assetsModules_exports = {};
|
|
20
|
+
__export(assetsModules_exports, {
|
|
21
|
+
getAssetsModulesData: () => getAssetsModulesData
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(assetsModules_exports);
|
|
24
|
+
var import_chunks = require("../../common/chunks");
|
|
25
|
+
var import_utils = require("../utils");
|
|
26
|
+
async function getAssetsModulesData(bundleStats, bundleDir) {
|
|
27
|
+
return (0, import_chunks.getAssetsModulesData)(bundleStats, bundleDir, { parseBundle: import_utils.parseBundle });
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
getAssetsModulesData
|
|
32
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
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 chunkTransform_exports = {};
|
|
20
|
+
__export(chunkTransform_exports, {
|
|
21
|
+
chunkTransform: () => chunkTransform
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(chunkTransform_exports);
|
|
24
|
+
var import_chunks = require("../../common/chunks");
|
|
25
|
+
function chunkTransform(assetMap, bundleStats) {
|
|
26
|
+
return (0, import_chunks.chunkTransform)(assetMap, bundleStats);
|
|
27
|
+
}
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
chunkTransform
|
|
31
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin } from '@rsdoctor/types';
|
|
2
|
+
export declare const TileGraphReportName = "rsdoctor-tile-graph.html";
|
|
3
|
+
type IGenerateReportOpts = {
|
|
4
|
+
reportFilename: string;
|
|
5
|
+
reportTitle?: string;
|
|
6
|
+
bundleDir?: string;
|
|
7
|
+
openBrowser?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function generateTileGraph(bundleStats: Plugin.BaseStats, opts: IGenerateReportOpts, buildOutputPath: string): Promise<string | null>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
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 generateTileGraph_exports = {};
|
|
30
|
+
__export(generateTileGraph_exports, {
|
|
31
|
+
TileGraphReportName: () => TileGraphReportName,
|
|
32
|
+
generateTileGraph: () => generateTileGraph
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(generateTileGraph_exports);
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_fs = __toESM(require("fs"));
|
|
37
|
+
var import_logger = require("@rsdoctor/utils/logger");
|
|
38
|
+
var import_viewer = require("webpack-bundle-analyzer/lib/viewer");
|
|
39
|
+
var import_constants = require("@rsdoctor/types/dist/constants");
|
|
40
|
+
const TileGraphReportName = "rsdoctor-tile-graph.html";
|
|
41
|
+
async function generateJSONReportUtil(bundleStats, opts) {
|
|
42
|
+
await (0, import_viewer.generateReport)(bundleStats, {
|
|
43
|
+
...opts,
|
|
44
|
+
logger: {
|
|
45
|
+
warn: () => {
|
|
46
|
+
},
|
|
47
|
+
info: () => {
|
|
48
|
+
},
|
|
49
|
+
error: (e) => {
|
|
50
|
+
console.log(e);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async function generateTileGraph(bundleStats, opts, buildOutputPath) {
|
|
56
|
+
try {
|
|
57
|
+
const tileReportHtmlDir = import_path.default.join(buildOutputPath, import_constants.DoctorOutputFolder);
|
|
58
|
+
if (!import_fs.default.existsSync(tileReportHtmlDir)) {
|
|
59
|
+
import_fs.default.mkdirSync(tileReportHtmlDir);
|
|
60
|
+
}
|
|
61
|
+
const { reportFilename } = opts;
|
|
62
|
+
await generateJSONReportUtil(bundleStats, {
|
|
63
|
+
...opts,
|
|
64
|
+
openBrowser: false,
|
|
65
|
+
bundleDir: tileReportHtmlDir
|
|
66
|
+
});
|
|
67
|
+
return import_path.default.join(tileReportHtmlDir, `${reportFilename}`);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
(0, import_logger.debug)(() => `Generate webpack-bundle-analyzer tile graph has error:${e}`);
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {
|
|
75
|
+
TileGraphReportName,
|
|
76
|
+
generateTileGraph
|
|
77
|
+
});
|
|
@@ -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 chunks_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(chunks_exports);
|
|
18
|
+
__reExport(chunks_exports, require("./assetsModules"), module.exports);
|
|
19
|
+
__reExport(chunks_exports, require("./chunkTransform"), module.exports);
|
|
20
|
+
__reExport(chunks_exports, require("./generateTileGraph"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("./assetsModules"),
|
|
24
|
+
...require("./chunkTransform"),
|
|
25
|
+
...require("./generateTileGraph")
|
|
26
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
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 build_exports = {};
|
|
30
|
+
__export(build_exports, {
|
|
31
|
+
Chunks: () => Chunks,
|
|
32
|
+
ModuleGraph: () => ModuleGraph,
|
|
33
|
+
Types: () => Types,
|
|
34
|
+
Utils: () => Utils
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(build_exports);
|
|
37
|
+
var Chunks = __toESM(require("./chunks"));
|
|
38
|
+
var Utils = __toESM(require("./utils"));
|
|
39
|
+
var Types = __toESM(require("../../types"));
|
|
40
|
+
var ModuleGraph = __toESM(require("./module-graph"));
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
Chunks,
|
|
44
|
+
ModuleGraph,
|
|
45
|
+
Types,
|
|
46
|
+
Utils
|
|
47
|
+
});
|
|
@@ -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("./webpack/transform"), module.exports);
|
|
19
|
+
__reExport(module_graph_exports, require("./transform"), module.exports);
|
|
20
|
+
__reExport(module_graph_exports, require("./treeShaking"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("./webpack/transform"),
|
|
24
|
+
...require("./transform"),
|
|
25
|
+
...require("./treeShaking")
|
|
26
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
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 parser_exports = {};
|
|
20
|
+
__export(parser_exports, {
|
|
21
|
+
hasSetEsModuleStatement: () => hasSetEsModuleStatement
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(parser_exports);
|
|
24
|
+
var import_ruleUtils = require("@rsdoctor/utils/ruleUtils");
|
|
25
|
+
const esmLabelStatement = import_ruleUtils.parser.internal.parseExpressionAt(
|
|
26
|
+
'Object.defineProperty(exports, "__esModule", { value: true })',
|
|
27
|
+
0,
|
|
28
|
+
{
|
|
29
|
+
ecmaVersion: 6,
|
|
30
|
+
ranges: false,
|
|
31
|
+
locations: false,
|
|
32
|
+
sourceType: "script"
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
function hasSetEsModuleStatement(program) {
|
|
36
|
+
const expressions = program.body.filter(import_ruleUtils.parser.asserts.isExpressionStatement).map((item) => item.expression).filter(import_ruleUtils.parser.asserts.isSimpleCallExpression);
|
|
37
|
+
return expressions.some(
|
|
38
|
+
(exp) => import_ruleUtils.parser.utils.isSameSemantics(exp, esmLabelStatement)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
hasSetEsModuleStatement
|
|
44
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Plugin } from '@rsdoctor/types';
|
|
2
|
+
import { TransformContext } from '.';
|
|
3
|
+
import { ChunkGraph } from '@rsdoctor/graph';
|
|
4
|
+
export declare function getModuleGraphByStats(compilation: Plugin.BaseCompilation, stats: Plugin.StatsCompilation, root: string, chunkGraph: ChunkGraph, features?: Plugin.DoctorWebpackPluginFeatures, context?: TransformContext): Promise<import("@rsdoctor/graph").ModuleGraph>;
|
|
@@ -0,0 +1,37 @@
|
|
|
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 transform_exports = {};
|
|
20
|
+
__export(transform_exports, {
|
|
21
|
+
getModuleGraphByStats: () => getModuleGraphByStats
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(transform_exports);
|
|
24
|
+
var import_module_graph = require("../../common/module-graph");
|
|
25
|
+
var import__ = require(".");
|
|
26
|
+
function getModuleGraphByStats(compilation, stats, root, chunkGraph, features, context) {
|
|
27
|
+
return (0, import__.appendModuleGraphByCompilation)(
|
|
28
|
+
compilation,
|
|
29
|
+
(0, import_module_graph.getModuleGraphByStats)(stats, root, chunkGraph),
|
|
30
|
+
features,
|
|
31
|
+
context
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
getModuleGraphByStats
|
|
37
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
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 treeShaking_exports = {};
|
|
20
|
+
__export(treeShaking_exports, {
|
|
21
|
+
appendTreeShaking: () => appendTreeShaking
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(treeShaking_exports);
|
|
24
|
+
var import_graph = require("@rsdoctor/graph");
|
|
25
|
+
var import_compatible = require("../../common/webpack/compatible");
|
|
26
|
+
var import_utils = require("./utils");
|
|
27
|
+
var import_module_graph = require("../../common/module-graph");
|
|
28
|
+
function transformMgm(origin, webpackGraph, graph, cache) {
|
|
29
|
+
const module2 = graph.getModuleByWebpackId(origin.identifier());
|
|
30
|
+
if (!module2) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const mgm = new import_graph.ModuleGraphModule(module2, graph);
|
|
34
|
+
const originalMgm = webpackGraph.getExportsInfo(origin);
|
|
35
|
+
graph.addModuleGraphModule(mgm);
|
|
36
|
+
for (const info of originalMgm.exports) {
|
|
37
|
+
const { name } = info;
|
|
38
|
+
const exportIdStatement = (0, import_utils.getExportIdentifierStatement)(name, module2) ?? import_graph.Statement.getDefaultStatement(module2);
|
|
39
|
+
const declareIdStatement = (0, import_utils.getDeclarationIdentifier)(name, module2);
|
|
40
|
+
const exportInfo = new import_graph.ExportInfo(info.name, exportIdStatement);
|
|
41
|
+
if (declareIdStatement) {
|
|
42
|
+
const variable = new import_graph.Variable(
|
|
43
|
+
name,
|
|
44
|
+
module2,
|
|
45
|
+
info.getUsedInfo(),
|
|
46
|
+
declareIdStatement
|
|
47
|
+
);
|
|
48
|
+
variable.setExportInfo(exportInfo);
|
|
49
|
+
mgm.addVariable(variable);
|
|
50
|
+
}
|
|
51
|
+
cache.set(info, exportInfo);
|
|
52
|
+
mgm.addExportInfo(exportInfo);
|
|
53
|
+
}
|
|
54
|
+
for (const dep of origin.dependencies) {
|
|
55
|
+
if (dep.type !== "harmony import specifier") {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const HISDep = dep;
|
|
59
|
+
const { name, userRequest } = HISDep;
|
|
60
|
+
const originName = HISDep.getIds(webpackGraph)[0] ?? import_graph.SideEffect.NamespaceSymbol;
|
|
61
|
+
const importIdStatement = module2.getStatement(dep.loc);
|
|
62
|
+
const importInfo = new import_graph.SideEffect(
|
|
63
|
+
name,
|
|
64
|
+
module2,
|
|
65
|
+
importIdStatement,
|
|
66
|
+
userRequest,
|
|
67
|
+
originName
|
|
68
|
+
);
|
|
69
|
+
mgm.addSideEffect(importInfo);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function appendExportConnection(origin, webpackGraph, graph, cache) {
|
|
73
|
+
const module2 = graph.getModuleByWebpackId(origin.identifier());
|
|
74
|
+
const mgm = graph.getModuleGraphModule(module2);
|
|
75
|
+
const originalMgm = webpackGraph.getExportsInfo(origin);
|
|
76
|
+
if (!mgm || !module2) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
for (const info of originalMgm.exports) {
|
|
80
|
+
if (!info.isReexport()) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const lastExport = (0, import_compatible.getLastExportInfo)(info, webpackGraph);
|
|
84
|
+
const lastSdkExport = cache.get(lastExport);
|
|
85
|
+
const sdkExport = cache.get(info);
|
|
86
|
+
if (!lastSdkExport || !sdkExport) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
sdkExport.setFromExport(lastSdkExport);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function appendImportConnection(origin, graph) {
|
|
93
|
+
const module2 = graph.getModuleByWebpackId(origin.identifier());
|
|
94
|
+
const mgm = graph.getModuleGraphModule(module2);
|
|
95
|
+
if (!mgm || !module2) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
for (const info of mgm.getSideEffects()) {
|
|
99
|
+
const exportName = info.originName ?? info.name;
|
|
100
|
+
const resolveModule = info.fromDependency?.dependency;
|
|
101
|
+
if (!resolveModule) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const resolveExport = graph.getModuleGraphModule(resolveModule).getExport(exportName);
|
|
105
|
+
if (resolveExport) {
|
|
106
|
+
info.setExportInfo(resolveExport);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function appendTreeShaking(moduleGraph, compilation) {
|
|
111
|
+
if (!(0, import_module_graph.isWebpack5orRspack)(compilation)) {
|
|
112
|
+
return moduleGraph;
|
|
113
|
+
}
|
|
114
|
+
const exportData = /* @__PURE__ */ new Map();
|
|
115
|
+
const { moduleGraph: webpackGraph } = compilation;
|
|
116
|
+
const allModules = (0, import_compatible.getAllModules)(compilation);
|
|
117
|
+
allModules.forEach(
|
|
118
|
+
(origin) => transformMgm(origin, webpackGraph, moduleGraph, exportData)
|
|
119
|
+
);
|
|
120
|
+
allModules.forEach(
|
|
121
|
+
(origin) => appendExportConnection(origin, webpackGraph, moduleGraph, exportData)
|
|
122
|
+
);
|
|
123
|
+
allModules.forEach((origin) => appendImportConnection(origin, moduleGraph));
|
|
124
|
+
exportData.clear();
|
|
125
|
+
return moduleGraph;
|
|
126
|
+
}
|
|
127
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
128
|
+
0 && (module.exports = {
|
|
129
|
+
appendTreeShaking
|
|
130
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
getDeclarationIdentifier: () => getDeclarationIdentifier,
|
|
22
|
+
getExportIdentifierStatement: () => getExportIdentifierStatement
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(utils_exports);
|
|
25
|
+
var import_lodash = require("lodash");
|
|
26
|
+
var import_ruleUtils = require("@rsdoctor/utils/ruleUtils");
|
|
27
|
+
function getDefaultExportIdentifier(node, module2, searchId) {
|
|
28
|
+
const { declaration } = node;
|
|
29
|
+
if (import_ruleUtils.parser.asserts.isLiteral(declaration) && declaration.loc) {
|
|
30
|
+
return module2.getStatement(declaration.loc);
|
|
31
|
+
}
|
|
32
|
+
if (import_ruleUtils.parser.asserts.isIdentifier(declaration)) {
|
|
33
|
+
if (searchId) {
|
|
34
|
+
const result = getDeclarationIdentifier(declaration.name, module2);
|
|
35
|
+
if (result) {
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
} else if (declaration.loc) {
|
|
39
|
+
return module2.getStatement(declaration.loc);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (import_ruleUtils.parser.asserts.isClassDeclaration(declaration) || import_ruleUtils.parser.asserts.isFunctionDeclaration(declaration)) {
|
|
43
|
+
if (declaration.id?.loc) {
|
|
44
|
+
return module2.getStatement(declaration.id.loc);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const startLine = node.declaration.loc?.start.line;
|
|
48
|
+
if (!(0, import_lodash.isNumber)(startLine)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const { transformed } = module2.getSource();
|
|
52
|
+
const endColumn = transformed.split("\n")[startLine - 1].length - 1;
|
|
53
|
+
return module2.getStatement({
|
|
54
|
+
start: {
|
|
55
|
+
line: startLine,
|
|
56
|
+
column: 0
|
|
57
|
+
},
|
|
58
|
+
end: {
|
|
59
|
+
line: startLine,
|
|
60
|
+
column: endColumn
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function getExportIdentifierStatement(name, module2) {
|
|
65
|
+
const ast = module2.getProgram();
|
|
66
|
+
if (!ast) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
for (const node of ast.body) {
|
|
70
|
+
if (import_ruleUtils.parser.asserts.isExportDefaultDeclaration(node)) {
|
|
71
|
+
const result = getDefaultExportIdentifier(node, module2, false);
|
|
72
|
+
if (result) {
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const id = import_ruleUtils.parser.utils.getIdentifierInExport(name, node);
|
|
77
|
+
if (id?.loc) {
|
|
78
|
+
return module2.getStatement(id.loc);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function getDeclarationIdentifier(name, module2) {
|
|
83
|
+
const ast = module2.getProgram();
|
|
84
|
+
if (!ast) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
for (const node of ast.body) {
|
|
88
|
+
const id = import_ruleUtils.parser.utils.getIdentifierInDeclaration(name, node);
|
|
89
|
+
if (id?.loc) {
|
|
90
|
+
return module2.getStatement(id.loc);
|
|
91
|
+
}
|
|
92
|
+
if (import_ruleUtils.parser.asserts.isExportNamedDeclaration(node) && node.declaration) {
|
|
93
|
+
const id2 = import_ruleUtils.parser.utils.getIdentifierInDeclaration(
|
|
94
|
+
name,
|
|
95
|
+
node.declaration
|
|
96
|
+
);
|
|
97
|
+
if (id2?.loc) {
|
|
98
|
+
return module2.getStatement(id2.loc);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (name === "default" && import_ruleUtils.parser.asserts.isExportDefaultDeclaration(node)) {
|
|
102
|
+
const result = getDefaultExportIdentifier(node, module2, true);
|
|
103
|
+
if (result) {
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
110
|
+
0 && (module.exports = {
|
|
111
|
+
getDeclarationIdentifier,
|
|
112
|
+
getExportIdentifierStatement
|
|
113
|
+
});
|