@rsdoctor/core 2.0.0-alpha.0 → 2.0.0-alpha.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 (393) hide show
  1. package/dist/build-utils/build/chunks/assetsModules.d.ts +1 -1
  2. package/dist/build-utils/build/chunks/assetsModules.js +1 -1
  3. package/dist/build-utils/build/chunks/index.d.ts +0 -1
  4. package/dist/build-utils/build/chunks/index.js +0 -1
  5. package/dist/build-utils/build/chunks/rspack/transform.d.ts +1 -1
  6. package/dist/build-utils/build/chunks/rspack/transform.js +1 -1
  7. package/dist/build-utils/build/envinfo.d.ts +13 -0
  8. package/dist/build-utils/build/envinfo.js +60 -0
  9. package/dist/build-utils/build/file/cache.d.ts +5 -0
  10. package/dist/build-utils/build/file/cache.js +24 -0
  11. package/dist/build-utils/build/file/index.d.ts +3 -0
  12. package/dist/build-utils/build/file/index.js +5 -0
  13. package/dist/build-utils/build/file/sharding.d.ts +21 -0
  14. package/dist/build-utils/build/file/sharding.js +38 -0
  15. package/dist/build-utils/build/index.d.ts +5 -0
  16. package/dist/build-utils/build/index.js +11 -6
  17. package/dist/build-utils/build/json.d.ts +3 -0
  18. package/dist/build-utils/build/json.js +67 -0
  19. package/dist/build-utils/build/loader/probeLoader.d.ts +2 -2
  20. package/dist/build-utils/build/loader/probeLoader.js +4 -4
  21. package/dist/build-utils/build/loader/probeLoaderPlugin.d.ts +1 -1
  22. package/dist/build-utils/build/loader/probeLoaderPlugin.js +1 -1
  23. package/dist/build-utils/build/module-graph/index.d.ts +0 -1
  24. package/dist/build-utils/build/module-graph/index.js +0 -1
  25. package/dist/build-utils/build/module-graph/parser.d.ts +1 -1
  26. package/dist/build-utils/build/module-graph/parser.js +1 -1
  27. package/dist/build-utils/build/module-graph/rspack/transform.d.ts +1 -1
  28. package/dist/build-utils/build/module-graph/rspack/transform.js +6 -4
  29. package/dist/build-utils/build/module-graph/utils.d.ts +1 -1
  30. package/dist/build-utils/build/module-graph/utils.js +5 -4
  31. package/dist/build-utils/build/process.d.ts +2 -0
  32. package/dist/build-utils/build/process.js +18 -0
  33. package/dist/build-utils/build/server.d.ts +15 -0
  34. package/dist/build-utils/build/server.js +107 -0
  35. package/dist/build-utils/build/utils/loader.d.ts +2 -2
  36. package/dist/build-utils/build/utils/loader.js +10 -19
  37. package/dist/build-utils/build/utils/parseBundle.d.ts +1 -1
  38. package/dist/build-utils/build/utils/parseBundle.js +6 -8
  39. package/dist/build-utils/build/utils/plugin.d.ts +1 -1
  40. package/dist/build-utils/index.d.ts +10 -0
  41. package/dist/build-utils/index.js +12 -2
  42. package/dist/collection.d.ts +1 -0
  43. package/dist/collection.js +2 -0
  44. package/dist/common/file.d.ts +2 -0
  45. package/dist/common/file.js +8 -0
  46. package/dist/common/global-config.d.ts +21 -0
  47. package/dist/common/global-config.js +33 -0
  48. package/dist/common/index.d.ts +4 -0
  49. package/dist/common/index.js +6 -0
  50. package/dist/common-browser.d.ts +1 -0
  51. package/dist/common-browser.js +2 -0
  52. package/dist/error/error.d.ts +35 -0
  53. package/dist/error/error.js +143 -0
  54. package/dist/error/index.d.ts +2 -0
  55. package/dist/error/index.js +3 -0
  56. package/dist/error/transform.d.ts +3 -0
  57. package/dist/error/transform.js +138 -0
  58. package/dist/error/utils.d.ts +4 -0
  59. package/dist/error/utils.js +23 -0
  60. package/dist/graph/index.d.ts +1 -0
  61. package/dist/graph/index.js +2 -0
  62. package/dist/index.d.ts +2 -0
  63. package/dist/index.js +4 -2
  64. package/dist/inner-plugins/loaders/proxy.d.ts +4 -4
  65. package/dist/inner-plugins/plugins/base.d.ts +1 -1
  66. package/dist/inner-plugins/plugins/bundle.d.ts +1 -1
  67. package/dist/inner-plugins/plugins/bundle.js +3 -3
  68. package/dist/inner-plugins/plugins/ensureModulesChunkGraph.d.ts +3 -3
  69. package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +11 -39
  70. package/dist/inner-plugins/plugins/errors.d.ts +2 -2
  71. package/dist/inner-plugins/plugins/errors.js +3 -3
  72. package/dist/inner-plugins/plugins/loader.d.ts +1 -1
  73. package/dist/inner-plugins/plugins/loader.js +7 -19
  74. package/dist/inner-plugins/plugins/plugins.d.ts +1 -1
  75. package/dist/inner-plugins/plugins/plugins.js +2 -2
  76. package/dist/inner-plugins/plugins/progress.d.ts +2 -2
  77. package/dist/inner-plugins/plugins/progress.js +2 -2
  78. package/dist/inner-plugins/plugins/resolver.d.ts +1 -1
  79. package/dist/inner-plugins/plugins/resolver.js +2 -2
  80. package/dist/inner-plugins/plugins/rspack.d.ts +8 -3
  81. package/dist/inner-plugins/plugins/rspack.js +18 -4
  82. package/dist/inner-plugins/plugins/rules.d.ts +1 -1
  83. package/dist/inner-plugins/plugins/rules.js +3 -3
  84. package/dist/inner-plugins/plugins/sourcemapTool.d.ts +2 -2
  85. package/dist/inner-plugins/plugins/sourcemapTool.js +2 -2
  86. package/dist/inner-plugins/plugins/summary.d.ts +1 -1
  87. package/dist/inner-plugins/plugins/summary.js +3 -3
  88. package/dist/inner-plugins/utils/config.d.ts +2 -3
  89. package/dist/inner-plugins/utils/config.js +16 -17
  90. package/dist/inner-plugins/utils/loader.d.ts +4 -7
  91. package/dist/inner-plugins/utils/loader.js +8 -34
  92. package/dist/inner-plugins/utils/normalize-config.d.ts +1 -1
  93. package/dist/inner-plugins/utils/openBrowser.d.ts +1 -0
  94. package/dist/inner-plugins/utils/openBrowser.js +55 -0
  95. package/dist/inner-plugins/utils/plugin-common.js +4 -4
  96. package/dist/inner-plugins/utils/plugin.d.ts +1 -1
  97. package/dist/inner-plugins/utils/plugin.js +1 -1
  98. package/dist/inner-plugins/utils/sdk.d.ts +2 -3
  99. package/dist/inner-plugins/utils/sdk.js +2 -2
  100. package/dist/logger.d.ts +9 -0
  101. package/dist/logger.js +51 -0
  102. package/dist/{inner-plugins/constants.d.cts → rspack-plugin/constants.d.ts} +3 -0
  103. package/dist/rspack-plugin/constants.js +23 -0
  104. package/dist/rspack-plugin/index.d.ts +2 -0
  105. package/dist/rspack-plugin/index.js +3 -0
  106. package/dist/rspack-plugin/multiple.d.ts +8 -0
  107. package/dist/rspack-plugin/multiple.js +39 -0
  108. package/dist/rspack-plugin/plugin.d.ts +25 -0
  109. package/dist/rspack-plugin/plugin.js +133 -0
  110. package/dist/rule-utils/document/document.d.ts +16 -0
  111. package/dist/rule-utils/document/document.js +46 -0
  112. package/dist/rule-utils/document/index.d.ts +3 -0
  113. package/dist/rule-utils/document/index.js +4 -0
  114. package/dist/rule-utils/document/server.d.ts +4 -0
  115. package/dist/rule-utils/document/server.js +13 -0
  116. package/dist/rule-utils/document/types.d.ts +31 -0
  117. package/dist/rule-utils/index.d.ts +2 -0
  118. package/dist/rule-utils/index.js +3 -0
  119. package/dist/rule-utils/parser/asserts.d.ts +81 -0
  120. package/dist/rule-utils/parser/asserts.js +105 -0
  121. package/dist/rule-utils/parser/index.d.ts +4 -0
  122. package/dist/rule-utils/parser/index.js +5 -0
  123. package/dist/rule-utils/parser/parser.d.ts +118 -0
  124. package/dist/rule-utils/parser/parser.js +24 -0
  125. package/dist/rule-utils/parser/types.d.ts +30 -0
  126. package/dist/rule-utils/parser/types.js +8 -0
  127. package/dist/rule-utils/parser/utils.d.ts +30 -0
  128. package/dist/rule-utils/parser/utils.js +106 -0
  129. package/dist/rules/linter.d.ts +1 -1
  130. package/dist/rules/linter.js +1 -1
  131. package/dist/rules/rule.d.ts +2 -2
  132. package/dist/rules/rule.js +2 -2
  133. package/dist/rules/rules/cjs-require/index.d.ts +1 -1
  134. package/dist/rules/rules/cjs-require/index.js +1 -1
  135. package/dist/rules/rules/cross-chunks-package/index.d.ts +1 -1
  136. package/dist/rules/rules/cross-chunks-package/index.js +2 -2
  137. package/dist/rules/rules/default-import-check/index.d.ts +1 -1
  138. package/dist/rules/rules/default-import-check/index.js +2 -2
  139. package/dist/rules/rules/default-import-check/utils.d.ts +2 -2
  140. package/dist/rules/rules/default-import-check/utils.js +2 -2
  141. package/dist/rules/rules/duplicate-package/index.d.ts +3 -3
  142. package/dist/rules/rules/duplicate-package/index.js +3 -3
  143. package/dist/rules/rules/duplicate-package/utils.d.ts +1 -1
  144. package/dist/rules/rules/ecma-version-check/index.d.ts +3 -2
  145. package/dist/rules/rules/ecma-version-check/index.js +1 -1
  146. package/dist/rules/rules/ecma-version-check/types.d.ts +1 -2
  147. package/dist/rules/rules/ecma-version-check/utils.d.ts +1 -1
  148. package/dist/rules/rules/esm-resolved-to-cjs/index.d.ts +1 -1
  149. package/dist/rules/rules/esm-resolved-to-cjs/index.js +1 -1
  150. package/dist/rules/rules/index.d.ts +1 -1
  151. package/dist/rules/rules/loader-performance-optimization/index.d.ts +1 -1
  152. package/dist/rules/rules/loader-performance-optimization/index.js +2 -2
  153. package/dist/rules/rules/loader-performance-optimization/types.d.ts +1 -1
  154. package/dist/rules/rules/module-mixed-chunks/index.d.ts +1 -1
  155. package/dist/rules/rules/module-mixed-chunks/index.js +1 -1
  156. package/dist/rules/rules/side-effects-only-imports/index.d.ts +1 -1
  157. package/dist/rules/rules/side-effects-only-imports/index.js +1 -1
  158. package/dist/rules/utils.d.ts +1 -1
  159. package/dist/rules/utils.js +1 -1
  160. package/dist/sdk/index.d.ts +2 -0
  161. package/dist/sdk/index.js +3 -0
  162. package/dist/sdk/multiple/controller.d.ts +12 -0
  163. package/dist/sdk/multiple/controller.js +42 -0
  164. package/dist/sdk/multiple/index.d.ts +2 -0
  165. package/dist/sdk/multiple/index.js +3 -0
  166. package/dist/sdk/multiple/primary.d.ts +32 -0
  167. package/dist/sdk/multiple/primary.js +64 -0
  168. package/dist/sdk/multiple/server.d.ts +7 -0
  169. package/dist/sdk/multiple/server.js +14 -0
  170. package/dist/sdk/sdk/core.d.ts +33 -0
  171. package/dist/sdk/sdk/core.js +163 -0
  172. package/dist/sdk/sdk/index.d.ts +52 -0
  173. package/dist/sdk/sdk/index.js +435 -0
  174. package/dist/sdk/sdk/types.d.ts +26 -0
  175. package/dist/sdk/sdk/types.js +1 -0
  176. package/dist/sdk/server/apis/alerts.d.ts +5 -0
  177. package/dist/sdk/server/apis/alerts.js +30 -0
  178. package/dist/sdk/server/apis/base.d.ts +11 -0
  179. package/dist/sdk/server/apis/base.js +22 -0
  180. package/dist/sdk/server/apis/bundle-diff.d.ts +6 -0
  181. package/dist/sdk/server/apis/bundle-diff.js +51 -0
  182. package/dist/sdk/server/apis/data.d.ts +6 -0
  183. package/dist/sdk/server/apis/data.js +44 -0
  184. package/dist/sdk/server/apis/fs.d.ts +5 -0
  185. package/dist/sdk/server/apis/fs.js +28 -0
  186. package/dist/sdk/server/apis/graph.d.ts +12 -0
  187. package/dist/sdk/server/apis/graph.js +116 -0
  188. package/dist/sdk/server/apis/index.d.ts +10 -0
  189. package/dist/sdk/server/apis/index.js +11 -0
  190. package/dist/sdk/server/apis/loader.d.ts +15 -0
  191. package/dist/sdk/server/apis/loader.js +120 -0
  192. package/dist/sdk/server/apis/plugin.d.ts +6 -0
  193. package/dist/sdk/server/apis/plugin.js +39 -0
  194. package/dist/sdk/server/apis/project.d.ts +8 -0
  195. package/dist/sdk/server/apis/project.js +59 -0
  196. package/dist/sdk/server/apis/renderer.d.ts +6 -0
  197. package/dist/sdk/server/apis/renderer.js +33 -0
  198. package/dist/sdk/server/apis/resolver.d.ts +6 -0
  199. package/dist/sdk/server/apis/resolver.js +38 -0
  200. package/dist/sdk/server/client.d.ts +3 -0
  201. package/dist/sdk/server/client.js +8 -0
  202. package/dist/sdk/server/fakeServer.d.ts +9 -0
  203. package/dist/sdk/server/fakeServer.js +12 -0
  204. package/dist/sdk/server/index.d.ts +44 -0
  205. package/dist/sdk/server/index.js +292 -0
  206. package/dist/sdk/server/json-body.d.ts +6 -0
  207. package/dist/sdk/server/json-body.js +150 -0
  208. package/dist/sdk/server/router.d.ts +24 -0
  209. package/dist/sdk/server/router.js +83 -0
  210. package/dist/sdk/server/security.d.ts +5 -0
  211. package/dist/sdk/server/security.js +47 -0
  212. package/dist/sdk/server/socket/api.d.ts +15 -0
  213. package/dist/sdk/server/socket/api.js +22 -0
  214. package/dist/sdk/server/socket/index.d.ts +48 -0
  215. package/dist/sdk/server/socket/index.js +166 -0
  216. package/dist/sdk/server/utils.d.ts +6 -0
  217. package/dist/sdk/server/utils.js +19 -0
  218. package/dist/sdk/utils/base.d.ts +1 -0
  219. package/dist/sdk/utils/base.js +22 -0
  220. package/dist/sdk/utils/constant.d.ts +1 -0
  221. package/dist/sdk/utils/constant.js +4 -0
  222. package/dist/sdk/utils/index.d.ts +3 -0
  223. package/dist/sdk/utils/index.js +4 -0
  224. package/dist/sdk/utils/openBrowser.d.ts +4 -0
  225. package/dist/sdk/utils/openBrowser.js +53 -0
  226. package/dist/sdk/utils/upload.d.ts +2 -0
  227. package/dist/sdk/utils/upload.js +6 -0
  228. package/dist/sdk.d.ts +1 -0
  229. package/dist/sdk.js +2 -0
  230. package/dist/types/index.d.ts +0 -1
  231. package/dist/types/index.js +0 -1
  232. package/dist/types/loader.d.ts +1 -1
  233. package/dist/types/plugin.d.ts +7 -28
  234. package/package.json +127 -58
  235. package/static/openChrome.applescript +95 -0
  236. package/dist/build-utils/build/chunks/assetsModules.cjs +0 -42
  237. package/dist/build-utils/build/chunks/assetsModules.d.cts +0 -17
  238. package/dist/build-utils/build/chunks/chunkTransform.cjs +0 -39
  239. package/dist/build-utils/build/chunks/chunkTransform.d.cts +0 -4
  240. package/dist/build-utils/build/chunks/chunkTransform.d.ts +0 -4
  241. package/dist/build-utils/build/chunks/chunkTransform.js +0 -6
  242. package/dist/build-utils/build/chunks/index.cjs +0 -72
  243. package/dist/build-utils/build/chunks/index.d.cts +0 -3
  244. package/dist/build-utils/build/chunks/rspack/transform.cjs +0 -80
  245. package/dist/build-utils/build/chunks/rspack/transform.d.cts +0 -13
  246. package/dist/build-utils/build/index.cjs +0 -52
  247. package/dist/build-utils/build/index.d.cts +0 -5
  248. package/dist/build-utils/build/loader/index.cjs +0 -65
  249. package/dist/build-utils/build/loader/index.d.cts +0 -2
  250. package/dist/build-utils/build/loader/probeLoader.cjs +0 -89
  251. package/dist/build-utils/build/loader/probeLoader.d.cts +0 -4
  252. package/dist/build-utils/build/loader/probeLoaderPlugin.cjs +0 -65
  253. package/dist/build-utils/build/loader/probeLoaderPlugin.d.cts +0 -5
  254. package/dist/build-utils/build/module-graph/index.cjs +0 -65
  255. package/dist/build-utils/build/module-graph/index.d.cts +0 -2
  256. package/dist/build-utils/build/module-graph/parser.cjs +0 -46
  257. package/dist/build-utils/build/module-graph/parser.d.cts +0 -2
  258. package/dist/build-utils/build/module-graph/rspack/transform.cjs +0 -151
  259. package/dist/build-utils/build/module-graph/rspack/transform.d.cts +0 -26
  260. package/dist/build-utils/build/module-graph/transform.cjs +0 -39
  261. package/dist/build-utils/build/module-graph/transform.d.cts +0 -3
  262. package/dist/build-utils/build/module-graph/transform.d.ts +0 -3
  263. package/dist/build-utils/build/module-graph/transform.js +0 -6
  264. package/dist/build-utils/build/module-graph/utils.cjs +0 -95
  265. package/dist/build-utils/build/module-graph/utils.d.cts +0 -3
  266. package/dist/build-utils/build/utils/index.cjs +0 -72
  267. package/dist/build-utils/build/utils/index.d.cts +0 -3
  268. package/dist/build-utils/build/utils/loader.cjs +0 -354
  269. package/dist/build-utils/build/utils/loader.d.cts +0 -20
  270. package/dist/build-utils/build/utils/parseBundle.cjs +0 -283
  271. package/dist/build-utils/build/utils/parseBundle.d.cts +0 -12
  272. package/dist/build-utils/build/utils/plugin.cjs +0 -60
  273. package/dist/build-utils/build/utils/plugin.d.cts +0 -5
  274. package/dist/build-utils/index.cjs +0 -36
  275. package/dist/build-utils/index.d.cts +0 -1
  276. package/dist/index.cjs +0 -81
  277. package/dist/index.d.cts +0 -3
  278. package/dist/inner-plugins/constants.cjs +0 -64
  279. package/dist/inner-plugins/index.cjs +0 -65
  280. package/dist/inner-plugins/index.d.cts +0 -2
  281. package/dist/inner-plugins/loaders/proxy.cjs +0 -104
  282. package/dist/inner-plugins/loaders/proxy.d.cts +0 -7
  283. package/dist/inner-plugins/plugins/base.cjs +0 -53
  284. package/dist/inner-plugins/plugins/base.d.cts +0 -12
  285. package/dist/inner-plugins/plugins/bundle.cjs +0 -96
  286. package/dist/inner-plugins/plugins/bundle.d.cts +0 -15
  287. package/dist/inner-plugins/plugins/ensureModulesChunkGraph.cjs +0 -141
  288. package/dist/inner-plugins/plugins/ensureModulesChunkGraph.d.cts +0 -34
  289. package/dist/inner-plugins/plugins/errors.cjs +0 -98
  290. package/dist/inner-plugins/plugins/errors.d.cts +0 -11
  291. package/dist/inner-plugins/plugins/index.cjs +0 -121
  292. package/dist/inner-plugins/plugins/index.d.cts +0 -10
  293. package/dist/inner-plugins/plugins/loader.cjs +0 -165
  294. package/dist/inner-plugins/plugins/loader.d.cts +0 -10
  295. package/dist/inner-plugins/plugins/plugins.cjs +0 -73
  296. package/dist/inner-plugins/plugins/plugins.d.cts +0 -8
  297. package/dist/inner-plugins/plugins/progress.cjs +0 -68
  298. package/dist/inner-plugins/plugins/progress.d.cts +0 -8
  299. package/dist/inner-plugins/plugins/resolver.cjs +0 -90
  300. package/dist/inner-plugins/plugins/resolver.d.cts +0 -12
  301. package/dist/inner-plugins/plugins/rspack.cjs +0 -118
  302. package/dist/inner-plugins/plugins/rspack.d.cts +0 -4
  303. package/dist/inner-plugins/plugins/rules.cjs +0 -97
  304. package/dist/inner-plugins/plugins/rules.d.cts +0 -8
  305. package/dist/inner-plugins/plugins/sourcemapTool.cjs +0 -275
  306. package/dist/inner-plugins/plugins/sourcemapTool.d.cts +0 -52
  307. package/dist/inner-plugins/plugins/summary.cjs +0 -125
  308. package/dist/inner-plugins/plugins/summary.d.cts +0 -14
  309. package/dist/inner-plugins/utils/circleDetect.cjs +0 -49
  310. package/dist/inner-plugins/utils/circleDetect.d.cts +0 -4
  311. package/dist/inner-plugins/utils/config.cjs +0 -191
  312. package/dist/inner-plugins/utils/config.d.cts +0 -5
  313. package/dist/inner-plugins/utils/index.cjs +0 -106
  314. package/dist/inner-plugins/utils/index.d.cts +0 -9
  315. package/dist/inner-plugins/utils/loader.cjs +0 -218
  316. package/dist/inner-plugins/utils/loader.d.cts +0 -13
  317. package/dist/inner-plugins/utils/normalize-config.cjs +0 -122
  318. package/dist/inner-plugins/utils/normalize-config.d.cts +0 -37
  319. package/dist/inner-plugins/utils/plugin-common.cjs +0 -143
  320. package/dist/inner-plugins/utils/plugin-common.d.cts +0 -11
  321. package/dist/inner-plugins/utils/plugin.cjs +0 -106
  322. package/dist/inner-plugins/utils/plugin.d.cts +0 -4
  323. package/dist/inner-plugins/utils/sdk.cjs +0 -55
  324. package/dist/inner-plugins/utils/sdk.d.cts +0 -8
  325. package/dist/rslib-runtime.js +0 -19
  326. package/dist/rules/index.cjs +0 -81
  327. package/dist/rules/index.d.cts +0 -3
  328. package/dist/rules/linter.cjs +0 -72
  329. package/dist/rules/linter.d.cts +0 -9
  330. package/dist/rules/rule.cjs +0 -137
  331. package/dist/rules/rule.d.cts +0 -27
  332. package/dist/rules/rules/cjs-require/index.cjs +0 -83
  333. package/dist/rules/rules/cjs-require/index.d.cts +0 -4
  334. package/dist/rules/rules/cjs-require/types.cjs +0 -18
  335. package/dist/rules/rules/cjs-require/types.d.cts +0 -7
  336. package/dist/rules/rules/cross-chunks-package/index.cjs +0 -74
  337. package/dist/rules/rules/cross-chunks-package/index.d.cts +0 -4
  338. package/dist/rules/rules/cross-chunks-package/types.cjs +0 -18
  339. package/dist/rules/rules/cross-chunks-package/types.d.cts +0 -3
  340. package/dist/rules/rules/cross-chunks-package/utils.cjs +0 -40
  341. package/dist/rules/rules/cross-chunks-package/utils.d.cts +0 -1
  342. package/dist/rules/rules/default-import-check/index.cjs +0 -116
  343. package/dist/rules/rules/default-import-check/index.d.cts +0 -4
  344. package/dist/rules/rules/default-import-check/types.cjs +0 -18
  345. package/dist/rules/rules/default-import-check/types.d.cts +0 -4
  346. package/dist/rules/rules/default-import-check/utils.cjs +0 -97
  347. package/dist/rules/rules/default-import-check/utils.d.cts +0 -10
  348. package/dist/rules/rules/duplicate-package/index.cjs +0 -72
  349. package/dist/rules/rules/duplicate-package/index.d.cts +0 -4
  350. package/dist/rules/rules/duplicate-package/types.cjs +0 -60
  351. package/dist/rules/rules/duplicate-package/types.d.cts +0 -24
  352. package/dist/rules/rules/duplicate-package/utils.cjs +0 -84
  353. package/dist/rules/rules/duplicate-package/utils.d.cts +0 -3
  354. package/dist/rules/rules/ecma-version-check/index.cjs +0 -96
  355. package/dist/rules/rules/ecma-version-check/index.d.cts +0 -4
  356. package/dist/rules/rules/ecma-version-check/types.cjs +0 -18
  357. package/dist/rules/rules/ecma-version-check/types.d.cts +0 -3
  358. package/dist/rules/rules/ecma-version-check/utils.cjs +0 -39
  359. package/dist/rules/rules/ecma-version-check/utils.d.cts +0 -2
  360. package/dist/rules/rules/esm-resolved-to-cjs/index.cjs +0 -237
  361. package/dist/rules/rules/esm-resolved-to-cjs/index.d.cts +0 -4
  362. package/dist/rules/rules/esm-resolved-to-cjs/types.cjs +0 -18
  363. package/dist/rules/rules/esm-resolved-to-cjs/types.d.cts +0 -8
  364. package/dist/rules/rules/index.cjs +0 -55
  365. package/dist/rules/rules/index.d.cts +0 -2
  366. package/dist/rules/rules/loader-performance-optimization/index.cjs +0 -119
  367. package/dist/rules/rules/loader-performance-optimization/index.d.cts +0 -4
  368. package/dist/rules/rules/loader-performance-optimization/types.cjs +0 -18
  369. package/dist/rules/rules/loader-performance-optimization/types.d.cts +0 -22
  370. package/dist/rules/rules/loader-performance-optimization/utils.cjs +0 -43
  371. package/dist/rules/rules/loader-performance-optimization/utils.d.cts +0 -1
  372. package/dist/rules/rules/module-mixed-chunks/index.cjs +0 -85
  373. package/dist/rules/rules/module-mixed-chunks/index.d.cts +0 -4
  374. package/dist/rules/rules/module-mixed-chunks/types.cjs +0 -18
  375. package/dist/rules/rules/module-mixed-chunks/types.d.cts +0 -3
  376. package/dist/rules/rules/side-effects-only-imports/index.cjs +0 -114
  377. package/dist/rules/rules/side-effects-only-imports/index.d.cts +0 -4
  378. package/dist/rules/rules/side-effects-only-imports/types.cjs +0 -18
  379. package/dist/rules/rules/side-effects-only-imports/types.d.cts +0 -9
  380. package/dist/rules/utils.cjs +0 -46
  381. package/dist/rules/utils.d.cts +0 -3
  382. package/dist/types/chunks.cjs +0 -18
  383. package/dist/types/chunks.d.cts +0 -6
  384. package/dist/types/chunks.d.ts +0 -6
  385. package/dist/types/index.cjs +0 -79
  386. package/dist/types/index.d.cts +0 -4
  387. package/dist/types/loader.cjs +0 -18
  388. package/dist/types/loader.d.cts +0 -19
  389. package/dist/types/plugin.cjs +0 -18
  390. package/dist/types/plugin.d.cts +0 -51
  391. package/dist/types/rules.cjs +0 -18
  392. package/dist/types/rules.d.cts +0 -7
  393. /package/dist/{types/chunks.js → rule-utils/document/types.js} +0 -0
@@ -0,0 +1,292 @@
1
+ import "node:module";
2
+ import { Client, SDK } from "@rsdoctor/shared/types";
3
+ import { Server } from "../../build-utils/index.js";
4
+ import sirv from "sirv";
5
+ import { Bundle, GlobalConfig } from "../../common/index.js";
6
+ import assert from "assert";
7
+ import cors from "cors";
8
+ import { PassThrough } from "stream";
9
+ import { Socket } from "./socket/index.js";
10
+ import { Router } from "./router.js";
11
+ import * as __rspack_external__apis_index_js_275823d6 from "./apis/index.js";
12
+ import { chalk, logger } from "../../logger.js";
13
+ import { openBrowser } from "../utils/openBrowser.js";
14
+ import path from "path";
15
+ import { createRequire } from "module";
16
+ import { randomBytes } from "crypto";
17
+ import { jsonBodyParser } from "./json-body.js";
18
+ import { DEFAULT_ALLOWED_CORS_ORIGINS, isAllowedCorsRequest, isAllowedOpenInEditorToken, isAllowedRequestHost } from "./security.js";
19
+ export * from "./utils.js";
20
+ const server_require = createRequire(import.meta.url);
21
+ const OPEN_IN_EDITOR_PATH = '/__open-in-editor';
22
+ const LISTEN_RETRY_LIMIT = 10;
23
+ const OPEN_IN_EDITOR_EDITORS = new Set(SDK.OPEN_IN_EDITOR_EDITORS);
24
+ const DEFAULT_JSON_BODY_LIMIT = '10mb';
25
+ const LARGE_JSON_BODY_LIMIT = '500mb';
26
+ const LARGE_JSON_BODY_ROUTES = new Set([
27
+ SDK.ServerAPI.API.ReportLoader,
28
+ SDK.ServerAPI.API.ReportSourceMap
29
+ ]);
30
+ function isAddressInUseError(error) {
31
+ return 'EADDRINUSE' === error.code;
32
+ }
33
+ function isAllowedOpenInEditorEditor(editor) {
34
+ return 'string' == typeof editor && OPEN_IN_EDITOR_EDITORS.has(editor);
35
+ }
36
+ class RsdoctorServer {
37
+ get app() {
38
+ return this._server.app;
39
+ }
40
+ get host() {
41
+ return Server.defaultHost;
42
+ }
43
+ get origin() {
44
+ return `http://${this.host}:${this.port}`;
45
+ }
46
+ get socketUrl() {
47
+ return {
48
+ port: this.port,
49
+ socketUrl: `ws://localhost:${this.port}?token=${this._socketToken}`,
50
+ token: this._socketToken
51
+ };
52
+ }
53
+ get innerClientPath() {
54
+ return this._innerClientPath;
55
+ }
56
+ async createInnerServer() {
57
+ let expectedPort = this.port;
58
+ let lastError;
59
+ for(let retry = 0; retry < LISTEN_RETRY_LIMIT; retry++){
60
+ const port = Server.getPortSync(expectedPort, this.host);
61
+ try {
62
+ return {
63
+ port,
64
+ server: await Server.createServer(port, this.host)
65
+ };
66
+ } catch (error) {
67
+ if (!isAddressInUseError(error)) throw error;
68
+ lastError = error;
69
+ expectedPort = port + 1;
70
+ }
71
+ }
72
+ throw lastError;
73
+ }
74
+ resolveCorsOptions() {
75
+ if (false === this._cors) return false;
76
+ if (true === this._cors) return {};
77
+ if (void 0 === this._cors) return {
78
+ origin: DEFAULT_ALLOWED_CORS_ORIGINS
79
+ };
80
+ return {
81
+ ...this._cors,
82
+ origin: void 0 === this._cors.origin ? DEFAULT_ALLOWED_CORS_ORIGINS : this._cors.origin
83
+ };
84
+ }
85
+ async bootstrap() {
86
+ if (!this.disposed) return;
87
+ const { port, server } = await this.createInnerServer();
88
+ const corsOptions = this.resolveCorsOptions();
89
+ this.port = port;
90
+ this._server = server;
91
+ this._socket = new Socket({
92
+ sdk: this.sdk,
93
+ server: this._server.server,
94
+ port: this.port,
95
+ token: this._socketToken
96
+ });
97
+ await this._socket.bootstrap();
98
+ GlobalConfig.writeMcpPort(this.port, this.sdk.name);
99
+ logger.debug(`Successfully wrote mcp.json for ${chalk.cyan(this.sdk.name)} builder`);
100
+ this.disposed = false;
101
+ this.app.use((req, res, next)=>{
102
+ const host = req.headers.host || req.headers[':authority'];
103
+ if (!isAllowedRequestHost(host)) {
104
+ res.statusCode = 403;
105
+ res.end();
106
+ return;
107
+ }
108
+ next();
109
+ });
110
+ if (false !== corsOptions && corsOptions.origin === DEFAULT_ALLOWED_CORS_ORIGINS) this.app.use((req, res, next)=>{
111
+ const host = req.headers.host || req.headers[':authority'];
112
+ if (!isAllowedCorsRequest(req.headers.origin, host)) {
113
+ res.statusCode = 403;
114
+ res.end();
115
+ return;
116
+ }
117
+ next();
118
+ });
119
+ if (false !== corsOptions) this.app.use(cors(corsOptions));
120
+ this.app.use(jsonBodyParser({
121
+ limit: (req)=>{
122
+ const pathname = new URL(req.url || '/', 'http://localhost').pathname;
123
+ return LARGE_JSON_BODY_ROUTES.has(pathname) ? LARGE_JSON_BODY_LIMIT : DEFAULT_JSON_BODY_LIMIT;
124
+ }
125
+ }));
126
+ await this._router.setup();
127
+ const clientHtmlPath = this._innerClientPath ? this._innerClientPath : server_require.resolve('@rsdoctor/client');
128
+ const clientDistPath = path.resolve(clientHtmlPath, '..');
129
+ this.app.use(sirv(clientDistPath, {
130
+ dev: true
131
+ }));
132
+ this.app.use(OPEN_IN_EDITOR_PATH, (req, res, next)=>{
133
+ if ('GET' !== req.method && 'HEAD' !== req.method) return next();
134
+ const url = new URL(req.url || '', "http://localhost");
135
+ const file = url.searchParams.get('file');
136
+ const editor = url.searchParams.get('editor');
137
+ const token = url.searchParams.get('token');
138
+ if (!isAllowedOpenInEditorToken(token, this._socketToken)) {
139
+ res.statusCode = 403;
140
+ res.end();
141
+ return;
142
+ }
143
+ if (!file) {
144
+ res.statusCode = 400;
145
+ res.end('Missing file parameter');
146
+ return;
147
+ }
148
+ if (!isAllowedOpenInEditorEditor(editor)) {
149
+ res.statusCode = 400;
150
+ res.end('Unsupported editor parameter');
151
+ return;
152
+ }
153
+ try {
154
+ const launch = server_require('launch-editor');
155
+ let responded = false;
156
+ const safeEnd = (code, body)=>{
157
+ if (responded) return;
158
+ responded = true;
159
+ res.statusCode = code;
160
+ res.end(body);
161
+ };
162
+ launch(file, editor, (_fileName, errorMessage)=>{
163
+ if (errorMessage) safeEnd(500, errorMessage);
164
+ });
165
+ setTimeout(()=>{
166
+ safeEnd(200, '');
167
+ }, 200);
168
+ } catch (err) {
169
+ if (!res.writableEnded) {
170
+ res.statusCode = 500;
171
+ res.end(err.message);
172
+ }
173
+ }
174
+ });
175
+ process.once('exit', ()=>this.dispose());
176
+ process.once('SIGINT', ()=>this.dispose(0));
177
+ process.once('SIGTERM', ()=>this.dispose(0));
178
+ process.once('unhandledRejection', (reason)=>{
179
+ console.error('Unhandled promise rejection:', reason);
180
+ this.dispose(1);
181
+ });
182
+ process.once('uncaughtException', (err, origin)=>{
183
+ console.error('Uncaught exception:', err);
184
+ if (origin) console.error('Exception origin:', origin);
185
+ this.dispose(1);
186
+ });
187
+ }
188
+ wrapNextHandleFunction(method, cb) {
189
+ return async (req, res, next)=>{
190
+ const m = req.method?.toUpperCase();
191
+ if (m === method) {
192
+ try {
193
+ const body = await cb(req, res, next);
194
+ res.statusCode = 200;
195
+ if (Buffer.isBuffer(body)) {
196
+ res.setHeader('Content-Length', body.byteLength);
197
+ const ps = new PassThrough();
198
+ ps.write(body);
199
+ ps.end();
200
+ ps.pipe(res);
201
+ } else if (body && 'object' == typeof body) {
202
+ res.writeHead(200, {
203
+ 'Content-Type': 'application/json;utf-8'
204
+ });
205
+ res.write(JSON.stringify(body));
206
+ res.end();
207
+ } else res.writeHead(200).end(body);
208
+ } catch (error) {
209
+ res.statusCode = 500;
210
+ res.end(error.message);
211
+ return next(error);
212
+ }
213
+ return;
214
+ }
215
+ await next();
216
+ };
217
+ }
218
+ proxy(api, method, cb) {
219
+ let idx = this.app.stack.findIndex((e)=>e.route === api);
220
+ if (-1 === idx) idx = this.app.stack.length - 1;
221
+ this.app.stack.splice(idx, 0, {
222
+ route: api,
223
+ handle: this.wrapNextHandleFunction(method, cb)
224
+ });
225
+ }
226
+ getClientUrl(route = 'homepage', ...args) {
227
+ const relativeUrl = SDK.ServerAPI.API.EntryHtml;
228
+ switch(route){
229
+ case Client.RsdoctorClientRoutes.BundleDiff:
230
+ {
231
+ const [baseline, current] = args;
232
+ const qs = Bundle.getBundleDiffPageQueryString([
233
+ baseline,
234
+ current
235
+ ]);
236
+ return `${relativeUrl}${qs}#${Client.RsdoctorClientRoutes.BundleDiff}`;
237
+ }
238
+ default:
239
+ return relativeUrl;
240
+ }
241
+ }
242
+ async openClientPage(...args) {
243
+ const relativeUrl = this.getClientUrl(...args);
244
+ const needEncodeURI = args[0] === Client.RsdoctorClientRoutes.BundleDiff;
245
+ const url = `http://${this.host}:${this.port}${relativeUrl}`;
246
+ const localhostUrl = `http://localhost:${this.port}${relativeUrl}`;
247
+ await openBrowser(localhostUrl, !needEncodeURI);
248
+ if (this._printServerUrl) logger.info(`${chalk.green(`${this.sdk.name} compiler's`)} analyzer running on: ${chalk.cyan(url)}`);
249
+ }
250
+ sendAPIDataToClient(api, msg) {
251
+ this._socket?.sendAPIData(api, msg);
252
+ }
253
+ async broadcast() {
254
+ await this._socket?.broadcast();
255
+ }
256
+ constructor(sdk, port = Server.defaultPort, config){
257
+ this.sdk = sdk;
258
+ this.disposed = true;
259
+ this._socketToken = randomBytes(16).toString('hex');
260
+ this.get = (route, cb)=>{
261
+ const { app } = this;
262
+ app.use(route, this.wrapNextHandleFunction('GET', cb));
263
+ return app;
264
+ };
265
+ this.post = (route, cb)=>{
266
+ const { app } = this;
267
+ app.use(route, this.wrapNextHandleFunction('POST', cb));
268
+ return app;
269
+ };
270
+ this.dispose = async (exitCode)=>{
271
+ if (this.disposed) {
272
+ if (void 0 !== exitCode) process.exit(exitCode);
273
+ return;
274
+ }
275
+ this.disposed = true;
276
+ if (this._server) await this._server.close();
277
+ if (this._socket) this._socket.dispose();
278
+ if (void 0 !== exitCode) process.exit(exitCode);
279
+ };
280
+ assert('number' == typeof port);
281
+ this.port = port;
282
+ this._router = new Router({
283
+ sdk,
284
+ server: this,
285
+ apis: Object.values(__rspack_external__apis_index_js_275823d6)
286
+ });
287
+ this._innerClientPath = config?.innerClientPath || '';
288
+ this._printServerUrl = config?.printServerUrl ?? true;
289
+ this._cors = config?.cors;
290
+ }
291
+ }
292
+ export { RsdoctorServer };
@@ -0,0 +1,6 @@
1
+ import type { Thirdparty } from '@rsdoctor/shared/types';
2
+ interface JsonBodyParserOptions {
3
+ limit?: number | string | ((req: Thirdparty.connect.IncomingMessage) => number | string);
4
+ }
5
+ export declare function jsonBodyParser(options?: JsonBodyParserOptions): Thirdparty.connect.NextHandleFunction;
6
+ export {};
@@ -0,0 +1,150 @@
1
+ import "node:module";
2
+ import raw_body from "raw-body";
3
+ import { createBrotliDecompress, createGunzip, createInflate } from "node:zlib";
4
+ const JSON_CONTENT_TYPE = 'application/json';
5
+ const DEFAULT_CHARSET = 'utf-8';
6
+ function createHttpError(status, message, type) {
7
+ return Object.assign(new Error(message), {
8
+ status,
9
+ statusCode: status,
10
+ type
11
+ });
12
+ }
13
+ function hasBody(req) {
14
+ return void 0 !== req.headers['transfer-encoding'] || !Number.isNaN(Number(req.headers['content-length']));
15
+ }
16
+ function getContentType(req) {
17
+ const contentType = req.headers['content-type'];
18
+ if ('string' != typeof contentType) return;
19
+ return contentType;
20
+ }
21
+ function shouldParse(req) {
22
+ const contentType = getContentType(req);
23
+ if (!contentType) return false;
24
+ return contentType.split(';', 1)[0].trim().toLowerCase() === JSON_CONTENT_TYPE;
25
+ }
26
+ function getCharset(req) {
27
+ const contentType = getContentType(req);
28
+ const match = contentType?.match(/(?:^|;)\s*charset\s*=\s*(?:"([^"]+)"|([^;\s]+))/i);
29
+ return (match?.[1] || match?.[2] || DEFAULT_CHARSET).toLowerCase();
30
+ }
31
+ function getContentStream(req) {
32
+ const contentEncoding = req.headers['content-encoding'];
33
+ const encoding = 'string' == typeof contentEncoding ? contentEncoding.toLowerCase() : 'identity';
34
+ if ('identity' === encoding) return {
35
+ stream: req,
36
+ length: req.headers['content-length']
37
+ };
38
+ let stream;
39
+ switch(encoding){
40
+ case 'gzip':
41
+ stream = createGunzip();
42
+ break;
43
+ case 'deflate':
44
+ stream = createInflate();
45
+ break;
46
+ case 'br':
47
+ stream = createBrotliDecompress();
48
+ break;
49
+ default:
50
+ throw createHttpError(415, `unsupported content encoding "${encoding}"`, 'encoding.unsupported');
51
+ }
52
+ const cleanup = ()=>{
53
+ req.removeListener('aborted', onAborted);
54
+ req.removeListener('close', onClose);
55
+ req.removeListener('error', onError);
56
+ stream.removeListener('close', cleanup);
57
+ };
58
+ const destroy = (error)=>{
59
+ if (!stream.destroyed) stream.destroy(error);
60
+ };
61
+ const onAborted = ()=>{
62
+ destroy(createHttpError(400, 'request aborted', 'request.aborted'));
63
+ };
64
+ const onClose = ()=>{
65
+ if (false === req.complete) onAborted();
66
+ };
67
+ const onError = (error)=>{
68
+ destroy(error);
69
+ };
70
+ req.once('aborted', onAborted);
71
+ req.once('close', onClose);
72
+ req.once('error', onError);
73
+ stream.once('close', cleanup);
74
+ req.pipe(stream);
75
+ return {
76
+ stream,
77
+ cleanup,
78
+ decompressor: stream
79
+ };
80
+ }
81
+ function parseJson(body) {
82
+ if (0 === body.length) return {};
83
+ let value;
84
+ try {
85
+ value = JSON.parse(body);
86
+ } catch (error) {
87
+ throw createHttpError(400, error.message, 'entity.parse.failed');
88
+ }
89
+ if (null === value || 'object' != typeof value) throw createHttpError(400, 'JSON body must be an object or array', 'entity.parse.failed');
90
+ return value;
91
+ }
92
+ function normalizeReadError(error, charset) {
93
+ if (error instanceof Error && 'status' in error && 'number' == typeof error.status) {
94
+ if (charset && 'type' in error && 'encoding.unsupported' === error.type) return createHttpError(415, `unsupported charset "${charset.toUpperCase()}"`, 'charset.unsupported');
95
+ return error;
96
+ }
97
+ return createHttpError(400, error instanceof Error ? error.message : 'failed to read request body', 'request.invalid');
98
+ }
99
+ function jsonBodyParser(options = {}) {
100
+ return (req, _res, next)=>{
101
+ const request = req;
102
+ if (!('body' in request)) request.body = void 0;
103
+ if (!hasBody(req) || !shouldParse(req)) return void next();
104
+ const charset = getCharset(req);
105
+ if (!charset.startsWith('utf-')) {
106
+ req.resume();
107
+ next(createHttpError(415, `unsupported charset "${charset.toUpperCase()}"`, 'charset.unsupported'));
108
+ return;
109
+ }
110
+ let content;
111
+ try {
112
+ content = getContentStream(req);
113
+ } catch (error) {
114
+ req.resume();
115
+ next(normalizeReadError(error));
116
+ return;
117
+ }
118
+ const handleError = (error)=>{
119
+ content.cleanup?.();
120
+ if (content.decompressor) {
121
+ req.unpipe(content.decompressor);
122
+ content.decompressor.destroy();
123
+ }
124
+ req.resume();
125
+ next(normalizeReadError(error, charset));
126
+ };
127
+ let limit;
128
+ try {
129
+ limit = 'function' == typeof options.limit ? options.limit(req) : options.limit;
130
+ } catch (error) {
131
+ handleError(error);
132
+ return;
133
+ }
134
+ raw_body(content.stream, {
135
+ encoding: charset,
136
+ length: content.length,
137
+ limit
138
+ }).then((body)=>{
139
+ try {
140
+ request.body = parseJson(body);
141
+ } catch (error) {
142
+ handleError(error);
143
+ return;
144
+ }
145
+ content.cleanup?.();
146
+ next();
147
+ }, handleError);
148
+ };
149
+ }
150
+ export { jsonBodyParser };
@@ -0,0 +1,24 @@
1
+ import type { ServerResponse } from 'http';
2
+ import { Common, SDK, Thirdparty } from '@rsdoctor/shared/types';
3
+ import { BaseAPI } from './apis/base.js';
4
+ interface RouterOptions {
5
+ apis: Common.Constructor<typeof BaseAPI>[];
6
+ sdk: SDK.RsdoctorBuilderSDKInstance;
7
+ server: SDK.RsdoctorServerInstance;
8
+ }
9
+ export declare class Router {
10
+ protected options: RouterOptions;
11
+ static routes: {
12
+ /**
13
+ * - `key` is the constructor of object which used to match the API class
14
+ */
15
+ get: Map<new (sdk: SDK.RsdoctorSDKInstance, server: SDK.RsdoctorServerInstance) => BaseAPI, [apiKey: PropertyKey, pathname: string][]>;
16
+ post: Map<new (sdk: SDK.RsdoctorSDKInstance, server: SDK.RsdoctorServerInstance) => BaseAPI, [apiKey: PropertyKey, pathname: string][]>;
17
+ };
18
+ static get(pathname: string): MethodDecorator;
19
+ static post(pathname: string): MethodDecorator;
20
+ constructor(options: RouterOptions);
21
+ setup(): Promise<void>;
22
+ wrapAPIFunction<T extends BaseAPI>(api: T, key: PropertyKey): (req: Thirdparty.connect.IncomingMessage, res: ServerResponse) => Promise<unknown>;
23
+ }
24
+ export {};
@@ -0,0 +1,83 @@
1
+ import "node:module";
2
+ const normalizeAPIKey = (key)=>{
3
+ if (key && 'object' == typeof key && 'name' in key) return key.name;
4
+ return key;
5
+ };
6
+ class Router {
7
+ static get(pathname) {
8
+ return (target, propertyKey, descriptor)=>{
9
+ const routes = Router.routes.get;
10
+ const constructor = target.constructor;
11
+ if (!routes.has(constructor)) routes.set(constructor, []);
12
+ routes.get(constructor).push([
13
+ normalizeAPIKey(propertyKey),
14
+ pathname
15
+ ]);
16
+ return descriptor;
17
+ };
18
+ }
19
+ static post(pathname) {
20
+ return (target, propertyKey, descriptor)=>{
21
+ const routes = Router.routes.post;
22
+ const constructor = target.constructor;
23
+ if (!routes.has(constructor)) routes.set(constructor, []);
24
+ routes.get(constructor).push([
25
+ normalizeAPIKey(propertyKey),
26
+ pathname
27
+ ]);
28
+ return descriptor;
29
+ };
30
+ }
31
+ async setup() {
32
+ const { apis, sdk, server } = this.options;
33
+ apis.forEach((API)=>{
34
+ const obj = new API(sdk, server);
35
+ Router.routes.get.get(API)?.forEach(([key, pathname])=>{
36
+ server.get(pathname, this.wrapAPIFunction(obj, key));
37
+ });
38
+ Router.routes.post.get(API)?.forEach(([key, pathname])=>{
39
+ server.post(pathname, this.wrapAPIFunction(obj, key));
40
+ });
41
+ });
42
+ }
43
+ wrapAPIFunction(api, key) {
44
+ const { sdk, server } = this.options;
45
+ return async (req, res)=>{
46
+ const ctx = {
47
+ req,
48
+ res,
49
+ sdk,
50
+ server
51
+ };
52
+ const trap = new Proxy(api, {
53
+ get (target, key, receiver) {
54
+ switch(key){
55
+ case 'ctx':
56
+ return ctx;
57
+ default:
58
+ return Reflect.get(target, key, receiver);
59
+ }
60
+ },
61
+ set (target, key, value, receiver) {
62
+ return Reflect.set(target, key, value, receiver);
63
+ },
64
+ defineProperty (target, p, attrs) {
65
+ return Reflect.defineProperty(target, p, attrs);
66
+ }
67
+ });
68
+ const fn = api[key];
69
+ const result = await fn.call(trap, trap);
70
+ if ('string' == typeof result) return Buffer.from(result, 'utf-8');
71
+ if (result && 'object' == typeof result) return Buffer.from(JSON.stringify(result), 'utf-8');
72
+ return result;
73
+ };
74
+ }
75
+ constructor(options){
76
+ this.options = options;
77
+ }
78
+ }
79
+ Router.routes = {
80
+ get: new Map(),
81
+ post: new Map()
82
+ };
83
+ export { Router };
@@ -0,0 +1,5 @@
1
+ export declare const DEFAULT_ALLOWED_CORS_ORIGINS: RegExp;
2
+ export declare function isAllowedRequestOrigin(origin: string | string[] | undefined): boolean;
3
+ export declare function isAllowedRequestHost(host: string | string[] | undefined): boolean;
4
+ export declare function isAllowedCorsRequest(origin: string | string[] | undefined, host: string | string[] | undefined): boolean;
5
+ export declare function isAllowedOpenInEditorToken(token: string | null, expectedToken: string): boolean;
@@ -0,0 +1,47 @@
1
+ import "node:module";
2
+ import { isIP } from "node:net";
3
+ import { timingSafeEqual } from "node:crypto";
4
+ const DEFAULT_ALLOWED_CORS_ORIGINS = /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/;
5
+ const LOCAL_HOSTNAMES = /^(?:localhost|[^:]+\.localhost)$/;
6
+ function isAllowedRequestOrigin(origin) {
7
+ if (void 0 === origin) return true;
8
+ return 'string' == typeof origin && DEFAULT_ALLOWED_CORS_ORIGINS.test(origin);
9
+ }
10
+ function getHostnameFromOrigin(origin) {
11
+ try {
12
+ const hostname = new URL(origin).hostname.toLowerCase();
13
+ return hostname.startsWith('[') && hostname.endsWith(']') ? hostname.slice(1, -1) : hostname;
14
+ } catch {
15
+ return '';
16
+ }
17
+ }
18
+ function isIpAddress(hostname) {
19
+ return 0 !== isIP(hostname);
20
+ }
21
+ function getHostnameFromHost(host) {
22
+ if (host.startsWith('[')) {
23
+ const endIndex = host.indexOf(']');
24
+ return -1 === endIndex ? '' : host.slice(1, endIndex);
25
+ }
26
+ return host.split(':')[0];
27
+ }
28
+ function isAllowedRequestHost(host) {
29
+ if ('string' != typeof host) return false;
30
+ const hostname = getHostnameFromHost(host).toLowerCase();
31
+ return LOCAL_HOSTNAMES.test(hostname) || isIpAddress(hostname);
32
+ }
33
+ function isAllowedCorsRequest(origin, host) {
34
+ if (void 0 === origin) return true;
35
+ if ('string' != typeof origin || 'string' != typeof host || !isAllowedRequestOrigin(origin)) return false;
36
+ const originHostname = getHostnameFromOrigin(origin);
37
+ const hostHostname = getHostnameFromHost(host).toLowerCase();
38
+ if (originHostname.endsWith('.localhost')) return originHostname === hostHostname;
39
+ return true;
40
+ }
41
+ function isAllowedOpenInEditorToken(token, expectedToken) {
42
+ if ('string' != typeof token || !expectedToken) return false;
43
+ const tokenBuffer = Buffer.from(token);
44
+ const expectedTokenBuffer = Buffer.from(expectedToken);
45
+ return tokenBuffer.length === expectedTokenBuffer.length && timingSafeEqual(tokenBuffer, expectedTokenBuffer);
46
+ }
47
+ export { DEFAULT_ALLOWED_CORS_ORIGINS, isAllowedCorsRequest, isAllowedOpenInEditorToken, isAllowedRequestHost, isAllowedRequestOrigin };
@@ -0,0 +1,15 @@
1
+ import { Data } from '../../../common/index.js';
2
+ import { Manifest, SDK } from '@rsdoctor/shared/types';
3
+ interface SocketAPILoaderOptions {
4
+ sdk: SDK.RsdoctorBuilderSDKInstance;
5
+ }
6
+ export declare class SocketAPILoader implements Manifest.ManifestDataLoader {
7
+ protected options: SocketAPILoaderOptions;
8
+ protected dataLoader: Data.APIDataLoader;
9
+ constructor(options: SocketAPILoaderOptions);
10
+ loadManifest(): Promise<Manifest.RsdoctorManifestWithShardingFiles>;
11
+ loadData<T extends Manifest.RsdoctorManifestMappingKeys>(key: T): Promise<Manifest.InferManifestDataValue<T>>;
12
+ loadData(key: string): Promise<void>;
13
+ get loadAPIData(): <T extends SDK.ServerAPI.API | SDK.ServerAPI.APIExtends>(api: T, body: SDK.ServerAPI.InferRequestBodyType<T>) => Promise<SDK.ServerAPI.InferResponseType<T>>;
14
+ }
15
+ export {};
@@ -0,0 +1,22 @@
1
+ import "node:module";
2
+ import { Data } from "../../../common/index.js";
3
+ class SocketAPILoader {
4
+ async loadManifest() {
5
+ return this.options.sdk.getManifestData();
6
+ }
7
+ async loadData(key) {
8
+ const data = this.options.sdk.getStoreData();
9
+ const sep = '.';
10
+ let res = data[key];
11
+ if (key.includes(sep)) res = key.split(sep).reduce((t, k)=>t[k], data);
12
+ return res;
13
+ }
14
+ get loadAPIData() {
15
+ return this.dataLoader.loadAPI;
16
+ }
17
+ constructor(options){
18
+ this.options = options;
19
+ this.dataLoader = new Data.APIDataLoader(this);
20
+ }
21
+ }
22
+ export { SocketAPILoader };