@rspack-debug/test-tools 1.4.11 → 1.6.4

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 (259) hide show
  1. package/README.md +1 -1
  2. package/dist/case/builtin.d.ts +3 -0
  3. package/dist/case/builtin.js +152 -14
  4. package/dist/case/cache.d.ts +2 -2
  5. package/dist/case/cache.js +214 -12
  6. package/dist/case/common.d.ts +11 -0
  7. package/dist/case/common.js +249 -0
  8. package/dist/case/compiler.d.ts +17 -4
  9. package/dist/case/compiler.js +149 -12
  10. package/dist/case/config.d.ts +7 -2
  11. package/dist/case/config.js +106 -18
  12. package/dist/case/defaults.d.ts +13 -4
  13. package/dist/case/defaults.js +73 -18
  14. package/dist/case/diagnostic.d.ts +6 -0
  15. package/dist/case/diagnostic.js +121 -14
  16. package/dist/case/error.d.ts +15 -4
  17. package/dist/case/error.js +137 -12
  18. package/dist/case/esm-output.d.ts +1 -0
  19. package/dist/case/esm-output.js +117 -0
  20. package/dist/case/example.d.ts +1 -0
  21. package/dist/case/example.js +57 -0
  22. package/dist/case/hash.d.ts +2 -2
  23. package/dist/case/hash.js +72 -9
  24. package/dist/case/hook.d.ts +36 -4
  25. package/dist/case/hook.js +209 -20
  26. package/dist/case/hot-step.d.ts +2 -2
  27. package/dist/case/hot-step.js +309 -13
  28. package/dist/case/hot.d.ts +11 -2
  29. package/dist/case/hot.js +217 -12
  30. package/dist/case/incremental.d.ts +2 -2
  31. package/dist/case/incremental.js +24 -45
  32. package/dist/case/index.d.ts +31 -20
  33. package/dist/case/index.js +50 -34
  34. package/dist/case/multi-compiler.d.ts +19 -0
  35. package/dist/case/multi-compiler.js +97 -0
  36. package/dist/case/{nativeWatcher.js → native-watcher.js} +11 -23
  37. package/dist/case/normal.d.ts +3 -0
  38. package/dist/case/normal.js +202 -18
  39. package/dist/case/runner.d.ts +19 -0
  40. package/dist/case/runner.js +113 -0
  41. package/dist/case/serial.d.ts +2 -2
  42. package/dist/case/serial.js +10 -14
  43. package/dist/case/stats-api.d.ts +8 -3
  44. package/dist/case/stats-api.js +69 -10
  45. package/dist/case/stats-output.d.ts +11 -0
  46. package/dist/case/stats-output.js +199 -8
  47. package/dist/case/treeshaking.js +34 -7
  48. package/dist/case/watch.d.ts +27 -0
  49. package/dist/case/watch.js +318 -22
  50. package/dist/compiler.d.ts +16 -16
  51. package/dist/compiler.js +120 -15
  52. package/dist/helper/directory.d.ts +1 -1
  53. package/dist/helper/directory.js +6 -2
  54. package/dist/helper/disable-iconv-lite-warning.d.ts +1 -0
  55. package/dist/helper/disable-iconv-lite-warning.js +12 -0
  56. package/dist/helper/expect/error.js +1 -1
  57. package/dist/helper/expect/placeholder.js +7 -7
  58. package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -2
  59. package/dist/helper/expect/to-match-file-snapshot.js +3 -3
  60. package/dist/helper/hot-update/loader.d.ts +2 -1
  61. package/dist/helper/hot-update/loader.js +5 -30
  62. package/dist/helper/hot-update/plugin.d.ts +1 -1
  63. package/dist/helper/hot-update/plugin.js +14 -13
  64. package/dist/helper/index.d.ts +2 -1
  65. package/dist/helper/index.js +2 -1
  66. package/dist/helper/is.d.ts +2 -0
  67. package/dist/helper/is.js +15 -0
  68. package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
  69. package/dist/helper/legacy/LogTestPlugin.js +35 -0
  70. package/dist/helper/legacy/asModule.js +0 -2
  71. package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -1
  72. package/dist/helper/legacy/checkArrayExpectation.js +8 -8
  73. package/dist/helper/legacy/createFakeWorker.d.ts +2 -2
  74. package/dist/helper/legacy/createFakeWorker.js +44 -20
  75. package/dist/helper/legacy/createLazyTestEnv.d.ts +3 -2
  76. package/dist/helper/legacy/createLazyTestEnv.js +3 -3
  77. package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
  78. package/dist/helper/legacy/deprecationTracking.js +41 -0
  79. package/dist/helper/legacy/expectSource.d.ts +10 -0
  80. package/dist/helper/legacy/expectSource.js +23 -0
  81. package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
  82. package/dist/helper/legacy/findOutputFiles.js +14 -0
  83. package/dist/helper/legacy/regexEscape.d.ts +2 -0
  84. package/dist/helper/legacy/regexEscape.js +5 -0
  85. package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
  86. package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
  87. package/dist/helper/legacy/supportsTextDecoder.js +9 -0
  88. package/dist/helper/legacy/supportsUsing.d.ts +2 -0
  89. package/dist/helper/legacy/supportsUsing.js +26 -0
  90. package/dist/helper/legacy/urlToRelativePath.js +5 -2
  91. package/dist/helper/read-config-file.d.ts +3 -2
  92. package/dist/helper/read-config-file.js +12 -2
  93. package/dist/helper/setup-env.js +26 -4
  94. package/dist/helper/setup-expect.js +2 -2
  95. package/dist/helper/setup-wasm.js +2 -2
  96. package/dist/helper/stringify-config.d.ts +2 -0
  97. package/dist/helper/stringify-config.js +43 -0
  98. package/dist/helper/util/checkStats.d.ts +0 -1
  99. package/dist/helper/util/checkStats.js +0 -18
  100. package/dist/helper/util/expectWarningFactory.js +2 -4
  101. package/dist/index.d.ts +0 -4
  102. package/dist/index.js +1 -4
  103. package/dist/plugin/index.d.ts +0 -3
  104. package/dist/plugin/index.js +0 -3
  105. package/dist/plugin/lazy-compilation-test-plugin.js +4 -4
  106. package/dist/runner/index.d.ts +2 -9
  107. package/dist/runner/index.js +2 -9
  108. package/dist/runner/node/index.d.ts +41 -0
  109. package/dist/runner/node/index.js +450 -0
  110. package/dist/runner/web/index.d.ts +30 -0
  111. package/dist/runner/web/index.js +343 -0
  112. package/dist/test/context.d.ts +15 -18
  113. package/dist/test/context.js +52 -57
  114. package/dist/test/creator.d.ts +20 -19
  115. package/dist/test/creator.js +69 -57
  116. package/dist/test/debug.d.ts +15 -0
  117. package/dist/test/debug.js +205 -0
  118. package/dist/test/tester.d.ts +1 -0
  119. package/dist/test/tester.js +44 -6
  120. package/dist/type.d.ts +94 -64
  121. package/dist/type.js +8 -12
  122. package/package.json +22 -61
  123. package/rstest.d.ts +24 -0
  124. package/dist/case/diff.d.ts +0 -3
  125. package/dist/case/diff.js +0 -126
  126. package/dist/compare/comparator.d.ts +0 -17
  127. package/dist/compare/comparator.js +0 -52
  128. package/dist/compare/compare.d.ts +0 -17
  129. package/dist/compare/compare.js +0 -175
  130. package/dist/compare/format-code.d.ts +0 -16
  131. package/dist/compare/format-code.js +0 -239
  132. package/dist/compare/index.d.ts +0 -5
  133. package/dist/compare/index.js +0 -21
  134. package/dist/compare/replace-module-argument.d.ts +0 -1
  135. package/dist/compare/replace-module-argument.js +0 -8
  136. package/dist/compare/replace-runtime-module-name.d.ts +0 -1
  137. package/dist/compare/replace-runtime-module-name.js +0 -71
  138. package/dist/helper/legacy/FakeDocument.d.ts +0 -54
  139. package/dist/helper/legacy/FakeDocument.js +0 -278
  140. package/dist/helper/legacy/createLogger.d.ts +0 -23
  141. package/dist/helper/legacy/createLogger.js +0 -20
  142. package/dist/helper/legacy/supportsImportFn.d.ts +0 -1
  143. package/dist/helper/legacy/supportsImportFn.js +0 -15
  144. package/dist/helper/legacy/supportsWorker.js +0 -17
  145. package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
  146. package/dist/helper/legacy/walkCssTokens.js +0 -761
  147. package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
  148. package/dist/helper/legacy/warmup-webpack.js +0 -26
  149. package/dist/helper/loaders/hot-update.d.ts +0 -1
  150. package/dist/helper/loaders/hot-update.js +0 -40
  151. package/dist/helper/plugins/hot-update.d.ts +0 -7
  152. package/dist/helper/plugins/hot-update.js +0 -40
  153. package/dist/helper/plugins/index.d.ts +0 -1
  154. package/dist/helper/plugins/index.js +0 -17
  155. package/dist/helper/util/currentWatchStep.d.ts +0 -1
  156. package/dist/helper/util/currentWatchStep.js +0 -2
  157. package/dist/helper/util/identifier.d.ts +0 -76
  158. package/dist/helper/util/identifier.js +0 -339
  159. package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
  160. package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
  161. package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
  162. package/dist/plugin/rspack-diff-config-plugin.js +0 -42
  163. package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
  164. package/dist/plugin/webpack-diff-config-plugin.js +0 -41
  165. package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
  166. package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
  167. package/dist/processor/basic.d.ts +0 -24
  168. package/dist/processor/basic.js +0 -146
  169. package/dist/processor/builtin.d.ts +0 -9
  170. package/dist/processor/builtin.js +0 -171
  171. package/dist/processor/cache.d.ts +0 -20
  172. package/dist/processor/cache.js +0 -128
  173. package/dist/processor/config.d.ts +0 -11
  174. package/dist/processor/config.js +0 -81
  175. package/dist/processor/defaults.d.ts +0 -30
  176. package/dist/processor/defaults.js +0 -72
  177. package/dist/processor/diagnostic.d.ts +0 -15
  178. package/dist/processor/diagnostic.js +0 -102
  179. package/dist/processor/diff.d.ts +0 -30
  180. package/dist/processor/diff.js +0 -140
  181. package/dist/processor/error.d.ts +0 -23
  182. package/dist/processor/error.js +0 -95
  183. package/dist/processor/hash.d.ts +0 -10
  184. package/dist/processor/hash.js +0 -63
  185. package/dist/processor/hook.d.ts +0 -44
  186. package/dist/processor/hook.js +0 -204
  187. package/dist/processor/hot-incremental.d.ts +0 -14
  188. package/dist/processor/hot-incremental.js +0 -43
  189. package/dist/processor/hot-step.d.ts +0 -18
  190. package/dist/processor/hot-step.js +0 -304
  191. package/dist/processor/hot.d.ts +0 -17
  192. package/dist/processor/hot.js +0 -140
  193. package/dist/processor/index.d.ts +0 -20
  194. package/dist/processor/index.js +0 -36
  195. package/dist/processor/multi.d.ts +0 -17
  196. package/dist/processor/multi.js +0 -73
  197. package/dist/processor/normal.d.ts +0 -12
  198. package/dist/processor/normal.js +0 -150
  199. package/dist/processor/simple.d.ts +0 -23
  200. package/dist/processor/simple.js +0 -49
  201. package/dist/processor/snapshot.d.ts +0 -12
  202. package/dist/processor/snapshot.js +0 -66
  203. package/dist/processor/stats-api.d.ts +0 -18
  204. package/dist/processor/stats-api.js +0 -48
  205. package/dist/processor/stats.d.ts +0 -18
  206. package/dist/processor/stats.js +0 -206
  207. package/dist/processor/treeshaking.d.ts +0 -10
  208. package/dist/processor/treeshaking.js +0 -33
  209. package/dist/processor/watch.d.ts +0 -30
  210. package/dist/processor/watch.js +0 -241
  211. package/dist/reporter/diff-html.d.ts +0 -15
  212. package/dist/reporter/diff-html.js +0 -69
  213. package/dist/reporter/diff-stats.d.ts +0 -24
  214. package/dist/reporter/diff-stats.js +0 -131
  215. package/dist/reporter/index.d.ts +0 -2
  216. package/dist/reporter/index.js +0 -18
  217. package/dist/runner/basic.d.ts +0 -10
  218. package/dist/runner/basic.js +0 -63
  219. package/dist/runner/cache.d.ts +0 -5
  220. package/dist/runner/cache.js +0 -90
  221. package/dist/runner/hot-step.d.ts +0 -5
  222. package/dist/runner/hot-step.js +0 -87
  223. package/dist/runner/hot.d.ts +0 -5
  224. package/dist/runner/hot.js +0 -83
  225. package/dist/runner/multiple.d.ts +0 -11
  226. package/dist/runner/multiple.js +0 -38
  227. package/dist/runner/normal.d.ts +0 -5
  228. package/dist/runner/normal.js +0 -20
  229. package/dist/runner/runner/basic.d.ts +0 -30
  230. package/dist/runner/runner/basic.js +0 -107
  231. package/dist/runner/runner/cjs.d.ts +0 -14
  232. package/dist/runner/runner/cjs.js +0 -151
  233. package/dist/runner/runner/esm.d.ts +0 -7
  234. package/dist/runner/runner/esm.js +0 -125
  235. package/dist/runner/runner/index.d.ts +0 -8
  236. package/dist/runner/runner/index.js +0 -24
  237. package/dist/runner/runner/normal.d.ts +0 -9
  238. package/dist/runner/runner/normal.js +0 -23
  239. package/dist/runner/runner/watch.d.ts +0 -16
  240. package/dist/runner/runner/watch.js +0 -27
  241. package/dist/runner/runner/web/fake.d.ts +0 -18
  242. package/dist/runner/runner/web/fake.js +0 -143
  243. package/dist/runner/runner/web/jsdom.d.ts +0 -26
  244. package/dist/runner/runner/web/jsdom.js +0 -219
  245. package/dist/runner/runner/web.d.ts +0 -15
  246. package/dist/runner/runner/web.js +0 -32
  247. package/dist/runner/type.d.ts +0 -42
  248. package/dist/runner/type.js +0 -9
  249. package/dist/runner/watch.d.ts +0 -7
  250. package/dist/runner/watch.js +0 -60
  251. package/dist/test/simple.d.ts +0 -5
  252. package/dist/test/simple.js +0 -43
  253. package/jest.d.ts +0 -25
  254. package/template/diff.bundle.css +0 -1
  255. package/template/diff.bundle.js +0 -144
  256. package/template/diff.html +0 -14
  257. package/template/editor.worker.js +0 -1
  258. /package/dist/case/{nativeWatcher.d.ts → native-watcher.d.ts} +0 -0
  259. /package/dist/helper/legacy/{supportsWorker.d.ts → supportDefaultAssignment.d.ts} +0 -0
@@ -1,175 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.compareFile = compareFile;
7
- exports.compareModules = compareModules;
8
- exports.compareContent = compareContent;
9
- const node_path_1 = __importDefault(require("node:path"));
10
- const fs_extra_1 = __importDefault(require("fs-extra"));
11
- const jest_diff_1 = require("jest-diff");
12
- const helper_1 = require("../helper");
13
- const type_1 = require("../type");
14
- const format_code_1 = require("./format-code");
15
- const replace_runtime_module_name_1 = require("./replace-runtime-module-name");
16
- const WORKSPACE = node_path_1.default.resolve(__dirname, "../../../..");
17
- function compareFile(sourceFile, distFile, compareOptions) {
18
- const result = {
19
- type: type_1.ECompareResultType.Same,
20
- file: {
21
- source: sourceFile,
22
- dist: distFile
23
- },
24
- modules: {}
25
- };
26
- const sourceExists = fs_extra_1.default.existsSync(sourceFile);
27
- const distExists = compareOptions.snapshot
28
- ? fs_extra_1.default.existsSync(compareOptions.snapshot)
29
- : fs_extra_1.default.existsSync(distFile);
30
- if (!sourceExists && !distExists) {
31
- result.type = type_1.ECompareResultType.Missing;
32
- return result;
33
- }
34
- if (!sourceExists && distExists) {
35
- result.type = type_1.ECompareResultType.OnlyDist;
36
- return result;
37
- }
38
- if (sourceExists && !distExists) {
39
- result.type = type_1.ECompareResultType.OnlySource;
40
- return result;
41
- }
42
- function formatModules(modules) {
43
- const res = {};
44
- for (const [name, content] of Object.entries(modules)) {
45
- const renamed = name.replaceAll(node_path_1.default.win32.sep, node_path_1.default.posix.sep);
46
- if (!renamed.includes("node_modules/css-loader/dist")) {
47
- res[renamed] = (0, format_code_1.formatCode)(renamed, content, compareOptions.format);
48
- }
49
- }
50
- return res;
51
- }
52
- const sourceContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default.readFileSync(sourceFile, "utf-8").replaceAll(WORKSPACE, "__WORKSPACE__"));
53
- const sourceModules = (0, helper_1.parseModules)(sourceContent, {
54
- bootstrap: compareOptions.bootstrap,
55
- renameModule: compareOptions.renameModule
56
- });
57
- sourceModules.modules = formatModules(sourceModules.modules);
58
- sourceModules.runtimeModules = formatModules(sourceModules.runtimeModules);
59
- let distModules = {
60
- modules: {},
61
- runtimeModules: {}
62
- };
63
- if (!global.updateSnapshot &&
64
- compareOptions.snapshot &&
65
- fs_extra_1.default.existsSync(compareOptions.snapshot)) {
66
- distModules = JSON.parse(fs_extra_1.default.readFileSync(compareOptions.snapshot, "utf-8"));
67
- }
68
- else {
69
- const distContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default.readFileSync(distFile, "utf-8").replaceAll(WORKSPACE, "__WORKSPACE__"));
70
- distModules = (0, helper_1.parseModules)(distContent, {
71
- bootstrap: compareOptions.bootstrap,
72
- renameModule: compareOptions.renameModule
73
- });
74
- distModules.modules = formatModules(distModules.modules);
75
- distModules.runtimeModules = formatModules(distModules.runtimeModules);
76
- if (compareOptions.snapshot) {
77
- fs_extra_1.default.ensureDirSync(node_path_1.default.dirname(compareOptions.snapshot));
78
- fs_extra_1.default.writeFileSync(compareOptions.snapshot, JSON.stringify(distModules, null, 2));
79
- }
80
- }
81
- result.type = type_1.ECompareResultType.Different;
82
- for (const type of ["modules", "runtimeModules"]) {
83
- const t = type;
84
- let moduleList = [];
85
- if (compareOptions[t] === true) {
86
- moduleList = [
87
- ...Object.keys(sourceModules[t]),
88
- ...Object.keys(distModules[t])
89
- ].filter((i, idx, arr) => arr.indexOf(i) === idx);
90
- }
91
- else if (Array.isArray(compareOptions[t])) {
92
- moduleList = compareOptions[t];
93
- }
94
- else {
95
- continue;
96
- }
97
- result.modules[t] = compareModules(moduleList, sourceModules[t], distModules[t], compareOptions);
98
- }
99
- return result;
100
- }
101
- function compareModules(modules, sourceModules, distModules, compareOptions) {
102
- const compareResults = [];
103
- for (const name of modules) {
104
- const renamed = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(name).replaceAll(node_path_1.default.win32.sep, node_path_1.default.posix.sep);
105
- const sourceContent = sourceModules[renamed];
106
- const distContent = distModules[renamed];
107
- compareResults.push({
108
- ...compareContent(sourceContent, distContent, compareOptions),
109
- name
110
- });
111
- }
112
- return compareResults;
113
- }
114
- function compareContent(sourceContent, distContent, compareOptions) {
115
- if (sourceContent) {
116
- if (distContent) {
117
- if (sourceContent === distContent) {
118
- const lines = sourceContent.trim().split("\n").length;
119
- return {
120
- type: type_1.ECompareResultType.Same,
121
- source: sourceContent,
122
- dist: distContent,
123
- lines: {
124
- source: 0,
125
- common: lines,
126
- dist: 0
127
- }
128
- };
129
- }
130
- const difference = compareOptions.detail
131
- ? (0, jest_diff_1.diffStringsUnified)(sourceContent.trim(), distContent.trim())
132
- : undefined;
133
- const diffLines = (0, jest_diff_1.diffLinesRaw)(sourceContent.trim().split("\n"), distContent.trim().split("\n"));
134
- return {
135
- type: type_1.ECompareResultType.Different,
136
- detail: difference,
137
- source: sourceContent,
138
- dist: distContent,
139
- lines: {
140
- source: diffLines.filter(l => l[0] < 0).length,
141
- common: diffLines.filter(l => l[0] === 0).length,
142
- dist: diffLines.filter(l => l[0] > 0).length
143
- }
144
- };
145
- }
146
- return {
147
- type: type_1.ECompareResultType.OnlySource,
148
- source: sourceContent,
149
- lines: {
150
- source: sourceContent.trim().split("\n").length,
151
- common: 0,
152
- dist: 0
153
- }
154
- };
155
- }
156
- if (distContent) {
157
- return {
158
- type: type_1.ECompareResultType.OnlyDist,
159
- dist: distContent,
160
- lines: {
161
- source: 0,
162
- common: 0,
163
- dist: distContent.trim().split("\n").length
164
- }
165
- };
166
- }
167
- return {
168
- type: type_1.ECompareResultType.Missing,
169
- lines: {
170
- source: 0,
171
- common: 0,
172
- dist: 0
173
- }
174
- };
175
- }
@@ -1,16 +0,0 @@
1
- export interface IFormatCodeOptions {
2
- replacements?: IFormatCodeReplacement[];
3
- ignorePropertyQuotationMark: boolean;
4
- ignoreModuleId: boolean;
5
- ignoreModuleArguments: boolean;
6
- ignoreBlockOnlyStatement: boolean;
7
- ignoreSwcHelpersPath: boolean;
8
- ignoreObjectPropertySequence: boolean;
9
- ignoreCssFilePath: boolean;
10
- ignoreIfCertainCondition: boolean;
11
- }
12
- export interface IFormatCodeReplacement {
13
- from: string | RegExp;
14
- to: string;
15
- }
16
- export declare function formatCode(name: string, raw: string, options: IFormatCodeOptions): string;
@@ -1,239 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.formatCode = formatCode;
40
- const generator_1 = __importDefault(require("@babel/generator"));
41
- const parser_1 = require("@babel/parser");
42
- const traverse_1 = __importDefault(require("@babel/traverse"));
43
- const T = __importStar(require("@babel/types"));
44
- const replace_module_argument_1 = require("./replace-module-argument");
45
- const SWC_HELPER_PATH_REG = /^_swc_helpers_[a-zA-Z\d_-]+__WEBPACK_IMPORTED_MODULE_xxx__$/;
46
- const CSS_FILE_EXT_REG = /(le|sa|c|sc)ss$/;
47
- const INVALID_PATH_REG = /[<>:"/\\|?*.]/g;
48
- const MODULE_ID_REG = /__WEBPACK_IMPORTED_MODULE_\d+__/;
49
- function formatCode(name, raw, options) {
50
- const ast = (0, parser_1.parse)(raw, {
51
- sourceType: "unambiguous"
52
- });
53
- (0, traverse_1.default)(ast, {
54
- BlockStatement(path) {
55
- if (options.ignoreBlockOnlyStatement) {
56
- if (path.parentPath.isBlockStatement()) {
57
- path.replaceWithMultiple(path.node.body);
58
- }
59
- }
60
- },
61
- ObjectProperty(path) {
62
- if (options.ignorePropertyQuotationMark) {
63
- const keyPath = path.get("key");
64
- if (keyPath.isIdentifier()) {
65
- keyPath.replaceWith(T.stringLiteral(keyPath.node.name));
66
- }
67
- }
68
- if (options.ignoreCssFilePath && CSS_FILE_EXT_REG.test(name)) {
69
- const valuePath = path.get("value");
70
- if (valuePath.isStringLiteral()) {
71
- valuePath.node.value = valuePath.node.value.replace(INVALID_PATH_REG, "-");
72
- }
73
- }
74
- },
75
- Identifier(path) {
76
- if (options.ignoreModuleId) {
77
- if (MODULE_ID_REG.test(path.node.name)) {
78
- path.node.name = "__WEBPACK_IMPORTED_MODULE_xxx__";
79
- }
80
- }
81
- if (options.ignoreSwcHelpersPath) {
82
- if (SWC_HELPER_PATH_REG.test(path.node.name)) {
83
- path.node.name = "$$SWC_HELPERS$$";
84
- }
85
- }
86
- },
87
- StringLiteral(path) {
88
- if (path.node.extra?.raw) {
89
- path.node.extra.raw = JSON.stringify(path.node.extra.rawValue);
90
- }
91
- },
92
- IfStatement(path) {
93
- let consequentNode;
94
- let alternateNode;
95
- if (options.ignoreBlockOnlyStatement) {
96
- const consequent = path.get("consequent");
97
- if (consequent.isBlockStatement() &&
98
- consequent.node.body.length === 1) {
99
- consequent.node.body[0].leadingComments =
100
- consequent.node.leadingComments;
101
- consequentNode = consequent.node.body[0];
102
- consequent.replaceWith(consequentNode);
103
- }
104
- const alternate = path.get("alternate");
105
- if (alternate.isBlockStatement() && alternate.node.body.length === 1) {
106
- alternate.node.body[0].leadingComments =
107
- alternate.node.leadingComments;
108
- alternateNode = alternate.node.body[0];
109
- alternate.replaceWith(alternateNode);
110
- }
111
- }
112
- if (options.ignoreIfCertainCondition) {
113
- const testExpr = path.get("test");
114
- const testResult = testExpr.isBooleanLiteral()
115
- ? testExpr.node.value
116
- : undefined;
117
- if (typeof testResult === "boolean") {
118
- if (testResult) {
119
- const consequent = path.get("consequent");
120
- if (consequent.isBlockStatement()) {
121
- if (consequentNode) {
122
- path.replaceWith(consequentNode);
123
- }
124
- else {
125
- path.replaceWithMultiple(consequent.node.body);
126
- }
127
- }
128
- else {
129
- path.replaceWith(consequent);
130
- }
131
- }
132
- else {
133
- const alternate = path.get("alternate");
134
- if (alternate.isBlockStatement()) {
135
- if (alternateNode) {
136
- path.replaceWith(alternateNode);
137
- }
138
- else {
139
- path.replaceWithMultiple(alternate.node.body);
140
- }
141
- }
142
- else if (alternate.isStatement()) {
143
- path.replaceWith(alternate);
144
- }
145
- else {
146
- path.remove();
147
- }
148
- }
149
- }
150
- }
151
- },
152
- For(path) {
153
- if (options.ignoreBlockOnlyStatement) {
154
- const body = path.get("body");
155
- if (body.isBlockStatement() && body.node.body.length === 1) {
156
- body.node.body[0].leadingComments = body.node.leadingComments;
157
- body.replaceWith(T.cloneNode(body.node.body[0], true, false));
158
- }
159
- }
160
- },
161
- While(path) {
162
- if (options.ignoreBlockOnlyStatement) {
163
- const body = path.get("body");
164
- if (body.isBlockStatement() && body.node.body.length === 1) {
165
- body.node.body[0].leadingComments = body.node.leadingComments;
166
- body.replaceWith(T.cloneNode(body.node.body[0], true, false));
167
- }
168
- }
169
- },
170
- SwitchCase(path) {
171
- if (path.node.consequent.length === 1 &&
172
- path.node.consequent[0].type === "BlockStatement") {
173
- path.node.consequent = path.node.consequent[0].body;
174
- }
175
- },
176
- ObjectExpression(path) {
177
- if (options.ignoreObjectPropertySequence) {
178
- const result = [];
179
- let safe = [];
180
- while (path.node.properties.length || safe.length) {
181
- const cur = path.node.properties.shift();
182
- if (cur && T.isObjectProperty(cur)) {
183
- if (T.isIdentifier(cur.key)) {
184
- safe.push({
185
- name: cur.key.name,
186
- node: cur
187
- });
188
- continue;
189
- }
190
- if (T.isStringLiteral(cur.key)) {
191
- safe.push({
192
- name: cur.key.value,
193
- node: cur
194
- });
195
- continue;
196
- }
197
- }
198
- if (safe.length) {
199
- safe.sort((a, b) => (a.name > b.name ? 1 : -1));
200
- result.push(...safe.map(n => n.node));
201
- safe = [];
202
- }
203
- if (cur) {
204
- result.push(cur);
205
- }
206
- }
207
- path.node.properties = result;
208
- }
209
- }
210
- });
211
- let result = (0, generator_1.default)(ast, {
212
- comments: false,
213
- compact: false,
214
- concise: false,
215
- jsescOption: {
216
- quotes: "double"
217
- }
218
- }).code;
219
- if (options.ignoreModuleArguments) {
220
- result = (0, replace_module_argument_1.replaceModuleArgument)(result);
221
- }
222
- if (options.replacements) {
223
- for (const { from, to } of options.replacements) {
224
- result = result.replaceAll(from, to);
225
- }
226
- }
227
- // result of generate() is not stable with comments sometimes
228
- // so do it again
229
- return (0, generator_1.default)((0, parser_1.parse)(result, {
230
- sourceType: "unambiguous"
231
- }), {
232
- comments: false,
233
- compact: false,
234
- concise: false,
235
- jsescOption: {
236
- quotes: "double"
237
- }
238
- }).code.trim();
239
- }
@@ -1,5 +0,0 @@
1
- export * from "./comparator";
2
- export * from "./compare";
3
- export * from "./format-code";
4
- export * from "./replace-module-argument";
5
- export * from "./replace-runtime-module-name";
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./comparator"), exports);
18
- __exportStar(require("./compare"), exports);
19
- __exportStar(require("./format-code"), exports);
20
- __exportStar(require("./replace-module-argument"), exports);
21
- __exportStar(require("./replace-runtime-module-name"), exports);
@@ -1 +0,0 @@
1
- export declare function replaceModuleArgument(raw: string): string;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.replaceModuleArgument = replaceModuleArgument;
4
- function replaceModuleArgument(raw) {
5
- return raw
6
- .trim()
7
- .replace(/^\(function\s?\([\w_,\s]+\)\s?{/, "(function () {");
8
- }
@@ -1 +0,0 @@
1
- export declare function replaceRuntimeModuleName(content: string): string;
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.replaceRuntimeModuleName = replaceRuntimeModuleName;
4
- const RUNTIME_MODULE_REGEX = /(webpack\/runtime\/)([a-z_]+)/g;
5
- const RUNTIME_MODULE_NAME_REPLACER = {
6
- auto_public_path: "publicPath",
7
- public_path: "publicPath",
8
- async_module: "async module",
9
- base_uri: "base uri",
10
- chunk_name: "chunkName",
11
- compat_get_default_export: "compat get default export",
12
- compat: "compat",
13
- create_fake_namespace_object: "create fake namespace object",
14
- create_script_url: "trusted types script url",
15
- create_script: "trusted types script",
16
- define_property_getters: "define property getters",
17
- ensure_chunk: "ensure chunk",
18
- get_full_hash: "getFullHash",
19
- get_trusted_types_policy: "trusted types policy",
20
- global: "global",
21
- has_own_property: "hasOwnProperty shorthand",
22
- load_script: "load script",
23
- make_namespace_object: "make namespace object",
24
- nonce: "nonce",
25
- on_chunk_loaded: "chunk loaded",
26
- relative_url: "relative url",
27
- runtime_id: "runtimeId",
28
- startup_chunk_dependencies: "startup chunk dependencies",
29
- startup_entrypoint: "startup entrypoint",
30
- system_context: "__system_context__",
31
- chunk_prefetch_startup: "startup prefetch",
32
- chunk_prefetch_trigger: "chunk prefetch trigger",
33
- chunk_preload_trigger: "chunk preload trigger",
34
- css_loading: "css loading",
35
- async_wasm_loading: "wasm loading",
36
- hot_module_replacement: "hot module replacement",
37
- readfile_chunk_loading: "readFile chunk loading",
38
- require_chunk_loading: "require chunk loading",
39
- import_scripts_chunk_loading: "importScripts chunk loading",
40
- module_chunk_loading: "import chunk loading",
41
- export_webpack_runtime: "export webpack runtime",
42
- jsonp_chunk_loading: "jsonp chunk loading",
43
- remote: "remotes loading",
44
- share: "sharing",
45
- consume_shared: "consumes",
46
- esm_module_decorator: "harmony module decorator",
47
- node_module_decorator: "node module decorator"
48
- };
49
- const RUNTIME_MODULE_NAME_MAPPING = {
50
- // module name with parameters
51
- "webpack/runtime/get_chunk_filename": "webpack/runtime/get $1 chunk filename",
52
- "webpack/runtime/get_main_filename": "webpack/runtime/get $1 filename",
53
- "webpack/runtime/chunk_prefetch_function": "webpack/runtime/chunk $1 function"
54
- };
55
- const RUNTIME_MODULE_PARAM_REGEX = {
56
- "webpack/runtime/get_chunk_filename": /webpack\/runtime\/get_chunk_filename\/([\w.\-_\s]+)(\*\/)?/g,
57
- "webpack/runtime/get_main_filename": /webpack\/runtime\/get_main_filename\/([\w.\-_\s]+)(\*\/)?/g,
58
- "webpack/runtime/chunk_prefetch_function": /webpack\/runtime\/chunk_prefetch_function\/([\w.\-_\s]+)(\*\/)?/g
59
- };
60
- function replaceRuntimeModuleName(content) {
61
- let res = content.replace(RUNTIME_MODULE_REGEX, (_, $1, $2) => `${$1}${RUNTIME_MODULE_NAME_REPLACER[$2] || $2}`);
62
- res = Object.entries(RUNTIME_MODULE_NAME_MAPPING).reduce((res, [rspackName, webpackName]) => {
63
- if (RUNTIME_MODULE_PARAM_REGEX[rspackName]) {
64
- return res.replace(RUNTIME_MODULE_PARAM_REGEX[rspackName], (_, $1, $2) => {
65
- return webpackName.replace("$1", $1.trim()) + ($2 ? " */" : "");
66
- });
67
- }
68
- return res.replaceAll(rspackName, webpackName);
69
- }, res);
70
- return res;
71
- }
@@ -1,54 +0,0 @@
1
- export default class FakeDocument {
2
- constructor(basePath: any, options?: {});
3
- head: FakeElement;
4
- body: FakeElement;
5
- baseURI: string;
6
- _elementsByTagName: Map<string, FakeElement[]>;
7
- _basePath: any;
8
- currentScript: any;
9
- _options: {};
10
- createElement(type: any): FakeElement;
11
- _onElementAttached(element: any): void;
12
- _onElementRemoved(element: any): void;
13
- getElementsByTagName(name: any): FakeElement[];
14
- querySelectorAll(name: any): FakeElement[];
15
- getComputedStyle(element: any): {
16
- getPropertyValue: (property: any) => any;
17
- };
18
- }
19
- export class FakeElement {
20
- constructor(document: any, type: any, basePath: any);
21
- _document: any;
22
- _type: any;
23
- _basePath: any;
24
- _children: any[];
25
- _attributes: any;
26
- _src: any;
27
- _href: any;
28
- rel: any;
29
- parentNode: any;
30
- sheet: FakeSheet | undefined;
31
- cloneNode(): FakeElement;
32
- addEventListener(): void;
33
- insertBefore(node: any, before: any): void;
34
- appendChild(node: any): void;
35
- removeChild(node: any): void;
36
- setAttribute(name: any, value: any): void;
37
- removeAttribute(name: any): void;
38
- getAttribute(name: any): any;
39
- _toRealUrl(value: any): any;
40
- set src(value: any);
41
- get src(): any;
42
- get children(): any[];
43
- set href(value: any);
44
- get href(): any;
45
- }
46
- export class FakeSheet {
47
- constructor(element: any, basePath: any);
48
- _element: any;
49
- _basePath: any;
50
- cachedCss: string | undefined;
51
- cachedCssRules: any[] | undefined;
52
- get css(): string;
53
- get cssRules(): any[];
54
- }