@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,60 +0,0 @@
1
- import "node:module";
2
- import envinfo from "envinfo";
3
- import { exec } from "child_process";
4
- const helpers = envinfo.helpers;
5
- const run = envinfo.run;
6
- const getCPUInfo = ()=>helpers.getCPUInfo().then((res)=>res[1]);
7
- const getOSInfo = ()=>helpers.getOSInfo().then((res)=>res[1]);
8
- const getMemoryInfo = ()=>helpers.getMemoryInfo().then((res)=>res[1]);
9
- const getNodeVersion = ()=>helpers.getNodeInfo().then((res)=>res[1]);
10
- const getYarnVersion = ()=>helpers.getYarnInfo().then((res)=>res[1]);
11
- const getNpmVersion = ()=>helpers.getnpmInfo().then((res)=>res[1]);
12
- const getPnpmVersion = ()=>helpers.getpnpmInfo().then((res)=>res[1]);
13
- function getNpmPackageVersion(pkg) {
14
- const isArray = Array.isArray(pkg);
15
- return run({
16
- npmPackages: isArray ? pkg : [
17
- pkg
18
- ]
19
- }, {
20
- json: true,
21
- showNotFound: true
22
- }).then((res)=>{
23
- const { npmPackages = {} } = JSON.parse(res) || {};
24
- return isArray ? pkg.map((e)=>npmPackages[e] || 'Not Found') : npmPackages[pkg];
25
- });
26
- }
27
- function getGlobalNpmPackageVersion(pkg) {
28
- const isArray = Array.isArray(pkg);
29
- return run({
30
- npmGlobalPackages: isArray ? pkg : [
31
- pkg
32
- ]
33
- }, {
34
- json: true,
35
- showNotFound: true
36
- }).then((res)=>{
37
- const { npmGlobalPackages = {} } = JSON.parse(res) || {};
38
- return isArray ? pkg.map((e)=>npmGlobalPackages[e] || 'Not Found') : npmGlobalPackages[pkg];
39
- });
40
- }
41
- function getGitBranch() {
42
- return new Promise((resolve, reject)=>{
43
- exec('git branch --show-current', (err, stdout)=>{
44
- if (err) exec('git branch', (err, stdout)=>{
45
- if (err) reject(err);
46
- else resolve(stdout.split('\n').map((e)=>e.replace('* ', '')).join('').trim());
47
- });
48
- else resolve(stdout.trim());
49
- });
50
- });
51
- }
52
- function getGitRepo() {
53
- return new Promise((resolve, reject)=>{
54
- exec('git config --get remote.origin.url', (err, stdout)=>{
55
- if (err) reject(err);
56
- else resolve(stdout.trim());
57
- });
58
- });
59
- }
60
- export { getCPUInfo, getGitBranch, getGitRepo, getGlobalNpmPackageVersion, getMemoryInfo, getNodeVersion, getNpmPackageVersion, getNpmVersion, getOSInfo, getPnpmVersion, getYarnVersion };
@@ -1,24 +0,0 @@
1
- import "node:module";
2
- import node_fs from "node:fs";
3
- const cache = new Map();
4
- async function readFile(path) {
5
- if (cache.has(path)) return cache.get(path);
6
- const res = await node_fs.promises.readFile(path, 'utf-8');
7
- cache.set(path, res);
8
- return res;
9
- }
10
- function readFileSync(path) {
11
- if (cache.has(path)) return cache.get(path);
12
- const res = node_fs.readFileSync(path, 'utf-8');
13
- cache.set(path, res);
14
- return res;
15
- }
16
- async function readJSON(path) {
17
- const str = await readFile(path);
18
- return JSON.parse(str);
19
- }
20
- function readJSONSync(path) {
21
- const str = readFileSync(path);
22
- return JSON.parse(str);
23
- }
24
- export { readFile, readFileSync, readJSON, readJSONSync };
@@ -1,5 +0,0 @@
1
- import "node:module";
2
- import * as __rspack_external__cache_js_3b19274f from "./cache.js";
3
- export * from "./sharding.js";
4
- export { default as fse } from "fs-extra";
5
- export { __rspack_external__cache_js_3b19274f as cache };
@@ -1,38 +0,0 @@
1
- import "node:module";
2
- import fs_extra from "fs-extra";
3
- import fs from "fs";
4
- import path from "path";
5
- class FileSharding {
6
- createVirtualShardingFiles(ext = '', index = 0) {
7
- const bf = Buffer.from(this.content, this.encoding);
8
- const res = [];
9
- const threshold = this.limitBytes;
10
- let tmpBytes = 0;
11
- while(bf.byteLength > tmpBytes){
12
- res.push(bf.subarray(tmpBytes, tmpBytes + threshold));
13
- tmpBytes += threshold;
14
- }
15
- return res.map((e, i)=>({
16
- filename: `${i + index}${ext}`,
17
- content: e
18
- }));
19
- }
20
- async writeStringToFolder(folder, ext = '', index) {
21
- const dist = path.resolve(folder);
22
- await fs_extra.ensureDir(dist);
23
- const res = this.createVirtualShardingFiles(ext, index);
24
- await Promise.all(res.map((e)=>new Promise((resolve, reject)=>{
25
- const stream = fs.createWriteStream(path.join(dist, e.filename), this.encoding);
26
- stream.end(e.content);
27
- stream.once('close', ()=>resolve(void 0));
28
- stream.once('error', (err)=>reject(err));
29
- })));
30
- return res;
31
- }
32
- constructor(content, limitBytes = 10485760, encoding = 'utf-8'){
33
- this.content = content;
34
- this.limitBytes = limitBytes;
35
- this.encoding = encoding;
36
- }
37
- }
38
- export { FileSharding };
@@ -1,12 +0,0 @@
1
- import "node:module";
2
- import * as __rspack_external__file_index_js_5cbcde29 from "./file/index.js";
3
- import * as __rspack_external__json_js_faef839e from "./json.js";
4
- import * as __rspack_external__server_js_186b33b9 from "./server.js";
5
- import * as __rspack_external__envinfo_js_2b90a03d from "./envinfo.js";
6
- import * as __rspack_external__process_js_7eda60d3 from "./process.js";
7
- import * as __rspack_external__chunks_index_js_c4bbc2de from "./chunks/index.js";
8
- import * as __rspack_external__utils_index_js_d2e4ad7a from "./utils/index.js";
9
- import * as __rspack_external__loader_index_js_ef25077c from "./loader/index.js";
10
- import * as __rspack_external__types_index_js_d78e4824 from "../../types/index.js";
11
- import * as __rspack_external__module_graph_index_js_f91481f4 from "./module-graph/index.js";
12
- export { __rspack_external__chunks_index_js_c4bbc2de as Chunks, __rspack_external__envinfo_js_2b90a03d as EnvInfo, __rspack_external__file_index_js_5cbcde29 as File, __rspack_external__json_js_faef839e as Json, __rspack_external__loader_index_js_ef25077c as Loader, __rspack_external__module_graph_index_js_f91481f4 as ModuleGraph, __rspack_external__process_js_7eda60d3 as Process, __rspack_external__server_js_186b33b9 as Server, __rspack_external__types_index_js_d78e4824 as Types, __rspack_external__utils_index_js_d2e4ad7a as Utils };
@@ -1,67 +0,0 @@
1
- import "node:module";
2
- import { JsonStreamStringify } from "json-stream-stringify";
3
- import { dirname, join } from "path";
4
- import { Package } from "../../common/index.js";
5
- import { Transform } from "stream";
6
- const maxFileSize = 419430400;
7
- function stringify(json, replacer, space, cycle) {
8
- const jsonList = [];
9
- if (json && 'object' == typeof json) return new Promise((resolve, reject)=>{
10
- const stream = new JsonStreamStringify(json, replacer, space, cycle);
11
- let currentLength = 0;
12
- let currentContent = '';
13
- const batchProcessor = new Transform({
14
- readableObjectMode: true,
15
- transform (chunk, _encoding, callback) {
16
- const lines = chunk.toString().split('\\n');
17
- lines.forEach((line)=>{
18
- if (currentLength + line.length > maxFileSize) {
19
- jsonList.push(currentContent);
20
- currentContent = '';
21
- currentLength = 0;
22
- }
23
- if (line.length) {
24
- currentContent += line;
25
- currentLength += line.length;
26
- }
27
- });
28
- callback();
29
- }
30
- });
31
- stream.pipe(batchProcessor).on('data', (line)=>{
32
- if (currentLength + line.length > maxFileSize) {
33
- jsonList.push(currentContent);
34
- currentContent = '';
35
- currentLength = 0;
36
- }
37
- if (line.length) {
38
- currentContent += line;
39
- currentLength += line.length;
40
- }
41
- }).on('end', ()=>{
42
- if (jsonList.length < 1) jsonList.push(currentContent);
43
- resolve(jsonList);
44
- }).on('error', (err)=>reject(err));
45
- });
46
- return Promise.resolve(JSON.stringify(json, replacer, space));
47
- }
48
- const readPackageJson = (file, readFile)=>{
49
- let result;
50
- let current = file;
51
- while('/' !== current && !result){
52
- const parent = dirname(current);
53
- if (parent === current) break;
54
- current = parent;
55
- if (readFile) result = readFile(join(current, 'package.json'));
56
- if (readFile) {
57
- if (!result?.name) result = void 0;
58
- } else result = Package.getPackageMetaFromModulePath(file);
59
- }
60
- if (!result) return;
61
- if (readFile && (!result.name || !result.version)) return readPackageJson(dirname(current), readFile);
62
- return {
63
- ...result,
64
- root: current
65
- };
66
- };
67
- export { readPackageJson, stringify };
@@ -1,3 +0,0 @@
1
- import "node:module";
2
- export * from "./probeLoaderPlugin.js";
3
- export * from "./probeLoader.js";
@@ -1,44 +0,0 @@
1
- import "node:module";
2
- import { parseQuery } from "../utils/index.js";
3
- import { getSDK } from "../../../inner-plugins/utils/sdk.js";
4
- import { omit } from "../../../collection.js";
5
- import path from "path";
6
- const loaderModule = function(...args) {
7
- const time = Date.now();
8
- const code = args[0];
9
- const _options = this.getOptions();
10
- const sdk = getSDK(_options.builderName);
11
- const loaderData = {
12
- resource: {
13
- path: this._module?.layer ? `${this.resourcePath}[${this._module.layer}]` : this.resourcePath,
14
- query: parseQuery(this.resourceQuery),
15
- queryRaw: this.resourceQuery,
16
- ext: path.extname(this.resourcePath).slice(1),
17
- ...this._module?.layer ? {
18
- layer: this._module.layer
19
- } : {}
20
- },
21
- loaders: [
22
- {
23
- loader: _options.loader,
24
- loaderIndex: this.loaderIndex,
25
- path: _options.loader,
26
- input: 'start' === _options.type ? code : null,
27
- result: 'end' === _options.type ? code : null,
28
- startAt: 'start' === _options.type ? time : 0,
29
- endAt: 'end' === _options.type ? time : 0,
30
- options: omit(_options.options, 'type'),
31
- isPitch: false,
32
- sync: false,
33
- errors: [],
34
- pid: process.pid,
35
- ppid: process.ppid
36
- }
37
- ]
38
- };
39
- sdk?.reportLoaderStartOrEnd(loaderData);
40
- this.callback(null, ...args);
41
- };
42
- const probeLoader = loaderModule;
43
- export default probeLoader;
44
- export { loaderModule };
@@ -1,32 +0,0 @@
1
- import "node:module";
2
- import { Loader } from "../../../common/index.js";
3
- import { Build } from "../../index.js";
4
- import { Utils } from "../index.js";
5
- const BuiltinLoaderName = 'builtin:swc-loader';
6
- const BuiltinLightingCssName = 'builtin:lightningcss-loader';
7
- const ESMLoaderFile = '.mjs';
8
- class ProbeLoaderPlugin {
9
- apply(compiler) {
10
- compiler.hooks.beforeRun.tap({
11
- name: 'ProbeLoaderPlugin'
12
- }, ()=>{
13
- this.addProbeLoader(compiler);
14
- });
15
- compiler.hooks.watchRun.tap({
16
- name: 'ProbeLoaderPlugin'
17
- }, ()=>{
18
- this.addProbeLoader(compiler);
19
- });
20
- }
21
- addProbeLoader(compiler) {
22
- let rules = compiler.options.module.rules;
23
- if (Loader.isVue(compiler)) {
24
- compiler.options.module.rules = Utils.addProbeLoader2Rules(rules, compiler, (r)=>!!r.loader || 'string' == typeof r);
25
- return;
26
- }
27
- rules = Utils.addProbeLoader2Rules(rules, compiler, (r)=>Build.Utils.getLoaderNameMatch(r, BuiltinLoaderName, true));
28
- rules = Utils.addProbeLoader2Rules(rules, compiler, (r)=>Build.Utils.getLoaderNameMatch(r, BuiltinLightingCssName, true));
29
- compiler.options.module.rules = Utils.addProbeLoader2Rules(rules, compiler, (r)=>Build.Utils.getLoaderNameMatch(r, ESMLoaderFile, false) || Build.Utils.isESMLoader(r));
30
- }
31
- }
32
- export { ProbeLoaderPlugin };
@@ -1,2 +0,0 @@
1
- import "node:module";
2
- export * from "./rspack/transform.js";
@@ -1,13 +0,0 @@
1
- import "node:module";
2
- import { parser } from "../../../rule-utils/index.js";
3
- const esmLabelStatement = parser.internal.parseExpressionAt('Object.defineProperty(exports, "__esModule", { value: true })', 0, {
4
- ecmaVersion: 6,
5
- ranges: false,
6
- locations: false,
7
- sourceType: "script"
8
- });
9
- function hasSetEsModuleStatement(program) {
10
- const expressions = program.body.filter(parser.asserts.isExpressionStatement).map((item)=>item.expression).filter(parser.asserts.isSimpleCallExpression);
11
- return expressions.some((exp)=>parser.utils.isSameSemantics(exp, esmLabelStatement));
12
- }
13
- export { hasSetEsModuleStatement };
@@ -1,111 +0,0 @@
1
- import "node:module";
2
- import { Dependency, Module, extractCodeFromSourceLines, parseLocation } from "../../../../graph/index.js";
3
- import { SDK } from "@rsdoctor/shared/types";
4
- const createDependencyKind = (type)=>{
5
- if (type.includes('harmony') || 'esm import' === type) return SDK.DependencyKind.ImportStatement;
6
- if (type.includes('cjs')) return SDK.DependencyKind.RequireCall;
7
- if (type.includes('import()')) return SDK.DependencyKind.DynamicImport;
8
- if (type.includes('amd')) return SDK.DependencyKind.AMDRequire;
9
- return SDK.DependencyKind.Unknown;
10
- };
11
- function patchNativeModuleGraph(mg, cg, rawModuleGraph) {
12
- const { modules: rawModules, dependencies: rawDependencies, chunkModules: rawChunkModules } = rawModuleGraph;
13
- const modules = rawModules.map((module)=>{
14
- const res = new Module(module.identifier, module.path, module.isEntry, 'concatenated' === module.kind ? SDK.ModuleKind.Concatenation : SDK.ModuleKind.Normal, void 0, module.layer);
15
- res.setId(module.ukey);
16
- return res;
17
- });
18
- mg.setModules(modules);
19
- for (const rawModule of rawModules){
20
- const module = mg.getModuleById(rawModule.ukey);
21
- if (module) module.setImported(rawModule.imported.map((ukey)=>mg.getModuleById(ukey)).filter(Boolean));
22
- }
23
- for (const rawModule of rawModules){
24
- const module = mg.getModuleById(rawModule.ukey);
25
- module.setModules(rawModule.modules.map((ukey)=>mg.getModuleById(ukey)).filter(Boolean));
26
- }
27
- for (const rawModule of rawModules){
28
- const module = mg.getModuleById(rawModule.ukey);
29
- if (module) module.setConcatenationModules(rawModule.belongModules.map((ukey)=>mg.getModuleById(ukey)).filter(Boolean));
30
- }
31
- for (const rawModule of rawModules){
32
- const module = mg.getModuleById(rawModule.ukey);
33
- if (module) module.setChunks(rawModule.chunks.map((ukey)=>cg.getChunkById(ukey.toString())).filter(Boolean));
34
- }
35
- for (const rawChunkModule of rawChunkModules){
36
- const chunk = cg.getChunkById(rawChunkModule.chunk.toString());
37
- if (chunk) chunk.setModules(rawChunkModule.modules.map((ukey)=>mg.getModuleById(ukey)).filter(Boolean));
38
- }
39
- const deppendencies = rawDependencies.map((dep)=>{
40
- const res = new Dependency(dep.request, mg.getModuleById(dep.module), mg.getModuleById(dep.dependency), createDependencyKind(dep.kind));
41
- res.setId(dep.ukey);
42
- if (void 0 !== dep.kind) res.typeString = dep.kind;
43
- return res;
44
- });
45
- mg.setDependencies(deppendencies);
46
- for (const rawModule of rawModules){
47
- const module = mg.getModuleById(rawModule.ukey);
48
- module.setDependencies(rawModule.dependencies.map((ukey)=>mg.getDependencyById(ukey)).filter(Boolean));
49
- if (module && rawModule.bailoutReason) rawModule.bailoutReason.filter((reason)=>!reason.includes('ModuleConcatenation bailout')).forEach((reason)=>module.addBailoutReason(reason));
50
- if (module && 'sideEffectsLocations' in rawModule && Array.isArray(rawModule.sideEffectsLocations) && rawModule.sideEffectsLocations.length) rawModule.sideEffectsLocations.forEach((item)=>{
51
- module.addSideEffectLocation({
52
- location: item.location,
53
- nodeType: item.nodeType,
54
- module: item.module,
55
- request: item.request
56
- });
57
- });
58
- }
59
- const rawConnectionsOnlyImports = rawModuleGraph.connectionsOnlyImports;
60
- if (rawConnectionsOnlyImports?.length) mg.setConnectionsOnlyImports(rawConnectionsOnlyImports);
61
- }
62
- function patchNativeModuleIds(mg, rawModuleIdsPatch) {
63
- const { moduleIds: rawModuleIds } = rawModuleIdsPatch;
64
- for (const rawModuleId of rawModuleIds){
65
- const module = mg.getModuleById(rawModuleId.module);
66
- if (module) module.setRenderId(rawModuleId.renderId);
67
- }
68
- }
69
- function patchNativeModuleSources(mg, rawModuleSourcesPatch) {
70
- const { moduleOriginalSources: rawModuleOriginalSources } = rawModuleSourcesPatch;
71
- for (const rawModuleOriginalSource of rawModuleOriginalSources){
72
- const module = mg.getModuleById(rawModuleOriginalSource.module);
73
- if (module) {
74
- module.setSource({
75
- source: rawModuleOriginalSource.source
76
- });
77
- module.setSize({
78
- sourceSize: rawModuleOriginalSource.size
79
- });
80
- }
81
- }
82
- const jsonModuleSizes = rawModuleSourcesPatch.jsonModuleSizes;
83
- if (jsonModuleSizes && jsonModuleSizes.length > 0) for (const jsonModuleSize of jsonModuleSizes){
84
- const module = mg.getModuleByIdentifier(jsonModuleSize.identifier);
85
- if (module) module.setSize({
86
- parsedSize: jsonModuleSize.size
87
- });
88
- }
89
- }
90
- function extractSideEffectCodes(mg) {
91
- const modules = mg.getModules();
92
- for (const module of modules){
93
- const sideEffectLocations = module.getSideEffectLocations();
94
- if (!sideEffectLocations.length) continue;
95
- const moduleSource = module.getSource();
96
- const source = moduleSource.source || moduleSource.parsedSource;
97
- if (!source) continue;
98
- const sourceLines = source.split('\n');
99
- for (const sideEffectLocation of sideEffectLocations){
100
- const parsedLocation = parseLocation(sideEffectLocation.location);
101
- if (!parsedLocation) continue;
102
- const code = extractCodeFromSourceLines(sourceLines, parsedLocation);
103
- if (code) module.addSideEffectCode({
104
- moduleId: module.id,
105
- startLine: parsedLocation.startLine,
106
- code
107
- });
108
- }
109
- }
110
- }
111
- export { extractSideEffectCodes, patchNativeModuleGraph, patchNativeModuleIds, patchNativeModuleSources };
@@ -1,60 +0,0 @@
1
- import "node:module";
2
- import { parser } from "../../../rule-utils/index.js";
3
- function getDefaultExportIdentifier(node, module, searchId) {
4
- const { declaration } = node;
5
- if (parser.asserts.isLiteral(declaration) && declaration.loc) return module.getStatement(declaration.loc);
6
- if (parser.asserts.isIdentifier(declaration)) {
7
- if (searchId) {
8
- const result = getDeclarationIdentifier(declaration.name, module);
9
- if (result) return result;
10
- } else if (declaration.loc) return module.getStatement(declaration.loc);
11
- }
12
- if (parser.asserts.isClassDeclaration(declaration) || parser.asserts.isFunctionDeclaration(declaration)) {
13
- if (declaration.id?.loc) return module.getStatement(declaration.id.loc);
14
- }
15
- const startLine = node.declaration.loc?.start.line;
16
- if ('number' != typeof startLine) return;
17
- const { transformed } = module.getSource();
18
- const line = transformed.split('\n')[startLine - 1];
19
- if (void 0 === line) return;
20
- const endColumn = line.length - 1;
21
- return module.getStatement({
22
- start: {
23
- line: startLine,
24
- column: 0
25
- },
26
- end: {
27
- line: startLine,
28
- column: endColumn
29
- }
30
- });
31
- }
32
- function getExportIdentifierStatement(name, module) {
33
- const ast = module.getProgram();
34
- if (!ast) return;
35
- for (const node of ast.body){
36
- if (parser.asserts.isExportDefaultDeclaration(node)) {
37
- const result = getDefaultExportIdentifier(node, module, false);
38
- if (result) return result;
39
- }
40
- const id = parser.utils.getIdentifierInExport(name, node);
41
- if (id?.loc) return module.getStatement(id.loc);
42
- }
43
- }
44
- function getDeclarationIdentifier(name, module) {
45
- const ast = module.getProgram();
46
- if (!ast) return;
47
- for (const node of ast.body){
48
- const id = parser.utils.getIdentifierInDeclaration(name, node);
49
- if (id?.loc) return module.getStatement(id.loc);
50
- if (parser.asserts.isExportNamedDeclaration(node) && node.declaration) {
51
- const id = parser.utils.getIdentifierInDeclaration(name, node.declaration);
52
- if (id?.loc) return module.getStatement(id.loc);
53
- }
54
- if ('default' === name && parser.asserts.isExportDefaultDeclaration(node)) {
55
- const result = getDefaultExportIdentifier(node, module, true);
56
- if (result) return result;
57
- }
58
- }
59
- }
60
- export { getDeclarationIdentifier, getExportIdentifierStatement };
@@ -1,18 +0,0 @@
1
- import "node:module";
2
- import { filesize } from "filesize";
3
- import { memoryUsage, pid } from "process";
4
- function getMemoryUsage() {
5
- return memoryUsage();
6
- }
7
- function getMemoryUsageMessage() {
8
- const usage = getMemoryUsage();
9
- const msgs = [
10
- `RSS: ${filesize(usage.rss)}`,
11
- `Heap Total: ${filesize(usage.heapTotal)}`,
12
- `Heap Used: ${filesize(usage.heapUsed)}`
13
- ];
14
- if (usage.arrayBuffers) msgs.push(`ArrayBuffers: ${filesize(usage.arrayBuffers)}`);
15
- if (usage.external) msgs.push(`External: ${filesize(usage.external)}`);
16
- return `["${pid}" Memory Usage] ${msgs.join(', ')}`;
17
- }
18
- export { getMemoryUsage, getMemoryUsageMessage };
@@ -1,107 +0,0 @@
1
- import "node:module";
2
- import connect from "connect";
3
- import http from "http";
4
- import os from "os";
5
- import get_port from "get-port";
6
- import { execFileSync } from "child_process";
7
- import { Algorithm } from "../../common/index.js";
8
- const RESTRICTED_PORTS = [
9
- 3659,
10
- 4045,
11
- 6000,
12
- 6665,
13
- 6666,
14
- 6667,
15
- 6668,
16
- 6669
17
- ];
18
- const defaultHost = '127.0.0.1';
19
- function getRandomPort(min, max) {
20
- let port;
21
- do port = Algorithm.random(min, max);
22
- while (RESTRICTED_PORTS.includes(port));
23
- return port;
24
- }
25
- const defaultPort = getRandomPort(3000, 8999);
26
- async function getPort(expectPort, host = defaultHost) {
27
- return get_port({
28
- port: expectPort,
29
- host
30
- });
31
- }
32
- const createGetPortSyncFunctionString = (expectPort, host = defaultHost)=>`
33
- (() => {
34
- const net = require('net');
35
-
36
- function getPort(expectPort, host) {
37
- return new Promise((resolve, reject) => {
38
- const server = net.createServer();
39
- server.unref();
40
- server.on('error', reject);
41
- server.listen(expectPort, host, () => {
42
- const { port } = server.address();
43
- server.close(() => {
44
- resolve(port);
45
- });
46
- });
47
- });
48
- }
49
-
50
- async function getAvailablePort(expectPort) {
51
- let port = expectPort;
52
- while (true) {
53
- try {
54
- const res = await getPort(port, ${JSON.stringify(host)});
55
- return res;
56
- } catch (error) {
57
- port += Math.floor(Math.random() * 100 + 1);
58
- }
59
- }
60
- }
61
-
62
- getAvailablePort(${expectPort}).then(port => process.stdout.write(port.toString()));
63
- })();
64
- `.trim();
65
- function getPortSync(expectPort, host = defaultHost) {
66
- const statement = '\n' === os.EOL ? createGetPortSyncFunctionString(expectPort, host) : createGetPortSyncFunctionString(expectPort, host).replace(/\n/g, '');
67
- const port = execFileSync(process.execPath, [
68
- '-e',
69
- statement
70
- ], {
71
- encoding: 'utf-8'
72
- });
73
- return Number(port);
74
- }
75
- function createApp() {
76
- return connect();
77
- }
78
- async function createServer(port, host = defaultHost) {
79
- const app = createApp();
80
- const server = http.createServer(app);
81
- const res = {
82
- app,
83
- server,
84
- port,
85
- close () {
86
- return new Promise((resolve, reject)=>{
87
- if ('closeAllConnections' in server) server.closeAllConnections();
88
- if ('closeIdleConnections' in server) server.closeIdleConnections();
89
- server.close((err)=>{
90
- if (err) reject(err);
91
- resolve();
92
- });
93
- });
94
- }
95
- };
96
- return new Promise((resolve, reject)=>{
97
- const onError = (error)=>{
98
- reject(error);
99
- };
100
- server.once('error', onError);
101
- server.listen(port, host, ()=>{
102
- server.off('error', onError);
103
- resolve(res);
104
- });
105
- });
106
- }
107
- export { createApp, createGetPortSyncFunctionString, createServer, defaultHost, defaultPort, getPort, getPortSync };
@@ -1,4 +0,0 @@
1
- import "node:module";
2
- export * from "./loader.js";
3
- export * from "./plugin.js";
4
- export * from "./parseBundle.js";