@rsdoctor/core 2.0.0-alpha.1 → 2.0.0-alpha.2
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 +26163 -0
- package/dist/630.js +1269 -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/utils/parseBundle.d.ts +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1725 -7
- package/dist/inner-plugins/constants.d.ts +1 -1
- package/dist/inner-plugins/plugins/base.d.ts +2 -2
- 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/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/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 +20 -113
- 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,44 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { parseQuery } from "../utils/index.js";
|
|
3
|
-
import { getSDK } from "../../../inner-plugins/utils/sdk.js";
|
|
4
|
-
import { omit } from "../../../collection.js";
|
|
5
|
-
import path from "path";
|
|
6
|
-
const loaderModule = function(...args) {
|
|
7
|
-
const time = Date.now();
|
|
8
|
-
const code = args[0];
|
|
9
|
-
const _options = this.getOptions();
|
|
10
|
-
const sdk = getSDK(_options.builderName);
|
|
11
|
-
const loaderData = {
|
|
12
|
-
resource: {
|
|
13
|
-
path: this._module?.layer ? `${this.resourcePath}[${this._module.layer}]` : this.resourcePath,
|
|
14
|
-
query: parseQuery(this.resourceQuery),
|
|
15
|
-
queryRaw: this.resourceQuery,
|
|
16
|
-
ext: path.extname(this.resourcePath).slice(1),
|
|
17
|
-
...this._module?.layer ? {
|
|
18
|
-
layer: this._module.layer
|
|
19
|
-
} : {}
|
|
20
|
-
},
|
|
21
|
-
loaders: [
|
|
22
|
-
{
|
|
23
|
-
loader: _options.loader,
|
|
24
|
-
loaderIndex: this.loaderIndex,
|
|
25
|
-
path: _options.loader,
|
|
26
|
-
input: 'start' === _options.type ? code : null,
|
|
27
|
-
result: 'end' === _options.type ? code : null,
|
|
28
|
-
startAt: 'start' === _options.type ? time : 0,
|
|
29
|
-
endAt: 'end' === _options.type ? time : 0,
|
|
30
|
-
options: omit(_options.options, 'type'),
|
|
31
|
-
isPitch: false,
|
|
32
|
-
sync: false,
|
|
33
|
-
errors: [],
|
|
34
|
-
pid: process.pid,
|
|
35
|
-
ppid: process.ppid
|
|
36
|
-
}
|
|
37
|
-
]
|
|
38
|
-
};
|
|
39
|
-
sdk?.reportLoaderStartOrEnd(loaderData);
|
|
40
|
-
this.callback(null, ...args);
|
|
41
|
-
};
|
|
42
|
-
const probeLoader = loaderModule;
|
|
43
|
-
export default probeLoader;
|
|
44
|
-
export { loaderModule };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { Loader } from "../../../common/index.js";
|
|
3
|
-
import { Build } from "../../index.js";
|
|
4
|
-
import { Utils } from "../index.js";
|
|
5
|
-
const BuiltinLoaderName = 'builtin:swc-loader';
|
|
6
|
-
const BuiltinLightingCssName = 'builtin:lightningcss-loader';
|
|
7
|
-
const ESMLoaderFile = '.mjs';
|
|
8
|
-
class ProbeLoaderPlugin {
|
|
9
|
-
apply(compiler) {
|
|
10
|
-
compiler.hooks.beforeRun.tap({
|
|
11
|
-
name: 'ProbeLoaderPlugin'
|
|
12
|
-
}, ()=>{
|
|
13
|
-
this.addProbeLoader(compiler);
|
|
14
|
-
});
|
|
15
|
-
compiler.hooks.watchRun.tap({
|
|
16
|
-
name: 'ProbeLoaderPlugin'
|
|
17
|
-
}, ()=>{
|
|
18
|
-
this.addProbeLoader(compiler);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
addProbeLoader(compiler) {
|
|
22
|
-
let rules = compiler.options.module.rules;
|
|
23
|
-
if (Loader.isVue(compiler)) {
|
|
24
|
-
compiler.options.module.rules = Utils.addProbeLoader2Rules(rules, compiler, (r)=>!!r.loader || 'string' == typeof r);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
rules = Utils.addProbeLoader2Rules(rules, compiler, (r)=>Build.Utils.getLoaderNameMatch(r, BuiltinLoaderName, true));
|
|
28
|
-
rules = Utils.addProbeLoader2Rules(rules, compiler, (r)=>Build.Utils.getLoaderNameMatch(r, BuiltinLightingCssName, true));
|
|
29
|
-
compiler.options.module.rules = Utils.addProbeLoader2Rules(rules, compiler, (r)=>Build.Utils.getLoaderNameMatch(r, ESMLoaderFile, false) || Build.Utils.isESMLoader(r));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export { ProbeLoaderPlugin };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { parser } from "../../../rule-utils/index.js";
|
|
3
|
-
const esmLabelStatement = parser.internal.parseExpressionAt('Object.defineProperty(exports, "__esModule", { value: true })', 0, {
|
|
4
|
-
ecmaVersion: 6,
|
|
5
|
-
ranges: false,
|
|
6
|
-
locations: false,
|
|
7
|
-
sourceType: "script"
|
|
8
|
-
});
|
|
9
|
-
function hasSetEsModuleStatement(program) {
|
|
10
|
-
const expressions = program.body.filter(parser.asserts.isExpressionStatement).map((item)=>item.expression).filter(parser.asserts.isSimpleCallExpression);
|
|
11
|
-
return expressions.some((exp)=>parser.utils.isSameSemantics(exp, esmLabelStatement));
|
|
12
|
-
}
|
|
13
|
-
export { hasSetEsModuleStatement };
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { Dependency, Module, extractCodeFromSourceLines, parseLocation } from "../../../../graph/index.js";
|
|
3
|
-
import { SDK } from "@rsdoctor/shared/types";
|
|
4
|
-
const createDependencyKind = (type)=>{
|
|
5
|
-
if (type.includes('harmony') || 'esm import' === type) return SDK.DependencyKind.ImportStatement;
|
|
6
|
-
if (type.includes('cjs')) return SDK.DependencyKind.RequireCall;
|
|
7
|
-
if (type.includes('import()')) return SDK.DependencyKind.DynamicImport;
|
|
8
|
-
if (type.includes('amd')) return SDK.DependencyKind.AMDRequire;
|
|
9
|
-
return SDK.DependencyKind.Unknown;
|
|
10
|
-
};
|
|
11
|
-
function patchNativeModuleGraph(mg, cg, rawModuleGraph) {
|
|
12
|
-
const { modules: rawModules, dependencies: rawDependencies, chunkModules: rawChunkModules } = rawModuleGraph;
|
|
13
|
-
const modules = rawModules.map((module)=>{
|
|
14
|
-
const res = new Module(module.identifier, module.path, module.isEntry, 'concatenated' === module.kind ? SDK.ModuleKind.Concatenation : SDK.ModuleKind.Normal, void 0, module.layer);
|
|
15
|
-
res.setId(module.ukey);
|
|
16
|
-
return res;
|
|
17
|
-
});
|
|
18
|
-
mg.setModules(modules);
|
|
19
|
-
for (const rawModule of rawModules){
|
|
20
|
-
const module = mg.getModuleById(rawModule.ukey);
|
|
21
|
-
if (module) module.setImported(rawModule.imported.map((ukey)=>mg.getModuleById(ukey)).filter(Boolean));
|
|
22
|
-
}
|
|
23
|
-
for (const rawModule of rawModules){
|
|
24
|
-
const module = mg.getModuleById(rawModule.ukey);
|
|
25
|
-
module.setModules(rawModule.modules.map((ukey)=>mg.getModuleById(ukey)).filter(Boolean));
|
|
26
|
-
}
|
|
27
|
-
for (const rawModule of rawModules){
|
|
28
|
-
const module = mg.getModuleById(rawModule.ukey);
|
|
29
|
-
if (module) module.setConcatenationModules(rawModule.belongModules.map((ukey)=>mg.getModuleById(ukey)).filter(Boolean));
|
|
30
|
-
}
|
|
31
|
-
for (const rawModule of rawModules){
|
|
32
|
-
const module = mg.getModuleById(rawModule.ukey);
|
|
33
|
-
if (module) module.setChunks(rawModule.chunks.map((ukey)=>cg.getChunkById(ukey.toString())).filter(Boolean));
|
|
34
|
-
}
|
|
35
|
-
for (const rawChunkModule of rawChunkModules){
|
|
36
|
-
const chunk = cg.getChunkById(rawChunkModule.chunk.toString());
|
|
37
|
-
if (chunk) chunk.setModules(rawChunkModule.modules.map((ukey)=>mg.getModuleById(ukey)).filter(Boolean));
|
|
38
|
-
}
|
|
39
|
-
const deppendencies = rawDependencies.map((dep)=>{
|
|
40
|
-
const res = new Dependency(dep.request, mg.getModuleById(dep.module), mg.getModuleById(dep.dependency), createDependencyKind(dep.kind));
|
|
41
|
-
res.setId(dep.ukey);
|
|
42
|
-
if (void 0 !== dep.kind) res.typeString = dep.kind;
|
|
43
|
-
return res;
|
|
44
|
-
});
|
|
45
|
-
mg.setDependencies(deppendencies);
|
|
46
|
-
for (const rawModule of rawModules){
|
|
47
|
-
const module = mg.getModuleById(rawModule.ukey);
|
|
48
|
-
module.setDependencies(rawModule.dependencies.map((ukey)=>mg.getDependencyById(ukey)).filter(Boolean));
|
|
49
|
-
if (module && rawModule.bailoutReason) rawModule.bailoutReason.filter((reason)=>!reason.includes('ModuleConcatenation bailout')).forEach((reason)=>module.addBailoutReason(reason));
|
|
50
|
-
if (module && 'sideEffectsLocations' in rawModule && Array.isArray(rawModule.sideEffectsLocations) && rawModule.sideEffectsLocations.length) rawModule.sideEffectsLocations.forEach((item)=>{
|
|
51
|
-
module.addSideEffectLocation({
|
|
52
|
-
location: item.location,
|
|
53
|
-
nodeType: item.nodeType,
|
|
54
|
-
module: item.module,
|
|
55
|
-
request: item.request
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
const rawConnectionsOnlyImports = rawModuleGraph.connectionsOnlyImports;
|
|
60
|
-
if (rawConnectionsOnlyImports?.length) mg.setConnectionsOnlyImports(rawConnectionsOnlyImports);
|
|
61
|
-
}
|
|
62
|
-
function patchNativeModuleIds(mg, rawModuleIdsPatch) {
|
|
63
|
-
const { moduleIds: rawModuleIds } = rawModuleIdsPatch;
|
|
64
|
-
for (const rawModuleId of rawModuleIds){
|
|
65
|
-
const module = mg.getModuleById(rawModuleId.module);
|
|
66
|
-
if (module) module.setRenderId(rawModuleId.renderId);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function patchNativeModuleSources(mg, rawModuleSourcesPatch) {
|
|
70
|
-
const { moduleOriginalSources: rawModuleOriginalSources } = rawModuleSourcesPatch;
|
|
71
|
-
for (const rawModuleOriginalSource of rawModuleOriginalSources){
|
|
72
|
-
const module = mg.getModuleById(rawModuleOriginalSource.module);
|
|
73
|
-
if (module) {
|
|
74
|
-
module.setSource({
|
|
75
|
-
source: rawModuleOriginalSource.source
|
|
76
|
-
});
|
|
77
|
-
module.setSize({
|
|
78
|
-
sourceSize: rawModuleOriginalSource.size
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const jsonModuleSizes = rawModuleSourcesPatch.jsonModuleSizes;
|
|
83
|
-
if (jsonModuleSizes && jsonModuleSizes.length > 0) for (const jsonModuleSize of jsonModuleSizes){
|
|
84
|
-
const module = mg.getModuleByIdentifier(jsonModuleSize.identifier);
|
|
85
|
-
if (module) module.setSize({
|
|
86
|
-
parsedSize: jsonModuleSize.size
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function extractSideEffectCodes(mg) {
|
|
91
|
-
const modules = mg.getModules();
|
|
92
|
-
for (const module of modules){
|
|
93
|
-
const sideEffectLocations = module.getSideEffectLocations();
|
|
94
|
-
if (!sideEffectLocations.length) continue;
|
|
95
|
-
const moduleSource = module.getSource();
|
|
96
|
-
const source = moduleSource.source || moduleSource.parsedSource;
|
|
97
|
-
if (!source) continue;
|
|
98
|
-
const sourceLines = source.split('\n');
|
|
99
|
-
for (const sideEffectLocation of sideEffectLocations){
|
|
100
|
-
const parsedLocation = parseLocation(sideEffectLocation.location);
|
|
101
|
-
if (!parsedLocation) continue;
|
|
102
|
-
const code = extractCodeFromSourceLines(sourceLines, parsedLocation);
|
|
103
|
-
if (code) module.addSideEffectCode({
|
|
104
|
-
moduleId: module.id,
|
|
105
|
-
startLine: parsedLocation.startLine,
|
|
106
|
-
code
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
export { extractSideEffectCodes, patchNativeModuleGraph, patchNativeModuleIds, patchNativeModuleSources };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { parser } from "../../../rule-utils/index.js";
|
|
3
|
-
function getDefaultExportIdentifier(node, module, searchId) {
|
|
4
|
-
const { declaration } = node;
|
|
5
|
-
if (parser.asserts.isLiteral(declaration) && declaration.loc) return module.getStatement(declaration.loc);
|
|
6
|
-
if (parser.asserts.isIdentifier(declaration)) {
|
|
7
|
-
if (searchId) {
|
|
8
|
-
const result = getDeclarationIdentifier(declaration.name, module);
|
|
9
|
-
if (result) return result;
|
|
10
|
-
} else if (declaration.loc) return module.getStatement(declaration.loc);
|
|
11
|
-
}
|
|
12
|
-
if (parser.asserts.isClassDeclaration(declaration) || parser.asserts.isFunctionDeclaration(declaration)) {
|
|
13
|
-
if (declaration.id?.loc) return module.getStatement(declaration.id.loc);
|
|
14
|
-
}
|
|
15
|
-
const startLine = node.declaration.loc?.start.line;
|
|
16
|
-
if ('number' != typeof startLine) return;
|
|
17
|
-
const { transformed } = module.getSource();
|
|
18
|
-
const line = transformed.split('\n')[startLine - 1];
|
|
19
|
-
if (void 0 === line) return;
|
|
20
|
-
const endColumn = line.length - 1;
|
|
21
|
-
return module.getStatement({
|
|
22
|
-
start: {
|
|
23
|
-
line: startLine,
|
|
24
|
-
column: 0
|
|
25
|
-
},
|
|
26
|
-
end: {
|
|
27
|
-
line: startLine,
|
|
28
|
-
column: endColumn
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
function getExportIdentifierStatement(name, module) {
|
|
33
|
-
const ast = module.getProgram();
|
|
34
|
-
if (!ast) return;
|
|
35
|
-
for (const node of ast.body){
|
|
36
|
-
if (parser.asserts.isExportDefaultDeclaration(node)) {
|
|
37
|
-
const result = getDefaultExportIdentifier(node, module, false);
|
|
38
|
-
if (result) return result;
|
|
39
|
-
}
|
|
40
|
-
const id = parser.utils.getIdentifierInExport(name, node);
|
|
41
|
-
if (id?.loc) return module.getStatement(id.loc);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function getDeclarationIdentifier(name, module) {
|
|
45
|
-
const ast = module.getProgram();
|
|
46
|
-
if (!ast) return;
|
|
47
|
-
for (const node of ast.body){
|
|
48
|
-
const id = parser.utils.getIdentifierInDeclaration(name, node);
|
|
49
|
-
if (id?.loc) return module.getStatement(id.loc);
|
|
50
|
-
if (parser.asserts.isExportNamedDeclaration(node) && node.declaration) {
|
|
51
|
-
const id = parser.utils.getIdentifierInDeclaration(name, node.declaration);
|
|
52
|
-
if (id?.loc) return module.getStatement(id.loc);
|
|
53
|
-
}
|
|
54
|
-
if ('default' === name && parser.asserts.isExportDefaultDeclaration(node)) {
|
|
55
|
-
const result = getDefaultExportIdentifier(node, module, true);
|
|
56
|
-
if (result) return result;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export { getDeclarationIdentifier, getExportIdentifierStatement };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { filesize } from "filesize";
|
|
3
|
-
import { memoryUsage, pid } from "process";
|
|
4
|
-
function getMemoryUsage() {
|
|
5
|
-
return memoryUsage();
|
|
6
|
-
}
|
|
7
|
-
function getMemoryUsageMessage() {
|
|
8
|
-
const usage = getMemoryUsage();
|
|
9
|
-
const msgs = [
|
|
10
|
-
`RSS: ${filesize(usage.rss)}`,
|
|
11
|
-
`Heap Total: ${filesize(usage.heapTotal)}`,
|
|
12
|
-
`Heap Used: ${filesize(usage.heapUsed)}`
|
|
13
|
-
];
|
|
14
|
-
if (usage.arrayBuffers) msgs.push(`ArrayBuffers: ${filesize(usage.arrayBuffers)}`);
|
|
15
|
-
if (usage.external) msgs.push(`External: ${filesize(usage.external)}`);
|
|
16
|
-
return `["${pid}" Memory Usage] ${msgs.join(', ')}`;
|
|
17
|
-
}
|
|
18
|
-
export { getMemoryUsage, getMemoryUsageMessage };
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import connect from "connect";
|
|
3
|
-
import http from "http";
|
|
4
|
-
import os from "os";
|
|
5
|
-
import get_port from "get-port";
|
|
6
|
-
import { execFileSync } from "child_process";
|
|
7
|
-
import { Algorithm } from "../../common/index.js";
|
|
8
|
-
const RESTRICTED_PORTS = [
|
|
9
|
-
3659,
|
|
10
|
-
4045,
|
|
11
|
-
6000,
|
|
12
|
-
6665,
|
|
13
|
-
6666,
|
|
14
|
-
6667,
|
|
15
|
-
6668,
|
|
16
|
-
6669
|
|
17
|
-
];
|
|
18
|
-
const defaultHost = '127.0.0.1';
|
|
19
|
-
function getRandomPort(min, max) {
|
|
20
|
-
let port;
|
|
21
|
-
do port = Algorithm.random(min, max);
|
|
22
|
-
while (RESTRICTED_PORTS.includes(port));
|
|
23
|
-
return port;
|
|
24
|
-
}
|
|
25
|
-
const defaultPort = getRandomPort(3000, 8999);
|
|
26
|
-
async function getPort(expectPort, host = defaultHost) {
|
|
27
|
-
return get_port({
|
|
28
|
-
port: expectPort,
|
|
29
|
-
host
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
const createGetPortSyncFunctionString = (expectPort, host = defaultHost)=>`
|
|
33
|
-
(() => {
|
|
34
|
-
const net = require('net');
|
|
35
|
-
|
|
36
|
-
function getPort(expectPort, host) {
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
const server = net.createServer();
|
|
39
|
-
server.unref();
|
|
40
|
-
server.on('error', reject);
|
|
41
|
-
server.listen(expectPort, host, () => {
|
|
42
|
-
const { port } = server.address();
|
|
43
|
-
server.close(() => {
|
|
44
|
-
resolve(port);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async function getAvailablePort(expectPort) {
|
|
51
|
-
let port = expectPort;
|
|
52
|
-
while (true) {
|
|
53
|
-
try {
|
|
54
|
-
const res = await getPort(port, ${JSON.stringify(host)});
|
|
55
|
-
return res;
|
|
56
|
-
} catch (error) {
|
|
57
|
-
port += Math.floor(Math.random() * 100 + 1);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
getAvailablePort(${expectPort}).then(port => process.stdout.write(port.toString()));
|
|
63
|
-
})();
|
|
64
|
-
`.trim();
|
|
65
|
-
function getPortSync(expectPort, host = defaultHost) {
|
|
66
|
-
const statement = '\n' === os.EOL ? createGetPortSyncFunctionString(expectPort, host) : createGetPortSyncFunctionString(expectPort, host).replace(/\n/g, '');
|
|
67
|
-
const port = execFileSync(process.execPath, [
|
|
68
|
-
'-e',
|
|
69
|
-
statement
|
|
70
|
-
], {
|
|
71
|
-
encoding: 'utf-8'
|
|
72
|
-
});
|
|
73
|
-
return Number(port);
|
|
74
|
-
}
|
|
75
|
-
function createApp() {
|
|
76
|
-
return connect();
|
|
77
|
-
}
|
|
78
|
-
async function createServer(port, host = defaultHost) {
|
|
79
|
-
const app = createApp();
|
|
80
|
-
const server = http.createServer(app);
|
|
81
|
-
const res = {
|
|
82
|
-
app,
|
|
83
|
-
server,
|
|
84
|
-
port,
|
|
85
|
-
close () {
|
|
86
|
-
return new Promise((resolve, reject)=>{
|
|
87
|
-
if ('closeAllConnections' in server) server.closeAllConnections();
|
|
88
|
-
if ('closeIdleConnections' in server) server.closeIdleConnections();
|
|
89
|
-
server.close((err)=>{
|
|
90
|
-
if (err) reject(err);
|
|
91
|
-
resolve();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
return new Promise((resolve, reject)=>{
|
|
97
|
-
const onError = (error)=>{
|
|
98
|
-
reject(error);
|
|
99
|
-
};
|
|
100
|
-
server.once('error', onError);
|
|
101
|
-
server.listen(port, host, ()=>{
|
|
102
|
-
server.off('error', onError);
|
|
103
|
-
resolve(res);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
export { createApp, createGetPortSyncFunctionString, createServer, defaultHost, defaultPort, getPort, getPortSync };
|
|
@@ -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 };
|