@rspack-debug/test-tools 1.3.14
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/LICENSE +22 -0
- package/README.md +17 -0
- package/dist/case/builtin.d.ts +1 -0
- package/dist/case/builtin.js +39 -0
- package/dist/case/cache.d.ts +2 -0
- package/dist/case/cache.js +34 -0
- package/dist/case/compiler.d.ts +6 -0
- package/dist/case/compiler.js +17 -0
- package/dist/case/config.d.ts +3 -0
- package/dist/case/config.js +39 -0
- package/dist/case/defaults.d.ts +6 -0
- package/dist/case/defaults.js +39 -0
- package/dist/case/diagnostic.d.ts +1 -0
- package/dist/case/diagnostic.js +29 -0
- package/dist/case/diff.d.ts +3 -0
- package/dist/case/diff.js +126 -0
- package/dist/case/error.d.ts +6 -0
- package/dist/case/error.js +21 -0
- package/dist/case/hash.d.ts +3 -0
- package/dist/case/hash.js +30 -0
- package/dist/case/hook.d.ts +6 -0
- package/dist/case/hook.js +35 -0
- package/dist/case/hot-step.d.ts +2 -0
- package/dist/case/hot-step.js +32 -0
- package/dist/case/hot.d.ts +2 -0
- package/dist/case/hot.js +32 -0
- package/dist/case/index.d.ts +19 -0
- package/dist/case/index.js +35 -0
- package/dist/case/new-incremental.d.ts +6 -0
- package/dist/case/new-incremental.js +100 -0
- package/dist/case/normal.d.ts +1 -0
- package/dist/case/normal.js +29 -0
- package/dist/case/serial.d.ts +3 -0
- package/dist/case/serial.js +34 -0
- package/dist/case/stats-api.d.ts +6 -0
- package/dist/case/stats-api.js +21 -0
- package/dist/case/stats-output.d.ts +1 -0
- package/dist/case/stats-output.js +22 -0
- package/dist/case/treeshaking.d.ts +1 -0
- package/dist/case/treeshaking.js +23 -0
- package/dist/case/watch.d.ts +1 -0
- package/dist/case/watch.js +53 -0
- package/dist/compare/comparator.d.ts +17 -0
- package/dist/compare/comparator.js +52 -0
- package/dist/compare/compare.d.ts +17 -0
- package/dist/compare/compare.js +175 -0
- package/dist/compare/format-code.d.ts +16 -0
- package/dist/compare/format-code.js +239 -0
- package/dist/compare/index.d.ts +5 -0
- package/dist/compare/index.js +21 -0
- package/dist/compare/replace-module-argument.d.ts +1 -0
- package/dist/compare/replace-module-argument.js +8 -0
- package/dist/compare/replace-runtime-module-name.d.ts +1 -0
- package/dist/compare/replace-runtime-module-name.js +71 -0
- package/dist/compiler.d.ts +28 -0
- package/dist/compiler.js +111 -0
- package/dist/helper/directory.d.ts +12 -0
- package/dist/helper/directory.js +81 -0
- package/dist/helper/expect/diff.d.ts +3 -0
- package/dist/helper/expect/diff.js +21 -0
- package/dist/helper/expect/error.d.ts +5 -0
- package/dist/helper/expect/error.js +51 -0
- package/dist/helper/expect/placeholder.d.ts +1 -0
- package/dist/helper/expect/placeholder.js +41 -0
- package/dist/helper/expect/rspack.d.ts +3 -0
- package/dist/helper/expect/rspack.js +14 -0
- package/dist/helper/expect/to-be-typeof.d.ts +4 -0
- package/dist/helper/expect/to-be-typeof.js +12 -0
- package/dist/helper/expect/to-end-with.d.ts +4 -0
- package/dist/helper/expect/to-end-with.js +11 -0
- package/dist/helper/expect/to-match-file-snapshot.d.ts +23 -0
- package/dist/helper/expect/to-match-file-snapshot.js +108 -0
- package/dist/helper/hot-update/index.d.ts +1 -0
- package/dist/helper/hot-update/index.js +5 -0
- package/dist/helper/hot-update/loader.d.ts +1 -0
- package/dist/helper/hot-update/loader.js +32 -0
- package/dist/helper/hot-update/plugin.d.ts +17 -0
- package/dist/helper/hot-update/plugin.js +133 -0
- package/dist/helper/index.d.ts +7 -0
- package/dist/helper/index.js +23 -0
- package/dist/helper/legacy/EventSourceForNode.d.ts +8 -0
- package/dist/helper/legacy/EventSourceForNode.js +40 -0
- package/dist/helper/legacy/FakeDocument.d.ts +54 -0
- package/dist/helper/legacy/FakeDocument.js +278 -0
- package/dist/helper/legacy/asModule.d.ts +3 -0
- package/dist/helper/legacy/asModule.js +25 -0
- package/dist/helper/legacy/captureStdio.d.ts +8 -0
- package/dist/helper/legacy/captureStdio.js +32 -0
- package/dist/helper/legacy/checkArrayExpectation.d.ts +2 -0
- package/dist/helper/legacy/checkArrayExpectation.js +111 -0
- package/dist/helper/legacy/copyDiff.d.ts +2 -0
- package/dist/helper/legacy/copyDiff.js +33 -0
- package/dist/helper/legacy/createFakeWorker.d.ts +13 -0
- package/dist/helper/legacy/createFakeWorker.js +80 -0
- package/dist/helper/legacy/createLazyTestEnv.d.ts +10 -0
- package/dist/helper/legacy/createLazyTestEnv.js +116 -0
- package/dist/helper/legacy/createLogger.d.ts +23 -0
- package/dist/helper/legacy/createLogger.js +20 -0
- package/dist/helper/legacy/currentScript.d.ts +6 -0
- package/dist/helper/legacy/currentScript.js +8 -0
- package/dist/helper/legacy/fakeSystem.d.ts +9 -0
- package/dist/helper/legacy/fakeSystem.js +124 -0
- package/dist/helper/legacy/parseResource.d.ts +6 -0
- package/dist/helper/legacy/parseResource.js +15 -0
- package/dist/helper/legacy/supportsImportFn.d.ts +1 -0
- package/dist/helper/legacy/supportsImportFn.js +15 -0
- package/dist/helper/legacy/supportsWorker.d.ts +2 -0
- package/dist/helper/legacy/supportsWorker.js +17 -0
- package/dist/helper/legacy/urlToRelativePath.d.ts +2 -0
- package/dist/helper/legacy/urlToRelativePath.js +7 -0
- package/dist/helper/legacy/walkCssTokens.d.ts +40 -0
- package/dist/helper/legacy/walkCssTokens.js +761 -0
- package/dist/helper/legacy/warmup-webpack.d.ts +1 -0
- package/dist/helper/legacy/warmup-webpack.js +26 -0
- package/dist/helper/loaders/hot-update.d.ts +1 -0
- package/dist/helper/loaders/hot-update.js +40 -0
- package/dist/helper/parse-modules.d.ts +7 -0
- package/dist/helper/parse-modules.js +73 -0
- package/dist/helper/plugins/hot-update.d.ts +7 -0
- package/dist/helper/plugins/hot-update.js +40 -0
- package/dist/helper/plugins/index.d.ts +1 -0
- package/dist/helper/plugins/index.js +17 -0
- package/dist/helper/read-config-file.d.ts +2 -0
- package/dist/helper/read-config-file.js +13 -0
- package/dist/helper/serializers.d.ts +2 -0
- package/dist/helper/serializers.js +52 -0
- package/dist/helper/setup-env.d.ts +1 -0
- package/dist/helper/setup-env.js +80 -0
- package/dist/helper/setup-expect.d.ts +1 -0
- package/dist/helper/setup-expect.js +16 -0
- package/dist/helper/update-snapshot.d.ts +1 -0
- package/dist/helper/update-snapshot.js +6 -0
- package/dist/helper/util/checkSourceMap.d.ts +1 -0
- package/dist/helper/util/checkSourceMap.js +96 -0
- package/dist/helper/util/checkStats.d.ts +2 -0
- package/dist/helper/util/checkStats.js +43 -0
- package/dist/helper/util/currentWatchStep.d.ts +1 -0
- package/dist/helper/util/currentWatchStep.js +2 -0
- package/dist/helper/util/expectWarningFactory.d.ts +2 -0
- package/dist/helper/util/expectWarningFactory.js +21 -0
- package/dist/helper/util/filterUtil.d.ts +8 -0
- package/dist/helper/util/filterUtil.js +50 -0
- package/dist/helper/util/identifier.d.ts +76 -0
- package/dist/helper/util/identifier.js +339 -0
- package/dist/helper/util/replaceMitteDiagnostic.d.ts +2 -0
- package/dist/helper/util/replaceMitteDiagnostic.js +17 -0
- package/dist/helper/win.d.ts +1 -0
- package/dist/helper/win.js +10 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +28 -0
- package/dist/plugin/index.d.ts +4 -0
- package/dist/plugin/index.js +20 -0
- package/dist/plugin/lazy-compilation-test-plugin.d.ts +4 -0
- package/dist/plugin/lazy-compilation-test-plugin.js +67 -0
- package/dist/plugin/rspack-diff-config-plugin.d.ts +7 -0
- package/dist/plugin/rspack-diff-config-plugin.js +42 -0
- package/dist/plugin/webpack-diff-config-plugin.d.ts +7 -0
- package/dist/plugin/webpack-diff-config-plugin.js +41 -0
- package/dist/plugin/webpack-module-placeholder-plugin.d.ts +3 -0
- package/dist/plugin/webpack-module-placeholder-plugin.js +107 -0
- package/dist/processor/basic.d.ts +24 -0
- package/dist/processor/basic.js +146 -0
- package/dist/processor/builtin.d.ts +9 -0
- package/dist/processor/builtin.js +171 -0
- package/dist/processor/cache.d.ts +20 -0
- package/dist/processor/cache.js +127 -0
- package/dist/processor/config.d.ts +11 -0
- package/dist/processor/config.js +81 -0
- package/dist/processor/defaults.d.ts +30 -0
- package/dist/processor/defaults.js +72 -0
- package/dist/processor/diagnostic.d.ts +15 -0
- package/dist/processor/diagnostic.js +102 -0
- package/dist/processor/diff.d.ts +30 -0
- package/dist/processor/diff.js +140 -0
- package/dist/processor/error.d.ts +23 -0
- package/dist/processor/error.js +95 -0
- package/dist/processor/hash.d.ts +10 -0
- package/dist/processor/hash.js +63 -0
- package/dist/processor/hook.d.ts +44 -0
- package/dist/processor/hook.js +204 -0
- package/dist/processor/hot-new-incremental.d.ts +14 -0
- package/dist/processor/hot-new-incremental.js +43 -0
- package/dist/processor/hot-step.d.ts +18 -0
- package/dist/processor/hot-step.js +299 -0
- package/dist/processor/hot.d.ts +17 -0
- package/dist/processor/hot.js +138 -0
- package/dist/processor/index.d.ts +20 -0
- package/dist/processor/index.js +36 -0
- package/dist/processor/multi.d.ts +17 -0
- package/dist/processor/multi.js +73 -0
- package/dist/processor/normal.d.ts +12 -0
- package/dist/processor/normal.js +150 -0
- package/dist/processor/simple.d.ts +23 -0
- package/dist/processor/simple.js +49 -0
- package/dist/processor/snapshot.d.ts +12 -0
- package/dist/processor/snapshot.js +62 -0
- package/dist/processor/stats-api.d.ts +18 -0
- package/dist/processor/stats-api.js +48 -0
- package/dist/processor/stats.d.ts +18 -0
- package/dist/processor/stats.js +206 -0
- package/dist/processor/treeshaking.d.ts +10 -0
- package/dist/processor/treeshaking.js +33 -0
- package/dist/processor/watch.d.ts +29 -0
- package/dist/processor/watch.js +234 -0
- package/dist/reporter/diff-html.d.ts +15 -0
- package/dist/reporter/diff-html.js +69 -0
- package/dist/reporter/diff-stats.d.ts +24 -0
- package/dist/reporter/diff-stats.js +131 -0
- package/dist/reporter/index.d.ts +2 -0
- package/dist/reporter/index.js +18 -0
- package/dist/runner/basic.d.ts +10 -0
- package/dist/runner/basic.js +63 -0
- package/dist/runner/cache.d.ts +5 -0
- package/dist/runner/cache.js +90 -0
- package/dist/runner/hot-step.d.ts +5 -0
- package/dist/runner/hot-step.js +87 -0
- package/dist/runner/hot.d.ts +5 -0
- package/dist/runner/hot.js +83 -0
- package/dist/runner/index.d.ts +9 -0
- package/dist/runner/index.js +25 -0
- package/dist/runner/multiple.d.ts +11 -0
- package/dist/runner/multiple.js +38 -0
- package/dist/runner/normal.d.ts +5 -0
- package/dist/runner/normal.js +20 -0
- package/dist/runner/runner/basic.d.ts +30 -0
- package/dist/runner/runner/basic.js +107 -0
- package/dist/runner/runner/cjs.d.ts +14 -0
- package/dist/runner/runner/cjs.js +151 -0
- package/dist/runner/runner/esm.d.ts +7 -0
- package/dist/runner/runner/esm.js +125 -0
- package/dist/runner/runner/index.d.ts +8 -0
- package/dist/runner/runner/index.js +24 -0
- package/dist/runner/runner/normal.d.ts +9 -0
- package/dist/runner/runner/normal.js +23 -0
- package/dist/runner/runner/watch.d.ts +16 -0
- package/dist/runner/runner/watch.js +27 -0
- package/dist/runner/runner/web/fake.d.ts +18 -0
- package/dist/runner/runner/web/fake.js +143 -0
- package/dist/runner/runner/web/jsdom.d.ts +26 -0
- package/dist/runner/runner/web/jsdom.js +219 -0
- package/dist/runner/runner/web.d.ts +15 -0
- package/dist/runner/runner/web.js +32 -0
- package/dist/runner/type.d.ts +42 -0
- package/dist/runner/type.js +9 -0
- package/dist/runner/watch.d.ts +7 -0
- package/dist/runner/watch.js +60 -0
- package/dist/test/context.d.ts +26 -0
- package/dist/test/context.js +108 -0
- package/dist/test/creator.d.ts +46 -0
- package/dist/test/creator.js +310 -0
- package/dist/test/simple.d.ts +5 -0
- package/dist/test/simple.js +43 -0
- package/dist/test/tester.d.ts +17 -0
- package/dist/test/tester.js +88 -0
- package/dist/type.d.ts +168 -0
- package/dist/type.js +22 -0
- package/jest.d.ts +25 -0
- package/package.json +116 -0
- package/template/diff.bundle.css +1 -0
- package/template/diff.bundle.js +144 -0
- package/template/diff.html +14 -0
- package/template/editor.worker.js +1 -0
|
@@ -0,0 +1,239 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function replaceModuleArgument(raw: string): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function replaceRuntimeModuleName(content: string): string;
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import EventEmitter from "node:events";
|
|
2
|
+
import { ECompilerType, type ITestCompilerManager, type TCompiler, type TCompilerFactories, type TCompilerOptions, type TCompilerStats } from "./type";
|
|
3
|
+
export declare enum ECompilerEvent {
|
|
4
|
+
Build = "build",
|
|
5
|
+
Option = "option",
|
|
6
|
+
Create = "create",
|
|
7
|
+
Close = "close"
|
|
8
|
+
}
|
|
9
|
+
export declare const COMPILER_FACTORIES: TCompilerFactories;
|
|
10
|
+
export declare class TestCompilerManager<T extends ECompilerType> implements ITestCompilerManager<T> {
|
|
11
|
+
protected type: T;
|
|
12
|
+
protected factories: TCompilerFactories;
|
|
13
|
+
protected compilerOptions: TCompilerOptions<T>;
|
|
14
|
+
protected compilerInstance: TCompiler<T> | null;
|
|
15
|
+
protected compilerStats: TCompilerStats<T> | null;
|
|
16
|
+
protected emitter: EventEmitter;
|
|
17
|
+
constructor(type: T, factories?: TCompilerFactories);
|
|
18
|
+
getOptions(): TCompilerOptions<T>;
|
|
19
|
+
setOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
|
|
20
|
+
mergeOptions(newOptions: TCompilerOptions<T>): TCompilerOptions<T>;
|
|
21
|
+
getCompiler(): TCompiler<T> | null;
|
|
22
|
+
createCompiler(): TCompiler<T>;
|
|
23
|
+
build(): Promise<TCompilerStats<T>>;
|
|
24
|
+
watch(timeout?: number): void;
|
|
25
|
+
getStats(): TCompilerStats<T> | null;
|
|
26
|
+
getEmitter(): EventEmitter<[never]>;
|
|
27
|
+
close(): Promise<void>;
|
|
28
|
+
}
|
package/dist/compiler.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
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.TestCompilerManager = exports.COMPILER_FACTORIES = exports.ECompilerEvent = void 0;
|
|
7
|
+
const node_events_1 = __importDefault(require("node:events"));
|
|
8
|
+
const webpack_merge_1 = __importDefault(require("webpack-merge"));
|
|
9
|
+
const type_1 = require("./type");
|
|
10
|
+
var ECompilerEvent;
|
|
11
|
+
(function (ECompilerEvent) {
|
|
12
|
+
ECompilerEvent["Build"] = "build";
|
|
13
|
+
ECompilerEvent["Option"] = "option";
|
|
14
|
+
ECompilerEvent["Create"] = "create";
|
|
15
|
+
ECompilerEvent["Close"] = "close";
|
|
16
|
+
})(ECompilerEvent || (exports.ECompilerEvent = ECompilerEvent = {}));
|
|
17
|
+
exports.COMPILER_FACTORIES = {
|
|
18
|
+
[type_1.ECompilerType.Rspack]: ((options) => require("@rspack/core")(options)),
|
|
19
|
+
[type_1.ECompilerType.Webpack]: ((options) => require("webpack")(options))
|
|
20
|
+
};
|
|
21
|
+
class TestCompilerManager {
|
|
22
|
+
constructor(type, factories = exports.COMPILER_FACTORIES) {
|
|
23
|
+
this.type = type;
|
|
24
|
+
this.factories = factories;
|
|
25
|
+
this.compilerOptions = {};
|
|
26
|
+
this.compilerInstance = null;
|
|
27
|
+
this.compilerStats = null;
|
|
28
|
+
this.emitter = new node_events_1.default();
|
|
29
|
+
}
|
|
30
|
+
getOptions() {
|
|
31
|
+
return this.compilerOptions;
|
|
32
|
+
}
|
|
33
|
+
setOptions(newOptions) {
|
|
34
|
+
this.compilerOptions = newOptions;
|
|
35
|
+
this.emitter.emit(ECompilerEvent.Option, this.compilerOptions);
|
|
36
|
+
return this.compilerOptions;
|
|
37
|
+
}
|
|
38
|
+
mergeOptions(newOptions) {
|
|
39
|
+
this.compilerOptions = (0, webpack_merge_1.default)(this.compilerOptions, newOptions);
|
|
40
|
+
this.emitter.emit(ECompilerEvent.Option, this.compilerOptions);
|
|
41
|
+
return this.compilerOptions;
|
|
42
|
+
}
|
|
43
|
+
getCompiler() {
|
|
44
|
+
return this.compilerInstance;
|
|
45
|
+
}
|
|
46
|
+
createCompiler() {
|
|
47
|
+
this.compilerInstance = this.factories[this.type](this.compilerOptions);
|
|
48
|
+
this.emitter.emit(ECompilerEvent.Create, this.compilerInstance);
|
|
49
|
+
return this.compilerInstance;
|
|
50
|
+
}
|
|
51
|
+
build() {
|
|
52
|
+
if (!this.compilerInstance)
|
|
53
|
+
throw new Error("Compiler should be created before build");
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
try {
|
|
56
|
+
this.compilerInstance.run((error, newStats) => {
|
|
57
|
+
this.emitter.emit(ECompilerEvent.Build, error, newStats);
|
|
58
|
+
if (error)
|
|
59
|
+
return reject(error);
|
|
60
|
+
this.compilerStats = newStats;
|
|
61
|
+
resolve(newStats);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
reject(e);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
watch(timeout = 1000) {
|
|
70
|
+
if (!this.compilerInstance)
|
|
71
|
+
throw new Error("Compiler should be created before watch");
|
|
72
|
+
this.compilerInstance.watch({
|
|
73
|
+
// IMPORTANT:
|
|
74
|
+
// This is a workaround for the issue that watchpack cannot detect the file change in time
|
|
75
|
+
// so we set the poll to 300ms to make it more sensitive to the file change
|
|
76
|
+
poll: 300,
|
|
77
|
+
// Rspack ignored node_modules and .git by default for better performance, but for tests we
|
|
78
|
+
// want to watch all files, which aligns with webpack's default behavior
|
|
79
|
+
ignored: [],
|
|
80
|
+
aggregateTimeout: timeout
|
|
81
|
+
}, (error, newStats) => {
|
|
82
|
+
this.emitter.emit(ECompilerEvent.Build, error, newStats);
|
|
83
|
+
if (error)
|
|
84
|
+
return error;
|
|
85
|
+
if (newStats) {
|
|
86
|
+
this.compilerStats = newStats;
|
|
87
|
+
}
|
|
88
|
+
return newStats;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
getStats() {
|
|
92
|
+
return this.compilerStats;
|
|
93
|
+
}
|
|
94
|
+
getEmitter() {
|
|
95
|
+
return this.emitter;
|
|
96
|
+
}
|
|
97
|
+
close() {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
if (this.compilerInstance) {
|
|
100
|
+
this.compilerInstance.close(e => {
|
|
101
|
+
this.emitter.emit(ECompilerEvent.Close, e);
|
|
102
|
+
e ? reject(e) : resolve();
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
resolve();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.TestCompilerManager = TestCompilerManager;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const isDirectory: (p: string) => boolean;
|
|
2
|
+
export declare const isFile: (p: string) => boolean;
|
|
3
|
+
export declare const isValidCaseDirectory: (name: string) => boolean;
|
|
4
|
+
export declare function describeByWalk(testFile: string, createCase: (name: string, src: string, dist: string) => void, options?: {
|
|
5
|
+
type?: "file" | "directory";
|
|
6
|
+
level?: number;
|
|
7
|
+
source?: string;
|
|
8
|
+
dist?: string;
|
|
9
|
+
absoluteDist?: boolean;
|
|
10
|
+
describe?: jest.Describe;
|
|
11
|
+
exclude?: RegExp[];
|
|
12
|
+
}): void;
|
|
@@ -0,0 +1,81 @@
|
|
|
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.isValidCaseDirectory = exports.isFile = exports.isDirectory = void 0;
|
|
7
|
+
exports.describeByWalk = describeByWalk;
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const _1 = require(".");
|
|
11
|
+
const isDirectory = (p) => node_fs_1.default.lstatSync(p).isDirectory();
|
|
12
|
+
exports.isDirectory = isDirectory;
|
|
13
|
+
const isFile = (p) => node_fs_1.default.lstatSync(p).isFile();
|
|
14
|
+
exports.isFile = isFile;
|
|
15
|
+
const isValidCaseDirectory = (name) => !name.startsWith("_") && !name.startsWith(".") && name !== "node_modules";
|
|
16
|
+
exports.isValidCaseDirectory = isValidCaseDirectory;
|
|
17
|
+
function describeByWalk(testFile, createCase, options = {}) {
|
|
18
|
+
const describeFn = options.describe || describe;
|
|
19
|
+
const testBasename = node_path_1.default
|
|
20
|
+
.basename(testFile)
|
|
21
|
+
.replace(/\.(diff|hot)?test\.(j|t)s/, "");
|
|
22
|
+
const testId = testBasename.charAt(0).toLowerCase() + testBasename.slice(1);
|
|
23
|
+
const sourceBase = options.source || node_path_1.default.join(node_path_1.default.dirname(testFile), `${testId}Cases`);
|
|
24
|
+
const distBase = options.dist || node_path_1.default.join(node_path_1.default.dirname(testFile), "js", testId);
|
|
25
|
+
const level = options.level || 2;
|
|
26
|
+
const type = options.type || "directory";
|
|
27
|
+
const absoluteDist = options.absoluteDist ?? true;
|
|
28
|
+
function describeDirectory(dirname, currentLevel) {
|
|
29
|
+
node_fs_1.default.readdirSync(node_path_1.default.join(sourceBase, dirname))
|
|
30
|
+
.filter(exports.isValidCaseDirectory)
|
|
31
|
+
.filter(folder => {
|
|
32
|
+
if (options.exclude) {
|
|
33
|
+
if (options.exclude.some(exclude => {
|
|
34
|
+
return exclude.test(folder);
|
|
35
|
+
})) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
})
|
|
41
|
+
.filter(folder => {
|
|
42
|
+
const p = node_path_1.default.join(sourceBase, dirname, folder);
|
|
43
|
+
if (type === "file" && currentLevel === 1) {
|
|
44
|
+
return (0, exports.isFile)(p);
|
|
45
|
+
}
|
|
46
|
+
if (type === "directory" || currentLevel > 1) {
|
|
47
|
+
return (0, exports.isDirectory)(p);
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
})
|
|
51
|
+
.map(folder => {
|
|
52
|
+
const caseName = node_path_1.default.join(dirname, folder);
|
|
53
|
+
if (currentLevel > 1) {
|
|
54
|
+
describeDirectory(caseName, currentLevel - 1);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const name = (0, _1.escapeSep)(node_path_1.default.join(testId, caseName).split(".").shift());
|
|
58
|
+
describeFn(name, () => {
|
|
59
|
+
const source = node_path_1.default.join(sourceBase, caseName);
|
|
60
|
+
let dist = "";
|
|
61
|
+
if (absoluteDist) {
|
|
62
|
+
dist = node_path_1.default.join(distBase, caseName);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const relativeDist = options.dist || "dist";
|
|
66
|
+
if (node_path_1.default.isAbsolute(relativeDist)) {
|
|
67
|
+
dist = node_path_1.default.join(relativeDist, caseName);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
dist = node_path_1.default.join(sourceBase, caseName, relativeDist);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
createCase(name, source, dist);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
describeFn(testId, () => {
|
|
79
|
+
describeDirectory("", level);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeDiff = void 0;
|
|
4
|
+
const CURRENT_CWD = process.cwd();
|
|
5
|
+
const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&");
|
|
6
|
+
const cwdRegExp = new RegExp(`${quoteMeta(CURRENT_CWD)}((?:\\\\)?(?:[a-zA-Z.\\-_]+\\\\)*)`, "g");
|
|
7
|
+
const escapedCwd = JSON.stringify(CURRENT_CWD).slice(1, -1);
|
|
8
|
+
const escapedCwdRegExp = new RegExp(`${quoteMeta(escapedCwd)}((?:\\\\\\\\)?(?:[a-zA-Z.\\-_]+\\\\\\\\)*)`, "g");
|
|
9
|
+
const normalizeDiff = (diff) => {
|
|
10
|
+
let normalizedStr = diff.value;
|
|
11
|
+
if (CURRENT_CWD.startsWith("/")) {
|
|
12
|
+
normalizedStr = normalizedStr.replace(new RegExp(quoteMeta(CURRENT_CWD), "g"), "<cwd>");
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
normalizedStr = normalizedStr.replace(cwdRegExp, (_, g) => `<cwd>${g.replace(/\\/g, "/")}`);
|
|
16
|
+
normalizedStr = normalizedStr.replace(escapedCwdRegExp, (_, g) => `<cwd>${g.replace(/\\\\/g, "/")}`);
|
|
17
|
+
}
|
|
18
|
+
normalizedStr = normalizedStr.replace(/@@ -\d+,\d+ \+\d+,\d+ @@/g, "@@ ... @@");
|
|
19
|
+
return normalizedStr;
|
|
20
|
+
};
|
|
21
|
+
exports.normalizeDiff = normalizeDiff;
|
|
@@ -0,0 +1,51 @@
|
|
|
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.normalizeDignostics = normalizeDignostics;
|
|
7
|
+
exports.normalizeError = normalizeError;
|
|
8
|
+
const pretty_format_1 = __importDefault(require("pretty-format"));
|
|
9
|
+
const ERROR_STACK_PATTERN = /(│.* at ).*/g;
|
|
10
|
+
const prettyFormatOptions = {
|
|
11
|
+
escapeRegex: false,
|
|
12
|
+
printFunctionName: false,
|
|
13
|
+
plugins: [
|
|
14
|
+
{
|
|
15
|
+
test(val) {
|
|
16
|
+
return typeof val === "string";
|
|
17
|
+
},
|
|
18
|
+
print(val) {
|
|
19
|
+
return `"${val
|
|
20
|
+
.replace(/\\/gm, "/")
|
|
21
|
+
.replace(/"/gm, '\\"')
|
|
22
|
+
.replace(/\r?\n/gm, "\\n")}"`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
};
|
|
27
|
+
function cleanErrorStack(message) {
|
|
28
|
+
return message.replace(ERROR_STACK_PATTERN, "$1xxx");
|
|
29
|
+
}
|
|
30
|
+
function cleanError(err) {
|
|
31
|
+
const result = {};
|
|
32
|
+
for (const key of Object.getOwnPropertyNames(err)) {
|
|
33
|
+
result[key] = err[key];
|
|
34
|
+
}
|
|
35
|
+
if (result.message) {
|
|
36
|
+
result.message = cleanErrorStack(err.message);
|
|
37
|
+
}
|
|
38
|
+
if (result.stack) {
|
|
39
|
+
result.stack = cleanErrorStack(result.stack);
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
function normalizeDignostics(received) {
|
|
44
|
+
return (0, pretty_format_1.default)({
|
|
45
|
+
errors: received.errors.map(e => cleanError(e)),
|
|
46
|
+
warnings: received.warnings.map(e => cleanError(e))
|
|
47
|
+
}, prettyFormatOptions).trim();
|
|
48
|
+
}
|
|
49
|
+
function normalizeError(received) {
|
|
50
|
+
return (0, pretty_format_1.default)(cleanError(received), prettyFormatOptions).trim();
|
|
51
|
+
}
|