@rspack-canary/test-tools 1.5.9-canary-a915dabc-20251013174148 → 1.5.9-canary-e259bc79-20251014173821

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 (83) hide show
  1. package/dist/case/hot-step.d.ts +1 -1
  2. package/dist/case/hot-step.js +12 -10
  3. package/dist/case/hot.d.ts +5 -4
  4. package/dist/case/hot.js +32 -41
  5. package/dist/case/incremental.d.ts +1 -1
  6. package/dist/case/incremental.js +8 -6
  7. package/dist/case/normal.js +0 -4
  8. package/dist/case/watch.js +0 -7
  9. package/dist/helper/hot-update/plugin.d.ts +1 -1
  10. package/dist/helper/hot-update/plugin.js +4 -4
  11. package/dist/helper/legacy/update.d.ts +2 -0
  12. package/dist/helper/legacy/update.esm.d.ts +1 -0
  13. package/dist/helper/legacy/update.esm.js +23 -0
  14. package/dist/helper/legacy/update.js +19 -0
  15. package/dist/helper/util/checkStats.d.ts +0 -1
  16. package/dist/helper/util/checkStats.js +0 -18
  17. package/dist/index.d.ts +0 -1
  18. package/dist/index.js +0 -1
  19. package/dist/jest/ignore-snapshot-default-reporter.d.ts +2 -0
  20. package/dist/jest/ignore-snapshot-default-reporter.js +57 -0
  21. package/dist/jest/ignore-snapshot-summary-reporter.d.ts +2 -0
  22. package/dist/jest/ignore-snapshot-summary-reporter.js +24 -0
  23. package/dist/jest/patch-node-env.d.ts +5 -0
  24. package/dist/jest/patch-node-env.js +18 -0
  25. package/dist/jest/slash.d.ts +2 -0
  26. package/dist/jest/slash.js +16 -0
  27. package/package.json +9 -6
  28. package/dist/helper/legacy/createLogger.d.ts +0 -23
  29. package/dist/helper/legacy/createLogger.js +0 -20
  30. package/dist/helper/legacy/diffStats.d.ts +0 -2
  31. package/dist/helper/legacy/diffStats.js +0 -13
  32. package/dist/helper/legacy/supportsBlob.d.ts +0 -2
  33. package/dist/helper/legacy/supportsBlob.js +0 -10
  34. package/dist/helper/legacy/supportsClassFields.d.ts +0 -2
  35. package/dist/helper/legacy/supportsClassFields.js +0 -11
  36. package/dist/helper/legacy/supportsES6.d.ts +0 -2
  37. package/dist/helper/legacy/supportsES6.js +0 -11
  38. package/dist/helper/legacy/supportsForOf.d.ts +0 -2
  39. package/dist/helper/legacy/supportsForOf.js +0 -11
  40. package/dist/helper/legacy/supportsIteratorDestructuring.d.ts +0 -2
  41. package/dist/helper/legacy/supportsIteratorDestructuring.js +0 -11
  42. package/dist/helper/legacy/supportsLogicalAssignment.d.ts +0 -2
  43. package/dist/helper/legacy/supportsLogicalAssignment.js +0 -11
  44. package/dist/helper/legacy/supportsObjectDestructuring.d.ts +0 -2
  45. package/dist/helper/legacy/supportsObjectDestructuring.js +0 -11
  46. package/dist/helper/legacy/supportsOptionalCatchBinding.d.ts +0 -2
  47. package/dist/helper/legacy/supportsOptionalCatchBinding.js +0 -11
  48. package/dist/helper/legacy/supportsOptionalChaining.d.ts +0 -2
  49. package/dist/helper/legacy/supportsOptionalChaining.js +0 -11
  50. package/dist/helper/legacy/supportsRequireInModule.d.ts +0 -2
  51. package/dist/helper/legacy/supportsRequireInModule.js +0 -5
  52. package/dist/helper/legacy/supportsResponse.d.ts +0 -2
  53. package/dist/helper/legacy/supportsResponse.js +0 -10
  54. package/dist/helper/legacy/supportsSpread.d.ts +0 -2
  55. package/dist/helper/legacy/supportsSpread.js +0 -12
  56. package/dist/helper/legacy/supportsTemplateStrings.d.ts +0 -2
  57. package/dist/helper/legacy/supportsTemplateStrings.js +0 -11
  58. package/dist/helper/legacy/supportsTextDecoder.d.ts +0 -2
  59. package/dist/helper/legacy/supportsTextDecoder.js +0 -10
  60. package/dist/helper/legacy/supportsWebAssembly.d.ts +0 -2
  61. package/dist/helper/legacy/supportsWebAssembly.js +0 -10
  62. package/dist/helper/legacy/supportsWorker.d.ts +0 -2
  63. package/dist/helper/legacy/supportsWorker.js +0 -17
  64. package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
  65. package/dist/helper/legacy/warmup-webpack.js +0 -26
  66. package/dist/helper/loaders/hot-update.d.ts +0 -1
  67. package/dist/helper/loaders/hot-update.js +0 -43
  68. package/dist/helper/plugins/hot-update.d.ts +0 -7
  69. package/dist/helper/plugins/hot-update.js +0 -40
  70. package/dist/helper/plugins/index.d.ts +0 -1
  71. package/dist/helper/plugins/index.js +0 -17
  72. package/dist/helper/util/currentWatchStep.d.ts +0 -1
  73. package/dist/helper/util/currentWatchStep.js +0 -2
  74. package/dist/helper/util/identifier.d.ts +0 -76
  75. package/dist/helper/util/identifier.js +0 -339
  76. package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
  77. package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
  78. package/dist/reporter/diff-html.d.ts +0 -15
  79. package/dist/reporter/diff-html.js +0 -69
  80. package/dist/reporter/diff-stats.d.ts +0 -24
  81. package/dist/reporter/diff-stats.js +0 -131
  82. package/dist/reporter/index.d.ts +0 -2
  83. package/dist/reporter/index.js +0 -18
@@ -1,339 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- /*
4
- * MIT License http://www.opensource.org/licenses/mit-license.php
5
- */
6
- const path = require("node:path");
7
- const WINDOWS_ABS_PATH_REGEXP = /^[a-zA-Z]:[\\/]/;
8
- const SEGMENTS_SPLIT_REGEXP = /([|!])/;
9
- const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
10
- /**
11
- * @typedef {Object} MakeRelativePathsCache
12
- * @property {Map<string, Map<string, string>>=} relativePaths
13
- */
14
- const relativePathToRequest = relativePath => {
15
- if (relativePath === "")
16
- return "./.";
17
- if (relativePath === "..")
18
- return "../.";
19
- if (relativePath.startsWith("../"))
20
- return relativePath;
21
- return `./${relativePath}`;
22
- };
23
- /**
24
- * @param {string} context context for relative path
25
- * @param {string} maybeAbsolutePath path to make relative
26
- * @returns {string} relative path in request style
27
- */
28
- const absoluteToRequest = (context, maybeAbsolutePath) => {
29
- if (maybeAbsolutePath[0] === "/") {
30
- if (maybeAbsolutePath.length > 1 &&
31
- maybeAbsolutePath[maybeAbsolutePath.length - 1] === "/") {
32
- // this 'path' is actually a regexp generated by dynamic requires.
33
- // Don't treat it as an absolute path.
34
- return maybeAbsolutePath;
35
- }
36
- const querySplitPos = maybeAbsolutePath.indexOf("?");
37
- let resource = querySplitPos === -1
38
- ? maybeAbsolutePath
39
- : maybeAbsolutePath.slice(0, querySplitPos);
40
- resource = relativePathToRequest(path.posix.relative(context, resource));
41
- return querySplitPos === -1
42
- ? resource
43
- : resource + maybeAbsolutePath.slice(querySplitPos);
44
- }
45
- if (WINDOWS_ABS_PATH_REGEXP.test(maybeAbsolutePath)) {
46
- const querySplitPos = maybeAbsolutePath.indexOf("?");
47
- let resource = querySplitPos === -1
48
- ? maybeAbsolutePath
49
- : maybeAbsolutePath.slice(0, querySplitPos);
50
- resource = path.win32.relative(context, resource);
51
- if (!WINDOWS_ABS_PATH_REGEXP.test(resource)) {
52
- resource = relativePathToRequest(resource.replace(WINDOWS_PATH_SEPARATOR_REGEXP, "/"));
53
- }
54
- return querySplitPos === -1
55
- ? resource
56
- : resource + maybeAbsolutePath.slice(querySplitPos);
57
- }
58
- // not an absolute path
59
- return maybeAbsolutePath;
60
- };
61
- /**
62
- * @param {string} context context for relative path
63
- * @param {string} relativePath path
64
- * @returns {string} absolute path
65
- */
66
- const requestToAbsolute = (context, relativePath) => {
67
- if (relativePath.startsWith("./") || relativePath.startsWith("../"))
68
- return path.join(context, relativePath);
69
- return relativePath;
70
- };
71
- const makeCacheable = realFn => {
72
- /** @type {WeakMap<object, Map<string, ParsedResource>>} */
73
- const cache = new WeakMap();
74
- const getCache = associatedObjectForCache => {
75
- const entry = cache.get(associatedObjectForCache);
76
- if (entry !== undefined)
77
- return entry;
78
- /** @type {Map<string, ParsedResource>} */
79
- const map = new Map();
80
- cache.set(associatedObjectForCache, map);
81
- return map;
82
- };
83
- /**
84
- * @param {string} str the path with query and fragment
85
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
86
- * @returns {ParsedResource} parsed parts
87
- */
88
- const fn = (str, associatedObjectForCache) => {
89
- if (!associatedObjectForCache)
90
- return realFn(str);
91
- const cache = getCache(associatedObjectForCache);
92
- const entry = cache.get(str);
93
- if (entry !== undefined)
94
- return entry;
95
- const result = realFn(str);
96
- cache.set(str, result);
97
- return result;
98
- };
99
- fn.bindCache = associatedObjectForCache => {
100
- const cache = getCache(associatedObjectForCache);
101
- return str => {
102
- const entry = cache.get(str);
103
- if (entry !== undefined)
104
- return entry;
105
- const result = realFn(str);
106
- cache.set(str, result);
107
- return result;
108
- };
109
- };
110
- return fn;
111
- };
112
- const makeCacheableWithContext = fn => {
113
- /** @type {WeakMap<object, Map<string, Map<string, string>>>} */
114
- const cache = new WeakMap();
115
- /**
116
- * @param {string} context context used to create relative path
117
- * @param {string} identifier identifier used to create relative path
118
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
119
- * @returns {string} the returned relative path
120
- */
121
- const cachedFn = (context, identifier, associatedObjectForCache) => {
122
- if (!associatedObjectForCache)
123
- return fn(context, identifier);
124
- let innerCache = cache.get(associatedObjectForCache);
125
- if (innerCache === undefined) {
126
- innerCache = new Map();
127
- cache.set(associatedObjectForCache, innerCache);
128
- }
129
- let cachedResult;
130
- let innerSubCache = innerCache.get(context);
131
- if (innerSubCache === undefined) {
132
- innerCache.set(context, (innerSubCache = new Map()));
133
- }
134
- else {
135
- cachedResult = innerSubCache.get(identifier);
136
- }
137
- if (cachedResult !== undefined) {
138
- return cachedResult;
139
- }
140
- const result = fn(context, identifier);
141
- innerSubCache.set(identifier, result);
142
- return result;
143
- };
144
- /**
145
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
146
- * @returns {function(string, string): string} cached function
147
- */
148
- cachedFn.bindCache = associatedObjectForCache => {
149
- let innerCache;
150
- if (associatedObjectForCache) {
151
- innerCache = cache.get(associatedObjectForCache);
152
- if (innerCache === undefined) {
153
- innerCache = new Map();
154
- cache.set(associatedObjectForCache, innerCache);
155
- }
156
- }
157
- else {
158
- innerCache = new Map();
159
- }
160
- /**
161
- * @param {string} context context used to create relative path
162
- * @param {string} identifier identifier used to create relative path
163
- * @returns {string} the returned relative path
164
- */
165
- const boundFn = (context, identifier) => {
166
- let cachedResult;
167
- let innerSubCache = innerCache.get(context);
168
- if (innerSubCache === undefined) {
169
- innerCache.set(context, (innerSubCache = new Map()));
170
- }
171
- else {
172
- cachedResult = innerSubCache.get(identifier);
173
- }
174
- if (cachedResult !== undefined) {
175
- return cachedResult;
176
- }
177
- const result = fn(context, identifier);
178
- innerSubCache.set(identifier, result);
179
- return result;
180
- };
181
- return boundFn;
182
- };
183
- /**
184
- * @param {string} context context used to create relative path
185
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
186
- * @returns {function(string): string} cached function
187
- */
188
- cachedFn.bindContextCache = (context, associatedObjectForCache) => {
189
- let innerSubCache;
190
- if (associatedObjectForCache) {
191
- let innerCache = cache.get(associatedObjectForCache);
192
- if (innerCache === undefined) {
193
- innerCache = new Map();
194
- cache.set(associatedObjectForCache, innerCache);
195
- }
196
- innerSubCache = innerCache.get(context);
197
- if (innerSubCache === undefined) {
198
- innerCache.set(context, (innerSubCache = new Map()));
199
- }
200
- }
201
- else {
202
- innerSubCache = new Map();
203
- }
204
- /**
205
- * @param {string} identifier identifier used to create relative path
206
- * @returns {string} the returned relative path
207
- */
208
- const boundFn = identifier => {
209
- const cachedResult = innerSubCache.get(identifier);
210
- if (cachedResult !== undefined) {
211
- return cachedResult;
212
- }
213
- const result = fn(context, identifier);
214
- innerSubCache.set(identifier, result);
215
- return result;
216
- };
217
- return boundFn;
218
- };
219
- return cachedFn;
220
- };
221
- /**
222
- *
223
- * @param {string} context context for relative path
224
- * @param {string} identifier identifier for path
225
- * @returns {string} a converted relative path
226
- */
227
- const _makePathsRelative = (context, identifier) => {
228
- return identifier
229
- .split(SEGMENTS_SPLIT_REGEXP)
230
- .map(str => absoluteToRequest(context, str))
231
- .join("");
232
- };
233
- exports.makePathsRelative = makeCacheableWithContext(_makePathsRelative);
234
- /**
235
- *
236
- * @param {string} context context for relative path
237
- * @param {string} identifier identifier for path
238
- * @returns {string} a converted relative path
239
- */
240
- const _makePathsAbsolute = (context, identifier) => {
241
- return identifier
242
- .split(SEGMENTS_SPLIT_REGEXP)
243
- .map(str => requestToAbsolute(context, str))
244
- .join("");
245
- };
246
- exports.makePathsAbsolute = makeCacheableWithContext(_makePathsAbsolute);
247
- /**
248
- * @param {string} context absolute context path
249
- * @param {string} request any request string may containing absolute paths, query string, etc.
250
- * @returns {string} a new request string avoiding absolute paths when possible
251
- */
252
- const _contextify = (context, request) => {
253
- return request
254
- .split("!")
255
- .map(r => absoluteToRequest(context, r))
256
- .join("!");
257
- };
258
- const contextify = makeCacheableWithContext(_contextify);
259
- exports.contextify = contextify;
260
- /**
261
- * @param {string} context absolute context path
262
- * @param {string} request any request string
263
- * @returns {string} a new request string using absolute paths when possible
264
- */
265
- const _absolutify = (context, request) => {
266
- return request
267
- .split("!")
268
- .map(r => requestToAbsolute(context, r))
269
- .join("!");
270
- };
271
- const absolutify = makeCacheableWithContext(_absolutify);
272
- exports.absolutify = absolutify;
273
- const PATH_QUERY_FRAGMENT_REGEXP = /^((?:\u200b.|[^?#\u200b])*)(\?(?:\u200b.|[^#\u200b])*)?(#.*)?$/;
274
- const PATH_QUERY_REGEXP = /^((?:\u200b.|[^?\u200b])*)(\?.*)?$/;
275
- /** @typedef {{ resource: string, path: string, query: string, fragment: string }} ParsedResource */
276
- /** @typedef {{ resource: string, path: string, query: string }} ParsedResourceWithoutFragment */
277
- /**
278
- * @param {string} str the path with query and fragment
279
- * @returns {ParsedResource} parsed parts
280
- */
281
- const _parseResource = str => {
282
- const match = PATH_QUERY_FRAGMENT_REGEXP.exec(str);
283
- return {
284
- resource: str,
285
- path: match[1].replace(/\u200b(.)/g, "$1"),
286
- query: match[2] ? match[2].replace(/\u200b(.)/g, "$1") : "",
287
- fragment: match[3] || ""
288
- };
289
- };
290
- exports.parseResource = makeCacheable(_parseResource);
291
- /**
292
- * Parse resource, skips fragment part
293
- * @param {string} str the path with query and fragment
294
- * @returns {ParsedResourceWithoutFragment} parsed parts
295
- */
296
- const _parseResourceWithoutFragment = str => {
297
- const match = PATH_QUERY_REGEXP.exec(str);
298
- return {
299
- resource: str,
300
- path: match[1].replace(/\u200b(.)/g, "$1"),
301
- query: match[2] ? match[2].replace(/\u200b(.)/g, "$1") : ""
302
- };
303
- };
304
- exports.parseResourceWithoutFragment = makeCacheable(_parseResourceWithoutFragment);
305
- /**
306
- * @param {string} filename the filename which should be undone
307
- * @param {string} outputPath the output path that is restored (only relevant when filename contains "..")
308
- * @param {boolean} enforceRelative true returns ./ for empty paths
309
- * @returns {string} repeated ../ to leave the directory of the provided filename to be back on output dir
310
- */
311
- exports.getUndoPath = (filename, outputPath, enforceRelative) => {
312
- let depth = -1;
313
- let append = "";
314
- let path = outputPath.replace(/[\\/]$/, "");
315
- for (const part of filename.split(/[/\\]+/)) {
316
- if (part === "..") {
317
- if (depth > -1) {
318
- depth--;
319
- }
320
- else {
321
- const i = path.lastIndexOf("/");
322
- const j = path.lastIndexOf("\\");
323
- const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j);
324
- if (pos < 0)
325
- return `${path}/`;
326
- append = `${path.slice(pos + 1)}/${append}`;
327
- path = path.slice(0, pos);
328
- }
329
- }
330
- else if (part !== ".") {
331
- depth++;
332
- }
333
- }
334
- return depth > 0
335
- ? `${"../".repeat(depth)}${append}`
336
- : enforceRelative
337
- ? `./${append}`
338
- : append;
339
- };
@@ -1,2 +0,0 @@
1
- export function replace(s: any): any;
2
- export function replaceStack(s: any): any;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- // Remove the "|" padding from miette,
4
- // used to ensure no line breaks with padding being returned,
5
- // miette generates diagnostics lines with respect to terminal size
6
- // and this might varies among different `process.cwd()` being used,
7
- // which breaks local and CI checks.
8
- const replace = s => s.replace(/\r?\n[ ]+│ /g, "");
9
- // HOW THIS WORKS:
10
- // 1. Remove potential line break and "|"
11
- // 2. Save the JS stack for each line
12
- // 3. If the current line was splitted because of terminal size, merge them together
13
- const replaceStack = s => s.replace(/(?:\s|│)*(at.*)(\s|│)*/g, "\n$1");
14
- module.exports = {
15
- replace,
16
- replaceStack
17
- };
@@ -1,15 +0,0 @@
1
- import type { ITestReporter, TModuleCompareResult } from "../type";
2
- export interface IDiffHtmlReporterOptions {
3
- dist: string;
4
- ignore?: RegExp;
5
- }
6
- export declare class DiffHtmlReporter implements ITestReporter<TModuleCompareResult[]> {
7
- private options;
8
- private failed;
9
- private results;
10
- constructor(options: IDiffHtmlReporterOptions);
11
- init(data?: TModuleCompareResult[]): Promise<void>;
12
- failure(id: string): Promise<void>;
13
- increment(id: string, data: TModuleCompareResult[]): Promise<void>;
14
- output(): Promise<void>;
15
- }
@@ -1,69 +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.DiffHtmlReporter = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const VIEWER_DIR = node_path_1.default.join(__dirname, "../../template");
10
- const DIFF_STATS_PLACEHOLDER = "$$RSPACK_DIFF_STATS_PLACEHOLDER$$";
11
- const DEFAULT_IGNORE = /node_modules/;
12
- class DiffHtmlReporter {
13
- constructor(options) {
14
- this.options = options;
15
- this.failed = new Set();
16
- this.results = new Map();
17
- }
18
- async init(data = []) { }
19
- async failure(id) {
20
- this.failed.add(id);
21
- this.results.delete(id);
22
- }
23
- async increment(id, data) {
24
- if (this.failed.has(id))
25
- return;
26
- if (!this.results.has(id)) {
27
- this.results.set(id, []);
28
- }
29
- const ignore = this.options.ignore || DEFAULT_IGNORE;
30
- const current = this.results.get(id);
31
- for (const i of data) {
32
- if (!ignore.test(i.name)) {
33
- current.push({
34
- name: i.name,
35
- source: i.source || "",
36
- dist: i.dist || "",
37
- type: i.type
38
- });
39
- }
40
- }
41
- }
42
- async output() {
43
- fs_extra_1.default.ensureDirSync(this.options.dist);
44
- for (const viewerFile of fs_extra_1.default
45
- .readdirSync(VIEWER_DIR)
46
- .filter(file => file.startsWith("diff"))) {
47
- const sourceFile = node_path_1.default.join(VIEWER_DIR, viewerFile);
48
- if (node_path_1.default.extname(viewerFile) === ".html") {
49
- const template = fs_extra_1.default.readFileSync(sourceFile, "utf-8");
50
- for (const [id, items] of this.results.entries()) {
51
- const data = {
52
- root: id,
53
- data: items
54
- };
55
- const casename = node_path_1.default.basename(id);
56
- const extname = node_path_1.default.extname(viewerFile);
57
- const filename = node_path_1.default.basename(viewerFile, extname);
58
- const content = template.replace(`<script id="${DIFF_STATS_PLACEHOLDER}"></script>`, `<script src="${filename}_${casename}.js"></script>`);
59
- fs_extra_1.default.writeFileSync(node_path_1.default.join(this.options.dist, `${filename}_${casename}${extname}`), content, "utf-8");
60
- fs_extra_1.default.writeFileSync(node_path_1.default.join(this.options.dist, `${filename}_${casename}.js`), `window.$$diff_detail$$ = ${JSON.stringify(data)}`, "utf-8");
61
- }
62
- }
63
- else {
64
- fs_extra_1.default.copyFileSync(sourceFile, node_path_1.default.join(this.options.dist, viewerFile));
65
- }
66
- }
67
- }
68
- }
69
- exports.DiffHtmlReporter = DiffHtmlReporter;
@@ -1,24 +0,0 @@
1
- import { ECompilerType, type ITestReporter, type TModuleCompareResult } from "../type";
2
- export interface IDiffStatsReporterOptions {
3
- header?: string[];
4
- footer?: string[];
5
- file: string;
6
- report?: boolean;
7
- }
8
- export type TCompilerTypeId = ECompilerType.Rspack | ECompilerType.Webpack | "common";
9
- export type TModuleTypeId = "normal" | "runtime";
10
- export type TDimenTypeId = "modules" | "lines" | "lines-in-common";
11
- export type TCaseSummaryId = `${TCompilerTypeId}|${TModuleTypeId}|${TDimenTypeId}`;
12
- export type TCaseSummary = Record<TCaseSummaryId, number>;
13
- export declare class DiffStatsReporter implements ITestReporter<TModuleCompareResult[]> {
14
- private options;
15
- private summary;
16
- private failed;
17
- constructor(options: IDiffStatsReporterOptions);
18
- init(data?: TModuleCompareResult[]): Promise<void>;
19
- failure(id: string): Promise<void>;
20
- increment(id: string, data: TModuleCompareResult[]): Promise<void>;
21
- output(): Promise<void>;
22
- private stringifySummary;
23
- private createSummary;
24
- }
@@ -1,131 +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.DiffStatsReporter = void 0;
7
- const csv_to_markdown_table_1 = __importDefault(require("csv-to-markdown-table"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const type_1 = require("../type");
10
- const toPercent = (d) => `${(d * 100).toFixed(2)}%`;
11
- const toFirstLetterUpperCase = (s) => (s.charAt(0).toUpperCase() + s.slice(1)).split("-").join(" ");
12
- const GITHUB_RUN_ID = process.env.GITHUB_RUN_ID;
13
- class DiffStatsReporter {
14
- constructor(options) {
15
- this.options = options;
16
- this.summary = new Map();
17
- this.failed = new Set();
18
- }
19
- async init(data = []) { }
20
- async failure(id) {
21
- this.failed.add(id);
22
- if (this.summary.has(id)) {
23
- this.summary.delete(id);
24
- }
25
- }
26
- async increment(id, data) {
27
- if (this.failed.has(id))
28
- return;
29
- if (!this.summary.has(id)) {
30
- this.summary.set(id, this.createSummary());
31
- }
32
- const current = this.summary.get(id);
33
- for (const item of data) {
34
- if (item.type === type_1.ECompareResultType.Missing)
35
- continue;
36
- const moduleType = item.name.startsWith("webpack/runtime")
37
- ? "runtime"
38
- : "normal";
39
- // handle modules
40
- if (item.type === type_1.ECompareResultType.OnlySource) {
41
- current[`${type_1.ECompilerType.Rspack}|${moduleType}|${"modules"}`]++;
42
- }
43
- else if (item.type === type_1.ECompareResultType.OnlyDist) {
44
- current[`${type_1.ECompilerType.Webpack}|${moduleType}|${"modules"}`]++;
45
- }
46
- else {
47
- current[`${"common"}|${moduleType}|${"modules"}`]++;
48
- }
49
- // handle lines
50
- current[`${type_1.ECompilerType.Rspack}|${moduleType}|${"lines"}`] +=
51
- item.lines?.source || 0;
52
- current[`${type_1.ECompilerType.Webpack}|${moduleType}|${"lines"}`] +=
53
- item.lines?.dist || 0;
54
- current[`${"common"}|${moduleType}|${"lines"}`] +=
55
- item.lines?.common || 0;
56
- // handle lines in common modules
57
- if (item.type === type_1.ECompareResultType.Same ||
58
- item.type === type_1.ECompareResultType.Different) {
59
- current[`${type_1.ECompilerType.Rspack}|${moduleType}|${"lines-in-common"}`] +=
60
- item.lines?.source || 0;
61
- current[`${type_1.ECompilerType.Webpack}|${moduleType}|${"lines-in-common"}`] += item.lines?.dist || 0;
62
- current[`${"common"}|${moduleType}|${"lines-in-common"}`] +=
63
- item.lines?.common || 0;
64
- }
65
- }
66
- }
67
- async output() {
68
- const chunks = [];
69
- for (const [id, summary] of this.summary.entries()) {
70
- chunks.push(this.stringifySummary(id, summary));
71
- }
72
- for (const id of this.failed.values()) {
73
- chunks.push(`### ${id}\n\n> Failed\n\n`);
74
- }
75
- const output = [
76
- ...(this.options.header || []),
77
- chunks.join("\n---\n"),
78
- ...(this.options.footer || [])
79
- ].join("\n\n");
80
- fs_extra_1.default.ensureFileSync(this.options.file);
81
- fs_extra_1.default.writeFileSync(this.options.file, output);
82
- }
83
- stringifySummary(id, summary) {
84
- let output = `### ${id}\n\n`;
85
- for (const moduleType of ["runtime", "normal"]) {
86
- const csv = [];
87
- csv.push(`${moduleType.charAt(0).toUpperCase() + moduleType.slice(1)} Modules,Rspack Only,Common,Webpack Only,Common Percent`);
88
- for (const dimen of [
89
- "modules",
90
- "lines",
91
- "lines-in-common"
92
- ]) {
93
- const counts = [
94
- type_1.ECompilerType.Rspack,
95
- "common",
96
- type_1.ECompilerType.Webpack
97
- ].map(i => summary[`${i}|${moduleType}|${dimen}`]);
98
- csv.push(`${dimen === "lines-in-common"
99
- ? "Lines(Common Modules)"
100
- : toFirstLetterUpperCase(dimen)},${counts.join(",")},${toPercent(counts[1] / (counts[0] + counts[1] + counts[2]))}`);
101
- }
102
- output += (0, csv_to_markdown_table_1.default)(csv.join("\n"), ",", true);
103
- output += "\n\n";
104
- }
105
- if (this.options.report && GITHUB_RUN_ID) {
106
- output += `> [View diff report](https://web-infra-dev.github.io/rspack-report-website/diff/${GITHUB_RUN_ID}/diff_${id}.html)`;
107
- output += "\n\n";
108
- }
109
- return output;
110
- }
111
- createSummary() {
112
- const result = {};
113
- for (const i of [
114
- type_1.ECompilerType.Rspack,
115
- type_1.ECompilerType.Webpack,
116
- "common"
117
- ]) {
118
- for (const j of ["runtime", "normal"]) {
119
- for (const k of [
120
- "modules",
121
- "lines",
122
- "lines-in-common"
123
- ]) {
124
- result[`${i}|${j}|${k}`] = 0;
125
- }
126
- }
127
- }
128
- return result;
129
- }
130
- }
131
- exports.DiffStatsReporter = DiffStatsReporter;
@@ -1,2 +0,0 @@
1
- export * from "./diff-html";
2
- export * from "./diff-stats";
@@ -1,18 +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("./diff-html"), exports);
18
- __exportStar(require("./diff-stats"), exports);