@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,92 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { Summary } from "../../common/index.js";
|
|
3
|
-
import { minBy, sumBy } from "../../collection.js";
|
|
4
|
-
import { InternalBasePlugin } from "./base.js";
|
|
5
|
-
import { time, timeEnd } from "../../logger.js";
|
|
6
|
-
class InternalSummaryPlugin extends InternalBasePlugin {
|
|
7
|
-
apply(compiler) {
|
|
8
|
-
time('InternalSummaryPlugin.apply');
|
|
9
|
-
try {
|
|
10
|
-
compiler.hooks.beforeCompile.tapPromise(this.tapPostOptions, this.beforeCompile);
|
|
11
|
-
compiler.hooks.afterCompile.tapPromise(this.tapPreOptions, this.afterCompile);
|
|
12
|
-
compiler.hooks.done.tapPromise(this.tapPostOptions, this.done.bind(this, compiler));
|
|
13
|
-
} finally{
|
|
14
|
-
timeEnd('InternalSummaryPlugin.apply');
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
mark(key, type) {
|
|
18
|
-
const now = Date.now();
|
|
19
|
-
switch(type){
|
|
20
|
-
case 'pre':
|
|
21
|
-
this.preTimes.set(key, now);
|
|
22
|
-
break;
|
|
23
|
-
case 'post':
|
|
24
|
-
this.postTimes.set(key, now);
|
|
25
|
-
break;
|
|
26
|
-
default:
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
report(name, start) {
|
|
31
|
-
this.times.set(name, start);
|
|
32
|
-
this.sdk.reportSummaryData({
|
|
33
|
-
costs: [
|
|
34
|
-
{
|
|
35
|
-
name,
|
|
36
|
-
startAt: start,
|
|
37
|
-
costs: Date.now() - start
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
constructor(...args){
|
|
43
|
-
super(...args), this.name = 'summary', this.times = new Map(), this.preTimes = new Map(), this.postTimes = new Map(), this.beforeCompile = async ()=>{
|
|
44
|
-
time('InternalSummaryPlugin.beforeCompile');
|
|
45
|
-
try {
|
|
46
|
-
if (!this.times.has(Summary.SummaryCostsDataName.Bootstrap)) {
|
|
47
|
-
const costs = Math.floor(1000 * process.uptime());
|
|
48
|
-
const startAt = Date.now() - costs;
|
|
49
|
-
this.report(Summary.SummaryCostsDataName.Bootstrap, startAt);
|
|
50
|
-
this.mark(Summary.SummaryCostsDataName.Bootstrap, 'post');
|
|
51
|
-
}
|
|
52
|
-
} finally{
|
|
53
|
-
timeEnd('InternalSummaryPlugin.beforeCompile');
|
|
54
|
-
}
|
|
55
|
-
}, this.afterCompile = async (compilation)=>{
|
|
56
|
-
time('InternalSummaryPlugin.afterCompile');
|
|
57
|
-
try {
|
|
58
|
-
if (!this.times.has(Summary.SummaryCostsDataName.Compile) && !compilation.compiler.isChild()) {
|
|
59
|
-
const start = this.postTimes.get(Summary.SummaryCostsDataName.Bootstrap);
|
|
60
|
-
this.report(Summary.SummaryCostsDataName.Compile, start);
|
|
61
|
-
this.mark(Summary.SummaryCostsDataName.Compile, 'post');
|
|
62
|
-
}
|
|
63
|
-
} finally{
|
|
64
|
-
timeEnd('InternalSummaryPlugin.afterCompile');
|
|
65
|
-
}
|
|
66
|
-
}, this.done = async (compiler)=>{
|
|
67
|
-
time('InternalSummaryPlugin.done');
|
|
68
|
-
try {
|
|
69
|
-
const start = this.postTimes.get(Summary.SummaryCostsDataName.Compile);
|
|
70
|
-
this.report(Summary.SummaryCostsDataName.Done, start);
|
|
71
|
-
if (false !== compiler.options.optimization.minimize) {
|
|
72
|
-
const pluginData = this.sdk.getStoreData().plugin;
|
|
73
|
-
const minifyHookData = [
|
|
74
|
-
...pluginData.processAssets || []
|
|
75
|
-
];
|
|
76
|
-
if (minifyHookData.length) this.sdk.reportSummaryData({
|
|
77
|
-
costs: [
|
|
78
|
-
{
|
|
79
|
-
name: Summary.SummaryCostsDataName.Minify,
|
|
80
|
-
startAt: minBy(minifyHookData, (e)=>e.startAt).startAt,
|
|
81
|
-
costs: sumBy(minifyHookData, (e)=>e.costs)
|
|
82
|
-
}
|
|
83
|
-
]
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
} finally{
|
|
87
|
-
timeEnd('InternalSummaryPlugin.done');
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
export { InternalSummaryPlugin };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
const checkCirclePath = (obj, record, res, level, maxLevel = 3)=>{
|
|
3
|
-
const idx = record.slice(0, record.length - 1).findIndex((v)=>v.ref === obj);
|
|
4
|
-
if (-1 !== idx) {
|
|
5
|
-
const key = record.map((v)=>v.prop);
|
|
6
|
-
if (res.indexOf(key) < 0) return void res.push(key);
|
|
7
|
-
}
|
|
8
|
-
if ('object' == typeof obj && null !== obj && level < maxLevel) for (const [k, v] of Object.entries(obj))checkCirclePath(v, [
|
|
9
|
-
...record,
|
|
10
|
-
{
|
|
11
|
-
prop: k,
|
|
12
|
-
ref: v
|
|
13
|
-
}
|
|
14
|
-
], res, level + 1);
|
|
15
|
-
};
|
|
16
|
-
export { checkCirclePath };
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { SDK } from "@rsdoctor/shared/types";
|
|
3
|
-
import { chalk, logger } from "../../logger.js";
|
|
4
|
-
import assert from "assert";
|
|
5
|
-
import { convertReportCodeTypeObject, processModeConfigurations } from "./normalize-config.js";
|
|
6
|
-
function defaultBoolean(v, dft) {
|
|
7
|
-
return 'boolean' == typeof v ? v : dft;
|
|
8
|
-
}
|
|
9
|
-
function getDefaultOutput() {
|
|
10
|
-
return {
|
|
11
|
-
mode: void 0,
|
|
12
|
-
reportCodeType: {
|
|
13
|
-
noModuleSource: false,
|
|
14
|
-
noAssetsAndModuleSource: false,
|
|
15
|
-
noCode: false
|
|
16
|
-
},
|
|
17
|
-
options: void 0,
|
|
18
|
-
reportDir: '',
|
|
19
|
-
compressData: void 0
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function getDefaultSupports() {
|
|
23
|
-
return {
|
|
24
|
-
parseBundle: true,
|
|
25
|
-
gzip: true
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function isJsonOutputEnv(value) {
|
|
29
|
-
return 'json' === value;
|
|
30
|
-
}
|
|
31
|
-
function normalizeFeatures(features, mode) {
|
|
32
|
-
if (Array.isArray(features)) return {
|
|
33
|
-
loader: features.includes('loader'),
|
|
34
|
-
plugins: features.includes('plugins'),
|
|
35
|
-
resolver: features.includes('resolver'),
|
|
36
|
-
bundle: features.includes('bundle'),
|
|
37
|
-
treeShaking: features.includes('treeShaking'),
|
|
38
|
-
lite: features.includes('lite') || mode === SDK.IMode[SDK.IMode.lite]
|
|
39
|
-
};
|
|
40
|
-
return {
|
|
41
|
-
loader: defaultBoolean(features.loader, true),
|
|
42
|
-
plugins: defaultBoolean(features.plugins, true),
|
|
43
|
-
resolver: defaultBoolean(features.resolver, false),
|
|
44
|
-
bundle: defaultBoolean(features.bundle, true),
|
|
45
|
-
treeShaking: defaultBoolean(features.treeShaking, false),
|
|
46
|
-
lite: defaultBoolean(features.lite, false) || mode === SDK.IMode[SDK.IMode.lite]
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function normalizeLinter(linter) {
|
|
50
|
-
return {
|
|
51
|
-
rules: {},
|
|
52
|
-
extends: [],
|
|
53
|
-
level: 'Error',
|
|
54
|
-
...linter
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function isValidMode(mode) {
|
|
58
|
-
return 'string' == typeof mode && [
|
|
59
|
-
'brief',
|
|
60
|
-
'normal',
|
|
61
|
-
'lite'
|
|
62
|
-
].includes(mode);
|
|
63
|
-
}
|
|
64
|
-
function normalizeUserConfig(config = {}) {
|
|
65
|
-
const userOutput = config.output;
|
|
66
|
-
const defaultOutput = getDefaultOutput();
|
|
67
|
-
const outputConfig = isJsonOutputEnv(process.env.RSDOCTOR_OUTPUT) ? {
|
|
68
|
-
reportDir: userOutput?.reportDir,
|
|
69
|
-
compressData: userOutput?.compressData,
|
|
70
|
-
mode: 'brief',
|
|
71
|
-
options: {
|
|
72
|
-
type: [
|
|
73
|
-
'json'
|
|
74
|
-
]
|
|
75
|
-
}
|
|
76
|
-
} : userOutput ?? defaultOutput;
|
|
77
|
-
const normalizedConfig = {
|
|
78
|
-
...config,
|
|
79
|
-
output: outputConfig
|
|
80
|
-
};
|
|
81
|
-
const { linter = {}, features = {}, loaderInterceptorOptions = {}, disableClientServer: userDisableClientServer = false, sdkInstance, innerClientPath = '', output = outputConfig, supports: userSupports = {}, port, server: userServer = {}, printLog = {
|
|
82
|
-
serverUrls: true
|
|
83
|
-
}, mode, brief } = normalizedConfig;
|
|
84
|
-
const supports = {
|
|
85
|
-
...getDefaultSupports(),
|
|
86
|
-
...userSupports
|
|
87
|
-
};
|
|
88
|
-
const disableClientServer = 'true' === process.env.RSTEST ? false : process.env.CI ? true : userDisableClientServer;
|
|
89
|
-
assert('object' == typeof linter);
|
|
90
|
-
assert('object' == typeof features || Array.isArray(features));
|
|
91
|
-
assert('object' == typeof loaderInterceptorOptions);
|
|
92
|
-
assert('boolean' == typeof disableClientServer);
|
|
93
|
-
assert(void 0 === port || 'number' == typeof port);
|
|
94
|
-
assert('object' == typeof userServer && null !== userServer);
|
|
95
|
-
const server = {
|
|
96
|
-
...userServer
|
|
97
|
-
};
|
|
98
|
-
assert(void 0 === server.port || 'number' == typeof server.port);
|
|
99
|
-
if (void 0 === server.port && void 0 !== port) server.port = port;
|
|
100
|
-
let finalMode = ('mode' in output && isValidMode(output.mode) ? 'lite' === output.mode ? SDK.IMode[SDK.IMode.normal] : output.mode : void 0) || mode || SDK.IMode[SDK.IMode.normal];
|
|
101
|
-
if (mode) logger.info(chalk.yellow("The 'mode' configuration will be deprecated in a future version. Please use 'output.mode' instead."));
|
|
102
|
-
const _features = normalizeFeatures(features, finalMode);
|
|
103
|
-
const _linter = normalizeLinter(linter);
|
|
104
|
-
if (_features.lite || finalMode === SDK.IMode[SDK.IMode.lite]) logger.info(chalk.yellow("Lite features will be deprecated in a future version. Please use 'output: { reportCodeType: { noAssetsAndModuleSource: true }}' instead."));
|
|
105
|
-
const { finalBrief, finalNormalOptions } = processModeConfigurations(finalMode, output, brief);
|
|
106
|
-
if (_features.lite && finalMode !== SDK.IMode[SDK.IMode.brief]) finalMode = SDK.IMode[SDK.IMode.lite];
|
|
107
|
-
const reportCodeType = output.reportCodeType ? normalizeReportType(output.reportCodeType, finalMode) : normalizeReportType(getDefaultOutput().reportCodeType, finalMode);
|
|
108
|
-
const res = {
|
|
109
|
-
linter: _linter,
|
|
110
|
-
features: _features,
|
|
111
|
-
loaderInterceptorOptions: {
|
|
112
|
-
skipLoaders: Array.isArray(loaderInterceptorOptions.skipLoaders) ? loaderInterceptorOptions.skipLoaders : []
|
|
113
|
-
},
|
|
114
|
-
disableClientServer,
|
|
115
|
-
sdkInstance,
|
|
116
|
-
output: {
|
|
117
|
-
mode: finalMode,
|
|
118
|
-
options: 'brief' === finalMode ? finalBrief : finalNormalOptions,
|
|
119
|
-
reportCodeType,
|
|
120
|
-
reportDir: output.reportDir || ''
|
|
121
|
-
},
|
|
122
|
-
innerClientPath,
|
|
123
|
-
supports,
|
|
124
|
-
port,
|
|
125
|
-
server,
|
|
126
|
-
printLog
|
|
127
|
-
};
|
|
128
|
-
if (void 0 !== output.compressData) logger.info(chalk.yellow("The 'compressData' configuration will be deprecated in a future version."));
|
|
129
|
-
return res;
|
|
130
|
-
}
|
|
131
|
-
const normalizeReportType = (reportCodeType, mode)=>{
|
|
132
|
-
const convertedReportCodeType = 'object' == typeof reportCodeType ? convertReportCodeTypeObject(reportCodeType) : reportCodeType;
|
|
133
|
-
if ('noCode' === convertedReportCodeType) return SDK.ToDataType.NoCode;
|
|
134
|
-
if (mode === SDK.IMode[SDK.IMode.brief]) return SDK.ToDataType.NoCode;
|
|
135
|
-
if (mode === SDK.IMode[SDK.IMode.lite]) return SDK.ToDataType.NoSourceAndAssets;
|
|
136
|
-
if ('noAssetsAndModuleSource' === convertedReportCodeType) return SDK.ToDataType.NoSourceAndAssets;
|
|
137
|
-
if ('noModuleSource' === convertedReportCodeType) return SDK.ToDataType.NoSource;
|
|
138
|
-
return SDK.ToDataType.Normal;
|
|
139
|
-
};
|
|
140
|
-
const normalizeRspackUserOptions = normalizeUserConfig;
|
|
141
|
-
export { normalizeReportType, normalizeRspackUserOptions, normalizeUserConfig };
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { omit } from "../../collection.js";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { logger } from "../../logger.js";
|
|
5
|
-
import { Fetch, Loader, Lodash, Time } from "../../common/index.js";
|
|
6
|
-
import { SDK } from "@rsdoctor/shared/types";
|
|
7
|
-
import { DevToolError } from "../../error/index.js";
|
|
8
|
-
import { getSDK } from "./sdk.js";
|
|
9
|
-
import { checkCirclePath } from "./circleDetect.js";
|
|
10
|
-
import { Utils } from "../../build-utils/build/index.js";
|
|
11
|
-
import { isESMLoader, parseQuery } from "../../build-utils/build/utils/index.js";
|
|
12
|
-
function getInternalLoaderOptions(loaderContext) {
|
|
13
|
-
const options = loaderContext.getOptions();
|
|
14
|
-
return options[Loader.LoaderInternalPropertyName];
|
|
15
|
-
}
|
|
16
|
-
function getLoaderOptionsWithoutInternalKeys(loaderContext) {
|
|
17
|
-
const options = loaderContext.getOptions();
|
|
18
|
-
const circlePaths = [];
|
|
19
|
-
const loaderOptions = omit(options, [
|
|
20
|
-
Loader.LoaderInternalPropertyName
|
|
21
|
-
]);
|
|
22
|
-
checkCirclePath(loaderOptions, [], circlePaths, 0);
|
|
23
|
-
if (circlePaths.length > 0) circlePaths.forEach((_path)=>{
|
|
24
|
-
if (_path?.length > 0 && '[Circular]' !== loaderOptions[_path[0]]) loaderOptions[_path[0]] = '[Circular]';
|
|
25
|
-
});
|
|
26
|
-
return loaderOptions;
|
|
27
|
-
}
|
|
28
|
-
function getOriginLoaderModule(loaderContext) {
|
|
29
|
-
const { loader, cwd } = getInternalLoaderOptions(loaderContext);
|
|
30
|
-
return Utils.loadLoaderModule(loader, cwd);
|
|
31
|
-
}
|
|
32
|
-
function shouldSkipLoader(loaderContext) {
|
|
33
|
-
const { skipLoaders, cwd, loader } = getInternalLoaderOptions(loaderContext) || {};
|
|
34
|
-
if (!loader) return true;
|
|
35
|
-
if (Array.isArray(skipLoaders) && skipLoaders.length) {
|
|
36
|
-
if (skipLoaders.includes(loader)) return true;
|
|
37
|
-
const loaderName = Utils.extractLoaderName(loader, cwd);
|
|
38
|
-
if (skipLoaders.includes(loaderName)) return true;
|
|
39
|
-
}
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
function interceptLoader(rules, loaderPath, options, loaderResolver, cwd = process.cwd()) {
|
|
43
|
-
const resolve = (target)=>{
|
|
44
|
-
try {
|
|
45
|
-
const result = loaderResolver.resolveSync({}, cwd, target);
|
|
46
|
-
if (result) return result;
|
|
47
|
-
} catch {}
|
|
48
|
-
return target;
|
|
49
|
-
};
|
|
50
|
-
return Utils.mapEachRules(rules, (rule)=>{
|
|
51
|
-
if (rule.loader?.startsWith('builtin:') || rule.loader?.endsWith('.mjs') || isESMLoader(rule)) return rule;
|
|
52
|
-
const opts = {
|
|
53
|
-
...'options' in rule ? 'string' == typeof rule.options ? JSON.parse(rule.options) : rule.options : {}
|
|
54
|
-
};
|
|
55
|
-
opts[Loader.LoaderInternalPropertyName] = rule.loader && /proxy\.(js|cjs)/.test(rule.loader) && 'options' in rule && 'object' == typeof rule.options ? rule.options[Loader.LoaderInternalPropertyName] : {
|
|
56
|
-
...options,
|
|
57
|
-
hasOptions: 'options' in rule && Boolean(rule.options),
|
|
58
|
-
loader: 'loader' in rule ? resolve(rule.loader) : ''
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
...rule,
|
|
62
|
-
loader: loaderPath,
|
|
63
|
-
options: opts
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
async function reportLoader(ctx, start, startHRTime, isPitch, sync, code, err, res, sourceMap) {
|
|
68
|
-
const end = Time.getCurrentTimestamp(start, startHRTime);
|
|
69
|
-
const { loader, host } = getInternalLoaderOptions(ctx);
|
|
70
|
-
const loaderData = [
|
|
71
|
-
{
|
|
72
|
-
resource: {
|
|
73
|
-
path: ctx._module?.layer ? `${ctx.resourcePath}[${ctx._module.layer}]` : ctx.resourcePath,
|
|
74
|
-
query: parseQuery(ctx.resourceQuery || '?'),
|
|
75
|
-
queryRaw: ctx.resourceQuery,
|
|
76
|
-
ext: path.extname(ctx.resourcePath).slice(1),
|
|
77
|
-
...ctx._module?.layer ? {
|
|
78
|
-
layer: ctx._module.layer
|
|
79
|
-
} : {}
|
|
80
|
-
},
|
|
81
|
-
loaders: [
|
|
82
|
-
{
|
|
83
|
-
loader: Utils.extractLoaderName(loader),
|
|
84
|
-
loaderIndex: ctx.loaderIndex,
|
|
85
|
-
path: loader,
|
|
86
|
-
input: code,
|
|
87
|
-
result: 'string' == typeof res || Buffer.isBuffer(res) ? res.toString() : res,
|
|
88
|
-
startAt: start,
|
|
89
|
-
endAt: end,
|
|
90
|
-
options: getLoaderOptionsWithoutInternalKeys(ctx),
|
|
91
|
-
isPitch,
|
|
92
|
-
sync,
|
|
93
|
-
errors: err ? [
|
|
94
|
-
new DevToolError(code, err.message, {
|
|
95
|
-
controller: {
|
|
96
|
-
noStack: false,
|
|
97
|
-
noColor: true
|
|
98
|
-
},
|
|
99
|
-
stack: err.stack
|
|
100
|
-
})
|
|
101
|
-
] : [],
|
|
102
|
-
pid: process.pid,
|
|
103
|
-
ppid: process.ppid
|
|
104
|
-
}
|
|
105
|
-
]
|
|
106
|
-
}
|
|
107
|
-
];
|
|
108
|
-
const data = sourceMap ? Lodash.isString(sourceMap) ? JSON.parse(sourceMap) : sourceMap : {};
|
|
109
|
-
const sourceMapData = {
|
|
110
|
-
version: data.version ?? -1,
|
|
111
|
-
sources: data.sources ?? [],
|
|
112
|
-
names: data.names ?? [],
|
|
113
|
-
sourceRoot: data.sourceRoot,
|
|
114
|
-
sourcesContent: data.sourcesContent,
|
|
115
|
-
mappings: data.mappings,
|
|
116
|
-
file: loaderData[0].resource.path
|
|
117
|
-
};
|
|
118
|
-
const sdk = getSDK(ctx._compilation?.name);
|
|
119
|
-
if (sdk?.reportLoader && !('parent' in sdk && sdk.parent)) {
|
|
120
|
-
sdk.reportLoader(loaderData);
|
|
121
|
-
sdk.reportSourceMap(sourceMapData);
|
|
122
|
-
return loaderData;
|
|
123
|
-
}
|
|
124
|
-
await Promise.all([
|
|
125
|
-
Fetch.postJSON(`${host}${SDK.ServerAPI.API.ReportLoader}`, loaderData, 8888).catch((err)=>{
|
|
126
|
-
logger.debug(`${err.message}`, '[RspackPlugin.ReportLoader][error]');
|
|
127
|
-
}),
|
|
128
|
-
Fetch.postJSON(`${host}${SDK.ServerAPI.API.ReportSourceMap}`, sourceMapData, 8888).catch((err)=>{
|
|
129
|
-
logger.debug(`${err.message}`, '[RspackPlugin.ReportSourceMap][error]');
|
|
130
|
-
})
|
|
131
|
-
]);
|
|
132
|
-
return loaderData;
|
|
133
|
-
}
|
|
134
|
-
export { getInternalLoaderOptions, getLoaderOptionsWithoutInternalKeys, getOriginLoaderModule, interceptLoader, reportLoader, shouldSkipLoader };
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
function processModeConfigurations(finalMode, output, brief) {
|
|
3
|
-
let finalBrief = {};
|
|
4
|
-
let finalNormalOptions = {};
|
|
5
|
-
if ('brief' === finalMode) finalBrief = processBriefHtmlModeConfig(output, brief);
|
|
6
|
-
else if ('normal' === finalMode) finalNormalOptions = {};
|
|
7
|
-
return {
|
|
8
|
-
finalBrief,
|
|
9
|
-
finalNormalOptions
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
function processBriefHtmlModeConfig(output, brief) {
|
|
13
|
-
let htmlOptions = {
|
|
14
|
-
reportHtmlName: void 0,
|
|
15
|
-
writeDataJson: false
|
|
16
|
-
};
|
|
17
|
-
let jsonOptions = {};
|
|
18
|
-
const briefOptions = output?.options || {};
|
|
19
|
-
if ('type' in briefOptions && briefOptions.type?.includes('json')) jsonOptions = briefOptions.jsonOptions || {
|
|
20
|
-
fileName: 'rsdoctor-data.json',
|
|
21
|
-
sections: {
|
|
22
|
-
moduleGraph: true,
|
|
23
|
-
chunkGraph: true,
|
|
24
|
-
rules: true
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
if ('type' in briefOptions && briefOptions.type?.includes('html') || !briefOptions.type) {
|
|
28
|
-
const outputBriefOptions = briefOptions?.htmlOptions;
|
|
29
|
-
const outputBrief = brief;
|
|
30
|
-
htmlOptions = {
|
|
31
|
-
reportHtmlName: outputBriefOptions?.reportHtmlName || outputBrief?.reportHtmlName || void 0,
|
|
32
|
-
writeDataJson: outputBriefOptions?.writeDataJson || outputBrief?.writeDataJson || false
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
type: output.options?.type || [
|
|
37
|
-
'html'
|
|
38
|
-
],
|
|
39
|
-
htmlOptions,
|
|
40
|
-
jsonOptions
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function convertReportCodeTypeObject(reportCodeType) {
|
|
44
|
-
if (!reportCodeType) return;
|
|
45
|
-
if (reportCodeType.noCode) return 'noCode';
|
|
46
|
-
if (reportCodeType.noAssetsAndModuleSource) return 'noAssetsAndModuleSource';
|
|
47
|
-
if (reportCodeType.noModuleSource) return 'noModuleSource';
|
|
48
|
-
}
|
|
49
|
-
function makeRuleSetSerializable(item) {
|
|
50
|
-
if (!item) return;
|
|
51
|
-
if (item instanceof RegExp) item.toJSON = item.toString;
|
|
52
|
-
else if (Array.isArray(item)) item.forEach((i)=>makeRuleSetSerializable(i));
|
|
53
|
-
else if ('object' == typeof item) {
|
|
54
|
-
makeRuleSetSerializable(item.and);
|
|
55
|
-
makeRuleSetSerializable(item.or);
|
|
56
|
-
makeRuleSetSerializable(item.not);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function makeRulesSerializable(rules) {
|
|
60
|
-
if (!Array.isArray(rules)) return;
|
|
61
|
-
if (!rules.length) return;
|
|
62
|
-
rules.forEach((rule)=>{
|
|
63
|
-
if (!rule) return;
|
|
64
|
-
makeRuleSetSerializable(rule.test);
|
|
65
|
-
makeRuleSetSerializable(rule.resourceQuery);
|
|
66
|
-
makeRuleSetSerializable(rule.resource);
|
|
67
|
-
makeRuleSetSerializable(rule.resourceFragment);
|
|
68
|
-
makeRuleSetSerializable(rule.scheme);
|
|
69
|
-
makeRuleSetSerializable(rule.issuer);
|
|
70
|
-
if ('issuerLayer' in rule) makeRuleSetSerializable(rule.issuerLayer);
|
|
71
|
-
makeRuleSetSerializable(rule.include);
|
|
72
|
-
makeRuleSetSerializable(rule.exclude);
|
|
73
|
-
if (rule.oneOf) makeRulesSerializable(rule.oneOf);
|
|
74
|
-
if ('rules' in rule && rule.rules) makeRulesSerializable(rule.rules);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
export { convertReportCodeTypeObject, makeRuleSetSerializable, makeRulesSerializable, processBriefHtmlModeConfig, processModeConfigurations };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { exec } from "node:child_process";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
4
|
-
import { promisify } from "node:util";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { logger } from "../../logger.js";
|
|
7
|
-
const execAsync = promisify(exec);
|
|
8
|
-
const openBrowser_dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
const supportedChromiumBrowsers = [
|
|
10
|
-
'Google Chrome Canary',
|
|
11
|
-
'Google Chrome Dev',
|
|
12
|
-
'Google Chrome Beta',
|
|
13
|
-
'Google Chrome',
|
|
14
|
-
'Microsoft Edge',
|
|
15
|
-
'Brave Browser',
|
|
16
|
-
'Vivaldi',
|
|
17
|
-
'Chromium'
|
|
18
|
-
];
|
|
19
|
-
const getTargetBrowser = async ()=>{
|
|
20
|
-
let targetBrowser = process.env.BROWSER;
|
|
21
|
-
if (!targetBrowser || !supportedChromiumBrowsers.includes(targetBrowser)) {
|
|
22
|
-
const { stdout: ps } = await execAsync('ps cax');
|
|
23
|
-
targetBrowser = supportedChromiumBrowsers.find((b)=>ps.includes(b));
|
|
24
|
-
}
|
|
25
|
-
return targetBrowser;
|
|
26
|
-
};
|
|
27
|
-
const openWithDefaultBrowser = async (url)=>{
|
|
28
|
-
try {
|
|
29
|
-
const { default: open } = await import("open");
|
|
30
|
-
await open(url);
|
|
31
|
-
return true;
|
|
32
|
-
} catch (err) {
|
|
33
|
-
logger.error('Failed to open Rsdoctor URL.');
|
|
34
|
-
logger.error(err);
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
async function openBrowser(url, needEncodeURI = true) {
|
|
39
|
-
const shouldTryOpenChromeWithAppleScript = 'darwin' === process.platform;
|
|
40
|
-
if (shouldTryOpenChromeWithAppleScript) try {
|
|
41
|
-
const targetBrowser = await getTargetBrowser();
|
|
42
|
-
if (targetBrowser) {
|
|
43
|
-
await execAsync(`osascript openChrome.applescript "${needEncodeURI ? encodeURI(url) : url}" "${targetBrowser}"`, {
|
|
44
|
-
cwd: join(openBrowser_dirname, '../../../static')
|
|
45
|
-
});
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
logger.debug('Failed to find the target browser.');
|
|
49
|
-
} catch (err) {
|
|
50
|
-
logger.debug("Failed to open Rsdoctor URL with apple script.");
|
|
51
|
-
logger.debug(err);
|
|
52
|
-
}
|
|
53
|
-
return openWithDefaultBrowser(url);
|
|
54
|
-
}
|
|
55
|
-
export { openBrowser };
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { makeRulesSerializable } from "../index.js";
|
|
3
|
-
import { SDK } from "@rsdoctor/shared/types";
|
|
4
|
-
import { chalk } from "../../logger.js";
|
|
5
|
-
import path from "path";
|
|
6
|
-
import { openBrowser } from "./openBrowser.js";
|
|
7
|
-
function safeCloneDeep(value, visited = new WeakMap()) {
|
|
8
|
-
if (null == value) return value;
|
|
9
|
-
if ('object' != typeof value) return value;
|
|
10
|
-
if (value instanceof Date) return new Date(value.getTime());
|
|
11
|
-
if (value instanceof RegExp) return new RegExp(value.source, value.flags);
|
|
12
|
-
if (visited.has(value)) return visited.get(value);
|
|
13
|
-
if (Array.isArray(value)) {
|
|
14
|
-
const len = value.length;
|
|
15
|
-
const cloned = new Array(len);
|
|
16
|
-
visited.set(value, cloned);
|
|
17
|
-
for(let i = 0; i < len; i++)cloned[i] = safeCloneDeep(value[i], visited);
|
|
18
|
-
return cloned;
|
|
19
|
-
}
|
|
20
|
-
const cloned = {};
|
|
21
|
-
visited.set(value, cloned);
|
|
22
|
-
const ownPropertyNames = Object.getOwnPropertyNames(value);
|
|
23
|
-
const ownSymbols = Object.getOwnPropertySymbols(value);
|
|
24
|
-
const enumerableKeys = Object.keys(value);
|
|
25
|
-
const enumerableKeysSet = new Set(enumerableKeys);
|
|
26
|
-
const obj = value;
|
|
27
|
-
for(let i = 0; i < enumerableKeys.length; i++){
|
|
28
|
-
const key = enumerableKeys[i];
|
|
29
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
30
|
-
if (!descriptor || !descriptor.get || descriptor.set) try {
|
|
31
|
-
const propValue = obj[key];
|
|
32
|
-
cloned[key] = safeCloneDeep(propValue, visited);
|
|
33
|
-
} catch {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
for(let i = 0; i < ownPropertyNames.length; i++){
|
|
38
|
-
const key = ownPropertyNames[i];
|
|
39
|
-
if (enumerableKeysSet.has(key)) continue;
|
|
40
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
41
|
-
if (descriptor) {
|
|
42
|
-
if (!descriptor.get || descriptor.set) {
|
|
43
|
-
if (void 0 !== descriptor.set) try {
|
|
44
|
-
const propValue = obj[key];
|
|
45
|
-
cloned[key] = safeCloneDeep(propValue, visited);
|
|
46
|
-
} catch {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
for(let i = 0; i < ownSymbols.length; i++){
|
|
53
|
-
const key = ownSymbols[i];
|
|
54
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
55
|
-
if (descriptor) {
|
|
56
|
-
if (!descriptor.get || descriptor.set) {
|
|
57
|
-
if (descriptor.enumerable || void 0 !== descriptor.set) try {
|
|
58
|
-
const propValue = obj[key];
|
|
59
|
-
cloned[key] = safeCloneDeep(propValue, visited);
|
|
60
|
-
} catch {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return cloned;
|
|
67
|
-
}
|
|
68
|
-
function processCompilerConfig(config) {
|
|
69
|
-
const { plugins, infrastructureLogging: _infrastructureLogging, ...rest } = config;
|
|
70
|
-
const _rest = safeCloneDeep(rest);
|
|
71
|
-
if (_rest.module?.defaultRules) makeRulesSerializable(_rest.module.defaultRules);
|
|
72
|
-
if (_rest.module?.rules) makeRulesSerializable(_rest.module.rules);
|
|
73
|
-
return {
|
|
74
|
-
..._rest,
|
|
75
|
-
plugins: plugins.map((e)=>e?.constructor.name)
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
async function handleBriefModeReport(sdk, options, disableClientServer) {
|
|
79
|
-
if (!disableClientServer && options.output.mode === SDK.IMode[SDK.IMode.brief]) {
|
|
80
|
-
const outputTypes = options.output.options?.type || [];
|
|
81
|
-
const isJsonOnly = Array.isArray(outputTypes) && 1 === outputTypes.length && 'json' === outputTypes[0];
|
|
82
|
-
if (isJsonOnly) {
|
|
83
|
-
const jsonFileName = options.output.options?.jsonOptions?.fileName || 'rsdoctor-data.json';
|
|
84
|
-
const jsonFilePath = path.resolve(sdk.outputDir, jsonFileName);
|
|
85
|
-
console.log(`${chalk.green('[RSDOCTOR] generated JSON data')}: ${jsonFilePath}`);
|
|
86
|
-
} else {
|
|
87
|
-
const htmlOptions = 'htmlOptions' in options.output.options && options.output.options.htmlOptions || void 0;
|
|
88
|
-
const outputFilePath = path.resolve(sdk.outputDir, htmlOptions?.reportHtmlName || 'rsdoctor-report.html');
|
|
89
|
-
console.log(`${chalk.green('[RSDOCTOR] generated brief report')}: ${outputFilePath}`);
|
|
90
|
-
openBrowser(`file:///${outputFilePath}`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
export { handleBriefModeReport, processCompilerConfig, safeCloneDeep };
|