@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
package/dist/sdk/sdk/index.js
DELETED
|
@@ -1,435 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import node_fs from "node:fs";
|
|
3
|
-
import fs_extra from "fs-extra";
|
|
4
|
-
import path_0 from "path";
|
|
5
|
-
import { createRequire } from "module";
|
|
6
|
-
import { DevToolError } from "../../error/index.js";
|
|
7
|
-
import { Constants, SDK } from "@rsdoctor/shared/types";
|
|
8
|
-
import { SourceMapConsumer } from "source-map";
|
|
9
|
-
import { ChunkGraph, ModuleGraph, PackageGraph } from "../../graph/index.js";
|
|
10
|
-
import { logger } from "../../logger.js";
|
|
11
|
-
import { RsdoctorServer } from "../server/index.js";
|
|
12
|
-
import { RsdoctorFakeServer } from "../server/fakeServer.js";
|
|
13
|
-
import { SDKCore } from "./core.js";
|
|
14
|
-
import { Algorithm, Lodash, decycle } from "../../common/index.js";
|
|
15
|
-
import { findRoot } from "../utils/index.js";
|
|
16
|
-
export * from "../utils/openBrowser.js";
|
|
17
|
-
export * from "../utils/base.js";
|
|
18
|
-
const sdk_require = createRequire(import.meta.url);
|
|
19
|
-
class RsdoctorSDK extends SDKCore {
|
|
20
|
-
async bootstrap() {
|
|
21
|
-
logger.debug(`${Date.now()}`, '[RsdoctorSDK][bootstrap start]');
|
|
22
|
-
if (this.server) await this.server.bootstrap();
|
|
23
|
-
await super.bootstrap();
|
|
24
|
-
logger.debug(`${Date.now()} ${this.server.origin}`, '[RsdoctorSDK][bootstrap end]');
|
|
25
|
-
}
|
|
26
|
-
async dispose() {
|
|
27
|
-
logger.debug(`${Date.now()}`, '[RsdoctorSDK][dispose start]');
|
|
28
|
-
if (this.server) await this.server.dispose();
|
|
29
|
-
await super.dispose();
|
|
30
|
-
logger.debug(`${Date.now()}`, '[RsdoctorSDK][dispose end]');
|
|
31
|
-
}
|
|
32
|
-
async applyErrorFix(id) {
|
|
33
|
-
const { _errors: errors } = this;
|
|
34
|
-
const error = errors.find((err)=>err.id === id);
|
|
35
|
-
if (!error || !error.path || !error.fixData || error.fixData.isFixed) return;
|
|
36
|
-
const { path: filePath, fixData } = error;
|
|
37
|
-
const sameFileErrors = errors.filter((item)=>item.path === filePath && item !== error);
|
|
38
|
-
let content = (await node_fs.promises.readFile(filePath, 'utf-8')).toString();
|
|
39
|
-
const startTxt = content.substring(0, fixData.start);
|
|
40
|
-
const endTxt = content.substring(fixData.end, content.length);
|
|
41
|
-
const offset = (fixData.newText ?? '').length - (fixData.end - fixData.start);
|
|
42
|
-
content = startTxt + fixData.newText + endTxt;
|
|
43
|
-
for (const other of sameFileErrors){
|
|
44
|
-
const { fixData: otherFixData } = other;
|
|
45
|
-
if (otherFixData) {
|
|
46
|
-
if (otherFixData.start >= fixData.end) {
|
|
47
|
-
otherFixData.start += offset;
|
|
48
|
-
otherFixData.end += offset;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
await node_fs.promises.writeFile(filePath, content);
|
|
53
|
-
}
|
|
54
|
-
clear() {
|
|
55
|
-
this._errors = [];
|
|
56
|
-
this._loader = [];
|
|
57
|
-
this._resolver = [];
|
|
58
|
-
this._plugin = {};
|
|
59
|
-
this._moduleGraph = new ModuleGraph();
|
|
60
|
-
this._chunkGraph = new ChunkGraph();
|
|
61
|
-
}
|
|
62
|
-
clearSourceMapCache() {
|
|
63
|
-
this._rawSourceMapCache = new Map();
|
|
64
|
-
this._sourceMap = new Map();
|
|
65
|
-
}
|
|
66
|
-
async getSourceMap(file) {
|
|
67
|
-
const { _sourceMap: sourceMap, _rawSourceMapCache: rawMap } = this;
|
|
68
|
-
if (sourceMap.has(file)) return sourceMap.get(file);
|
|
69
|
-
const rawData = rawMap.get(file);
|
|
70
|
-
if (!rawData || rawData.version < 0 || !rawData.sourcesContent?.[0] || !rawData.mappings) return Promise.resolve(void 0);
|
|
71
|
-
try {
|
|
72
|
-
const result = await new SourceMapConsumer(rawData);
|
|
73
|
-
sourceMap.set(file, result);
|
|
74
|
-
return result;
|
|
75
|
-
} catch {
|
|
76
|
-
return Promise.resolve(void 0);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
reportSourceMap(data) {
|
|
80
|
-
this._rawSourceMapCache.set(data.file, data);
|
|
81
|
-
}
|
|
82
|
-
reportConfiguration(config) {
|
|
83
|
-
config.root ??= this.root;
|
|
84
|
-
this._configs.push(config);
|
|
85
|
-
this.onDataReport();
|
|
86
|
-
}
|
|
87
|
-
reportError(errors) {
|
|
88
|
-
errors.forEach((item)=>{
|
|
89
|
-
this._errors.push(DevToolError.from(item, {
|
|
90
|
-
code: this.name
|
|
91
|
-
}));
|
|
92
|
-
});
|
|
93
|
-
this.onDataReport();
|
|
94
|
-
}
|
|
95
|
-
reportLoader(data) {
|
|
96
|
-
data.forEach((item)=>{
|
|
97
|
-
if (this.extraConfig?.mode === SDK.IMode[SDK.IMode.brief]) item.loaders.forEach((_loader)=>{
|
|
98
|
-
_loader.input = void 0;
|
|
99
|
-
_loader.result = void 0;
|
|
100
|
-
});
|
|
101
|
-
let match = this._loader.find((e)=>e.resource.path === item.resource.path);
|
|
102
|
-
if (match) match.loaders.push(...item.loaders);
|
|
103
|
-
else {
|
|
104
|
-
match = item;
|
|
105
|
-
this._loader.push(item);
|
|
106
|
-
}
|
|
107
|
-
match.loaders.sort((a, b)=>{
|
|
108
|
-
if (a.startAt !== b.startAt) return a.startAt - b.startAt;
|
|
109
|
-
if (a.isPitch) {
|
|
110
|
-
if (b.isPitch) return a.loaderIndex - b.loaderIndex;
|
|
111
|
-
return -1;
|
|
112
|
-
}
|
|
113
|
-
if (b.isPitch) return 1;
|
|
114
|
-
return b.loaderIndex - a.loaderIndex;
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
this.onDataReport();
|
|
118
|
-
}
|
|
119
|
-
reportLoaderStartOrEnd(data) {
|
|
120
|
-
const _builtinLoader = data.loaders[0];
|
|
121
|
-
if (_builtinLoader.startAt) this._loaderStart.push(data);
|
|
122
|
-
else if (_builtinLoader.endAt) {
|
|
123
|
-
const matchLoaderStart = this._loaderStart.find((e)=>e.resource.path === data.resource.path && e.loaders[0].loader === _builtinLoader.loader);
|
|
124
|
-
if (matchLoaderStart) {
|
|
125
|
-
matchLoaderStart.loaders[0].result = _builtinLoader.result;
|
|
126
|
-
matchLoaderStart.loaders[0].endAt = _builtinLoader.endAt;
|
|
127
|
-
this.reportLoader([
|
|
128
|
-
matchLoaderStart
|
|
129
|
-
]);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
reportResolver(data) {
|
|
134
|
-
data.forEach((item)=>this._resolver.push(item));
|
|
135
|
-
this.onDataReport();
|
|
136
|
-
}
|
|
137
|
-
reportPlugin(data) {
|
|
138
|
-
Object.keys(data).forEach((hook)=>{
|
|
139
|
-
if (this._plugin[hook]) data[hook].forEach((item)=>{
|
|
140
|
-
this._plugin[hook].push(item || void 0);
|
|
141
|
-
});
|
|
142
|
-
else this._plugin[hook] = data[hook];
|
|
143
|
-
});
|
|
144
|
-
this.onDataReport();
|
|
145
|
-
}
|
|
146
|
-
reportModuleGraph(data) {
|
|
147
|
-
logger.debug(`data size: ${data.size()}`, '[SDK.reportModuleGraph][start]');
|
|
148
|
-
this._moduleGraph.fromInstance(data);
|
|
149
|
-
this.createPackageGraph();
|
|
150
|
-
this.onDataReport();
|
|
151
|
-
logger.debug(`sdk._moduleGraph size: ${this._moduleGraph.size()}`, '[SDK reportModuleGraph][end]');
|
|
152
|
-
}
|
|
153
|
-
reportPackageGraph(data) {
|
|
154
|
-
logger.debug('[SDK.reportPackageGraph][start]');
|
|
155
|
-
if (!this._packageGraph) this._packageGraph = data;
|
|
156
|
-
this.onDataReport();
|
|
157
|
-
logger.debug(`sdk._packageGraph size: ${this._packageGraph.getPackages().length}`, '[SDK reportPackageGraph][end]');
|
|
158
|
-
}
|
|
159
|
-
reportChunkGraph(data) {
|
|
160
|
-
this._chunkGraph.addAsset(...data.getAssets());
|
|
161
|
-
this._chunkGraph.addChunk(...data.getChunks());
|
|
162
|
-
this._chunkGraph.addEntryPoint(...data.getEntryPoints());
|
|
163
|
-
this.onDataReport();
|
|
164
|
-
}
|
|
165
|
-
reportSummaryData(part) {
|
|
166
|
-
const keys = [
|
|
167
|
-
'costs'
|
|
168
|
-
];
|
|
169
|
-
for (const key of keys){
|
|
170
|
-
const v = part[key];
|
|
171
|
-
if (v) if ('object' == typeof v) if (Array.isArray(v)) this._summary[key] = [
|
|
172
|
-
...this._summary[key] || [],
|
|
173
|
-
...v
|
|
174
|
-
];
|
|
175
|
-
else this._summary[key] = {
|
|
176
|
-
...this._summary[key] || {},
|
|
177
|
-
...v
|
|
178
|
-
};
|
|
179
|
-
else this._summary[key] = v;
|
|
180
|
-
}
|
|
181
|
-
this.onDataReport();
|
|
182
|
-
}
|
|
183
|
-
createPackageGraph() {
|
|
184
|
-
logger.debug(`sdk._moduleGraph size: ${this._moduleGraph.size()}`, '[SDK.createPackageGraph][start]');
|
|
185
|
-
if (!this._packageGraph) {
|
|
186
|
-
const pkgGraph = PackageGraph.fromModuleGraph(this._moduleGraph, this.root, (path)=>{
|
|
187
|
-
try {
|
|
188
|
-
const exists = node_fs.existsSync(path);
|
|
189
|
-
if (exists) {
|
|
190
|
-
const res = fs_extra.readJsonSync(path);
|
|
191
|
-
return res;
|
|
192
|
-
}
|
|
193
|
-
} catch (error) {
|
|
194
|
-
const { message, stack } = error;
|
|
195
|
-
logger.debug(()=>`sdk.createPackageGraph error, path: ${path}, error message: ${stack || message}`, '[SDK.createPackageGraph][error]');
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
this._packageGraph = pkgGraph;
|
|
199
|
-
logger.debug(`sdk._packageGraph packages: ${this._packageGraph.getPackages().length}`, '[SDK.createPackageGraph][end]');
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async writeStore(options) {
|
|
203
|
-
logger.debug("sdk.writeStore has run.", '[SDK.writeStore][end]');
|
|
204
|
-
let htmlPath = '';
|
|
205
|
-
if (this.extraConfig?.mode === SDK.IMode[SDK.IMode.brief]) {
|
|
206
|
-
const clientHtmlPath = this.extraConfig.innerClientPath ? this.extraConfig.innerClientPath : sdk_require.resolve('@rsdoctor/client');
|
|
207
|
-
if (this.extraConfig?.brief?.type?.includes('json')) {
|
|
208
|
-
const data = this.getStoreData();
|
|
209
|
-
const clientRoutes = this.getClientRoutes();
|
|
210
|
-
const jsonData = {
|
|
211
|
-
data,
|
|
212
|
-
clientRoutes
|
|
213
|
-
};
|
|
214
|
-
node_fs.mkdirSync(this.outputDir, {
|
|
215
|
-
recursive: true
|
|
216
|
-
});
|
|
217
|
-
node_fs.writeFileSync(path_0.resolve(this.outputDir, this.extraConfig.brief.jsonOptions?.fileName ?? 'rsdoctor-data.json'), JSON.stringify(jsonData));
|
|
218
|
-
}
|
|
219
|
-
if (this.extraConfig.brief?.type?.includes('html')) htmlPath = this.inlineScriptsAndStyles(clientHtmlPath);
|
|
220
|
-
return htmlPath;
|
|
221
|
-
}
|
|
222
|
-
return this.saveManifest(this.getStoreData(), options || {});
|
|
223
|
-
}
|
|
224
|
-
getStoreData() {
|
|
225
|
-
const ctx = this;
|
|
226
|
-
const briefOptions = this.extraConfig?.brief;
|
|
227
|
-
const sections = briefOptions?.jsonOptions?.sections;
|
|
228
|
-
const isJsonType = briefOptions?.type?.includes('json');
|
|
229
|
-
return {
|
|
230
|
-
get hash () {
|
|
231
|
-
return ctx.hash;
|
|
232
|
-
},
|
|
233
|
-
get root () {
|
|
234
|
-
return ctx.root;
|
|
235
|
-
},
|
|
236
|
-
get envinfo () {
|
|
237
|
-
return ctx._envinfo;
|
|
238
|
-
},
|
|
239
|
-
get pid () {
|
|
240
|
-
return ctx.pid;
|
|
241
|
-
},
|
|
242
|
-
get errors () {
|
|
243
|
-
if (isJsonType && sections && !sections.rules) return [];
|
|
244
|
-
return ctx._errors.map((err)=>err.toData());
|
|
245
|
-
},
|
|
246
|
-
get configs () {
|
|
247
|
-
return ctx._configs.slice();
|
|
248
|
-
},
|
|
249
|
-
get summary () {
|
|
250
|
-
return {
|
|
251
|
-
...ctx._summary
|
|
252
|
-
};
|
|
253
|
-
},
|
|
254
|
-
get resolver () {
|
|
255
|
-
return ctx._resolver.slice();
|
|
256
|
-
},
|
|
257
|
-
get loader () {
|
|
258
|
-
return ctx._loader.slice();
|
|
259
|
-
},
|
|
260
|
-
get moduleGraph () {
|
|
261
|
-
if (isJsonType && sections && !sections.moduleGraph) return {
|
|
262
|
-
dependencies: [],
|
|
263
|
-
modules: [],
|
|
264
|
-
moduleGraphModules: [],
|
|
265
|
-
exports: [],
|
|
266
|
-
sideEffects: [],
|
|
267
|
-
variables: [],
|
|
268
|
-
layers: []
|
|
269
|
-
};
|
|
270
|
-
return ctx._moduleGraph.toData({
|
|
271
|
-
contextPath: ctx._configs?.[0]?.config?.context || '',
|
|
272
|
-
briefOptions
|
|
273
|
-
});
|
|
274
|
-
},
|
|
275
|
-
get chunkGraph () {
|
|
276
|
-
if (isJsonType && sections && !sections.chunkGraph) return {
|
|
277
|
-
assets: [],
|
|
278
|
-
chunks: [],
|
|
279
|
-
entrypoints: []
|
|
280
|
-
};
|
|
281
|
-
return ctx._chunkGraph.toData(ctx.type);
|
|
282
|
-
},
|
|
283
|
-
get moduleCodeMap () {
|
|
284
|
-
if (ctx.extraConfig?.mode === SDK.IMode[SDK.IMode.brief]) return {};
|
|
285
|
-
return ctx._moduleGraph.toCodeData(ctx.type);
|
|
286
|
-
},
|
|
287
|
-
get plugin () {
|
|
288
|
-
return {
|
|
289
|
-
...ctx._plugin
|
|
290
|
-
};
|
|
291
|
-
},
|
|
292
|
-
get packageGraph () {
|
|
293
|
-
return ctx._packageGraph ? ctx._packageGraph.toData() : {
|
|
294
|
-
packages: [],
|
|
295
|
-
dependencies: []
|
|
296
|
-
};
|
|
297
|
-
},
|
|
298
|
-
get treeShaking () {
|
|
299
|
-
if (ctx.extraConfig?.mode === SDK.IMode[SDK.IMode.brief]) return;
|
|
300
|
-
if (!ctx.extraConfig?.features?.treeShaking) return;
|
|
301
|
-
return ctx._moduleGraph.toTreeShakingData();
|
|
302
|
-
},
|
|
303
|
-
get otherReports () {
|
|
304
|
-
return {
|
|
305
|
-
treemapReportHtml: ''
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
getManifestData() {
|
|
311
|
-
const dataValue = this.getStoreData();
|
|
312
|
-
const data = {
|
|
313
|
-
client: {
|
|
314
|
-
enableRoutes: this.getClientRoutes()
|
|
315
|
-
},
|
|
316
|
-
data: Object.keys(dataValue).reduce((t, e)=>{
|
|
317
|
-
const _e = e;
|
|
318
|
-
if (dataValue[_e] && 'object' == typeof dataValue[_e]) t[e] = [
|
|
319
|
-
`${this.server.origin}${SDK.ServerAPI.API.LoadDataByKey}/${e}`
|
|
320
|
-
];
|
|
321
|
-
else t[e] = dataValue[_e];
|
|
322
|
-
return t;
|
|
323
|
-
}, {}),
|
|
324
|
-
__LOCAL__SERVER__: true,
|
|
325
|
-
__SOCKET__PORT__: this.server.socketUrl.port.toString(),
|
|
326
|
-
__SOCKET__URL__: this.server.socketUrl.socketUrl
|
|
327
|
-
};
|
|
328
|
-
return data;
|
|
329
|
-
}
|
|
330
|
-
getRuleContext(_options) {
|
|
331
|
-
this.createPackageGraph();
|
|
332
|
-
return {
|
|
333
|
-
root: this.root,
|
|
334
|
-
errors: this._errors.slice(),
|
|
335
|
-
configs: this._configs.slice(),
|
|
336
|
-
moduleGraph: this._moduleGraph,
|
|
337
|
-
chunkGraph: this._chunkGraph,
|
|
338
|
-
packageGraph: this._packageGraph,
|
|
339
|
-
loader: this._loader.slice(),
|
|
340
|
-
otherReports: {
|
|
341
|
-
treemapReportHtml: ''
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
onDataReport() {
|
|
346
|
-
this.server.broadcast();
|
|
347
|
-
}
|
|
348
|
-
addRsdoctorDataToHTML(storeData, htmlContent) {
|
|
349
|
-
let compressTextScripts = `<script>window.${Constants.WINDOW_RSDOCTOR_TAG}={}</script>`;
|
|
350
|
-
for (const key of Object.keys(storeData)){
|
|
351
|
-
const data = storeData[key];
|
|
352
|
-
const jsonStrFn = ()=>{
|
|
353
|
-
try {
|
|
354
|
-
if ('configs' === key) return JSON.stringify(decycle(data));
|
|
355
|
-
return JSON.stringify(data);
|
|
356
|
-
} catch (error) {
|
|
357
|
-
console.error(error);
|
|
358
|
-
return '';
|
|
359
|
-
}
|
|
360
|
-
};
|
|
361
|
-
const compressText = Algorithm.compressText(jsonStrFn());
|
|
362
|
-
compressTextScripts = `${compressTextScripts} <script>window.${Constants.WINDOW_RSDOCTOR_TAG}.${key}=${JSON.stringify(compressText)}</script>`;
|
|
363
|
-
}
|
|
364
|
-
compressTextScripts = `${compressTextScripts} <script>window.${Constants.WINDOW_RSDOCTOR_TAG}.enableRoutes=${JSON.stringify(this.getClientRoutes())}</script>`;
|
|
365
|
-
htmlContent = htmlContent.replace('<body>', `<body>${compressTextScripts}`);
|
|
366
|
-
return htmlContent;
|
|
367
|
-
}
|
|
368
|
-
inlineScriptsAndStyles(htmlFilePath) {
|
|
369
|
-
function inlineScripts(basePath, scripts) {
|
|
370
|
-
return scripts.map((src)=>{
|
|
371
|
-
const scriptPath = resolveFilePath(basePath, src);
|
|
372
|
-
try {
|
|
373
|
-
const scriptContent = node_fs.readFileSync(scriptPath, 'utf-8');
|
|
374
|
-
return `<script>${scriptContent}</script>`;
|
|
375
|
-
} catch (error) {
|
|
376
|
-
console.error(`Could not read script at ${scriptPath}:`, error);
|
|
377
|
-
return '';
|
|
378
|
-
}
|
|
379
|
-
}).join('');
|
|
380
|
-
}
|
|
381
|
-
function resolveFilePath(basePath, filePath) {
|
|
382
|
-
if (filePath.startsWith('/')) return path_0.resolve(basePath, filePath.slice(1));
|
|
383
|
-
return path_0.resolve(basePath, filePath);
|
|
384
|
-
}
|
|
385
|
-
function inlineCss(basePath, cssFiles) {
|
|
386
|
-
return cssFiles.map((href)=>{
|
|
387
|
-
const cssPath = resolveFilePath(basePath, href);
|
|
388
|
-
try {
|
|
389
|
-
const cssContent = node_fs.readFileSync(cssPath, 'utf-8');
|
|
390
|
-
return `<style>${cssContent}</style>`;
|
|
391
|
-
} catch (error) {
|
|
392
|
-
console.error(`Could not read CSS at ${cssPath}:`, error);
|
|
393
|
-
return '';
|
|
394
|
-
}
|
|
395
|
-
}).join('');
|
|
396
|
-
}
|
|
397
|
-
let htmlContent = node_fs.readFileSync(htmlFilePath, 'utf-8');
|
|
398
|
-
const basePath = path_0.dirname(htmlFilePath);
|
|
399
|
-
const scriptSrcs = Array.from(htmlContent.matchAll(/<script\s+(?:defer="defer"|defer)\s+src=["'](.+?)["']><\/script>/g), (m)=>m[1]);
|
|
400
|
-
const cssHrefs = Array.from(htmlContent.matchAll(/<link\s+href=["'](.+?)["']\s+rel="stylesheet">/g), (m)=>m[1]);
|
|
401
|
-
htmlContent = htmlContent.replace(/<script\s+.*?src=["'].*?["']><\/script>/g, '');
|
|
402
|
-
htmlContent = htmlContent.replace(/<link\s+.*?rel=["']stylesheet["'].*?>/g, '');
|
|
403
|
-
const inlinedScripts = inlineScripts(basePath, scriptSrcs);
|
|
404
|
-
const inlinedCss = inlineCss(basePath, cssHrefs);
|
|
405
|
-
const index = htmlContent.indexOf('</body>');
|
|
406
|
-
htmlContent = htmlContent.slice(0, index) + inlinedCss + inlinedScripts + htmlContent.slice(index);
|
|
407
|
-
htmlContent = this.addRsdoctorDataToHTML(this.getStoreData(), htmlContent);
|
|
408
|
-
const outputFilePath = path_0.resolve(this.outputDir, this.extraConfig?.brief?.htmlOptions?.reportHtmlName || 'rsdoctor-report.html');
|
|
409
|
-
node_fs.mkdirSync(path_0.dirname(outputFilePath), {
|
|
410
|
-
recursive: true
|
|
411
|
-
});
|
|
412
|
-
node_fs.writeFileSync(outputFilePath, htmlContent, {
|
|
413
|
-
encoding: 'utf-8',
|
|
414
|
-
flag: 'w'
|
|
415
|
-
});
|
|
416
|
-
return outputFilePath;
|
|
417
|
-
}
|
|
418
|
-
constructor(options){
|
|
419
|
-
super(options), this._summary = {
|
|
420
|
-
costs: []
|
|
421
|
-
}, this._configs = [], this._errors = [], this._loader = [], this._loaderStart = [], this._resolver = [], this._plugin = {}, this._moduleGraph = new ModuleGraph(), this._chunkGraph = new ChunkGraph(), this._rawSourceMapCache = new Map(), this._sourceMap = new Map();
|
|
422
|
-
const serverConfig = options.config?.server;
|
|
423
|
-
const port = serverConfig?.port ?? options.port;
|
|
424
|
-
this.server = options.config?.noServer ? new RsdoctorFakeServer(this, port) : new RsdoctorServer(this, port, {
|
|
425
|
-
innerClientPath: options.config?.innerClientPath || '',
|
|
426
|
-
printServerUrl: options.config?.printLog?.serverUrls,
|
|
427
|
-
cors: serverConfig?.cors
|
|
428
|
-
});
|
|
429
|
-
this.type = Lodash.isNumber(options.type) ? options.type : SDK.ToDataType.Normal;
|
|
430
|
-
this.extraConfig = options.config;
|
|
431
|
-
this.root = findRoot() ?? '';
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
export { resolveClientDiffHtmlPath } from "../server/client.js";
|
|
435
|
-
export { RsdoctorSDK };
|
package/dist/sdk/sdk/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { SDK } from "@rsdoctor/shared/types";
|
|
3
|
-
import { BaseAPI } from "./base.js";
|
|
4
|
-
import { Router } from "../router.js";
|
|
5
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
6
|
-
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
-
}
|
|
11
|
-
function _ts_metadata(k, v) {
|
|
12
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
13
|
-
}
|
|
14
|
-
class AlertsAPI extends BaseAPI {
|
|
15
|
-
async getPackageRelationAlertDetails() {
|
|
16
|
-
const { req } = this.ctx;
|
|
17
|
-
const { id, target } = req.body;
|
|
18
|
-
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetPackageRelationAlertDetails, {
|
|
19
|
-
id,
|
|
20
|
-
target
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
_ts_decorate([
|
|
25
|
-
Router.post(SDK.ServerAPI.API.GetPackageRelationAlertDetails),
|
|
26
|
-
_ts_metadata("design:type", Function),
|
|
27
|
-
_ts_metadata("design:paramtypes", []),
|
|
28
|
-
_ts_metadata("design:returntype", Promise)
|
|
29
|
-
], AlertsAPI.prototype, "getPackageRelationAlertDetails", null);
|
|
30
|
-
export { AlertsAPI };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { Data } from "../../../common/index.js";
|
|
3
|
-
class BaseAPI {
|
|
4
|
-
async loadManifest() {
|
|
5
|
-
return this.ctx.sdk.getManifestData();
|
|
6
|
-
}
|
|
7
|
-
async loadData(key) {
|
|
8
|
-
const data = this.ctx.sdk.getStoreData();
|
|
9
|
-
const sep = '.';
|
|
10
|
-
let res = data[key];
|
|
11
|
-
if (key.includes(sep)) res = key.split(sep).reduce((t, k)=>t[k], data);
|
|
12
|
-
return res;
|
|
13
|
-
}
|
|
14
|
-
constructor(sdk, server){
|
|
15
|
-
this.ctx = {
|
|
16
|
-
sdk,
|
|
17
|
-
server
|
|
18
|
-
};
|
|
19
|
-
this.dataLoader = new Data.APIDataLoader(this);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export { BaseAPI };
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { SDK } from "@rsdoctor/shared/types";
|
|
3
|
-
import { BaseAPI } from "./base.js";
|
|
4
|
-
import { Router } from "../router.js";
|
|
5
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
6
|
-
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
-
}
|
|
11
|
-
function _ts_metadata(k, v) {
|
|
12
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
13
|
-
}
|
|
14
|
-
class BundleDiffAPI extends BaseAPI {
|
|
15
|
-
async getBundleDiffSummary() {
|
|
16
|
-
const { sdk } = this.ctx;
|
|
17
|
-
const { root, hash, errors, chunkGraph, moduleGraph, packageGraph, configs, moduleCodeMap, cloudManifestUrl } = sdk.getStoreData();
|
|
18
|
-
let outputFilename = '';
|
|
19
|
-
if ('string' == typeof configs?.[0]?.config?.output?.filename) outputFilename = configs?.[0]?.config?.output?.filename;
|
|
20
|
-
return {
|
|
21
|
-
root,
|
|
22
|
-
hash,
|
|
23
|
-
errors,
|
|
24
|
-
chunkGraph,
|
|
25
|
-
moduleGraph,
|
|
26
|
-
packageGraph,
|
|
27
|
-
outputFilename,
|
|
28
|
-
moduleCodeMap,
|
|
29
|
-
cloudManifestUrl
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
async bundleDiffManifest() {
|
|
33
|
-
const { sdk } = this.ctx;
|
|
34
|
-
const data = sdk.getStoreData();
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
_ts_decorate([
|
|
39
|
-
Router.get(SDK.ServerAPI.API.GetBundleDiffSummary),
|
|
40
|
-
Router.post(SDK.ServerAPI.API.GetBundleDiffSummary),
|
|
41
|
-
_ts_metadata("design:type", Function),
|
|
42
|
-
_ts_metadata("design:paramtypes", []),
|
|
43
|
-
_ts_metadata("design:returntype", Promise)
|
|
44
|
-
], BundleDiffAPI.prototype, "getBundleDiffSummary", null);
|
|
45
|
-
_ts_decorate([
|
|
46
|
-
Router.get(SDK.ServerAPI.API.BundleDiffManifest),
|
|
47
|
-
_ts_metadata("design:type", Function),
|
|
48
|
-
_ts_metadata("design:paramtypes", []),
|
|
49
|
-
_ts_metadata("design:returntype", Promise)
|
|
50
|
-
], BundleDiffAPI.prototype, "bundleDiffManifest", null);
|
|
51
|
-
export { BundleDiffAPI };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { SDK } from "@rsdoctor/shared/types";
|
|
3
|
-
import { BaseAPI } from "./base.js";
|
|
4
|
-
import { Router } from "../router.js";
|
|
5
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
6
|
-
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
-
}
|
|
11
|
-
function _ts_metadata(k, v) {
|
|
12
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
13
|
-
}
|
|
14
|
-
class DataAPI extends BaseAPI {
|
|
15
|
-
async loadDataByKey() {
|
|
16
|
-
const { req } = this.ctx;
|
|
17
|
-
const { url } = req;
|
|
18
|
-
let { key } = req.body;
|
|
19
|
-
if (!key && url) {
|
|
20
|
-
const uri = new URL(url, 'http://127.0.0.1');
|
|
21
|
-
key = uri.pathname.replace(/^\//, '');
|
|
22
|
-
}
|
|
23
|
-
const data = await this.loadData(key);
|
|
24
|
-
return data;
|
|
25
|
-
}
|
|
26
|
-
async sendMessageToClient() {
|
|
27
|
-
const { req, server } = this.ctx;
|
|
28
|
-
const { api, data } = req.body;
|
|
29
|
-
await server.sendAPIDataToClient(api, data);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
_ts_decorate([
|
|
33
|
-
Router.post(SDK.ServerAPI.API.LoadDataByKey),
|
|
34
|
-
_ts_metadata("design:type", Function),
|
|
35
|
-
_ts_metadata("design:paramtypes", []),
|
|
36
|
-
_ts_metadata("design:returntype", Promise)
|
|
37
|
-
], DataAPI.prototype, "loadDataByKey", null);
|
|
38
|
-
_ts_decorate([
|
|
39
|
-
Router.post(SDK.ServerAPI.API.SendAPIDataToClient),
|
|
40
|
-
_ts_metadata("design:type", Function),
|
|
41
|
-
_ts_metadata("design:paramtypes", []),
|
|
42
|
-
_ts_metadata("design:returntype", Promise)
|
|
43
|
-
], DataAPI.prototype, "sendMessageToClient", null);
|
|
44
|
-
export { DataAPI };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { SDK } from "@rsdoctor/shared/types";
|
|
3
|
-
import { BaseAPI } from "./base.js";
|
|
4
|
-
import { Router } from "../router.js";
|
|
5
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
6
|
-
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
-
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
-
}
|
|
11
|
-
function _ts_metadata(k, v) {
|
|
12
|
-
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
13
|
-
}
|
|
14
|
-
class FileSystemAPI extends BaseAPI {
|
|
15
|
-
async applyErrorFix() {
|
|
16
|
-
const { body } = this.ctx.req;
|
|
17
|
-
const data = body;
|
|
18
|
-
await this.ctx.sdk.applyErrorFix(data.id);
|
|
19
|
-
return 'success';
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
_ts_decorate([
|
|
23
|
-
Router.post(SDK.ServerAPI.API.ApplyErrorFix),
|
|
24
|
-
_ts_metadata("design:type", Function),
|
|
25
|
-
_ts_metadata("design:paramtypes", []),
|
|
26
|
-
_ts_metadata("design:returntype", Promise)
|
|
27
|
-
], FileSystemAPI.prototype, "applyErrorFix", null);
|
|
28
|
-
export { FileSystemAPI };
|