@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,143 +0,0 @@
1
- import "node:module";
2
- import { codeFrameColumns } from "@babel/code-frame";
3
- import { Lodash } from "../common/index.js";
4
- import { Err } from "@rsdoctor/shared/types";
5
- import { createColors } from "picocolors";
6
- import deep_eql from "deep-eql";
7
- import strip_ansi from "strip-ansi";
8
- import { transform } from "./transform.js";
9
- import { insertSpace, toLevel } from "./utils.js";
10
- let id = 1;
11
- class DevToolError extends Error {
12
- static from(err, opt) {
13
- if (err instanceof DevToolError) return err;
14
- return transform(err, opt);
15
- }
16
- get level() {
17
- return Err.ErrorLevel[this._level];
18
- }
19
- get path() {
20
- return this._codeFrame?.filePath;
21
- }
22
- set path(file) {
23
- if (!file) return;
24
- if (this._codeFrame) {
25
- this._codeFrame.filePath = file;
26
- return;
27
- }
28
- this._codeFrame = {
29
- filePath: file
30
- };
31
- }
32
- get codeFrame() {
33
- return this._codeFrame;
34
- }
35
- printCodeFrame(print) {
36
- const msgs = [];
37
- const { _codeFrame: codeFrameOpt, _controller: controller } = this;
38
- if (!codeFrameOpt) return msgs;
39
- if ('start' in codeFrameOpt && codeFrameOpt.start) {
40
- const { filePath, start } = codeFrameOpt;
41
- msgs.push(`\n ${print.red(print.bold('File: '))}${print.bold(filePath)}:${start.line}${start.column ? `:${start.column}` : ''}`);
42
- if ('fileContent' in codeFrameOpt) {
43
- const { end, fileContent } = codeFrameOpt;
44
- msgs.push(codeFrameColumns(fileContent, {
45
- start,
46
- end
47
- }, {
48
- highlightCode: !controller.noColor
49
- }));
50
- } else if ('lineText' in codeFrameOpt) {
51
- const { length, lineText } = codeFrameOpt;
52
- let lineCodeFrame = codeFrameColumns(lineText, {
53
- start: {
54
- line: 1,
55
- column: start.column
56
- },
57
- end: {
58
- line: 1,
59
- column: Lodash.isNil(start.column) || Lodash.isNil(length) ? void 0 : start.column + length
60
- }
61
- }, {
62
- highlightCode: !controller.noColor
63
- });
64
- if (start.line > 1) {
65
- lineCodeFrame = lineCodeFrame.replace(' 1 |', ` ${start.line} |`);
66
- if (start.line >= 10) lineCodeFrame = insertSpace(lineCodeFrame, 2, String(start.line).length - 1);
67
- }
68
- msgs.push(lineCodeFrame);
69
- }
70
- } else msgs.push(`\n ${print.red(print.bold('File: '))}${print.bold(codeFrameOpt.filePath)}\n`);
71
- return msgs;
72
- }
73
- toString() {
74
- const msgs = [];
75
- const { code, title, message, hint, referenceUrl, _controller: controller } = this;
76
- const print = createColors(!controller.noColor);
77
- const mainColorPrint = this._level === Err.ErrorLevel.Error ? print.red : print.yellow;
78
- const codeText = code ? `${mainColorPrint(print.blue(code))}:` : '';
79
- msgs.push(mainColorPrint(print.bold(`[${codeText}${this.level}:${title.toUpperCase()}] `) + message));
80
- msgs.push(...this.printCodeFrame(print));
81
- if (hint || referenceUrl) msgs.push('');
82
- if (hint) msgs.push(` ${print.blue(`HINT: ${hint}`)}`);
83
- if (referenceUrl) msgs.push(print.magenta(print.bold(` See: ${referenceUrl}`)));
84
- if (!controller.noStack && this.stack) msgs.push(print.red(print.bold(` Error Stack:\n${this.stack}\n`)));
85
- return msgs.join('\n');
86
- }
87
- toData() {
88
- return {
89
- ...this.detail,
90
- id: this.id,
91
- category: this.category,
92
- description: strip_ansi(this.detail?.description ?? this.message),
93
- title: this.title.toUpperCase(),
94
- code: this.code,
95
- level: this.level.toLowerCase()
96
- };
97
- }
98
- toError() {
99
- const error = new Error();
100
- error.message = this.toString();
101
- error.name = this.name;
102
- error.stack = this.stack;
103
- return error;
104
- }
105
- toJSON() {
106
- return {
107
- message: this.toString(),
108
- name: this.name,
109
- stack: this.stack
110
- };
111
- }
112
- setControllerOption(opt) {
113
- this._controller = {
114
- noStack: opt.noStack ?? this._controller.noStack ?? true,
115
- noColor: opt.noColor ?? this._controller.noColor ?? false
116
- };
117
- }
118
- setCodeFrame(opt) {
119
- this._codeFrame = opt;
120
- }
121
- isSame(error) {
122
- return this.code === error.code && this.message === error.message && this.hint === error.hint && this.level === error.level && this.title === error.title && this.referenceUrl === error.referenceUrl && this.code === error.code && deep_eql(this.codeFrame, error.codeFrame);
123
- }
124
- constructor(title, message, opts){
125
- super(message), this._controller = {
126
- noStack: true,
127
- noColor: false
128
- };
129
- this.id = id++;
130
- this.title = title;
131
- this.code = opts?.code;
132
- this.hint = opts?.hint;
133
- this.stack = opts?.stack;
134
- this.detail = opts?.detail;
135
- this.fixData = opts?.fixData;
136
- this.category = opts?.category;
137
- this.referenceUrl = opts?.referenceUrl;
138
- this._level = opts?.level ? toLevel(opts.level) : Err.ErrorLevel.Error;
139
- this._codeFrame = opts?.codeFrame;
140
- this.setControllerOption(opts?.controller ?? {});
141
- }
142
- }
143
- export { DevToolError };
@@ -1,3 +0,0 @@
1
- import "node:module";
2
- export * from "./error.js";
3
- export { printErrors } from "./utils.js";
@@ -1,138 +0,0 @@
1
- import "node:module";
2
- import strip_ansi from "strip-ansi";
3
- import { Linter } from "@rsdoctor/shared/types";
4
- import { DevToolError } from "./error.js";
5
- const MAX_ERROR_MESSAGE_LENGTH = 1000;
6
- function truncateMessage(input, maxLen = MAX_ERROR_MESSAGE_LENGTH) {
7
- const str = 'string' == typeof input ? input : String(input ?? '');
8
- return str.length > maxLen ? str.slice(0, maxLen) : str;
9
- }
10
- function isEsbuildError(err) {
11
- return 'pluginName' in err && 'text' in err && 'location' in err;
12
- }
13
- function isBabelError(err) {
14
- return 'code' in err && 'reasonCode' in err;
15
- }
16
- function isDiagnosticError(err) {
17
- return 'severity' in err && 'title' in err;
18
- }
19
- function parseBabelErrorMessage(input) {
20
- const lines = strip_ansi(truncateMessage(input)).split('\n');
21
- const filePath = lines[0].replace(/^([^:]+):.*/, '$1');
22
- const message = lines[0].replace(/.*: (.*) \(\d+:\d+\)*/, '$1');
23
- const lineText = lines.find((line)=>line.startsWith('> '))?.replace(/> \d+ \| /, '') ?? '';
24
- return {
25
- message,
26
- filePath,
27
- lineText
28
- };
29
- }
30
- function clearMessage(str) {
31
- return strip_ansi(truncateMessage(str)).replace(/.*: (.*)\n\n[\s\S]*/g, '$1');
32
- }
33
- function clearStack(str) {
34
- return str.slice(str.indexOf(' at')).replace(/\s*at(.*) \((.*)\)/g, '$1\n$2\n');
35
- }
36
- function transformEsbuildError(err, opt) {
37
- if (isEsbuildError(err)) {
38
- const errorCode = opt?.code ?? 'ESBUILD_ERROR';
39
- const speedyError = 'object' == typeof err.detail ? DevToolError.from(err.detail) : new DevToolError(errorCode, clearMessage(err.text), {
40
- ...opt,
41
- hint: err.location?.suggestion,
42
- codeFrame: {
43
- filePath: err.text.split(':')[0]
44
- }
45
- });
46
- if (err.location) speedyError.setCodeFrame({
47
- filePath: err.location.file,
48
- lineText: err.location.lineText,
49
- length: err.location.length,
50
- start: {
51
- line: err.location.line,
52
- column: err.location.column + 1
53
- }
54
- });
55
- return speedyError;
56
- }
57
- }
58
- function transformBabelError(err, opt) {
59
- if (isBabelError(err)) {
60
- const errorCode = opt?.code ?? err.code ?? 'BABEL';
61
- const title = err.reasonCode;
62
- const errorParsed = parseBabelErrorMessage(err.message);
63
- const speedyError = new DevToolError(title, truncateMessage(errorParsed.message), {
64
- ...opt,
65
- code: errorCode,
66
- stack: err.stack && clearStack(err.stack)
67
- });
68
- if (err.loc) speedyError.setCodeFrame({
69
- ...errorParsed,
70
- start: {
71
- line: err.loc.line,
72
- column: err.loc.column + 1
73
- }
74
- });
75
- return speedyError;
76
- }
77
- }
78
- function transformNormalError(err, opt) {
79
- if (err instanceof Error) {
80
- const stacks = [];
81
- const filePath = stacks?.[0]?.getFileName?.();
82
- return new DevToolError(err.name, clearMessage(err.message), {
83
- ...opt,
84
- codeFrame: filePath ? {
85
- filePath
86
- } : void 0,
87
- stack: err.stack && clearStack(err.stack)
88
- });
89
- }
90
- }
91
- function transformErrorLike(err, opt) {
92
- const isErrorLike = err && 'object' == typeof err && err.message;
93
- if (isErrorLike) {
94
- const stacks = [];
95
- const filePath = stacks?.[0]?.getFileName?.();
96
- const message = truncateMessage(err.message);
97
- return new DevToolError(err.name || 'UNKNOWN_ERROR', clearMessage(message), {
98
- ...opt,
99
- codeFrame: filePath ? {
100
- filePath
101
- } : void 0,
102
- stack: err.stack && clearStack(err.stack)
103
- });
104
- }
105
- }
106
- function transformDiagnostic(err, opt) {
107
- if (isDiagnosticError(err)) return new DevToolError(err.title, truncateMessage(err.message), {
108
- ...err,
109
- ...opt,
110
- hint: err.suggestions?.description,
111
- fixData: err.suggestions?.fixData,
112
- codeFrame: err.document ? {
113
- filePath: err.document.path,
114
- fileContent: err.document.content,
115
- start: err.document.range.start,
116
- end: err.document.range.end
117
- } : void 0,
118
- level: Linter.Severity[err.severity]
119
- });
120
- }
121
- function defaultError(err, opt) {
122
- return new DevToolError('UNKNOWN_ERROR', JSON.stringify(err), opt);
123
- }
124
- function transform(err, opt) {
125
- const transformers = [
126
- transformEsbuildError,
127
- transformBabelError,
128
- transformDiagnostic,
129
- transformNormalError,
130
- transformErrorLike
131
- ];
132
- for (const fn of transformers){
133
- const result = fn(err, opt);
134
- if (result) return result;
135
- }
136
- return defaultError(err, opt);
137
- }
138
- export { transform };
@@ -1,23 +0,0 @@
1
- import "node:module";
2
- import { Err } from "@rsdoctor/shared/types";
3
- function toLevel(level) {
4
- return Err.ErrorLevel[level];
5
- }
6
- function insertSpace(rawLines, line, width) {
7
- const lines = rawLines.split('\n');
8
- lines[line - 1] = Array(width).fill(' ').join('') + lines[line - 1];
9
- return lines.join('\n');
10
- }
11
- function printErrors({ errors, warnings }, logLevel = 'Error') {
12
- const onlyError = 'Error' === logLevel;
13
- if ('Silent' === logLevel) return '';
14
- if (onlyError && 0 === errors.length || !onlyError && 0 === errors.length && 0 === warnings.length) return '';
15
- const msgs = [];
16
- if (onlyError) msgs.push(`Build failed with ${errors.length} error:`, ...errors.map((item)=>item.toString()), '');
17
- else {
18
- const title = 0 === errors.length ? `Build succuss with ${warnings.length} warning:` : `Build failed with ${errors.length} error, ${warnings.length} warning:`;
19
- msgs.push(title, ...errors.map((item)=>item.toString()), ...warnings.map((item)=>item.toString()), '');
20
- }
21
- return msgs.join('\n\n');
22
- }
23
- export { insertSpace, printErrors, toLevel };
@@ -1 +0,0 @@
1
- export * from '@rsdoctor/shared/graph';
@@ -1,2 +0,0 @@
1
- import "node:module";
2
- export * from "@rsdoctor/shared/graph";
@@ -1,19 +0,0 @@
1
- import "node:module";
2
- const pluginTapName = 'RsdoctorRspackPlugin';
3
- const pluginTapPostOptions = {
4
- name: pluginTapName,
5
- stage: 999
6
- };
7
- const pluginTapPreOptions = {
8
- name: pluginTapName,
9
- stage: -999
10
- };
11
- const internalPluginTapPreOptions = (namespace)=>({
12
- name: `${pluginTapName}:${namespace}`,
13
- stage: -998
14
- });
15
- const internalPluginTapPostOptions = (namespace)=>({
16
- name: `${pluginTapName}:${namespace}`,
17
- stage: 1000
18
- });
19
- export { internalPluginTapPostOptions, internalPluginTapPreOptions, pluginTapName, pluginTapPostOptions, pluginTapPreOptions };
@@ -1,3 +0,0 @@
1
- import "node:module";
2
- export * from "./plugins/index.js";
3
- export * from "./utils/index.js";
@@ -1,65 +0,0 @@
1
- import "node:module";
2
- import { Utils } from "../../build-utils/build/index.js";
3
- import { getOriginLoaderModule, reportLoader, shouldSkipLoader } from "../utils/index.js";
4
- const loaderModule = function(...args) {
5
- if (shouldSkipLoader(this)) return void this.callback(null, ...args);
6
- this.cacheable(false);
7
- const mod = getOriginLoaderModule(this);
8
- if (mod.default) {
9
- if (false === mod.raw && Buffer.isBuffer(args[0])) args[0] = args[0].toString();
10
- let start = 0;
11
- let startHRTime = [
12
- 0,
13
- 0
14
- ];
15
- const trap = Utils.createLoaderContextTrap.call(this, (err, res, sourceMap)=>{
16
- reportLoader(this, start, startHRTime, false, false, args[0].toString(), err, res, sourceMap);
17
- });
18
- start = Date.now();
19
- startHRTime = process.hrtime();
20
- try {
21
- const result = mod.default.apply(trap, args);
22
- if (result) {
23
- if (!(result instanceof Promise)) reportLoader(this, start, startHRTime, false, true, args[0].toString(), null, result);
24
- }
25
- return result || '';
26
- } catch (error) {
27
- reportLoader(this, start, startHRTime, false, true, args[0].toString(), error, null);
28
- throw error;
29
- }
30
- }
31
- this.callback(null, ...args);
32
- };
33
- const pitch = function() {
34
- if (shouldSkipLoader(this)) return;
35
- this.cacheable(false);
36
- const mod = getOriginLoaderModule(this);
37
- if (mod.pitch && 'function' == typeof mod.pitch) {
38
- let start = 0;
39
- let startHRTime = [
40
- 0,
41
- 0
42
- ];
43
- const trap = Utils.createLoaderContextTrap.call(this, (err, res)=>{
44
- reportLoader(this, start, startHRTime, true, false, err ? 'Loader Pitch Async Error' : '', err, res);
45
- });
46
- start = Date.now();
47
- startHRTime = process.hrtime();
48
- try {
49
- const res = mod.pitch.apply(trap, arguments);
50
- if (res) {
51
- if (!(res instanceof Promise)) reportLoader(this, start, startHRTime, true, true, '', null, res);
52
- }
53
- return res;
54
- } catch (error) {
55
- reportLoader(this, start, startHRTime, true, true, 'Loader Pitch Sync Error', error, null);
56
- throw error;
57
- }
58
- }
59
- };
60
- loaderModule.raw = true;
61
- loaderModule.pitch = pitch;
62
- const raw = true;
63
- const proxy = loaderModule;
64
- export default proxy;
65
- export { pitch, raw };
@@ -1,20 +0,0 @@
1
- import "node:module";
2
- import { internalPluginTapPostOptions, internalPluginTapPreOptions } from "../constants.js";
3
- class InternalBasePlugin {
4
- get options() {
5
- return this.scheduler.options;
6
- }
7
- get sdk() {
8
- return this.scheduler.sdk;
9
- }
10
- get tapPostOptions() {
11
- return internalPluginTapPostOptions(this.name);
12
- }
13
- get tapPreOptions() {
14
- return internalPluginTapPreOptions(this.name);
15
- }
16
- constructor(scheduler){
17
- this.scheduler = scheduler;
18
- }
19
- }
20
- export { InternalBasePlugin };
@@ -1,63 +0,0 @@
1
- import "node:module";
2
- import { Manifest } from "@rsdoctor/shared/types";
3
- import { InternalBasePlugin } from "./base.js";
4
- import { Chunks } from "../../graph/index.js";
5
- import { logger, time, timeEnd } from "../../logger.js";
6
- class InternalBundlePlugin extends InternalBasePlugin {
7
- apply(compiler) {
8
- time('InternalBundlePlugin.apply');
9
- try {
10
- this.scheduler.ensureModulesChunksGraphApplied(compiler);
11
- this.changeDevtoolModuleFilename(compiler);
12
- compiler.hooks.compilation.tap(this.tapPostOptions, this.thisCompilation);
13
- compiler.hooks.done.tapPromise(this.tapPreOptions, this.done.bind(this));
14
- } finally{
15
- timeEnd('InternalBundlePlugin.apply');
16
- }
17
- }
18
- changeDevtoolModuleFilename(compiler) {
19
- const devtool = compiler.options.devtool;
20
- if (devtool) {
21
- if (!compiler.options.output) compiler.options.output = {};
22
- compiler.options.output.devtoolModuleFilenameTemplate = '[absolute-resource-path]';
23
- logger.warn("output.devtoolModuleFilenameTemplate has been changed to [absolute-resource-path], this is for bundle analysis.");
24
- if ('string' == typeof devtool && devtool.includes('source-map')) compiler.options.output.devtoolFallbackModuleFilenameTemplate = ()=>'[absolute-resource-path]';
25
- }
26
- }
27
- ensureAssetContent(name) {
28
- const asset = this.map.get(name);
29
- if (asset) return asset;
30
- const v = {
31
- content: ''
32
- };
33
- this.map.set(name, v);
34
- return v;
35
- }
36
- constructor(...args){
37
- super(...args), this.name = 'bundle', this.map = new Map(), this.thisCompilation = (compilation)=>{
38
- time('InternalBundlePlugin.thisCompilation');
39
- try {
40
- if (compilation.hooks.processAssets) compilation.hooks.afterProcessAssets.tap(this.tapPostOptions, (assets)=>{
41
- Object.keys(assets).forEach((file)=>{
42
- const v = this.ensureAssetContent(file);
43
- v.content = assets[file].source().toString();
44
- });
45
- });
46
- } finally{
47
- timeEnd('InternalBundlePlugin.thisCompilation');
48
- }
49
- }, this.done = async ()=>{
50
- time('InternalBundlePlugin.done');
51
- try {
52
- if (this.scheduler.chunkGraph) Chunks.assetsContents(this.map, this.scheduler.chunkGraph, this.scheduler.options?.supports);
53
- this.sdk.addClientRoutes([
54
- Manifest.RsdoctorManifestClientRoutes.ModuleGraph,
55
- Manifest.RsdoctorManifestClientRoutes.BundleSize
56
- ]);
57
- } finally{
58
- timeEnd('InternalBundlePlugin.done');
59
- }
60
- };
61
- }
62
- }
63
- export { InternalBundlePlugin };
@@ -1,74 +0,0 @@
1
- import "node:module";
2
- import { chalk, logger } from "../../logger.js";
3
- import { Chunks } from "../../build-utils/build/index.js";
4
- import { internalPluginTapPreOptions, pluginTapPostOptions } from "../constants.js";
5
- import { applyRspackNativePlugin, getRspackNativePlugin } from "./rspack.js";
6
- import { handleAfterEmitAssets } from "./sourcemapTool.js";
7
- let hasConsole = false;
8
- const ensureModulesChunksGraphFn = (compiler, _this)=>{
9
- if (_this._modulesGraphApplied) return;
10
- const RsdoctorRspackPlugin = getRspackNativePlugin(compiler);
11
- _this._modulesGraphApplied = true;
12
- const nativeGraphState = applyRspackNativePlugin(compiler, _this, RsdoctorRspackPlugin);
13
- if (!_this._realSourcePathCache) _this._realSourcePathCache = new Map();
14
- compiler.hooks.done.tapPromise(internalPluginTapPreOptions('moduleGraph'), async ()=>{
15
- await doneHandler(_this, compiler, nativeGraphState);
16
- });
17
- compiler.hooks.compilation.tap({
18
- ...pluginTapPostOptions,
19
- name: 'RsdoctorSourceMapCollector'
20
- }, (compilation)=>{
21
- if (compilation.hooks.processAssets) compilation.hooks.processAssets.tapPromise({
22
- name: 'RsdoctorSourceMapCollector',
23
- stage: 2400
24
- }, async ()=>{
25
- if (!ensureDevtools(compiler)) return;
26
- const { namespace, sourceMapFilenameRegex } = calculateNamespaceAndRegex(compiler);
27
- await handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex, namespace);
28
- });
29
- });
30
- };
31
- async function doneHandler(_this, compiler, nativeGraphState) {
32
- if (!nativeGraphState.chunkGraph || !_this.chunkGraph) throw new Error('[RsdoctorRspackPlugin] The Rspack native plugin did not provide chunk graph data.');
33
- if (!nativeGraphState.moduleGraph) throw new Error('[RsdoctorRspackPlugin] The Rspack native plugin did not provide module graph data.');
34
- const shouldParseBundle = false !== _this.options.supports.parseBundle;
35
- await getModulesInfos(compiler, _this.modulesGraph, _this.chunkGraph, shouldParseBundle, _this.sourceMapSets, _this.assetsWithoutSourceMap);
36
- logger.debug('reportModuleGraph start');
37
- await _this.sdk.reportModuleGraph(_this.modulesGraph);
38
- logger.debug('reportModuleGraph done');
39
- logger.debug('reportChunkGraph start');
40
- await _this.sdk.reportChunkGraph(_this.chunkGraph);
41
- logger.debug('reportChunkGraph done');
42
- if (_this.options.supports.generateTileGraph) logger.warn(chalk.yellow('The option generateTileGraph is deprecated. Treemap (i.e. Tile Graph) is now supported by default.'));
43
- logger.debug('doneHandler done');
44
- }
45
- const ensureDevtools = (compiler)=>{
46
- const devtool = compiler.options.devtool;
47
- if ('string' == typeof devtool && /eval/i.test(devtool)) {
48
- if (!hasConsole) logger.warn('SourceMap with eval is not supported. Please use other sourcemap options.');
49
- hasConsole = true;
50
- return false;
51
- }
52
- return true;
53
- };
54
- async function getModulesInfos(compiler, moduleGraph, chunkGraph, parseBundle, sourceMapSets, assetsWithoutSourceMap) {
55
- if (!moduleGraph) return;
56
- try {
57
- await Chunks.getAssetsModulesData(moduleGraph, chunkGraph, compiler.outputPath, sourceMapSets, parseBundle, assetsWithoutSourceMap);
58
- } catch {}
59
- }
60
- function escapeRegExp(str) {
61
- return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
62
- }
63
- function calculateNamespaceAndRegex(compiler) {
64
- let namespace = compiler.options.output.devtoolNamespace || compiler.options.output.library?.name || '[^/]+/';
65
- if (Array.isArray(namespace)) namespace = namespace[0];
66
- else if ('object' == typeof namespace && 'name' in namespace) namespace = namespace.name;
67
- const safeNamespace = escapeRegExp(namespace);
68
- const sourceMapFilenameRegex = new RegExp(`(?:webpack://)?(?:${safeNamespace})?([^?]*)`);
69
- return {
70
- namespace: namespace,
71
- sourceMapFilenameRegex
72
- };
73
- }
74
- export { calculateNamespaceAndRegex, ensureDevtools, ensureModulesChunksGraphFn };
@@ -1,65 +0,0 @@
1
- import "node:module";
2
- import { Rule } from "@rsdoctor/shared/types";
3
- import { InternalBasePlugin } from "./base.js";
4
- import { DevToolError } from "../../error/index.js";
5
- import { time, timeEnd } from "../../logger.js";
6
- class InternalErrorReporterPlugin extends InternalBasePlugin {
7
- apply(compiler) {
8
- time('InternalErrorReporterPlugin.apply');
9
- try {
10
- compiler.hooks.done.tapPromise(this.tapPreOptions, this.done);
11
- } finally{
12
- timeEnd('InternalErrorReporterPlugin.apply');
13
- }
14
- }
15
- handleBundlerError(err, category, level) {
16
- return DevToolError.from(err, {
17
- category,
18
- code: Rule.RuleMessageCodeEnumerated.Overlay,
19
- controller: {
20
- noStack: false
21
- },
22
- detail: {
23
- stack: 'stack' in err ? err.stack : err.message
24
- },
25
- level
26
- });
27
- }
28
- async reportWarnings(warnings) {
29
- time('InternalErrorReporterPlugin.reportWarnings');
30
- try {
31
- const arr = warnings.map((warning)=>this.handleBundlerError(warning, Rule.RuleMessageCategory.Compile, 'Warn'));
32
- this.sdk.reportError(arr);
33
- } finally{
34
- timeEnd('InternalErrorReporterPlugin.reportWarnings');
35
- }
36
- }
37
- async reportErrors(errors) {
38
- time('InternalErrorReporterPlugin.reportErrors');
39
- try {
40
- const arr = errors.map((err)=>this.handleBundlerError(err, Rule.RuleMessageCategory.Bundle, 'Error'));
41
- this.sdk.reportError(arr);
42
- } finally{
43
- timeEnd('InternalErrorReporterPlugin.reportErrors');
44
- }
45
- }
46
- constructor(...args){
47
- super(...args), this.name = 'error-reporter', this.done = async (stats)=>{
48
- time('InternalErrorReporterPlugin.done');
49
- try {
50
- const tasks = [];
51
- const statsData = stats.toJson({
52
- all: false,
53
- errors: true,
54
- warnings: true
55
- });
56
- if (stats.hasErrors()) tasks.push(this.reportErrors(statsData.errors || []));
57
- if (stats.hasWarnings()) tasks.push(this.reportWarnings(statsData.warnings || []));
58
- await Promise.all(tasks);
59
- } finally{
60
- timeEnd('InternalErrorReporterPlugin.done');
61
- }
62
- };
63
- }
64
- }
65
- export { InternalErrorReporterPlugin };
@@ -1,11 +0,0 @@
1
- import "node:module";
2
- export * from "./loader.js";
3
- export * from "./plugins.js";
4
- export * from "./errors.js";
5
- export * from "./progress.js";
6
- export * from "./summary.js";
7
- export * from "./base.js";
8
- export * from "./bundle.js";
9
- export * from "./ensureModulesChunkGraph.js";
10
- export * from "./rules.js";
11
- export * from "./resolver.js";