@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,11 @@
|
|
|
1
|
+
import type { SourceMapConsumer } from 'source-map';
|
|
2
|
+
import * as Webpack from 'webpack';
|
|
3
|
+
import { Node } from '@rsdoctor/utils/ruleUtils';
|
|
4
|
+
import { Plugin } from '@rsdoctor/types';
|
|
5
|
+
import { ModuleGraph } from '@rsdoctor/graph';
|
|
6
|
+
export interface TransformContext {
|
|
7
|
+
astCache?: Map<Webpack.NormalModule, Node.Program>;
|
|
8
|
+
packagePathMap?: Map<string, string>;
|
|
9
|
+
getSourceMap?(module: string): Promise<SourceMapConsumer | undefined>;
|
|
10
|
+
}
|
|
11
|
+
export declare function appendModuleGraphByCompilation(compilation: Plugin.BaseCompilation, graph: ModuleGraph, features?: Plugin.DoctorWebpackPluginFeatures, context?: TransformContext): Promise<ModuleGraph>;
|
|
@@ -0,0 +1,197 @@
|
|
|
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
|
+
appendModuleGraphByCompilation: () => appendModuleGraphByCompilation
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(transform_exports);
|
|
24
|
+
var import_build = require("@rsdoctor/utils/build");
|
|
25
|
+
var import_compatible = require("../../../common/webpack/compatible");
|
|
26
|
+
var import_module_graph = require("../../../common/module-graph");
|
|
27
|
+
var import_parser = require("../parser");
|
|
28
|
+
async function readFile(target, wbFs) {
|
|
29
|
+
if (wbFs?.fs?.readFile) {
|
|
30
|
+
const result = new Promise((resolve, reject) => {
|
|
31
|
+
wbFs.fs.readFile(target, (err, content) => {
|
|
32
|
+
if (err) {
|
|
33
|
+
reject(err);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (content) {
|
|
37
|
+
resolve(Buffer.from(content));
|
|
38
|
+
} else {
|
|
39
|
+
resolve();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}).catch(() => {
|
|
43
|
+
});
|
|
44
|
+
if (result) {
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return import_build.File.fse.readFile(target).catch(() => {
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function appendDependency(webpackDep, module2, webpackGraph, graph) {
|
|
52
|
+
const resolvedWebpackModule = (0, import_compatible.getResolveModule)(
|
|
53
|
+
webpackDep,
|
|
54
|
+
webpackGraph
|
|
55
|
+
);
|
|
56
|
+
if (!resolvedWebpackModule) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const rawRequest = (0, import_compatible.getWebpackDependencyRequest)(
|
|
60
|
+
webpackDep,
|
|
61
|
+
resolvedWebpackModule
|
|
62
|
+
);
|
|
63
|
+
const resolveRequest = (0, import_compatible.getWebpackModulePath)(resolvedWebpackModule);
|
|
64
|
+
const request = rawRequest ?? resolveRequest;
|
|
65
|
+
if (!module2.getDependencyByRequest(request)) {
|
|
66
|
+
const depModule = graph.getModuleByFile(resolveRequest);
|
|
67
|
+
if (depModule) {
|
|
68
|
+
const dep = module2.addDependency(
|
|
69
|
+
request,
|
|
70
|
+
depModule,
|
|
71
|
+
(0, import_module_graph.getImportKind)(webpackDep)
|
|
72
|
+
);
|
|
73
|
+
if (dep) {
|
|
74
|
+
graph.addDependency(dep);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const dependency = module2.getDependencyByRequest(request);
|
|
79
|
+
if (dependency) {
|
|
80
|
+
dependency.setBuildMeta({
|
|
81
|
+
exportsType: (0, import_compatible.getModuleExportsType)(
|
|
82
|
+
resolvedWebpackModule,
|
|
83
|
+
webpackGraph,
|
|
84
|
+
module2.meta.strictHarmonyModule
|
|
85
|
+
)
|
|
86
|
+
});
|
|
87
|
+
const statement = (0, import_compatible.getDependencyPosition)(webpackDep, module2, false);
|
|
88
|
+
if (statement) {
|
|
89
|
+
dependency.addStatement(statement);
|
|
90
|
+
}
|
|
91
|
+
dependency.statements.forEach((state) => {
|
|
92
|
+
state.position.source = state.module.getSourceRange(
|
|
93
|
+
state.position.transformed
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function getModuleSource(modulePath, wbFs, sourceMap) {
|
|
99
|
+
if (sourceMap) {
|
|
100
|
+
try {
|
|
101
|
+
const contentFromSourceMap = sourceMap.sourceContentFor(modulePath);
|
|
102
|
+
if (contentFromSourceMap) {
|
|
103
|
+
return Buffer.from(contentFromSourceMap);
|
|
104
|
+
}
|
|
105
|
+
} catch (e) {
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return process.env.NODE_ENV === "test" ? Buffer.from("test code") : readFile(modulePath, wbFs);
|
|
109
|
+
}
|
|
110
|
+
async function appendModuleData(origin, webpackGraph, graph, wbFs, features, context) {
|
|
111
|
+
const module2 = graph.getModuleByWebpackId((0, import_compatible.getWebpackModuleId)(origin));
|
|
112
|
+
if (!origin || !module2) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const { getSourceMap, astCache, packagePathMap } = context ?? {};
|
|
116
|
+
try {
|
|
117
|
+
const sourceMap = await getSourceMap?.(module2.path);
|
|
118
|
+
const source = await getModuleSource(module2.path, wbFs, sourceMap) ?? Buffer.from("");
|
|
119
|
+
if (sourceMap) {
|
|
120
|
+
module2.setSourceMap(sourceMap);
|
|
121
|
+
}
|
|
122
|
+
if (astCache?.has(origin)) {
|
|
123
|
+
const program = astCache.get(origin);
|
|
124
|
+
module2.setProgram(program);
|
|
125
|
+
module2.meta.hasSetEsModuleStatement = (0, import_parser.hasSetEsModuleStatement)(program);
|
|
126
|
+
}
|
|
127
|
+
const transformed = (0, import_compatible.isExternalModule)(origin) ? "" : module2.getSource().transformed.length > 0 ? module2.getSource().transformed : origin.originalSource?.()?.source().toString() ?? "";
|
|
128
|
+
const transformedSize = (0, import_compatible.isExternalModule)(origin) ? 0 : module2.getSize().transformedSize > 0 ? module2.getSize().transformedSize : Buffer.from(transformed).byteLength;
|
|
129
|
+
module2.setSource({
|
|
130
|
+
transformed,
|
|
131
|
+
source: source.toString()
|
|
132
|
+
});
|
|
133
|
+
module2.setSize({
|
|
134
|
+
transformedSize,
|
|
135
|
+
sourceSize: source.byteLength
|
|
136
|
+
});
|
|
137
|
+
let packageData;
|
|
138
|
+
if (packagePathMap && origin.resourceResolveData) {
|
|
139
|
+
let { descriptionFileRoot: root } = origin.resourceResolveData;
|
|
140
|
+
const { descriptionFileData: data } = origin.resourceResolveData;
|
|
141
|
+
if (root && data.name && data.version) {
|
|
142
|
+
if (packagePathMap.has(root)) {
|
|
143
|
+
root = packagePathMap.get(root);
|
|
144
|
+
} else {
|
|
145
|
+
const realpath = await import_build.File.fse.realpath(root);
|
|
146
|
+
root = realpath;
|
|
147
|
+
packagePathMap.set(root, realpath);
|
|
148
|
+
}
|
|
149
|
+
packageData = {
|
|
150
|
+
...origin.resourceResolveData.descriptionFileData,
|
|
151
|
+
root
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
module2.meta.strictHarmonyModule = origin.buildMeta?.strictHarmonyModule ?? false;
|
|
156
|
+
module2.meta.packageData = packageData;
|
|
157
|
+
if (!features?.lite) {
|
|
158
|
+
Array.from(origin.dependencies).filter((item) => (0, import_module_graph.isImportDependency)(item)).concat(
|
|
159
|
+
origin.blocks.reduce(
|
|
160
|
+
(ans, item) => ans.concat(item.dependencies),
|
|
161
|
+
[]
|
|
162
|
+
)
|
|
163
|
+
).forEach((dep) => appendDependency(dep, module2, webpackGraph, graph));
|
|
164
|
+
}
|
|
165
|
+
} catch (e) {
|
|
166
|
+
console.error(`module ${module2.path} transform has error:`, e);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async function appendModuleGraphByCompilation(compilation, graph, features, context) {
|
|
170
|
+
try {
|
|
171
|
+
if ("rspackVersion" in compilation.compiler && compilation.compiler.rspackVersion) {
|
|
172
|
+
return graph;
|
|
173
|
+
}
|
|
174
|
+
const { moduleGraph: webpackGraph, fileSystemInfo } = compilation;
|
|
175
|
+
const allModules = (0, import_compatible.getAllModules)(compilation);
|
|
176
|
+
await Promise.all(
|
|
177
|
+
allModules.map((module2) => {
|
|
178
|
+
return appendModuleData(
|
|
179
|
+
module2,
|
|
180
|
+
webpackGraph,
|
|
181
|
+
graph,
|
|
182
|
+
fileSystemInfo,
|
|
183
|
+
features,
|
|
184
|
+
context
|
|
185
|
+
);
|
|
186
|
+
})
|
|
187
|
+
);
|
|
188
|
+
(0, import_module_graph.removeNoImportStyle)(graph);
|
|
189
|
+
return graph;
|
|
190
|
+
} catch (e) {
|
|
191
|
+
return graph;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
195
|
+
0 && (module.exports = {
|
|
196
|
+
appendModuleGraphByCompilation
|
|
197
|
+
});
|
|
@@ -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 utils_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(utils_exports);
|
|
18
|
+
__reExport(utils_exports, require("./loader"), module.exports);
|
|
19
|
+
__reExport(utils_exports, require("./plugin"), module.exports);
|
|
20
|
+
__reExport(utils_exports, require("./parseBundle"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("./loader"),
|
|
24
|
+
...require("./plugin"),
|
|
25
|
+
...require("./parseBundle")
|
|
26
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Common, Plugin } from '@rsdoctor/types';
|
|
3
|
+
import { SourceMapInput as WebpackSourceMapInput } from '../../../types';
|
|
4
|
+
export declare function loadLoaderModule(p: string, cwd?: string): {
|
|
5
|
+
default: Plugin.LoaderDefinition<Common.PlainObject, {}>;
|
|
6
|
+
pitch: Plugin.PitchLoaderDefinitionFunction;
|
|
7
|
+
raw: boolean | void;
|
|
8
|
+
};
|
|
9
|
+
export declare function getLoaderOptions<T>(loaderContext: Plugin.LoaderContext<T>): T;
|
|
10
|
+
export declare function extractLoaderName(loaderPath: string, cwd?: string): string;
|
|
11
|
+
export declare function mapEachRules<T extends Plugin.BuildRuleSetRule>(rules: T[], callback: (rule: T) => T): T[];
|
|
12
|
+
export declare function createLoaderContextTrap(this: Plugin.LoaderContext<Common.PlainObject>, final: (err: Error | null | undefined, res: string | Buffer | null, sourceMap?: WebpackSourceMapInput) => void): Plugin.LoaderContext<Common.PlainObject<any>>;
|
|
@@ -0,0 +1,210 @@
|
|
|
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 loader_exports = {};
|
|
30
|
+
__export(loader_exports, {
|
|
31
|
+
createLoaderContextTrap: () => createLoaderContextTrap,
|
|
32
|
+
extractLoaderName: () => extractLoaderName,
|
|
33
|
+
getLoaderOptions: () => getLoaderOptions,
|
|
34
|
+
loadLoaderModule: () => loadLoaderModule,
|
|
35
|
+
mapEachRules: () => mapEachRules
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(loader_exports);
|
|
38
|
+
var import_loader_utils = require("loader-utils");
|
|
39
|
+
var import_path = __toESM(require("path"));
|
|
40
|
+
var import_lodash = require("lodash");
|
|
41
|
+
var import_common = require("@rsdoctor/utils/common");
|
|
42
|
+
function loadLoaderModule(p, cwd = process.cwd()) {
|
|
43
|
+
const mod = process.env.DOCTOR_TEST ? require(import_path.default.resolve(cwd, p)) : require(require.resolve(p, {
|
|
44
|
+
paths: [cwd, import_path.default.resolve(cwd, "node_modules")]
|
|
45
|
+
}));
|
|
46
|
+
const isESM = mod.__esModule && typeof mod.default === "function";
|
|
47
|
+
return {
|
|
48
|
+
default: isESM ? mod.default : typeof mod === "function" ? mod : null,
|
|
49
|
+
pitch: mod.default?.pitch || mod.pitch,
|
|
50
|
+
raw: mod.default?.raw || mod.raw || false
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function getLoaderOptions(loaderContext) {
|
|
54
|
+
if (typeof loaderContext.getOptions === "function") {
|
|
55
|
+
return loaderContext.getOptions();
|
|
56
|
+
}
|
|
57
|
+
return (0, import_loader_utils.getOptions)(loaderContext);
|
|
58
|
+
}
|
|
59
|
+
function extractLoaderName(loaderPath, cwd = "") {
|
|
60
|
+
let res = loaderPath.replace(cwd, "");
|
|
61
|
+
if (!import_path.default.isAbsolute(res))
|
|
62
|
+
return res;
|
|
63
|
+
const nms = "/node_modules/";
|
|
64
|
+
const idx = res.lastIndexOf(nms);
|
|
65
|
+
if (idx !== -1) {
|
|
66
|
+
res = res.slice(idx + nms.length);
|
|
67
|
+
const ln = "loader";
|
|
68
|
+
const lnIdx = res.lastIndexOf(ln);
|
|
69
|
+
if (lnIdx > -1) {
|
|
70
|
+
res = res.slice(0, lnIdx + ln.length);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return res;
|
|
74
|
+
}
|
|
75
|
+
function mapEachRules(rules, callback) {
|
|
76
|
+
return rules.map((rule, i) => {
|
|
77
|
+
if (typeof rule === "string") {
|
|
78
|
+
return callback({
|
|
79
|
+
loader: rule
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (rule.loader && typeof rule.loader === "string") {
|
|
83
|
+
return callback(rule);
|
|
84
|
+
}
|
|
85
|
+
if (Array.isArray(rule.loaders)) {
|
|
86
|
+
const { loaders, ...rest } = rule;
|
|
87
|
+
return {
|
|
88
|
+
...rest,
|
|
89
|
+
use: mapEachRules(loaders, callback)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (rule.use && (!Array.isArray(rule.use) || rule.use.length !== 0)) {
|
|
93
|
+
if (typeof rule.use === "string") {
|
|
94
|
+
return {
|
|
95
|
+
...rule,
|
|
96
|
+
use: mapEachRules(
|
|
97
|
+
[
|
|
98
|
+
{
|
|
99
|
+
loader: rule.use,
|
|
100
|
+
options: rule.options
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
callback
|
|
104
|
+
)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (Array.isArray(rule.use)) {
|
|
108
|
+
return {
|
|
109
|
+
...rule,
|
|
110
|
+
use: mapEachRules(rule.use, callback)
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
...rule,
|
|
115
|
+
use: mapEachRules([rule.use], callback)
|
|
116
|
+
};
|
|
117
|
+
throw new Error(
|
|
118
|
+
`webpack.module.rules.use[${i}] parse error: ${rule.use}`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if ("rules" in rule && Array.isArray(rule.rules)) {
|
|
122
|
+
return {
|
|
123
|
+
...rule,
|
|
124
|
+
rules: mapEachRules(rule.rules, callback)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (Array.isArray(rule.oneOf)) {
|
|
128
|
+
return {
|
|
129
|
+
...rule,
|
|
130
|
+
oneOf: mapEachRules(rule.oneOf, callback)
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return rule;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function createLoaderContextTrap(final) {
|
|
137
|
+
const cb = this.callback;
|
|
138
|
+
let callback = (...args) => {
|
|
139
|
+
final(args[0], args[1] ?? null, args[2]);
|
|
140
|
+
return cb.call(this, ...args);
|
|
141
|
+
};
|
|
142
|
+
const ac = this.async;
|
|
143
|
+
let async = (...args) => {
|
|
144
|
+
const cb2 = ac(...args);
|
|
145
|
+
return (...args2) => {
|
|
146
|
+
final(args2[0], args2[1] ?? null, args2[2]);
|
|
147
|
+
return cb2(...args2);
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
const trap = new Proxy(this, {
|
|
151
|
+
get(target, key, receiver) {
|
|
152
|
+
switch (key) {
|
|
153
|
+
case "async":
|
|
154
|
+
return async;
|
|
155
|
+
case "callback":
|
|
156
|
+
return callback;
|
|
157
|
+
case "query":
|
|
158
|
+
if (target.query) {
|
|
159
|
+
if (typeof target.query === "string") {
|
|
160
|
+
const res = target.query.replace(
|
|
161
|
+
// eslint-disable-next-line no-useless-escape
|
|
162
|
+
new RegExp(
|
|
163
|
+
`"${import_common.Loader.LoaderInternalPropertyName}":{[^}]*},{0,1}`
|
|
164
|
+
),
|
|
165
|
+
""
|
|
166
|
+
);
|
|
167
|
+
return res;
|
|
168
|
+
}
|
|
169
|
+
if (typeof target.query === "object") {
|
|
170
|
+
const options = target.query[import_common.Loader.LoaderInternalPropertyName];
|
|
171
|
+
if (options.hasOptions) {
|
|
172
|
+
return (0, import_lodash.omit)(target.query, [import_common.Loader.LoaderInternalPropertyName]);
|
|
173
|
+
}
|
|
174
|
+
return target.resourceQuery;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return Reflect.get(target, key, receiver);
|
|
178
|
+
case "getOptions":
|
|
179
|
+
return typeof target.getOptions === "function" ? () => (0, import_lodash.omit)(target.getOptions(), [import_common.Loader.LoaderInternalPropertyName]) : Reflect.get(target, key, receiver);
|
|
180
|
+
default:
|
|
181
|
+
const _target = target;
|
|
182
|
+
return _target[key];
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
set(target, key, value, receiver) {
|
|
186
|
+
switch (key) {
|
|
187
|
+
case "async":
|
|
188
|
+
async = value;
|
|
189
|
+
return true;
|
|
190
|
+
case "callback":
|
|
191
|
+
callback = value;
|
|
192
|
+
return true;
|
|
193
|
+
default:
|
|
194
|
+
return Reflect.set(target, key, value, receiver);
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
defineProperty(target, p, attrs) {
|
|
198
|
+
return Reflect.defineProperty(target, p, attrs);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
return trap;
|
|
202
|
+
}
|
|
203
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
204
|
+
0 && (module.exports = {
|
|
205
|
+
createLoaderContextTrap,
|
|
206
|
+
extractLoaderName,
|
|
207
|
+
getLoaderOptions,
|
|
208
|
+
loadLoaderModule,
|
|
209
|
+
mapEachRules
|
|
210
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ParseBundle } from "../../../types";
|
|
2
|
+
/**
|
|
3
|
+
* The following code is based on
|
|
4
|
+
* https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/44bd8d0f9aa3b098e271af220096ea70cc44bc9e/src/parseUtils.js#L10
|
|
5
|
+
*
|
|
6
|
+
*
|
|
7
|
+
* MIT Licensed
|
|
8
|
+
* Author th0r
|
|
9
|
+
* Copyright JS Foundation and other contributors.
|
|
10
|
+
* https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/44bd8d0f9aa3b098e271af220096ea70cc44bc9e/LICENSE
|
|
11
|
+
*/
|
|
12
|
+
export declare const parseBundle: ParseBundle;
|