@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.
Files changed (167) hide show
  1. package/dist/26.js +26163 -0
  2. package/dist/630.js +1269 -0
  3. package/dist/630.js.LICENSE.txt +7 -0
  4. package/dist/build-utils/build/chunks/assetsModules.d.ts +7 -1
  5. package/dist/build-utils/build/loader/probeLoader.d.ts +7 -2
  6. package/dist/build-utils/build/utils/parseBundle.d.ts +1 -1
  7. package/dist/index.d.ts +5 -5
  8. package/dist/index.js +1725 -7
  9. package/dist/inner-plugins/constants.d.ts +1 -1
  10. package/dist/inner-plugins/plugins/base.d.ts +2 -2
  11. package/dist/logger.d.ts +2 -2
  12. package/dist/probe-loader.js +2 -0
  13. package/dist/proxy-loader.d.ts +1 -0
  14. package/dist/proxy-loader.js +48 -0
  15. package/dist/rslib-runtime.js +28 -0
  16. package/dist/rspack-plugin/constants.d.ts +1 -1
  17. package/dist/rules/rules/ecma-version-check/htmlParserStub.d.ts +3 -0
  18. package/dist/rules/rules/ecma-version-check/types.d.ts +13 -2
  19. package/dist/sdk/server/apis/base.d.ts +1 -1
  20. package/dist/sdk/server/socket/api.d.ts +1 -1
  21. package/dist/sdk/utils/date.d.ts +1 -0
  22. package/dist/types/loader.d.ts +1 -1
  23. package/package.json +20 -113
  24. package/dist/build-utils/build/chunks/assetsModules.js +0 -9
  25. package/dist/build-utils/build/chunks/index.js +0 -3
  26. package/dist/build-utils/build/chunks/rspack/transform.js +0 -44
  27. package/dist/build-utils/build/envinfo.js +0 -60
  28. package/dist/build-utils/build/file/cache.js +0 -24
  29. package/dist/build-utils/build/file/index.js +0 -5
  30. package/dist/build-utils/build/file/sharding.js +0 -38
  31. package/dist/build-utils/build/index.js +0 -12
  32. package/dist/build-utils/build/json.js +0 -67
  33. package/dist/build-utils/build/loader/index.js +0 -3
  34. package/dist/build-utils/build/loader/probeLoader.js +0 -44
  35. package/dist/build-utils/build/loader/probeLoaderPlugin.js +0 -32
  36. package/dist/build-utils/build/module-graph/index.js +0 -2
  37. package/dist/build-utils/build/module-graph/parser.js +0 -13
  38. package/dist/build-utils/build/module-graph/rspack/transform.js +0 -111
  39. package/dist/build-utils/build/module-graph/utils.js +0 -60
  40. package/dist/build-utils/build/process.js +0 -18
  41. package/dist/build-utils/build/server.js +0 -107
  42. package/dist/build-utils/build/utils/index.js +0 -4
  43. package/dist/build-utils/build/utils/loader.js +0 -267
  44. package/dist/build-utils/build/utils/parseBundle.js +0 -238
  45. package/dist/build-utils/build/utils/plugin.js +0 -21
  46. package/dist/build-utils/index.js +0 -13
  47. package/dist/collection.d.ts +0 -1
  48. package/dist/collection.js +0 -2
  49. package/dist/common/file.js +0 -8
  50. package/dist/common/global-config.js +0 -33
  51. package/dist/common/index.d.ts +0 -4
  52. package/dist/common/index.js +0 -6
  53. package/dist/common-browser.d.ts +0 -1
  54. package/dist/common-browser.js +0 -2
  55. package/dist/error/error.js +0 -143
  56. package/dist/error/index.js +0 -3
  57. package/dist/error/transform.js +0 -138
  58. package/dist/error/utils.js +0 -23
  59. package/dist/graph/index.d.ts +0 -1
  60. package/dist/graph/index.js +0 -2
  61. package/dist/inner-plugins/constants.js +0 -19
  62. package/dist/inner-plugins/index.js +0 -3
  63. package/dist/inner-plugins/loaders/proxy.js +0 -65
  64. package/dist/inner-plugins/plugins/base.js +0 -20
  65. package/dist/inner-plugins/plugins/bundle.js +0 -63
  66. package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +0 -74
  67. package/dist/inner-plugins/plugins/errors.js +0 -65
  68. package/dist/inner-plugins/plugins/index.js +0 -11
  69. package/dist/inner-plugins/plugins/loader.js +0 -108
  70. package/dist/inner-plugins/plugins/plugins.js +0 -40
  71. package/dist/inner-plugins/plugins/progress.js +0 -35
  72. package/dist/inner-plugins/plugins/resolver.js +0 -57
  73. package/dist/inner-plugins/plugins/rspack.js +0 -99
  74. package/dist/inner-plugins/plugins/rules.js +0 -64
  75. package/dist/inner-plugins/plugins/sourcemapTool.js +0 -230
  76. package/dist/inner-plugins/plugins/summary.js +0 -92
  77. package/dist/inner-plugins/utils/circleDetect.js +0 -16
  78. package/dist/inner-plugins/utils/config.js +0 -141
  79. package/dist/inner-plugins/utils/index.js +0 -8
  80. package/dist/inner-plugins/utils/loader.js +0 -134
  81. package/dist/inner-plugins/utils/normalize-config.js +0 -77
  82. package/dist/inner-plugins/utils/openBrowser.js +0 -55
  83. package/dist/inner-plugins/utils/plugin-common.js +0 -94
  84. package/dist/inner-plugins/utils/plugin.js +0 -70
  85. package/dist/inner-plugins/utils/sdk.js +0 -19
  86. package/dist/logger.js +0 -51
  87. package/dist/rspack-plugin/constants.js +0 -23
  88. package/dist/rspack-plugin/index.js +0 -3
  89. package/dist/rspack-plugin/multiple.js +0 -39
  90. package/dist/rspack-plugin/plugin.js +0 -133
  91. package/dist/rule-utils/document/document.js +0 -46
  92. package/dist/rule-utils/document/index.js +0 -4
  93. package/dist/rule-utils/document/server.js +0 -13
  94. package/dist/rule-utils/document/types.js +0 -1
  95. package/dist/rule-utils/index.js +0 -3
  96. package/dist/rule-utils/parser/asserts.js +0 -105
  97. package/dist/rule-utils/parser/index.js +0 -5
  98. package/dist/rule-utils/parser/parser.js +0 -24
  99. package/dist/rule-utils/parser/types.js +0 -8
  100. package/dist/rule-utils/parser/utils.js +0 -106
  101. package/dist/rules/index.js +0 -4
  102. package/dist/rules/linter.js +0 -36
  103. package/dist/rules/rule.js +0 -101
  104. package/dist/rules/rules/cjs-require/index.js +0 -50
  105. package/dist/rules/rules/cjs-require/types.js +0 -1
  106. package/dist/rules/rules/cross-chunks-package/index.js +0 -41
  107. package/dist/rules/rules/cross-chunks-package/types.js +0 -1
  108. package/dist/rules/rules/cross-chunks-package/utils.js +0 -7
  109. package/dist/rules/rules/default-import-check/index.js +0 -83
  110. package/dist/rules/rules/default-import-check/types.js +0 -1
  111. package/dist/rules/rules/default-import-check/utils.js +0 -52
  112. package/dist/rules/rules/duplicate-package/index.js +0 -39
  113. package/dist/rules/rules/duplicate-package/types.js +0 -24
  114. package/dist/rules/rules/duplicate-package/utils.js +0 -38
  115. package/dist/rules/rules/ecma-version-check/index.js +0 -53
  116. package/dist/rules/rules/ecma-version-check/types.js +0 -1
  117. package/dist/rules/rules/ecma-version-check/utils.js +0 -6
  118. package/dist/rules/rules/esm-resolved-to-cjs/index.js +0 -193
  119. package/dist/rules/rules/esm-resolved-to-cjs/types.js +0 -1
  120. package/dist/rules/rules/index.js +0 -22
  121. package/dist/rules/rules/loader-performance-optimization/index.js +0 -86
  122. package/dist/rules/rules/loader-performance-optimization/types.js +0 -1
  123. package/dist/rules/rules/loader-performance-optimization/utils.js +0 -10
  124. package/dist/rules/rules/module-mixed-chunks/index.js +0 -52
  125. package/dist/rules/rules/module-mixed-chunks/types.js +0 -1
  126. package/dist/rules/rules/side-effects-only-imports/index.js +0 -81
  127. package/dist/rules/rules/side-effects-only-imports/types.js +0 -1
  128. package/dist/rules/utils.js +0 -10
  129. package/dist/sdk/index.js +0 -3
  130. package/dist/sdk/multiple/controller.js +0 -42
  131. package/dist/sdk/multiple/index.js +0 -3
  132. package/dist/sdk/multiple/primary.js +0 -64
  133. package/dist/sdk/multiple/server.js +0 -14
  134. package/dist/sdk/sdk/core.js +0 -163
  135. package/dist/sdk/sdk/index.js +0 -435
  136. package/dist/sdk/sdk/types.js +0 -1
  137. package/dist/sdk/server/apis/alerts.js +0 -30
  138. package/dist/sdk/server/apis/base.js +0 -22
  139. package/dist/sdk/server/apis/bundle-diff.js +0 -51
  140. package/dist/sdk/server/apis/data.js +0 -44
  141. package/dist/sdk/server/apis/fs.js +0 -28
  142. package/dist/sdk/server/apis/graph.js +0 -116
  143. package/dist/sdk/server/apis/index.js +0 -11
  144. package/dist/sdk/server/apis/loader.js +0 -120
  145. package/dist/sdk/server/apis/plugin.js +0 -39
  146. package/dist/sdk/server/apis/project.js +0 -59
  147. package/dist/sdk/server/apis/renderer.js +0 -33
  148. package/dist/sdk/server/apis/resolver.js +0 -38
  149. package/dist/sdk/server/client.js +0 -8
  150. package/dist/sdk/server/fakeServer.js +0 -12
  151. package/dist/sdk/server/index.js +0 -292
  152. package/dist/sdk/server/json-body.js +0 -150
  153. package/dist/sdk/server/router.js +0 -83
  154. package/dist/sdk/server/security.js +0 -47
  155. package/dist/sdk/server/socket/api.js +0 -22
  156. package/dist/sdk/server/socket/index.js +0 -166
  157. package/dist/sdk/server/utils.js +0 -19
  158. package/dist/sdk/utils/base.js +0 -22
  159. package/dist/sdk/utils/constant.js +0 -4
  160. package/dist/sdk/utils/index.js +0 -4
  161. package/dist/sdk/utils/openBrowser.js +0 -53
  162. package/dist/sdk/utils/upload.js +0 -6
  163. package/dist/sdk.js +0 -2
  164. package/dist/types/index.js +0 -4
  165. package/dist/types/loader.js +0 -1
  166. package/dist/types/plugin.js +0 -1
  167. package/dist/types/rules.js +0 -1
@@ -1 +0,0 @@
1
- import "node:module";
@@ -1,10 +0,0 @@
1
- import "node:module";
2
- function match(str, patterns) {
3
- if (0 === patterns.length) return false;
4
- return patterns.some((p)=>{
5
- if ('string' == typeof p) return str === p;
6
- if (p instanceof RegExp) return p.test(str);
7
- return false;
8
- });
9
- }
10
- export { match };
@@ -1,52 +0,0 @@
1
- import "node:module";
2
- import { Linter } from "@rsdoctor/shared/types";
3
- import { defineRule } from "../../rule.js";
4
- const title = 'module-mixed-chunks';
5
- const rule = defineRule(()=>({
6
- meta: {
7
- code: 'E1006',
8
- title: title,
9
- category: 'bundle',
10
- severity: Linter.Severity.Warn,
11
- defaultConfig: {
12
- ignore: []
13
- }
14
- },
15
- check ({ moduleGraph, report, ruleConfig }) {
16
- const modules = moduleGraph.getModules();
17
- for (const module of modules){
18
- if (ruleConfig.ignore.some((pattern)=>module.path.includes(pattern))) continue;
19
- const moduleChunks = module.getChunks();
20
- if (0 === moduleChunks.length) continue;
21
- const hasInitial = moduleChunks.some((chunk)=>chunk.initial);
22
- const hasAsync = moduleChunks.some((chunk)=>!chunk.initial);
23
- if (hasInitial && hasAsync) {
24
- const initialChunks = moduleChunks.filter((chunk)=>chunk.initial);
25
- const asyncChunks = moduleChunks.filter((chunk)=>!chunk.initial);
26
- const detail = {
27
- type: title,
28
- module: {
29
- id: module.id,
30
- path: module.path,
31
- identifier: module.identifier
32
- },
33
- initialChunks: initialChunks.map((chunk)=>({
34
- id: chunk.id,
35
- name: chunk.name
36
- })),
37
- asyncChunks: asyncChunks.map((chunk)=>({
38
- id: chunk.id,
39
- name: chunk.name
40
- }))
41
- };
42
- const chunkNames = moduleChunks.map((chunk)=>chunk.name || `chunk-${chunk.id}`).join(', ');
43
- const message = `Module "${module.path}" is included in both initial and async chunks: ${chunkNames}. This should be optimized to avoid code duplication.`;
44
- report({
45
- message,
46
- detail
47
- });
48
- }
49
- }
50
- }
51
- }));
52
- export { rule };
@@ -1 +0,0 @@
1
- import "node:module";
@@ -1,81 +0,0 @@
1
- import "node:module";
2
- import { Linter } from "@rsdoctor/shared/types";
3
- import { defineRule } from "../../rule.js";
4
- const title = 'tree-shaking-side-effects-only';
5
- function isSideEffectDependencyType(dependencyType) {
6
- return 'esm import' === dependencyType.toLowerCase();
7
- }
8
- function isImportSpecifierDependencyType(dependencyType) {
9
- return 'esm import specifier' === dependencyType.toLowerCase();
10
- }
11
- function isStyleFile(modulePath) {
12
- const normalizedPath = modulePath.split('?')[0].split('#')[0].toLowerCase();
13
- return /\.(css|less|sass|scss|styl|stylus|pcss|postcss)$/.test(normalizedPath);
14
- }
15
- function shouldCheckModule(modulePath, include) {
16
- const isNodeModulesModule = modulePath.includes('/node_modules/');
17
- if (!isNodeModulesModule) return true;
18
- return include.some((pattern)=>modulePath.includes(pattern));
19
- }
20
- function getSideEffectsImportConnections(connections, fallbackOriginModule) {
21
- const byOrigin = new Map();
22
- for (const connection of connections){
23
- const originModule = connection.originModule ?? fallbackOriginModule;
24
- const existing = byOrigin.get(originModule);
25
- if (existing) existing.push(connection);
26
- else byOrigin.set(originModule, [
27
- connection
28
- ]);
29
- }
30
- const result = [];
31
- for (const group of byOrigin.values()){
32
- const hasEsmImport = group.some((connection)=>isSideEffectDependencyType(connection.dependencyType));
33
- const hasEsmImportSpecifier = group.some((connection)=>isImportSpecifierDependencyType(connection.dependencyType));
34
- if (hasEsmImport && !hasEsmImportSpecifier) result.push(...group.filter((connection)=>isSideEffectDependencyType(connection.dependencyType)));
35
- }
36
- return result;
37
- }
38
- const rule = defineRule(()=>({
39
- meta: {
40
- code: 'E1007',
41
- title: title,
42
- category: 'bundle',
43
- severity: Linter.Severity.Warn,
44
- defaultConfig: {
45
- ignore: [],
46
- include: []
47
- }
48
- },
49
- check ({ moduleGraph, report, ruleConfig }) {
50
- const precomputed = moduleGraph.getConnectionsOnlyImports();
51
- for (const item of precomputed){
52
- if (isStyleFile(item.modulePath)) continue;
53
- if (ruleConfig.ignore.some((pattern)=>item.modulePath.includes(pattern))) continue;
54
- if (!shouldCheckModule(item.modulePath, ruleConfig.include)) continue;
55
- const module = moduleGraph.getModuleById(item.moduleUkey);
56
- if (!module) continue;
57
- const sideEffectConnections = getSideEffectsImportConnections(item.connections, item.moduleUkey);
58
- if (!sideEffectConnections.length) continue;
59
- const detail = {
60
- type: title,
61
- module: {
62
- id: module.id,
63
- path: module.path,
64
- identifier: module.identifier
65
- },
66
- connections: sideEffectConnections.map((c)=>({
67
- originModule: c.originModule ?? module.id,
68
- dependencyType: c.dependencyType,
69
- userRequest: c.userRequest
70
- }))
71
- };
72
- const importerCount = new Set(sideEffectConnections.map((c)=>c.originModule ?? module.id)).size;
73
- const message = `Module "${item.modulePath}" is only imported for its side effects by ${importerCount} importer(s). This may indicate an unintended tree-shaking failure causing redundant bundle output.`;
74
- report({
75
- message,
76
- detail
77
- });
78
- }
79
- }
80
- }));
81
- export { rule };
@@ -1 +0,0 @@
1
- import "node:module";
@@ -1,10 +0,0 @@
1
- import "node:module";
2
- import { Linter } from "@rsdoctor/shared/types";
3
- function toSeverity(input, defaultLevel) {
4
- if ('off' === input) return Linter.Severity.Ignore;
5
- if ('on' === input) return defaultLevel;
6
- const key = `${input[0].toUpperCase()}${input.slice(1)}`;
7
- return Linter.Severity[key];
8
- }
9
- function noop() {}
10
- export { noop, toSeverity };
package/dist/sdk/index.js DELETED
@@ -1,3 +0,0 @@
1
- import "node:module";
2
- export * from "./sdk/index.js";
3
- export * from "./multiple/index.js";
@@ -1,42 +0,0 @@
1
- import "node:module";
2
- import { RsdoctorPrimarySDK } from "./primary.js";
3
- class RsdoctorSDKController {
4
- get master() {
5
- return this.slaves[0];
6
- }
7
- getLastSdk() {
8
- return this.slaves[this.slaves.length - 1];
9
- }
10
- hasName(name) {
11
- return Boolean(this.slaves.find((item)=>item.name === name));
12
- }
13
- getSeriesData(serverUrl = false) {
14
- return this.slaves.map((item)=>{
15
- const data = {
16
- name: item.name,
17
- path: item.diskManifestPath,
18
- stage: item.stage
19
- };
20
- if (serverUrl) data.origin = item.server.origin;
21
- return data;
22
- });
23
- }
24
- createSlave({ name, stage, extraConfig, type }) {
25
- const slave = new RsdoctorPrimarySDK({
26
- name,
27
- stage,
28
- controller: this,
29
- extraConfig,
30
- type
31
- });
32
- this.slaves.push(slave);
33
- this.slaves.sort((a, b)=>a.stage - b.stage);
34
- return slave;
35
- }
36
- constructor(root = process.cwd()){
37
- this.slaves = [];
38
- this.root = '';
39
- this.root = root;
40
- }
41
- }
42
- export { RsdoctorSDKController };
@@ -1,3 +0,0 @@
1
- import "node:module";
2
- export * from "./controller.js";
3
- export * from "./primary.js";
@@ -1,64 +0,0 @@
1
- import "node:module";
2
- import path from "path";
3
- import { RsdoctorSDK } from "../sdk/index.js";
4
- import { RsdoctorSlaveServer } from "./server.js";
5
- let id = 1;
6
- class RsdoctorPrimarySDK extends RsdoctorSDK {
7
- clearSwitch() {
8
- this.uploadPieces = new Promise((resolve)=>{
9
- this.finishUploadPieceSwitch = resolve;
10
- });
11
- }
12
- get isMaster() {
13
- return this.parent.master === this;
14
- }
15
- async writePieces() {
16
- const { name, parent, isMaster, outputDir, finishUploadPieceSwitch } = this;
17
- this.setOutputDir(isMaster ? outputDir : path.join(parent.master.outputDir, '.slaves', name.replace(/\s+/g, '-')));
18
- await super.writePieces(this.getStoreData());
19
- finishUploadPieceSwitch?.();
20
- }
21
- async writeManifest() {
22
- const { parent, cloudData, dependencies } = this;
23
- if (!dependencies?.length) await Promise.all(this.parent.slaves.filter((item)=>!item.dependencies?.length).map((item)=>item.uploadPieces));
24
- if (cloudData) {
25
- cloudData.name = this.name;
26
- cloudData.series = parent.getSeriesData();
27
- }
28
- const result = await super.writeManifest();
29
- this.clearSwitch();
30
- return result;
31
- }
32
- getSeriesData(serverUrl = false) {
33
- return this.parent.getSeriesData(serverUrl);
34
- }
35
- setName(name) {
36
- this._name = this.parent.hasName(name) ? `${name}-${id}` : name;
37
- }
38
- getManifestData() {
39
- const data = super.getManifestData();
40
- data.name = this.name;
41
- data.series = this.getSeriesData(true);
42
- return data;
43
- }
44
- constructor({ name, stage, controller, extraConfig, type }){
45
- super({
46
- name,
47
- root: controller.root,
48
- config: extraConfig
49
- });
50
- const lastSdk = controller.getLastSdk();
51
- const port = lastSdk ? lastSdk.server.port + 1 : extraConfig?.server?.port ?? this.server.port;
52
- this.id = id++;
53
- this.stage = 'number' == typeof stage ? stage : 1;
54
- this.extraConfig = extraConfig;
55
- this.parent = controller;
56
- this.server = new RsdoctorSlaveServer(this, port, {
57
- cors: extraConfig?.server?.cors
58
- });
59
- this.type = type;
60
- this.setName(name);
61
- this.clearSwitch();
62
- }
63
- }
64
- export { RsdoctorPrimarySDK };
@@ -1,14 +0,0 @@
1
- import "node:module";
2
- import { Server } from "../../build-utils/index.js";
3
- import { RsdoctorServer } from "../server/index.js";
4
- class RsdoctorSlaveServer extends RsdoctorServer {
5
- async openClientPage(...args) {
6
- if (this.sdk.isMaster) return super.openClientPage(...args);
7
- return Promise.resolve();
8
- }
9
- constructor(sdk, port = Server.defaultPort, config){
10
- super(sdk, port, config);
11
- this.sdk = sdk;
12
- }
13
- }
14
- export { RsdoctorSlaveServer };
@@ -1,163 +0,0 @@
1
- import "node:module";
2
- import { Constants, Manifest } from "@rsdoctor/shared/types";
3
- import { EnvInfo, File, Json } from "../../build-utils/index.js";
4
- import node_fs from "node:fs";
5
- import node_path from "node:path";
6
- import { createHash, randomUUID } from "node:crypto";
7
- import node_process from "node:process";
8
- import { AsyncSeriesHook } from "tapable";
9
- import { Algorithm, decycle } from "../../common/index.js";
10
- import { logger } from "../../logger.js";
11
- import { transformDataUrls } from "../utils/index.js";
12
- class SDKCore {
13
- get outputDir() {
14
- return this._outputDir;
15
- }
16
- get name() {
17
- return this._name;
18
- }
19
- async bootstrap() {
20
- const [cpu, memory, nodeVersion, yarnVersion, npmVersion, pnpmVersion] = await Promise.all([
21
- EnvInfo.getCPUInfo(),
22
- EnvInfo.getMemoryInfo(),
23
- EnvInfo.getNodeVersion(),
24
- EnvInfo.getYarnVersion(),
25
- EnvInfo.getNpmVersion(),
26
- EnvInfo.getPnpmVersion()
27
- ]);
28
- this._envinfo = {
29
- ...this._envinfo,
30
- cpu,
31
- memory,
32
- nodeVersion,
33
- yarnVersion,
34
- npmVersion,
35
- pnpmVersion
36
- };
37
- const hash = createHash('md5').update([
38
- this.name,
39
- this.root,
40
- JSON.stringify(this._envinfo),
41
- Date.now()
42
- ].join('_')).digest('hex');
43
- this.setHash(hash);
44
- }
45
- async dispose() {}
46
- setOutputDir(outputDir) {
47
- this._outputDir = outputDir;
48
- }
49
- setName(name) {
50
- this._name = name;
51
- }
52
- setHash(hash) {
53
- this.hash = hash;
54
- }
55
- getHash() {
56
- return this.hash;
57
- }
58
- getClientRoutes() {
59
- return [
60
- ...this._clientRoutes
61
- ];
62
- }
63
- addClientRoutes(routes) {
64
- routes.forEach((route)=>{
65
- this._clientRoutes.add(route);
66
- });
67
- this.onDataReport();
68
- }
69
- async writePieces(storeData, _options) {
70
- const { outputDir } = this;
71
- const manifest = node_path.resolve(outputDir, Constants.RsdoctorOutputManifest);
72
- this.diskManifestPath = manifest;
73
- await File.fse.ensureDir(outputDir);
74
- const urlsPromiseList = [];
75
- for (const key of Object.keys(storeData)){
76
- const data = storeData[key];
77
- if ('object' != typeof data) {
78
- urlsPromiseList.push({
79
- name: key,
80
- files: data
81
- });
82
- continue;
83
- }
84
- const jsonStr = await (async ()=>{
85
- try {
86
- if ('configs' === key) return JSON.stringify(decycle(data));
87
- return JSON.stringify(data);
88
- } catch {
89
- return Json.stringify(data);
90
- }
91
- })();
92
- if (Array.isArray(jsonStr)) {
93
- let fileOffset = 0;
94
- for (const str of jsonStr){
95
- const result = await this.writeToFolder(str, outputDir, key, fileOffset);
96
- fileOffset += result.files.length;
97
- urlsPromiseList.push(result);
98
- }
99
- } else urlsPromiseList.push(this.writeToFolder(jsonStr, outputDir, key));
100
- }
101
- const dataUrls = await Promise.all(urlsPromiseList);
102
- logger.debug(`SDKCore.writePieces extraConfig: ${JSON.stringify(this.extraConfig)}`, '[SDKCore.writePieces]');
103
- this.cloudData = {
104
- client: {
105
- enableRoutes: this.getClientRoutes()
106
- },
107
- data: transformDataUrls(dataUrls)
108
- };
109
- }
110
- async writeManifest() {
111
- const { cloudData: data, diskManifestPath } = this;
112
- const dataStr = JSON.stringify(data, null, 2);
113
- logger.debug(`SDKCore.writeManifest extraConfig: ${this.extraConfig}`, '[SDKCore.writeManifest]');
114
- const dir = node_path.dirname(diskManifestPath);
115
- const base = node_path.basename(diskManifestPath);
116
- const tmpPath = node_path.join(dir, `${base}.${Date.now()}.${randomUUID()}.tmp`);
117
- await File.fse.outputFile(tmpPath, dataStr);
118
- node_fs.renameSync(tmpPath, diskManifestPath);
119
- return diskManifestPath;
120
- }
121
- async saveManifest(data, options) {
122
- await this.writePieces(data, options);
123
- const manifestDiskPath = await this.writeManifest();
124
- await this.hooks.afterSaveManifest.promise({
125
- manifestWithShardingFiles: this.cloudData,
126
- manifestDiskPath
127
- });
128
- return manifestDiskPath;
129
- }
130
- writeToFolder(jsonStr, dir, key, index) {
131
- const sharding = new File.FileSharding(Algorithm.compressText(jsonStr));
132
- const folder = node_path.resolve(dir, key);
133
- const writer = sharding.writeStringToFolder(folder, '', index);
134
- return writer.then((item)=>{
135
- const res = {
136
- name: key,
137
- files: item.map((el)=>({
138
- path: node_path.resolve(folder, el.filename),
139
- basename: el.filename,
140
- content: el.content
141
- }))
142
- };
143
- return res;
144
- });
145
- }
146
- constructor({ name, root }){
147
- this.hooks = {
148
- afterSaveManifest: new AsyncSeriesHook([
149
- 'result'
150
- ])
151
- };
152
- this._envinfo = {};
153
- this._clientRoutes = new Set([
154
- Manifest.RsdoctorManifestClientRoutes.Overall
155
- ]);
156
- this.diskManifestPath = '';
157
- this._name = name;
158
- this.root = root;
159
- this.pid = node_process.pid;
160
- this._outputDir = node_path.join(this.outputDir || this.root, Constants.RsdoctorOutputFolder);
161
- }
162
- }
163
- export { SDKCore };