@rsdoctor/core 2.0.0-alpha.1 → 2.0.0-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/dist/26.js +26174 -0
- package/dist/630.js +1280 -0
- package/dist/630.js.LICENSE.txt +7 -0
- package/dist/build-utils/build/chunks/assetsModules.d.ts +7 -1
- package/dist/build-utils/build/loader/probeLoader.d.ts +7 -2
- package/dist/build-utils/build/server.d.ts +1 -2
- package/dist/build-utils/build/utils/parseBundle.d.ts +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1908 -7
- package/dist/inner-plugins/constants.d.ts +1 -1
- package/dist/inner-plugins/plugins/base.d.ts +2 -2
- package/dist/inner-plugins/plugins/errors.d.ts +1 -0
- package/dist/inner-plugins/plugins/plugins.d.ts +1 -1
- package/dist/inner-plugins/plugins/summary.d.ts +3 -2
- package/dist/inner-plugins/utils/sdk.d.ts +2 -1
- package/dist/logger.d.ts +2 -2
- package/dist/probe-loader.js +2 -0
- package/dist/proxy-loader.d.ts +1 -0
- package/dist/proxy-loader.js +48 -0
- package/dist/rslib-runtime.js +28 -0
- package/dist/rspack-plugin/constants.d.ts +1 -1
- package/dist/rspack-plugin/multiple.d.ts +5 -3
- package/dist/rspack-plugin/plugin.d.ts +43 -17
- package/dist/rspack-plugin/session.d.ts +20 -0
- package/dist/rules/rules/ecma-version-check/htmlParserStub.d.ts +3 -0
- package/dist/rules/rules/ecma-version-check/types.d.ts +13 -2
- package/dist/sdk/multiple/controller.d.ts +13 -2
- package/dist/sdk/multiple/primary.d.ts +12 -4
- package/dist/sdk/server/apis/base.d.ts +1 -1
- package/dist/sdk/server/socket/api.d.ts +1 -1
- package/dist/sdk/utils/date.d.ts +1 -0
- package/dist/types/loader.d.ts +1 -1
- package/package.json +23 -117
- package/dist/build-utils/build/chunks/assetsModules.js +0 -9
- package/dist/build-utils/build/chunks/index.js +0 -3
- package/dist/build-utils/build/chunks/rspack/transform.js +0 -44
- package/dist/build-utils/build/envinfo.js +0 -60
- package/dist/build-utils/build/file/cache.js +0 -24
- package/dist/build-utils/build/file/index.js +0 -5
- package/dist/build-utils/build/file/sharding.js +0 -38
- package/dist/build-utils/build/index.js +0 -12
- package/dist/build-utils/build/json.js +0 -67
- package/dist/build-utils/build/loader/index.js +0 -3
- package/dist/build-utils/build/loader/probeLoader.js +0 -44
- package/dist/build-utils/build/loader/probeLoaderPlugin.js +0 -32
- package/dist/build-utils/build/module-graph/index.js +0 -2
- package/dist/build-utils/build/module-graph/parser.js +0 -13
- package/dist/build-utils/build/module-graph/rspack/transform.js +0 -111
- package/dist/build-utils/build/module-graph/utils.js +0 -60
- package/dist/build-utils/build/process.js +0 -18
- package/dist/build-utils/build/server.js +0 -107
- package/dist/build-utils/build/utils/index.js +0 -4
- package/dist/build-utils/build/utils/loader.js +0 -267
- package/dist/build-utils/build/utils/parseBundle.js +0 -238
- package/dist/build-utils/build/utils/plugin.js +0 -21
- package/dist/build-utils/index.js +0 -13
- package/dist/collection.d.ts +0 -1
- package/dist/collection.js +0 -2
- package/dist/common/file.js +0 -8
- package/dist/common/global-config.js +0 -33
- package/dist/common/index.d.ts +0 -4
- package/dist/common/index.js +0 -6
- package/dist/common-browser.d.ts +0 -1
- package/dist/common-browser.js +0 -2
- package/dist/error/error.js +0 -143
- package/dist/error/index.js +0 -3
- package/dist/error/transform.js +0 -138
- package/dist/error/utils.js +0 -23
- package/dist/graph/index.d.ts +0 -1
- package/dist/graph/index.js +0 -2
- package/dist/inner-plugins/constants.js +0 -19
- package/dist/inner-plugins/index.js +0 -3
- package/dist/inner-plugins/loaders/proxy.js +0 -65
- package/dist/inner-plugins/plugins/base.js +0 -20
- package/dist/inner-plugins/plugins/bundle.js +0 -63
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +0 -74
- package/dist/inner-plugins/plugins/errors.js +0 -65
- package/dist/inner-plugins/plugins/index.js +0 -11
- package/dist/inner-plugins/plugins/loader.js +0 -108
- package/dist/inner-plugins/plugins/plugins.js +0 -40
- package/dist/inner-plugins/plugins/progress.js +0 -35
- package/dist/inner-plugins/plugins/resolver.js +0 -57
- package/dist/inner-plugins/plugins/rspack.js +0 -99
- package/dist/inner-plugins/plugins/rules.js +0 -64
- package/dist/inner-plugins/plugins/sourcemapTool.js +0 -230
- package/dist/inner-plugins/plugins/summary.js +0 -92
- package/dist/inner-plugins/utils/circleDetect.js +0 -16
- package/dist/inner-plugins/utils/config.js +0 -141
- package/dist/inner-plugins/utils/index.js +0 -8
- package/dist/inner-plugins/utils/loader.js +0 -134
- package/dist/inner-plugins/utils/normalize-config.js +0 -77
- package/dist/inner-plugins/utils/openBrowser.js +0 -55
- package/dist/inner-plugins/utils/plugin-common.js +0 -94
- package/dist/inner-plugins/utils/plugin.js +0 -70
- package/dist/inner-plugins/utils/sdk.js +0 -19
- package/dist/logger.js +0 -51
- package/dist/rspack-plugin/constants.js +0 -23
- package/dist/rspack-plugin/index.js +0 -3
- package/dist/rspack-plugin/multiple.js +0 -39
- package/dist/rspack-plugin/plugin.js +0 -133
- package/dist/rule-utils/document/document.js +0 -46
- package/dist/rule-utils/document/index.js +0 -4
- package/dist/rule-utils/document/server.js +0 -13
- package/dist/rule-utils/document/types.js +0 -1
- package/dist/rule-utils/index.js +0 -3
- package/dist/rule-utils/parser/asserts.js +0 -105
- package/dist/rule-utils/parser/index.js +0 -5
- package/dist/rule-utils/parser/parser.js +0 -24
- package/dist/rule-utils/parser/types.js +0 -8
- package/dist/rule-utils/parser/utils.js +0 -106
- package/dist/rules/index.js +0 -4
- package/dist/rules/linter.js +0 -36
- package/dist/rules/rule.js +0 -101
- package/dist/rules/rules/cjs-require/index.js +0 -50
- package/dist/rules/rules/cjs-require/types.js +0 -1
- package/dist/rules/rules/cross-chunks-package/index.js +0 -41
- package/dist/rules/rules/cross-chunks-package/types.js +0 -1
- package/dist/rules/rules/cross-chunks-package/utils.js +0 -7
- package/dist/rules/rules/default-import-check/index.js +0 -83
- package/dist/rules/rules/default-import-check/types.js +0 -1
- package/dist/rules/rules/default-import-check/utils.js +0 -52
- package/dist/rules/rules/duplicate-package/index.js +0 -39
- package/dist/rules/rules/duplicate-package/types.js +0 -24
- package/dist/rules/rules/duplicate-package/utils.js +0 -38
- package/dist/rules/rules/ecma-version-check/index.js +0 -53
- package/dist/rules/rules/ecma-version-check/types.js +0 -1
- package/dist/rules/rules/ecma-version-check/utils.js +0 -6
- package/dist/rules/rules/esm-resolved-to-cjs/index.js +0 -193
- package/dist/rules/rules/esm-resolved-to-cjs/types.js +0 -1
- package/dist/rules/rules/index.js +0 -22
- package/dist/rules/rules/loader-performance-optimization/index.js +0 -86
- package/dist/rules/rules/loader-performance-optimization/types.js +0 -1
- package/dist/rules/rules/loader-performance-optimization/utils.js +0 -10
- package/dist/rules/rules/module-mixed-chunks/index.js +0 -52
- package/dist/rules/rules/module-mixed-chunks/types.js +0 -1
- package/dist/rules/rules/side-effects-only-imports/index.js +0 -81
- package/dist/rules/rules/side-effects-only-imports/types.js +0 -1
- package/dist/rules/utils.js +0 -10
- package/dist/sdk/index.js +0 -3
- package/dist/sdk/multiple/controller.js +0 -42
- package/dist/sdk/multiple/index.js +0 -3
- package/dist/sdk/multiple/primary.js +0 -64
- package/dist/sdk/multiple/server.js +0 -14
- package/dist/sdk/sdk/core.js +0 -163
- package/dist/sdk/sdk/index.js +0 -435
- package/dist/sdk/sdk/types.js +0 -1
- package/dist/sdk/server/apis/alerts.js +0 -30
- package/dist/sdk/server/apis/base.js +0 -22
- package/dist/sdk/server/apis/bundle-diff.js +0 -51
- package/dist/sdk/server/apis/data.js +0 -44
- package/dist/sdk/server/apis/fs.js +0 -28
- package/dist/sdk/server/apis/graph.js +0 -116
- package/dist/sdk/server/apis/index.js +0 -11
- package/dist/sdk/server/apis/loader.js +0 -120
- package/dist/sdk/server/apis/plugin.js +0 -39
- package/dist/sdk/server/apis/project.js +0 -59
- package/dist/sdk/server/apis/renderer.js +0 -33
- package/dist/sdk/server/apis/resolver.js +0 -38
- package/dist/sdk/server/client.js +0 -8
- package/dist/sdk/server/fakeServer.js +0 -12
- package/dist/sdk/server/index.js +0 -292
- package/dist/sdk/server/json-body.js +0 -150
- package/dist/sdk/server/router.js +0 -83
- package/dist/sdk/server/security.js +0 -47
- package/dist/sdk/server/socket/api.js +0 -22
- package/dist/sdk/server/socket/index.js +0 -166
- package/dist/sdk/server/utils.js +0 -19
- package/dist/sdk/utils/base.js +0 -22
- package/dist/sdk/utils/constant.js +0 -4
- package/dist/sdk/utils/index.js +0 -4
- package/dist/sdk/utils/openBrowser.js +0 -53
- package/dist/sdk/utils/upload.js +0 -6
- package/dist/sdk.js +0 -2
- package/dist/types/index.js +0 -4
- package/dist/types/loader.js +0 -1
- package/dist/types/plugin.js +0 -1
- package/dist/types/rules.js +0 -1
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import node_path from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
|
-
import fs_extra from "fs-extra";
|
|
6
|
-
import { omit } from "../../../collection.js";
|
|
7
|
-
import { Loader } from "../../../common/index.js";
|
|
8
|
-
import { readPackageJson } from "../json.js";
|
|
9
|
-
import { logger } from "../../../logger.js";
|
|
10
|
-
const loader_filename = fileURLToPath(import.meta.url);
|
|
11
|
-
const loader_dirname = node_path.dirname(loader_filename);
|
|
12
|
-
const loader_require = createRequire(import.meta.url);
|
|
13
|
-
const PATH_QUERY_FRAGMENT_REGEXP = /^((?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;
|
|
14
|
-
function parsePathQueryFragment(str) {
|
|
15
|
-
const match = PATH_QUERY_FRAGMENT_REGEXP.exec(str);
|
|
16
|
-
return {
|
|
17
|
-
path: match?.[1].replace(/\0(.)/g, '$1') || '',
|
|
18
|
-
query: match?.[2] ? match[2].replace(/\0(.)/g, '$1') : '',
|
|
19
|
-
fragment: match?.[3] || ''
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function loadLoaderModule(loaderPath, cwd = process.cwd()) {
|
|
23
|
-
const cleanLoaderPath = parsePathQueryFragment(loaderPath).path;
|
|
24
|
-
const mod = loader_require(process.env.DOCTOR_TEST ? node_path.resolve(cwd, cleanLoaderPath) : loader_require.resolve(cleanLoaderPath, {
|
|
25
|
-
paths: [
|
|
26
|
-
cwd,
|
|
27
|
-
node_path.resolve(cwd, 'node_modules')
|
|
28
|
-
]
|
|
29
|
-
}));
|
|
30
|
-
const isESM = mod.__esModule && 'function' == typeof mod.default;
|
|
31
|
-
return {
|
|
32
|
-
default: isESM ? mod.default : 'function' == typeof mod ? mod : null,
|
|
33
|
-
pitch: mod.default?.pitch || mod.pitch,
|
|
34
|
-
raw: mod.default?.raw || mod.raw || false
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function extractLoaderName(loaderPath, cwd = '') {
|
|
38
|
-
let res = loaderPath.replace(cwd, '');
|
|
39
|
-
if (!node_path.isAbsolute(res)) return res;
|
|
40
|
-
const nms = '/node_modules/';
|
|
41
|
-
const idx = res.lastIndexOf(nms);
|
|
42
|
-
if (-1 !== idx) {
|
|
43
|
-
res = res.slice(idx + nms.length);
|
|
44
|
-
const ln = 'loader';
|
|
45
|
-
const lnIdx = res.lastIndexOf(ln);
|
|
46
|
-
if (lnIdx > -1) res = res.slice(0, lnIdx + ln.length);
|
|
47
|
-
}
|
|
48
|
-
return res;
|
|
49
|
-
}
|
|
50
|
-
function mapEachRules(rules, callback) {
|
|
51
|
-
return rules.filter(Boolean).map((rule)=>{
|
|
52
|
-
if ('string' == typeof rule) return callback({
|
|
53
|
-
loader: rule
|
|
54
|
-
});
|
|
55
|
-
if (rule.loader && 'string' == typeof rule.loader) return callback(rule);
|
|
56
|
-
if (Array.isArray(rule.loaders)) {
|
|
57
|
-
const { loaders, ...rest } = rule;
|
|
58
|
-
return {
|
|
59
|
-
...rest,
|
|
60
|
-
use: mapEachRules(loaders, callback)
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
if (rule.use && (!Array.isArray(rule.use) || 0 !== rule.use.length)) {
|
|
64
|
-
if ('string' == typeof rule.use) return {
|
|
65
|
-
...rule,
|
|
66
|
-
use: mapEachRules([
|
|
67
|
-
{
|
|
68
|
-
loader: rule.use,
|
|
69
|
-
options: rule.options
|
|
70
|
-
}
|
|
71
|
-
], callback)
|
|
72
|
-
};
|
|
73
|
-
if ('function' == typeof rule.use) {
|
|
74
|
-
const funcUse = rule.use;
|
|
75
|
-
const newRule = {
|
|
76
|
-
...rule,
|
|
77
|
-
use: (...args)=>{
|
|
78
|
-
const rules = funcUse(...args);
|
|
79
|
-
return mapEachRules(rules, callback);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
return newRule;
|
|
83
|
-
}
|
|
84
|
-
if (Array.isArray(rule.use)) return {
|
|
85
|
-
...rule,
|
|
86
|
-
use: mapEachRules(rule.use, callback)
|
|
87
|
-
};
|
|
88
|
-
return {
|
|
89
|
-
...rule,
|
|
90
|
-
use: mapEachRules([
|
|
91
|
-
rule.use
|
|
92
|
-
], callback)
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
if ('rules' in rule && Array.isArray(rule.rules)) return {
|
|
96
|
-
...rule,
|
|
97
|
-
rules: mapEachRules(rule.rules, callback)
|
|
98
|
-
};
|
|
99
|
-
if (Array.isArray(rule.oneOf)) return {
|
|
100
|
-
...rule,
|
|
101
|
-
oneOf: mapEachRules(rule.oneOf, callback)
|
|
102
|
-
};
|
|
103
|
-
return rule;
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
function isESMLoader(r) {
|
|
107
|
-
const _loaderName = 'object' == typeof r && 'string' == typeof r?.loader ? r.loader : 'string' == typeof r ? r : '';
|
|
108
|
-
if (!_loaderName) return false;
|
|
109
|
-
const isPath = node_path.isAbsolute(_loaderName) || _loaderName.startsWith('./') || _loaderName.startsWith('../');
|
|
110
|
-
if (isPath) {
|
|
111
|
-
const packageJsonData = readPackageJson(_loaderName, (file)=>{
|
|
112
|
-
try {
|
|
113
|
-
return fs_extra.readJsonSync(file, {
|
|
114
|
-
encoding: 'utf8'
|
|
115
|
-
});
|
|
116
|
-
} catch (e) {
|
|
117
|
-
logger.debug(`isESMLoader function error:${e}`);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
if (packageJsonData?.type === 'module' && !packageJsonData?.name.includes('@rsdoctor/')) return true;
|
|
121
|
-
}
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
function appendProbeLoaders(compiler, loaderConfig) {
|
|
125
|
-
const _options = 'object' == typeof loaderConfig ? 'string' == typeof loaderConfig.options ? {
|
|
126
|
-
options: loaderConfig.options
|
|
127
|
-
} : loaderConfig.options : {};
|
|
128
|
-
const loaderPath = process.env.DOCTOR_TEST ? node_path.resolve(loader_dirname, '../loader/probeLoader.ts') : loader_require.resolve(node_path.join(loader_dirname, '../loader/probeLoader'));
|
|
129
|
-
const loader = 'string' == typeof loaderConfig ? loaderConfig : 'object' == typeof loaderConfig && loaderConfig.loader;
|
|
130
|
-
const createProbeLoader = (type)=>({
|
|
131
|
-
loader: loaderPath,
|
|
132
|
-
options: {
|
|
133
|
-
..._options,
|
|
134
|
-
loader,
|
|
135
|
-
ident: void 0,
|
|
136
|
-
type,
|
|
137
|
-
builderName: compiler.options.name
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
return [
|
|
141
|
-
createProbeLoader('end'),
|
|
142
|
-
loaderConfig,
|
|
143
|
-
createProbeLoader('start')
|
|
144
|
-
];
|
|
145
|
-
}
|
|
146
|
-
function getLoaderNameMatch(r, loaderName, strict = true) {
|
|
147
|
-
if (!strict) return 'object' == typeof r && 'string' == typeof r?.loader && r.loader.includes(loaderName) || 'string' == typeof r && r.includes(loaderName);
|
|
148
|
-
return 'object' == typeof r && 'string' == typeof r?.loader && r.loader === loaderName || 'string' == typeof r && r === loaderName;
|
|
149
|
-
}
|
|
150
|
-
function addProbeLoader2Rules(rules, compiler, fn) {
|
|
151
|
-
return rules.map((rule)=>{
|
|
152
|
-
if (!rule || 'string' == typeof rule) return rule;
|
|
153
|
-
if (fn(rule) && !rule.use) {
|
|
154
|
-
const loaderConfig = {
|
|
155
|
-
loader: rule.loader ?? '',
|
|
156
|
-
options: rule.options,
|
|
157
|
-
ident: 'ident' in rule && 'string' == typeof rule.ident ? rule.ident : void 0
|
|
158
|
-
};
|
|
159
|
-
return {
|
|
160
|
-
...rule,
|
|
161
|
-
use: appendProbeLoaders(compiler, loaderConfig),
|
|
162
|
-
loader: void 0,
|
|
163
|
-
options: void 0
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
if (rule.use) {
|
|
167
|
-
if (Array.isArray(rule.use)) rule.use = rule.use.flatMap((loaderConfig)=>{
|
|
168
|
-
if ('string' == typeof loaderConfig || 'object' == typeof loaderConfig && loaderConfig && 'loader' in loaderConfig) return fn(loaderConfig) ? appendProbeLoaders(compiler, loaderConfig) : [
|
|
169
|
-
loaderConfig
|
|
170
|
-
];
|
|
171
|
-
return [
|
|
172
|
-
loaderConfig
|
|
173
|
-
];
|
|
174
|
-
});
|
|
175
|
-
else if ('object' != typeof rule.use || Array.isArray(rule.use) || 'function' == typeof rule.use) {
|
|
176
|
-
if ('string' == typeof rule.use) rule.use = fn(rule.use) ? appendProbeLoaders(compiler, {
|
|
177
|
-
loader: rule.use
|
|
178
|
-
}) : [
|
|
179
|
-
{
|
|
180
|
-
loader: rule.use
|
|
181
|
-
}
|
|
182
|
-
];
|
|
183
|
-
} else if ('loader' in rule.use) rule.use = fn(rule.use) ? appendProbeLoaders(compiler, rule.use) : [
|
|
184
|
-
rule.use
|
|
185
|
-
];
|
|
186
|
-
}
|
|
187
|
-
if ('oneOf' in rule && rule.oneOf) return {
|
|
188
|
-
...rule,
|
|
189
|
-
oneOf: addProbeLoader2Rules(rule.oneOf, compiler, fn)
|
|
190
|
-
};
|
|
191
|
-
if ('rules' in rule && rule.rules) return {
|
|
192
|
-
...rule,
|
|
193
|
-
rules: addProbeLoader2Rules(rule.rules, compiler, fn)
|
|
194
|
-
};
|
|
195
|
-
return rule;
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
function createLoaderContextTrap(final) {
|
|
199
|
-
const cb = this.callback;
|
|
200
|
-
let callback = (...args)=>{
|
|
201
|
-
final(args[0], args[1] ?? null, args[2]);
|
|
202
|
-
return cb.call(this, ...args);
|
|
203
|
-
};
|
|
204
|
-
const ac = this.async;
|
|
205
|
-
let async = (...args)=>{
|
|
206
|
-
const cb = ac(...args);
|
|
207
|
-
return (...args)=>{
|
|
208
|
-
final(args[0], args[1] ?? null, args[2]);
|
|
209
|
-
return cb(...args);
|
|
210
|
-
};
|
|
211
|
-
};
|
|
212
|
-
const trap = new Proxy(this, {
|
|
213
|
-
get (target, key, receiver) {
|
|
214
|
-
switch(key){
|
|
215
|
-
case 'async':
|
|
216
|
-
return async;
|
|
217
|
-
case 'callback':
|
|
218
|
-
return callback;
|
|
219
|
-
case 'query':
|
|
220
|
-
if (target.query) {
|
|
221
|
-
if ('string' == typeof target.query) {
|
|
222
|
-
const res = target.query.replace(new RegExp(`"${Loader.LoaderInternalPropertyName}":{[^}]*},{0,1}`), '');
|
|
223
|
-
return res;
|
|
224
|
-
}
|
|
225
|
-
if ('object' == typeof target.query) {
|
|
226
|
-
const options = target.query[Loader.LoaderInternalPropertyName];
|
|
227
|
-
if (options.hasOptions) return omit(target.query, [
|
|
228
|
-
Loader.LoaderInternalPropertyName
|
|
229
|
-
]);
|
|
230
|
-
const innerLoaderPath = options?.loader;
|
|
231
|
-
const loaderQuery = parsePathQueryFragment(innerLoaderPath).query;
|
|
232
|
-
return loaderQuery;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return Reflect.get(target, key, receiver);
|
|
236
|
-
case 'getOptions':
|
|
237
|
-
return 'function' == typeof target.getOptions ? ()=>omit(target.getOptions(), [
|
|
238
|
-
Loader.LoaderInternalPropertyName
|
|
239
|
-
]) : Reflect.get(target, key, receiver);
|
|
240
|
-
default:
|
|
241
|
-
return target[key];
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
set (target, key, value, receiver) {
|
|
245
|
-
switch(key){
|
|
246
|
-
case 'async':
|
|
247
|
-
async = value;
|
|
248
|
-
return true;
|
|
249
|
-
case 'callback':
|
|
250
|
-
callback = value;
|
|
251
|
-
return true;
|
|
252
|
-
default:
|
|
253
|
-
return Reflect.set(target, key, value, receiver);
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
|
-
defineProperty (target, p, attrs) {
|
|
257
|
-
return Reflect.defineProperty(target, p, attrs);
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
return trap;
|
|
261
|
-
}
|
|
262
|
-
function parseQuery(query) {
|
|
263
|
-
if (query.startsWith('?')) query = query.slice(1);
|
|
264
|
-
const searchParams = new URLSearchParams(query);
|
|
265
|
-
return Object.fromEntries(searchParams.entries());
|
|
266
|
-
}
|
|
267
|
-
export { addProbeLoader2Rules, createLoaderContextTrap, extractLoaderName, getLoaderNameMatch, isESMLoader, loadLoaderModule, mapEachRules, parsePathQueryFragment, parseQuery };
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import { find, mapValues } from "../../../collection.js";
|
|
4
|
-
import { filesize } from "filesize";
|
|
5
|
-
import { parser } from "../../../rule-utils/index.js";
|
|
6
|
-
import { extname } from "path";
|
|
7
|
-
import { Constants } from "@rsdoctor/shared/types";
|
|
8
|
-
import { logger } from "../../../logger.js";
|
|
9
|
-
const parseBundle = (bundlePath, modulesData)=>{
|
|
10
|
-
if (bundlePath.indexOf('.worker.') > 0) return {};
|
|
11
|
-
const ext = extname(bundlePath);
|
|
12
|
-
if (!Constants.JSExtensions.includes(ext)) return {};
|
|
13
|
-
let content = fs.readFileSync(bundlePath, 'utf8');
|
|
14
|
-
const tagCache = new Map();
|
|
15
|
-
const sourceMapRegex = /\/\/# sourceMappingURL=[^\n]*$/m;
|
|
16
|
-
content = content.replace(sourceMapRegex, '');
|
|
17
|
-
let hasBannerPlugin = content.indexOf('RSDOCTOR_START::') > 0;
|
|
18
|
-
if (hasBannerPlugin && !tagCache.get(bundlePath)) {
|
|
19
|
-
const tagMatchResult = getStringBetween(content, 0, /([a-z|A-Z|_]+\.[a-z]+)\(\SRSDOCTOR_START::(.*?)[;,]/, /([a-z|A-Z|_]+\.[a-z]+)\(\SRSDOCTOR_END::(.*?)\)/);
|
|
20
|
-
content = tagMatchResult.result?.trim() || content;
|
|
21
|
-
tagCache.set(bundlePath, tagMatchResult.loc);
|
|
22
|
-
hasBannerPlugin = true;
|
|
23
|
-
} else if (hasBannerPlugin && tagCache.get(bundlePath)) {
|
|
24
|
-
const loc = tagCache.get(bundlePath);
|
|
25
|
-
content = content.slice(loc.start, loc.end);
|
|
26
|
-
hasBannerPlugin = true;
|
|
27
|
-
}
|
|
28
|
-
const ast = parser.internal.parse(content, {
|
|
29
|
-
sourceType: "script",
|
|
30
|
-
ecmaVersion: 'latest'
|
|
31
|
-
});
|
|
32
|
-
const walkState = {
|
|
33
|
-
locations: null,
|
|
34
|
-
expressionStatementDepth: 0
|
|
35
|
-
};
|
|
36
|
-
parser.walk.recursive(ast, walkState, {
|
|
37
|
-
ExpressionStatement (node, state, c) {
|
|
38
|
-
if (state.locations) return;
|
|
39
|
-
state.expressionStatementDepth++;
|
|
40
|
-
try {
|
|
41
|
-
if (1 === state.expressionStatementDepth && isIIFE(node)) {
|
|
42
|
-
const fn = getIIFECallExpression(node);
|
|
43
|
-
if (0 === fn.arguments.length && 0 === fn.callee.params.length) {
|
|
44
|
-
const firstVariableDeclaration = fn.callee.body.body.find((node)=>'VariableDeclaration' === node.type);
|
|
45
|
-
if (firstVariableDeclaration) {
|
|
46
|
-
for (const declaration of firstVariableDeclaration.declarations)if (declaration.init) {
|
|
47
|
-
state.locations = getModulesLocations(declaration.init);
|
|
48
|
-
if (state.locations) break;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (!state.locations) c(node.expression, state);
|
|
54
|
-
} catch (e) {
|
|
55
|
-
logger.debug(e);
|
|
56
|
-
}
|
|
57
|
-
state.expressionStatementDepth--;
|
|
58
|
-
},
|
|
59
|
-
Program (node, state, _c) {
|
|
60
|
-
if (state.locations) return;
|
|
61
|
-
try {
|
|
62
|
-
if (hasBannerPlugin) {
|
|
63
|
-
const firstVariableDeclaration = node.body.find((node)=>'VariableDeclaration' === node.type && node.declarations?.[0]?.init?.type === 'ObjectExpression' && node.declarations?.[0]?.init?.properties?.length);
|
|
64
|
-
if (firstVariableDeclaration) {
|
|
65
|
-
for (const declaration of firstVariableDeclaration.declarations)if (declaration.init) {
|
|
66
|
-
state.locations = getModulesLocations(declaration.init);
|
|
67
|
-
if (state.locations) break;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (!state.locations) node.body.forEach((n)=>_c(n, state));
|
|
72
|
-
} catch (e) {
|
|
73
|
-
logger.debug(e);
|
|
74
|
-
}
|
|
75
|
-
state.expressionStatementDepth--;
|
|
76
|
-
},
|
|
77
|
-
AssignmentExpression (node, state) {
|
|
78
|
-
if (state.locations) return;
|
|
79
|
-
const { left, right } = node;
|
|
80
|
-
if (left?.object && 'exports' === left.object.name && left.property && 'modules' === left.property.name && isModulesHash(right)) state.locations = getModulesLocations(right);
|
|
81
|
-
},
|
|
82
|
-
CallExpression (node, state, c) {
|
|
83
|
-
if (state.locations) return;
|
|
84
|
-
const args = node.arguments;
|
|
85
|
-
if ('FunctionExpression' === node.callee.type && !node.callee.id && 1 === args.length && isSimpleModulesList(args[0])) {
|
|
86
|
-
state.locations = getModulesLocations(args[0]);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if ('Identifier' === node.callee.type && mayBeAsyncChunkArguments(args) && isModulesList(args[1])) {
|
|
90
|
-
state.locations = getModulesLocations(args[1]);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (isAsyncChunkPushExpression(node)) {
|
|
94
|
-
state.locations = getModulesLocations(args[0].elements[1]);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (isAsyncWebWorkerChunkExpression(node)) {
|
|
98
|
-
state.locations = getModulesLocations(args[1]);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
args.forEach((arg)=>c(arg, state));
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
let modules;
|
|
105
|
-
modules = walkState.locations ? mapValues(walkState.locations, (loc)=>content.slice(loc.start, loc.end)) : {};
|
|
106
|
-
const modulesObj = {};
|
|
107
|
-
for(const module in modules){
|
|
108
|
-
if (!module) return {};
|
|
109
|
-
const moduleContent = modules[module];
|
|
110
|
-
const size = moduleContent && Buffer.byteLength(moduleContent);
|
|
111
|
-
const identifier = find(modulesData, (item)=>item.renderId === module)?.identifier || '';
|
|
112
|
-
modulesObj[identifier] = {
|
|
113
|
-
size,
|
|
114
|
-
sizeConvert: filesize(size || 0),
|
|
115
|
-
content: moduleContent
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
modules: modulesObj,
|
|
120
|
-
src: content,
|
|
121
|
-
runtimeSrc: getBundleRuntime(content, walkState.locations)
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
function getBundleRuntime(content, modulesLocations) {
|
|
125
|
-
const sortedLocations = Object.values(modulesLocations || {}).sort((a, b)=>a.start - b.start);
|
|
126
|
-
let result = '';
|
|
127
|
-
let lastIndex = 0;
|
|
128
|
-
for (const { start, end } of sortedLocations){
|
|
129
|
-
result += content.slice(lastIndex, start);
|
|
130
|
-
lastIndex = end;
|
|
131
|
-
}
|
|
132
|
-
return result + content.slice(lastIndex, content.length);
|
|
133
|
-
}
|
|
134
|
-
function isIIFE(node) {
|
|
135
|
-
return 'ExpressionStatement' === node.type && ('CallExpression' === node.expression.type || 'UnaryExpression' === node.expression.type && 'CallExpression' === node.expression.argument.type);
|
|
136
|
-
}
|
|
137
|
-
function getIIFECallExpression(node) {
|
|
138
|
-
if ('UnaryExpression' === node.expression.type) return node.expression.argument;
|
|
139
|
-
return node.expression;
|
|
140
|
-
}
|
|
141
|
-
function isModulesList(node) {
|
|
142
|
-
return isSimpleModulesList(node) || isOptimizedModulesArray(node);
|
|
143
|
-
}
|
|
144
|
-
function isSimpleModulesList(node) {
|
|
145
|
-
return isModulesHash(node) || isModulesArray(node);
|
|
146
|
-
}
|
|
147
|
-
function isModulesHash(node) {
|
|
148
|
-
return 'ObjectExpression' === node.type && node.properties.map((node)=>node.value).every(isModuleWrapper);
|
|
149
|
-
}
|
|
150
|
-
function isModulesArray(node) {
|
|
151
|
-
return 'ArrayExpression' === node.type && node.elements.every((elem)=>!elem || isModuleWrapper(elem));
|
|
152
|
-
}
|
|
153
|
-
function isOptimizedModulesArray(node) {
|
|
154
|
-
return 'CallExpression' === node.type && 'MemberExpression' === node.callee.type && 'CallExpression' === node.callee.object.type && 'Identifier' === node.callee.object.callee.type && 'Array' === node.callee.object.callee.name && 1 === node.callee.object.arguments.length && isNumericId(node.callee.object.arguments[0]) && 'Identifier' === node.callee.property.type && 'concat' === node.callee.property.name && 1 === node.arguments.length && isModulesArray(node.arguments[0]);
|
|
155
|
-
}
|
|
156
|
-
function isModuleWrapper(node) {
|
|
157
|
-
return ('FunctionExpression' === node.type || 'ArrowFunctionExpression' === node.type) && !node.id || isModuleId(node) || 'ArrayExpression' === node.type && node.elements.length > 1 && isModuleId(node.elements[0]);
|
|
158
|
-
}
|
|
159
|
-
function isModuleId(node) {
|
|
160
|
-
return 'Literal' === node.type && (isNumericId(node) || 'string' == typeof node.value);
|
|
161
|
-
}
|
|
162
|
-
function isNumericId(node) {
|
|
163
|
-
return 'Literal' === node.type && Number.isInteger(node.value) && node.value >= 0;
|
|
164
|
-
}
|
|
165
|
-
function isChunkIds(node) {
|
|
166
|
-
return 'ArrayExpression' === node.type && node.elements.every(isModuleId);
|
|
167
|
-
}
|
|
168
|
-
function isAsyncChunkPushExpression(node) {
|
|
169
|
-
const { callee, arguments: args } = node;
|
|
170
|
-
return 'MemberExpression' === callee.type && 'push' === callee.property.name && 'AssignmentExpression' === callee.object.type && 1 === args.length && 'ArrayExpression' === args[0].type && mayBeAsyncChunkArguments(args[0].elements) && isModulesList(args[0].elements[1]);
|
|
171
|
-
}
|
|
172
|
-
function mayBeAsyncChunkArguments(args) {
|
|
173
|
-
return args.length >= 2 && isChunkIds(args[0]);
|
|
174
|
-
}
|
|
175
|
-
function isAsyncWebWorkerChunkExpression(node) {
|
|
176
|
-
const { callee, type, arguments: args } = node;
|
|
177
|
-
return 'CallExpression' === type && 'MemberExpression' === callee.type && 2 === args.length && isChunkIds(args[0]) && isModulesList(args[1]);
|
|
178
|
-
}
|
|
179
|
-
function getModulesLocations(node) {
|
|
180
|
-
if ('ObjectExpression' === node.type) {
|
|
181
|
-
const modulesNodes = node.properties;
|
|
182
|
-
return modulesNodes.reduce((result, moduleNode)=>{
|
|
183
|
-
const moduleId = moduleNode.key.name || moduleNode.key.value;
|
|
184
|
-
result[moduleId] = getModuleLocation(moduleNode.value);
|
|
185
|
-
return result;
|
|
186
|
-
}, {});
|
|
187
|
-
}
|
|
188
|
-
const isOptimizedArray = 'CallExpression' === node.type;
|
|
189
|
-
if ('ArrayExpression' === node.type || isOptimizedArray) {
|
|
190
|
-
const minId = isOptimizedArray ? node.callee.object.arguments[0].value : 0;
|
|
191
|
-
const modulesNodes = isOptimizedArray ? node.arguments[0].elements : node.elements;
|
|
192
|
-
return modulesNodes.reduce((result, moduleNode, i)=>{
|
|
193
|
-
if (moduleNode) result[i + minId] = getModuleLocation(moduleNode);
|
|
194
|
-
return result;
|
|
195
|
-
}, {});
|
|
196
|
-
}
|
|
197
|
-
return {};
|
|
198
|
-
}
|
|
199
|
-
function getModuleLocation(node) {
|
|
200
|
-
return {
|
|
201
|
-
start: node.start,
|
|
202
|
-
end: node.end
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
function getStringBetween(raw, position, start, end) {
|
|
206
|
-
try {
|
|
207
|
-
const matchStart = raw.match(start);
|
|
208
|
-
const startFlagIndex = matchStart?.length ? raw.indexOf(matchStart[0], position) : -1;
|
|
209
|
-
if (-1 === startFlagIndex || !matchStart?.length) return {
|
|
210
|
-
result: null,
|
|
211
|
-
remain: position
|
|
212
|
-
};
|
|
213
|
-
const startTagLength = matchStart[0].length;
|
|
214
|
-
const matchEnd = raw.match(end);
|
|
215
|
-
const endFlagIndex = matchEnd?.length ? raw.indexOf(matchEnd[0], startFlagIndex + startTagLength) : -1;
|
|
216
|
-
if (-1 === endFlagIndex || !matchEnd?.length) return {
|
|
217
|
-
result: null,
|
|
218
|
-
remain: position
|
|
219
|
-
};
|
|
220
|
-
let innerContent = raw.slice(startFlagIndex + startTagLength, endFlagIndex).trim();
|
|
221
|
-
if (innerContent.endsWith(',')) innerContent = innerContent.slice(0, -1);
|
|
222
|
-
return {
|
|
223
|
-
result: innerContent,
|
|
224
|
-
remain: matchEnd?.length ? endFlagIndex + matchEnd[0].length : endFlagIndex,
|
|
225
|
-
loc: {
|
|
226
|
-
start: startFlagIndex + startTagLength,
|
|
227
|
-
end: endFlagIndex
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
} catch (e) {
|
|
231
|
-
logger.debug(()=>e);
|
|
232
|
-
return {
|
|
233
|
-
result: null,
|
|
234
|
-
remain: position
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
export { parseBundle };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
function shouldInterceptPluginHook(hook) {
|
|
3
|
-
if (hook && hook._fakeHook) return false;
|
|
4
|
-
if (hook?.isUsed && 'function' == typeof hook.isUsed) return hook.isUsed();
|
|
5
|
-
if (hook?._map && 0 === hook._map.size) return false;
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
function interceptCompilerHooks(compiler, interceptor) {
|
|
9
|
-
Object.keys(compiler.hooks).forEach((hook)=>{
|
|
10
|
-
const v = compiler.hooks[hook];
|
|
11
|
-
if (shouldInterceptPluginHook(v)) interceptor(hook, v, 'compiler');
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
function interceptCompilationHooks(compilation, interceptor) {
|
|
15
|
-
Object.keys(compilation.hooks).forEach((hook)=>{
|
|
16
|
-
if ('normalModuleLoader' === hook) return;
|
|
17
|
-
const v = compilation.hooks[hook];
|
|
18
|
-
if (shouldInterceptPluginHook(v)) interceptor(hook, v, 'compilation');
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
export { interceptCompilationHooks, interceptCompilerHooks, shouldInterceptPluginHook };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import * as __rspack_external__build_index_js_dd3d3112 from "./build/index.js";
|
|
3
|
-
import * as __rspack_external__build_envinfo_js_bb7cc383 from "./build/envinfo.js";
|
|
4
|
-
import * as __rspack_external__build_file_index_js_b486e89f from "./build/file/index.js";
|
|
5
|
-
import * as __rspack_external__build_json_js_4cd59ece from "./build/json.js";
|
|
6
|
-
import * as __rspack_external__build_process_js_dbdc7299 from "./build/process.js";
|
|
7
|
-
import * as __rspack_external__build_server_js_f760cf8d from "./build/server.js";
|
|
8
|
-
import * as __rspack_external__build_chunks_index_js_b63f9e6b from "./build/chunks/index.js";
|
|
9
|
-
import * as __rspack_external__build_utils_index_js_2ab2484c from "./build/utils/index.js";
|
|
10
|
-
import * as __rspack_external__build_loader_index_js_a995ea1e from "./build/loader/index.js";
|
|
11
|
-
import * as __rspack_external__types_index_js_b312a465 from "../types/index.js";
|
|
12
|
-
import * as __rspack_external__build_module_graph_index_js_808da562 from "./build/module-graph/index.js";
|
|
13
|
-
export { __rspack_external__build_chunks_index_js_b63f9e6b as Chunks, __rspack_external__build_envinfo_js_bb7cc383 as EnvInfo, __rspack_external__build_file_index_js_b486e89f as File, __rspack_external__build_index_js_dd3d3112 as Build, __rspack_external__build_json_js_4cd59ece as Json, __rspack_external__build_loader_index_js_a995ea1e as Loader, __rspack_external__build_module_graph_index_js_808da562 as ModuleGraph, __rspack_external__build_process_js_dbdc7299 as Process, __rspack_external__build_server_js_f760cf8d as Server, __rspack_external__build_utils_index_js_2ab2484c as Utils, __rspack_external__types_index_js_b312a465 as Types };
|
package/dist/collection.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@rsdoctor/shared/collection';
|
package/dist/collection.js
DELETED
package/dist/common/file.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import os from "os";
|
|
5
|
-
import { logger } from "../logger.js";
|
|
6
|
-
function writeMcpPort(port, builderName) {
|
|
7
|
-
const homeDir = os.homedir();
|
|
8
|
-
const rsdoctorDir = path.join(homeDir, '.cache/rsdoctor');
|
|
9
|
-
const mcpPortFilePath = path.join(rsdoctorDir, 'mcp.json');
|
|
10
|
-
if (!fs.existsSync(rsdoctorDir)) fs.mkdirSync(rsdoctorDir, {
|
|
11
|
-
recursive: true
|
|
12
|
-
});
|
|
13
|
-
let mcpJson = {
|
|
14
|
-
portList: {},
|
|
15
|
-
port: 0
|
|
16
|
-
};
|
|
17
|
-
if (fs.existsSync(mcpPortFilePath)) try {
|
|
18
|
-
mcpJson = JSON.parse(fs.readFileSync(mcpPortFilePath, 'utf8'));
|
|
19
|
-
} catch (error) {
|
|
20
|
-
logger.debug('Failed to parse mcp.json', error);
|
|
21
|
-
}
|
|
22
|
-
if (!mcpJson.portList) mcpJson.portList = {};
|
|
23
|
-
mcpJson.portList[builderName || 'builder'] = port;
|
|
24
|
-
mcpJson.port = port;
|
|
25
|
-
fs.writeFileSync(mcpPortFilePath, JSON.stringify(mcpJson, null, 2), 'utf8');
|
|
26
|
-
}
|
|
27
|
-
function getMcpConfigPath() {
|
|
28
|
-
const homeDir = os.homedir();
|
|
29
|
-
const rsdoctorDir = path.join(homeDir, '.cache/rsdoctor');
|
|
30
|
-
const mcpPortFilePath = path.join(rsdoctorDir, 'mcp.json');
|
|
31
|
-
return mcpPortFilePath;
|
|
32
|
-
}
|
|
33
|
-
export { getMcpConfigPath, writeMcpPort };
|
package/dist/common/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { Alerts, Algorithm, Bundle, Crypto, Data, Fetch, Graph, Loader, Lodash, Manifest, Package, Plugin, Resolver, Rspack, Summary, Time, Url, } from '@rsdoctor/shared/common-browser';
|
|
2
|
-
export * as GlobalConfig from './global-config.js';
|
|
3
|
-
export * as File from './file.js';
|
|
4
|
-
export * from '@rsdoctor/shared/common-browser';
|
package/dist/common/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import * as __rspack_external__file_js_9fa33ca6 from "./file.js";
|
|
3
|
-
import * as __rspack_external__global_config_js_a07079db from "./global-config.js";
|
|
4
|
-
export * from "@rsdoctor/shared/common-browser";
|
|
5
|
-
export { Alerts, Algorithm, Bundle, Crypto, Data, Fetch, Graph, Loader, Lodash, Manifest, Package, Plugin, Resolver, Rspack, Summary, Time, Url } from "@rsdoctor/shared/common-browser";
|
|
6
|
-
export { __rspack_external__file_js_9fa33ca6 as File, __rspack_external__global_config_js_a07079db as GlobalConfig };
|
package/dist/common-browser.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@rsdoctor/shared/common-browser';
|
package/dist/common-browser.js
DELETED