@rsdoctor/sdk 0.0.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/cjs/index.js +22 -0
  4. package/dist/cjs/sdk/index.js +24 -0
  5. package/dist/cjs/sdk/multiple/controller.js +72 -0
  6. package/dist/cjs/sdk/multiple/index.js +24 -0
  7. package/dist/cjs/sdk/multiple/server.js +41 -0
  8. package/dist/cjs/sdk/multiple/slave.js +98 -0
  9. package/dist/cjs/sdk/sdk/core.js +185 -0
  10. package/dist/cjs/sdk/sdk/index.js +31 -0
  11. package/dist/cjs/sdk/sdk/types.js +16 -0
  12. package/dist/cjs/sdk/sdk/webpack.js +373 -0
  13. package/dist/cjs/sdk/server/apis/alerts.js +52 -0
  14. package/dist/cjs/sdk/server/apis/base.js +46 -0
  15. package/dist/cjs/sdk/server/apis/bundle-diff.js +79 -0
  16. package/dist/cjs/sdk/server/apis/data.js +66 -0
  17. package/dist/cjs/sdk/server/apis/fs.js +50 -0
  18. package/dist/cjs/sdk/server/apis/graph.js +117 -0
  19. package/dist/cjs/sdk/server/apis/index.js +38 -0
  20. package/dist/cjs/sdk/server/apis/loader.js +127 -0
  21. package/dist/cjs/sdk/server/apis/plugin.js +58 -0
  22. package/dist/cjs/sdk/server/apis/project.js +82 -0
  23. package/dist/cjs/sdk/server/apis/renderer.js +74 -0
  24. package/dist/cjs/sdk/server/apis/resolver.js +57 -0
  25. package/dist/cjs/sdk/server/fakeServer.js +38 -0
  26. package/dist/cjs/sdk/server/index.js +184 -0
  27. package/dist/cjs/sdk/server/router.js +116 -0
  28. package/dist/cjs/sdk/server/socket/api.js +49 -0
  29. package/dist/cjs/sdk/server/socket/index.js +104 -0
  30. package/dist/cjs/sdk/server/utils.js +38 -0
  31. package/dist/cjs/sdk/utils/constant.js +41 -0
  32. package/dist/cjs/sdk/utils/index.js +24 -0
  33. package/dist/cjs/sdk/utils/upload.js +33 -0
  34. package/dist/esm/index.js +1 -0
  35. package/dist/esm/sdk/index.js +2 -0
  36. package/dist/esm/sdk/multiple/controller.js +48 -0
  37. package/dist/esm/sdk/multiple/index.js +2 -0
  38. package/dist/esm/sdk/multiple/server.js +17 -0
  39. package/dist/esm/sdk/multiple/slave.js +64 -0
  40. package/dist/esm/sdk/sdk/core.js +151 -0
  41. package/dist/esm/sdk/sdk/index.js +5 -0
  42. package/dist/esm/sdk/sdk/types.js +0 -0
  43. package/dist/esm/sdk/sdk/webpack.js +349 -0
  44. package/dist/esm/sdk/server/apis/alerts.js +30 -0
  45. package/dist/esm/sdk/server/apis/base.js +22 -0
  46. package/dist/esm/sdk/server/apis/bundle-diff.js +57 -0
  47. package/dist/esm/sdk/server/apis/data.js +44 -0
  48. package/dist/esm/sdk/server/apis/fs.js +28 -0
  49. package/dist/esm/sdk/server/apis/graph.js +95 -0
  50. package/dist/esm/sdk/server/apis/index.js +9 -0
  51. package/dist/esm/sdk/server/apis/loader.js +105 -0
  52. package/dist/esm/sdk/server/apis/plugin.js +36 -0
  53. package/dist/esm/sdk/server/apis/project.js +50 -0
  54. package/dist/esm/sdk/server/apis/renderer.js +42 -0
  55. package/dist/esm/sdk/server/apis/resolver.js +35 -0
  56. package/dist/esm/sdk/server/fakeServer.js +14 -0
  57. package/dist/esm/sdk/server/index.js +148 -0
  58. package/dist/esm/sdk/server/router.js +92 -0
  59. package/dist/esm/sdk/server/socket/api.js +25 -0
  60. package/dist/esm/sdk/server/socket/index.js +82 -0
  61. package/dist/esm/sdk/server/utils.js +14 -0
  62. package/dist/esm/sdk/utils/constant.js +7 -0
  63. package/dist/esm/sdk/utils/index.js +2 -0
  64. package/dist/esm/sdk/utils/upload.js +9 -0
  65. package/dist/type/index.d.ts +1 -0
  66. package/dist/type/sdk/index.d.ts +2 -0
  67. package/dist/type/sdk/multiple/controller.d.ts +16 -0
  68. package/dist/type/sdk/multiple/index.d.ts +2 -0
  69. package/dist/type/sdk/multiple/server.d.ts +7 -0
  70. package/dist/type/sdk/multiple/slave.d.ts +35 -0
  71. package/dist/type/sdk/sdk/core.d.ts +35 -0
  72. package/dist/type/sdk/sdk/index.d.ts +2 -0
  73. package/dist/type/sdk/sdk/types.d.ts +28 -0
  74. package/dist/type/sdk/sdk/webpack.d.ts +47 -0
  75. package/dist/type/sdk/server/apis/alerts.d.ts +5 -0
  76. package/dist/type/sdk/server/apis/base.d.ts +11 -0
  77. package/dist/type/sdk/server/apis/bundle-diff.d.ts +6 -0
  78. package/dist/type/sdk/server/apis/data.d.ts +6 -0
  79. package/dist/type/sdk/server/apis/fs.d.ts +5 -0
  80. package/dist/type/sdk/server/apis/graph.d.ts +12 -0
  81. package/dist/type/sdk/server/apis/index.d.ts +9 -0
  82. package/dist/type/sdk/server/apis/loader.d.ts +16 -0
  83. package/dist/type/sdk/server/apis/plugin.d.ts +6 -0
  84. package/dist/type/sdk/server/apis/project.d.ts +8 -0
  85. package/dist/type/sdk/server/apis/renderer.d.ts +7 -0
  86. package/dist/type/sdk/server/apis/resolver.d.ts +6 -0
  87. package/dist/type/sdk/server/fakeServer.d.ts +7 -0
  88. package/dist/type/sdk/server/index.d.ts +27 -0
  89. package/dist/type/sdk/server/router.d.ts +25 -0
  90. package/dist/type/sdk/server/socket/api.d.ts +15 -0
  91. package/dist/type/sdk/server/socket/index.d.ts +28 -0
  92. package/dist/type/sdk/server/utils.d.ts +5 -0
  93. package/dist/type/sdk/utils/constant.d.ts +1 -0
  94. package/dist/type/sdk/utils/index.d.ts +2 -0
  95. package/dist/type/sdk/utils/upload.d.ts +2 -0
  96. package/package.json +51 -0
@@ -0,0 +1,64 @@
1
+ import path from "path";
2
+ import { DoctorWebpackSDK } from "../sdk";
3
+ import { DoctorSlaveServer } from "./server";
4
+ let id = 1;
5
+ class DoctorSlaveSDK extends DoctorWebpackSDK {
6
+ constructor({ name, stage, controller, extraConfig }) {
7
+ super({ name, root: controller.root });
8
+ const lastSdk = controller.getLastSdk();
9
+ const port = lastSdk ? lastSdk.server.port + 1 : this.server.port;
10
+ this.id = id++;
11
+ this.stage = typeof stage === "number" ? stage : 1;
12
+ this.extraConfig = extraConfig;
13
+ this.parent = controller;
14
+ this.server = new DoctorSlaveServer(this, port);
15
+ this.setName(name);
16
+ this.clearSwitch();
17
+ }
18
+ clearSwitch() {
19
+ this.uploadPieces = new Promise((resolve) => {
20
+ this.finishUploadPieceSwitch = resolve;
21
+ });
22
+ }
23
+ get isMaster() {
24
+ return this.parent.master === this;
25
+ }
26
+ async writePieces() {
27
+ const { name, parent, isMaster, outputDir, finishUploadPieceSwitch } = this;
28
+ this.setOutputDir(
29
+ isMaster ? outputDir : path.join(
30
+ parent.master.outputDir,
31
+ ".slaves",
32
+ name.replace(/\s+/g, "-")
33
+ )
34
+ );
35
+ await super.writePieces(this.getStoreData());
36
+ finishUploadPieceSwitch?.();
37
+ }
38
+ async writeManifest() {
39
+ const { parent, cloudData } = this;
40
+ await Promise.all(this.parent.slaves.map((item) => item.uploadPieces));
41
+ if (cloudData) {
42
+ cloudData.name = this.name;
43
+ cloudData.series = parent.getSeriesData();
44
+ }
45
+ const result = await super.writeManifest();
46
+ this.clearSwitch();
47
+ return result;
48
+ }
49
+ getSeriesData(serverUrl = false) {
50
+ return this.parent.getSeriesData(serverUrl);
51
+ }
52
+ setName(name) {
53
+ this._name = this.parent.hasName(name) ? `${name}-${id}` : name;
54
+ }
55
+ getManifestData() {
56
+ const data = super.getManifestData();
57
+ data.name = this.name;
58
+ data.series = this.getSeriesData(true);
59
+ return data;
60
+ }
61
+ }
62
+ export {
63
+ DoctorSlaveSDK
64
+ };
@@ -0,0 +1,151 @@
1
+ import { Constants, Manifest } from "@rsdoctor/types";
2
+ import { File, Json, EnvInfo } from "@rsdoctor/utils/build";
3
+ import { Algorithm } from "@rsdoctor/utils/common";
4
+ import path from "path";
5
+ import { createHash } from "crypto";
6
+ import process from "process";
7
+ import { AsyncSeriesHook } from "tapable";
8
+ import { debug } from "@rsdoctor/utils/logger";
9
+ import { transformDataUrls } from "../utils";
10
+ class SDKCore {
11
+ constructor({ name, root }) {
12
+ this.hooks = {
13
+ afterSaveManifest: new AsyncSeriesHook(["result"])
14
+ };
15
+ this._envinfo = {};
16
+ this._clientRoutes = /* @__PURE__ */ new Set([
17
+ Manifest.DoctorManifestClientRoutes.Overall
18
+ ]);
19
+ this.diskManifestPath = "";
20
+ this._name = name;
21
+ this.root = root;
22
+ this.pid = process.pid;
23
+ this._outputDir = path.join(this.root, Constants.DoctorOutputFolder);
24
+ }
25
+ get outputDir() {
26
+ return this._outputDir;
27
+ }
28
+ get name() {
29
+ return this._name;
30
+ }
31
+ async bootstrap() {
32
+ const [cpu, memory, nodeVersion, yarnVersion, npmVersion, pnpmVersion] = await Promise.all([
33
+ EnvInfo.getCPUInfo(),
34
+ EnvInfo.getMemoryInfo(),
35
+ EnvInfo.getNodeVersion(),
36
+ EnvInfo.getYarnVersion(),
37
+ EnvInfo.getNpmVersion(),
38
+ EnvInfo.getGlobalNpmPackageVersion("pnpm")
39
+ ]);
40
+ this._envinfo = {
41
+ ...this._envinfo,
42
+ cpu,
43
+ memory,
44
+ nodeVersion,
45
+ yarnVersion,
46
+ npmVersion,
47
+ pnpmVersion
48
+ };
49
+ const hash = createHash("md5").update(
50
+ [this.name, this.root, JSON.stringify(this._envinfo), Date.now()].join(
51
+ "_"
52
+ )
53
+ ).digest("hex");
54
+ this.setHash(hash);
55
+ }
56
+ async dispose() {
57
+ }
58
+ setOutputDir(outputDir) {
59
+ this._outputDir = outputDir;
60
+ }
61
+ setName(name) {
62
+ this._name = name;
63
+ }
64
+ setHash(hash) {
65
+ this.hash = hash;
66
+ }
67
+ getClientRoutes() {
68
+ return [...this._clientRoutes];
69
+ }
70
+ addClientRoutes(routes) {
71
+ routes.forEach((route) => {
72
+ this._clientRoutes.add(route);
73
+ });
74
+ this.onDataReport();
75
+ }
76
+ /** Upload analysis data pieces */
77
+ async writePieces(storeData, _options) {
78
+ const { outputDir } = this;
79
+ const manifest = path.resolve(outputDir, Constants.DoctorOutputManifest);
80
+ this.diskManifestPath = manifest;
81
+ await File.fse.ensureDir(outputDir);
82
+ const dataUrls = await Promise.all(
83
+ Object.keys(storeData).map(async (key) => {
84
+ const data = storeData[key];
85
+ if (typeof data !== "object") {
86
+ return {
87
+ name: key,
88
+ files: data
89
+ };
90
+ }
91
+ const jsonstr = await (async () => {
92
+ try {
93
+ return JSON.stringify(data);
94
+ } catch (error) {
95
+ return Json.stringify(data);
96
+ }
97
+ })();
98
+ return this.writeToFolder(jsonstr, outputDir, key);
99
+ })
100
+ );
101
+ debug(
102
+ () => `SDKCore.writePieces extraConfig: ${JSON.stringify(this.extraConfig)}`,
103
+ "[SDKCore.writePieces]"
104
+ );
105
+ this.cloudData = {
106
+ client: {
107
+ enableRoutes: this.getClientRoutes()
108
+ },
109
+ data: transformDataUrls(dataUrls)
110
+ };
111
+ }
112
+ /** Upload manifest file */
113
+ async writeManifest() {
114
+ const { cloudData: data, diskManifestPath } = this;
115
+ const dataStr = JSON.stringify(data, null, 2);
116
+ debug(
117
+ () => `SDKCore.writeManifest extraConfig: ${this.extraConfig}`,
118
+ "[SDKCore.writeManifest]"
119
+ );
120
+ await Promise.all([File.fse.writeFile(diskManifestPath, dataStr)]);
121
+ return diskManifestPath;
122
+ }
123
+ async saveManifest(data, options) {
124
+ await this.writePieces(data, options);
125
+ const manifestDiskPath = await this.writeManifest();
126
+ await this.hooks.afterSaveManifest.promise({
127
+ manifestWithShardingFiles: this.cloudData,
128
+ manifestDiskPath
129
+ });
130
+ return manifestDiskPath;
131
+ }
132
+ writeToFolder(jsonstr, dir, key) {
133
+ const sharding = new File.FileSharding(Algorithm.compressText(jsonstr));
134
+ const folder = path.resolve(dir, key);
135
+ const writer = sharding.writeStringToFolder(folder);
136
+ return writer.then((item) => {
137
+ const res = {
138
+ name: key,
139
+ files: item.map((el) => ({
140
+ path: path.resolve(folder, el.filename),
141
+ basename: el.filename,
142
+ content: el.content
143
+ }))
144
+ };
145
+ return res;
146
+ });
147
+ }
148
+ }
149
+ export {
150
+ SDKCore
151
+ };
@@ -0,0 +1,5 @@
1
+ export * from "./webpack";
2
+ import { DoctorWebpackSDK } from "./webpack";
3
+ export {
4
+ DoctorWebpackSDK as DoctorSDK
5
+ };
File without changes
@@ -0,0 +1,349 @@
1
+ import { DevToolError } from "@rsdoctor/utils/error";
2
+ import { SDK } from "@rsdoctor/types";
3
+ import { File } from "@rsdoctor/utils/build";
4
+ import { SourceMapConsumer } from "source-map";
5
+ import { ModuleGraph, ChunkGraph, PackageGraph } from "@rsdoctor/graph";
6
+ import { debug } from "@rsdoctor/utils/logger";
7
+ import { DoctorServer } from "../server";
8
+ import { DoctorFakeServer } from "../server/fakeServer";
9
+ import { SDKCore } from "./core";
10
+ class DoctorWebpackSDK extends SDKCore {
11
+ constructor(options) {
12
+ super(options);
13
+ this._summary = { costs: [] };
14
+ this._configs = [];
15
+ this._errors = [];
16
+ this._loader = [];
17
+ this._resolver = [];
18
+ this._plugin = {};
19
+ this._moduleGraph = new ModuleGraph();
20
+ this._chunkGraph = new ChunkGraph();
21
+ this._rawSourceMapCache = /* @__PURE__ */ new Map();
22
+ this._sourceMap = /* @__PURE__ */ new Map();
23
+ this.server = options.noServer ? new DoctorFakeServer(this, void 0) : new DoctorServer(this, options.port);
24
+ this.type = options.type || SDK.ToDataType.Normal;
25
+ this.extraConfig = options.config;
26
+ }
27
+ async bootstrap() {
28
+ debug(() => `${Date.now()}`, "[DoctorWebpackSDK][bootstrap start]");
29
+ this.server && await this.server.bootstrap();
30
+ await super.bootstrap();
31
+ debug(
32
+ () => `${Date.now()} ${this.server.origin}`,
33
+ "[DoctorWebpackSDK][bootstrap end]"
34
+ );
35
+ }
36
+ async dispose() {
37
+ debug(() => `${Date.now()}`, "[DoctorWebpackSDK][dispose start]");
38
+ this.server && await this.server.dispose();
39
+ await super.dispose();
40
+ debug(() => `${Date.now()}`, "[DoctorWebpackSDK][dispose end]");
41
+ }
42
+ async applyErrorFix(id) {
43
+ const { _errors: errors } = this;
44
+ const error = errors.find((err) => err.id === id);
45
+ if (!error || !error.path || !error.fixData || error.fixData.isFixed) {
46
+ return;
47
+ }
48
+ const { path: filePath, fixData } = error;
49
+ const sameFileErrors = errors.filter(
50
+ (item) => item.path === filePath && item !== error
51
+ );
52
+ let content = (await File.fse.readFile(filePath, "utf-8")).toString();
53
+ const startTxt = content.substring(0, fixData.start);
54
+ const endTxt = content.substring(fixData.end, content.length);
55
+ const offset = (fixData.newText ?? "").length - (fixData.end - fixData.start);
56
+ content = startTxt + fixData.newText + endTxt;
57
+ for (const other of sameFileErrors) {
58
+ const { fixData: otherFixData } = other;
59
+ if (!otherFixData) {
60
+ continue;
61
+ }
62
+ if (otherFixData.start >= fixData.end) {
63
+ otherFixData.start += offset;
64
+ otherFixData.end += offset;
65
+ }
66
+ }
67
+ await File.fse.writeFile(filePath, content);
68
+ }
69
+ clear() {
70
+ this._errors = [];
71
+ this._loader = [];
72
+ this._resolver = [];
73
+ this._plugin = {};
74
+ this._moduleGraph = new ModuleGraph();
75
+ this._chunkGraph = new ChunkGraph();
76
+ }
77
+ clearSourceMapCache() {
78
+ this._rawSourceMapCache = /* @__PURE__ */ new Map();
79
+ this._sourceMap = /* @__PURE__ */ new Map();
80
+ }
81
+ async getSourceMap(file) {
82
+ const { _sourceMap: sourceMap, _rawSourceMapCache: rawMap } = this;
83
+ if (sourceMap.has(file)) {
84
+ return sourceMap.get(file);
85
+ }
86
+ const rawData = rawMap.get(file);
87
+ if (!rawData || rawData.version < 0 || !rawData.sourcesContent?.[0] || !rawData.mappings) {
88
+ return Promise.resolve(void 0);
89
+ }
90
+ try {
91
+ const result = await new SourceMapConsumer(rawData);
92
+ sourceMap.set(file, result);
93
+ return result;
94
+ } catch (e) {
95
+ return Promise.resolve(void 0);
96
+ }
97
+ }
98
+ reportSourceMap(data) {
99
+ this._rawSourceMapCache.set(data.file, data);
100
+ }
101
+ reportConfiguration(config) {
102
+ this._configs.push(config);
103
+ this.onDataReport();
104
+ }
105
+ reportError(errors) {
106
+ errors.forEach((item) => {
107
+ this._errors.push(
108
+ DevToolError.from(item, {
109
+ code: this.name
110
+ })
111
+ );
112
+ });
113
+ this.onDataReport();
114
+ }
115
+ reportLoader(data) {
116
+ data.forEach((item) => {
117
+ let match = this._loader.find(
118
+ (e) => e.resource.path === item.resource.path
119
+ );
120
+ if (match) {
121
+ match.loaders.push(...item.loaders);
122
+ } else {
123
+ match = item;
124
+ this._loader.push(item);
125
+ }
126
+ match.loaders.sort((a, b) => {
127
+ if (a.startAt !== b.startAt) {
128
+ return a.startAt - b.startAt;
129
+ }
130
+ if (a.isPitch) {
131
+ if (b.isPitch) {
132
+ return a.loaderIndex - b.loaderIndex;
133
+ }
134
+ return -1;
135
+ }
136
+ if (b.isPitch) {
137
+ return 1;
138
+ }
139
+ return b.loaderIndex - a.loaderIndex;
140
+ });
141
+ });
142
+ this.onDataReport();
143
+ }
144
+ reportResolver(data) {
145
+ data.forEach((item) => this._resolver.push(item));
146
+ this.onDataReport();
147
+ }
148
+ reportPlugin(data) {
149
+ Object.keys(data).forEach((hook) => {
150
+ if (!this._plugin[hook]) {
151
+ this._plugin[hook] = data[hook];
152
+ } else {
153
+ data[hook].forEach((item) => {
154
+ this._plugin[hook].push(item);
155
+ });
156
+ }
157
+ });
158
+ this.onDataReport();
159
+ }
160
+ reportModuleGraph(data) {
161
+ debug(() => `data size: ${data.size()}`, "[SDK.reportModuleGraph][start]");
162
+ this._moduleGraph.fromInstance(data);
163
+ this.createPackageGraph();
164
+ this.onDataReport();
165
+ debug(
166
+ () => `sdk._moduleGraph size: ${this._moduleGraph.size()}`,
167
+ "[SDK reportModuleGraph][end]"
168
+ );
169
+ }
170
+ reportPackageGraph(data) {
171
+ debug(() => "[SDK.reportPackageGraph][start]");
172
+ if (!this._packageGraph) {
173
+ this._packageGraph = data;
174
+ }
175
+ this.onDataReport();
176
+ debug(
177
+ () => `sdk._moduleGraph size: ${this._moduleGraph.size()}`,
178
+ "[SDK reportPackageGraph][end]"
179
+ );
180
+ }
181
+ reportChunkGraph(data) {
182
+ this._chunkGraph.addAsset(...data.getAssets());
183
+ this._chunkGraph.addChunk(...data.getChunks());
184
+ this._chunkGraph.addEntryPoint(...data.getEntryPoints());
185
+ this.onDataReport();
186
+ }
187
+ reportSummaryData(part) {
188
+ const keys = ["costs"];
189
+ for (const key of keys) {
190
+ const v = part[key];
191
+ if (!v)
192
+ continue;
193
+ if (typeof v === "object") {
194
+ if (Array.isArray(v)) {
195
+ this._summary[key] = [
196
+ ...this._summary[key] || [],
197
+ ...v
198
+ ];
199
+ } else {
200
+ this._summary[key] = {
201
+ ...this._summary[key] || {},
202
+ ...v
203
+ };
204
+ }
205
+ } else {
206
+ this._summary[key] = v;
207
+ }
208
+ }
209
+ this.onDataReport();
210
+ }
211
+ reportTileHtml(tileReportHtml) {
212
+ this._tileReportHtml = tileReportHtml;
213
+ }
214
+ createPackageGraph() {
215
+ debug(
216
+ () => `sdk._moduleGraph size: ${this._moduleGraph.size()}`,
217
+ "[SDK.createPackageGraph][start]"
218
+ );
219
+ if (!this._packageGraph) {
220
+ const pkgGraph = PackageGraph.fromModuleGraph(
221
+ this._moduleGraph,
222
+ this.root,
223
+ (path) => {
224
+ try {
225
+ const exists = File.fse.existsSync(path);
226
+ if (exists) {
227
+ debug(
228
+ () => `sdk.PackageGraph package.json exists: ${exists}, path: ${path}`,
229
+ "[SDK.createPackageGraph][load]"
230
+ );
231
+ return File.fse.readJSONSync(path);
232
+ }
233
+ } catch (error) {
234
+ const { message, stack } = error;
235
+ debug(
236
+ () => `sdk.createPackageGraph error, path: ${path}, error message: ${stack || message}`,
237
+ "[SDK.createPackageGraph][error]"
238
+ );
239
+ }
240
+ }
241
+ );
242
+ this._packageGraph = pkgGraph;
243
+ debug(
244
+ () => `sdk._packageGraph packages: ${this._packageGraph.getPackages().length}`,
245
+ "[SDK.createPackageGraph][end]"
246
+ );
247
+ }
248
+ }
249
+ writeStore(options) {
250
+ debug(() => `sdk.writeStore has run.`, "[SDK.writeStore][end]");
251
+ return this.saveManifest(this.getStoreData(), options || {});
252
+ }
253
+ getStoreData() {
254
+ const ctx = this;
255
+ return {
256
+ get hash() {
257
+ return ctx.hash;
258
+ },
259
+ get root() {
260
+ return ctx.root;
261
+ },
262
+ get envinfo() {
263
+ return ctx._envinfo;
264
+ },
265
+ get pid() {
266
+ return ctx.pid;
267
+ },
268
+ get errors() {
269
+ return ctx._errors.map((err) => err.toData());
270
+ },
271
+ get configs() {
272
+ return ctx._configs.slice();
273
+ },
274
+ get summary() {
275
+ return { ...ctx._summary };
276
+ },
277
+ get resolver() {
278
+ return ctx._resolver.slice();
279
+ },
280
+ get loader() {
281
+ return ctx._loader.slice();
282
+ },
283
+ get moduleGraph() {
284
+ return ctx._moduleGraph.toData({
285
+ contextPath: ctx._configs?.[0]?.config?.context || ""
286
+ });
287
+ },
288
+ get chunkGraph() {
289
+ return ctx._chunkGraph.toData(ctx.type);
290
+ },
291
+ get moduleCodeMap() {
292
+ return ctx._moduleGraph.toCodeData(ctx.type);
293
+ },
294
+ get plugin() {
295
+ return { ...ctx._plugin };
296
+ },
297
+ get packageGraph() {
298
+ return ctx._packageGraph ? ctx._packageGraph.toData() : {
299
+ packages: [],
300
+ dependencies: []
301
+ };
302
+ },
303
+ get otherReports() {
304
+ return { tileReportHtml: ctx._tileReportHtml || "" };
305
+ }
306
+ };
307
+ }
308
+ getManifestData() {
309
+ const dataValue = this.getStoreData();
310
+ const data = {
311
+ client: {
312
+ enableRoutes: this.getClientRoutes()
313
+ },
314
+ data: Object.keys(dataValue).reduce((t, e) => {
315
+ const _e = e;
316
+ if (dataValue[_e] && typeof dataValue[_e] === "object") {
317
+ t[e] = [
318
+ `${this.server.origin}${SDK.ServerAPI.API.LoadDataByKey}/${e}`
319
+ ];
320
+ } else {
321
+ t[e] = dataValue[_e];
322
+ }
323
+ return t;
324
+ }, {}),
325
+ __LOCAL__SERVER__: true,
326
+ __SOCKET__URL__: this.server.socketUrl
327
+ };
328
+ return data;
329
+ }
330
+ getRuleContext(_options) {
331
+ this.createPackageGraph();
332
+ return {
333
+ root: this.root,
334
+ errors: this._errors.slice(),
335
+ configs: this._configs.slice(),
336
+ moduleGraph: this._moduleGraph,
337
+ chunkGraph: this._chunkGraph,
338
+ packageGraph: this._packageGraph,
339
+ loader: this._loader.slice(),
340
+ otherReports: { tileReportHtml: this._tileReportHtml || "" }
341
+ };
342
+ }
343
+ onDataReport() {
344
+ this.server.broadcast();
345
+ }
346
+ }
347
+ export {
348
+ DoctorWebpackSDK
349
+ };
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result)
9
+ __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ import { SDK } from "@rsdoctor/types";
13
+ import { BaseAPI } from "./base";
14
+ import { Router } from "../router";
15
+ class AlertsAPI extends BaseAPI {
16
+ async getPackageRelationAlertDetails() {
17
+ const { req } = this.ctx;
18
+ const { id, target } = req.body;
19
+ return this.dataLoader.loadAPI(
20
+ SDK.ServerAPI.API.GetPackageRelationAlertDetails,
21
+ { id, target }
22
+ );
23
+ }
24
+ }
25
+ __decorateClass([
26
+ Router.post(SDK.ServerAPI.API.GetPackageRelationAlertDetails)
27
+ ], AlertsAPI.prototype, "getPackageRelationAlertDetails", 1);
28
+ export {
29
+ AlertsAPI
30
+ };
@@ -0,0 +1,22 @@
1
+ import { Data } from "@rsdoctor/utils/common";
2
+ class BaseAPI {
3
+ constructor(sdk, server) {
4
+ this.ctx = { sdk, server };
5
+ this.dataLoader = new Data.APIDataLoader(this);
6
+ }
7
+ async loadManifest() {
8
+ return this.ctx.sdk.getManifestData();
9
+ }
10
+ async loadData(key) {
11
+ const data = this.ctx.sdk.getStoreData();
12
+ const sep = ".";
13
+ let res = data[key];
14
+ if (key.includes(sep)) {
15
+ res = key.split(sep).reduce((t, k) => t[k], data);
16
+ }
17
+ return res;
18
+ }
19
+ }
20
+ export {
21
+ BaseAPI
22
+ };
@@ -0,0 +1,57 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result)
9
+ __defProp(target, key, result);
10
+ return result;
11
+ };
12
+ import { SDK } from "@rsdoctor/types";
13
+ import { BaseAPI } from "./base";
14
+ import { Router } from "../router";
15
+ class BundleDiffAPI extends BaseAPI {
16
+ async getBundleDiffSummary() {
17
+ const { sdk } = this.ctx;
18
+ const {
19
+ root,
20
+ hash,
21
+ errors,
22
+ chunkGraph,
23
+ moduleGraph,
24
+ packageGraph,
25
+ configs,
26
+ moduleCodeMap
27
+ } = sdk.getStoreData();
28
+ let outputFilename = "";
29
+ if (typeof configs?.[0]?.config?.output?.filename === "string") {
30
+ outputFilename = configs?.[0]?.config?.output?.filename;
31
+ }
32
+ return {
33
+ root,
34
+ hash,
35
+ errors,
36
+ chunkGraph,
37
+ moduleGraph,
38
+ packageGraph,
39
+ outputFilename,
40
+ moduleCodeMap
41
+ };
42
+ }
43
+ async bundleDiffManifest() {
44
+ const { sdk } = this.ctx;
45
+ const data = sdk.getStoreData();
46
+ return data;
47
+ }
48
+ }
49
+ __decorateClass([
50
+ Router.get(SDK.ServerAPI.API.GetBundleDiffSummary)
51
+ ], BundleDiffAPI.prototype, "getBundleDiffSummary", 1);
52
+ __decorateClass([
53
+ Router.get(SDK.ServerAPI.API.BundleDiffManifest)
54
+ ], BundleDiffAPI.prototype, "bundleDiffManifest", 1);
55
+ export {
56
+ BundleDiffAPI
57
+ };