@rsdoctor/core 2.0.0-alpha.1 → 2.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/dist/26.js +26163 -0
  2. package/dist/630.js +1269 -0
  3. package/dist/630.js.LICENSE.txt +7 -0
  4. package/dist/build-utils/build/chunks/assetsModules.d.ts +7 -1
  5. package/dist/build-utils/build/loader/probeLoader.d.ts +7 -2
  6. package/dist/build-utils/build/utils/parseBundle.d.ts +1 -1
  7. package/dist/index.d.ts +5 -5
  8. package/dist/index.js +1725 -7
  9. package/dist/inner-plugins/constants.d.ts +1 -1
  10. package/dist/inner-plugins/plugins/base.d.ts +2 -2
  11. package/dist/logger.d.ts +2 -2
  12. package/dist/probe-loader.js +2 -0
  13. package/dist/proxy-loader.d.ts +1 -0
  14. package/dist/proxy-loader.js +48 -0
  15. package/dist/rslib-runtime.js +28 -0
  16. package/dist/rspack-plugin/constants.d.ts +1 -1
  17. package/dist/rules/rules/ecma-version-check/htmlParserStub.d.ts +3 -0
  18. package/dist/rules/rules/ecma-version-check/types.d.ts +13 -2
  19. package/dist/sdk/server/apis/base.d.ts +1 -1
  20. package/dist/sdk/server/socket/api.d.ts +1 -1
  21. package/dist/sdk/utils/date.d.ts +1 -0
  22. package/dist/types/loader.d.ts +1 -1
  23. package/package.json +20 -113
  24. package/dist/build-utils/build/chunks/assetsModules.js +0 -9
  25. package/dist/build-utils/build/chunks/index.js +0 -3
  26. package/dist/build-utils/build/chunks/rspack/transform.js +0 -44
  27. package/dist/build-utils/build/envinfo.js +0 -60
  28. package/dist/build-utils/build/file/cache.js +0 -24
  29. package/dist/build-utils/build/file/index.js +0 -5
  30. package/dist/build-utils/build/file/sharding.js +0 -38
  31. package/dist/build-utils/build/index.js +0 -12
  32. package/dist/build-utils/build/json.js +0 -67
  33. package/dist/build-utils/build/loader/index.js +0 -3
  34. package/dist/build-utils/build/loader/probeLoader.js +0 -44
  35. package/dist/build-utils/build/loader/probeLoaderPlugin.js +0 -32
  36. package/dist/build-utils/build/module-graph/index.js +0 -2
  37. package/dist/build-utils/build/module-graph/parser.js +0 -13
  38. package/dist/build-utils/build/module-graph/rspack/transform.js +0 -111
  39. package/dist/build-utils/build/module-graph/utils.js +0 -60
  40. package/dist/build-utils/build/process.js +0 -18
  41. package/dist/build-utils/build/server.js +0 -107
  42. package/dist/build-utils/build/utils/index.js +0 -4
  43. package/dist/build-utils/build/utils/loader.js +0 -267
  44. package/dist/build-utils/build/utils/parseBundle.js +0 -238
  45. package/dist/build-utils/build/utils/plugin.js +0 -21
  46. package/dist/build-utils/index.js +0 -13
  47. package/dist/collection.d.ts +0 -1
  48. package/dist/collection.js +0 -2
  49. package/dist/common/file.js +0 -8
  50. package/dist/common/global-config.js +0 -33
  51. package/dist/common/index.d.ts +0 -4
  52. package/dist/common/index.js +0 -6
  53. package/dist/common-browser.d.ts +0 -1
  54. package/dist/common-browser.js +0 -2
  55. package/dist/error/error.js +0 -143
  56. package/dist/error/index.js +0 -3
  57. package/dist/error/transform.js +0 -138
  58. package/dist/error/utils.js +0 -23
  59. package/dist/graph/index.d.ts +0 -1
  60. package/dist/graph/index.js +0 -2
  61. package/dist/inner-plugins/constants.js +0 -19
  62. package/dist/inner-plugins/index.js +0 -3
  63. package/dist/inner-plugins/loaders/proxy.js +0 -65
  64. package/dist/inner-plugins/plugins/base.js +0 -20
  65. package/dist/inner-plugins/plugins/bundle.js +0 -63
  66. package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +0 -74
  67. package/dist/inner-plugins/plugins/errors.js +0 -65
  68. package/dist/inner-plugins/plugins/index.js +0 -11
  69. package/dist/inner-plugins/plugins/loader.js +0 -108
  70. package/dist/inner-plugins/plugins/plugins.js +0 -40
  71. package/dist/inner-plugins/plugins/progress.js +0 -35
  72. package/dist/inner-plugins/plugins/resolver.js +0 -57
  73. package/dist/inner-plugins/plugins/rspack.js +0 -99
  74. package/dist/inner-plugins/plugins/rules.js +0 -64
  75. package/dist/inner-plugins/plugins/sourcemapTool.js +0 -230
  76. package/dist/inner-plugins/plugins/summary.js +0 -92
  77. package/dist/inner-plugins/utils/circleDetect.js +0 -16
  78. package/dist/inner-plugins/utils/config.js +0 -141
  79. package/dist/inner-plugins/utils/index.js +0 -8
  80. package/dist/inner-plugins/utils/loader.js +0 -134
  81. package/dist/inner-plugins/utils/normalize-config.js +0 -77
  82. package/dist/inner-plugins/utils/openBrowser.js +0 -55
  83. package/dist/inner-plugins/utils/plugin-common.js +0 -94
  84. package/dist/inner-plugins/utils/plugin.js +0 -70
  85. package/dist/inner-plugins/utils/sdk.js +0 -19
  86. package/dist/logger.js +0 -51
  87. package/dist/rspack-plugin/constants.js +0 -23
  88. package/dist/rspack-plugin/index.js +0 -3
  89. package/dist/rspack-plugin/multiple.js +0 -39
  90. package/dist/rspack-plugin/plugin.js +0 -133
  91. package/dist/rule-utils/document/document.js +0 -46
  92. package/dist/rule-utils/document/index.js +0 -4
  93. package/dist/rule-utils/document/server.js +0 -13
  94. package/dist/rule-utils/document/types.js +0 -1
  95. package/dist/rule-utils/index.js +0 -3
  96. package/dist/rule-utils/parser/asserts.js +0 -105
  97. package/dist/rule-utils/parser/index.js +0 -5
  98. package/dist/rule-utils/parser/parser.js +0 -24
  99. package/dist/rule-utils/parser/types.js +0 -8
  100. package/dist/rule-utils/parser/utils.js +0 -106
  101. package/dist/rules/index.js +0 -4
  102. package/dist/rules/linter.js +0 -36
  103. package/dist/rules/rule.js +0 -101
  104. package/dist/rules/rules/cjs-require/index.js +0 -50
  105. package/dist/rules/rules/cjs-require/types.js +0 -1
  106. package/dist/rules/rules/cross-chunks-package/index.js +0 -41
  107. package/dist/rules/rules/cross-chunks-package/types.js +0 -1
  108. package/dist/rules/rules/cross-chunks-package/utils.js +0 -7
  109. package/dist/rules/rules/default-import-check/index.js +0 -83
  110. package/dist/rules/rules/default-import-check/types.js +0 -1
  111. package/dist/rules/rules/default-import-check/utils.js +0 -52
  112. package/dist/rules/rules/duplicate-package/index.js +0 -39
  113. package/dist/rules/rules/duplicate-package/types.js +0 -24
  114. package/dist/rules/rules/duplicate-package/utils.js +0 -38
  115. package/dist/rules/rules/ecma-version-check/index.js +0 -53
  116. package/dist/rules/rules/ecma-version-check/types.js +0 -1
  117. package/dist/rules/rules/ecma-version-check/utils.js +0 -6
  118. package/dist/rules/rules/esm-resolved-to-cjs/index.js +0 -193
  119. package/dist/rules/rules/esm-resolved-to-cjs/types.js +0 -1
  120. package/dist/rules/rules/index.js +0 -22
  121. package/dist/rules/rules/loader-performance-optimization/index.js +0 -86
  122. package/dist/rules/rules/loader-performance-optimization/types.js +0 -1
  123. package/dist/rules/rules/loader-performance-optimization/utils.js +0 -10
  124. package/dist/rules/rules/module-mixed-chunks/index.js +0 -52
  125. package/dist/rules/rules/module-mixed-chunks/types.js +0 -1
  126. package/dist/rules/rules/side-effects-only-imports/index.js +0 -81
  127. package/dist/rules/rules/side-effects-only-imports/types.js +0 -1
  128. package/dist/rules/utils.js +0 -10
  129. package/dist/sdk/index.js +0 -3
  130. package/dist/sdk/multiple/controller.js +0 -42
  131. package/dist/sdk/multiple/index.js +0 -3
  132. package/dist/sdk/multiple/primary.js +0 -64
  133. package/dist/sdk/multiple/server.js +0 -14
  134. package/dist/sdk/sdk/core.js +0 -163
  135. package/dist/sdk/sdk/index.js +0 -435
  136. package/dist/sdk/sdk/types.js +0 -1
  137. package/dist/sdk/server/apis/alerts.js +0 -30
  138. package/dist/sdk/server/apis/base.js +0 -22
  139. package/dist/sdk/server/apis/bundle-diff.js +0 -51
  140. package/dist/sdk/server/apis/data.js +0 -44
  141. package/dist/sdk/server/apis/fs.js +0 -28
  142. package/dist/sdk/server/apis/graph.js +0 -116
  143. package/dist/sdk/server/apis/index.js +0 -11
  144. package/dist/sdk/server/apis/loader.js +0 -120
  145. package/dist/sdk/server/apis/plugin.js +0 -39
  146. package/dist/sdk/server/apis/project.js +0 -59
  147. package/dist/sdk/server/apis/renderer.js +0 -33
  148. package/dist/sdk/server/apis/resolver.js +0 -38
  149. package/dist/sdk/server/client.js +0 -8
  150. package/dist/sdk/server/fakeServer.js +0 -12
  151. package/dist/sdk/server/index.js +0 -292
  152. package/dist/sdk/server/json-body.js +0 -150
  153. package/dist/sdk/server/router.js +0 -83
  154. package/dist/sdk/server/security.js +0 -47
  155. package/dist/sdk/server/socket/api.js +0 -22
  156. package/dist/sdk/server/socket/index.js +0 -166
  157. package/dist/sdk/server/utils.js +0 -19
  158. package/dist/sdk/utils/base.js +0 -22
  159. package/dist/sdk/utils/constant.js +0 -4
  160. package/dist/sdk/utils/index.js +0 -4
  161. package/dist/sdk/utils/openBrowser.js +0 -53
  162. package/dist/sdk/utils/upload.js +0 -6
  163. package/dist/sdk.js +0 -2
  164. package/dist/types/index.js +0 -4
  165. package/dist/types/loader.js +0 -1
  166. package/dist/types/plugin.js +0 -1
  167. package/dist/types/rules.js +0 -1
@@ -1,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";