@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/index.js
CHANGED
|
@@ -1,7 +1,1725 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
let globalController;
|
|
2
|
+
import { createRequire as external_node_module_createRequire } from "node:module";
|
|
3
|
+
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
4
|
+
import node_fs, { existsSync } from "node:fs";
|
|
5
|
+
import fs_extra from "fs-extra";
|
|
6
|
+
import path_0 from "path";
|
|
7
|
+
import { createRequire } from "module";
|
|
8
|
+
import { Client, Constants, Manifest, SDK } from "@rsdoctor/shared/types";
|
|
9
|
+
import { SourceMapConsumer } from "source-map";
|
|
10
|
+
import { ChunkGraph, ModuleGraph, PackageGraph } from "@rsdoctor/shared/graph";
|
|
11
|
+
import sirv from "sirv";
|
|
12
|
+
import { Algorithm, Bundle, Data, Loader, Lodash, decycle } from "@rsdoctor/shared/common-browser";
|
|
13
|
+
import fs from "fs";
|
|
14
|
+
import os_0 from "os";
|
|
15
|
+
import assert from "assert";
|
|
16
|
+
import cors from "cors";
|
|
17
|
+
import { PassThrough } from "stream";
|
|
18
|
+
import ws, { WebSocketServer } from "ws";
|
|
19
|
+
import { isIP } from "node:net";
|
|
20
|
+
import { createHash, randomUUID, timingSafeEqual } from "node:crypto";
|
|
21
|
+
import { exec } from "node:child_process";
|
|
22
|
+
import node_path, { join, dirname as __rspack_dirname } from "node:path";
|
|
23
|
+
import { promisify } from "node:util";
|
|
24
|
+
import { randomBytes } from "crypto";
|
|
25
|
+
import raw_body from "raw-body";
|
|
26
|
+
import { createBrotliDecompress, createGunzip, createInflate } from "node:zlib";
|
|
27
|
+
import node_process from "node:process";
|
|
28
|
+
import { AsyncSeriesHook } from "@rspack/lite-tapable";
|
|
29
|
+
import { setSDK, logger as rsdoctorLogger, logger_time, timeEnd, color, stringify } from "./630.js";
|
|
30
|
+
import { InternalResolverPlugin, getYarnVersion, InternalPluginsPlugin, normalizeUserConfig, getRspackNativePlugin, InternalSummaryPlugin, InternalBundlePlugin, getNpmVersion, ensureModulesChunksGraphFn, getNodeVersion, fs_extra as external_fs_extra_fs_extra, handleBriefModeReport, processCompilerConfig, InternalLoaderPlugin, getCPUInfo, defaultPort, getPnpmVersion, FileSharding, createServer, getMemoryInfo, normalizeRspackUserOptions, defaultHost, InternalErrorReporterPlugin, getPortSync, InternalRulesPlugin, DevToolError, ProbeLoaderPlugin } from "./26.js";
|
|
31
|
+
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
32
|
+
var date, __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url)), apis_namespaceObject = {};
|
|
33
|
+
__webpack_require__.r(apis_namespaceObject), __webpack_require__.d(apis_namespaceObject, {
|
|
34
|
+
AlertsAPI: ()=>AlertsAPI,
|
|
35
|
+
BundleDiffAPI: ()=>BundleDiffAPI,
|
|
36
|
+
DataAPI: ()=>DataAPI,
|
|
37
|
+
FileSystemAPI: ()=>FileSystemAPI,
|
|
38
|
+
GraphAPI: ()=>GraphAPI,
|
|
39
|
+
LoaderAPI: ()=>LoaderAPI,
|
|
40
|
+
PluginAPI: ()=>PluginAPI,
|
|
41
|
+
ProjectAPI: ()=>ProjectAPI,
|
|
42
|
+
RendererAPI: ()=>RendererAPI,
|
|
43
|
+
ResolverAPI: ()=>ResolverAPI
|
|
44
|
+
});
|
|
45
|
+
class SocketAPILoader {
|
|
46
|
+
constructor(options){
|
|
47
|
+
this.options = options, this.dataLoader = new Data.APIDataLoader(this);
|
|
48
|
+
}
|
|
49
|
+
async loadManifest() {
|
|
50
|
+
return this.options.sdk.getManifestData();
|
|
51
|
+
}
|
|
52
|
+
async loadData(key) {
|
|
53
|
+
let data = this.options.sdk.getStoreData(), res = data[key];
|
|
54
|
+
return key.includes('.') && (res = key.split('.').reduce((t, k)=>t[k], data)), res;
|
|
55
|
+
}
|
|
56
|
+
get loadAPIData() {
|
|
57
|
+
return this.dataLoader.loadAPI;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
let DEFAULT_ALLOWED_CORS_ORIGINS = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/, LOCAL_HOSTNAMES = /^(?:localhost|[^:]+\.localhost)$/;
|
|
61
|
+
function getHostnameFromHost(host) {
|
|
62
|
+
if (host.startsWith('[')) {
|
|
63
|
+
let endIndex = host.indexOf(']');
|
|
64
|
+
return -1 === endIndex ? '' : host.slice(1, endIndex);
|
|
65
|
+
}
|
|
66
|
+
return host.split(':')[0];
|
|
67
|
+
}
|
|
68
|
+
function isAllowedRequestHost(host) {
|
|
69
|
+
if ('string' != typeof host) return !1;
|
|
70
|
+
let hostname = getHostnameFromHost(host).toLowerCase();
|
|
71
|
+
return LOCAL_HOSTNAMES.test(hostname) || 0 !== isIP(hostname);
|
|
72
|
+
}
|
|
73
|
+
class Socket {
|
|
74
|
+
constructor(options){
|
|
75
|
+
this.options = options, this.clients = new Set(), this.map = new Map(), this.clientSubscriptions = new Map(), this.loader = new SocketAPILoader({
|
|
76
|
+
sdk: options.sdk
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
bootstrap() {
|
|
80
|
+
this.server = new WebSocketServer({
|
|
81
|
+
server: this.options.server,
|
|
82
|
+
verifyClient: ({ req })=>{
|
|
83
|
+
var url, token;
|
|
84
|
+
return isAllowedRequestHost(req.headers.host || req.headers[':authority']) && (url = req.url, token = this.options.token, !!url && new URL(url, 'http://localhost').searchParams.get('token') === token);
|
|
85
|
+
}
|
|
86
|
+
}), this.server.on('connection', (client)=>{
|
|
87
|
+
this.attachClient(client);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
attachClient(client) {
|
|
91
|
+
this.clients.add(client), 'function' == typeof client.on && (client.on('message', (message)=>{
|
|
92
|
+
this.handleClientMessage(message.toString(), client);
|
|
93
|
+
}), client.on('close', ()=>{
|
|
94
|
+
this.clients.delete(client), this.removeClientSubscriptions(client);
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
async handleClientMessage(raw, client) {
|
|
98
|
+
let message;
|
|
99
|
+
try {
|
|
100
|
+
message = JSON.parse(raw);
|
|
101
|
+
} catch {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (message.api && Object.values(SDK.ServerAPI.API).includes(message.api)) {
|
|
105
|
+
if ('request' === message.type) return void await this.handleAPIRequestMessage(message, client);
|
|
106
|
+
if ('subscribe' === message.type) return void this.saveRequestToMap(message.api, message.body ?? null, client);
|
|
107
|
+
'unsubscribe' === message.type && this.removeRequestFromMap(message.api, message.body ?? null, client);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async handleAPIRequestMessage(message, client) {
|
|
111
|
+
if (message.id && client && client.readyState === ws.OPEN) try {
|
|
112
|
+
let response = await this.getAPIResponse(message.api, message.body);
|
|
113
|
+
client.send(JSON.stringify({
|
|
114
|
+
type: 'response',
|
|
115
|
+
id: message.id,
|
|
116
|
+
payload: response.res
|
|
117
|
+
}));
|
|
118
|
+
} catch (err) {
|
|
119
|
+
client.send(JSON.stringify({
|
|
120
|
+
type: 'response',
|
|
121
|
+
id: message.id,
|
|
122
|
+
error: err instanceof Error ? err.message : String(err)
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
getSubscriptions() {
|
|
127
|
+
return [
|
|
128
|
+
...this.map.values()
|
|
129
|
+
].map(({ api, body })=>({
|
|
130
|
+
api,
|
|
131
|
+
body
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
saveRequestToMap(api, body = null, client) {
|
|
135
|
+
let key = this.getSubscriptionKey(api, body);
|
|
136
|
+
if (client) {
|
|
137
|
+
this.clientSubscriptions.has(client) || this.clientSubscriptions.set(client, new Set());
|
|
138
|
+
let subscriptions = this.clientSubscriptions.get(client);
|
|
139
|
+
if (subscriptions.has(key)) return;
|
|
140
|
+
subscriptions.add(key);
|
|
141
|
+
}
|
|
142
|
+
let record = this.map.get(key);
|
|
143
|
+
if (record) {
|
|
144
|
+
record.count += 1;
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
this.map.set(key, {
|
|
148
|
+
api,
|
|
149
|
+
body,
|
|
150
|
+
count: 1
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
removeRequestFromMap(api, body = null, client) {
|
|
154
|
+
let key = this.getSubscriptionKey(api, body);
|
|
155
|
+
if (client) {
|
|
156
|
+
let subscriptions = this.clientSubscriptions.get(client);
|
|
157
|
+
if (!subscriptions?.has(key)) return;
|
|
158
|
+
subscriptions.delete(key), 0 === subscriptions.size && this.clientSubscriptions.delete(client);
|
|
159
|
+
}
|
|
160
|
+
this.removeSubscriptionKey(key);
|
|
161
|
+
}
|
|
162
|
+
removeClientSubscriptions(client) {
|
|
163
|
+
let subscriptions = this.clientSubscriptions.get(client);
|
|
164
|
+
subscriptions && (subscriptions.forEach((key)=>this.removeSubscriptionKey(key)), this.clientSubscriptions.delete(client));
|
|
165
|
+
}
|
|
166
|
+
removeSubscriptionKey(key) {
|
|
167
|
+
let record = this.map.get(key);
|
|
168
|
+
record && (record.count -= 1, record.count <= 0 && this.map.delete(key));
|
|
169
|
+
}
|
|
170
|
+
getSubscriptionKey(api, body) {
|
|
171
|
+
return `${api}:${JSON.stringify(body ?? null)}`;
|
|
172
|
+
}
|
|
173
|
+
async getAPIResponse(api, body) {
|
|
174
|
+
let data = await this.loader.loadAPIData(api, body);
|
|
175
|
+
return {
|
|
176
|
+
req: {
|
|
177
|
+
api,
|
|
178
|
+
body
|
|
179
|
+
},
|
|
180
|
+
res: data
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
async broadcast() {
|
|
184
|
+
clearImmediate(this.timer), this.timer = setImmediate(async ()=>{
|
|
185
|
+
let promises = [];
|
|
186
|
+
this.map.forEach(({ api, body })=>{
|
|
187
|
+
promises.push((async ()=>{
|
|
188
|
+
let res = await this.getAPIResponse(api, body);
|
|
189
|
+
this.sendAPIData(api, res);
|
|
190
|
+
})());
|
|
191
|
+
}), await Promise.all(promises);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
sendAPIData(api, payload) {
|
|
195
|
+
let message = JSON.stringify({
|
|
196
|
+
api,
|
|
197
|
+
payload
|
|
198
|
+
});
|
|
199
|
+
this.clients.forEach((client)=>{
|
|
200
|
+
client.readyState === ws.OPEN && client.send(message);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
dispose() {
|
|
204
|
+
this.clients.forEach((client)=>{
|
|
205
|
+
client.close();
|
|
206
|
+
}), this.clients.clear(), this.server?.close();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
let normalizeAPIKey = (key)=>key && 'object' == typeof key && 'name' in key ? key.name : key;
|
|
210
|
+
class Router {
|
|
211
|
+
static{
|
|
212
|
+
this.routes = {
|
|
213
|
+
get: new Map(),
|
|
214
|
+
post: new Map()
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
static get(pathname) {
|
|
218
|
+
return (target, propertyKey, descriptor)=>{
|
|
219
|
+
let routes = Router.routes.get, constructor = target.constructor;
|
|
220
|
+
return routes.has(constructor) || routes.set(constructor, []), routes.get(constructor).push([
|
|
221
|
+
normalizeAPIKey(propertyKey),
|
|
222
|
+
pathname
|
|
223
|
+
]), descriptor;
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
static post(pathname) {
|
|
227
|
+
return (target, propertyKey, descriptor)=>{
|
|
228
|
+
let routes = Router.routes.post, constructor = target.constructor;
|
|
229
|
+
return routes.has(constructor) || routes.set(constructor, []), routes.get(constructor).push([
|
|
230
|
+
normalizeAPIKey(propertyKey),
|
|
231
|
+
pathname
|
|
232
|
+
]), descriptor;
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
constructor(options){
|
|
236
|
+
this.options = options;
|
|
237
|
+
}
|
|
238
|
+
async setup() {
|
|
239
|
+
let { apis, sdk, server } = this.options;
|
|
240
|
+
apis.forEach((API)=>{
|
|
241
|
+
let obj = new API(sdk, server);
|
|
242
|
+
Router.routes.get.get(API)?.forEach(([key, pathname])=>{
|
|
243
|
+
server.get(pathname, this.wrapAPIFunction(obj, key));
|
|
244
|
+
}), Router.routes.post.get(API)?.forEach(([key, pathname])=>{
|
|
245
|
+
server.post(pathname, this.wrapAPIFunction(obj, key));
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
wrapAPIFunction(api, key) {
|
|
250
|
+
let { sdk, server } = this.options;
|
|
251
|
+
return async (req, res)=>{
|
|
252
|
+
let ctx = {
|
|
253
|
+
req,
|
|
254
|
+
res,
|
|
255
|
+
sdk,
|
|
256
|
+
server
|
|
257
|
+
}, trap = new Proxy(api, {
|
|
258
|
+
get: (target, key, receiver)=>'ctx' === key ? ctx : Reflect.get(target, key, receiver),
|
|
259
|
+
set: (target, key, value, receiver)=>Reflect.set(target, key, value, receiver),
|
|
260
|
+
defineProperty: (target, p, attrs)=>Reflect.defineProperty(target, p, attrs)
|
|
261
|
+
}), fn = api[key], result = await fn.call(trap, trap);
|
|
262
|
+
return 'string' == typeof result ? Buffer.from(result, 'utf-8') : result && 'object' == typeof result ? Buffer.from(JSON.stringify(result), 'utf-8') : result;
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
class BaseAPI {
|
|
267
|
+
constructor(sdk, server){
|
|
268
|
+
this.ctx = {
|
|
269
|
+
sdk,
|
|
270
|
+
server
|
|
271
|
+
}, this.dataLoader = new Data.APIDataLoader(this);
|
|
272
|
+
}
|
|
273
|
+
async loadManifest() {
|
|
274
|
+
return this.ctx.sdk.getManifestData();
|
|
275
|
+
}
|
|
276
|
+
async loadData(key) {
|
|
277
|
+
let data = this.ctx.sdk.getStoreData(), res = data[key];
|
|
278
|
+
return key.includes('.') && (res = key.split('.').reduce((t, k)=>t[k], data)), res;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function _ts_metadata(k, v) {
|
|
282
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
283
|
+
}
|
|
284
|
+
class AlertsAPI extends BaseAPI {
|
|
285
|
+
async getPackageRelationAlertDetails() {
|
|
286
|
+
let { req } = this.ctx, { id, target } = req.body;
|
|
287
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetPackageRelationAlertDetails, {
|
|
288
|
+
id,
|
|
289
|
+
target
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function bundle_diff_ts_decorate(decorators, target, key, desc) {
|
|
294
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
295
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
296
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
297
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
298
|
+
}
|
|
299
|
+
function bundle_diff_ts_metadata(k, v) {
|
|
300
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
301
|
+
}
|
|
302
|
+
!function(decorators, target, key, desc) {
|
|
303
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
304
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
305
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
306
|
+
c > 3 && r && Object.defineProperty(target, key, r);
|
|
307
|
+
}([
|
|
308
|
+
Router.post(SDK.ServerAPI.API.GetPackageRelationAlertDetails),
|
|
309
|
+
_ts_metadata("design:type", Function),
|
|
310
|
+
_ts_metadata("design:paramtypes", []),
|
|
311
|
+
_ts_metadata("design:returntype", Promise)
|
|
312
|
+
], AlertsAPI.prototype, "getPackageRelationAlertDetails", null);
|
|
313
|
+
class BundleDiffAPI extends BaseAPI {
|
|
314
|
+
async getBundleDiffSummary() {
|
|
315
|
+
let { sdk } = this.ctx, { root, hash, errors, chunkGraph, moduleGraph, packageGraph, configs, moduleCodeMap, cloudManifestUrl } = sdk.getStoreData(), outputFilename = '';
|
|
316
|
+
return 'string' == typeof configs?.[0]?.config?.output?.filename && (outputFilename = configs?.[0]?.config?.output?.filename), {
|
|
317
|
+
root,
|
|
318
|
+
hash,
|
|
319
|
+
errors,
|
|
320
|
+
chunkGraph,
|
|
321
|
+
moduleGraph,
|
|
322
|
+
packageGraph,
|
|
323
|
+
outputFilename,
|
|
324
|
+
moduleCodeMap,
|
|
325
|
+
cloudManifestUrl
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
async bundleDiffManifest() {
|
|
329
|
+
let { sdk } = this.ctx;
|
|
330
|
+
return sdk.getStoreData();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function data_ts_decorate(decorators, target, key, desc) {
|
|
334
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
335
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
336
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
337
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
338
|
+
}
|
|
339
|
+
function data_ts_metadata(k, v) {
|
|
340
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
341
|
+
}
|
|
342
|
+
bundle_diff_ts_decorate([
|
|
343
|
+
Router.get(SDK.ServerAPI.API.GetBundleDiffSummary),
|
|
344
|
+
Router.post(SDK.ServerAPI.API.GetBundleDiffSummary),
|
|
345
|
+
bundle_diff_ts_metadata("design:type", Function),
|
|
346
|
+
bundle_diff_ts_metadata("design:paramtypes", []),
|
|
347
|
+
bundle_diff_ts_metadata("design:returntype", Promise)
|
|
348
|
+
], BundleDiffAPI.prototype, "getBundleDiffSummary", null), bundle_diff_ts_decorate([
|
|
349
|
+
Router.get(SDK.ServerAPI.API.BundleDiffManifest),
|
|
350
|
+
bundle_diff_ts_metadata("design:type", Function),
|
|
351
|
+
bundle_diff_ts_metadata("design:paramtypes", []),
|
|
352
|
+
bundle_diff_ts_metadata("design:returntype", Promise)
|
|
353
|
+
], BundleDiffAPI.prototype, "bundleDiffManifest", null);
|
|
354
|
+
class DataAPI extends BaseAPI {
|
|
355
|
+
async loadDataByKey() {
|
|
356
|
+
let { req } = this.ctx, { url } = req, { key } = req.body;
|
|
357
|
+
return !key && url && (key = new URL(url, 'http://127.0.0.1').pathname.replace(/^\//, '')), await this.loadData(key);
|
|
358
|
+
}
|
|
359
|
+
async sendMessageToClient() {
|
|
360
|
+
let { req, server } = this.ctx, { api, data } = req.body;
|
|
361
|
+
await server.sendAPIDataToClient(api, data);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function fs_ts_metadata(k, v) {
|
|
365
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
366
|
+
}
|
|
367
|
+
data_ts_decorate([
|
|
368
|
+
Router.post(SDK.ServerAPI.API.LoadDataByKey),
|
|
369
|
+
data_ts_metadata("design:type", Function),
|
|
370
|
+
data_ts_metadata("design:paramtypes", []),
|
|
371
|
+
data_ts_metadata("design:returntype", Promise)
|
|
372
|
+
], DataAPI.prototype, "loadDataByKey", null), data_ts_decorate([
|
|
373
|
+
Router.post(SDK.ServerAPI.API.SendAPIDataToClient),
|
|
374
|
+
data_ts_metadata("design:type", Function),
|
|
375
|
+
data_ts_metadata("design:paramtypes", []),
|
|
376
|
+
data_ts_metadata("design:returntype", Promise)
|
|
377
|
+
], DataAPI.prototype, "sendMessageToClient", null);
|
|
378
|
+
class FileSystemAPI extends BaseAPI {
|
|
379
|
+
async applyErrorFix() {
|
|
380
|
+
let { body } = this.ctx.req;
|
|
381
|
+
return await this.ctx.sdk.applyErrorFix(body.id), 'success';
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function loader_ts_decorate(decorators, target, key, desc) {
|
|
385
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
386
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
387
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
388
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
389
|
+
}
|
|
390
|
+
function loader_ts_metadata(k, v) {
|
|
391
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
392
|
+
}
|
|
393
|
+
!function(decorators, target, key, desc) {
|
|
394
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
395
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
396
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
397
|
+
c > 3 && r && Object.defineProperty(target, key, r);
|
|
398
|
+
}([
|
|
399
|
+
Router.post(SDK.ServerAPI.API.ApplyErrorFix),
|
|
400
|
+
fs_ts_metadata("design:type", Function),
|
|
401
|
+
fs_ts_metadata("design:paramtypes", []),
|
|
402
|
+
fs_ts_metadata("design:returntype", Promise)
|
|
403
|
+
], FileSystemAPI.prototype, "applyErrorFix", null);
|
|
404
|
+
class LoaderAPI extends BaseAPI {
|
|
405
|
+
async reportLoader() {
|
|
406
|
+
let { req, sdk } = this.ctx, { body } = req;
|
|
407
|
+
return sdk.reportLoader(body), 'ok';
|
|
408
|
+
}
|
|
409
|
+
async reportSourceMap() {
|
|
410
|
+
let { req: { body }, sdk } = this.ctx;
|
|
411
|
+
return sdk.reportSourceMap(body), 'ok';
|
|
412
|
+
}
|
|
413
|
+
async getLoaderNames() {
|
|
414
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetLoaderNames);
|
|
415
|
+
}
|
|
416
|
+
async getLoaderChartData() {
|
|
417
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetLoaderChartData);
|
|
418
|
+
}
|
|
419
|
+
async getLoaderFileTree() {
|
|
420
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetLoaderFileTree);
|
|
421
|
+
}
|
|
422
|
+
async getLoaderFileDetails() {
|
|
423
|
+
let { req } = this.ctx, { path } = req.body;
|
|
424
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetLoaderFileDetails, {
|
|
425
|
+
path
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
async getLoaderFolderStatistics() {
|
|
429
|
+
let { req } = this.ctx, { folder } = req.body;
|
|
430
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetLoaderFolderStatistics, {
|
|
431
|
+
folder
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
async getLoaderFileFirstInput() {
|
|
435
|
+
let { req } = this.ctx, { file } = req.body;
|
|
436
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetLoaderFileFirstInput, {
|
|
437
|
+
file
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
async getLoaderFileInputAndOutput() {
|
|
441
|
+
let { req } = this.ctx, { file, loader, loaderIndex } = req.body;
|
|
442
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetLoaderFileInputAndOutput, {
|
|
443
|
+
file,
|
|
444
|
+
loader,
|
|
445
|
+
loaderIndex
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function graph_ts_decorate(decorators, target, key, desc) {
|
|
450
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
451
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
452
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
453
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
454
|
+
}
|
|
455
|
+
function graph_ts_metadata(k, v) {
|
|
456
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
457
|
+
}
|
|
458
|
+
loader_ts_decorate([
|
|
459
|
+
Router.post(SDK.ServerAPI.API.ReportLoader),
|
|
460
|
+
loader_ts_metadata("design:type", Function),
|
|
461
|
+
loader_ts_metadata("design:paramtypes", []),
|
|
462
|
+
loader_ts_metadata("design:returntype", Promise)
|
|
463
|
+
], LoaderAPI.prototype, "reportLoader", null), loader_ts_decorate([
|
|
464
|
+
Router.post(SDK.ServerAPI.API.ReportSourceMap),
|
|
465
|
+
loader_ts_metadata("design:type", Function),
|
|
466
|
+
loader_ts_metadata("design:paramtypes", []),
|
|
467
|
+
loader_ts_metadata("design:returntype", Promise)
|
|
468
|
+
], LoaderAPI.prototype, "reportSourceMap", null), loader_ts_decorate([
|
|
469
|
+
Router.post(SDK.ServerAPI.API.GetLoaderNames),
|
|
470
|
+
loader_ts_metadata("design:type", Function),
|
|
471
|
+
loader_ts_metadata("design:paramtypes", []),
|
|
472
|
+
loader_ts_metadata("design:returntype", Promise)
|
|
473
|
+
], LoaderAPI.prototype, "getLoaderNames", null), loader_ts_decorate([
|
|
474
|
+
Router.post(SDK.ServerAPI.API.GetLoaderChartData),
|
|
475
|
+
loader_ts_metadata("design:type", Function),
|
|
476
|
+
loader_ts_metadata("design:paramtypes", []),
|
|
477
|
+
loader_ts_metadata("design:returntype", Promise)
|
|
478
|
+
], LoaderAPI.prototype, "getLoaderChartData", null), loader_ts_decorate([
|
|
479
|
+
Router.post(SDK.ServerAPI.API.GetLoaderFileTree),
|
|
480
|
+
loader_ts_metadata("design:type", Function),
|
|
481
|
+
loader_ts_metadata("design:paramtypes", []),
|
|
482
|
+
loader_ts_metadata("design:returntype", Promise)
|
|
483
|
+
], LoaderAPI.prototype, "getLoaderFileTree", null), loader_ts_decorate([
|
|
484
|
+
Router.post(SDK.ServerAPI.API.GetLoaderFileDetails),
|
|
485
|
+
loader_ts_metadata("design:type", Function),
|
|
486
|
+
loader_ts_metadata("design:paramtypes", []),
|
|
487
|
+
loader_ts_metadata("design:returntype", Promise)
|
|
488
|
+
], LoaderAPI.prototype, "getLoaderFileDetails", null), loader_ts_decorate([
|
|
489
|
+
Router.post(SDK.ServerAPI.API.GetLoaderFolderStatistics),
|
|
490
|
+
loader_ts_metadata("design:type", Function),
|
|
491
|
+
loader_ts_metadata("design:paramtypes", []),
|
|
492
|
+
loader_ts_metadata("design:returntype", Promise)
|
|
493
|
+
], LoaderAPI.prototype, "getLoaderFolderStatistics", null), loader_ts_decorate([
|
|
494
|
+
Router.post(SDK.ServerAPI.API.GetLoaderFileFirstInput),
|
|
495
|
+
loader_ts_metadata("design:type", Function),
|
|
496
|
+
loader_ts_metadata("design:paramtypes", []),
|
|
497
|
+
loader_ts_metadata("design:returntype", Promise)
|
|
498
|
+
], LoaderAPI.prototype, "getLoaderFileFirstInput", null), loader_ts_decorate([
|
|
499
|
+
Router.post(SDK.ServerAPI.API.GetLoaderFileInputAndOutput),
|
|
500
|
+
loader_ts_metadata("design:type", Function),
|
|
501
|
+
loader_ts_metadata("design:paramtypes", []),
|
|
502
|
+
loader_ts_metadata("design:returntype", Promise)
|
|
503
|
+
], LoaderAPI.prototype, "getLoaderFileInputAndOutput", null);
|
|
504
|
+
class GraphAPI extends BaseAPI {
|
|
505
|
+
async getAssetsSummary() {
|
|
506
|
+
let { req } = this.ctx, { withFileContent } = req.body;
|
|
507
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetAssetsSummary, {
|
|
508
|
+
withFileContent
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
async getModuleGraphForAsset() {
|
|
512
|
+
let { req } = this.ctx, { assetPath } = req.body;
|
|
513
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetAssetDetails, {
|
|
514
|
+
assetPath
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
async getChunksByModuleId() {
|
|
518
|
+
let { req } = this.ctx, { moduleId } = req.body;
|
|
519
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetChunksByModuleId, {
|
|
520
|
+
moduleId
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
async getModuleDetails() {
|
|
524
|
+
let { req } = this.ctx, { moduleId } = req.body;
|
|
525
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetModuleDetails, {
|
|
526
|
+
moduleId
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
async getDependencyByResolvedRequest() {
|
|
530
|
+
let { req } = this.ctx, { moduleIds = [] } = req.body;
|
|
531
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetModulesByModuleIds, {
|
|
532
|
+
moduleIds
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
async getModuleCodeByModuleId() {
|
|
536
|
+
let { req } = this.ctx, { moduleId } = req.body;
|
|
537
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetModuleCodeByModuleId, {
|
|
538
|
+
moduleId
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
async getModuleCodeByModuleIds() {
|
|
542
|
+
let { req } = this.ctx, { moduleIds } = req.body;
|
|
543
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetModuleCodeByModuleIds, {
|
|
544
|
+
moduleIds
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
async getEntryModulesSummary() {
|
|
548
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetEntryPoints);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
function plugin_ts_decorate(decorators, target, key, desc) {
|
|
552
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
553
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
554
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
555
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
556
|
+
}
|
|
557
|
+
function plugin_ts_metadata(k, v) {
|
|
558
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
559
|
+
}
|
|
560
|
+
graph_ts_decorate([
|
|
561
|
+
Router.post(SDK.ServerAPI.API.GetAssetsSummary),
|
|
562
|
+
graph_ts_metadata("design:type", Function),
|
|
563
|
+
graph_ts_metadata("design:paramtypes", []),
|
|
564
|
+
graph_ts_metadata("design:returntype", Promise)
|
|
565
|
+
], GraphAPI.prototype, "getAssetsSummary", null), graph_ts_decorate([
|
|
566
|
+
Router.post(SDK.ServerAPI.API.GetAssetDetails),
|
|
567
|
+
graph_ts_metadata("design:type", Function),
|
|
568
|
+
graph_ts_metadata("design:paramtypes", []),
|
|
569
|
+
graph_ts_metadata("design:returntype", Promise)
|
|
570
|
+
], GraphAPI.prototype, "getModuleGraphForAsset", null), graph_ts_decorate([
|
|
571
|
+
Router.post(SDK.ServerAPI.API.GetChunksByModuleId),
|
|
572
|
+
graph_ts_metadata("design:type", Function),
|
|
573
|
+
graph_ts_metadata("design:paramtypes", []),
|
|
574
|
+
graph_ts_metadata("design:returntype", Promise)
|
|
575
|
+
], GraphAPI.prototype, "getChunksByModuleId", null), graph_ts_decorate([
|
|
576
|
+
Router.post(SDK.ServerAPI.API.GetModuleDetails),
|
|
577
|
+
graph_ts_metadata("design:type", Function),
|
|
578
|
+
graph_ts_metadata("design:paramtypes", []),
|
|
579
|
+
graph_ts_metadata("design:returntype", Promise)
|
|
580
|
+
], GraphAPI.prototype, "getModuleDetails", null), graph_ts_decorate([
|
|
581
|
+
Router.post(SDK.ServerAPI.API.GetModulesByModuleIds),
|
|
582
|
+
graph_ts_metadata("design:type", Function),
|
|
583
|
+
graph_ts_metadata("design:paramtypes", []),
|
|
584
|
+
graph_ts_metadata("design:returntype", Promise)
|
|
585
|
+
], GraphAPI.prototype, "getDependencyByResolvedRequest", null), graph_ts_decorate([
|
|
586
|
+
Router.post(SDK.ServerAPI.API.GetModuleCodeByModuleId),
|
|
587
|
+
graph_ts_metadata("design:type", Function),
|
|
588
|
+
graph_ts_metadata("design:paramtypes", []),
|
|
589
|
+
graph_ts_metadata("design:returntype", Promise)
|
|
590
|
+
], GraphAPI.prototype, "getModuleCodeByModuleId", null), graph_ts_decorate([
|
|
591
|
+
Router.post(SDK.ServerAPI.API.GetModuleCodeByModuleIds),
|
|
592
|
+
graph_ts_metadata("design:type", Function),
|
|
593
|
+
graph_ts_metadata("design:paramtypes", []),
|
|
594
|
+
graph_ts_metadata("design:returntype", Promise)
|
|
595
|
+
], GraphAPI.prototype, "getModuleCodeByModuleIds", null), graph_ts_decorate([
|
|
596
|
+
Router.post(SDK.ServerAPI.API.GetEntryPoints),
|
|
597
|
+
graph_ts_metadata("design:type", Function),
|
|
598
|
+
graph_ts_metadata("design:paramtypes", []),
|
|
599
|
+
graph_ts_metadata("design:returntype", Promise)
|
|
600
|
+
], GraphAPI.prototype, "getEntryModulesSummary", null);
|
|
601
|
+
class PluginAPI extends BaseAPI {
|
|
602
|
+
async getPluginSummary() {
|
|
603
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetPluginSummary);
|
|
604
|
+
}
|
|
605
|
+
async getPluginData() {
|
|
606
|
+
let { req } = this.ctx, { hooks = [], tapNames = [] } = req.body;
|
|
607
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetPluginData, {
|
|
608
|
+
hooks,
|
|
609
|
+
tapNames
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
function project_ts_decorate(decorators, target, key, desc) {
|
|
614
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
615
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
616
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
617
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
618
|
+
}
|
|
619
|
+
function project_ts_metadata(k, v) {
|
|
620
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
621
|
+
}
|
|
622
|
+
plugin_ts_decorate([
|
|
623
|
+
Router.post(SDK.ServerAPI.API.GetPluginSummary),
|
|
624
|
+
plugin_ts_metadata("design:type", Function),
|
|
625
|
+
plugin_ts_metadata("design:paramtypes", []),
|
|
626
|
+
plugin_ts_metadata("design:returntype", Promise)
|
|
627
|
+
], PluginAPI.prototype, "getPluginSummary", null), plugin_ts_decorate([
|
|
628
|
+
Router.post(SDK.ServerAPI.API.GetPluginData),
|
|
629
|
+
plugin_ts_metadata("design:type", Function),
|
|
630
|
+
plugin_ts_metadata("design:paramtypes", []),
|
|
631
|
+
plugin_ts_metadata("design:returntype", Promise)
|
|
632
|
+
], PluginAPI.prototype, "getPluginData", null);
|
|
633
|
+
class ProjectAPI extends BaseAPI {
|
|
634
|
+
async env() {
|
|
635
|
+
let { server } = this.ctx;
|
|
636
|
+
return {
|
|
637
|
+
ip: function() {
|
|
638
|
+
for (let iface of Object.values(os_0.networkInterfaces()))for (let alias of iface)if ('IPv4' === alias.family && !alias.internal) return alias.address;
|
|
639
|
+
return '127.0.0.1';
|
|
640
|
+
}(),
|
|
641
|
+
port: server.port
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
async manifest() {
|
|
645
|
+
let { sdk } = this.ctx;
|
|
646
|
+
return JSON.stringify(sdk.getManifestData());
|
|
647
|
+
}
|
|
648
|
+
async getProjectInfo() {
|
|
649
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetProjectInfo);
|
|
650
|
+
}
|
|
651
|
+
async getClientRoutes() {
|
|
652
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetClientRoutes);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
function renderer_ts_metadata(k, v) {
|
|
656
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
657
|
+
}
|
|
658
|
+
project_ts_decorate([
|
|
659
|
+
Router.get(SDK.ServerAPI.API.Env),
|
|
660
|
+
project_ts_metadata("design:type", Function),
|
|
661
|
+
project_ts_metadata("design:paramtypes", []),
|
|
662
|
+
project_ts_metadata("design:returntype", Promise)
|
|
663
|
+
], ProjectAPI.prototype, "env", null), project_ts_decorate([
|
|
664
|
+
Router.get(SDK.ServerAPI.API.Manifest),
|
|
665
|
+
project_ts_metadata("design:type", Function),
|
|
666
|
+
project_ts_metadata("design:paramtypes", []),
|
|
667
|
+
project_ts_metadata("design:returntype", Promise)
|
|
668
|
+
], ProjectAPI.prototype, "manifest", null), project_ts_decorate([
|
|
669
|
+
Router.post(SDK.ServerAPI.API.GetProjectInfo),
|
|
670
|
+
project_ts_metadata("design:type", Function),
|
|
671
|
+
project_ts_metadata("design:paramtypes", []),
|
|
672
|
+
project_ts_metadata("design:returntype", Promise)
|
|
673
|
+
], ProjectAPI.prototype, "getProjectInfo", null), project_ts_decorate([
|
|
674
|
+
Router.post(SDK.ServerAPI.API.GetClientRoutes),
|
|
675
|
+
project_ts_metadata("design:type", Function),
|
|
676
|
+
project_ts_metadata("design:paramtypes", []),
|
|
677
|
+
project_ts_metadata("design:returntype", Promise)
|
|
678
|
+
], ProjectAPI.prototype, "getClientRoutes", null);
|
|
679
|
+
let renderer_require = createRequire(import.meta.url);
|
|
680
|
+
class RendererAPI extends BaseAPI {
|
|
681
|
+
async entryHtml() {
|
|
682
|
+
let { server, res } = this.ctx, clientHtmlPath = server.innerClientPath ? server.innerClientPath : renderer_require.resolve('@rsdoctor/client'), clientHtml = node_fs.readFileSync(clientHtmlPath, 'utf-8');
|
|
683
|
+
return res.setHeader('Content-Type', 'text/html'), res.setHeader('Cache-Control', 'no-store'), clientHtml;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
function resolver_ts_decorate(decorators, target, key, desc) {
|
|
687
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
688
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
689
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
690
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
691
|
+
}
|
|
692
|
+
function resolver_ts_metadata(k, v) {
|
|
693
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
|
|
694
|
+
}
|
|
695
|
+
!function(decorators, target, key, desc) {
|
|
696
|
+
var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
|
|
697
|
+
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
|
|
698
|
+
else for(var i = decorators.length - 1; i >= 0; i--)(d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
|
|
699
|
+
c > 3 && r && Object.defineProperty(target, key, r);
|
|
700
|
+
}([
|
|
701
|
+
Router.get(SDK.ServerAPI.API.EntryHtml),
|
|
702
|
+
renderer_ts_metadata("design:type", Function),
|
|
703
|
+
renderer_ts_metadata("design:paramtypes", []),
|
|
704
|
+
renderer_ts_metadata("design:returntype", Promise)
|
|
705
|
+
], RendererAPI.prototype, "entryHtml", null);
|
|
706
|
+
class ResolverAPI extends BaseAPI {
|
|
707
|
+
async getResolverFileTree() {
|
|
708
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetResolverFileTree);
|
|
709
|
+
}
|
|
710
|
+
async getResolverFileDetails() {
|
|
711
|
+
let { req } = this.ctx, { filepath } = req.body;
|
|
712
|
+
return this.dataLoader.loadAPI(SDK.ServerAPI.API.GetResolverFileDetails, {
|
|
713
|
+
filepath
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
resolver_ts_decorate([
|
|
718
|
+
Router.post(SDK.ServerAPI.API.GetResolverFileTree),
|
|
719
|
+
resolver_ts_metadata("design:type", Function),
|
|
720
|
+
resolver_ts_metadata("design:paramtypes", []),
|
|
721
|
+
resolver_ts_metadata("design:returntype", Promise)
|
|
722
|
+
], ResolverAPI.prototype, "getResolverFileTree", null), resolver_ts_decorate([
|
|
723
|
+
Router.post(SDK.ServerAPI.API.GetResolverFileDetails),
|
|
724
|
+
resolver_ts_metadata("design:type", Function),
|
|
725
|
+
resolver_ts_metadata("design:paramtypes", []),
|
|
726
|
+
resolver_ts_metadata("design:returntype", Promise)
|
|
727
|
+
], ResolverAPI.prototype, "getResolverFileDetails", null);
|
|
728
|
+
let execAsync = promisify(exec), supportedChromiumBrowsers = [
|
|
729
|
+
'Google Chrome Canary',
|
|
730
|
+
'Google Chrome Dev',
|
|
731
|
+
'Google Chrome Beta',
|
|
732
|
+
'Google Chrome',
|
|
733
|
+
'Microsoft Edge',
|
|
734
|
+
'Brave Browser',
|
|
735
|
+
'Vivaldi',
|
|
736
|
+
'Chromium'
|
|
737
|
+
], getTargetBrowser = async ()=>{
|
|
738
|
+
let targetBrowser = process.env.BROWSER;
|
|
739
|
+
if (!targetBrowser || !supportedChromiumBrowsers.includes(targetBrowser)) {
|
|
740
|
+
let { stdout: ps } = await execAsync('ps cax');
|
|
741
|
+
targetBrowser = supportedChromiumBrowsers.find((b)=>ps.includes(b));
|
|
742
|
+
}
|
|
743
|
+
return targetBrowser;
|
|
744
|
+
}, openWithDefaultBrowser = async (url)=>{
|
|
745
|
+
try {
|
|
746
|
+
let { default: open } = await import("open");
|
|
747
|
+
return await open(url), !0;
|
|
748
|
+
} catch (err) {
|
|
749
|
+
return rsdoctorLogger.error('Failed to open Rsdoctor URL.'), rsdoctorLogger.error(err), !1;
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
async function openBrowser(url, needEncodeURI = !0) {
|
|
753
|
+
if ('darwin' === process.platform) try {
|
|
754
|
+
let targetBrowser = await getTargetBrowser();
|
|
755
|
+
if (targetBrowser) return await execAsync(`osascript openChrome.applescript "${needEncodeURI ? encodeURI(url) : url}" "${targetBrowser}"`, {
|
|
756
|
+
cwd: join(__rspack_import_meta_dirname__, '../static')
|
|
757
|
+
}), !0;
|
|
758
|
+
rsdoctorLogger.debug('Failed to find the target browser.');
|
|
759
|
+
} catch (err) {
|
|
760
|
+
rsdoctorLogger.debug("Failed to open Rsdoctor URL with apple script."), rsdoctorLogger.debug(err);
|
|
761
|
+
}
|
|
762
|
+
return openWithDefaultBrowser(url);
|
|
763
|
+
}
|
|
764
|
+
function createHttpError(status, message, type) {
|
|
765
|
+
return Object.assign(Error(message), {
|
|
766
|
+
status,
|
|
767
|
+
statusCode: status,
|
|
768
|
+
type
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
function getContentType(req) {
|
|
772
|
+
let contentType = req.headers['content-type'];
|
|
773
|
+
if ('string' == typeof contentType) return contentType;
|
|
774
|
+
}
|
|
775
|
+
function normalizeReadError(error, charset) {
|
|
776
|
+
return error instanceof Error && 'status' in error && 'number' == typeof error.status ? charset && 'type' in error && 'encoding.unsupported' === error.type ? createHttpError(415, `unsupported charset "${charset.toUpperCase()}"`, 'charset.unsupported') : error : createHttpError(400, error instanceof Error ? error.message : 'failed to read request body', 'request.invalid');
|
|
777
|
+
}
|
|
778
|
+
let server_require = createRequire(import.meta.url), OPEN_IN_EDITOR_EDITORS = new Set(SDK.OPEN_IN_EDITOR_EDITORS), LARGE_JSON_BODY_ROUTES = new Set([
|
|
779
|
+
SDK.ServerAPI.API.ReportLoader,
|
|
780
|
+
SDK.ServerAPI.API.ReportSourceMap
|
|
781
|
+
]);
|
|
782
|
+
class RsdoctorServer {
|
|
783
|
+
constructor(sdk, port = defaultPort, config){
|
|
784
|
+
this.sdk = sdk, this.disposed = !0, this._socketToken = randomBytes(16).toString('hex'), this.get = (route, cb)=>{
|
|
785
|
+
let { app } = this;
|
|
786
|
+
return app.use(route, this.wrapNextHandleFunction('GET', cb)), app;
|
|
787
|
+
}, this.post = (route, cb)=>{
|
|
788
|
+
let { app } = this;
|
|
789
|
+
return app.use(route, this.wrapNextHandleFunction('POST', cb)), app;
|
|
790
|
+
}, this.dispose = async (exitCode)=>{
|
|
791
|
+
if (this.disposed) {
|
|
792
|
+
void 0 !== exitCode && process.exit(exitCode);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
this.disposed = !0, this._server && await this._server.close(), this._socket && this._socket.dispose(), void 0 !== exitCode && process.exit(exitCode);
|
|
796
|
+
}, assert('number' == typeof port), this.port = port, this._router = new Router({
|
|
797
|
+
sdk,
|
|
798
|
+
server: this,
|
|
799
|
+
apis: Object.values(apis_namespaceObject)
|
|
800
|
+
}), this._innerClientPath = config?.innerClientPath || '', this._printServerUrl = config?.printServerUrl ?? !0, this._cors = config?.cors;
|
|
801
|
+
}
|
|
802
|
+
get app() {
|
|
803
|
+
return this._server.app;
|
|
804
|
+
}
|
|
805
|
+
get host() {
|
|
806
|
+
return defaultHost;
|
|
807
|
+
}
|
|
808
|
+
get origin() {
|
|
809
|
+
return `http://${this.host}:${this.port}`;
|
|
810
|
+
}
|
|
811
|
+
get socketUrl() {
|
|
812
|
+
return {
|
|
813
|
+
port: this.port,
|
|
814
|
+
socketUrl: `ws://localhost:${this.port}?token=${this._socketToken}`,
|
|
815
|
+
token: this._socketToken
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
get innerClientPath() {
|
|
819
|
+
return this._innerClientPath;
|
|
820
|
+
}
|
|
821
|
+
async createInnerServer() {
|
|
822
|
+
let lastError, expectedPort = this.port;
|
|
823
|
+
for(let retry = 0; retry < 10; retry++){
|
|
824
|
+
let port = getPortSync(expectedPort, this.host);
|
|
825
|
+
try {
|
|
826
|
+
return {
|
|
827
|
+
port,
|
|
828
|
+
server: await createServer(port, this.host)
|
|
829
|
+
};
|
|
830
|
+
} catch (error) {
|
|
831
|
+
if ('EADDRINUSE' !== error.code) throw error;
|
|
832
|
+
lastError = error, expectedPort = port + 1;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
throw lastError;
|
|
836
|
+
}
|
|
837
|
+
resolveCorsOptions() {
|
|
838
|
+
return !1 !== this._cors && (!0 === this._cors ? {} : void 0 === this._cors ? {
|
|
839
|
+
origin: DEFAULT_ALLOWED_CORS_ORIGINS
|
|
840
|
+
} : {
|
|
841
|
+
...this._cors,
|
|
842
|
+
origin: void 0 === this._cors.origin ? DEFAULT_ALLOWED_CORS_ORIGINS : this._cors.origin
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
async bootstrap() {
|
|
846
|
+
if (!this.disposed) return;
|
|
847
|
+
let { port, server } = await this.createInnerServer(), corsOptions = this.resolveCorsOptions();
|
|
848
|
+
this.port = port, this._server = server, this._socket = new Socket({
|
|
849
|
+
sdk: this.sdk,
|
|
850
|
+
server: this._server.server,
|
|
851
|
+
port: this.port,
|
|
852
|
+
token: this._socketToken
|
|
853
|
+
}), await this._socket.bootstrap(), function(port, builderName) {
|
|
854
|
+
let homeDir = os_0.homedir(), rsdoctorDir = path_0.join(homeDir, '.cache/rsdoctor'), mcpPortFilePath = path_0.join(rsdoctorDir, 'mcp.json');
|
|
855
|
+
fs.existsSync(rsdoctorDir) || fs.mkdirSync(rsdoctorDir, {
|
|
856
|
+
recursive: !0
|
|
857
|
+
});
|
|
858
|
+
let mcpJson = {
|
|
859
|
+
portList: {},
|
|
860
|
+
port: 0
|
|
861
|
+
};
|
|
862
|
+
if (fs.existsSync(mcpPortFilePath)) try {
|
|
863
|
+
mcpJson = JSON.parse(fs.readFileSync(mcpPortFilePath, 'utf8'));
|
|
864
|
+
} catch (error) {
|
|
865
|
+
rsdoctorLogger.debug('Failed to parse mcp.json', error);
|
|
866
|
+
}
|
|
867
|
+
mcpJson.portList || (mcpJson.portList = {}), mcpJson.portList[builderName || 'builder'] = port, mcpJson.port = port, fs.writeFileSync(mcpPortFilePath, JSON.stringify(mcpJson, null, 2), 'utf8');
|
|
868
|
+
}(this.port, this.sdk.name), rsdoctorLogger.debug(`Successfully wrote mcp.json for ${color.cyan(this.sdk.name)} builder`), this.disposed = !1, this.app.use((req, res, next)=>{
|
|
869
|
+
if (!isAllowedRequestHost(req.headers.host || req.headers[':authority'])) {
|
|
870
|
+
res.statusCode = 403, res.end();
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
next();
|
|
874
|
+
}), !1 !== corsOptions && corsOptions.origin === DEFAULT_ALLOWED_CORS_ORIGINS && this.app.use((req, res, next)=>{
|
|
875
|
+
let host = req.headers.host || req.headers[':authority'];
|
|
876
|
+
if (!function(origin, host) {
|
|
877
|
+
if (void 0 === origin) return !0;
|
|
878
|
+
if ('string' != typeof origin || 'string' != typeof host || !(void 0 === origin || 'string' == typeof origin && DEFAULT_ALLOWED_CORS_ORIGINS.test(origin))) return !1;
|
|
879
|
+
let originHostname = function(origin) {
|
|
880
|
+
try {
|
|
881
|
+
let hostname = new URL(origin).hostname.toLowerCase();
|
|
882
|
+
return hostname.startsWith('[') && hostname.endsWith(']') ? hostname.slice(1, -1) : hostname;
|
|
883
|
+
} catch {
|
|
884
|
+
return '';
|
|
885
|
+
}
|
|
886
|
+
}(origin), hostHostname = getHostnameFromHost(host).toLowerCase();
|
|
887
|
+
return !originHostname.endsWith('.localhost') || originHostname === hostHostname;
|
|
888
|
+
}(req.headers.origin, host)) {
|
|
889
|
+
res.statusCode = 403, res.end();
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
next();
|
|
893
|
+
}), !1 !== corsOptions && this.app.use(cors(corsOptions)), this.app.use(function(options = {}) {
|
|
894
|
+
return (req, _res, next)=>{
|
|
895
|
+
let content, limit, contentType, contentType1, match;
|
|
896
|
+
if ('body' in req || (req.body = void 0), !(void 0 !== req.headers['transfer-encoding'] || !Number.isNaN(Number(req.headers['content-length']))) || !(contentType = getContentType(req)) || 'application/json' !== contentType.split(';', 1)[0].trim().toLowerCase()) return void next();
|
|
897
|
+
let charset = (contentType1 = getContentType(req), match = contentType1?.match(/(?:^|;)\s*charset\s*=\s*(?:"([^"]+)"|([^;\s]+))/i), (match?.[1] || match?.[2] || 'utf-8').toLowerCase());
|
|
898
|
+
if (!charset.startsWith('utf-')) {
|
|
899
|
+
req.resume(), next(createHttpError(415, `unsupported charset "${charset.toUpperCase()}"`, 'charset.unsupported'));
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
try {
|
|
903
|
+
content = function(req) {
|
|
904
|
+
let stream, contentEncoding = req.headers['content-encoding'], encoding = 'string' == typeof contentEncoding ? contentEncoding.toLowerCase() : 'identity';
|
|
905
|
+
if ('identity' === encoding) return {
|
|
906
|
+
stream: req,
|
|
907
|
+
length: req.headers['content-length']
|
|
908
|
+
};
|
|
909
|
+
switch(encoding){
|
|
910
|
+
case 'gzip':
|
|
911
|
+
stream = createGunzip();
|
|
912
|
+
break;
|
|
913
|
+
case 'deflate':
|
|
914
|
+
stream = createInflate();
|
|
915
|
+
break;
|
|
916
|
+
case 'br':
|
|
917
|
+
stream = createBrotliDecompress();
|
|
918
|
+
break;
|
|
919
|
+
default:
|
|
920
|
+
throw createHttpError(415, `unsupported content encoding "${encoding}"`, 'encoding.unsupported');
|
|
921
|
+
}
|
|
922
|
+
let cleanup = ()=>{
|
|
923
|
+
req.removeListener('aborted', onAborted), req.removeListener('close', onClose), req.removeListener('error', onError), stream.removeListener('close', cleanup);
|
|
924
|
+
}, destroy = (error)=>{
|
|
925
|
+
stream.destroyed || stream.destroy(error);
|
|
926
|
+
}, onAborted = ()=>{
|
|
927
|
+
destroy(createHttpError(400, 'request aborted', 'request.aborted'));
|
|
928
|
+
}, onClose = ()=>{
|
|
929
|
+
!1 === req.complete && onAborted();
|
|
930
|
+
}, onError = (error)=>{
|
|
931
|
+
destroy(error);
|
|
932
|
+
};
|
|
933
|
+
return req.once('aborted', onAborted), req.once('close', onClose), req.once('error', onError), stream.once('close', cleanup), req.pipe(stream), {
|
|
934
|
+
stream,
|
|
935
|
+
cleanup,
|
|
936
|
+
decompressor: stream
|
|
937
|
+
};
|
|
938
|
+
}(req);
|
|
939
|
+
} catch (error) {
|
|
940
|
+
req.resume(), next(normalizeReadError(error));
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
let handleError = (error)=>{
|
|
944
|
+
content.cleanup?.(), content.decompressor && (req.unpipe(content.decompressor), content.decompressor.destroy()), req.resume(), next(normalizeReadError(error, charset));
|
|
945
|
+
};
|
|
946
|
+
try {
|
|
947
|
+
limit = 'function' == typeof options.limit ? options.limit(req) : options.limit;
|
|
948
|
+
} catch (error) {
|
|
949
|
+
handleError(error);
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
raw_body(content.stream, {
|
|
953
|
+
encoding: charset,
|
|
954
|
+
length: content.length,
|
|
955
|
+
limit
|
|
956
|
+
}).then((body)=>{
|
|
957
|
+
try {
|
|
958
|
+
req.body = function(body) {
|
|
959
|
+
let value;
|
|
960
|
+
if (0 === body.length) return {};
|
|
961
|
+
try {
|
|
962
|
+
value = JSON.parse(body);
|
|
963
|
+
} catch (error) {
|
|
964
|
+
throw createHttpError(400, error.message, 'entity.parse.failed');
|
|
965
|
+
}
|
|
966
|
+
if (null === value || 'object' != typeof value) throw createHttpError(400, 'JSON body must be an object or array', 'entity.parse.failed');
|
|
967
|
+
return value;
|
|
968
|
+
}(body);
|
|
969
|
+
} catch (error) {
|
|
970
|
+
handleError(error);
|
|
971
|
+
return;
|
|
972
|
+
}
|
|
973
|
+
content.cleanup?.(), next();
|
|
974
|
+
}, handleError);
|
|
975
|
+
};
|
|
976
|
+
}({
|
|
977
|
+
limit: (req)=>{
|
|
978
|
+
let pathname = new URL(req.url || '/', 'http://localhost').pathname;
|
|
979
|
+
return LARGE_JSON_BODY_ROUTES.has(pathname) ? '500mb' : '10mb';
|
|
980
|
+
}
|
|
981
|
+
})), await this._router.setup();
|
|
982
|
+
let clientHtmlPath = this._innerClientPath ? this._innerClientPath : server_require.resolve('@rsdoctor/client'), clientDistPath = path_0.resolve(clientHtmlPath, '..');
|
|
983
|
+
this.app.use(sirv(clientDistPath, {
|
|
984
|
+
dev: !0
|
|
985
|
+
})), this.app.use('/__open-in-editor', (req, res, next)=>{
|
|
986
|
+
if ('GET' !== req.method && 'HEAD' !== req.method) return next();
|
|
987
|
+
let url = new URL(req.url || '', "http://localhost"), file = url.searchParams.get('file'), editor = url.searchParams.get('editor');
|
|
988
|
+
if (!function(token, expectedToken) {
|
|
989
|
+
if ('string' != typeof token || !expectedToken) return !1;
|
|
990
|
+
let tokenBuffer = Buffer.from(token), expectedTokenBuffer = Buffer.from(expectedToken);
|
|
991
|
+
return tokenBuffer.length === expectedTokenBuffer.length && timingSafeEqual(tokenBuffer, expectedTokenBuffer);
|
|
992
|
+
}(url.searchParams.get('token'), this._socketToken)) {
|
|
993
|
+
res.statusCode = 403, res.end();
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
if (!file) {
|
|
997
|
+
res.statusCode = 400, res.end('Missing file parameter');
|
|
998
|
+
return;
|
|
999
|
+
}
|
|
1000
|
+
if (!('string' == typeof editor && OPEN_IN_EDITOR_EDITORS.has(editor))) {
|
|
1001
|
+
res.statusCode = 400, res.end('Unsupported editor parameter');
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
try {
|
|
1005
|
+
let launch = server_require('launch-editor'), responded = !1, safeEnd = (code, body)=>{
|
|
1006
|
+
responded || (responded = !0, res.statusCode = code, res.end(body));
|
|
1007
|
+
};
|
|
1008
|
+
launch(file, editor, (_fileName, errorMessage)=>{
|
|
1009
|
+
errorMessage && safeEnd(500, errorMessage);
|
|
1010
|
+
}), setTimeout(()=>{
|
|
1011
|
+
safeEnd(200, '');
|
|
1012
|
+
}, 200);
|
|
1013
|
+
} catch (err) {
|
|
1014
|
+
res.writableEnded || (res.statusCode = 500, res.end(err.message));
|
|
1015
|
+
}
|
|
1016
|
+
}), process.once('exit', ()=>this.dispose()), process.once('SIGINT', ()=>this.dispose(0)), process.once('SIGTERM', ()=>this.dispose(0)), process.once('unhandledRejection', (reason)=>{
|
|
1017
|
+
console.error('Unhandled promise rejection:', reason), this.dispose(1);
|
|
1018
|
+
}), process.once('uncaughtException', (err, origin)=>{
|
|
1019
|
+
console.error('Uncaught exception:', err), origin && console.error('Exception origin:', origin), this.dispose(1);
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
wrapNextHandleFunction(method, cb) {
|
|
1023
|
+
return async (req, res, next)=>{
|
|
1024
|
+
if (req.method?.toUpperCase() === method) {
|
|
1025
|
+
try {
|
|
1026
|
+
let body = await cb(req, res, next);
|
|
1027
|
+
if (res.statusCode = 200, Buffer.isBuffer(body)) {
|
|
1028
|
+
res.setHeader('Content-Length', body.byteLength);
|
|
1029
|
+
let ps = new PassThrough();
|
|
1030
|
+
ps.write(body), ps.end(), ps.pipe(res);
|
|
1031
|
+
} else body && 'object' == typeof body ? (res.writeHead(200, {
|
|
1032
|
+
'Content-Type': 'application/json;utf-8'
|
|
1033
|
+
}), res.write(JSON.stringify(body)), res.end()) : res.writeHead(200).end(body);
|
|
1034
|
+
} catch (error) {
|
|
1035
|
+
return res.statusCode = 500, res.end(error.message), next(error);
|
|
1036
|
+
}
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
await next();
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
proxy(api, method, cb) {
|
|
1043
|
+
let idx = this.app.stack.findIndex((e)=>e.route === api);
|
|
1044
|
+
-1 === idx && (idx = this.app.stack.length - 1), this.app.stack.splice(idx, 0, {
|
|
1045
|
+
route: api,
|
|
1046
|
+
handle: this.wrapNextHandleFunction(method, cb)
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
getClientUrl(route = 'homepage', ...args) {
|
|
1050
|
+
let relativeUrl = SDK.ServerAPI.API.EntryHtml;
|
|
1051
|
+
if (route !== Client.RsdoctorClientRoutes.BundleDiff) return relativeUrl;
|
|
1052
|
+
{
|
|
1053
|
+
let [baseline, current] = args, qs = Bundle.getBundleDiffPageQueryString([
|
|
1054
|
+
baseline,
|
|
1055
|
+
current
|
|
1056
|
+
]);
|
|
1057
|
+
return `${relativeUrl}${qs}#${Client.RsdoctorClientRoutes.BundleDiff}`;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
async openClientPage(...args) {
|
|
1061
|
+
let relativeUrl = this.getClientUrl(...args), needEncodeURI = args[0] === Client.RsdoctorClientRoutes.BundleDiff, url = `http://${this.host}:${this.port}${relativeUrl}`, localhostUrl = `http://localhost:${this.port}${relativeUrl}`;
|
|
1062
|
+
await openBrowser(localhostUrl, !needEncodeURI), this._printServerUrl && rsdoctorLogger.info(`${color.green(`${this.sdk.name} compiler's`)} analyzer running on: ${color.cyan(url)}`);
|
|
1063
|
+
}
|
|
1064
|
+
sendAPIDataToClient(api, msg) {
|
|
1065
|
+
this._socket?.sendAPIData(api, msg);
|
|
1066
|
+
}
|
|
1067
|
+
async broadcast() {
|
|
1068
|
+
await this._socket?.broadcast();
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
class RsdoctorFakeServer extends RsdoctorServer {
|
|
1072
|
+
constructor(sdk, port = defaultPort){
|
|
1073
|
+
super(sdk, port), this.sdk = sdk, this.dispose = async ()=>{}, this.sdk = sdk;
|
|
1074
|
+
}
|
|
1075
|
+
async bootstrap() {}
|
|
1076
|
+
async openClientPage() {}
|
|
1077
|
+
}
|
|
1078
|
+
function findRoot(startDir = process.cwd()) {
|
|
1079
|
+
let dir = startDir, firstPkgDir = null;
|
|
1080
|
+
for(; dir !== path_0.parse(dir).root;){
|
|
1081
|
+
if (fs.existsSync(path_0.join(dir, 'pnpm-workspace.yaml')) || fs.existsSync(path_0.join(dir, 'yarn.lock')) || fs.existsSync(path_0.join(dir, 'lerna.json'))) return dir;
|
|
1082
|
+
let pkgPath = path_0.join(dir, 'package.json');
|
|
1083
|
+
if (fs.existsSync(pkgPath) && (firstPkgDir || (firstPkgDir = dir), JSON.parse(fs.readFileSync(pkgPath, 'utf8')).workspaces)) return dir;
|
|
1084
|
+
dir = path_0.dirname(dir);
|
|
1085
|
+
}
|
|
1086
|
+
return firstPkgDir || null;
|
|
1087
|
+
}
|
|
1088
|
+
String((date = new Date()).getMonth() + 1).padStart(2, '0'), String(date.getDate()).padStart(2, '0'), date.getFullYear();
|
|
1089
|
+
class SDKCore {
|
|
1090
|
+
constructor({ name, root }){
|
|
1091
|
+
this.hooks = {
|
|
1092
|
+
afterSaveManifest: new AsyncSeriesHook([
|
|
1093
|
+
'result'
|
|
1094
|
+
])
|
|
1095
|
+
}, this._envinfo = {}, this._clientRoutes = new Set([
|
|
1096
|
+
Manifest.RsdoctorManifestClientRoutes.Overall
|
|
1097
|
+
]), this.diskManifestPath = '', this._name = name, this.root = root, this.pid = node_process.pid, this._outputDir = node_path.join(this.outputDir || this.root, Constants.RsdoctorOutputFolder);
|
|
1098
|
+
}
|
|
1099
|
+
get outputDir() {
|
|
1100
|
+
return this._outputDir;
|
|
1101
|
+
}
|
|
1102
|
+
get name() {
|
|
1103
|
+
return this._name;
|
|
1104
|
+
}
|
|
1105
|
+
async bootstrap() {
|
|
1106
|
+
let [cpu, memory, nodeVersion, yarnVersion, npmVersion, pnpmVersion] = await Promise.all([
|
|
1107
|
+
getCPUInfo(),
|
|
1108
|
+
getMemoryInfo(),
|
|
1109
|
+
getNodeVersion(),
|
|
1110
|
+
getYarnVersion(),
|
|
1111
|
+
getNpmVersion(),
|
|
1112
|
+
getPnpmVersion()
|
|
1113
|
+
]);
|
|
1114
|
+
this._envinfo = {
|
|
1115
|
+
...this._envinfo,
|
|
1116
|
+
cpu,
|
|
1117
|
+
memory,
|
|
1118
|
+
nodeVersion,
|
|
1119
|
+
yarnVersion,
|
|
1120
|
+
npmVersion,
|
|
1121
|
+
pnpmVersion
|
|
1122
|
+
};
|
|
1123
|
+
let hash = createHash('md5').update([
|
|
1124
|
+
this.name,
|
|
1125
|
+
this.root,
|
|
1126
|
+
JSON.stringify(this._envinfo),
|
|
1127
|
+
Date.now()
|
|
1128
|
+
].join('_')).digest('hex');
|
|
1129
|
+
this.setHash(hash);
|
|
1130
|
+
}
|
|
1131
|
+
async dispose() {}
|
|
1132
|
+
setOutputDir(outputDir) {
|
|
1133
|
+
this._outputDir = outputDir;
|
|
1134
|
+
}
|
|
1135
|
+
setName(name) {
|
|
1136
|
+
this._name = name;
|
|
1137
|
+
}
|
|
1138
|
+
setHash(hash) {
|
|
1139
|
+
this.hash = hash;
|
|
1140
|
+
}
|
|
1141
|
+
getHash() {
|
|
1142
|
+
return this.hash;
|
|
1143
|
+
}
|
|
1144
|
+
getClientRoutes() {
|
|
1145
|
+
return [
|
|
1146
|
+
...this._clientRoutes
|
|
1147
|
+
];
|
|
1148
|
+
}
|
|
1149
|
+
addClientRoutes(routes) {
|
|
1150
|
+
routes.forEach((route)=>{
|
|
1151
|
+
this._clientRoutes.add(route);
|
|
1152
|
+
}), this.onDataReport();
|
|
1153
|
+
}
|
|
1154
|
+
async writePieces(storeData, _options) {
|
|
1155
|
+
let { outputDir } = this, manifest = node_path.resolve(outputDir, Constants.RsdoctorOutputManifest);
|
|
1156
|
+
this.diskManifestPath = manifest, await external_fs_extra_fs_extra.ensureDir(outputDir);
|
|
1157
|
+
let urlsPromiseList = [];
|
|
1158
|
+
for (let key of Object.keys(storeData)){
|
|
1159
|
+
let data = storeData[key];
|
|
1160
|
+
if ('object' != typeof data) {
|
|
1161
|
+
urlsPromiseList.push({
|
|
1162
|
+
name: key,
|
|
1163
|
+
files: data
|
|
1164
|
+
});
|
|
1165
|
+
continue;
|
|
1166
|
+
}
|
|
1167
|
+
let jsonStr = await (async ()=>{
|
|
1168
|
+
try {
|
|
1169
|
+
if ('configs' === key) return JSON.stringify(decycle(data));
|
|
1170
|
+
return JSON.stringify(data);
|
|
1171
|
+
} catch {
|
|
1172
|
+
return stringify(data);
|
|
1173
|
+
}
|
|
1174
|
+
})();
|
|
1175
|
+
if (Array.isArray(jsonStr)) {
|
|
1176
|
+
let fileOffset = 0;
|
|
1177
|
+
for (let str of jsonStr){
|
|
1178
|
+
let result = await this.writeToFolder(str, outputDir, key, fileOffset);
|
|
1179
|
+
fileOffset += result.files.length, urlsPromiseList.push(result);
|
|
1180
|
+
}
|
|
1181
|
+
} else urlsPromiseList.push(this.writeToFolder(jsonStr, outputDir, key));
|
|
1182
|
+
}
|
|
1183
|
+
let dataUrls = await Promise.all(urlsPromiseList);
|
|
1184
|
+
rsdoctorLogger.debug(`SDKCore.writePieces extraConfig: ${JSON.stringify(this.extraConfig)}`, '[SDKCore.writePieces]'), this.cloudData = {
|
|
1185
|
+
client: {
|
|
1186
|
+
enableRoutes: this.getClientRoutes()
|
|
1187
|
+
},
|
|
1188
|
+
data: dataUrls.reduce((t, item)=>(t[item.name] = Array.isArray(item.files) ? item.files.map((e)=>e.path).concat(t[item.name] || []) : item.files, t), {})
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
async writeManifest() {
|
|
1192
|
+
let { cloudData: data, diskManifestPath } = this, dataStr = JSON.stringify(data, null, 2);
|
|
1193
|
+
rsdoctorLogger.debug(`SDKCore.writeManifest extraConfig: ${this.extraConfig}`, '[SDKCore.writeManifest]');
|
|
1194
|
+
let dir = node_path.dirname(diskManifestPath), base = node_path.basename(diskManifestPath), tmpPath = node_path.join(dir, `${base}.${Date.now()}.${randomUUID()}.tmp`);
|
|
1195
|
+
return await external_fs_extra_fs_extra.outputFile(tmpPath, dataStr), node_fs.renameSync(tmpPath, diskManifestPath), diskManifestPath;
|
|
1196
|
+
}
|
|
1197
|
+
async saveManifest(data, options) {
|
|
1198
|
+
await this.writePieces(data, options);
|
|
1199
|
+
let manifestDiskPath = await this.writeManifest();
|
|
1200
|
+
return await this.hooks.afterSaveManifest.promise({
|
|
1201
|
+
manifestWithShardingFiles: this.cloudData,
|
|
1202
|
+
manifestDiskPath
|
|
1203
|
+
}), manifestDiskPath;
|
|
1204
|
+
}
|
|
1205
|
+
writeToFolder(jsonStr, dir, key, index) {
|
|
1206
|
+
let sharding = new FileSharding(Algorithm.compressText(jsonStr)), folder = node_path.resolve(dir, key);
|
|
1207
|
+
return sharding.writeStringToFolder(folder, '', index).then((item)=>({
|
|
1208
|
+
name: key,
|
|
1209
|
+
files: item.map((el)=>({
|
|
1210
|
+
path: node_path.resolve(folder, el.filename),
|
|
1211
|
+
basename: el.filename,
|
|
1212
|
+
content: el.content
|
|
1213
|
+
}))
|
|
1214
|
+
}));
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
let client_require = createRequire(import.meta.url), resolveClientDiffHtmlPath = (innerClientPath)=>{
|
|
1218
|
+
let innerClientPath1;
|
|
1219
|
+
return path_0.resolve((innerClientPath1 = innerClientPath, path_0.dirname(innerClientPath1 || client_require.resolve('@rsdoctor/client'))), 'diff.html');
|
|
1220
|
+
}, sdk_require = createRequire(import.meta.url);
|
|
1221
|
+
class RsdoctorSDK extends SDKCore {
|
|
1222
|
+
constructor(options){
|
|
1223
|
+
super(options), this._summary = {
|
|
1224
|
+
costs: []
|
|
1225
|
+
}, 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();
|
|
1226
|
+
let serverConfig = options.config?.server, port = serverConfig?.port ?? options.port;
|
|
1227
|
+
this.server = options.config?.noServer ? new RsdoctorFakeServer(this, port) : new RsdoctorServer(this, port, {
|
|
1228
|
+
innerClientPath: options.config?.innerClientPath || '',
|
|
1229
|
+
printServerUrl: options.config?.printLog?.serverUrls,
|
|
1230
|
+
cors: serverConfig?.cors
|
|
1231
|
+
}), this.type = Lodash.isNumber(options.type) ? options.type : SDK.ToDataType.Normal, this.extraConfig = options.config, this.root = findRoot() ?? '';
|
|
1232
|
+
}
|
|
1233
|
+
async bootstrap() {
|
|
1234
|
+
rsdoctorLogger.debug(`${Date.now()}`, '[RsdoctorSDK][bootstrap start]'), this.server && await this.server.bootstrap(), await super.bootstrap(), rsdoctorLogger.debug(`${Date.now()} ${this.server.origin}`, '[RsdoctorSDK][bootstrap end]');
|
|
1235
|
+
}
|
|
1236
|
+
async dispose() {
|
|
1237
|
+
rsdoctorLogger.debug(`${Date.now()}`, '[RsdoctorSDK][dispose start]'), this.server && await this.server.dispose(), await super.dispose(), rsdoctorLogger.debug(`${Date.now()}`, '[RsdoctorSDK][dispose end]');
|
|
1238
|
+
}
|
|
1239
|
+
async applyErrorFix(id) {
|
|
1240
|
+
let { _errors: errors } = this, error = errors.find((err)=>err.id === id);
|
|
1241
|
+
if (!error || !error.path || !error.fixData || error.fixData.isFixed) return;
|
|
1242
|
+
let { path: filePath, fixData } = error, sameFileErrors = errors.filter((item)=>item.path === filePath && item !== error), content = (await node_fs.promises.readFile(filePath, 'utf-8')).toString(), startTxt = content.substring(0, fixData.start), endTxt = content.substring(fixData.end, content.length), offset = (fixData.newText ?? '').length - (fixData.end - fixData.start);
|
|
1243
|
+
for (let other of (content = startTxt + fixData.newText + endTxt, sameFileErrors)){
|
|
1244
|
+
let { fixData: otherFixData } = other;
|
|
1245
|
+
otherFixData && otherFixData.start >= fixData.end && (otherFixData.start += offset, otherFixData.end += offset);
|
|
1246
|
+
}
|
|
1247
|
+
await node_fs.promises.writeFile(filePath, content);
|
|
1248
|
+
}
|
|
1249
|
+
clear() {
|
|
1250
|
+
this._errors = [], this._loader = [], this._resolver = [], this._plugin = {}, this._moduleGraph = new ModuleGraph(), this._chunkGraph = new ChunkGraph();
|
|
1251
|
+
}
|
|
1252
|
+
clearSourceMapCache() {
|
|
1253
|
+
this._rawSourceMapCache = new Map(), this._sourceMap = new Map();
|
|
1254
|
+
}
|
|
1255
|
+
async getSourceMap(file) {
|
|
1256
|
+
let { _sourceMap: sourceMap, _rawSourceMapCache: rawMap } = this;
|
|
1257
|
+
if (sourceMap.has(file)) return sourceMap.get(file);
|
|
1258
|
+
let rawData = rawMap.get(file);
|
|
1259
|
+
if (!rawData || rawData.version < 0 || !rawData.sourcesContent?.[0] || !rawData.mappings) return Promise.resolve(void 0);
|
|
1260
|
+
try {
|
|
1261
|
+
let result = await new SourceMapConsumer(rawData);
|
|
1262
|
+
return sourceMap.set(file, result), result;
|
|
1263
|
+
} catch {
|
|
1264
|
+
return Promise.resolve(void 0);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
reportSourceMap(data) {
|
|
1268
|
+
this._rawSourceMapCache.set(data.file, data);
|
|
1269
|
+
}
|
|
1270
|
+
reportConfiguration(config) {
|
|
1271
|
+
config.root ??= this.root, this._configs.push(config), this.onDataReport();
|
|
1272
|
+
}
|
|
1273
|
+
reportError(errors) {
|
|
1274
|
+
errors.forEach((item)=>{
|
|
1275
|
+
this._errors.push(DevToolError.from(item, {
|
|
1276
|
+
code: this.name
|
|
1277
|
+
}));
|
|
1278
|
+
}), this.onDataReport();
|
|
1279
|
+
}
|
|
1280
|
+
reportLoader(data) {
|
|
1281
|
+
data.forEach((item)=>{
|
|
1282
|
+
this.extraConfig?.mode === SDK.IMode[SDK.IMode.brief] && item.loaders.forEach((_loader)=>{
|
|
1283
|
+
_loader.input = void 0, _loader.result = void 0;
|
|
1284
|
+
});
|
|
1285
|
+
let match = this._loader.find((e)=>e.resource.path === item.resource.path);
|
|
1286
|
+
match ? match.loaders.push(...item.loaders) : (match = item, this._loader.push(item)), match.loaders.sort((a, b)=>a.startAt !== b.startAt ? a.startAt - b.startAt : a.isPitch ? b.isPitch ? a.loaderIndex - b.loaderIndex : -1 : b.isPitch ? 1 : b.loaderIndex - a.loaderIndex);
|
|
1287
|
+
}), this.onDataReport();
|
|
1288
|
+
}
|
|
1289
|
+
reportLoaderStartOrEnd(data) {
|
|
1290
|
+
let _builtinLoader = data.loaders[0];
|
|
1291
|
+
if (_builtinLoader.startAt) this._loaderStart.push(data);
|
|
1292
|
+
else if (_builtinLoader.endAt) {
|
|
1293
|
+
let matchLoaderStart = this._loaderStart.find((e)=>e.resource.path === data.resource.path && e.loaders[0].loader === _builtinLoader.loader);
|
|
1294
|
+
matchLoaderStart && (matchLoaderStart.loaders[0].result = _builtinLoader.result, matchLoaderStart.loaders[0].endAt = _builtinLoader.endAt, this.reportLoader([
|
|
1295
|
+
matchLoaderStart
|
|
1296
|
+
]));
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
reportResolver(data) {
|
|
1300
|
+
data.forEach((item)=>this._resolver.push(item)), this.onDataReport();
|
|
1301
|
+
}
|
|
1302
|
+
reportPlugin(data) {
|
|
1303
|
+
Object.keys(data).forEach((hook)=>{
|
|
1304
|
+
this._plugin[hook] ? data[hook].forEach((item)=>{
|
|
1305
|
+
this._plugin[hook].push(item || void 0);
|
|
1306
|
+
}) : this._plugin[hook] = data[hook];
|
|
1307
|
+
}), this.onDataReport();
|
|
1308
|
+
}
|
|
1309
|
+
reportModuleGraph(data) {
|
|
1310
|
+
rsdoctorLogger.debug(`data size: ${data.size()}`, '[SDK.reportModuleGraph][start]'), this._moduleGraph.fromInstance(data), this.createPackageGraph(), this.onDataReport(), rsdoctorLogger.debug(`sdk._moduleGraph size: ${this._moduleGraph.size()}`, '[SDK reportModuleGraph][end]');
|
|
1311
|
+
}
|
|
1312
|
+
reportPackageGraph(data) {
|
|
1313
|
+
rsdoctorLogger.debug('[SDK.reportPackageGraph][start]'), this._packageGraph || (this._packageGraph = data), this.onDataReport(), rsdoctorLogger.debug(`sdk._packageGraph size: ${this._packageGraph.getPackages().length}`, '[SDK reportPackageGraph][end]');
|
|
1314
|
+
}
|
|
1315
|
+
reportChunkGraph(data) {
|
|
1316
|
+
this._chunkGraph.addAsset(...data.getAssets()), this._chunkGraph.addChunk(...data.getChunks()), this._chunkGraph.addEntryPoint(...data.getEntryPoints()), this.onDataReport();
|
|
1317
|
+
}
|
|
1318
|
+
reportSummaryData(part) {
|
|
1319
|
+
for (let key of [
|
|
1320
|
+
'costs'
|
|
1321
|
+
]){
|
|
1322
|
+
let v = part[key];
|
|
1323
|
+
v && ('object' == typeof v ? Array.isArray(v) ? this._summary[key] = [
|
|
1324
|
+
...this._summary[key] || [],
|
|
1325
|
+
...v
|
|
1326
|
+
] : this._summary[key] = {
|
|
1327
|
+
...this._summary[key] || {},
|
|
1328
|
+
...v
|
|
1329
|
+
} : this._summary[key] = v);
|
|
1330
|
+
}
|
|
1331
|
+
this.onDataReport();
|
|
1332
|
+
}
|
|
1333
|
+
createPackageGraph() {
|
|
1334
|
+
if (rsdoctorLogger.debug(`sdk._moduleGraph size: ${this._moduleGraph.size()}`, '[SDK.createPackageGraph][start]'), !this._packageGraph) {
|
|
1335
|
+
let pkgGraph = PackageGraph.fromModuleGraph(this._moduleGraph, this.root, (path)=>{
|
|
1336
|
+
try {
|
|
1337
|
+
if (node_fs.existsSync(path)) return fs_extra.readJsonSync(path);
|
|
1338
|
+
} catch (error) {
|
|
1339
|
+
let { message, stack } = error;
|
|
1340
|
+
rsdoctorLogger.debug(()=>`sdk.createPackageGraph error, path: ${path}, error message: ${stack || message}`, '[SDK.createPackageGraph][error]');
|
|
1341
|
+
}
|
|
1342
|
+
});
|
|
1343
|
+
this._packageGraph = pkgGraph, rsdoctorLogger.debug(`sdk._packageGraph packages: ${this._packageGraph.getPackages().length}`, '[SDK.createPackageGraph][end]');
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
async writeStore(options) {
|
|
1347
|
+
rsdoctorLogger.debug("sdk.writeStore has run.", '[SDK.writeStore][end]');
|
|
1348
|
+
let htmlPath = '';
|
|
1349
|
+
if (this.extraConfig?.mode === SDK.IMode[SDK.IMode.brief]) {
|
|
1350
|
+
let clientHtmlPath = this.extraConfig.innerClientPath ? this.extraConfig.innerClientPath : sdk_require.resolve('@rsdoctor/client');
|
|
1351
|
+
if (this.extraConfig?.brief?.type?.includes('json')) {
|
|
1352
|
+
let data = this.getStoreData(), clientRoutes = this.getClientRoutes();
|
|
1353
|
+
node_fs.mkdirSync(this.outputDir, {
|
|
1354
|
+
recursive: !0
|
|
1355
|
+
}), node_fs.writeFileSync(path_0.resolve(this.outputDir, this.extraConfig.brief.jsonOptions?.fileName ?? 'rsdoctor-data.json'), JSON.stringify({
|
|
1356
|
+
data,
|
|
1357
|
+
clientRoutes
|
|
1358
|
+
}));
|
|
1359
|
+
}
|
|
1360
|
+
return this.extraConfig.brief?.type?.includes('html') && (htmlPath = this.inlineScriptsAndStyles(clientHtmlPath)), htmlPath;
|
|
1361
|
+
}
|
|
1362
|
+
return this.saveManifest(this.getStoreData(), options || {});
|
|
1363
|
+
}
|
|
1364
|
+
getStoreData() {
|
|
1365
|
+
let ctx = this, briefOptions = this.extraConfig?.brief, sections = briefOptions?.jsonOptions?.sections, isJsonType = briefOptions?.type?.includes('json');
|
|
1366
|
+
return {
|
|
1367
|
+
get hash () {
|
|
1368
|
+
return ctx.hash;
|
|
1369
|
+
},
|
|
1370
|
+
get root () {
|
|
1371
|
+
return ctx.root;
|
|
1372
|
+
},
|
|
1373
|
+
get envinfo () {
|
|
1374
|
+
return ctx._envinfo;
|
|
1375
|
+
},
|
|
1376
|
+
get pid () {
|
|
1377
|
+
return ctx.pid;
|
|
1378
|
+
},
|
|
1379
|
+
get errors () {
|
|
1380
|
+
if (isJsonType && sections && !sections.rules) return [];
|
|
1381
|
+
return ctx._errors.map((err)=>err.toData());
|
|
1382
|
+
},
|
|
1383
|
+
get configs () {
|
|
1384
|
+
return ctx._configs.slice();
|
|
1385
|
+
},
|
|
1386
|
+
get summary () {
|
|
1387
|
+
return {
|
|
1388
|
+
...ctx._summary
|
|
1389
|
+
};
|
|
1390
|
+
},
|
|
1391
|
+
get resolver () {
|
|
1392
|
+
return ctx._resolver.slice();
|
|
1393
|
+
},
|
|
1394
|
+
get loader () {
|
|
1395
|
+
return ctx._loader.slice();
|
|
1396
|
+
},
|
|
1397
|
+
get moduleGraph () {
|
|
1398
|
+
if (isJsonType && sections && !sections.moduleGraph) return {
|
|
1399
|
+
dependencies: [],
|
|
1400
|
+
modules: [],
|
|
1401
|
+
moduleGraphModules: [],
|
|
1402
|
+
exports: [],
|
|
1403
|
+
sideEffects: [],
|
|
1404
|
+
variables: [],
|
|
1405
|
+
layers: []
|
|
1406
|
+
};
|
|
1407
|
+
return ctx._moduleGraph.toData({
|
|
1408
|
+
contextPath: ctx._configs?.[0]?.config?.context || '',
|
|
1409
|
+
briefOptions
|
|
1410
|
+
});
|
|
1411
|
+
},
|
|
1412
|
+
get chunkGraph () {
|
|
1413
|
+
if (isJsonType && sections && !sections.chunkGraph) return {
|
|
1414
|
+
assets: [],
|
|
1415
|
+
chunks: [],
|
|
1416
|
+
entrypoints: []
|
|
1417
|
+
};
|
|
1418
|
+
return ctx._chunkGraph.toData(ctx.type);
|
|
1419
|
+
},
|
|
1420
|
+
get moduleCodeMap () {
|
|
1421
|
+
if (ctx.extraConfig?.mode === SDK.IMode[SDK.IMode.brief]) return {};
|
|
1422
|
+
return ctx._moduleGraph.toCodeData(ctx.type);
|
|
1423
|
+
},
|
|
1424
|
+
get plugin () {
|
|
1425
|
+
return {
|
|
1426
|
+
...ctx._plugin
|
|
1427
|
+
};
|
|
1428
|
+
},
|
|
1429
|
+
get packageGraph () {
|
|
1430
|
+
return ctx._packageGraph ? ctx._packageGraph.toData() : {
|
|
1431
|
+
packages: [],
|
|
1432
|
+
dependencies: []
|
|
1433
|
+
};
|
|
1434
|
+
},
|
|
1435
|
+
get treeShaking () {
|
|
1436
|
+
if (ctx.extraConfig?.mode === SDK.IMode[SDK.IMode.brief] || !ctx.extraConfig?.features?.treeShaking) return;
|
|
1437
|
+
return ctx._moduleGraph.toTreeShakingData();
|
|
1438
|
+
},
|
|
1439
|
+
get otherReports () {
|
|
1440
|
+
return {
|
|
1441
|
+
treemapReportHtml: ''
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
getManifestData() {
|
|
1447
|
+
let dataValue = this.getStoreData();
|
|
1448
|
+
return {
|
|
1449
|
+
client: {
|
|
1450
|
+
enableRoutes: this.getClientRoutes()
|
|
1451
|
+
},
|
|
1452
|
+
data: Object.keys(dataValue).reduce((t, e)=>(dataValue[e] && 'object' == typeof dataValue[e] ? t[e] = [
|
|
1453
|
+
`${this.server.origin}${SDK.ServerAPI.API.LoadDataByKey}/${e}`
|
|
1454
|
+
] : t[e] = dataValue[e], t), {}),
|
|
1455
|
+
__LOCAL__SERVER__: !0,
|
|
1456
|
+
__SOCKET__PORT__: this.server.socketUrl.port.toString(),
|
|
1457
|
+
__SOCKET__URL__: this.server.socketUrl.socketUrl
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
getRuleContext(_options) {
|
|
1461
|
+
return this.createPackageGraph(), {
|
|
1462
|
+
root: this.root,
|
|
1463
|
+
errors: this._errors.slice(),
|
|
1464
|
+
configs: this._configs.slice(),
|
|
1465
|
+
moduleGraph: this._moduleGraph,
|
|
1466
|
+
chunkGraph: this._chunkGraph,
|
|
1467
|
+
packageGraph: this._packageGraph,
|
|
1468
|
+
loader: this._loader.slice(),
|
|
1469
|
+
otherReports: {
|
|
1470
|
+
treemapReportHtml: ''
|
|
1471
|
+
}
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
onDataReport() {
|
|
1475
|
+
this.server.broadcast();
|
|
1476
|
+
}
|
|
1477
|
+
addRsdoctorDataToHTML(storeData, htmlContent) {
|
|
1478
|
+
let compressTextScripts = `<script>window.${Constants.WINDOW_RSDOCTOR_TAG}={}</script>`;
|
|
1479
|
+
for (let key of Object.keys(storeData)){
|
|
1480
|
+
let data = storeData[key], jsonStrFn = ()=>{
|
|
1481
|
+
try {
|
|
1482
|
+
if ('configs' === key) return JSON.stringify(decycle(data));
|
|
1483
|
+
return JSON.stringify(data);
|
|
1484
|
+
} catch (error) {
|
|
1485
|
+
return console.error(error), '';
|
|
1486
|
+
}
|
|
1487
|
+
}, compressText = Algorithm.compressText(jsonStrFn());
|
|
1488
|
+
compressTextScripts = `${compressTextScripts} <script>window.${Constants.WINDOW_RSDOCTOR_TAG}.${key}=${JSON.stringify(compressText)}</script>`;
|
|
1489
|
+
}
|
|
1490
|
+
return compressTextScripts = `${compressTextScripts} <script>window.${Constants.WINDOW_RSDOCTOR_TAG}.enableRoutes=${JSON.stringify(this.getClientRoutes())}</script>`, htmlContent = htmlContent.replace('<body>', `<body>${compressTextScripts}`);
|
|
1491
|
+
}
|
|
1492
|
+
inlineScriptsAndStyles(htmlFilePath) {
|
|
1493
|
+
function resolveFilePath(basePath, filePath) {
|
|
1494
|
+
return filePath.startsWith('/') ? path_0.resolve(basePath, filePath.slice(1)) : path_0.resolve(basePath, filePath);
|
|
1495
|
+
}
|
|
1496
|
+
let htmlContent = node_fs.readFileSync(htmlFilePath, 'utf-8'), basePath = path_0.dirname(htmlFilePath), scriptSrcs = Array.from(htmlContent.matchAll(/<script\s+(?:defer="defer"|defer)\s+src=["'](.+?)["']><\/script>/g), (m)=>m[1]), cssHrefs = Array.from(htmlContent.matchAll(/<link\s+href=["'](.+?)["']\s+rel="stylesheet">/g), (m)=>m[1]);
|
|
1497
|
+
htmlContent = (htmlContent = htmlContent.replace(/<script\s+.*?src=["'].*?["']><\/script>/g, '')).replace(/<link\s+.*?rel=["']stylesheet["'].*?>/g, '');
|
|
1498
|
+
let inlinedScripts = scriptSrcs.map((src)=>{
|
|
1499
|
+
let scriptPath = resolveFilePath(basePath, src);
|
|
1500
|
+
try {
|
|
1501
|
+
let scriptContent = node_fs.readFileSync(scriptPath, 'utf-8');
|
|
1502
|
+
return `<script>${scriptContent}</script>`;
|
|
1503
|
+
} catch (error) {
|
|
1504
|
+
return console.error(`Could not read script at ${scriptPath}:`, error), '';
|
|
1505
|
+
}
|
|
1506
|
+
}).join(''), inlinedCss = cssHrefs.map((href)=>{
|
|
1507
|
+
let cssPath = resolveFilePath(basePath, href);
|
|
1508
|
+
try {
|
|
1509
|
+
let cssContent = node_fs.readFileSync(cssPath, 'utf-8');
|
|
1510
|
+
return `<style>${cssContent}</style>`;
|
|
1511
|
+
} catch (error) {
|
|
1512
|
+
return console.error(`Could not read CSS at ${cssPath}:`, error), '';
|
|
1513
|
+
}
|
|
1514
|
+
}).join(''), index = htmlContent.indexOf('</body>');
|
|
1515
|
+
htmlContent = htmlContent.slice(0, index) + inlinedCss + inlinedScripts + htmlContent.slice(index), htmlContent = this.addRsdoctorDataToHTML(this.getStoreData(), htmlContent);
|
|
1516
|
+
let outputFilePath = path_0.resolve(this.outputDir, this.extraConfig?.brief?.htmlOptions?.reportHtmlName || 'rsdoctor-report.html');
|
|
1517
|
+
return node_fs.mkdirSync(path_0.dirname(outputFilePath), {
|
|
1518
|
+
recursive: !0
|
|
1519
|
+
}), node_fs.writeFileSync(outputFilePath, htmlContent, {
|
|
1520
|
+
encoding: 'utf-8',
|
|
1521
|
+
flag: 'w'
|
|
1522
|
+
}), outputFilePath;
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
class RsdoctorSlaveServer extends RsdoctorServer {
|
|
1526
|
+
constructor(sdk, port = defaultPort, config){
|
|
1527
|
+
super(sdk, port, config), this.sdk = sdk;
|
|
1528
|
+
}
|
|
1529
|
+
async openClientPage(...args) {
|
|
1530
|
+
return this.sdk.isMaster ? super.openClientPage(...args) : Promise.resolve();
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
let primary_id = 1;
|
|
1534
|
+
class RsdoctorPrimarySDK extends RsdoctorSDK {
|
|
1535
|
+
constructor({ name, stage, controller, extraConfig, type }){
|
|
1536
|
+
super({
|
|
1537
|
+
name,
|
|
1538
|
+
root: controller.root,
|
|
1539
|
+
config: extraConfig
|
|
1540
|
+
});
|
|
1541
|
+
let lastSdk = controller.getLastSdk(), port = lastSdk ? lastSdk.server.port + 1 : extraConfig?.server?.port ?? this.server.port;
|
|
1542
|
+
this.id = primary_id++, this.stage = 'number' == typeof stage ? stage : 1, this.extraConfig = extraConfig, this.parent = controller, this.server = new RsdoctorSlaveServer(this, port, {
|
|
1543
|
+
cors: extraConfig?.server?.cors
|
|
1544
|
+
}), this.type = type, this.setName(name), this.clearSwitch();
|
|
1545
|
+
}
|
|
1546
|
+
clearSwitch() {
|
|
1547
|
+
this.uploadPieces = new Promise((resolve)=>{
|
|
1548
|
+
this.finishUploadPieceSwitch = resolve;
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
get isMaster() {
|
|
1552
|
+
return this.parent.master === this;
|
|
1553
|
+
}
|
|
1554
|
+
async writePieces() {
|
|
1555
|
+
let { name, parent, isMaster, outputDir, finishUploadPieceSwitch } = this;
|
|
1556
|
+
this.setOutputDir(isMaster ? outputDir : path_0.join(parent.master.outputDir, '.slaves', name.replace(/\s+/g, '-'))), await super.writePieces(this.getStoreData()), finishUploadPieceSwitch?.();
|
|
1557
|
+
}
|
|
1558
|
+
async writeManifest() {
|
|
1559
|
+
let { parent, cloudData, dependencies } = this;
|
|
1560
|
+
dependencies?.length || await Promise.all(this.parent.slaves.filter((item)=>!item.dependencies?.length).map((item)=>item.uploadPieces)), cloudData && (cloudData.name = this.name, cloudData.series = parent.getSeriesData());
|
|
1561
|
+
let result = await super.writeManifest();
|
|
1562
|
+
return this.clearSwitch(), result;
|
|
1563
|
+
}
|
|
1564
|
+
getSeriesData(serverUrl = !1) {
|
|
1565
|
+
return this.parent.getSeriesData(serverUrl);
|
|
1566
|
+
}
|
|
1567
|
+
setName(name) {
|
|
1568
|
+
this._name = this.parent.hasName(name) ? `${name}-${primary_id}` : name;
|
|
1569
|
+
}
|
|
1570
|
+
getManifestData() {
|
|
1571
|
+
let data = super.getManifestData();
|
|
1572
|
+
return data.name = this.name, data.series = this.getSeriesData(!0), data;
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
class RsdoctorSDKController {
|
|
1576
|
+
constructor(root = process.cwd()){
|
|
1577
|
+
this.slaves = [], this.root = '', this.root = root;
|
|
1578
|
+
}
|
|
1579
|
+
get master() {
|
|
1580
|
+
return this.slaves[0];
|
|
1581
|
+
}
|
|
1582
|
+
getLastSdk() {
|
|
1583
|
+
return this.slaves[this.slaves.length - 1];
|
|
1584
|
+
}
|
|
1585
|
+
hasName(name) {
|
|
1586
|
+
return !!this.slaves.find((item)=>item.name === name);
|
|
1587
|
+
}
|
|
1588
|
+
getSeriesData(serverUrl = !1) {
|
|
1589
|
+
return this.slaves.map((item)=>{
|
|
1590
|
+
let data = {
|
|
1591
|
+
name: item.name,
|
|
1592
|
+
path: item.diskManifestPath,
|
|
1593
|
+
stage: item.stage
|
|
1594
|
+
};
|
|
1595
|
+
return serverUrl && (data.origin = item.server.origin), data;
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
createSlave({ name, stage, extraConfig, type }) {
|
|
1599
|
+
let slave = new RsdoctorPrimarySDK({
|
|
1600
|
+
name,
|
|
1601
|
+
stage,
|
|
1602
|
+
controller: this,
|
|
1603
|
+
extraConfig,
|
|
1604
|
+
type
|
|
1605
|
+
});
|
|
1606
|
+
return this.slaves.push(slave), this.slaves.sort((a, b)=>a.stage - b.stage), slave;
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
let packageJson = external_node_module_createRequire(import.meta.url)(existsSync(new URL('../package.json', import.meta.url)) ? '../package.json' : '../../package.json'), pluginTapName = 'RsdoctorRspackPlugin', pluginTapPostOptions = {
|
|
1610
|
+
name: pluginTapName,
|
|
1611
|
+
stage: 999
|
|
1612
|
+
}, hasGreeted = !1;
|
|
1613
|
+
class RsdoctorRspackPlugin {
|
|
1614
|
+
constructor(options){
|
|
1615
|
+
this.name = pluginTapName, this.browserIsOpened = !1, this.afterPlugins = (compiler)=>{
|
|
1616
|
+
logger_time('RsdoctorRspackPlugin.afterPlugins');
|
|
1617
|
+
try {
|
|
1618
|
+
this.getRspackConfig(compiler);
|
|
1619
|
+
} finally{
|
|
1620
|
+
timeEnd('RsdoctorRspackPlugin.afterPlugins');
|
|
1621
|
+
}
|
|
1622
|
+
}, this.done = async (compiler)=>{
|
|
1623
|
+
logger_time('RsdoctorRspackPlugin.done');
|
|
1624
|
+
try {
|
|
1625
|
+
rsdoctorLogger.debug('[RsdoctorRspackPlugin] bootstrap(start) in done()'), await this.sdk.bootstrap(), rsdoctorLogger.debug('[RsdoctorRspackPlugin] bootstrap(end) in done()'), this.sdk.addClientRoutes([
|
|
1626
|
+
Manifest.RsdoctorManifestClientRoutes.Overall
|
|
1627
|
+
]), this.outsideInstance && 'parent' in this.sdk && this.sdk.parent.master.setOutputDir(path_0.resolve(this.options.output.reportDir || compiler.outputPath, this.options.output.mode === SDK.IMode[SDK.IMode.brief] ? '' : `./${Constants.RsdoctorOutputFolder}`)), this.sdk.setOutputDir(path_0.resolve(this.options.output.reportDir || compiler.outputPath, this.options.output.mode === SDK.IMode[SDK.IMode.brief] ? '' : `./${Constants.RsdoctorOutputFolder}`)), await this.sdk.writeStore(), this.options.disableClientServer || (this.options.output.mode === SDK.IMode[SDK.IMode.brief] ? await handleBriefModeReport(this.sdk, this.options, this.options.disableClientServer) : await this.sdk.server.openClientPage('homepage')), (this.options.disableClientServer || this.options.output.mode === SDK.IMode[SDK.IMode.brief] && Array.isArray(this.options.output.options?.type) && 1 === this.options.output.options.type.length && 'json' === this.options.output.options.type[0]) && await this.sdk.dispose();
|
|
1628
|
+
} finally{
|
|
1629
|
+
timeEnd('RsdoctorRspackPlugin.done');
|
|
1630
|
+
}
|
|
1631
|
+
}, this.options = normalizeRspackUserOptions(Object.assign(options || {}, {
|
|
1632
|
+
supports: {
|
|
1633
|
+
...options?.supports
|
|
1634
|
+
}
|
|
1635
|
+
}));
|
|
1636
|
+
let { port, server, output, innerClientPath, printLog, sdkInstance } = this.options;
|
|
1637
|
+
this.sdk = this.options.sdkInstance ?? new RsdoctorSDK({
|
|
1638
|
+
port,
|
|
1639
|
+
name: pluginTapName,
|
|
1640
|
+
root: process.cwd(),
|
|
1641
|
+
type: output.reportCodeType,
|
|
1642
|
+
config: {
|
|
1643
|
+
innerClientPath,
|
|
1644
|
+
printLog,
|
|
1645
|
+
server,
|
|
1646
|
+
mode: output.mode ? output.mode : void 0,
|
|
1647
|
+
brief: output.mode === SDK.IMode[SDK.IMode.brief] && output.options || void 0,
|
|
1648
|
+
features: {
|
|
1649
|
+
treeShaking: this.options.features.treeShaking
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
}), this.outsideInstance = !!sdkInstance, this.modulesGraph = new ModuleGraph(), this.isRsdoctorPlugin = !0;
|
|
1653
|
+
}
|
|
1654
|
+
apply(compiler) {
|
|
1655
|
+
logger_time('RsdoctorRspackPlugin.apply');
|
|
1656
|
+
try {
|
|
1657
|
+
hasGreeted || compiler.isChild() || (hasGreeted = !0, rsdoctorLogger.greet(`
|
|
1658
|
+
\nRsdoctor v${packageJson.version}\n`)), this._bootstrapTask || (this._bootstrapTask = this.sdk.bootstrap()), compiler.options.name && this.sdk.setName(compiler.options.name), setSDK(this.sdk), compiler.hooks.afterPlugins.tap(pluginTapPostOptions, this.afterPlugins.bind(this, compiler)), compiler.hooks.done.tapPromise({
|
|
1659
|
+
...pluginTapPostOptions,
|
|
1660
|
+
stage: pluginTapPostOptions.stage + 100
|
|
1661
|
+
}, this.done.bind(this, compiler)), new InternalSummaryPlugin(this).apply(compiler), this.options.features.loader && (new ProbeLoaderPlugin().apply(compiler), this.sdk.addClientRoutes([
|
|
1662
|
+
Manifest.RsdoctorManifestClientRoutes.Loaders
|
|
1663
|
+
]), Loader.isVue(compiler) || new InternalLoaderPlugin(this).apply(compiler)), this.options.features.plugins && new InternalPluginsPlugin(this).apply(compiler), this.options.features.bundle && new InternalBundlePlugin(this).apply(compiler), this.options.features.resolver && new InternalResolverPlugin(this).apply(compiler), new InternalRulesPlugin(this).apply(compiler), new InternalErrorReporterPlugin(this).apply(compiler);
|
|
1664
|
+
let RsdoctorRspackNativePlugin = getRspackNativePlugin(compiler);
|
|
1665
|
+
rsdoctorLogger.debug('[RspackNativePlugin] Enabled'), new RsdoctorRspackNativePlugin({
|
|
1666
|
+
moduleGraphFeatures: !0,
|
|
1667
|
+
chunkGraphFeatures: !0,
|
|
1668
|
+
sourceMapFeatures: {
|
|
1669
|
+
cheap: !1,
|
|
1670
|
+
module: !1
|
|
1671
|
+
}
|
|
1672
|
+
}).apply(compiler);
|
|
1673
|
+
} finally{
|
|
1674
|
+
timeEnd('RsdoctorRspackPlugin.apply');
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
ensureModulesChunksGraphApplied(compiler) {
|
|
1678
|
+
ensureModulesChunksGraphFn(compiler, this);
|
|
1679
|
+
}
|
|
1680
|
+
getRspackConfig(compiler) {
|
|
1681
|
+
logger_time('RsdoctorRspackPlugin.getRspackConfig');
|
|
1682
|
+
try {
|
|
1683
|
+
if (compiler.isChild()) return;
|
|
1684
|
+
let configuration = processCompilerConfig(compiler.options), { rspackVersion } = compiler.rspack;
|
|
1685
|
+
this.sdk.reportConfiguration({
|
|
1686
|
+
name: 'rspack',
|
|
1687
|
+
version: rspackVersion || 'unknown',
|
|
1688
|
+
config: configuration,
|
|
1689
|
+
root: findRoot() || ''
|
|
1690
|
+
});
|
|
1691
|
+
} finally{
|
|
1692
|
+
timeEnd('RsdoctorRspackPlugin.getRspackConfig');
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
class RsdoctorRspackMultiplePlugin extends RsdoctorRspackPlugin {
|
|
1697
|
+
constructor(options = {}){
|
|
1698
|
+
let controller = (()=>{
|
|
1699
|
+
if (globalController) return globalController;
|
|
1700
|
+
let controller = new RsdoctorSDKController();
|
|
1701
|
+
return globalController = controller, controller;
|
|
1702
|
+
})(), normallizedOptions = normalizeUserConfig(options), instance = controller.createSlave({
|
|
1703
|
+
name: options.name || 'Builder',
|
|
1704
|
+
stage: options.stage,
|
|
1705
|
+
extraConfig: {
|
|
1706
|
+
innerClientPath: normallizedOptions.innerClientPath,
|
|
1707
|
+
printLog: normallizedOptions.printLog,
|
|
1708
|
+
server: normallizedOptions.server,
|
|
1709
|
+
mode: normallizedOptions.output.mode ? normallizedOptions.output.mode : void 0,
|
|
1710
|
+
brief: normallizedOptions.output.mode === SDK.IMode[SDK.IMode.brief] && normallizedOptions.output.options || void 0
|
|
1711
|
+
},
|
|
1712
|
+
type: normallizedOptions.output.reportCodeType
|
|
1713
|
+
});
|
|
1714
|
+
super({
|
|
1715
|
+
...options,
|
|
1716
|
+
sdkInstance: instance
|
|
1717
|
+
}), this.controller = controller;
|
|
1718
|
+
}
|
|
1719
|
+
apply(compiler) {
|
|
1720
|
+
'dependencies' in compiler.options && (this.sdk.dependencies = compiler.options.dependencies), super.apply(compiler);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
export { Linter, LinterRule, LinterType, defineRule, rules } from "./26.js";
|
|
1724
|
+
export { logger } from "./630.js";
|
|
1725
|
+
export { RsdoctorRspackMultiplePlugin, RsdoctorRspackPlugin, RsdoctorSDK, resolveClientDiffHtmlPath };
|