@rsdoctor/utils 1.2.2 → 1.2.4-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 (211) hide show
  1. package/compiled/connect/index.d.ts +90 -0
  2. package/compiled/connect/index.js +2427 -0
  3. package/compiled/connect/license +25 -0
  4. package/compiled/connect/package.json +1 -0
  5. package/compiled/filesize/index.d.ts +58 -0
  6. package/compiled/filesize/index.js +255 -0
  7. package/compiled/filesize/license +28 -0
  8. package/compiled/filesize/package.json +1 -0
  9. package/dist/{type/build → build}/envinfo.d.ts +0 -1
  10. package/dist/{type/build → build}/file/cache.d.ts +0 -1
  11. package/dist/build/file/index.d.ts +3 -0
  12. package/dist/{type/build → build}/file/sharding.d.ts +0 -1
  13. package/dist/{type/build → build}/index.d.ts +0 -1
  14. package/dist/{type/build → build}/json.d.ts +0 -1
  15. package/dist/{type/build → build}/process.d.ts +0 -1
  16. package/dist/{type/build → build}/server.d.ts +0 -1
  17. package/dist/build.cjs +1310 -0
  18. package/dist/build.js +343 -0
  19. package/dist/{type/common → common}/alerts.d.ts +0 -1
  20. package/dist/{type/common → common}/algorithm.d.ts +0 -1
  21. package/dist/{type/common → common}/bundle.d.ts +0 -1
  22. package/dist/{type/common → common}/crypto.d.ts +0 -1
  23. package/dist/{type/common → common}/data/index.d.ts +0 -1
  24. package/dist/{type/common → common}/file.d.ts +0 -1
  25. package/dist/{type/common → common}/global-config.d.ts +0 -1
  26. package/dist/{type/common → common}/graph/assets.d.ts +0 -1
  27. package/dist/{type/common → common}/graph/chunk.d.ts +0 -1
  28. package/dist/{type/common → common}/graph/dependency.d.ts +0 -1
  29. package/dist/{type/common → common}/graph/entrypoints.d.ts +0 -1
  30. package/dist/{type/common → common}/graph/index.d.ts +0 -1
  31. package/dist/{type/common → common}/graph/modules.d.ts +0 -1
  32. package/dist/{type/common → common}/index.d.ts +0 -1
  33. package/dist/{type/common → common}/loader.d.ts +0 -1
  34. package/dist/{type/common → common}/lodash.d.ts +0 -1
  35. package/dist/{type/common → common}/manifest.d.ts +0 -1
  36. package/dist/{type/common → common}/package.d.ts +0 -1
  37. package/dist/{type/common → common}/plugin.d.ts +0 -1
  38. package/dist/{type/common → common}/resolver.d.ts +0 -1
  39. package/dist/{type/common → common}/rspack.d.ts +0 -1
  40. package/dist/{type/common → common}/summary.d.ts +0 -1
  41. package/dist/{type/common → common}/time.d.ts +0 -1
  42. package/dist/{type/common → common}/url.d.ts +0 -1
  43. package/dist/common.cjs +1328 -0
  44. package/dist/common.js +1255 -0
  45. package/dist/{type/error → error}/error.d.ts +0 -1
  46. package/dist/{type/error → error}/index.d.ts +0 -1
  47. package/dist/{type/error → error}/transform.d.ts +0 -1
  48. package/dist/{type/error → error}/utils.d.ts +0 -1
  49. package/dist/error.cjs +310 -0
  50. package/dist/error.js +232 -0
  51. package/dist/logger.cjs +82 -0
  52. package/dist/{type/logger.d.ts → logger.d.ts} +0 -1
  53. package/dist/{esm/logger.mjs → logger.js} +8 -13
  54. package/dist/{type/rule-utils → rule-utils}/document/document.d.ts +0 -1
  55. package/dist/{type/rule-utils → rule-utils}/document/index.d.ts +0 -1
  56. package/dist/{type/rule-utils → rule-utils}/document/server.d.ts +0 -1
  57. package/dist/{type/rule-utils → rule-utils}/document/types.d.ts +0 -1
  58. package/dist/{type/rule-utils → rule-utils}/index.d.ts +0 -1
  59. package/dist/{type/rule-utils → rule-utils}/parser/asserts.d.ts +0 -1
  60. package/dist/{type/rule-utils → rule-utils}/parser/index.d.ts +0 -1
  61. package/dist/{type/rule-utils → rule-utils}/parser/parser.d.ts +0 -1
  62. package/dist/{type/rule-utils → rule-utils}/parser/types.d.ts +0 -1
  63. package/dist/{type/rule-utils → rule-utils}/parser/utils.d.ts +0 -1
  64. package/dist/ruleUtils.cjs +320 -0
  65. package/dist/ruleUtils.js +256 -0
  66. package/package.json +35 -39
  67. package/dist/cjs/build/envinfo.js +0 -121
  68. package/dist/cjs/build/file/cache.js +0 -76
  69. package/dist/cjs/build/file/index.js +0 -81
  70. package/dist/cjs/build/file/sharding.js +0 -96
  71. package/dist/cjs/build/index.js +0 -52
  72. package/dist/cjs/build/json.js +0 -103
  73. package/dist/cjs/build/process.js +0 -54
  74. package/dist/cjs/build/server.js +0 -158
  75. package/dist/cjs/common/alerts.js +0 -51
  76. package/dist/cjs/common/algorithm.js +0 -75
  77. package/dist/cjs/common/bundle.js +0 -62
  78. package/dist/cjs/common/crypto.js +0 -54
  79. package/dist/cjs/common/data/index.js +0 -396
  80. package/dist/cjs/common/file.js +0 -44
  81. package/dist/cjs/common/global-config.js +0 -81
  82. package/dist/cjs/common/graph/assets.js +0 -314
  83. package/dist/cjs/common/graph/chunk.js +0 -81
  84. package/dist/cjs/common/graph/dependency.js +0 -50
  85. package/dist/cjs/common/graph/entrypoints.js +0 -38
  86. package/dist/cjs/common/graph/index.js +0 -96
  87. package/dist/cjs/common/graph/modules.js +0 -133
  88. package/dist/cjs/common/index.js +0 -104
  89. package/dist/cjs/common/loader.js +0 -320
  90. package/dist/cjs/common/lodash.js +0 -93
  91. package/dist/cjs/common/manifest.js +0 -70
  92. package/dist/cjs/common/package.js +0 -96
  93. package/dist/cjs/common/plugin.js +0 -91
  94. package/dist/cjs/common/resolver.js +0 -92
  95. package/dist/cjs/common/rspack.js +0 -65
  96. package/dist/cjs/common/summary.js +0 -42
  97. package/dist/cjs/common/time.js +0 -86
  98. package/dist/cjs/common/url.js +0 -54
  99. package/dist/cjs/error/error.js +0 -199
  100. package/dist/cjs/error/index.js +0 -73
  101. package/dist/cjs/error/transform.js +0 -182
  102. package/dist/cjs/error/utils.js +0 -62
  103. package/dist/cjs/index.js +0 -40
  104. package/dist/cjs/logger.js +0 -106
  105. package/dist/cjs/rule-utils/document/document.js +0 -92
  106. package/dist/cjs/rule-utils/document/index.js +0 -78
  107. package/dist/cjs/rule-utils/document/server.js +0 -49
  108. package/dist/cjs/rule-utils/document/types.js +0 -18
  109. package/dist/cjs/rule-utils/index.js +0 -69
  110. package/dist/cjs/rule-utils/parser/asserts.js +0 -138
  111. package/dist/cjs/rule-utils/parser/index.js +0 -87
  112. package/dist/cjs/rule-utils/parser/parser.js +0 -57
  113. package/dist/cjs/rule-utils/parser/types.js +0 -41
  114. package/dist/cjs/rule-utils/parser/utils.js +0 -170
  115. package/dist/esm/build/envinfo.mjs +0 -57
  116. package/dist/esm/build/file/cache.mjs +0 -23
  117. package/dist/esm/build/file/index.mjs +0 -4
  118. package/dist/esm/build/file/sharding.mjs +0 -50
  119. package/dist/esm/build/index.mjs +0 -6
  120. package/dist/esm/build/json.mjs +0 -66
  121. package/dist/esm/build/process.mjs +0 -17
  122. package/dist/esm/build/server.mjs +0 -96
  123. package/dist/esm/common/alerts.mjs +0 -17
  124. package/dist/esm/common/algorithm.mjs +0 -32
  125. package/dist/esm/common/bundle.mjs +0 -22
  126. package/dist/esm/common/crypto.mjs +0 -17
  127. package/dist/esm/common/data/index.mjs +0 -362
  128. package/dist/esm/common/file.mjs +0 -7
  129. package/dist/esm/common/global-config.mjs +0 -32
  130. package/dist/esm/common/graph/assets.mjs +0 -238
  131. package/dist/esm/common/graph/chunk.mjs +0 -32
  132. package/dist/esm/common/graph/dependency.mjs +0 -10
  133. package/dist/esm/common/graph/entrypoints.mjs +0 -4
  134. package/dist/esm/common/graph/index.mjs +0 -5
  135. package/dist/esm/common/graph/modules.mjs +0 -78
  136. package/dist/esm/common/index.mjs +0 -19
  137. package/dist/esm/common/loader.mjs +0 -247
  138. package/dist/esm/common/lodash.mjs +0 -32
  139. package/dist/esm/common/manifest.mjs +0 -30
  140. package/dist/esm/common/package.mjs +0 -56
  141. package/dist/esm/common/plugin.mjs +0 -48
  142. package/dist/esm/common/resolver.mjs +0 -46
  143. package/dist/esm/common/rspack.mjs +0 -25
  144. package/dist/esm/common/summary.mjs +0 -8
  145. package/dist/esm/common/time.mjs +0 -43
  146. package/dist/esm/common/url.mjs +0 -14
  147. package/dist/esm/error/error.mjs +0 -154
  148. package/dist/esm/error/index.mjs +0 -3
  149. package/dist/esm/error/transform.mjs +0 -138
  150. package/dist/esm/error/utils.mjs +0 -22
  151. package/dist/esm/index.mjs +0 -3
  152. package/dist/esm/rule-utils/document/document.mjs +0 -58
  153. package/dist/esm/rule-utils/document/index.mjs +0 -3
  154. package/dist/esm/rule-utils/document/server.mjs +0 -12
  155. package/dist/esm/rule-utils/document/types.mjs +0 -0
  156. package/dist/esm/rule-utils/index.mjs +0 -2
  157. package/dist/esm/rule-utils/parser/asserts.mjs +0 -104
  158. package/dist/esm/rule-utils/parser/index.mjs +0 -4
  159. package/dist/esm/rule-utils/parser/parser.mjs +0 -23
  160. package/dist/esm/rule-utils/parser/types.mjs +0 -7
  161. package/dist/esm/rule-utils/parser/utils.mjs +0 -109
  162. package/dist/type/build/envinfo.d.ts.map +0 -1
  163. package/dist/type/build/file/cache.d.ts.map +0 -1
  164. package/dist/type/build/file/index.d.ts +0 -4
  165. package/dist/type/build/file/index.d.ts.map +0 -1
  166. package/dist/type/build/file/sharding.d.ts.map +0 -1
  167. package/dist/type/build/index.d.ts.map +0 -1
  168. package/dist/type/build/json.d.ts.map +0 -1
  169. package/dist/type/build/process.d.ts.map +0 -1
  170. package/dist/type/build/server.d.ts.map +0 -1
  171. package/dist/type/common/alerts.d.ts.map +0 -1
  172. package/dist/type/common/algorithm.d.ts.map +0 -1
  173. package/dist/type/common/bundle.d.ts.map +0 -1
  174. package/dist/type/common/crypto.d.ts.map +0 -1
  175. package/dist/type/common/data/index.d.ts.map +0 -1
  176. package/dist/type/common/file.d.ts.map +0 -1
  177. package/dist/type/common/global-config.d.ts.map +0 -1
  178. package/dist/type/common/graph/assets.d.ts.map +0 -1
  179. package/dist/type/common/graph/chunk.d.ts.map +0 -1
  180. package/dist/type/common/graph/dependency.d.ts.map +0 -1
  181. package/dist/type/common/graph/entrypoints.d.ts.map +0 -1
  182. package/dist/type/common/graph/index.d.ts.map +0 -1
  183. package/dist/type/common/graph/modules.d.ts.map +0 -1
  184. package/dist/type/common/index.d.ts.map +0 -1
  185. package/dist/type/common/loader.d.ts.map +0 -1
  186. package/dist/type/common/lodash.d.ts.map +0 -1
  187. package/dist/type/common/manifest.d.ts.map +0 -1
  188. package/dist/type/common/package.d.ts.map +0 -1
  189. package/dist/type/common/plugin.d.ts.map +0 -1
  190. package/dist/type/common/resolver.d.ts.map +0 -1
  191. package/dist/type/common/rspack.d.ts.map +0 -1
  192. package/dist/type/common/summary.d.ts.map +0 -1
  193. package/dist/type/common/time.d.ts.map +0 -1
  194. package/dist/type/common/url.d.ts.map +0 -1
  195. package/dist/type/error/error.d.ts.map +0 -1
  196. package/dist/type/error/index.d.ts.map +0 -1
  197. package/dist/type/error/transform.d.ts.map +0 -1
  198. package/dist/type/error/utils.d.ts.map +0 -1
  199. package/dist/type/index.d.ts +0 -3
  200. package/dist/type/index.d.ts.map +0 -1
  201. package/dist/type/logger.d.ts.map +0 -1
  202. package/dist/type/rule-utils/document/document.d.ts.map +0 -1
  203. package/dist/type/rule-utils/document/index.d.ts.map +0 -1
  204. package/dist/type/rule-utils/document/server.d.ts.map +0 -1
  205. package/dist/type/rule-utils/document/types.d.ts.map +0 -1
  206. package/dist/type/rule-utils/index.d.ts.map +0 -1
  207. package/dist/type/rule-utils/parser/asserts.d.ts.map +0 -1
  208. package/dist/type/rule-utils/parser/index.d.ts.map +0 -1
  209. package/dist/type/rule-utils/parser/parser.d.ts.map +0 -1
  210. package/dist/type/rule-utils/parser/types.d.ts.map +0 -1
  211. package/dist/type/rule-utils/parser/utils.d.ts.map +0 -1
@@ -1,14 +0,0 @@
1
- import { isAbsolute } from "path";
2
- function isUrl(uri) {
3
- return /^https?:\/\//.test(uri);
4
- }
5
- function isFilePath(uri) {
6
- return isAbsolute(uri);
7
- }
8
- function isRemoteUrl(uri) {
9
- if ('string' == typeof uri) {
10
- if (isUrl(uri) || isFilePath(uri)) return true;
11
- }
12
- return false;
13
- }
14
- export { isFilePath, isRemoteUrl, isUrl };
@@ -1,154 +0,0 @@
1
- import { codeFrameColumns } from "@babel/code-frame";
2
- import { Err } from "@rsdoctor/types";
3
- import { createColors } from "picocolors";
4
- import deep_eql from "deep-eql";
5
- import strip_ansi from "strip-ansi";
6
- import { transform } from "./transform.mjs";
7
- import { insertSpace, toLevel } from "./utils.mjs";
8
- import { isNil } from "../common/lodash.mjs";
9
- function _define_property(obj, key, value) {
10
- if (key in obj) Object.defineProperty(obj, key, {
11
- value: value,
12
- enumerable: true,
13
- configurable: true,
14
- writable: true
15
- });
16
- else obj[key] = value;
17
- return obj;
18
- }
19
- let id = 1;
20
- class DevToolError extends Error {
21
- static from(err, opt) {
22
- if (err instanceof DevToolError) return err;
23
- return transform(err, opt);
24
- }
25
- get level() {
26
- return Err.ErrorLevel[this._level];
27
- }
28
- get path() {
29
- var _this__codeFrame;
30
- return null == (_this__codeFrame = this._codeFrame) ? void 0 : _this__codeFrame.filePath;
31
- }
32
- set path(file) {
33
- if (!file) return;
34
- if (this._codeFrame) {
35
- this._codeFrame.filePath = file;
36
- return;
37
- }
38
- this._codeFrame = {
39
- filePath: file
40
- };
41
- }
42
- get codeFrame() {
43
- return this._codeFrame;
44
- }
45
- printCodeFrame(print) {
46
- const msgs = [];
47
- const { _codeFrame: codeFrameOpt, _controller: controller } = this;
48
- if (!codeFrameOpt) return msgs;
49
- if ('start' in codeFrameOpt && codeFrameOpt.start) {
50
- const { filePath, start } = codeFrameOpt;
51
- msgs.push(`\n ${print.red(print.bold('File: '))}${print.bold(filePath)}:${start.line}${start.column ? `:${start.column}` : ''}`);
52
- if ('fileContent' in codeFrameOpt) {
53
- const { end, fileContent } = codeFrameOpt;
54
- msgs.push(codeFrameColumns(fileContent, {
55
- start,
56
- end
57
- }, {
58
- highlightCode: !controller.noColor
59
- }));
60
- } else if ('lineText' in codeFrameOpt) {
61
- const { length, lineText } = codeFrameOpt;
62
- let lineCodeFrame = codeFrameColumns(lineText, {
63
- start: {
64
- line: 1,
65
- column: start.column
66
- },
67
- end: {
68
- line: 1,
69
- column: isNil(start.column) || isNil(length) ? void 0 : start.column + length
70
- }
71
- }, {
72
- highlightCode: !controller.noColor
73
- });
74
- if (start.line > 1) {
75
- lineCodeFrame = lineCodeFrame.replace(' 1 |', ` ${start.line} |`);
76
- if (start.line >= 10) lineCodeFrame = insertSpace(lineCodeFrame, 2, String(start.line).length - 1);
77
- }
78
- msgs.push(lineCodeFrame);
79
- }
80
- } else msgs.push(`\n ${print.red(print.bold('File: '))}${print.bold(codeFrameOpt.filePath)}\n`);
81
- return msgs;
82
- }
83
- toString() {
84
- const msgs = [];
85
- const { code, title, message, hint, referenceUrl, _controller: controller } = this;
86
- const print = createColors(!controller.noColor);
87
- const mainColorPrint = this._level === Err.ErrorLevel.Error ? print.red : print.yellow;
88
- const codeText = code ? `${mainColorPrint(print.blue(code))}:` : '';
89
- msgs.push(mainColorPrint(print.bold(`[${codeText}${this.level}:${title.toUpperCase()}] `) + message));
90
- msgs.push(...this.printCodeFrame(print));
91
- if (hint || referenceUrl) msgs.push('');
92
- if (hint) msgs.push(` ${print.blue(`HINT: ${hint}`)}`);
93
- if (referenceUrl) msgs.push(print.magenta(print.bold(` See: ${referenceUrl}`)));
94
- if (!controller.noStack && this.stack) msgs.push(print.red(print.bold(` Error Stack:\n${this.stack}\n`)));
95
- return msgs.join('\n');
96
- }
97
- toData() {
98
- var _this_detail;
99
- return {
100
- ...this.detail,
101
- id: this.id,
102
- category: this.category,
103
- description: strip_ansi((null == (_this_detail = this.detail) ? void 0 : _this_detail.description) ?? this.message),
104
- title: this.title.toUpperCase(),
105
- code: this.code,
106
- level: this.level.toLowerCase()
107
- };
108
- }
109
- toError() {
110
- const error = new Error();
111
- error.message = this.toString();
112
- error.name = this.name;
113
- error.stack = this.stack;
114
- return error;
115
- }
116
- toJSON() {
117
- return {
118
- message: this.toString(),
119
- name: this.name,
120
- stack: this.stack
121
- };
122
- }
123
- setControllerOption(opt) {
124
- this._controller = {
125
- noStack: opt.noStack ?? this._controller.noStack ?? true,
126
- noColor: opt.noColor ?? this._controller.noColor ?? false
127
- };
128
- }
129
- setCodeFrame(opt) {
130
- this._codeFrame = opt;
131
- }
132
- isSame(error) {
133
- 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);
134
- }
135
- constructor(title, message, opts){
136
- super(message), _define_property(this, "id", void 0), _define_property(this, "code", void 0), _define_property(this, "category", void 0), _define_property(this, "title", void 0), _define_property(this, "detail", void 0), _define_property(this, "fixData", void 0), _define_property(this, "hint", void 0), _define_property(this, "referenceUrl", void 0), _define_property(this, "_codeFrame", void 0), _define_property(this, "_controller", {
137
- noStack: true,
138
- noColor: false
139
- }), _define_property(this, "_level", void 0);
140
- this.id = id++;
141
- this.title = title;
142
- this.code = null == opts ? void 0 : opts.code;
143
- this.hint = null == opts ? void 0 : opts.hint;
144
- this.stack = null == opts ? void 0 : opts.stack;
145
- this.detail = null == opts ? void 0 : opts.detail;
146
- this.fixData = null == opts ? void 0 : opts.fixData;
147
- this.category = null == opts ? void 0 : opts.category;
148
- this.referenceUrl = null == opts ? void 0 : opts.referenceUrl;
149
- this._level = (null == opts ? void 0 : opts.level) ? toLevel(opts.level) : Err.ErrorLevel.Error;
150
- this._codeFrame = null == opts ? void 0 : opts.codeFrame;
151
- this.setControllerOption((null == opts ? void 0 : opts.controller) ?? {});
152
- }
153
- }
154
- export { DevToolError };
@@ -1,3 +0,0 @@
1
- import { printErrors } from "./utils.mjs";
2
- export * from "./error.mjs";
3
- export { printErrors };
@@ -1,138 +0,0 @@
1
- import strip_ansi from "strip-ansi";
2
- import { Linter } from "@rsdoctor/types";
3
- import { DevToolError } from "./error.mjs";
4
- function isEsbuildError(err) {
5
- return 'pluginName' in err && 'text' in err && 'location' in err;
6
- }
7
- function isBabelError(err) {
8
- return 'code' in err && 'reasonCode' in err;
9
- }
10
- function isDiagnosticError(err) {
11
- return 'severity' in err && 'title' in err;
12
- }
13
- function parseBabelErrorMessage(input) {
14
- var _lines_find;
15
- const lines = strip_ansi(input).split('\n');
16
- const filePath = lines[0].replace(/^([^:]+):.*/, '$1');
17
- const message = lines[0].replace(/.*: (.*) \(\d+:\d+\)*/, '$1');
18
- const lineText = (null == (_lines_find = lines.find((line)=>line.startsWith('> '))) ? void 0 : _lines_find.replace(/> \d+ \| /, '')) ?? '';
19
- return {
20
- message,
21
- filePath,
22
- lineText
23
- };
24
- }
25
- function clearMessage(str) {
26
- return strip_ansi(str).replace(/.*: (.*)\n\n[\s\S]*/g, '$1');
27
- }
28
- function clearStack(str) {
29
- return str.slice(str.indexOf(' at')).replace(/\s*at(.*) \((.*)\)/g, '$1\n$2\n');
30
- }
31
- function transformEsbuildError(err, opt) {
32
- if (isEsbuildError(err)) {
33
- var _err_location;
34
- const errorCode = (null == opt ? void 0 : opt.code) ?? 'ESBUILD_ERROR';
35
- const speedyError = 'object' == typeof err.detail ? DevToolError.from(err.detail) : new DevToolError(errorCode, clearMessage(err.text), {
36
- ...opt,
37
- hint: null == (_err_location = err.location) ? void 0 : _err_location.suggestion,
38
- codeFrame: {
39
- filePath: err.text.split(':')[0]
40
- }
41
- });
42
- if (err.location) speedyError.setCodeFrame({
43
- filePath: err.location.file,
44
- lineText: err.location.lineText,
45
- length: err.location.length,
46
- start: {
47
- line: err.location.line,
48
- column: err.location.column + 1
49
- }
50
- });
51
- return speedyError;
52
- }
53
- }
54
- function transformBabelError(err, opt) {
55
- if (isBabelError(err)) {
56
- const errorCode = (null == opt ? void 0 : opt.code) ?? err.code ?? 'BABEL';
57
- const title = err.reasonCode;
58
- const errorParsed = parseBabelErrorMessage(err.message);
59
- const speedyError = new DevToolError(title, errorParsed.message, {
60
- ...opt,
61
- code: errorCode,
62
- stack: err.stack && clearStack(err.stack)
63
- });
64
- if (err.loc) speedyError.setCodeFrame({
65
- ...errorParsed,
66
- start: {
67
- line: err.loc.line,
68
- column: err.loc.column + 1
69
- }
70
- });
71
- return speedyError;
72
- }
73
- }
74
- function transformNormalError(err, opt) {
75
- if (err instanceof Error) {
76
- var _stacks__getFileName, _stacks_;
77
- const stacks = [];
78
- const filePath = null == stacks ? void 0 : null == (_stacks_ = stacks[0]) ? void 0 : null == (_stacks__getFileName = _stacks_.getFileName) ? void 0 : _stacks__getFileName.call(_stacks_);
79
- return new DevToolError(err.name, clearMessage(err.message), {
80
- ...opt,
81
- codeFrame: filePath ? {
82
- filePath
83
- } : void 0,
84
- stack: err.stack && clearStack(err.stack)
85
- });
86
- }
87
- }
88
- function transformErrorLike(err, opt) {
89
- const isErrorLike = err && 'object' == typeof err && err.message;
90
- if (isErrorLike) {
91
- var _stacks__getFileName, _stacks_;
92
- const stacks = [];
93
- const filePath = null == stacks ? void 0 : null == (_stacks_ = stacks[0]) ? void 0 : null == (_stacks__getFileName = _stacks_.getFileName) ? void 0 : _stacks__getFileName.call(_stacks_);
94
- return new DevToolError(err.name || 'UNKNOWN_ERROR', clearMessage(err.message), {
95
- ...opt,
96
- codeFrame: filePath ? {
97
- filePath
98
- } : void 0,
99
- stack: err.stack && clearStack(err.stack)
100
- });
101
- }
102
- }
103
- function transformDiagnostic(err, opt) {
104
- if (isDiagnosticError(err)) {
105
- var _err_suggestions, _err_suggestions1;
106
- return new DevToolError(err.title, err.message, {
107
- ...err,
108
- ...opt,
109
- hint: null == (_err_suggestions = err.suggestions) ? void 0 : _err_suggestions.description,
110
- fixData: null == (_err_suggestions1 = err.suggestions) ? void 0 : _err_suggestions1.fixData,
111
- codeFrame: err.document ? {
112
- filePath: err.document.path,
113
- fileContent: err.document.content,
114
- start: err.document.range.start,
115
- end: err.document.range.end
116
- } : void 0,
117
- level: Linter.Severity[err.severity]
118
- });
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,22 +0,0 @@
1
- import { Err } from "@rsdoctor/types";
2
- function toLevel(level) {
3
- return Err.ErrorLevel[level];
4
- }
5
- function insertSpace(rawLines, line, width) {
6
- const lines = rawLines.split('\n');
7
- lines[line - 1] = Array(width).fill(' ').join('') + lines[line - 1];
8
- return lines.join('\n');
9
- }
10
- function printErrors({ errors, warnings }, logLevel = 'Error') {
11
- const onlyError = 'Error' === logLevel;
12
- if ('Silent' === logLevel) return '';
13
- if (onlyError && 0 === errors.length || !onlyError && 0 === errors.length && 0 === warnings.length) return '';
14
- const msgs = [];
15
- if (onlyError) msgs.push(`Build failed with ${errors.length} error:`, ...errors.map((item)=>item.toString()), '');
16
- else {
17
- const title = 0 === errors.length ? `Build succuss with ${warnings.length} warning:` : `Build failed with ${errors.length} error, ${warnings.length} warning:`;
18
- msgs.push(title, ...errors.map((item)=>item.toString()), ...warnings.map((item)=>item.toString()), '');
19
- }
20
- return msgs.join('\n\n');
21
- }
22
- export { insertSpace, printErrors, toLevel };
@@ -1,3 +0,0 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE__rule_utils_index_mjs_79331901__ from "./rule-utils/index.mjs";
2
- import * as __WEBPACK_EXTERNAL_MODULE__logger_mjs_dfc7ebda__ from "./logger.mjs";
3
- export { __WEBPACK_EXTERNAL_MODULE__logger_mjs_dfc7ebda__ as Logger, __WEBPACK_EXTERNAL_MODULE__rule_utils_index_mjs_79331901__ as RuleUtils };
@@ -1,58 +0,0 @@
1
- import { LinesAndColumns } from "lines-and-columns";
2
- import { isNumber, isUndefined } from "../../common/lodash.mjs";
3
- function _define_property(obj, key, value) {
4
- if (key in obj) Object.defineProperty(obj, key, {
5
- value: value,
6
- enumerable: true,
7
- configurable: true,
8
- writable: true
9
- });
10
- else obj[key] = value;
11
- return obj;
12
- }
13
- class Document {
14
- createFinder() {
15
- const find = new LinesAndColumns(this._text);
16
- this.positionAt = (offset)=>{
17
- if (offset >= this._text.length) offset = this._text.length - 1;
18
- if (offset < 0) offset = 0;
19
- const result = find.locationForIndex(offset);
20
- if (!result) return;
21
- return {
22
- line: result.line + 1,
23
- column: result.column
24
- };
25
- };
26
- this.offsetAt = (position)=>find.indexForLocation({
27
- line: position.line - 1,
28
- column: position.column
29
- }) ?? void 0;
30
- }
31
- getText(range) {
32
- if (!range) return this._text;
33
- const start = 'number' == typeof range.start ? range.start : this.offsetAt(range.start);
34
- const end = 'number' == typeof range.end ? range.end : this.offsetAt(range.end);
35
- if (isUndefined(start)) throw new Error(`Location ${JSON.stringify(start)} is illegal`);
36
- if (isUndefined(end)) throw new Error(`Location ${JSON.stringify(end)} is illegal`);
37
- return this._text.slice(start, end);
38
- }
39
- edit(data) {
40
- let { _text: content } = this;
41
- const startOffset = isNumber(data.start) ? data.start : this.offsetAt(data.start);
42
- const endOffset = isNumber(data.end) ? data.end : this.offsetAt(data.end);
43
- if (isUndefined(startOffset) || isUndefined(endOffset)) return;
44
- const startTxt = content.substring(0, startOffset);
45
- const endTxt = content.substring(endOffset, content.length);
46
- content = startTxt + data.newText + endTxt;
47
- return content;
48
- }
49
- constructor(content){
50
- _define_property(this, "_text", '');
51
- _define_property(this, "positionAt", void 0);
52
- _define_property(this, "offsetAt", void 0);
53
- this._text;
54
- this._text = content;
55
- this.createFinder();
56
- }
57
- }
58
- export { Document };
@@ -1,3 +0,0 @@
1
- export * from "./document.mjs";
2
- export * from "./types.mjs";
3
- export * from "./server.mjs";
@@ -1,12 +0,0 @@
1
- import { Document } from "./document.mjs";
2
- const store = new Map();
3
- function getDocument(content) {
4
- if (store.has(content)) return store.get(content);
5
- const doc = new Document(content);
6
- store.set(content, doc);
7
- return doc;
8
- }
9
- function clearDocument() {
10
- store.clear();
11
- }
12
- export { clearDocument, getDocument };
File without changes
@@ -1,2 +0,0 @@
1
- export * from "./document/index.mjs";
2
- export * from "./parser/index.mjs";
@@ -1,104 +0,0 @@
1
- import { isObject } from "../../common/lodash.mjs";
2
- function isSyntaxNode(node) {
3
- return isObject(node) && 'type' in node;
4
- }
5
- function assertCreator(type) {
6
- return (node)=>isSyntaxNode(node) && node.type === type;
7
- }
8
- const asserts = {
9
- isProgram: assertCreator('Program'),
10
- isEmptyStatement: assertCreator('EmptyStatement'),
11
- isBlockStatement: assertCreator('BlockStatement'),
12
- isStaticBlock: assertCreator('StaticBlock'),
13
- isExpressionStatement: assertCreator('ExpressionStatement'),
14
- isIfStatement: assertCreator('IfStatement'),
15
- isLabeledStatement: assertCreator('LabeledStatement'),
16
- isBreakStatement: assertCreator('BreakStatement'),
17
- isContinueStatement: assertCreator('ContinueStatement'),
18
- isWithStatement: assertCreator('WithStatement'),
19
- isSwitchStatement: assertCreator('SwitchStatement'),
20
- isReturnStatement: assertCreator('ReturnStatement'),
21
- isThrowStatement: assertCreator('ThrowStatement'),
22
- isTryStatement: assertCreator('TryStatement'),
23
- isWhileStatement: assertCreator('WhileStatement'),
24
- isDoWhileStatement: assertCreator('DoWhileStatement'),
25
- isForStatement: assertCreator('ForStatement'),
26
- isForInStatement: assertCreator('ForInStatement'),
27
- isForOfStatement: assertCreator('ForOfStatement'),
28
- isDebuggerStatement: assertCreator('DebuggerStatement'),
29
- isFunctionDeclaration: assertCreator('FunctionDeclaration'),
30
- isVariableDeclaration: assertCreator('VariableDeclaration'),
31
- isVariableDeclarator: assertCreator('VariableDeclarator'),
32
- isChainExpression: assertCreator('ChainExpression'),
33
- isThisExpression: assertCreator('ThisExpression'),
34
- isArrayExpression: assertCreator('ArrayExpression'),
35
- isObjectExpression: assertCreator('ObjectExpression'),
36
- isPrivateIdentifier: assertCreator('PrivateIdentifier'),
37
- isProperty: assertCreator('Property'),
38
- isPropertyDefinition: assertCreator('PropertyDefinition'),
39
- isFunctionExpression: assertCreator('FunctionExpression'),
40
- isSequenceExpression: assertCreator('SequenceExpression'),
41
- isUnaryExpression: assertCreator('UnaryExpression'),
42
- isBinaryExpression: assertCreator('BinaryExpression'),
43
- isAssignmentExpression: assertCreator('AssignmentExpression'),
44
- isUpdateExpression: assertCreator('UpdateExpression'),
45
- isLogicalExpression: assertCreator('LogicalExpression'),
46
- isConditionalExpression: assertCreator('ConditionalExpression'),
47
- isNewExpression: assertCreator('NewExpression'),
48
- isSwitchCase: assertCreator('SwitchCase'),
49
- isCatchClause: assertCreator('CatchClause'),
50
- isIdentifier: assertCreator('Identifier'),
51
- isLiteral: assertCreator('Literal'),
52
- isSuper: assertCreator('Super'),
53
- isSpreadElement: assertCreator('SpreadElement'),
54
- isArrowFunctionExpression: assertCreator('ArrowFunctionExpression'),
55
- isYieldExpression: assertCreator('YieldExpression'),
56
- isTemplateLiteral: assertCreator('TemplateLiteral'),
57
- isTaggedTemplateExpression: assertCreator('TaggedTemplateExpression'),
58
- isTemplateElement: assertCreator('TemplateElement'),
59
- isObjectPattern: assertCreator('ObjectPattern'),
60
- isArrayPattern: assertCreator('ArrayPattern'),
61
- isRestElement: assertCreator('RestElement'),
62
- isAssignmentPattern: assertCreator('AssignmentPattern'),
63
- isClassBody: assertCreator('ClassBody'),
64
- isClassDeclaration: assertCreator('ClassDeclaration'),
65
- isClassExpression: assertCreator('ClassExpression'),
66
- isMetaProperty: assertCreator('MetaProperty'),
67
- isImportDeclaration: assertCreator('ImportDeclaration'),
68
- isImportSpecifier: assertCreator('ImportSpecifier'),
69
- isImportExpression: assertCreator('ImportExpression'),
70
- isImportDefaultSpecifier: assertCreator('ImportDefaultSpecifier'),
71
- isImportNamespaceSpecifier: assertCreator('ImportNamespaceSpecifier'),
72
- isExportNamedDeclaration: assertCreator('ExportNamedDeclaration'),
73
- isExportSpecifier: assertCreator('ExportSpecifier'),
74
- isExportDefaultDeclaration: assertCreator('ExportDefaultDeclaration'),
75
- isExportAllDeclaration: assertCreator('ExportAllDeclaration'),
76
- isAwaitExpression: assertCreator('AwaitExpression'),
77
- isMethodDefinition: assertCreator('MethodDefinition'),
78
- isMemberExpression: assertCreator('MemberExpression'),
79
- isComment (node) {
80
- return isSyntaxNode(node) && ('Line' === node.type || 'Block' === node.type);
81
- },
82
- isDirective (node) {
83
- return asserts.isExpressionStatement(node) && 'directive' in node;
84
- },
85
- isSimpleCallExpression (node) {
86
- return isSyntaxNode(node) && 'CallExpression' === node.type;
87
- },
88
- isAssignmentProperty (node) {
89
- return asserts.isProperty(node) && 'init' === node.kind;
90
- },
91
- isSimpleLiteral (node) {
92
- return asserts.isLiteral(node) && !asserts.isRegExpLiteral(node) && !asserts.isBigIntLiteral(node);
93
- },
94
- isRegExpLiteral (node) {
95
- return asserts.isLiteral(node) && 'regex' in node;
96
- },
97
- isBigIntLiteral (node) {
98
- return asserts.isLiteral(node) && 'bigint' in node;
99
- },
100
- isExportStatement (node) {
101
- return asserts.isExportAllDeclaration(node) || asserts.isExportDefaultDeclaration(node) || asserts.isExportNamedDeclaration(node);
102
- }
103
- };
104
- export { asserts };
@@ -1,4 +0,0 @@
1
- export * from "./asserts.mjs";
2
- export * from "./parser.mjs";
3
- export * from "./utils.mjs";
4
- export * from "./types.mjs";
@@ -1,23 +0,0 @@
1
- import { Parser } from "acorn";
2
- import { importAttributes } from "acorn-import-attributes";
3
- import { asserts } from "./asserts.mjs";
4
- import * as __WEBPACK_EXTERNAL_MODULE__utils_mjs_25ece7d1__ from "./utils.mjs";
5
- import * as __WEBPACK_EXTERNAL_MODULE_acorn_walk_9c3ac672__ from "acorn-walk";
6
- const acornParserInternal = Parser.extend(importAttributes);
7
- let acornParserExport = Parser.extend(importAttributes);
8
- const parser = {
9
- walk: __WEBPACK_EXTERNAL_MODULE_acorn_walk_9c3ac672__,
10
- parse: (input, options)=>acornParserExport.parse(input, options),
11
- parseExpressionAt: (input, pos, options)=>acornParserExport.parseExpressionAt(input, pos, options),
12
- extend (...args) {
13
- acornParserExport = acornParserExport.extend(...args);
14
- return acornParserExport;
15
- },
16
- asserts: asserts,
17
- utils: __WEBPACK_EXTERNAL_MODULE__utils_mjs_25ece7d1__,
18
- internal: {
19
- parse: (input, options)=>acornParserInternal.parse(input, options),
20
- parseExpressionAt: (input, pos, options)=>acornParserInternal.parseExpressionAt(input, pos, options)
21
- }
22
- };
23
- export { parser };
@@ -1,7 +0,0 @@
1
- var types_ECMAVersion = /*#__PURE__*/ function(ECMAVersion) {
2
- ECMAVersion["ES5"] = "ES5";
3
- ECMAVersion["ES6"] = "ES6";
4
- ECMAVersion["ES7P"] = "ES7+";
5
- return ECMAVersion;
6
- }({});
7
- export { types_ECMAVersion as ECMAVersion };