@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.
- package/README.md +1 -1
- package/dist/case/builtin.d.ts +3 -0
- package/dist/case/builtin.js +152 -14
- package/dist/case/cache.d.ts +2 -2
- package/dist/case/cache.js +214 -12
- package/dist/case/common.d.ts +11 -0
- package/dist/case/common.js +249 -0
- package/dist/case/compiler.d.ts +17 -4
- package/dist/case/compiler.js +149 -12
- package/dist/case/config.d.ts +7 -2
- package/dist/case/config.js +106 -18
- package/dist/case/defaults.d.ts +13 -4
- package/dist/case/defaults.js +73 -18
- package/dist/case/diagnostic.d.ts +6 -0
- package/dist/case/diagnostic.js +121 -14
- package/dist/case/error.d.ts +15 -4
- package/dist/case/error.js +137 -12
- package/dist/case/esm-output.d.ts +1 -0
- package/dist/case/esm-output.js +117 -0
- package/dist/case/example.d.ts +1 -0
- package/dist/case/example.js +57 -0
- package/dist/case/hash.d.ts +2 -2
- package/dist/case/hash.js +72 -9
- package/dist/case/hook.d.ts +36 -4
- package/dist/case/hook.js +209 -20
- package/dist/case/hot-step.d.ts +2 -2
- package/dist/case/hot-step.js +309 -13
- package/dist/case/hot.d.ts +11 -2
- package/dist/case/hot.js +217 -12
- package/dist/case/incremental.d.ts +2 -2
- package/dist/case/incremental.js +24 -45
- package/dist/case/index.d.ts +31 -20
- package/dist/case/index.js +50 -34
- package/dist/case/multi-compiler.d.ts +19 -0
- package/dist/case/multi-compiler.js +97 -0
- package/dist/case/{nativeWatcher.js → native-watcher.js} +11 -23
- package/dist/case/normal.d.ts +3 -0
- package/dist/case/normal.js +202 -18
- package/dist/case/runner.d.ts +19 -0
- package/dist/case/runner.js +113 -0
- package/dist/case/serial.d.ts +2 -2
- package/dist/case/serial.js +10 -14
- package/dist/case/stats-api.d.ts +8 -3
- package/dist/case/stats-api.js +69 -10
- package/dist/case/stats-output.d.ts +11 -0
- package/dist/case/stats-output.js +199 -8
- package/dist/case/treeshaking.js +34 -7
- package/dist/case/watch.d.ts +27 -0
- package/dist/case/watch.js +318 -22
- package/dist/compiler.d.ts +16 -16
- package/dist/compiler.js +120 -15
- package/dist/helper/directory.d.ts +1 -1
- package/dist/helper/directory.js +6 -2
- package/dist/helper/disable-iconv-lite-warning.d.ts +1 -0
- package/dist/helper/disable-iconv-lite-warning.js +12 -0
- package/dist/helper/expect/error.js +1 -1
- package/dist/helper/expect/placeholder.js +7 -7
- package/dist/helper/expect/to-match-file-snapshot.d.ts +1 -2
- package/dist/helper/expect/to-match-file-snapshot.js +3 -3
- package/dist/helper/hot-update/loader.d.ts +2 -1
- package/dist/helper/hot-update/loader.js +5 -30
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +14 -13
- package/dist/helper/index.d.ts +2 -1
- package/dist/helper/index.js +2 -1
- package/dist/helper/is.d.ts +2 -0
- package/dist/helper/is.js +15 -0
- package/dist/helper/legacy/LogTestPlugin.d.ts +6 -0
- package/dist/helper/legacy/LogTestPlugin.js +35 -0
- package/dist/helper/legacy/asModule.js +0 -2
- package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -1
- package/dist/helper/legacy/checkArrayExpectation.js +8 -8
- package/dist/helper/legacy/createFakeWorker.d.ts +2 -2
- package/dist/helper/legacy/createFakeWorker.js +44 -20
- package/dist/helper/legacy/createLazyTestEnv.d.ts +3 -2
- package/dist/helper/legacy/createLazyTestEnv.js +3 -3
- package/dist/helper/legacy/deprecationTracking.d.ts +1 -0
- package/dist/helper/legacy/deprecationTracking.js +41 -0
- package/dist/helper/legacy/expectSource.d.ts +10 -0
- package/dist/helper/legacy/expectSource.js +23 -0
- package/dist/helper/legacy/findOutputFiles.d.ts +6 -0
- package/dist/helper/legacy/findOutputFiles.js +14 -0
- package/dist/helper/legacy/regexEscape.d.ts +2 -0
- package/dist/helper/legacy/regexEscape.js +5 -0
- package/dist/helper/legacy/supportDefaultAssignment.js +13 -0
- package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
- package/dist/helper/legacy/supportsTextDecoder.js +9 -0
- package/dist/helper/legacy/supportsUsing.d.ts +2 -0
- package/dist/helper/legacy/supportsUsing.js +26 -0
- package/dist/helper/legacy/urlToRelativePath.js +5 -2
- package/dist/helper/read-config-file.d.ts +3 -2
- package/dist/helper/read-config-file.js +12 -2
- package/dist/helper/setup-env.js +26 -4
- package/dist/helper/setup-expect.js +2 -2
- package/dist/helper/setup-wasm.js +2 -2
- package/dist/helper/stringify-config.d.ts +2 -0
- package/dist/helper/stringify-config.js +43 -0
- package/dist/helper/util/checkStats.d.ts +0 -1
- package/dist/helper/util/checkStats.js +0 -18
- package/dist/helper/util/expectWarningFactory.js +2 -4
- package/dist/index.d.ts +0 -4
- package/dist/index.js +1 -4
- package/dist/plugin/index.d.ts +0 -3
- package/dist/plugin/index.js +0 -3
- package/dist/plugin/lazy-compilation-test-plugin.js +4 -4
- package/dist/runner/index.d.ts +2 -9
- package/dist/runner/index.js +2 -9
- package/dist/runner/node/index.d.ts +41 -0
- package/dist/runner/node/index.js +450 -0
- package/dist/runner/web/index.d.ts +30 -0
- package/dist/runner/web/index.js +343 -0
- package/dist/test/context.d.ts +15 -18
- package/dist/test/context.js +52 -57
- package/dist/test/creator.d.ts +20 -19
- package/dist/test/creator.js +69 -57
- package/dist/test/debug.d.ts +15 -0
- package/dist/test/debug.js +205 -0
- package/dist/test/tester.d.ts +1 -0
- package/dist/test/tester.js +44 -6
- package/dist/type.d.ts +94 -64
- package/dist/type.js +8 -12
- package/package.json +22 -61
- package/rstest.d.ts +24 -0
- package/dist/case/diff.d.ts +0 -3
- package/dist/case/diff.js +0 -126
- 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 -175
- package/dist/compare/format-code.d.ts +0 -16
- package/dist/compare/format-code.js +0 -239
- 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/helper/legacy/FakeDocument.d.ts +0 -54
- package/dist/helper/legacy/FakeDocument.js +0 -278
- package/dist/helper/legacy/createLogger.d.ts +0 -23
- package/dist/helper/legacy/createLogger.js +0 -20
- package/dist/helper/legacy/supportsImportFn.d.ts +0 -1
- package/dist/helper/legacy/supportsImportFn.js +0 -15
- package/dist/helper/legacy/supportsWorker.js +0 -17
- package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
- package/dist/helper/legacy/walkCssTokens.js +0 -761
- package/dist/helper/legacy/warmup-webpack.d.ts +0 -1
- package/dist/helper/legacy/warmup-webpack.js +0 -26
- package/dist/helper/loaders/hot-update.d.ts +0 -1
- package/dist/helper/loaders/hot-update.js +0 -40
- package/dist/helper/plugins/hot-update.d.ts +0 -7
- package/dist/helper/plugins/hot-update.js +0 -40
- package/dist/helper/plugins/index.d.ts +0 -1
- package/dist/helper/plugins/index.js +0 -17
- package/dist/helper/util/currentWatchStep.d.ts +0 -1
- package/dist/helper/util/currentWatchStep.js +0 -2
- package/dist/helper/util/identifier.d.ts +0 -76
- package/dist/helper/util/identifier.js +0 -339
- package/dist/helper/util/replaceMitteDiagnostic.d.ts +0 -2
- package/dist/helper/util/replaceMitteDiagnostic.js +0 -17
- 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/dist/processor/basic.d.ts +0 -24
- package/dist/processor/basic.js +0 -146
- package/dist/processor/builtin.d.ts +0 -9
- package/dist/processor/builtin.js +0 -171
- package/dist/processor/cache.d.ts +0 -20
- package/dist/processor/cache.js +0 -128
- package/dist/processor/config.d.ts +0 -11
- package/dist/processor/config.js +0 -81
- package/dist/processor/defaults.d.ts +0 -30
- package/dist/processor/defaults.js +0 -72
- package/dist/processor/diagnostic.d.ts +0 -15
- package/dist/processor/diagnostic.js +0 -102
- package/dist/processor/diff.d.ts +0 -30
- package/dist/processor/diff.js +0 -140
- package/dist/processor/error.d.ts +0 -23
- package/dist/processor/error.js +0 -95
- package/dist/processor/hash.d.ts +0 -10
- package/dist/processor/hash.js +0 -63
- package/dist/processor/hook.d.ts +0 -44
- package/dist/processor/hook.js +0 -204
- package/dist/processor/hot-incremental.d.ts +0 -14
- package/dist/processor/hot-incremental.js +0 -43
- package/dist/processor/hot-step.d.ts +0 -18
- package/dist/processor/hot-step.js +0 -304
- package/dist/processor/hot.d.ts +0 -17
- package/dist/processor/hot.js +0 -140
- package/dist/processor/index.d.ts +0 -20
- package/dist/processor/index.js +0 -36
- package/dist/processor/multi.d.ts +0 -17
- package/dist/processor/multi.js +0 -73
- package/dist/processor/normal.d.ts +0 -12
- package/dist/processor/normal.js +0 -150
- package/dist/processor/simple.d.ts +0 -23
- package/dist/processor/simple.js +0 -49
- package/dist/processor/snapshot.d.ts +0 -12
- package/dist/processor/snapshot.js +0 -66
- package/dist/processor/stats-api.d.ts +0 -18
- package/dist/processor/stats-api.js +0 -48
- package/dist/processor/stats.d.ts +0 -18
- package/dist/processor/stats.js +0 -206
- package/dist/processor/treeshaking.d.ts +0 -10
- package/dist/processor/treeshaking.js +0 -33
- package/dist/processor/watch.d.ts +0 -30
- package/dist/processor/watch.js +0 -241
- package/dist/reporter/diff-html.d.ts +0 -15
- package/dist/reporter/diff-html.js +0 -69
- package/dist/reporter/diff-stats.d.ts +0 -24
- package/dist/reporter/diff-stats.js +0 -131
- package/dist/reporter/index.d.ts +0 -2
- package/dist/reporter/index.js +0 -18
- package/dist/runner/basic.d.ts +0 -10
- package/dist/runner/basic.js +0 -63
- package/dist/runner/cache.d.ts +0 -5
- package/dist/runner/cache.js +0 -90
- package/dist/runner/hot-step.d.ts +0 -5
- package/dist/runner/hot-step.js +0 -87
- package/dist/runner/hot.d.ts +0 -5
- package/dist/runner/hot.js +0 -83
- package/dist/runner/multiple.d.ts +0 -11
- package/dist/runner/multiple.js +0 -38
- package/dist/runner/normal.d.ts +0 -5
- package/dist/runner/normal.js +0 -20
- package/dist/runner/runner/basic.d.ts +0 -30
- package/dist/runner/runner/basic.js +0 -107
- package/dist/runner/runner/cjs.d.ts +0 -14
- package/dist/runner/runner/cjs.js +0 -151
- package/dist/runner/runner/esm.d.ts +0 -7
- package/dist/runner/runner/esm.js +0 -125
- package/dist/runner/runner/index.d.ts +0 -8
- package/dist/runner/runner/index.js +0 -24
- package/dist/runner/runner/normal.d.ts +0 -9
- package/dist/runner/runner/normal.js +0 -23
- package/dist/runner/runner/watch.d.ts +0 -16
- package/dist/runner/runner/watch.js +0 -27
- package/dist/runner/runner/web/fake.d.ts +0 -18
- package/dist/runner/runner/web/fake.js +0 -143
- package/dist/runner/runner/web/jsdom.d.ts +0 -26
- package/dist/runner/runner/web/jsdom.js +0 -219
- package/dist/runner/runner/web.d.ts +0 -15
- package/dist/runner/runner/web.js +0 -32
- package/dist/runner/type.d.ts +0 -42
- package/dist/runner/type.js +0 -9
- package/dist/runner/watch.d.ts +0 -7
- package/dist/runner/watch.js +0 -60
- package/dist/test/simple.d.ts +0 -5
- package/dist/test/simple.js +0 -43
- package/jest.d.ts +0 -25
- 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
- /package/dist/case/{nativeWatcher.d.ts → native-watcher.d.ts} +0 -0
- /package/dist/helper/legacy/{supportsWorker.d.ts → supportDefaultAssignment.d.ts} +0 -0
package/dist/compare/compare.js
DELETED
|
@@ -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
|
-
}
|
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,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
|
-
}
|