@rspack-canary/test-tools 1.6.0-canary-6cd722f4-20251022123039 → 1.6.0-canary-e28e40e9-20251022173516
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.
- package/dist/case/builtin.d.ts +3 -2
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +4 -1
- package/dist/case/common.d.ts +11 -10
- package/dist/case/common.js +2 -5
- package/dist/case/compiler.d.ts +9 -8
- package/dist/case/config.d.ts +6 -5
- package/dist/case/defaults.d.ts +5 -4
- package/dist/case/defaults.js +1 -1
- package/dist/case/error.d.ts +5 -5
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hook.d.ts +4 -3
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +1 -2
- package/dist/case/hot.d.ts +5 -4
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/index.d.ts +0 -1
- package/dist/case/index.js +1 -3
- package/dist/case/multi-compiler.d.ts +9 -8
- package/dist/case/runner.d.ts +5 -4
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/stats-api.d.ts +6 -5
- package/dist/case/stats-api.js +1 -2
- package/dist/case/stats-output.d.ts +3 -2
- package/dist/case/watch.d.ts +6 -6
- package/dist/case/watch.js +2 -1
- package/dist/compiler.d.ts +15 -17
- package/dist/compiler.js +4 -11
- package/dist/helper/legacy/checkArrayExpectation.js +1 -1
- package/dist/helper/read-config-file.d.ts +3 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/plugin/index.d.ts +0 -3
- package/dist/plugin/index.js +0 -3
- package/dist/runner/node/index.d.ts +9 -8
- package/dist/runner/node/index.js +3 -1
- package/dist/runner/web/index.d.ts +5 -5
- package/dist/test/context.d.ts +4 -4
- package/dist/test/context.js +5 -13
- package/dist/test/creator.d.ts +14 -14
- package/dist/test/creator.js +3 -4
- package/dist/type.d.ts +27 -40
- package/dist/type.js +1 -6
- package/package.json +4 -9
- package/dist/case/diff.d.ts +0 -19
- package/dist/case/diff.js +0 -274
- package/dist/compare/comparator.d.ts +0 -17
- package/dist/compare/comparator.js +0 -52
- package/dist/compare/compare.d.ts +0 -17
- package/dist/compare/compare.js +0 -178
- package/dist/compare/format-code.d.ts +0 -16
- package/dist/compare/format-code.js +0 -244
- package/dist/compare/index.d.ts +0 -5
- package/dist/compare/index.js +0 -21
- package/dist/compare/replace-module-argument.d.ts +0 -1
- package/dist/compare/replace-module-argument.js +0 -8
- package/dist/compare/replace-runtime-module-name.d.ts +0 -1
- package/dist/compare/replace-runtime-module-name.js +0 -71
- package/dist/plugin/rspack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/rspack-diff-config-plugin.js +0 -42
- package/dist/plugin/webpack-diff-config-plugin.d.ts +0 -7
- package/dist/plugin/webpack-diff-config-plugin.js +0 -41
- package/dist/plugin/webpack-module-placeholder-plugin.d.ts +0 -3
- package/dist/plugin/webpack-module-placeholder-plugin.js +0 -106
- package/template/diff.bundle.css +0 -1
- package/template/diff.bundle.js +0 -144
- package/template/diff.html +0 -14
- package/template/editor.worker.js +0 -1
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ITestReporter, TCompareModules } from "../type";
|
|
2
|
-
import type { IFormatCodeOptions } from "./format-code";
|
|
3
|
-
export interface IDiffComparatorOptions {
|
|
4
|
-
rspackDist: string;
|
|
5
|
-
webpackDist: string;
|
|
6
|
-
files: string[];
|
|
7
|
-
modules?: TCompareModules;
|
|
8
|
-
runtimeModules?: TCompareModules;
|
|
9
|
-
reporters: ITestReporter<unknown>[];
|
|
10
|
-
formatOptions?: IFormatCodeOptions;
|
|
11
|
-
bootstrap?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export declare class DiffComparator {
|
|
14
|
-
private options;
|
|
15
|
-
constructor(options: IDiffComparatorOptions);
|
|
16
|
-
compare(): Promise<void>;
|
|
17
|
-
}
|
|
@@ -1,52 +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.DiffComparator = void 0;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
9
|
-
const compare_1 = require("./compare");
|
|
10
|
-
const replace_runtime_module_name_1 = require("./replace-runtime-module-name");
|
|
11
|
-
class DiffComparator {
|
|
12
|
-
constructor(options) {
|
|
13
|
-
this.options = options;
|
|
14
|
-
}
|
|
15
|
-
async compare() {
|
|
16
|
-
for (const file of this.options.files) {
|
|
17
|
-
try {
|
|
18
|
-
const result = (0, compare_1.compareFile)(node_path_1.default.join(this.options.rspackDist, file), node_path_1.default.join(this.options.webpackDist, file), {
|
|
19
|
-
modules: this.options.modules,
|
|
20
|
-
runtimeModules: this.options.runtimeModules,
|
|
21
|
-
format: (0, deepmerge_1.default)({
|
|
22
|
-
replacements: {},
|
|
23
|
-
ignorePropertyQuotationMark: true,
|
|
24
|
-
ignoreModuleId: true,
|
|
25
|
-
ignoreModuleArguments: true,
|
|
26
|
-
ignoreBlockOnlyStatement: true,
|
|
27
|
-
ignoreIfCertainCondition: true,
|
|
28
|
-
ignoreSwcHelpersPath: true,
|
|
29
|
-
ignoreObjectPropertySequence: true,
|
|
30
|
-
ignoreCssFilePath: true
|
|
31
|
-
}, this.options.formatOptions || {}),
|
|
32
|
-
renameModule: replace_runtime_module_name_1.replaceRuntimeModuleName,
|
|
33
|
-
bootstrap: this.options.bootstrap
|
|
34
|
-
});
|
|
35
|
-
for (const reporter of this.options.reporters) {
|
|
36
|
-
reporter.increment(file, result.modules.modules || []);
|
|
37
|
-
}
|
|
38
|
-
for (const reporter of this.options.reporters) {
|
|
39
|
-
reporter.increment(file, result.modules.runtimeModules || []);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
catch (e) {
|
|
43
|
-
console.error(e);
|
|
44
|
-
for (const reporter of this.options.reporters) {
|
|
45
|
-
reporter.failure(file);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
await Promise.all(this.options.reporters.map(r => r.output()));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.DiffComparator = DiffComparator;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type TCompareModules, type TCompareResult, type TFileCompareResult, type TModuleCompareResult } from "../type";
|
|
2
|
-
import { type IFormatCodeOptions } from "./format-code";
|
|
3
|
-
declare global {
|
|
4
|
-
var updateSnapshot: boolean;
|
|
5
|
-
}
|
|
6
|
-
export interface ICompareOptions {
|
|
7
|
-
modules?: TCompareModules;
|
|
8
|
-
runtimeModules?: TCompareModules;
|
|
9
|
-
format: IFormatCodeOptions;
|
|
10
|
-
renameModule?: (name: string) => string;
|
|
11
|
-
bootstrap?: boolean;
|
|
12
|
-
detail?: boolean;
|
|
13
|
-
snapshot?: string;
|
|
14
|
-
}
|
|
15
|
-
export declare function compareFile(sourceFile: string, distFile: string, compareOptions: ICompareOptions): TFileCompareResult;
|
|
16
|
-
export declare function compareModules(modules: string[], sourceModules: Record<string, string>, distModules: Record<string, string>, compareOptions: ICompareOptions): TModuleCompareResult[];
|
|
17
|
-
export declare function compareContent(sourceContent: string | false, distContent: string | false, compareOptions: ICompareOptions): TCompareResult;
|
package/dist/compare/compare.js
DELETED
|
@@ -1,178 +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
|
-
function compareFile(sourceFile, distFile, compareOptions) {
|
|
17
|
-
const result = {
|
|
18
|
-
type: type_1.ECompareResultType.Same,
|
|
19
|
-
file: {
|
|
20
|
-
source: sourceFile,
|
|
21
|
-
dist: distFile
|
|
22
|
-
},
|
|
23
|
-
modules: {}
|
|
24
|
-
};
|
|
25
|
-
const sourceExists = fs_extra_1.default.existsSync(sourceFile);
|
|
26
|
-
const distExists = compareOptions.snapshot
|
|
27
|
-
? fs_extra_1.default.existsSync(compareOptions.snapshot)
|
|
28
|
-
: fs_extra_1.default.existsSync(distFile);
|
|
29
|
-
if (!sourceExists && !distExists) {
|
|
30
|
-
result.type = type_1.ECompareResultType.Missing;
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
if (!sourceExists && distExists) {
|
|
34
|
-
result.type = type_1.ECompareResultType.OnlyDist;
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
if (sourceExists && !distExists) {
|
|
38
|
-
result.type = type_1.ECompareResultType.OnlySource;
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
function formatModules(modules) {
|
|
42
|
-
const res = {};
|
|
43
|
-
for (const [name, content] of Object.entries(modules)) {
|
|
44
|
-
const renamed = name.replaceAll(node_path_1.default.win32.sep, node_path_1.default.posix.sep);
|
|
45
|
-
if (!renamed.includes("node_modules/css-loader/dist")) {
|
|
46
|
-
res[renamed] = (0, format_code_1.formatCode)(renamed, content, compareOptions.format);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return res;
|
|
50
|
-
}
|
|
51
|
-
const sourceContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default
|
|
52
|
-
.readFileSync(sourceFile, "utf-8")
|
|
53
|
-
.replaceAll(__ROOT_PATH__, "__WORKSPACE__"));
|
|
54
|
-
const sourceModules = (0, helper_1.parseModules)(sourceContent, {
|
|
55
|
-
bootstrap: compareOptions.bootstrap,
|
|
56
|
-
renameModule: compareOptions.renameModule
|
|
57
|
-
});
|
|
58
|
-
sourceModules.modules = formatModules(sourceModules.modules);
|
|
59
|
-
sourceModules.runtimeModules = formatModules(sourceModules.runtimeModules);
|
|
60
|
-
let distModules = {
|
|
61
|
-
modules: {},
|
|
62
|
-
runtimeModules: {}
|
|
63
|
-
};
|
|
64
|
-
if (!global.updateSnapshot &&
|
|
65
|
-
compareOptions.snapshot &&
|
|
66
|
-
fs_extra_1.default.existsSync(compareOptions.snapshot)) {
|
|
67
|
-
distModules = JSON.parse(fs_extra_1.default.readFileSync(compareOptions.snapshot, "utf-8"));
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
const distContent = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(fs_extra_1.default
|
|
71
|
-
.readFileSync(distFile, "utf-8")
|
|
72
|
-
.replaceAll(__ROOT_PATH__, "__WORKSPACE__"));
|
|
73
|
-
distModules = (0, helper_1.parseModules)(distContent, {
|
|
74
|
-
bootstrap: compareOptions.bootstrap,
|
|
75
|
-
renameModule: compareOptions.renameModule
|
|
76
|
-
});
|
|
77
|
-
distModules.modules = formatModules(distModules.modules);
|
|
78
|
-
distModules.runtimeModules = formatModules(distModules.runtimeModules);
|
|
79
|
-
if (compareOptions.snapshot) {
|
|
80
|
-
fs_extra_1.default.ensureDirSync(node_path_1.default.dirname(compareOptions.snapshot));
|
|
81
|
-
fs_extra_1.default.writeFileSync(compareOptions.snapshot, JSON.stringify(distModules, null, 2));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
result.type = type_1.ECompareResultType.Different;
|
|
85
|
-
for (const type of ["modules", "runtimeModules"]) {
|
|
86
|
-
const t = type;
|
|
87
|
-
let moduleList = [];
|
|
88
|
-
if (compareOptions[t] === true) {
|
|
89
|
-
moduleList = [
|
|
90
|
-
...Object.keys(sourceModules[t]),
|
|
91
|
-
...Object.keys(distModules[t])
|
|
92
|
-
].filter((i, idx, arr) => arr.indexOf(i) === idx);
|
|
93
|
-
}
|
|
94
|
-
else if (Array.isArray(compareOptions[t])) {
|
|
95
|
-
moduleList = compareOptions[t];
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
result.modules[t] = compareModules(moduleList, sourceModules[t], distModules[t], compareOptions);
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
function compareModules(modules, sourceModules, distModules, compareOptions) {
|
|
105
|
-
const compareResults = [];
|
|
106
|
-
for (const name of modules) {
|
|
107
|
-
const renamed = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(name).replaceAll(node_path_1.default.win32.sep, node_path_1.default.posix.sep);
|
|
108
|
-
const sourceContent = sourceModules[renamed];
|
|
109
|
-
const distContent = distModules[renamed];
|
|
110
|
-
compareResults.push({
|
|
111
|
-
...compareContent(sourceContent, distContent, compareOptions),
|
|
112
|
-
name
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return compareResults;
|
|
116
|
-
}
|
|
117
|
-
function compareContent(sourceContent, distContent, compareOptions) {
|
|
118
|
-
if (sourceContent) {
|
|
119
|
-
if (distContent) {
|
|
120
|
-
if (sourceContent === distContent) {
|
|
121
|
-
const lines = sourceContent.trim().split("\n").length;
|
|
122
|
-
return {
|
|
123
|
-
type: type_1.ECompareResultType.Same,
|
|
124
|
-
source: sourceContent,
|
|
125
|
-
dist: distContent,
|
|
126
|
-
lines: {
|
|
127
|
-
source: 0,
|
|
128
|
-
common: lines,
|
|
129
|
-
dist: 0
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
const difference = compareOptions.detail
|
|
134
|
-
? (0, jest_diff_1.diffStringsUnified)(sourceContent.trim(), distContent.trim())
|
|
135
|
-
: undefined;
|
|
136
|
-
const diffLines = (0, jest_diff_1.diffLinesRaw)(sourceContent.trim().split("\n"), distContent.trim().split("\n"));
|
|
137
|
-
return {
|
|
138
|
-
type: type_1.ECompareResultType.Different,
|
|
139
|
-
detail: difference,
|
|
140
|
-
source: sourceContent,
|
|
141
|
-
dist: distContent,
|
|
142
|
-
lines: {
|
|
143
|
-
source: diffLines.filter(l => l[0] < 0).length,
|
|
144
|
-
common: diffLines.filter(l => l[0] === 0).length,
|
|
145
|
-
dist: diffLines.filter(l => l[0] > 0).length
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
return {
|
|
150
|
-
type: type_1.ECompareResultType.OnlySource,
|
|
151
|
-
source: sourceContent,
|
|
152
|
-
lines: {
|
|
153
|
-
source: sourceContent.trim().split("\n").length,
|
|
154
|
-
common: 0,
|
|
155
|
-
dist: 0
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
if (distContent) {
|
|
160
|
-
return {
|
|
161
|
-
type: type_1.ECompareResultType.OnlyDist,
|
|
162
|
-
dist: distContent,
|
|
163
|
-
lines: {
|
|
164
|
-
source: 0,
|
|
165
|
-
common: 0,
|
|
166
|
-
dist: distContent.trim().split("\n").length
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
return {
|
|
171
|
-
type: type_1.ECompareResultType.Missing,
|
|
172
|
-
lines: {
|
|
173
|
-
source: 0,
|
|
174
|
-
common: 0,
|
|
175
|
-
dist: 0
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
}
|
|
@@ -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 | ((substring: string, ...args: any[]) => string);
|
|
15
|
-
}
|
|
16
|
-
export declare function formatCode(name: string, raw: string, options: IFormatCodeOptions): string;
|
|
@@ -1,244 +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
|
-
if (typeof to === "string") {
|
|
225
|
-
result = result.replaceAll(from, to);
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
result = result.replaceAll(from, to);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
// result of generate() is not stable with comments sometimes
|
|
233
|
-
// so do it again
|
|
234
|
-
return (0, generator_1.default)((0, parser_1.parse)(result, {
|
|
235
|
-
sourceType: "unambiguous"
|
|
236
|
-
}), {
|
|
237
|
-
comments: false,
|
|
238
|
-
compact: false,
|
|
239
|
-
concise: false,
|
|
240
|
-
jsescOption: {
|
|
241
|
-
quotes: "double"
|
|
242
|
-
}
|
|
243
|
-
}).code.trim();
|
|
244
|
-
}
|
package/dist/compare/index.d.ts
DELETED
package/dist/compare/index.js
DELETED
|
@@ -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,7 +0,0 @@
|
|
|
1
|
-
import type { Compiler, RspackOptionsNormalized, RspackPluginInstance } from "@rspack/core";
|
|
2
|
-
export declare class RspackDiffConfigPlugin implements RspackPluginInstance {
|
|
3
|
-
private modifier?;
|
|
4
|
-
name: string;
|
|
5
|
-
constructor(modifier?: ((options: RspackOptionsNormalized) => RspackOptionsNormalized) | undefined);
|
|
6
|
-
apply(compiler: Compiler): void;
|
|
7
|
-
}
|