@rsdoctor/core 2.0.0-alpha.1 → 2.0.0-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 (177) hide show
  1. package/dist/26.js +26174 -0
  2. package/dist/630.js +1280 -0
  3. package/dist/630.js.LICENSE.txt +7 -0
  4. package/dist/build-utils/build/chunks/assetsModules.d.ts +7 -1
  5. package/dist/build-utils/build/loader/probeLoader.d.ts +7 -2
  6. package/dist/build-utils/build/server.d.ts +1 -2
  7. package/dist/build-utils/build/utils/parseBundle.d.ts +1 -1
  8. package/dist/index.d.ts +5 -5
  9. package/dist/index.js +1908 -7
  10. package/dist/inner-plugins/constants.d.ts +1 -1
  11. package/dist/inner-plugins/plugins/base.d.ts +2 -2
  12. package/dist/inner-plugins/plugins/errors.d.ts +1 -0
  13. package/dist/inner-plugins/plugins/plugins.d.ts +1 -1
  14. package/dist/inner-plugins/plugins/summary.d.ts +3 -2
  15. package/dist/inner-plugins/utils/sdk.d.ts +2 -1
  16. package/dist/logger.d.ts +2 -2
  17. package/dist/probe-loader.js +2 -0
  18. package/dist/proxy-loader.d.ts +1 -0
  19. package/dist/proxy-loader.js +48 -0
  20. package/dist/rslib-runtime.js +28 -0
  21. package/dist/rspack-plugin/constants.d.ts +1 -1
  22. package/dist/rspack-plugin/multiple.d.ts +5 -3
  23. package/dist/rspack-plugin/plugin.d.ts +43 -17
  24. package/dist/rspack-plugin/session.d.ts +20 -0
  25. package/dist/rules/rules/ecma-version-check/htmlParserStub.d.ts +3 -0
  26. package/dist/rules/rules/ecma-version-check/types.d.ts +13 -2
  27. package/dist/sdk/multiple/controller.d.ts +13 -2
  28. package/dist/sdk/multiple/primary.d.ts +12 -4
  29. package/dist/sdk/server/apis/base.d.ts +1 -1
  30. package/dist/sdk/server/socket/api.d.ts +1 -1
  31. package/dist/sdk/utils/date.d.ts +1 -0
  32. package/dist/types/loader.d.ts +1 -1
  33. package/package.json +23 -117
  34. package/dist/build-utils/build/chunks/assetsModules.js +0 -9
  35. package/dist/build-utils/build/chunks/index.js +0 -3
  36. package/dist/build-utils/build/chunks/rspack/transform.js +0 -44
  37. package/dist/build-utils/build/envinfo.js +0 -60
  38. package/dist/build-utils/build/file/cache.js +0 -24
  39. package/dist/build-utils/build/file/index.js +0 -5
  40. package/dist/build-utils/build/file/sharding.js +0 -38
  41. package/dist/build-utils/build/index.js +0 -12
  42. package/dist/build-utils/build/json.js +0 -67
  43. package/dist/build-utils/build/loader/index.js +0 -3
  44. package/dist/build-utils/build/loader/probeLoader.js +0 -44
  45. package/dist/build-utils/build/loader/probeLoaderPlugin.js +0 -32
  46. package/dist/build-utils/build/module-graph/index.js +0 -2
  47. package/dist/build-utils/build/module-graph/parser.js +0 -13
  48. package/dist/build-utils/build/module-graph/rspack/transform.js +0 -111
  49. package/dist/build-utils/build/module-graph/utils.js +0 -60
  50. package/dist/build-utils/build/process.js +0 -18
  51. package/dist/build-utils/build/server.js +0 -107
  52. package/dist/build-utils/build/utils/index.js +0 -4
  53. package/dist/build-utils/build/utils/loader.js +0 -267
  54. package/dist/build-utils/build/utils/parseBundle.js +0 -238
  55. package/dist/build-utils/build/utils/plugin.js +0 -21
  56. package/dist/build-utils/index.js +0 -13
  57. package/dist/collection.d.ts +0 -1
  58. package/dist/collection.js +0 -2
  59. package/dist/common/file.js +0 -8
  60. package/dist/common/global-config.js +0 -33
  61. package/dist/common/index.d.ts +0 -4
  62. package/dist/common/index.js +0 -6
  63. package/dist/common-browser.d.ts +0 -1
  64. package/dist/common-browser.js +0 -2
  65. package/dist/error/error.js +0 -143
  66. package/dist/error/index.js +0 -3
  67. package/dist/error/transform.js +0 -138
  68. package/dist/error/utils.js +0 -23
  69. package/dist/graph/index.d.ts +0 -1
  70. package/dist/graph/index.js +0 -2
  71. package/dist/inner-plugins/constants.js +0 -19
  72. package/dist/inner-plugins/index.js +0 -3
  73. package/dist/inner-plugins/loaders/proxy.js +0 -65
  74. package/dist/inner-plugins/plugins/base.js +0 -20
  75. package/dist/inner-plugins/plugins/bundle.js +0 -63
  76. package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +0 -74
  77. package/dist/inner-plugins/plugins/errors.js +0 -65
  78. package/dist/inner-plugins/plugins/index.js +0 -11
  79. package/dist/inner-plugins/plugins/loader.js +0 -108
  80. package/dist/inner-plugins/plugins/plugins.js +0 -40
  81. package/dist/inner-plugins/plugins/progress.js +0 -35
  82. package/dist/inner-plugins/plugins/resolver.js +0 -57
  83. package/dist/inner-plugins/plugins/rspack.js +0 -99
  84. package/dist/inner-plugins/plugins/rules.js +0 -64
  85. package/dist/inner-plugins/plugins/sourcemapTool.js +0 -230
  86. package/dist/inner-plugins/plugins/summary.js +0 -92
  87. package/dist/inner-plugins/utils/circleDetect.js +0 -16
  88. package/dist/inner-plugins/utils/config.js +0 -141
  89. package/dist/inner-plugins/utils/index.js +0 -8
  90. package/dist/inner-plugins/utils/loader.js +0 -134
  91. package/dist/inner-plugins/utils/normalize-config.js +0 -77
  92. package/dist/inner-plugins/utils/openBrowser.js +0 -55
  93. package/dist/inner-plugins/utils/plugin-common.js +0 -94
  94. package/dist/inner-plugins/utils/plugin.js +0 -70
  95. package/dist/inner-plugins/utils/sdk.js +0 -19
  96. package/dist/logger.js +0 -51
  97. package/dist/rspack-plugin/constants.js +0 -23
  98. package/dist/rspack-plugin/index.js +0 -3
  99. package/dist/rspack-plugin/multiple.js +0 -39
  100. package/dist/rspack-plugin/plugin.js +0 -133
  101. package/dist/rule-utils/document/document.js +0 -46
  102. package/dist/rule-utils/document/index.js +0 -4
  103. package/dist/rule-utils/document/server.js +0 -13
  104. package/dist/rule-utils/document/types.js +0 -1
  105. package/dist/rule-utils/index.js +0 -3
  106. package/dist/rule-utils/parser/asserts.js +0 -105
  107. package/dist/rule-utils/parser/index.js +0 -5
  108. package/dist/rule-utils/parser/parser.js +0 -24
  109. package/dist/rule-utils/parser/types.js +0 -8
  110. package/dist/rule-utils/parser/utils.js +0 -106
  111. package/dist/rules/index.js +0 -4
  112. package/dist/rules/linter.js +0 -36
  113. package/dist/rules/rule.js +0 -101
  114. package/dist/rules/rules/cjs-require/index.js +0 -50
  115. package/dist/rules/rules/cjs-require/types.js +0 -1
  116. package/dist/rules/rules/cross-chunks-package/index.js +0 -41
  117. package/dist/rules/rules/cross-chunks-package/types.js +0 -1
  118. package/dist/rules/rules/cross-chunks-package/utils.js +0 -7
  119. package/dist/rules/rules/default-import-check/index.js +0 -83
  120. package/dist/rules/rules/default-import-check/types.js +0 -1
  121. package/dist/rules/rules/default-import-check/utils.js +0 -52
  122. package/dist/rules/rules/duplicate-package/index.js +0 -39
  123. package/dist/rules/rules/duplicate-package/types.js +0 -24
  124. package/dist/rules/rules/duplicate-package/utils.js +0 -38
  125. package/dist/rules/rules/ecma-version-check/index.js +0 -53
  126. package/dist/rules/rules/ecma-version-check/types.js +0 -1
  127. package/dist/rules/rules/ecma-version-check/utils.js +0 -6
  128. package/dist/rules/rules/esm-resolved-to-cjs/index.js +0 -193
  129. package/dist/rules/rules/esm-resolved-to-cjs/types.js +0 -1
  130. package/dist/rules/rules/index.js +0 -22
  131. package/dist/rules/rules/loader-performance-optimization/index.js +0 -86
  132. package/dist/rules/rules/loader-performance-optimization/types.js +0 -1
  133. package/dist/rules/rules/loader-performance-optimization/utils.js +0 -10
  134. package/dist/rules/rules/module-mixed-chunks/index.js +0 -52
  135. package/dist/rules/rules/module-mixed-chunks/types.js +0 -1
  136. package/dist/rules/rules/side-effects-only-imports/index.js +0 -81
  137. package/dist/rules/rules/side-effects-only-imports/types.js +0 -1
  138. package/dist/rules/utils.js +0 -10
  139. package/dist/sdk/index.js +0 -3
  140. package/dist/sdk/multiple/controller.js +0 -42
  141. package/dist/sdk/multiple/index.js +0 -3
  142. package/dist/sdk/multiple/primary.js +0 -64
  143. package/dist/sdk/multiple/server.js +0 -14
  144. package/dist/sdk/sdk/core.js +0 -163
  145. package/dist/sdk/sdk/index.js +0 -435
  146. package/dist/sdk/sdk/types.js +0 -1
  147. package/dist/sdk/server/apis/alerts.js +0 -30
  148. package/dist/sdk/server/apis/base.js +0 -22
  149. package/dist/sdk/server/apis/bundle-diff.js +0 -51
  150. package/dist/sdk/server/apis/data.js +0 -44
  151. package/dist/sdk/server/apis/fs.js +0 -28
  152. package/dist/sdk/server/apis/graph.js +0 -116
  153. package/dist/sdk/server/apis/index.js +0 -11
  154. package/dist/sdk/server/apis/loader.js +0 -120
  155. package/dist/sdk/server/apis/plugin.js +0 -39
  156. package/dist/sdk/server/apis/project.js +0 -59
  157. package/dist/sdk/server/apis/renderer.js +0 -33
  158. package/dist/sdk/server/apis/resolver.js +0 -38
  159. package/dist/sdk/server/client.js +0 -8
  160. package/dist/sdk/server/fakeServer.js +0 -12
  161. package/dist/sdk/server/index.js +0 -292
  162. package/dist/sdk/server/json-body.js +0 -150
  163. package/dist/sdk/server/router.js +0 -83
  164. package/dist/sdk/server/security.js +0 -47
  165. package/dist/sdk/server/socket/api.js +0 -22
  166. package/dist/sdk/server/socket/index.js +0 -166
  167. package/dist/sdk/server/utils.js +0 -19
  168. package/dist/sdk/utils/base.js +0 -22
  169. package/dist/sdk/utils/constant.js +0 -4
  170. package/dist/sdk/utils/index.js +0 -4
  171. package/dist/sdk/utils/openBrowser.js +0 -53
  172. package/dist/sdk/utils/upload.js +0 -6
  173. package/dist/sdk.js +0 -2
  174. package/dist/types/index.js +0 -4
  175. package/dist/types/loader.js +0 -1
  176. package/dist/types/plugin.js +0 -1
  177. package/dist/types/rules.js +0 -1
@@ -1,166 +0,0 @@
1
- import "node:module";
2
- import { SDK } from "@rsdoctor/shared/types";
3
- import ws, { WebSocketServer } from "ws";
4
- import { SocketAPILoader } from "./api.js";
5
- import { isAllowedRequestHost } from "../security.js";
6
- function isAllowedSocketToken(url, token) {
7
- if (!url) return false;
8
- return new URL(url, 'http://localhost').searchParams.get('token') === token;
9
- }
10
- class Socket {
11
- bootstrap() {
12
- this.server = new WebSocketServer({
13
- server: this.options.server,
14
- verifyClient: ({ req })=>{
15
- const host = req.headers.host || req.headers[':authority'];
16
- return isAllowedRequestHost(host) && isAllowedSocketToken(req.url, this.options.token);
17
- }
18
- });
19
- this.server.on('connection', (client)=>{
20
- this.attachClient(client);
21
- });
22
- }
23
- attachClient(client) {
24
- this.clients.add(client);
25
- if ('function' == typeof client.on) {
26
- client.on('message', (message)=>{
27
- this.handleClientMessage(message.toString(), client);
28
- });
29
- client.on('close', ()=>{
30
- this.clients.delete(client);
31
- this.removeClientSubscriptions(client);
32
- });
33
- }
34
- }
35
- async handleClientMessage(raw, client) {
36
- let message;
37
- try {
38
- message = JSON.parse(raw);
39
- } catch {
40
- return;
41
- }
42
- if (!message.api || !Object.values(SDK.ServerAPI.API).includes(message.api)) return;
43
- if ('request' === message.type) return void await this.handleAPIRequestMessage(message, client);
44
- if ('subscribe' === message.type) return void this.saveRequestToMap(message.api, message.body ?? null, client);
45
- if ('unsubscribe' === message.type) this.removeRequestFromMap(message.api, message.body ?? null, client);
46
- }
47
- async handleAPIRequestMessage(message, client) {
48
- if (!message.id || !client || client.readyState !== ws.OPEN) return;
49
- try {
50
- const response = await this.getAPIResponse(message.api, message.body);
51
- client.send(JSON.stringify({
52
- type: 'response',
53
- id: message.id,
54
- payload: response.res
55
- }));
56
- } catch (err) {
57
- client.send(JSON.stringify({
58
- type: 'response',
59
- id: message.id,
60
- error: err instanceof Error ? err.message : String(err)
61
- }));
62
- }
63
- }
64
- getSubscriptions() {
65
- return [
66
- ...this.map.values()
67
- ].map(({ api, body })=>({
68
- api,
69
- body
70
- }));
71
- }
72
- saveRequestToMap(api, body = null, client) {
73
- const key = this.getSubscriptionKey(api, body);
74
- if (client) {
75
- if (!this.clientSubscriptions.has(client)) this.clientSubscriptions.set(client, new Set());
76
- const subscriptions = this.clientSubscriptions.get(client);
77
- if (subscriptions.has(key)) return;
78
- subscriptions.add(key);
79
- }
80
- const record = this.map.get(key);
81
- if (record) {
82
- record.count += 1;
83
- return;
84
- }
85
- this.map.set(key, {
86
- api,
87
- body,
88
- count: 1
89
- });
90
- }
91
- removeRequestFromMap(api, body = null, client) {
92
- const key = this.getSubscriptionKey(api, body);
93
- if (client) {
94
- const subscriptions = this.clientSubscriptions.get(client);
95
- if (!subscriptions?.has(key)) return;
96
- subscriptions.delete(key);
97
- if (0 === subscriptions.size) this.clientSubscriptions.delete(client);
98
- }
99
- this.removeSubscriptionKey(key);
100
- }
101
- removeClientSubscriptions(client) {
102
- const subscriptions = this.clientSubscriptions.get(client);
103
- if (!subscriptions) return;
104
- subscriptions.forEach((key)=>this.removeSubscriptionKey(key));
105
- this.clientSubscriptions.delete(client);
106
- }
107
- removeSubscriptionKey(key) {
108
- const record = this.map.get(key);
109
- if (!record) return;
110
- record.count -= 1;
111
- if (record.count <= 0) this.map.delete(key);
112
- }
113
- getSubscriptionKey(api, body) {
114
- return `${api}:${JSON.stringify(body ?? null)}`;
115
- }
116
- async getAPIResponse(api, body) {
117
- const data = await this.loader.loadAPIData(api, body);
118
- const response = {
119
- req: {
120
- api,
121
- body
122
- },
123
- res: data
124
- };
125
- return response;
126
- }
127
- async broadcast() {
128
- clearImmediate(this.timer);
129
- this.timer = setImmediate(async ()=>{
130
- const promises = [];
131
- this.map.forEach(({ api, body })=>{
132
- promises.push((async ()=>{
133
- const res = await this.getAPIResponse(api, body);
134
- this.sendAPIData(api, res);
135
- })());
136
- });
137
- await Promise.all(promises);
138
- });
139
- }
140
- sendAPIData(api, payload) {
141
- const message = JSON.stringify({
142
- api,
143
- payload
144
- });
145
- this.clients.forEach((client)=>{
146
- if (client.readyState === ws.OPEN) client.send(message);
147
- });
148
- }
149
- dispose() {
150
- this.clients.forEach((client)=>{
151
- client.close();
152
- });
153
- this.clients.clear();
154
- this.server?.close();
155
- }
156
- constructor(options){
157
- this.options = options;
158
- this.clients = new Set();
159
- this.map = new Map();
160
- this.clientSubscriptions = new Map();
161
- this.loader = new SocketAPILoader({
162
- sdk: options.sdk
163
- });
164
- }
165
- }
166
- export { Socket };
@@ -1,19 +0,0 @@
1
- import "node:module";
2
- import os from "os";
3
- function getDataByPagination(data, pagination) {
4
- const { page = 1, pageSize = 1000 } = pagination;
5
- return {
6
- data: data.slice((page - 1) * pageSize, page * pageSize),
7
- pagination: {
8
- page,
9
- pageSize,
10
- hasNextPage: page <= 0 ? false : page * pageSize < data.length
11
- }
12
- };
13
- }
14
- function getLocalIpAddress() {
15
- const interfaces = os.networkInterfaces();
16
- for (const iface of Object.values(interfaces))for (const alias of iface)if ('IPv4' === alias.family && !alias.internal) return alias.address;
17
- return '127.0.0.1';
18
- }
19
- export { getDataByPagination, getLocalIpAddress };
@@ -1,22 +0,0 @@
1
- import "node:module";
2
- import path from "path";
3
- import fs from "fs";
4
- function findRoot(startDir = process.cwd()) {
5
- let dir = startDir;
6
- let firstPkgDir = null;
7
- while(dir !== path.parse(dir).root){
8
- if (fs.existsSync(path.join(dir, 'pnpm-workspace.yaml'))) return dir;
9
- if (fs.existsSync(path.join(dir, 'yarn.lock'))) return dir;
10
- if (fs.existsSync(path.join(dir, 'lerna.json'))) return dir;
11
- const pkgPath = path.join(dir, 'package.json');
12
- if (fs.existsSync(pkgPath)) {
13
- if (!firstPkgDir) firstPkgDir = dir;
14
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
15
- if (pkg.workspaces) return dir;
16
- }
17
- dir = path.dirname(dir);
18
- }
19
- if (firstPkgDir) return firstPkgDir;
20
- return null;
21
- }
22
- export { findRoot };
@@ -1,4 +0,0 @@
1
- import "node:module";
2
- import dayjs from "dayjs";
3
- const CLOUD_DIR = `rsdoctor/manifests/${dayjs().format('YYYYMMDD')}`;
4
- export { CLOUD_DIR };
@@ -1,4 +0,0 @@
1
- import "node:module";
2
- export * from "./constant.js";
3
- export * from "./base.js";
4
- export * from "./upload.js";
@@ -1,53 +0,0 @@
1
- import "node:module";
2
- import { exec } from "node:child_process";
3
- import { promisify } from "node:util";
4
- import { logger } from "../../logger.js";
5
- import { join } from "node:path";
6
- const execAsync = promisify(exec);
7
- const supportedChromiumBrowsers = [
8
- 'Google Chrome Canary',
9
- 'Google Chrome Dev',
10
- 'Google Chrome Beta',
11
- 'Google Chrome',
12
- 'Microsoft Edge',
13
- 'Brave Browser',
14
- 'Vivaldi',
15
- 'Chromium'
16
- ];
17
- const getTargetBrowser = async ()=>{
18
- let targetBrowser = process.env.BROWSER;
19
- if (!targetBrowser || !supportedChromiumBrowsers.includes(targetBrowser)) {
20
- const { stdout: ps } = await execAsync('ps cax');
21
- targetBrowser = supportedChromiumBrowsers.find((b)=>ps.includes(b));
22
- }
23
- return targetBrowser;
24
- };
25
- const openWithDefaultBrowser = async (url)=>{
26
- try {
27
- const { default: open } = await import("open");
28
- await open(url);
29
- return true;
30
- } catch (err) {
31
- logger.error('Failed to open Rsdoctor URL.');
32
- logger.error(err);
33
- return false;
34
- }
35
- };
36
- async function openBrowser(url, needEncodeURI = true) {
37
- const shouldTryOpenChromeWithAppleScript = 'darwin' === process.platform;
38
- if (shouldTryOpenChromeWithAppleScript) try {
39
- const targetBrowser = await getTargetBrowser();
40
- if (targetBrowser) {
41
- await execAsync(`osascript openChrome.applescript "${needEncodeURI ? encodeURI(url) : url}" "${targetBrowser}"`, {
42
- cwd: join(__dirname, '../static')
43
- });
44
- return true;
45
- }
46
- logger.debug('Failed to find the target browser.');
47
- } catch (err) {
48
- logger.debug("Failed to open Rsdoctor URL with apple script.");
49
- logger.debug(err);
50
- }
51
- return openWithDefaultBrowser(url);
52
- }
53
- export { openBrowser };
@@ -1,6 +0,0 @@
1
- import "node:module";
2
- const transformDataUrls = (d)=>d.reduce((t, item)=>{
3
- t[item.name] = Array.isArray(item.files) ? item.files.map((e)=>e.path).concat(t[item.name] || []) : item.files;
4
- return t;
5
- }, {});
6
- export { transformDataUrls };
package/dist/sdk.js DELETED
@@ -1,2 +0,0 @@
1
- import "node:module";
2
- export * from "./sdk/index.js";
@@ -1,4 +0,0 @@
1
- import "node:module";
2
- export * from "./rules.js";
3
- export * from "./loader.js";
4
- export * from "./plugin.js";
@@ -1 +0,0 @@
1
- import "node:module";
@@ -1 +0,0 @@
1
- import "node:module";
@@ -1 +0,0 @@
1
- import "node:module";