@rsdoctor/sdk 0.4.8 → 0.4.10
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/cjs/sdk/multiple/controller.js +1 -1
- package/dist/cjs/sdk/multiple/slave.js +3 -3
- package/dist/cjs/sdk/sdk/core.js +4 -0
- package/dist/cjs/sdk/sdk/index.js +479 -4
- package/dist/esm/sdk/multiple/controller.js +2 -2
- package/dist/esm/sdk/multiple/slave.js +3 -3
- package/dist/esm/sdk/sdk/core.js +4 -0
- package/dist/esm/sdk/sdk/index.js +468 -3
- package/dist/type/sdk/multiple/controller.d.ts +5 -5
- package/dist/type/sdk/multiple/controller.d.ts.map +1 -1
- package/dist/type/sdk/multiple/server.d.ts +3 -3
- package/dist/type/sdk/multiple/server.d.ts.map +1 -1
- package/dist/type/sdk/multiple/slave.d.ts +2 -2
- package/dist/type/sdk/multiple/slave.d.ts.map +1 -1
- package/dist/type/sdk/sdk/core.d.ts.map +1 -1
- package/dist/type/sdk/sdk/index.d.ts +52 -2
- package/dist/type/sdk/sdk/index.d.ts.map +1 -1
- package/package.json +7 -6
- package/dist/cjs/sdk/sdk/webpack.js +0 -502
- package/dist/esm/sdk/sdk/webpack.js +0 -466
- package/dist/type/sdk/sdk/webpack.d.ts +0 -53
- package/dist/type/sdk/sdk/webpack.d.ts.map +0 -1
|
@@ -28,14 +28,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var slave_exports = {};
|
|
30
30
|
__export(slave_exports, {
|
|
31
|
-
|
|
31
|
+
RsdoctorPrimarySDK: () => RsdoctorPrimarySDK
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(slave_exports);
|
|
34
34
|
var import_path = __toESM(require("path"));
|
|
35
35
|
var import_sdk = require("../sdk");
|
|
36
36
|
var import_server = require("./server");
|
|
37
37
|
let id = 1;
|
|
38
|
-
class
|
|
38
|
+
class RsdoctorPrimarySDK extends import_sdk.RsdoctorSDK {
|
|
39
39
|
constructor({
|
|
40
40
|
name,
|
|
41
41
|
stage,
|
|
@@ -99,5 +99,5 @@ class RsdoctorSlaveSDK extends import_sdk.RsdoctorWebpackSDK {
|
|
|
99
99
|
}
|
|
100
100
|
// Annotate the CommonJS export names for ESM import in node:
|
|
101
101
|
0 && (module.exports = {
|
|
102
|
-
|
|
102
|
+
RsdoctorPrimarySDK
|
|
103
103
|
});
|
package/dist/cjs/sdk/sdk/core.js
CHANGED
|
@@ -40,6 +40,7 @@ var import_process = __toESM(require("process"));
|
|
|
40
40
|
var import_tapable = require("tapable");
|
|
41
41
|
var import_logger = require("@rsdoctor/utils/logger");
|
|
42
42
|
var import_utils = require("../utils");
|
|
43
|
+
const jc = require("json-cycle");
|
|
43
44
|
class SDKCore {
|
|
44
45
|
constructor({ name, root }) {
|
|
45
46
|
this.hooks = {
|
|
@@ -130,6 +131,9 @@ class SDKCore {
|
|
|
130
131
|
}
|
|
131
132
|
const jsonStr = await (async () => {
|
|
132
133
|
try {
|
|
134
|
+
if (key === "configs") {
|
|
135
|
+
return JSON.stringify(jc.decycle(data));
|
|
136
|
+
}
|
|
133
137
|
return JSON.stringify(data);
|
|
134
138
|
} catch (error) {
|
|
135
139
|
return import_build.Json.stringify(data);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -16,16 +18,489 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
18
20
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
19
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
30
|
var sdk_exports = {};
|
|
21
31
|
__export(sdk_exports, {
|
|
22
|
-
RsdoctorSDK: () =>
|
|
32
|
+
RsdoctorSDK: () => RsdoctorSDK
|
|
23
33
|
});
|
|
24
34
|
module.exports = __toCommonJS(sdk_exports);
|
|
25
|
-
|
|
26
|
-
var
|
|
35
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_error = require("@rsdoctor/utils/error");
|
|
38
|
+
var import_types = require("@rsdoctor/types");
|
|
39
|
+
var import_build = require("@rsdoctor/utils/build");
|
|
40
|
+
var import_source_map = require("source-map");
|
|
41
|
+
var import_graph = require("@rsdoctor/graph");
|
|
42
|
+
var import_logger = require("@rsdoctor/utils/logger");
|
|
43
|
+
var import_server = require("../server");
|
|
44
|
+
var import_fakeServer = require("../server/fakeServer");
|
|
45
|
+
var import_core = require("./core");
|
|
46
|
+
var import_common = require("@rsdoctor/utils/common");
|
|
47
|
+
var import_lodash = require("lodash");
|
|
48
|
+
__reExport(sdk_exports, require("../utils/openBrowser"), module.exports);
|
|
49
|
+
const jc = require("json-cycle");
|
|
50
|
+
class RsdoctorSDK extends import_core.SDKCore {
|
|
51
|
+
constructor(options) {
|
|
52
|
+
super(options);
|
|
53
|
+
this._summary = { costs: [] };
|
|
54
|
+
this._configs = [];
|
|
55
|
+
this._errors = [];
|
|
56
|
+
this._loader = [];
|
|
57
|
+
this._loaderStart = [];
|
|
58
|
+
this._resolver = [];
|
|
59
|
+
this._plugin = {};
|
|
60
|
+
this._moduleGraph = new import_graph.ModuleGraph();
|
|
61
|
+
this._chunkGraph = new import_graph.ChunkGraph();
|
|
62
|
+
this._rawSourceMapCache = /* @__PURE__ */ new Map();
|
|
63
|
+
this._sourceMap = /* @__PURE__ */ new Map();
|
|
64
|
+
this.server = options.config?.noServer ? new import_fakeServer.RsdoctorFakeServer(this, void 0) : new import_server.RsdoctorServer(this, options.port, {
|
|
65
|
+
innerClientPath: options.config?.innerClientPath || "",
|
|
66
|
+
printServerUrl: options.config?.printLog?.serverUrls
|
|
67
|
+
});
|
|
68
|
+
this.type = (0, import_lodash.isNumber)(options.type) ? options.type : import_types.SDK.ToDataType.Normal;
|
|
69
|
+
this.extraConfig = options.config;
|
|
70
|
+
}
|
|
71
|
+
async bootstrap() {
|
|
72
|
+
(0, import_logger.debug)(() => `${Date.now()}`, "[RsdoctorSDK][bootstrap start]");
|
|
73
|
+
this.server && await this.server.bootstrap();
|
|
74
|
+
await super.bootstrap();
|
|
75
|
+
(0, import_logger.debug)(
|
|
76
|
+
() => `${Date.now()} ${this.server.origin}`,
|
|
77
|
+
"[RsdoctorSDK][bootstrap end]"
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
async dispose() {
|
|
81
|
+
(0, import_logger.debug)(() => `${Date.now()}`, "[RsdoctorSDK][dispose start]");
|
|
82
|
+
this.server && await this.server.dispose();
|
|
83
|
+
await super.dispose();
|
|
84
|
+
(0, import_logger.debug)(() => `${Date.now()}`, "[RsdoctorSDK][dispose end]");
|
|
85
|
+
}
|
|
86
|
+
async applyErrorFix(id) {
|
|
87
|
+
const { _errors: errors } = this;
|
|
88
|
+
const error = errors.find((err) => err.id === id);
|
|
89
|
+
if (!error || !error.path || !error.fixData || error.fixData.isFixed) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const { path: filePath, fixData } = error;
|
|
93
|
+
const sameFileErrors = errors.filter(
|
|
94
|
+
(item) => item.path === filePath && item !== error
|
|
95
|
+
);
|
|
96
|
+
let content = (await import_build.File.fse.readFile(filePath, "utf-8")).toString();
|
|
97
|
+
const startTxt = content.substring(0, fixData.start);
|
|
98
|
+
const endTxt = content.substring(fixData.end, content.length);
|
|
99
|
+
const offset = (fixData.newText ?? "").length - (fixData.end - fixData.start);
|
|
100
|
+
content = startTxt + fixData.newText + endTxt;
|
|
101
|
+
for (const other of sameFileErrors) {
|
|
102
|
+
const { fixData: otherFixData } = other;
|
|
103
|
+
if (!otherFixData) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (otherFixData.start >= fixData.end) {
|
|
107
|
+
otherFixData.start += offset;
|
|
108
|
+
otherFixData.end += offset;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
await import_build.File.fse.writeFile(filePath, content);
|
|
112
|
+
}
|
|
113
|
+
clear() {
|
|
114
|
+
this._errors = [];
|
|
115
|
+
this._loader = [];
|
|
116
|
+
this._resolver = [];
|
|
117
|
+
this._plugin = {};
|
|
118
|
+
this._moduleGraph = new import_graph.ModuleGraph();
|
|
119
|
+
this._chunkGraph = new import_graph.ChunkGraph();
|
|
120
|
+
}
|
|
121
|
+
clearSourceMapCache() {
|
|
122
|
+
this._rawSourceMapCache = /* @__PURE__ */ new Map();
|
|
123
|
+
this._sourceMap = /* @__PURE__ */ new Map();
|
|
124
|
+
}
|
|
125
|
+
async getSourceMap(file) {
|
|
126
|
+
const { _sourceMap: sourceMap, _rawSourceMapCache: rawMap } = this;
|
|
127
|
+
if (sourceMap.has(file)) {
|
|
128
|
+
return sourceMap.get(file);
|
|
129
|
+
}
|
|
130
|
+
const rawData = rawMap.get(file);
|
|
131
|
+
if (!rawData || rawData.version < 0 || !rawData.sourcesContent?.[0] || !rawData.mappings) {
|
|
132
|
+
return Promise.resolve(void 0);
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const result = await new import_source_map.SourceMapConsumer(rawData);
|
|
136
|
+
sourceMap.set(file, result);
|
|
137
|
+
return result;
|
|
138
|
+
} catch (e) {
|
|
139
|
+
return Promise.resolve(void 0);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
reportSourceMap(data) {
|
|
143
|
+
this._rawSourceMapCache.set(data.file, data);
|
|
144
|
+
}
|
|
145
|
+
reportConfiguration(config) {
|
|
146
|
+
this._configs.push(config);
|
|
147
|
+
this.onDataReport();
|
|
148
|
+
}
|
|
149
|
+
reportError(errors) {
|
|
150
|
+
errors.forEach((item) => {
|
|
151
|
+
this._errors.push(
|
|
152
|
+
import_error.DevToolError.from(item, {
|
|
153
|
+
code: this.name
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
this.onDataReport();
|
|
158
|
+
}
|
|
159
|
+
reportLoader(data) {
|
|
160
|
+
data.forEach((item) => {
|
|
161
|
+
if (this.extraConfig?.mode === import_types.SDK.IMode[import_types.SDK.IMode.brief]) {
|
|
162
|
+
item.loaders.forEach((_loader) => {
|
|
163
|
+
_loader.input = "";
|
|
164
|
+
_loader.result = "";
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
let match = this._loader.find(
|
|
168
|
+
(e) => e.resource.path === item.resource.path
|
|
169
|
+
);
|
|
170
|
+
if (match) {
|
|
171
|
+
match.loaders.push(...item.loaders);
|
|
172
|
+
} else {
|
|
173
|
+
match = item;
|
|
174
|
+
this._loader.push(item);
|
|
175
|
+
}
|
|
176
|
+
match.loaders.sort((a, b) => {
|
|
177
|
+
if (a.startAt !== b.startAt) {
|
|
178
|
+
return a.startAt - b.startAt;
|
|
179
|
+
}
|
|
180
|
+
if (a.isPitch) {
|
|
181
|
+
if (b.isPitch) {
|
|
182
|
+
return a.loaderIndex - b.loaderIndex;
|
|
183
|
+
}
|
|
184
|
+
return -1;
|
|
185
|
+
}
|
|
186
|
+
if (b.isPitch) {
|
|
187
|
+
return 1;
|
|
188
|
+
}
|
|
189
|
+
return b.loaderIndex - a.loaderIndex;
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
this.onDataReport();
|
|
193
|
+
}
|
|
194
|
+
reportLoaderStartOrEnd(data) {
|
|
195
|
+
const _builtinLoader = data.loaders[0];
|
|
196
|
+
if (_builtinLoader.startAt) {
|
|
197
|
+
this._loaderStart.push(data);
|
|
198
|
+
} else if (_builtinLoader.endAt) {
|
|
199
|
+
const matchLoaderStart = this._loaderStart.find(
|
|
200
|
+
(e) => e.resource.path === data.resource.path && e.loaders[0].loader === _builtinLoader.loader
|
|
201
|
+
);
|
|
202
|
+
if (matchLoaderStart) {
|
|
203
|
+
matchLoaderStart.loaders[0].result = _builtinLoader.result;
|
|
204
|
+
matchLoaderStart.loaders[0].endAt = _builtinLoader.endAt;
|
|
205
|
+
this.reportLoader([matchLoaderStart]);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
reportResolver(data) {
|
|
210
|
+
data.forEach((item) => this._resolver.push(item));
|
|
211
|
+
this.onDataReport();
|
|
212
|
+
}
|
|
213
|
+
reportPlugin(data) {
|
|
214
|
+
Object.keys(data).forEach((hook) => {
|
|
215
|
+
if (!this._plugin[hook]) {
|
|
216
|
+
this._plugin[hook] = data[hook];
|
|
217
|
+
} else {
|
|
218
|
+
data[hook].forEach((item) => {
|
|
219
|
+
this._plugin[hook].push(item);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
this.onDataReport();
|
|
224
|
+
}
|
|
225
|
+
reportModuleGraph(data) {
|
|
226
|
+
(0, import_logger.debug)(() => `data size: ${data.size()}`, "[SDK.reportModuleGraph][start]");
|
|
227
|
+
this._moduleGraph.fromInstance(data);
|
|
228
|
+
this.createPackageGraph();
|
|
229
|
+
this.onDataReport();
|
|
230
|
+
(0, import_logger.debug)(
|
|
231
|
+
() => `sdk._moduleGraph size: ${this._moduleGraph.size()}`,
|
|
232
|
+
"[SDK reportModuleGraph][end]"
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
reportPackageGraph(data) {
|
|
236
|
+
(0, import_logger.debug)(() => "[SDK.reportPackageGraph][start]");
|
|
237
|
+
if (!this._packageGraph) {
|
|
238
|
+
this._packageGraph = data;
|
|
239
|
+
}
|
|
240
|
+
this.onDataReport();
|
|
241
|
+
(0, import_logger.debug)(
|
|
242
|
+
() => `sdk._moduleGraph size: ${this._moduleGraph.size()}`,
|
|
243
|
+
"[SDK reportPackageGraph][end]"
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
reportChunkGraph(data) {
|
|
247
|
+
this._chunkGraph.addAsset(...data.getAssets());
|
|
248
|
+
this._chunkGraph.addChunk(...data.getChunks());
|
|
249
|
+
this._chunkGraph.addEntryPoint(...data.getEntryPoints());
|
|
250
|
+
this.onDataReport();
|
|
251
|
+
}
|
|
252
|
+
reportSummaryData(part) {
|
|
253
|
+
const keys = ["costs"];
|
|
254
|
+
for (const key of keys) {
|
|
255
|
+
const v = part[key];
|
|
256
|
+
if (!v)
|
|
257
|
+
continue;
|
|
258
|
+
if (typeof v === "object") {
|
|
259
|
+
if (Array.isArray(v)) {
|
|
260
|
+
this._summary[key] = [
|
|
261
|
+
...this._summary[key] || [],
|
|
262
|
+
...v
|
|
263
|
+
];
|
|
264
|
+
} else {
|
|
265
|
+
this._summary[key] = {
|
|
266
|
+
...this._summary[key] || {},
|
|
267
|
+
...v
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
} else {
|
|
271
|
+
this._summary[key] = v;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
this.onDataReport();
|
|
275
|
+
}
|
|
276
|
+
reportTileHtml(tileReportHtml) {
|
|
277
|
+
this._tileReportHtml = tileReportHtml;
|
|
278
|
+
}
|
|
279
|
+
createPackageGraph() {
|
|
280
|
+
(0, import_logger.debug)(
|
|
281
|
+
() => `sdk._moduleGraph size: ${this._moduleGraph.size()}`,
|
|
282
|
+
"[SDK.createPackageGraph][start]"
|
|
283
|
+
);
|
|
284
|
+
if (!this._packageGraph) {
|
|
285
|
+
const pkgGraph = import_graph.PackageGraph.fromModuleGraph(
|
|
286
|
+
this._moduleGraph,
|
|
287
|
+
this.root,
|
|
288
|
+
(path2) => {
|
|
289
|
+
try {
|
|
290
|
+
const exists = import_build.File.fse.existsSync(path2);
|
|
291
|
+
if (exists) {
|
|
292
|
+
(0, import_logger.debug)(
|
|
293
|
+
() => `sdk.PackageGraph package.json exists: ${exists}, path: ${path2}`,
|
|
294
|
+
"[SDK.createPackageGraph][load]"
|
|
295
|
+
);
|
|
296
|
+
return import_build.File.fse.readJSONSync(path2);
|
|
297
|
+
}
|
|
298
|
+
} catch (error) {
|
|
299
|
+
const { message, stack } = error;
|
|
300
|
+
(0, import_logger.debug)(
|
|
301
|
+
() => `sdk.createPackageGraph error, path: ${path2}, error message: ${stack || message}`,
|
|
302
|
+
"[SDK.createPackageGraph][error]"
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
);
|
|
307
|
+
this._packageGraph = pkgGraph;
|
|
308
|
+
(0, import_logger.debug)(
|
|
309
|
+
() => `sdk._packageGraph packages: ${this._packageGraph.getPackages().length}`,
|
|
310
|
+
"[SDK.createPackageGraph][end]"
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
async writeStore(options) {
|
|
315
|
+
(0, import_logger.debug)(() => `sdk.writeStore has run.`, "[SDK.writeStore][end]");
|
|
316
|
+
if (this.extraConfig?.mode === import_types.SDK.IMode[import_types.SDK.IMode.brief]) {
|
|
317
|
+
const clientHtmlPath = this.extraConfig.innerClientPath ? this.extraConfig.innerClientPath : require.resolve("@rsdoctor/client");
|
|
318
|
+
if (this.extraConfig.brief?.writeDataJson) {
|
|
319
|
+
await this.saveManifest(this.getStoreData(), options || {});
|
|
320
|
+
}
|
|
321
|
+
return this.inlineScriptsAndStyles(clientHtmlPath);
|
|
322
|
+
}
|
|
323
|
+
return this.saveManifest(this.getStoreData(), options || {});
|
|
324
|
+
}
|
|
325
|
+
getStoreData() {
|
|
326
|
+
const ctx = this;
|
|
327
|
+
return {
|
|
328
|
+
get hash() {
|
|
329
|
+
return ctx.hash;
|
|
330
|
+
},
|
|
331
|
+
get root() {
|
|
332
|
+
return ctx.root;
|
|
333
|
+
},
|
|
334
|
+
get envinfo() {
|
|
335
|
+
return ctx._envinfo;
|
|
336
|
+
},
|
|
337
|
+
get pid() {
|
|
338
|
+
return ctx.pid;
|
|
339
|
+
},
|
|
340
|
+
get errors() {
|
|
341
|
+
return ctx._errors.map((err) => err.toData());
|
|
342
|
+
},
|
|
343
|
+
get configs() {
|
|
344
|
+
return ctx._configs.slice();
|
|
345
|
+
},
|
|
346
|
+
get summary() {
|
|
347
|
+
return { ...ctx._summary };
|
|
348
|
+
},
|
|
349
|
+
get resolver() {
|
|
350
|
+
return ctx._resolver.slice();
|
|
351
|
+
},
|
|
352
|
+
get loader() {
|
|
353
|
+
return ctx._loader.slice();
|
|
354
|
+
},
|
|
355
|
+
get moduleGraph() {
|
|
356
|
+
return ctx._moduleGraph.toData({
|
|
357
|
+
contextPath: ctx._configs?.[0]?.config?.context || ""
|
|
358
|
+
});
|
|
359
|
+
},
|
|
360
|
+
get chunkGraph() {
|
|
361
|
+
return ctx._chunkGraph.toData(ctx.type);
|
|
362
|
+
},
|
|
363
|
+
get moduleCodeMap() {
|
|
364
|
+
return ctx._moduleGraph.toCodeData(ctx.type);
|
|
365
|
+
},
|
|
366
|
+
get plugin() {
|
|
367
|
+
return { ...ctx._plugin };
|
|
368
|
+
},
|
|
369
|
+
get packageGraph() {
|
|
370
|
+
return ctx._packageGraph ? ctx._packageGraph.toData() : {
|
|
371
|
+
packages: [],
|
|
372
|
+
dependencies: []
|
|
373
|
+
};
|
|
374
|
+
},
|
|
375
|
+
get otherReports() {
|
|
376
|
+
return { tileReportHtml: ctx._tileReportHtml || "" };
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
getManifestData() {
|
|
381
|
+
const dataValue = this.getStoreData();
|
|
382
|
+
const data = {
|
|
383
|
+
client: {
|
|
384
|
+
enableRoutes: this.getClientRoutes()
|
|
385
|
+
},
|
|
386
|
+
data: Object.keys(dataValue).reduce((t, e) => {
|
|
387
|
+
const _e = e;
|
|
388
|
+
if (dataValue[_e] && typeof dataValue[_e] === "object") {
|
|
389
|
+
t[e] = [
|
|
390
|
+
`${this.server.origin}${import_types.SDK.ServerAPI.API.LoadDataByKey}/${e}`
|
|
391
|
+
];
|
|
392
|
+
} else {
|
|
393
|
+
t[e] = dataValue[_e];
|
|
394
|
+
}
|
|
395
|
+
return t;
|
|
396
|
+
}, {}),
|
|
397
|
+
__LOCAL__SERVER__: true,
|
|
398
|
+
__SOCKET__PORT__: this.server.socketUrl.port.toString(),
|
|
399
|
+
__SOCKET__URL__: this.server.socketUrl.socketUrl
|
|
400
|
+
};
|
|
401
|
+
return data;
|
|
402
|
+
}
|
|
403
|
+
getRuleContext(_options) {
|
|
404
|
+
this.createPackageGraph();
|
|
405
|
+
return {
|
|
406
|
+
root: this.root,
|
|
407
|
+
errors: this._errors.slice(),
|
|
408
|
+
configs: this._configs.slice(),
|
|
409
|
+
moduleGraph: this._moduleGraph,
|
|
410
|
+
chunkGraph: this._chunkGraph,
|
|
411
|
+
packageGraph: this._packageGraph,
|
|
412
|
+
loader: this._loader.slice(),
|
|
413
|
+
otherReports: { tileReportHtml: this._tileReportHtml || "" }
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
onDataReport() {
|
|
417
|
+
this.server.broadcast();
|
|
418
|
+
}
|
|
419
|
+
addRsdoctorDataToHTML(storeData, htmlContent) {
|
|
420
|
+
let compressTextScripts = `<script>window.${import_types.Constants.WINDOW_RSDOCTOR_TAG}={}</script>`;
|
|
421
|
+
for (let key of Object.keys(storeData)) {
|
|
422
|
+
const data = storeData[key];
|
|
423
|
+
const jsonStrFn = () => {
|
|
424
|
+
try {
|
|
425
|
+
if (key === "configs") {
|
|
426
|
+
return JSON.stringify(jc.decycle(data));
|
|
427
|
+
}
|
|
428
|
+
return JSON.stringify(data);
|
|
429
|
+
} catch (error) {
|
|
430
|
+
console.error(error);
|
|
431
|
+
return "";
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
const compressText = import_common.Algorithm.compressText(jsonStrFn());
|
|
435
|
+
compressTextScripts = `${compressTextScripts} <script>window.${import_types.Constants.WINDOW_RSDOCTOR_TAG}.${key}=${JSON.stringify(compressText)}</script>`;
|
|
436
|
+
}
|
|
437
|
+
compressTextScripts = `${compressTextScripts} <script>window.${import_types.Constants.WINDOW_RSDOCTOR_TAG}.enableRoutes=${JSON.stringify(this.getClientRoutes())}</script>`;
|
|
438
|
+
htmlContent = htmlContent.replace("<body>", `<body>${compressTextScripts}`);
|
|
439
|
+
return htmlContent;
|
|
440
|
+
}
|
|
441
|
+
inlineScriptsAndStyles(htmlFilePath) {
|
|
442
|
+
function inlineScripts(basePath2, scripts) {
|
|
443
|
+
return scripts.map((src) => {
|
|
444
|
+
const scriptPath = import_path.default.resolve(basePath2, src);
|
|
445
|
+
try {
|
|
446
|
+
const scriptContent = import_fs_extra.default.readFileSync(scriptPath, "utf-8");
|
|
447
|
+
return `<script>${scriptContent}</script>`;
|
|
448
|
+
} catch (error) {
|
|
449
|
+
console.error(`Could not read script at ${scriptPath}:`, error);
|
|
450
|
+
return "";
|
|
451
|
+
}
|
|
452
|
+
}).join("");
|
|
453
|
+
}
|
|
454
|
+
function inlineCss(basePath2, cssFiles) {
|
|
455
|
+
return cssFiles.map((href) => {
|
|
456
|
+
const cssPath = import_path.default.resolve(basePath2, href);
|
|
457
|
+
try {
|
|
458
|
+
const cssContent = import_fs_extra.default.readFileSync(cssPath, "utf-8");
|
|
459
|
+
return `<style>${cssContent}</style>`;
|
|
460
|
+
} catch (error) {
|
|
461
|
+
console.error(`Could not read CSS at ${cssPath}:`, error);
|
|
462
|
+
return "";
|
|
463
|
+
}
|
|
464
|
+
}).join("");
|
|
465
|
+
}
|
|
466
|
+
let htmlContent = import_fs_extra.default.readFileSync(htmlFilePath, "utf-8");
|
|
467
|
+
const basePath = import_path.default.dirname(htmlFilePath);
|
|
468
|
+
const scriptSrcs = Array.from(
|
|
469
|
+
htmlContent.matchAll(
|
|
470
|
+
/<script\s+(?:defer="defer"|defer)\s+src=["'](.+?)["']><\/script>/g
|
|
471
|
+
),
|
|
472
|
+
(m) => m[1]
|
|
473
|
+
);
|
|
474
|
+
const cssHrefs = Array.from(
|
|
475
|
+
htmlContent.matchAll(/<link\s+href=["'](.+?)["']\s+rel="stylesheet">/g),
|
|
476
|
+
(m) => m[1]
|
|
477
|
+
);
|
|
478
|
+
htmlContent = htmlContent.replace(
|
|
479
|
+
/<script\s+.*?src=["'].*?["']><\/script>/g,
|
|
480
|
+
""
|
|
481
|
+
);
|
|
482
|
+
htmlContent = htmlContent.replace(
|
|
483
|
+
/<link\s+.*?rel=["']stylesheet["'].*?>/g,
|
|
484
|
+
""
|
|
485
|
+
);
|
|
486
|
+
const inlinedScripts = inlineScripts(basePath, scriptSrcs);
|
|
487
|
+
const inlinedCss = inlineCss(basePath, cssHrefs);
|
|
488
|
+
const index = htmlContent.indexOf("</body>");
|
|
489
|
+
htmlContent = htmlContent.slice(0, index) + inlinedCss + inlinedScripts + htmlContent.slice(index);
|
|
490
|
+
htmlContent = this.addRsdoctorDataToHTML(this.getStoreData(), htmlContent);
|
|
491
|
+
const outputFilePath = import_path.default.resolve(
|
|
492
|
+
this.outputDir,
|
|
493
|
+
this.extraConfig?.brief?.reportHtmlName || "rsdoctor-report.html"
|
|
494
|
+
);
|
|
495
|
+
import_fs_extra.default.outputFileSync(outputFilePath, htmlContent, {
|
|
496
|
+
encoding: "utf-8",
|
|
497
|
+
flag: "w"
|
|
498
|
+
});
|
|
499
|
+
return outputFilePath;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
27
502
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
503
|
0 && (module.exports = {
|
|
29
504
|
RsdoctorSDK,
|
|
30
|
-
...require("
|
|
505
|
+
...require("../utils/openBrowser")
|
|
31
506
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RsdoctorPrimarySDK } from "./slave";
|
|
2
2
|
class RsdoctorSDKController {
|
|
3
3
|
constructor(root = process.cwd()) {
|
|
4
4
|
this.slaves = [];
|
|
@@ -32,7 +32,7 @@ class RsdoctorSDKController {
|
|
|
32
32
|
stage,
|
|
33
33
|
extraConfig
|
|
34
34
|
}) {
|
|
35
|
-
const slave = new
|
|
35
|
+
const slave = new RsdoctorPrimarySDK({
|
|
36
36
|
name,
|
|
37
37
|
stage,
|
|
38
38
|
controller: this,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
2
|
+
import { RsdoctorSDK } from "../sdk";
|
|
3
3
|
import { RsdoctorSlaveServer } from "./server";
|
|
4
4
|
let id = 1;
|
|
5
|
-
class
|
|
5
|
+
class RsdoctorPrimarySDK extends RsdoctorSDK {
|
|
6
6
|
constructor({
|
|
7
7
|
name,
|
|
8
8
|
stage,
|
|
@@ -65,5 +65,5 @@ class RsdoctorSlaveSDK extends RsdoctorWebpackSDK {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
export {
|
|
68
|
-
|
|
68
|
+
RsdoctorPrimarySDK
|
|
69
69
|
};
|
package/dist/esm/sdk/sdk/core.js
CHANGED
|
@@ -5,6 +5,7 @@ import path from "path";
|
|
|
5
5
|
import { createHash } from "crypto";
|
|
6
6
|
import process from "process";
|
|
7
7
|
import { AsyncSeriesHook } from "tapable";
|
|
8
|
+
const jc = require("json-cycle");
|
|
8
9
|
import { debug } from "@rsdoctor/utils/logger";
|
|
9
10
|
import { transformDataUrls } from "../utils";
|
|
10
11
|
class SDKCore {
|
|
@@ -97,6 +98,9 @@ class SDKCore {
|
|
|
97
98
|
}
|
|
98
99
|
const jsonStr = await (async () => {
|
|
99
100
|
try {
|
|
101
|
+
if (key === "configs") {
|
|
102
|
+
return JSON.stringify(jc.decycle(data));
|
|
103
|
+
}
|
|
100
104
|
return JSON.stringify(data);
|
|
101
105
|
} catch (error) {
|
|
102
106
|
return Json.stringify(data);
|