@rsdoctor/utils 1.1.10 → 1.2.0-beta.1

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 (151) hide show
  1. package/dist/cjs/build/envinfo.js +107 -95
  2. package/dist/cjs/build/file/cache.js +65 -56
  3. package/dist/cjs/build/file/index.js +78 -41
  4. package/dist/cjs/build/file/sharding.js +90 -78
  5. package/dist/cjs/build/index.js +49 -47
  6. package/dist/cjs/build/json.js +91 -98
  7. package/dist/cjs/build/process.js +47 -42
  8. package/dist/cjs/build/server.js +110 -87
  9. package/dist/cjs/common/alerts.js +46 -44
  10. package/dist/cjs/common/algorithm.js +63 -54
  11. package/dist/cjs/common/bundle.js +52 -46
  12. package/dist/cjs/common/crypto.js +47 -46
  13. package/dist/cjs/common/data/index.js +381 -455
  14. package/dist/cjs/common/file.js +44 -0
  15. package/dist/cjs/common/global-config.js +72 -64
  16. package/dist/cjs/common/graph/assets.js +274 -308
  17. package/dist/cjs/common/graph/chunk.js +66 -63
  18. package/dist/cjs/common/graph/dependency.js +42 -32
  19. package/dist/cjs/common/graph/entrypoints.js +33 -25
  20. package/dist/cjs/common/graph/index.js +93 -27
  21. package/dist/cjs/common/graph/modules.js +113 -98
  22. package/dist/cjs/common/index.js +101 -83
  23. package/dist/cjs/common/loader.js +277 -273
  24. package/dist/cjs/common/lodash.js +73 -62
  25. package/dist/cjs/common/manifest.js +57 -59
  26. package/dist/cjs/common/package.js +79 -80
  27. package/dist/cjs/common/plugin.js +78 -73
  28. package/dist/cjs/common/resolver.js +79 -69
  29. package/dist/cjs/common/rspack.js +43 -34
  30. package/dist/cjs/common/summary.js +39 -31
  31. package/dist/cjs/common/time.js +73 -78
  32. package/dist/cjs/common/url.js +44 -36
  33. package/dist/cjs/error/error.js +183 -220
  34. package/dist/cjs/error/index.js +70 -28
  35. package/dist/cjs/error/transform.js +150 -143
  36. package/dist/cjs/error/utils.js +54 -58
  37. package/dist/cjs/index.js +37 -38
  38. package/dist/cjs/logger.js +99 -73
  39. package/dist/cjs/rule-utils/document/document.js +83 -82
  40. package/dist/cjs/rule-utils/document/index.js +75 -23
  41. package/dist/cjs/rule-utils/document/server.js +42 -35
  42. package/dist/cjs/rule-utils/document/types.js +17 -15
  43. package/dist/cjs/rule-utils/index.js +66 -21
  44. package/dist/cjs/rule-utils/parser/asserts.js +129 -147
  45. package/dist/cjs/rule-utils/parser/index.js +84 -25
  46. package/dist/cjs/rule-utils/parser/parser.js +50 -85
  47. package/dist/cjs/rule-utils/parser/types.js +38 -30
  48. package/dist/cjs/rule-utils/parser/utils.js +141 -168
  49. package/dist/esm/build/envinfo.mjs +57 -0
  50. package/dist/esm/build/file/cache.mjs +23 -0
  51. package/dist/esm/build/file/index.mjs +4 -0
  52. package/dist/esm/build/file/sharding.mjs +50 -0
  53. package/dist/esm/build/index.mjs +6 -0
  54. package/dist/esm/build/json.mjs +66 -0
  55. package/dist/esm/build/process.mjs +17 -0
  56. package/dist/esm/build/server.mjs +96 -0
  57. package/dist/esm/common/alerts.mjs +17 -0
  58. package/dist/esm/common/algorithm.mjs +32 -0
  59. package/dist/esm/common/bundle.mjs +22 -0
  60. package/dist/esm/common/crypto.mjs +17 -0
  61. package/dist/esm/common/data/index.mjs +354 -0
  62. package/dist/esm/common/file.mjs +7 -0
  63. package/dist/esm/common/global-config.mjs +32 -0
  64. package/dist/esm/common/graph/assets.mjs +238 -0
  65. package/dist/esm/common/graph/chunk.mjs +32 -0
  66. package/dist/esm/common/graph/dependency.mjs +10 -0
  67. package/dist/esm/common/graph/entrypoints.mjs +4 -0
  68. package/dist/esm/common/graph/index.mjs +5 -0
  69. package/dist/esm/common/graph/modules.mjs +78 -0
  70. package/dist/esm/common/index.mjs +19 -0
  71. package/dist/esm/common/loader.mjs +247 -0
  72. package/dist/esm/common/lodash.mjs +32 -0
  73. package/dist/esm/common/manifest.mjs +30 -0
  74. package/dist/esm/common/package.mjs +56 -0
  75. package/dist/esm/common/plugin.mjs +48 -0
  76. package/dist/esm/common/resolver.mjs +46 -0
  77. package/dist/esm/common/rspack.mjs +9 -0
  78. package/dist/esm/common/summary.mjs +8 -0
  79. package/dist/esm/common/time.mjs +43 -0
  80. package/dist/esm/common/url.mjs +14 -0
  81. package/dist/esm/error/error.mjs +154 -0
  82. package/dist/esm/error/index.mjs +3 -0
  83. package/dist/esm/error/transform.mjs +138 -0
  84. package/dist/esm/error/utils.mjs +22 -0
  85. package/dist/esm/index.mjs +3 -0
  86. package/dist/esm/logger.mjs +50 -0
  87. package/dist/esm/rule-utils/document/document.mjs +58 -0
  88. package/dist/esm/rule-utils/document/index.mjs +3 -0
  89. package/dist/esm/rule-utils/document/server.mjs +12 -0
  90. package/dist/esm/rule-utils/index.mjs +2 -0
  91. package/dist/esm/rule-utils/parser/asserts.mjs +104 -0
  92. package/dist/esm/rule-utils/parser/index.mjs +4 -0
  93. package/dist/esm/rule-utils/parser/parser.mjs +23 -0
  94. package/dist/esm/rule-utils/parser/types.mjs +7 -0
  95. package/dist/esm/rule-utils/parser/utils.mjs +109 -0
  96. package/dist/type/common/file.d.ts +3 -0
  97. package/dist/type/common/file.d.ts.map +1 -0
  98. package/dist/type/common/graph/modules.d.ts +1 -1
  99. package/dist/type/common/graph/modules.d.ts.map +1 -1
  100. package/dist/type/common/index.d.ts +1 -0
  101. package/dist/type/common/index.d.ts.map +1 -1
  102. package/dist/type/logger.d.ts +3 -1
  103. package/dist/type/logger.d.ts.map +1 -1
  104. package/package.json +13 -12
  105. package/dist/esm/build/envinfo.js +0 -75
  106. package/dist/esm/build/file/cache.js +0 -30
  107. package/dist/esm/build/file/index.js +0 -7
  108. package/dist/esm/build/file/sharding.js +0 -50
  109. package/dist/esm/build/index.js +0 -12
  110. package/dist/esm/build/json.js +0 -85
  111. package/dist/esm/build/process.js +0 -24
  112. package/dist/esm/build/server.js +0 -96
  113. package/dist/esm/common/alerts.js +0 -25
  114. package/dist/esm/common/algorithm.js +0 -39
  115. package/dist/esm/common/bundle.js +0 -30
  116. package/dist/esm/common/crypto.js +0 -28
  117. package/dist/esm/common/data/index.js +0 -428
  118. package/dist/esm/common/global-config.js +0 -38
  119. package/dist/esm/common/graph/assets.js +0 -310
  120. package/dist/esm/common/graph/chunk.js +0 -49
  121. package/dist/esm/common/graph/dependency.js +0 -14
  122. package/dist/esm/common/graph/entrypoints.js +0 -6
  123. package/dist/esm/common/graph/index.js +0 -5
  124. package/dist/esm/common/graph/modules.js +0 -90
  125. package/dist/esm/common/index.js +0 -36
  126. package/dist/esm/common/loader.js +0 -279
  127. package/dist/esm/common/lodash.js +0 -49
  128. package/dist/esm/common/manifest.js +0 -46
  129. package/dist/esm/common/package.js +0 -71
  130. package/dist/esm/common/plugin.js +0 -59
  131. package/dist/esm/common/resolver.js +0 -54
  132. package/dist/esm/common/rspack.js +0 -12
  133. package/dist/esm/common/summary.js +0 -10
  134. package/dist/esm/common/time.js +0 -64
  135. package/dist/esm/common/url.js +0 -20
  136. package/dist/esm/error/error.js +0 -202
  137. package/dist/esm/error/index.js +0 -5
  138. package/dist/esm/error/transform.js +0 -141
  139. package/dist/esm/error/utils.js +0 -40
  140. package/dist/esm/index.js +0 -6
  141. package/dist/esm/logger.js +0 -44
  142. package/dist/esm/rule-utils/document/document.js +0 -67
  143. package/dist/esm/rule-utils/document/index.js +0 -3
  144. package/dist/esm/rule-utils/document/server.js +0 -17
  145. package/dist/esm/rule-utils/index.js +0 -2
  146. package/dist/esm/rule-utils/parser/asserts.js +0 -132
  147. package/dist/esm/rule-utils/parser/index.js +0 -4
  148. package/dist/esm/rule-utils/parser/parser.js +0 -58
  149. package/dist/esm/rule-utils/parser/types.js +0 -9
  150. package/dist/esm/rule-utils/parser/utils.js +0 -164
  151. /package/dist/esm/rule-utils/document/{types.js → types.mjs} +0 -0
@@ -0,0 +1,96 @@
1
+ import connect from "connect";
2
+ import http from "http";
3
+ import os from "os";
4
+ import get_port from "get-port";
5
+ import { execSync } from "child_process";
6
+ import { random } from "../common/algorithm.mjs";
7
+ const RESTRICTED_PORTS = [
8
+ 3659,
9
+ 4045,
10
+ 6000,
11
+ 6665,
12
+ 6666,
13
+ 6667,
14
+ 6668,
15
+ 6669
16
+ ];
17
+ function getRandomPort(min, max) {
18
+ let port;
19
+ do port = random(min, max);
20
+ while (RESTRICTED_PORTS.includes(port));
21
+ return port;
22
+ }
23
+ const defaultPort = getRandomPort(3000, 8999);
24
+ async function getPort(expectPort) {
25
+ return get_port({
26
+ port: expectPort
27
+ });
28
+ }
29
+ const createGetPortSyncFunctionString = (expectPort)=>`
30
+ (() => {
31
+ const net = require('net');
32
+
33
+ function getPort(expectPort) {
34
+ return new Promise((resolve, reject) => {
35
+ const server = net.createServer();
36
+ server.unref();
37
+ server.on('error', reject);
38
+ server.listen(expectPort, () => {
39
+ const { port } = server.address();
40
+ server.close(() => {
41
+ resolve(port);
42
+ });
43
+ });
44
+ });
45
+ }
46
+
47
+ async function getAvailablePort(expectPort) {
48
+ let port = expectPort;
49
+ while (true) {
50
+ try {
51
+ const res = await getPort(port);
52
+ return res;
53
+ } catch (error) {
54
+ port += Math.floor(Math.random() * 100 + 1);
55
+ }
56
+ }
57
+ }
58
+
59
+ getAvailablePort(${expectPort}).then(port => process.stdout.write(port.toString()));
60
+ })();
61
+ `.trim();
62
+ function getPortSync(expectPort) {
63
+ const statement = '\n' === os.EOL ? createGetPortSyncFunctionString(expectPort) : createGetPortSyncFunctionString(expectPort).replace(/\n/g, '');
64
+ const port = execSync(`node -e "${statement}"`, {
65
+ encoding: 'utf-8'
66
+ });
67
+ return Number(port);
68
+ }
69
+ function createApp() {
70
+ return connect();
71
+ }
72
+ async function createServer(port) {
73
+ const app = createApp();
74
+ const server = http.createServer(app);
75
+ const res = {
76
+ app,
77
+ server,
78
+ port,
79
+ close () {
80
+ return new Promise((resolve, reject)=>{
81
+ if ('closeAllConnections' in server) server.closeAllConnections();
82
+ if ('closeIdleConnections' in server) server.closeIdleConnections();
83
+ server.close((err)=>{
84
+ if (err) reject(err);
85
+ resolve();
86
+ });
87
+ });
88
+ }
89
+ };
90
+ return new Promise((resolve)=>{
91
+ server.listen(port, ()=>{
92
+ resolve(res);
93
+ });
94
+ });
95
+ }
96
+ export { createApp, createGetPortSyncFunctionString, createServer, defaultPort, getPort, getPortSync };
@@ -0,0 +1,17 @@
1
+ import { relative } from "path";
2
+ function getPackageRelationAlertDetails(modules, dependencies, root, packageDependencies, moduleCodeMap) {
3
+ return packageDependencies.slice().reverse().map((dep)=>{
4
+ const dependency = dependencies.find((item)=>item.id === dep.dependencyId);
5
+ if (!dependency) return null;
6
+ const module = modules.find((item)=>item.id === dependency.module);
7
+ if (!module) return null;
8
+ return {
9
+ group: dep.group,
10
+ module,
11
+ dependency,
12
+ relativePath: relative(root, module.path),
13
+ moduleCode: null == moduleCodeMap ? void 0 : moduleCodeMap[module.id]
14
+ };
15
+ }).filter(Boolean);
16
+ }
17
+ export { getPackageRelationAlertDetails };
@@ -0,0 +1,32 @@
1
+ import { deflateSync, inflateSync } from "zlib";
2
+ import { Buffer } from "buffer";
3
+ import { logger } from "../logger.mjs";
4
+ function mergeIntervals(intervals) {
5
+ intervals.sort((a, b)=>a[0] - b[0]);
6
+ let previous;
7
+ let current;
8
+ const result = [];
9
+ for(let i = 0; i < intervals.length; i++){
10
+ current = intervals[i];
11
+ if (!previous || current[0] > previous[1]) {
12
+ previous = current;
13
+ result.push(current);
14
+ } else previous[1] = Math.max(previous[1], current[1]);
15
+ }
16
+ return result;
17
+ }
18
+ function compressText(input) {
19
+ try {
20
+ return deflateSync(input).toString('base64');
21
+ } catch (e) {
22
+ logger.debug(`compressText error: ${e}`);
23
+ return '';
24
+ }
25
+ }
26
+ function decompressText(input) {
27
+ return inflateSync(Buffer.from(input, 'base64')).toString();
28
+ }
29
+ function random(min, max) {
30
+ return Math.floor(Math.random() * (max - min + 1) + min);
31
+ }
32
+ export { compressText, decompressText, mergeIntervals, random };
@@ -0,0 +1,22 @@
1
+ import { Client } from "@rsdoctor/types";
2
+ const sep = ',';
3
+ function getBundleDiffPageQueryString(files) {
4
+ let qs = encodeURIComponent(files.join(sep));
5
+ if (qs) qs = `?${Client.RsdoctorClientUrlQuery.BundleDiffFiles}=${qs}`;
6
+ return qs;
7
+ }
8
+ function getBundleDiffPageUrl(files) {
9
+ let qs = getBundleDiffPageQueryString(files);
10
+ if ('development' === process.env.NODE_ENV) {
11
+ if ('undefined' != typeof location) {
12
+ const { search = '', origin } = location;
13
+ if (search) qs += `&${search.slice(1)}`;
14
+ return `${origin}${qs}#${Client.RsdoctorClientRoutes.BundleDiff}`;
15
+ }
16
+ }
17
+ return `${qs}#${Client.RsdoctorClientRoutes.BundleDiff}`;
18
+ }
19
+ function parseFilesFromBundlePageUrlQuery(queryValue) {
20
+ return decodeURIComponent(queryValue).split(sep);
21
+ }
22
+ export { getBundleDiffPageQueryString, getBundleDiffPageUrl, parseFilesFromBundlePageUrlQuery };
@@ -0,0 +1,17 @@
1
+ const sep = '!';
2
+ function encode(str) {
3
+ let res = `${str.charCodeAt(0)}`;
4
+ for(let i = 1; i < str.length; i++)res += `${sep}${str.charCodeAt(i)}`;
5
+ return res;
6
+ }
7
+ function decode(str) {
8
+ let res = '';
9
+ let tmp = '';
10
+ for(let i = 0; i < str.length; i++)if (str[i] === sep) {
11
+ res += String.fromCharCode(+tmp);
12
+ tmp = '';
13
+ } else tmp += str[i];
14
+ if (tmp) res += String.fromCharCode(+tmp);
15
+ return res;
16
+ }
17
+ export { decode, encode };
@@ -0,0 +1,354 @@
1
+ import { Constants, Rule, SDK } from "@rsdoctor/types";
2
+ import { getDirectoriesLoaders, getLoaderChartData, getLoaderFileDetails, getLoaderFileFirstInput, getLoaderFileTree, getLoaderFolderStatistics, getLoaderNames } from "../loader.mjs";
3
+ import { getResolverFileDetails, getResolverFileTree } from "../resolver.mjs";
4
+ import { getPluginData, getPluginSummary } from "../plugin.mjs";
5
+ import { getAllBundleData, getAssetDetails, getAssetsSummary, getChunksByModuleId, getEntryPoints, getModuleDetails, getModuleIdsByModulesIds } from "../graph/index.mjs";
6
+ import { getPackageRelationAlertDetails } from "../alerts.mjs";
7
+ import { relative } from "path";
8
+ function _define_property(obj, key, value) {
9
+ if (key in obj) Object.defineProperty(obj, key, {
10
+ value: value,
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true
14
+ });
15
+ else obj[key] = value;
16
+ return obj;
17
+ }
18
+ class APIDataLoader {
19
+ log(...args) {
20
+ console.log(`[${this.constructor.name}]`, ...args);
21
+ }
22
+ loadAPI(...args) {
23
+ const [api, body] = args;
24
+ switch(api){
25
+ case SDK.ServerAPI.API.LoadDataByKey:
26
+ return this.loader.loadData(body.key);
27
+ case SDK.ServerAPI.API.GetProjectInfo:
28
+ return Promise.all([
29
+ this.loader.loadData('root'),
30
+ this.loader.loadData('pid'),
31
+ this.loader.loadData('hash'),
32
+ this.loader.loadData('summary'),
33
+ this.loader.loadData('configs'),
34
+ this.loader.loadData('envinfo'),
35
+ this.loader.loadData('errors')
36
+ ]).then(([root, pid, hash, summary, configs, envinfo, errors])=>({
37
+ root,
38
+ pid,
39
+ hash,
40
+ summary,
41
+ configs,
42
+ envinfo,
43
+ errors
44
+ }));
45
+ case SDK.ServerAPI.API.GetClientRoutes:
46
+ var _window;
47
+ if ('undefined' != typeof window && (null == (_window = window) ? void 0 : _window[Constants.WINDOW_RSDOCTOR_TAG])) return window[Constants.WINDOW_RSDOCTOR_TAG].enableRoutes;
48
+ return this.loader.loadManifest().then((res)=>{
49
+ const { enableRoutes = [] } = res.client || {};
50
+ return enableRoutes;
51
+ });
52
+ case SDK.ServerAPI.API.GetLoaderNames:
53
+ return this.loader.loadData('loader').then((res)=>getLoaderNames(res || []));
54
+ case SDK.ServerAPI.API.GetLayers:
55
+ return this.loader.loadData('moduleGraph').then((res)=>{
56
+ const { layers } = res || {};
57
+ return layers;
58
+ });
59
+ case SDK.ServerAPI.API.GetLoaderChartData:
60
+ return this.loader.loadData('loader').then((res)=>getLoaderChartData(res || []));
61
+ case SDK.ServerAPI.API.GetLoaderFileTree:
62
+ return this.loader.loadData('loader').then((res)=>getLoaderFileTree(res || []));
63
+ case SDK.ServerAPI.API.GetLoaderFileDetails:
64
+ return this.loader.loadData('loader').then((res)=>getLoaderFileDetails(body.path, res || []));
65
+ case SDK.ServerAPI.API.GetLoaderFolderStatistics:
66
+ return this.loader.loadData('loader').then((res)=>getLoaderFolderStatistics(body.folder, res || []));
67
+ case SDK.ServerAPI.API.GetLoaderFileFirstInput:
68
+ return this.loader.loadData('loader').then((res)=>getLoaderFileFirstInput(body.file, res || []));
69
+ case SDK.ServerAPI.API.GetLoaderFileInputAndOutput:
70
+ return this.loader.loadData('loader').then((res)=>getLoaderFileFirstInput(body.file, res || []));
71
+ case SDK.ServerAPI.API.GetResolverFileTree:
72
+ return this.loader.loadData('resolver').then((res)=>getResolverFileTree(res || []));
73
+ case SDK.ServerAPI.API.GetResolverFileDetails:
74
+ return Promise.all([
75
+ this.loader.loadData('resolver'),
76
+ this.loader.loadData('moduleGraph.modules'),
77
+ this.loader.loadData('moduleCodeMap')
78
+ ]).then((res)=>{
79
+ const resolverData = res[0];
80
+ const modules = res[1];
81
+ const moduleCodeMap = res[2];
82
+ return getResolverFileDetails(body.filepath, resolverData || [], modules || [], moduleCodeMap || {});
83
+ });
84
+ case SDK.ServerAPI.API.GetPluginSummary:
85
+ return this.loader.loadData('plugin').then((res)=>getPluginSummary(res || {}));
86
+ case SDK.ServerAPI.API.GetPluginData:
87
+ return this.loader.loadData('plugin').then((res)=>{
88
+ const { hooks, tapNames } = body;
89
+ return getPluginData(res || {}, hooks, tapNames);
90
+ });
91
+ case SDK.ServerAPI.API.GetAssetsSummary:
92
+ return this.loader.loadData('chunkGraph').then((res)=>{
93
+ const { withFileContent = true } = body;
94
+ const { assets = [], chunks = [] } = res || {};
95
+ return getAssetsSummary(assets, chunks, {
96
+ withFileContent
97
+ });
98
+ });
99
+ case SDK.ServerAPI.API.GetAssetDetails:
100
+ return Promise.all([
101
+ this.loader.loadData('chunkGraph'),
102
+ this.loader.loadData('moduleGraph')
103
+ ]).then((res)=>{
104
+ const { assetPath } = body;
105
+ const { assets = [], chunks = [] } = res[0] || {};
106
+ const { modules = [] } = res[1] || {};
107
+ return getAssetDetails(assetPath, assets, chunks, modules);
108
+ });
109
+ case SDK.ServerAPI.API.GetSummaryBundles:
110
+ return Promise.all([
111
+ this.loader.loadData('chunkGraph'),
112
+ this.loader.loadData('moduleGraph')
113
+ ]).then((res)=>{
114
+ const { assets = [], chunks = [] } = res[0] || {};
115
+ const { modules = [] } = res[1] || {};
116
+ return getAllBundleData(assets, chunks, modules, [
117
+ 'id',
118
+ 'path',
119
+ 'size',
120
+ 'kind'
121
+ ]);
122
+ });
123
+ case SDK.ServerAPI.API.GetChunksByModuleId:
124
+ return Promise.all([
125
+ this.loader.loadData('chunkGraph'),
126
+ this.loader.loadData('moduleGraph')
127
+ ]).then((res)=>{
128
+ const { moduleId } = body;
129
+ const { chunks = [] } = res[0] || {};
130
+ const { modules = [] } = res[1] || {};
131
+ return getChunksByModuleId(moduleId, modules, chunks);
132
+ });
133
+ case SDK.ServerAPI.API.GetModuleDetails:
134
+ return Promise.all([
135
+ this.loader.loadData('chunkGraph'),
136
+ this.loader.loadData('moduleGraph')
137
+ ]).then((res)=>{
138
+ const { moduleId } = body;
139
+ const { modules = [], dependencies = [] } = res[1] || {};
140
+ return getModuleDetails(moduleId, modules, dependencies);
141
+ });
142
+ case SDK.ServerAPI.API.GetModulesByModuleIds:
143
+ return this.loader.loadData('moduleGraph').then((res)=>{
144
+ const { moduleIds } = body;
145
+ const { modules = [] } = res || {};
146
+ return getModuleIdsByModulesIds(moduleIds, modules);
147
+ });
148
+ case SDK.ServerAPI.API.GetEntryPoints:
149
+ return Promise.all([
150
+ this.loader.loadData('chunkGraph')
151
+ ]).then((res)=>{
152
+ const [chunkGraph] = res;
153
+ const { entrypoints = [] } = chunkGraph || {};
154
+ return getEntryPoints(entrypoints);
155
+ });
156
+ case SDK.ServerAPI.API.GetModuleCodeByModuleId:
157
+ return this.loader.loadData('moduleCodeMap').then((moduleCodeMap)=>{
158
+ const { moduleId } = body;
159
+ if (moduleCodeMap) return moduleCodeMap[moduleId];
160
+ return {
161
+ source: '',
162
+ transformed: '',
163
+ parsedSource: ''
164
+ };
165
+ });
166
+ case SDK.ServerAPI.API.GetModuleCodeByModuleIds:
167
+ return this.loader.loadData('moduleCodeMap').then((moduleCodeMap)=>{
168
+ const { moduleIds } = body;
169
+ const _moduleCodeData = {};
170
+ if (moduleCodeMap) {
171
+ moduleIds.forEach((id)=>{
172
+ _moduleCodeData[id] = moduleCodeMap[id];
173
+ });
174
+ return _moduleCodeData;
175
+ }
176
+ return [];
177
+ });
178
+ case SDK.ServerAPI.API.GetAllModuleGraph:
179
+ return this.loader.loadData('moduleGraph').then((moduleGraph)=>null == moduleGraph ? void 0 : moduleGraph.modules);
180
+ case SDK.ServerAPI.API.GetSearchModules:
181
+ return Promise.all([
182
+ this.loader.loadData('moduleGraph'),
183
+ this.loader.loadData('chunkGraph')
184
+ ]).then((res)=>{
185
+ const [moduleGraph, chunkGraph] = res;
186
+ const { moduleName } = body;
187
+ if (!moduleName) return [];
188
+ const assetMap = chunkGraph.chunks.reduce((acc, chunk)=>{
189
+ chunk.assets.forEach((asset)=>{
190
+ if (!acc[chunk.id]) acc[chunk.id] = [];
191
+ acc[chunk.id].push(asset);
192
+ });
193
+ return acc;
194
+ }, {});
195
+ const searchedChunksMap = new Map();
196
+ null == moduleGraph || moduleGraph.modules.filter((module)=>{
197
+ if (module.webpackId.includes(moduleName)) module.chunks.forEach((chunk)=>{
198
+ if (searchedChunksMap.has(chunk)) return;
199
+ const assets = assetMap[chunk] || [];
200
+ assets.forEach((asset)=>{
201
+ if (asset.endsWith('.js')) searchedChunksMap.set(chunk, asset);
202
+ });
203
+ });
204
+ });
205
+ return Object.fromEntries(searchedChunksMap);
206
+ });
207
+ case SDK.ServerAPI.API.GetSearchModuleInChunk:
208
+ return Promise.all([
209
+ this.loader.loadData('moduleGraph'),
210
+ this.loader.loadData('root')
211
+ ]).then((res)=>{
212
+ const [moduleGraph, root] = res;
213
+ const { moduleName, chunk } = body;
214
+ if (!moduleName) return [];
215
+ const filteredModules = null == moduleGraph ? void 0 : moduleGraph.modules.filter((module)=>module.webpackId.includes(moduleName) && module.chunks.includes(chunk)).map((filteredModule)=>({
216
+ id: filteredModule.id,
217
+ path: filteredModule.path,
218
+ relativePath: relative(root, filteredModule.path)
219
+ }));
220
+ return filteredModules;
221
+ });
222
+ case SDK.ServerAPI.API.GetAllChunkGraph:
223
+ return this.loader.loadData('chunkGraph').then((chunkGraph)=>null == chunkGraph ? void 0 : chunkGraph.chunks);
224
+ case SDK.ServerAPI.API.GetPackageRelationAlertDetails:
225
+ return Promise.all([
226
+ this.loader.loadData('moduleGraph'),
227
+ this.loader.loadData('errors'),
228
+ this.loader.loadData('root'),
229
+ this.loader.loadData('moduleCodeMap')
230
+ ]).then((res)=>{
231
+ const { id, target } = body;
232
+ const [moduleGraph, errors = [], root = '', moduleCodeMap] = res;
233
+ const { modules = [], dependencies = [] } = moduleGraph || {};
234
+ const { packages = [] } = errors.find((e)=>e.id === id) || {};
235
+ const { dependencies: pkgDependencies = [] } = packages.find((e)=>e.target.name === target.name && e.target.root === target.root && e.target.version === target.version) || {};
236
+ return getPackageRelationAlertDetails(modules, dependencies, root, pkgDependencies, moduleCodeMap || {});
237
+ });
238
+ case SDK.ServerAPI.API.GetOverlayAlerts:
239
+ return this.loader.loadData('errors').then((res)=>(res || []).filter((e)=>e.code === Rule.RuleMessageCodeEnumerated.Overlay));
240
+ case SDK.ServerAPI.API.BundleDiffManifest:
241
+ return this.loader.loadManifest();
242
+ case SDK.ServerAPI.API.GetBundleDiffSummary:
243
+ return Promise.all([
244
+ this.loader.loadManifest(),
245
+ this.loader.loadData('root'),
246
+ this.loader.loadData('hash'),
247
+ this.loader.loadData('errors'),
248
+ this.loader.loadData('chunkGraph'),
249
+ this.loader.loadData('moduleGraph'),
250
+ this.loader.loadData('moduleCodeMap'),
251
+ this.loader.loadData('packageGraph'),
252
+ this.loader.loadData('configs')
253
+ ]).then(([_manifest, root = '', hash = '', errors = {}, chunkGraph = {}, moduleGraph = {}, moduleCodeMap = {}, packageGraph = {}, configs = []])=>{
254
+ var _configs__config_output, _configs__config, _configs_;
255
+ let outputFilename = '';
256
+ if ('string' == typeof (null == (_configs_ = configs[0]) ? void 0 : null == (_configs__config = _configs_.config) ? void 0 : null == (_configs__config_output = _configs__config.output) ? void 0 : _configs__config_output.chunkFilename)) {
257
+ var _configs_1;
258
+ outputFilename = null == (_configs_1 = configs[0]) ? void 0 : _configs_1.config.output.chunkFilename;
259
+ }
260
+ return {
261
+ root,
262
+ hash,
263
+ errors,
264
+ chunkGraph,
265
+ moduleGraph,
266
+ packageGraph,
267
+ outputFilename,
268
+ moduleCodeMap
269
+ };
270
+ });
271
+ case SDK.ServerAPI.API.GetTileReportHtml:
272
+ return this.loader.loadData('otherReports').then((otherReports)=>null == otherReports ? void 0 : otherReports.tileReportHtml);
273
+ case SDK.ServerAPI.API.GetChunkGraph:
274
+ return this.loader.loadData('chunkGraph').then((res)=>{
275
+ const { chunks = [] } = res || {};
276
+ return chunks;
277
+ });
278
+ case SDK.ServerAPI.API.GetAllModuleGraphFilter:
279
+ return this.loader.loadData('moduleGraph').then((moduleGraph)=>null == moduleGraph ? void 0 : moduleGraph.modules.map((m)=>({
280
+ id: m.id,
281
+ webpackId: m.webpackId,
282
+ path: m.path,
283
+ size: m.size,
284
+ chunks: m.chunks,
285
+ kind: m.kind
286
+ })));
287
+ case SDK.ServerAPI.API.GetModuleByName:
288
+ return this.loader.loadData('moduleGraph').then((moduleGraph)=>{
289
+ const { moduleName } = body;
290
+ const { modules = [] } = moduleGraph || {};
291
+ return modules.filter((m)=>m.path.includes(moduleName)).map((m)=>({
292
+ id: m.id,
293
+ path: m.path
294
+ })) || [];
295
+ });
296
+ case SDK.ServerAPI.API.GetModuleIssuerPath:
297
+ return this.loader.loadData('moduleGraph').then((moduleGraph)=>{
298
+ var _modules_find;
299
+ const { moduleId } = body;
300
+ const modules = (null == moduleGraph ? void 0 : moduleGraph.modules) || [];
301
+ const issuerPath = (null == (_modules_find = modules.find((m)=>String(m.id) === moduleId)) ? void 0 : _modules_find.issuerPath) || [];
302
+ if (Array.isArray(issuerPath) && issuerPath.length > 0 && 'number' == typeof issuerPath[0]) return issuerPath.map((id)=>{
303
+ var _modules_find;
304
+ return null == (_modules_find = modules.find((m)=>m.id === id)) ? void 0 : _modules_find.path;
305
+ }).filter(Boolean);
306
+ return issuerPath;
307
+ });
308
+ case SDK.ServerAPI.API.GetPackageInfo:
309
+ return this.loader.loadData('packageGraph').then((packageGraph)=>null == packageGraph ? void 0 : packageGraph.packages);
310
+ case SDK.ServerAPI.API.GetPackageDependency:
311
+ return this.loader.loadData('packageGraph').then((packageGraph)=>(null == packageGraph ? void 0 : packageGraph.dependencies) || []);
312
+ case SDK.ServerAPI.API.GetChunkGraphAI:
313
+ return this.loader.loadData('chunkGraph').then((res)=>{
314
+ const { chunks = [] } = res || {};
315
+ const filteredChunks = chunks.map(({ modules, ...rest })=>rest);
316
+ return filteredChunks;
317
+ });
318
+ case SDK.ServerAPI.API.GetChunkByIdAI:
319
+ return Promise.all([
320
+ this.loader.loadData('chunkGraph'),
321
+ this.loader.loadData('moduleGraph')
322
+ ]).then(([chunkGraph, moduleGraph])=>{
323
+ const { chunks = [] } = chunkGraph || {};
324
+ const { modules = [] } = moduleGraph || {};
325
+ const { chunkId } = body;
326
+ const chunkInfo = chunks.find((c)=>c.id === chunkId);
327
+ if (!chunkInfo) return null;
328
+ const chunkModules = modules.filter((m)=>chunkInfo.modules.includes(m.id)).map((module)=>({
329
+ id: module.id,
330
+ path: module.path,
331
+ size: module.size,
332
+ chunks: module.chunks,
333
+ kind: module.kind,
334
+ issuerPath: module.issuerPath
335
+ }));
336
+ chunkInfo.modulesInfo = chunkModules;
337
+ return chunkInfo;
338
+ });
339
+ case SDK.ServerAPI.API.GetDirectoriesLoaders:
340
+ return Promise.all([
341
+ this.loader.loadData('root'),
342
+ this.loader.loadData('loader')
343
+ ]).then(([root, loaders])=>getDirectoriesLoaders(loaders || [], root || ''));
344
+ default:
345
+ throw new Error(`API not implement: "${api}"`);
346
+ }
347
+ }
348
+ constructor(loader){
349
+ _define_property(this, "loader", void 0);
350
+ this.loader = loader;
351
+ this.loadAPI = this.loadAPI.bind(this);
352
+ }
353
+ }
354
+ export { APIDataLoader };
@@ -0,0 +1,7 @@
1
+ function isStyleExt(path) {
2
+ return /\.(c|le|sa|sc)ss(\?.*)?$/.test(path);
3
+ }
4
+ function isJsExt(path) {
5
+ return /\.(js|ts|jsx|tsx)(\?.*)?$/.test(path);
6
+ }
7
+ export { isJsExt, isStyleExt };
@@ -0,0 +1,32 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import os from "os";
4
+ import { logger } from "../logger.mjs";
5
+ function writeMcpPort(port, builderName) {
6
+ const homeDir = os.homedir();
7
+ const rsdoctorDir = path.join(homeDir, '.cache/rsdoctor');
8
+ const mcpPortFilePath = path.join(rsdoctorDir, 'mcp.json');
9
+ if (!fs.existsSync(rsdoctorDir)) fs.mkdirSync(rsdoctorDir, {
10
+ recursive: true
11
+ });
12
+ let mcpJson = {
13
+ portList: {},
14
+ port: 0
15
+ };
16
+ if (fs.existsSync(mcpPortFilePath)) try {
17
+ mcpJson = JSON.parse(fs.readFileSync(mcpPortFilePath, 'utf8'));
18
+ } catch (error) {
19
+ logger.debug('Failed to parse mcp.json', error);
20
+ }
21
+ if (!mcpJson.portList) mcpJson.portList = {};
22
+ mcpJson.portList[builderName || 'builder'] = port;
23
+ mcpJson.port = port;
24
+ fs.writeFileSync(mcpPortFilePath, JSON.stringify(mcpJson, null, 2), 'utf8');
25
+ }
26
+ function getMcpConfigPath() {
27
+ const homeDir = os.homedir();
28
+ const rsdoctorDir = path.join(homeDir, '.cache/rsdoctor');
29
+ const mcpPortFilePath = path.join(rsdoctorDir, 'mcp.json');
30
+ return mcpPortFilePath;
31
+ }
32
+ export { getMcpConfigPath, writeMcpPort };