@rsdoctor/utils 1.2.2 → 1.2.4-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 (211) hide show
  1. package/compiled/connect/index.d.ts +90 -0
  2. package/compiled/connect/index.js +2427 -0
  3. package/compiled/connect/license +25 -0
  4. package/compiled/connect/package.json +1 -0
  5. package/compiled/filesize/index.d.ts +58 -0
  6. package/compiled/filesize/index.js +255 -0
  7. package/compiled/filesize/license +28 -0
  8. package/compiled/filesize/package.json +1 -0
  9. package/dist/{type/build → build}/envinfo.d.ts +0 -1
  10. package/dist/{type/build → build}/file/cache.d.ts +0 -1
  11. package/dist/build/file/index.d.ts +3 -0
  12. package/dist/{type/build → build}/file/sharding.d.ts +0 -1
  13. package/dist/{type/build → build}/index.d.ts +0 -1
  14. package/dist/{type/build → build}/json.d.ts +0 -1
  15. package/dist/{type/build → build}/process.d.ts +0 -1
  16. package/dist/{type/build → build}/server.d.ts +0 -1
  17. package/dist/build.cjs +1310 -0
  18. package/dist/build.js +343 -0
  19. package/dist/{type/common → common}/alerts.d.ts +0 -1
  20. package/dist/{type/common → common}/algorithm.d.ts +0 -1
  21. package/dist/{type/common → common}/bundle.d.ts +0 -1
  22. package/dist/{type/common → common}/crypto.d.ts +0 -1
  23. package/dist/{type/common → common}/data/index.d.ts +0 -1
  24. package/dist/{type/common → common}/file.d.ts +0 -1
  25. package/dist/{type/common → common}/global-config.d.ts +0 -1
  26. package/dist/{type/common → common}/graph/assets.d.ts +0 -1
  27. package/dist/{type/common → common}/graph/chunk.d.ts +0 -1
  28. package/dist/{type/common → common}/graph/dependency.d.ts +0 -1
  29. package/dist/{type/common → common}/graph/entrypoints.d.ts +0 -1
  30. package/dist/{type/common → common}/graph/index.d.ts +0 -1
  31. package/dist/{type/common → common}/graph/modules.d.ts +0 -1
  32. package/dist/{type/common → common}/index.d.ts +0 -1
  33. package/dist/{type/common → common}/loader.d.ts +0 -1
  34. package/dist/{type/common → common}/lodash.d.ts +0 -1
  35. package/dist/{type/common → common}/manifest.d.ts +0 -1
  36. package/dist/{type/common → common}/package.d.ts +0 -1
  37. package/dist/{type/common → common}/plugin.d.ts +0 -1
  38. package/dist/{type/common → common}/resolver.d.ts +0 -1
  39. package/dist/{type/common → common}/rspack.d.ts +0 -1
  40. package/dist/{type/common → common}/summary.d.ts +0 -1
  41. package/dist/{type/common → common}/time.d.ts +0 -1
  42. package/dist/{type/common → common}/url.d.ts +0 -1
  43. package/dist/common.cjs +1328 -0
  44. package/dist/common.js +1255 -0
  45. package/dist/{type/error → error}/error.d.ts +0 -1
  46. package/dist/{type/error → error}/index.d.ts +0 -1
  47. package/dist/{type/error → error}/transform.d.ts +0 -1
  48. package/dist/{type/error → error}/utils.d.ts +0 -1
  49. package/dist/error.cjs +310 -0
  50. package/dist/error.js +232 -0
  51. package/dist/logger.cjs +82 -0
  52. package/dist/{type/logger.d.ts → logger.d.ts} +0 -1
  53. package/dist/{esm/logger.mjs → logger.js} +8 -13
  54. package/dist/{type/rule-utils → rule-utils}/document/document.d.ts +0 -1
  55. package/dist/{type/rule-utils → rule-utils}/document/index.d.ts +0 -1
  56. package/dist/{type/rule-utils → rule-utils}/document/server.d.ts +0 -1
  57. package/dist/{type/rule-utils → rule-utils}/document/types.d.ts +0 -1
  58. package/dist/{type/rule-utils → rule-utils}/index.d.ts +0 -1
  59. package/dist/{type/rule-utils → rule-utils}/parser/asserts.d.ts +0 -1
  60. package/dist/{type/rule-utils → rule-utils}/parser/index.d.ts +0 -1
  61. package/dist/{type/rule-utils → rule-utils}/parser/parser.d.ts +0 -1
  62. package/dist/{type/rule-utils → rule-utils}/parser/types.d.ts +0 -1
  63. package/dist/{type/rule-utils → rule-utils}/parser/utils.d.ts +0 -1
  64. package/dist/ruleUtils.cjs +320 -0
  65. package/dist/ruleUtils.js +256 -0
  66. package/package.json +35 -39
  67. package/dist/cjs/build/envinfo.js +0 -121
  68. package/dist/cjs/build/file/cache.js +0 -76
  69. package/dist/cjs/build/file/index.js +0 -81
  70. package/dist/cjs/build/file/sharding.js +0 -96
  71. package/dist/cjs/build/index.js +0 -52
  72. package/dist/cjs/build/json.js +0 -103
  73. package/dist/cjs/build/process.js +0 -54
  74. package/dist/cjs/build/server.js +0 -158
  75. package/dist/cjs/common/alerts.js +0 -51
  76. package/dist/cjs/common/algorithm.js +0 -75
  77. package/dist/cjs/common/bundle.js +0 -62
  78. package/dist/cjs/common/crypto.js +0 -54
  79. package/dist/cjs/common/data/index.js +0 -396
  80. package/dist/cjs/common/file.js +0 -44
  81. package/dist/cjs/common/global-config.js +0 -81
  82. package/dist/cjs/common/graph/assets.js +0 -314
  83. package/dist/cjs/common/graph/chunk.js +0 -81
  84. package/dist/cjs/common/graph/dependency.js +0 -50
  85. package/dist/cjs/common/graph/entrypoints.js +0 -38
  86. package/dist/cjs/common/graph/index.js +0 -96
  87. package/dist/cjs/common/graph/modules.js +0 -133
  88. package/dist/cjs/common/index.js +0 -104
  89. package/dist/cjs/common/loader.js +0 -320
  90. package/dist/cjs/common/lodash.js +0 -93
  91. package/dist/cjs/common/manifest.js +0 -70
  92. package/dist/cjs/common/package.js +0 -96
  93. package/dist/cjs/common/plugin.js +0 -91
  94. package/dist/cjs/common/resolver.js +0 -92
  95. package/dist/cjs/common/rspack.js +0 -65
  96. package/dist/cjs/common/summary.js +0 -42
  97. package/dist/cjs/common/time.js +0 -86
  98. package/dist/cjs/common/url.js +0 -54
  99. package/dist/cjs/error/error.js +0 -199
  100. package/dist/cjs/error/index.js +0 -73
  101. package/dist/cjs/error/transform.js +0 -182
  102. package/dist/cjs/error/utils.js +0 -62
  103. package/dist/cjs/index.js +0 -40
  104. package/dist/cjs/logger.js +0 -106
  105. package/dist/cjs/rule-utils/document/document.js +0 -92
  106. package/dist/cjs/rule-utils/document/index.js +0 -78
  107. package/dist/cjs/rule-utils/document/server.js +0 -49
  108. package/dist/cjs/rule-utils/document/types.js +0 -18
  109. package/dist/cjs/rule-utils/index.js +0 -69
  110. package/dist/cjs/rule-utils/parser/asserts.js +0 -138
  111. package/dist/cjs/rule-utils/parser/index.js +0 -87
  112. package/dist/cjs/rule-utils/parser/parser.js +0 -57
  113. package/dist/cjs/rule-utils/parser/types.js +0 -41
  114. package/dist/cjs/rule-utils/parser/utils.js +0 -170
  115. package/dist/esm/build/envinfo.mjs +0 -57
  116. package/dist/esm/build/file/cache.mjs +0 -23
  117. package/dist/esm/build/file/index.mjs +0 -4
  118. package/dist/esm/build/file/sharding.mjs +0 -50
  119. package/dist/esm/build/index.mjs +0 -6
  120. package/dist/esm/build/json.mjs +0 -66
  121. package/dist/esm/build/process.mjs +0 -17
  122. package/dist/esm/build/server.mjs +0 -96
  123. package/dist/esm/common/alerts.mjs +0 -17
  124. package/dist/esm/common/algorithm.mjs +0 -32
  125. package/dist/esm/common/bundle.mjs +0 -22
  126. package/dist/esm/common/crypto.mjs +0 -17
  127. package/dist/esm/common/data/index.mjs +0 -362
  128. package/dist/esm/common/file.mjs +0 -7
  129. package/dist/esm/common/global-config.mjs +0 -32
  130. package/dist/esm/common/graph/assets.mjs +0 -238
  131. package/dist/esm/common/graph/chunk.mjs +0 -32
  132. package/dist/esm/common/graph/dependency.mjs +0 -10
  133. package/dist/esm/common/graph/entrypoints.mjs +0 -4
  134. package/dist/esm/common/graph/index.mjs +0 -5
  135. package/dist/esm/common/graph/modules.mjs +0 -78
  136. package/dist/esm/common/index.mjs +0 -19
  137. package/dist/esm/common/loader.mjs +0 -247
  138. package/dist/esm/common/lodash.mjs +0 -32
  139. package/dist/esm/common/manifest.mjs +0 -30
  140. package/dist/esm/common/package.mjs +0 -56
  141. package/dist/esm/common/plugin.mjs +0 -48
  142. package/dist/esm/common/resolver.mjs +0 -46
  143. package/dist/esm/common/rspack.mjs +0 -25
  144. package/dist/esm/common/summary.mjs +0 -8
  145. package/dist/esm/common/time.mjs +0 -43
  146. package/dist/esm/common/url.mjs +0 -14
  147. package/dist/esm/error/error.mjs +0 -154
  148. package/dist/esm/error/index.mjs +0 -3
  149. package/dist/esm/error/transform.mjs +0 -138
  150. package/dist/esm/error/utils.mjs +0 -22
  151. package/dist/esm/index.mjs +0 -3
  152. package/dist/esm/rule-utils/document/document.mjs +0 -58
  153. package/dist/esm/rule-utils/document/index.mjs +0 -3
  154. package/dist/esm/rule-utils/document/server.mjs +0 -12
  155. package/dist/esm/rule-utils/document/types.mjs +0 -0
  156. package/dist/esm/rule-utils/index.mjs +0 -2
  157. package/dist/esm/rule-utils/parser/asserts.mjs +0 -104
  158. package/dist/esm/rule-utils/parser/index.mjs +0 -4
  159. package/dist/esm/rule-utils/parser/parser.mjs +0 -23
  160. package/dist/esm/rule-utils/parser/types.mjs +0 -7
  161. package/dist/esm/rule-utils/parser/utils.mjs +0 -109
  162. package/dist/type/build/envinfo.d.ts.map +0 -1
  163. package/dist/type/build/file/cache.d.ts.map +0 -1
  164. package/dist/type/build/file/index.d.ts +0 -4
  165. package/dist/type/build/file/index.d.ts.map +0 -1
  166. package/dist/type/build/file/sharding.d.ts.map +0 -1
  167. package/dist/type/build/index.d.ts.map +0 -1
  168. package/dist/type/build/json.d.ts.map +0 -1
  169. package/dist/type/build/process.d.ts.map +0 -1
  170. package/dist/type/build/server.d.ts.map +0 -1
  171. package/dist/type/common/alerts.d.ts.map +0 -1
  172. package/dist/type/common/algorithm.d.ts.map +0 -1
  173. package/dist/type/common/bundle.d.ts.map +0 -1
  174. package/dist/type/common/crypto.d.ts.map +0 -1
  175. package/dist/type/common/data/index.d.ts.map +0 -1
  176. package/dist/type/common/file.d.ts.map +0 -1
  177. package/dist/type/common/global-config.d.ts.map +0 -1
  178. package/dist/type/common/graph/assets.d.ts.map +0 -1
  179. package/dist/type/common/graph/chunk.d.ts.map +0 -1
  180. package/dist/type/common/graph/dependency.d.ts.map +0 -1
  181. package/dist/type/common/graph/entrypoints.d.ts.map +0 -1
  182. package/dist/type/common/graph/index.d.ts.map +0 -1
  183. package/dist/type/common/graph/modules.d.ts.map +0 -1
  184. package/dist/type/common/index.d.ts.map +0 -1
  185. package/dist/type/common/loader.d.ts.map +0 -1
  186. package/dist/type/common/lodash.d.ts.map +0 -1
  187. package/dist/type/common/manifest.d.ts.map +0 -1
  188. package/dist/type/common/package.d.ts.map +0 -1
  189. package/dist/type/common/plugin.d.ts.map +0 -1
  190. package/dist/type/common/resolver.d.ts.map +0 -1
  191. package/dist/type/common/rspack.d.ts.map +0 -1
  192. package/dist/type/common/summary.d.ts.map +0 -1
  193. package/dist/type/common/time.d.ts.map +0 -1
  194. package/dist/type/common/url.d.ts.map +0 -1
  195. package/dist/type/error/error.d.ts.map +0 -1
  196. package/dist/type/error/index.d.ts.map +0 -1
  197. package/dist/type/error/transform.d.ts.map +0 -1
  198. package/dist/type/error/utils.d.ts.map +0 -1
  199. package/dist/type/index.d.ts +0 -3
  200. package/dist/type/index.d.ts.map +0 -1
  201. package/dist/type/logger.d.ts.map +0 -1
  202. package/dist/type/rule-utils/document/document.d.ts.map +0 -1
  203. package/dist/type/rule-utils/document/index.d.ts.map +0 -1
  204. package/dist/type/rule-utils/document/server.d.ts.map +0 -1
  205. package/dist/type/rule-utils/document/types.d.ts.map +0 -1
  206. package/dist/type/rule-utils/index.d.ts.map +0 -1
  207. package/dist/type/rule-utils/parser/asserts.d.ts.map +0 -1
  208. package/dist/type/rule-utils/parser/index.d.ts.map +0 -1
  209. package/dist/type/rule-utils/parser/parser.d.ts.map +0 -1
  210. package/dist/type/rule-utils/parser/types.d.ts.map +0 -1
  211. package/dist/type/rule-utils/parser/utils.d.ts.map +0 -1
@@ -1,362 +0,0 @@
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
- import { checkSourceMapSupport } from "../rspack.mjs";
9
- function _define_property(obj, key, value) {
10
- if (key in obj) Object.defineProperty(obj, key, {
11
- value: value,
12
- enumerable: true,
13
- configurable: true,
14
- writable: true
15
- });
16
- else obj[key] = value;
17
- return obj;
18
- }
19
- class APIDataLoader {
20
- log(...args) {
21
- console.log(`[${this.constructor.name}]`, ...args);
22
- }
23
- loadAPI(...args) {
24
- const [api, body] = args;
25
- switch(api){
26
- case SDK.ServerAPI.API.LoadDataByKey:
27
- return this.loader.loadData(body.key);
28
- case SDK.ServerAPI.API.GetProjectInfo:
29
- return Promise.all([
30
- this.loader.loadData('root'),
31
- this.loader.loadData('pid'),
32
- this.loader.loadData('hash'),
33
- this.loader.loadData('summary'),
34
- this.loader.loadData('configs'),
35
- this.loader.loadData('envinfo'),
36
- this.loader.loadData('errors')
37
- ]).then(([root, pid, hash, summary, configs, envinfo, errors])=>({
38
- root,
39
- pid,
40
- hash,
41
- summary,
42
- configs,
43
- envinfo,
44
- errors
45
- }));
46
- case SDK.ServerAPI.API.GetClientRoutes:
47
- var _window;
48
- if ('undefined' != typeof window && (null == (_window = window) ? void 0 : _window[Constants.WINDOW_RSDOCTOR_TAG])) return window[Constants.WINDOW_RSDOCTOR_TAG].enableRoutes;
49
- return this.loader.loadManifest().then((res)=>{
50
- const { enableRoutes = [] } = res.client || {};
51
- return enableRoutes;
52
- });
53
- case SDK.ServerAPI.API.GetLoaderNames:
54
- return this.loader.loadData('loader').then((res)=>getLoaderNames(res || []));
55
- case SDK.ServerAPI.API.GetLayers:
56
- return this.loader.loadData('moduleGraph').then((res)=>{
57
- const { layers } = res || {};
58
- return layers;
59
- });
60
- case SDK.ServerAPI.API.GetLoaderChartData:
61
- return this.loader.loadData('loader').then((res)=>getLoaderChartData(res || []));
62
- case SDK.ServerAPI.API.GetLoaderFileTree:
63
- return this.loader.loadData('loader').then((res)=>getLoaderFileTree(res || []));
64
- case SDK.ServerAPI.API.GetLoaderFileDetails:
65
- return this.loader.loadData('loader').then((res)=>getLoaderFileDetails(body.path, res || []));
66
- case SDK.ServerAPI.API.GetLoaderFolderStatistics:
67
- return this.loader.loadData('loader').then((res)=>getLoaderFolderStatistics(body.folder, res || []));
68
- case SDK.ServerAPI.API.GetLoaderFileFirstInput:
69
- return this.loader.loadData('loader').then((res)=>getLoaderFileFirstInput(body.file, res || []));
70
- case SDK.ServerAPI.API.GetLoaderFileInputAndOutput:
71
- return this.loader.loadData('loader').then((res)=>getLoaderFileFirstInput(body.file, res || []));
72
- case SDK.ServerAPI.API.GetResolverFileTree:
73
- return this.loader.loadData('resolver').then((res)=>getResolverFileTree(res || []));
74
- case SDK.ServerAPI.API.GetResolverFileDetails:
75
- return Promise.all([
76
- this.loader.loadData('resolver'),
77
- this.loader.loadData('moduleGraph.modules'),
78
- this.loader.loadData('moduleCodeMap')
79
- ]).then((res)=>{
80
- const resolverData = res[0];
81
- const modules = res[1];
82
- const moduleCodeMap = res[2];
83
- return getResolverFileDetails(body.filepath, resolverData || [], modules || [], moduleCodeMap || {});
84
- });
85
- case SDK.ServerAPI.API.GetPluginSummary:
86
- return this.loader.loadData('plugin').then((res)=>getPluginSummary(res || {}));
87
- case SDK.ServerAPI.API.GetPluginData:
88
- return this.loader.loadData('plugin').then((res)=>{
89
- const { hooks, tapNames } = body;
90
- return getPluginData(res || {}, hooks, tapNames);
91
- });
92
- case SDK.ServerAPI.API.GetAssetsSummary:
93
- return this.loader.loadData('chunkGraph').then((res)=>{
94
- const { withFileContent = true } = body;
95
- const { assets = [], chunks = [] } = res || {};
96
- return getAssetsSummary(assets, chunks, {
97
- withFileContent
98
- });
99
- });
100
- case SDK.ServerAPI.API.GetAssetDetails:
101
- return Promise.all([
102
- this.loader.loadData('chunkGraph'),
103
- this.loader.loadData('moduleGraph'),
104
- this.loader.loadData('configs')
105
- ]).then((res)=>{
106
- const { assetPath } = body;
107
- const configs = res[2] || [];
108
- const { isRspack, hasSourceMap } = checkSourceMapSupport(configs);
109
- const { assets = [], chunks = [] } = res[0] || {};
110
- const { modules = [] } = res[1] || {};
111
- const checkModules = (module)=>{
112
- if (0 === module.size.parsedSize) return false;
113
- return true;
114
- };
115
- return getAssetDetails(assetPath, assets, chunks, modules, isRspack || hasSourceMap ? checkModules : ()=>true);
116
- });
117
- case SDK.ServerAPI.API.GetSummaryBundles:
118
- return Promise.all([
119
- this.loader.loadData('chunkGraph'),
120
- this.loader.loadData('moduleGraph')
121
- ]).then((res)=>{
122
- const { assets = [], chunks = [] } = res[0] || {};
123
- const { modules = [] } = res[1] || {};
124
- return getAllBundleData(assets, chunks, modules, [
125
- 'id',
126
- 'path',
127
- 'size',
128
- 'kind'
129
- ]);
130
- });
131
- case SDK.ServerAPI.API.GetChunksByModuleId:
132
- return Promise.all([
133
- this.loader.loadData('chunkGraph'),
134
- this.loader.loadData('moduleGraph')
135
- ]).then((res)=>{
136
- const { moduleId } = body;
137
- const { chunks = [] } = res[0] || {};
138
- const { modules = [] } = res[1] || {};
139
- return getChunksByModuleId(moduleId, modules, chunks);
140
- });
141
- case SDK.ServerAPI.API.GetModuleDetails:
142
- return Promise.all([
143
- this.loader.loadData('chunkGraph'),
144
- this.loader.loadData('moduleGraph')
145
- ]).then((res)=>{
146
- const { moduleId } = body;
147
- const { modules = [], dependencies = [] } = res[1] || {};
148
- return getModuleDetails(moduleId, modules, dependencies);
149
- });
150
- case SDK.ServerAPI.API.GetModulesByModuleIds:
151
- return this.loader.loadData('moduleGraph').then((res)=>{
152
- const { moduleIds } = body;
153
- const { modules = [] } = res || {};
154
- return getModuleIdsByModulesIds(moduleIds, modules);
155
- });
156
- case SDK.ServerAPI.API.GetEntryPoints:
157
- return Promise.all([
158
- this.loader.loadData('chunkGraph')
159
- ]).then((res)=>{
160
- const [chunkGraph] = res;
161
- const { entrypoints = [] } = chunkGraph || {};
162
- return getEntryPoints(entrypoints);
163
- });
164
- case SDK.ServerAPI.API.GetModuleCodeByModuleId:
165
- return this.loader.loadData('moduleCodeMap').then((moduleCodeMap)=>{
166
- const { moduleId } = body;
167
- if (moduleCodeMap) return moduleCodeMap[moduleId];
168
- return {
169
- source: '',
170
- transformed: '',
171
- parsedSource: ''
172
- };
173
- });
174
- case SDK.ServerAPI.API.GetModuleCodeByModuleIds:
175
- return this.loader.loadData('moduleCodeMap').then((moduleCodeMap)=>{
176
- const { moduleIds } = body;
177
- const _moduleCodeData = {};
178
- if (moduleCodeMap) {
179
- moduleIds.forEach((id)=>{
180
- _moduleCodeData[id] = moduleCodeMap[id];
181
- });
182
- return _moduleCodeData;
183
- }
184
- return [];
185
- });
186
- case SDK.ServerAPI.API.GetAllModuleGraph:
187
- return this.loader.loadData('moduleGraph').then((moduleGraph)=>null == moduleGraph ? void 0 : moduleGraph.modules);
188
- case SDK.ServerAPI.API.GetSearchModules:
189
- return Promise.all([
190
- this.loader.loadData('moduleGraph'),
191
- this.loader.loadData('chunkGraph')
192
- ]).then((res)=>{
193
- const [moduleGraph, chunkGraph] = res;
194
- const { moduleName } = body;
195
- if (!moduleName) return [];
196
- const assetMap = chunkGraph.chunks.reduce((acc, chunk)=>{
197
- chunk.assets.forEach((asset)=>{
198
- if (!acc[chunk.id]) acc[chunk.id] = [];
199
- acc[chunk.id].push(asset);
200
- });
201
- return acc;
202
- }, {});
203
- const searchedChunksMap = new Map();
204
- null == moduleGraph || moduleGraph.modules.filter((module)=>{
205
- if (module.webpackId.includes(moduleName)) module.chunks.forEach((chunk)=>{
206
- if (searchedChunksMap.has(chunk)) return;
207
- const assets = assetMap[chunk] || [];
208
- assets.forEach((asset)=>{
209
- if (asset.endsWith('.js')) searchedChunksMap.set(chunk, asset);
210
- });
211
- });
212
- });
213
- return Object.fromEntries(searchedChunksMap);
214
- });
215
- case SDK.ServerAPI.API.GetSearchModuleInChunk:
216
- return Promise.all([
217
- this.loader.loadData('moduleGraph'),
218
- this.loader.loadData('root')
219
- ]).then((res)=>{
220
- const [moduleGraph, root] = res;
221
- const { moduleName, chunk } = body;
222
- if (!moduleName) return [];
223
- const filteredModules = null == moduleGraph ? void 0 : moduleGraph.modules.filter((module)=>module.webpackId.includes(moduleName) && module.chunks.includes(chunk)).map((filteredModule)=>({
224
- id: filteredModule.id,
225
- path: filteredModule.path,
226
- relativePath: relative(root, filteredModule.path)
227
- }));
228
- return filteredModules;
229
- });
230
- case SDK.ServerAPI.API.GetAllChunkGraph:
231
- return this.loader.loadData('chunkGraph').then((chunkGraph)=>null == chunkGraph ? void 0 : chunkGraph.chunks);
232
- case SDK.ServerAPI.API.GetPackageRelationAlertDetails:
233
- return Promise.all([
234
- this.loader.loadData('moduleGraph'),
235
- this.loader.loadData('errors'),
236
- this.loader.loadData('root'),
237
- this.loader.loadData('moduleCodeMap')
238
- ]).then((res)=>{
239
- const { id, target } = body;
240
- const [moduleGraph, errors = [], root = '', moduleCodeMap] = res;
241
- const { modules = [], dependencies = [] } = moduleGraph || {};
242
- const { packages = [] } = errors.find((e)=>e.id === id) || {};
243
- const { dependencies: pkgDependencies = [] } = packages.find((e)=>e.target.name === target.name && e.target.root === target.root && e.target.version === target.version) || {};
244
- return getPackageRelationAlertDetails(modules, dependencies, root, pkgDependencies, moduleCodeMap || {});
245
- });
246
- case SDK.ServerAPI.API.GetOverlayAlerts:
247
- return this.loader.loadData('errors').then((res)=>(res || []).filter((e)=>e.code === Rule.RuleMessageCodeEnumerated.Overlay));
248
- case SDK.ServerAPI.API.BundleDiffManifest:
249
- return this.loader.loadManifest();
250
- case SDK.ServerAPI.API.GetBundleDiffSummary:
251
- return Promise.all([
252
- this.loader.loadManifest(),
253
- this.loader.loadData('root'),
254
- this.loader.loadData('hash'),
255
- this.loader.loadData('errors'),
256
- this.loader.loadData('chunkGraph'),
257
- this.loader.loadData('moduleGraph'),
258
- this.loader.loadData('moduleCodeMap'),
259
- this.loader.loadData('packageGraph'),
260
- this.loader.loadData('configs')
261
- ]).then(([_manifest, root = '', hash = '', errors = {}, chunkGraph = {}, moduleGraph = {}, moduleCodeMap = {}, packageGraph = {}, configs = []])=>{
262
- var _configs__config_output, _configs__config, _configs_;
263
- let outputFilename = '';
264
- 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)) {
265
- var _configs_1;
266
- outputFilename = null == (_configs_1 = configs[0]) ? void 0 : _configs_1.config.output.chunkFilename;
267
- }
268
- return {
269
- root,
270
- hash,
271
- errors,
272
- chunkGraph,
273
- moduleGraph,
274
- packageGraph,
275
- outputFilename,
276
- moduleCodeMap
277
- };
278
- });
279
- case SDK.ServerAPI.API.GetTileReportHtml:
280
- return this.loader.loadData('otherReports').then((otherReports)=>null == otherReports ? void 0 : otherReports.tileReportHtml);
281
- case SDK.ServerAPI.API.GetChunkGraph:
282
- return this.loader.loadData('chunkGraph').then((res)=>{
283
- const { chunks = [] } = res || {};
284
- return chunks;
285
- });
286
- case SDK.ServerAPI.API.GetAllModuleGraphFilter:
287
- return this.loader.loadData('moduleGraph').then((moduleGraph)=>null == moduleGraph ? void 0 : moduleGraph.modules.map((m)=>({
288
- id: m.id,
289
- webpackId: m.webpackId,
290
- path: m.path,
291
- size: m.size,
292
- chunks: m.chunks,
293
- kind: m.kind
294
- })));
295
- case SDK.ServerAPI.API.GetModuleByName:
296
- return this.loader.loadData('moduleGraph').then((moduleGraph)=>{
297
- const { moduleName } = body;
298
- const { modules = [] } = moduleGraph || {};
299
- return modules.filter((m)=>m.path.includes(moduleName)).map((m)=>({
300
- id: m.id,
301
- path: m.path
302
- })) || [];
303
- });
304
- case SDK.ServerAPI.API.GetModuleIssuerPath:
305
- return this.loader.loadData('moduleGraph').then((moduleGraph)=>{
306
- var _modules_find;
307
- const { moduleId } = body;
308
- const modules = (null == moduleGraph ? void 0 : moduleGraph.modules) || [];
309
- const issuerPath = (null == (_modules_find = modules.find((m)=>String(m.id) === moduleId)) ? void 0 : _modules_find.issuerPath) || [];
310
- if (Array.isArray(issuerPath) && issuerPath.length > 0 && 'number' == typeof issuerPath[0]) return issuerPath.map((id)=>{
311
- var _modules_find;
312
- return null == (_modules_find = modules.find((m)=>m.id === id)) ? void 0 : _modules_find.path;
313
- }).filter(Boolean);
314
- return issuerPath;
315
- });
316
- case SDK.ServerAPI.API.GetPackageInfo:
317
- return this.loader.loadData('packageGraph').then((packageGraph)=>null == packageGraph ? void 0 : packageGraph.packages);
318
- case SDK.ServerAPI.API.GetPackageDependency:
319
- return this.loader.loadData('packageGraph').then((packageGraph)=>(null == packageGraph ? void 0 : packageGraph.dependencies) || []);
320
- case SDK.ServerAPI.API.GetChunkGraphAI:
321
- return this.loader.loadData('chunkGraph').then((res)=>{
322
- const { chunks = [] } = res || {};
323
- const filteredChunks = chunks.map(({ modules, ...rest })=>rest);
324
- return filteredChunks;
325
- });
326
- case SDK.ServerAPI.API.GetChunkByIdAI:
327
- return Promise.all([
328
- this.loader.loadData('chunkGraph'),
329
- this.loader.loadData('moduleGraph')
330
- ]).then(([chunkGraph, moduleGraph])=>{
331
- const { chunks = [] } = chunkGraph || {};
332
- const { modules = [] } = moduleGraph || {};
333
- const { chunkId } = body;
334
- const chunkInfo = chunks.find((c)=>c.id === chunkId);
335
- if (!chunkInfo) return null;
336
- const chunkModules = modules.filter((m)=>chunkInfo.modules.includes(m.id)).map((module)=>({
337
- id: module.id,
338
- path: module.path,
339
- size: module.size,
340
- chunks: module.chunks,
341
- kind: module.kind,
342
- issuerPath: module.issuerPath
343
- }));
344
- chunkInfo.modulesInfo = chunkModules;
345
- return chunkInfo;
346
- });
347
- case SDK.ServerAPI.API.GetDirectoriesLoaders:
348
- return Promise.all([
349
- this.loader.loadData('root'),
350
- this.loader.loadData('loader')
351
- ]).then(([root, loaders])=>getDirectoriesLoaders(loaders || [], root || ''));
352
- default:
353
- throw new Error(`API not implement: "${api}"`);
354
- }
355
- }
356
- constructor(loader){
357
- _define_property(this, "loader", void 0);
358
- this.loader = loader;
359
- this.loadAPI = this.loadAPI.bind(this);
360
- }
361
- }
362
- export { APIDataLoader };
@@ -1,7 +0,0 @@
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 };
@@ -1,32 +0,0 @@
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 };
@@ -1,238 +0,0 @@
1
- import { Client, Constants } from "@rsdoctor/types";
2
- import { getChunksByAsset } from "./chunk.mjs";
3
- import { getModulesByAsset } from "./modules.mjs";
4
- const EXT = 'js|css|html';
5
- const hashPattern = /[a-z|A-Z|0-9]{4,32}/;
6
- const hashSeparatorPattern = /[-|.]/;
7
- const fileExtensionPattern = /(?:\.[a-z|A-Z|0-9]{2,}){1,}/;
8
- const filenamePattern = new RegExp(`(.*)${hashSeparatorPattern.source}${hashPattern.source}(${fileExtensionPattern.source})$`);
9
- function formatAssetName(assetName, fileConfig) {
10
- var _splitFilesList_;
11
- const splitFilesList = null == fileConfig ? void 0 : fileConfig.split('.');
12
- let outputFileTailName = '';
13
- let unHashedFileName = assetName;
14
- if ((null == splitFilesList ? void 0 : splitFilesList.length) && splitFilesList.length >= 3 && (null == (_splitFilesList_ = splitFilesList[splitFilesList.length - 2]) ? void 0 : _splitFilesList_.indexOf('[')) < 0 && EXT.indexOf(splitFilesList[splitFilesList.length - 1]) > -1) {
15
- outputFileTailName = splitFilesList[splitFilesList.length - 2];
16
- const _regPattern = /(.*)(\.[a-f0-9]{4,32})([^.]*.[^.]+){2,}/g;
17
- unHashedFileName = assetName.replace(_regPattern, '$1');
18
- return `${unHashedFileName}.${outputFileTailName}.${assetName.substring(assetName.lastIndexOf('.') + 1)}`;
19
- }
20
- return assetName.replace(filenamePattern, '$1$2');
21
- }
22
- function isAssetMatchExtension(asset, ext) {
23
- return asset.path.slice(-ext.length) === ext || extname(asset.path) === ext;
24
- }
25
- function isAssetMatchExtensions(asset, exts) {
26
- if (!exts.length) return false;
27
- return exts.some((ext)=>isAssetMatchExtension(asset, ext));
28
- }
29
- function filterAssetsByExtensions(assets, exts) {
30
- if ('string' == typeof exts) return assets.filter((e)=>isAssetMatchExtension(e, exts));
31
- if (Array.isArray(exts)) return assets.filter((e)=>isAssetMatchExtensions(e, exts));
32
- return [];
33
- }
34
- function filterAssets(assets, filterOrExtensions) {
35
- if (filterOrExtensions) assets = 'function' == typeof filterOrExtensions ? assets.filter(filterOrExtensions) : filterAssetsByExtensions(assets, filterOrExtensions);
36
- return assets;
37
- }
38
- function getAssetsSizeInfo(assets, chunks, options = {}) {
39
- const { withFileContent = true, filterOrExtensions } = options;
40
- assets = assets.filter((e)=>!isAssetMatchExtensions(e, Constants.MapExtensions));
41
- if (filterOrExtensions) assets = filterAssets(assets, filterOrExtensions);
42
- if (assets.length) return {
43
- count: assets.length,
44
- size: assets.reduce((t, c)=>t + c.size, 0),
45
- files: assets.map((e)=>({
46
- path: e.path,
47
- size: e.size,
48
- gzipSize: e.gzipSize,
49
- initial: isInitialAsset(e, chunks),
50
- content: withFileContent ? e.content : void 0
51
- }))
52
- };
53
- return {
54
- count: 0,
55
- size: 0,
56
- files: []
57
- };
58
- }
59
- function isInitialAsset(asset, chunks) {
60
- const cks = getChunksByAsset(asset, chunks);
61
- return cks.some((e)=>Boolean(e.initial));
62
- }
63
- function getInitialAssetsSizeInfo(assets, chunks, options = {}) {
64
- if (options.filterOrExtensions) assets = filterAssets(assets, options.filterOrExtensions);
65
- return getAssetsSizeInfo(assets, chunks, {
66
- ...options,
67
- filterOrExtensions: (asset)=>isInitialAsset(asset, chunks)
68
- });
69
- }
70
- function getAssetsDiffResult(baseline, current) {
71
- return {
72
- all: {
73
- total: diffAssetsByExtensions(baseline, current)
74
- },
75
- js: {
76
- total: diffAssetsByExtensions(baseline, current, Constants.JSExtension),
77
- initial: diffAssetsByExtensions(baseline, current, Constants.JSExtension, true)
78
- },
79
- css: {
80
- total: diffAssetsByExtensions(baseline, current, Constants.CSSExtension),
81
- initial: diffAssetsByExtensions(baseline, current, Constants.CSSExtension, true)
82
- },
83
- imgs: {
84
- total: diffAssetsByExtensions(baseline, current, Constants.ImgExtensions)
85
- },
86
- html: {
87
- total: diffAssetsByExtensions(baseline, current, Constants.HtmlExtension)
88
- },
89
- media: {
90
- total: diffAssetsByExtensions(baseline, current, Constants.MediaExtensions)
91
- },
92
- fonts: {
93
- total: diffAssetsByExtensions(baseline, current, Constants.FontExtensions)
94
- },
95
- others: {
96
- total: diffAssetsByExtensions(baseline, current, (asset)=>!isAssetMatchExtensions(asset, [
97
- Constants.JSExtension,
98
- Constants.CSSExtension,
99
- Constants.HtmlExtension
100
- ].concat(Constants.ImgExtensions, Constants.MediaExtensions, Constants.FontExtensions, Constants.MapExtensions)))
101
- }
102
- };
103
- }
104
- function diffSize(bSize, cSize) {
105
- const isEqual = bSize === cSize;
106
- const percent = isEqual ? 0 : 0 === bSize ? 100 : Math.abs(cSize - bSize) / bSize * 100;
107
- const state = isEqual ? Client.RsdoctorClientDiffState.Equal : bSize > cSize ? Client.RsdoctorClientDiffState.Down : Client.RsdoctorClientDiffState.Up;
108
- return {
109
- percent,
110
- state
111
- };
112
- }
113
- function diffAssetsByExtensions(baseline, current, filterOrExtensions, isInitial = false) {
114
- const { size: bSize, count: bCount } = isInitial ? getInitialAssetsSizeInfo(baseline.assets, baseline.chunks, {
115
- filterOrExtensions
116
- }) : getAssetsSizeInfo(baseline.assets, baseline.chunks, {
117
- filterOrExtensions
118
- });
119
- let cSize;
120
- let cCount;
121
- if (baseline === current) {
122
- cSize = bSize;
123
- cCount = bCount;
124
- } else {
125
- const { size, count } = isInitial ? getInitialAssetsSizeInfo(current.assets, current.chunks, {
126
- filterOrExtensions
127
- }) : getAssetsSizeInfo(current.assets, current.chunks, {
128
- filterOrExtensions
129
- });
130
- cSize = size;
131
- cCount = count;
132
- }
133
- const { percent, state } = diffSize(bSize, cSize);
134
- return {
135
- size: {
136
- baseline: bSize,
137
- current: cSize
138
- },
139
- count: {
140
- baseline: bCount,
141
- current: cCount
142
- },
143
- percent,
144
- state
145
- };
146
- }
147
- function getAssetsSummary(assets, chunks, options = {}) {
148
- const jsOpt = {
149
- ...options,
150
- filterOrExtensions: Constants.JSExtension
151
- };
152
- const cssOpt = {
153
- ...options,
154
- filterOrExtensions: Constants.CSSExtension
155
- };
156
- const imgOpt = {
157
- ...options,
158
- filterOrExtensions: Constants.ImgExtensions
159
- };
160
- const htmlOpt = {
161
- ...options,
162
- filterOrExtensions: Constants.HtmlExtension
163
- };
164
- const mediaOpt = {
165
- ...options,
166
- filterOrExtensions: Constants.MediaExtensions
167
- };
168
- const fontOpt = {
169
- ...options,
170
- filterOrExtensions: Constants.FontExtensions
171
- };
172
- const otherOpt = {
173
- ...options,
174
- filterOrExtensions: (asset)=>!isAssetMatchExtensions(asset, [
175
- Constants.JSExtension,
176
- Constants.CSSExtension,
177
- Constants.HtmlExtension
178
- ].concat(Constants.ImgExtensions, Constants.MediaExtensions, Constants.FontExtensions, Constants.MapExtensions))
179
- };
180
- return {
181
- all: {
182
- total: getAssetsSizeInfo(assets, chunks, options)
183
- },
184
- js: {
185
- total: getAssetsSizeInfo(assets, chunks, jsOpt),
186
- initial: getInitialAssetsSizeInfo(assets, chunks, jsOpt)
187
- },
188
- css: {
189
- total: getAssetsSizeInfo(assets, chunks, cssOpt),
190
- initial: getInitialAssetsSizeInfo(assets, chunks, cssOpt)
191
- },
192
- imgs: {
193
- total: getAssetsSizeInfo(assets, chunks, imgOpt)
194
- },
195
- html: {
196
- total: getAssetsSizeInfo(assets, chunks, htmlOpt)
197
- },
198
- media: {
199
- total: getAssetsSizeInfo(assets, chunks, mediaOpt)
200
- },
201
- fonts: {
202
- total: getAssetsSizeInfo(assets, chunks, fontOpt)
203
- },
204
- others: {
205
- total: getAssetsSizeInfo(assets, chunks, otherOpt)
206
- }
207
- };
208
- }
209
- function getAssetDetails(assetPath, assets, chunks, modules, checkModules) {
210
- const asset = assets.find((e)=>e.path === assetPath);
211
- return {
212
- asset,
213
- chunks: getChunksByAsset(asset, chunks),
214
- modules: getModulesByAsset(asset, chunks, modules, void 0, checkModules)
215
- };
216
- }
217
- function getAllBundleData(assets, chunks, modules, filtersModules) {
218
- const result = [];
219
- try {
220
- for(let i = 0; i < assets.length; i++){
221
- const asset = assets[i];
222
- result.push({
223
- asset,
224
- modules: getModulesByAsset(asset, chunks, modules, filtersModules)
225
- });
226
- }
227
- return result;
228
- } catch (error) {
229
- console.error(error);
230
- return [];
231
- }
232
- }
233
- function extname(filename) {
234
- const baseName = filename.split('?')[0];
235
- const matches = baseName.match(/\.([0-9a-z]+)(?:[\?#]|$)/i);
236
- return matches ? `.${matches[1]}` : '';
237
- }
238
- export { diffAssetsByExtensions, diffSize, extname, filterAssets, filterAssetsByExtensions, formatAssetName, getAllBundleData, getAssetDetails, getAssetsDiffResult, getAssetsSizeInfo, getAssetsSummary, getInitialAssetsSizeInfo, isAssetMatchExtension, isAssetMatchExtensions, isInitialAsset };
@@ -1,32 +0,0 @@
1
- function getChunkIdsByAsset(asset) {
2
- if (asset.chunks) return asset.chunks;
3
- return [];
4
- }
5
- function getChunksByModule(module, chunks) {
6
- if (module.chunks.length) return getChunksByChunkIds(module.chunks, chunks);
7
- return [];
8
- }
9
- function getChunkByChunkId(chunkId, chunks) {
10
- return chunks.find((e)=>e.id === chunkId);
11
- }
12
- function getChunksByChunkIds(chunkIds, chunks, filters) {
13
- if (!chunkIds.length) return [];
14
- const result = chunkIds.map((id)=>chunks.find((e)=>e.id === id)).filter(Boolean).map((chunk)=>{
15
- if (filters && filters.length > 0) {
16
- const filtered = {};
17
- for (const key of filters)if (void 0 !== chunk[key]) filtered[key] = chunk[key];
18
- return filtered;
19
- }
20
- return chunk;
21
- });
22
- return result;
23
- }
24
- function getChunksByAsset(asset, chunks, filters) {
25
- return getChunksByChunkIds(getChunkIdsByAsset(asset), chunks, filters);
26
- }
27
- function getChunksByModuleId(id, modules, chunks) {
28
- const mod = modules.find((e)=>e.id === id);
29
- if (!mod) return [];
30
- return getChunksByModule(mod, chunks);
31
- }
32
- export { getChunkByChunkId, getChunkIdsByAsset, getChunksByAsset, getChunksByChunkIds, getChunksByModule, getChunksByModuleId };