@rspack/test-tools 0.5.0 → 0.5.1
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/diff.d.ts +1 -0
- package/dist/case/diff.js +144 -0
- package/dist/compare/comparator.d.ts +1 -0
- package/dist/compare/comparator.js +3 -1
- package/dist/compare/compare.d.ts +4 -2
- package/dist/compare/compare.js +15 -9
- package/dist/helper/parse-modules.d.ts +3 -1
- package/dist/helper/parse-modules.js +19 -9
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/plugin/rspack-diff-config-plugin.d.ts +3 -3
- package/dist/plugin/rspack-diff-config-plugin.js +5 -2
- package/dist/plugin/webpack-diff-config-plugin.d.ts +3 -3
- package/dist/plugin/webpack-diff-config-plugin.js +6 -3
- package/dist/plugin/webpack-module-placeholder-plugin.d.ts +1 -2
- package/dist/plugin/webpack-module-placeholder-plugin.js +6 -6
- package/dist/processor/diff.d.ts +2 -0
- package/dist/processor/diff.js +5 -5
- package/package.json +12 -13
- package/template/diff.bundle.js +2 -2
- package/template/editor.worker.js +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createDiffCase(name: string, src: string, dist: string): void;
|
|
@@ -0,0 +1,144 @@
|
|
|
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.createDiffCase = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const __1 = require("../");
|
|
10
|
+
const rimraf_1 = __importDefault(require("rimraf"));
|
|
11
|
+
const DEFAULT_CASE_CONFIG = {
|
|
12
|
+
webpackPath: require.resolve("webpack"),
|
|
13
|
+
rspackPath: require.resolve("@rspack/core"),
|
|
14
|
+
files: ["bundle.js"],
|
|
15
|
+
bootstrap: true,
|
|
16
|
+
detail: true
|
|
17
|
+
};
|
|
18
|
+
function createDiffCase(name, src, dist) {
|
|
19
|
+
const caseConfigFile = path_1.default.join(src, "test.config.js");
|
|
20
|
+
if (!fs_extra_1.default.existsSync(caseConfigFile)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const caseConfig = Object.assign({}, DEFAULT_CASE_CONFIG, require(caseConfigFile));
|
|
24
|
+
const [processor, compareMap] = createDiffProcessor(caseConfig);
|
|
25
|
+
const tester = new __1.Tester({
|
|
26
|
+
name,
|
|
27
|
+
src,
|
|
28
|
+
dist,
|
|
29
|
+
steps: [processor]
|
|
30
|
+
});
|
|
31
|
+
describe(name, () => {
|
|
32
|
+
beforeAll(async () => {
|
|
33
|
+
rimraf_1.default.sync(dist);
|
|
34
|
+
await tester.prepare();
|
|
35
|
+
});
|
|
36
|
+
do {
|
|
37
|
+
const prefix = `[${name}][${tester.step + 1}]:`;
|
|
38
|
+
describe(`${prefix}build`, () => {
|
|
39
|
+
beforeAll(async () => {
|
|
40
|
+
await tester.compile();
|
|
41
|
+
});
|
|
42
|
+
checkBundleFiles("webpack", path_1.default.join(dist, "webpack"), caseConfig.files);
|
|
43
|
+
checkBundleFiles("rspack", path_1.default.join(dist, "rspack"), caseConfig.files);
|
|
44
|
+
});
|
|
45
|
+
describe(`${prefix}check`, () => {
|
|
46
|
+
beforeAll(async () => {
|
|
47
|
+
compareMap.clear();
|
|
48
|
+
await tester.check();
|
|
49
|
+
});
|
|
50
|
+
for (let file of caseConfig.files) {
|
|
51
|
+
describe(`Comparing "${file}"`, () => {
|
|
52
|
+
let moduleResults = [];
|
|
53
|
+
let runtimeResults = [];
|
|
54
|
+
beforeAll(() => {
|
|
55
|
+
const fileResult = compareMap.get(file);
|
|
56
|
+
if (!fileResult) {
|
|
57
|
+
throw new Error(`File ${file} has no results`);
|
|
58
|
+
}
|
|
59
|
+
moduleResults = fileResult.modules;
|
|
60
|
+
runtimeResults = fileResult.runtimeModules;
|
|
61
|
+
});
|
|
62
|
+
if (caseConfig.modules) {
|
|
63
|
+
checkCompareResults("modules", () => moduleResults);
|
|
64
|
+
}
|
|
65
|
+
if (caseConfig.runtimeModules) {
|
|
66
|
+
checkCompareResults("runtime modules", () => runtimeResults);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
} while (tester.next());
|
|
72
|
+
afterAll(async () => {
|
|
73
|
+
await tester.resume();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
exports.createDiffCase = createDiffCase;
|
|
78
|
+
function createDiffProcessor(config) {
|
|
79
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
80
|
+
const fileCompareMap = new Map();
|
|
81
|
+
const createCompareResultHandler = (type) => {
|
|
82
|
+
return (file, results) => {
|
|
83
|
+
const fileResult = fileCompareMap.get(file) || {
|
|
84
|
+
modules: [],
|
|
85
|
+
runtimeModules: []
|
|
86
|
+
};
|
|
87
|
+
fileResult[type] = results;
|
|
88
|
+
fileCompareMap.set(file, fileResult);
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
const processor = new __1.DiffProcessor({
|
|
92
|
+
webpackPath: config.webpackPath,
|
|
93
|
+
rspackPath: config.rspackPath,
|
|
94
|
+
files: config.files,
|
|
95
|
+
modules: config.modules,
|
|
96
|
+
runtimeModules: config.runtimeModules,
|
|
97
|
+
ignoreModuleId: (_a = config.ignoreModuleId) !== null && _a !== void 0 ? _a : true,
|
|
98
|
+
ignoreModuleArguments: (_b = config.ignoreModuleArguments) !== null && _b !== void 0 ? _b : true,
|
|
99
|
+
ignorePropertyQuotationMark: (_c = config.ignorePropertyQuotationMark) !== null && _c !== void 0 ? _c : true,
|
|
100
|
+
ignoreBlockOnlyStatement: (_d = config.ignoreBlockOnlyStatement) !== null && _d !== void 0 ? _d : true,
|
|
101
|
+
ignoreSwcHelpersPath: (_e = config.ignoreSwcHelpersPath) !== null && _e !== void 0 ? _e : true,
|
|
102
|
+
ignoreObjectPropertySequence: (_f = config.ignoreObjectPropertySequence) !== null && _f !== void 0 ? _f : true,
|
|
103
|
+
ignoreCssFilePath: (_g = config.ignoreCssFilePath) !== null && _g !== void 0 ? _g : true,
|
|
104
|
+
onCompareModules: createCompareResultHandler("modules"),
|
|
105
|
+
onCompareRuntimeModules: createCompareResultHandler("runtimeModules"),
|
|
106
|
+
bootstrap: (_h = config.bootstrap) !== null && _h !== void 0 ? _h : true,
|
|
107
|
+
detail: (_j = config.detail) !== null && _j !== void 0 ? _j : true
|
|
108
|
+
});
|
|
109
|
+
return [processor, fileCompareMap];
|
|
110
|
+
}
|
|
111
|
+
function checkBundleFiles(name, dist, files) {
|
|
112
|
+
describe(`Checking ${name} dist files`, () => {
|
|
113
|
+
for (let file of files) {
|
|
114
|
+
it(`${name}: ${file} should be generated`, () => {
|
|
115
|
+
expect(fs_extra_1.default.existsSync(path_1.default.join(dist, file))).toBeTruthy();
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function checkCompareResults(name, getResults) {
|
|
121
|
+
describe(`Comparing ${name}`, () => {
|
|
122
|
+
it("should not miss any module", () => {
|
|
123
|
+
expect(getResults()
|
|
124
|
+
.filter(i => i.type === __1.ECompareResultType.Missing)
|
|
125
|
+
.map(i => i.name)).toEqual([]);
|
|
126
|
+
});
|
|
127
|
+
it("should not have any respack-only module", () => {
|
|
128
|
+
expect(getResults()
|
|
129
|
+
.filter(i => i.type === __1.ECompareResultType.OnlySource)
|
|
130
|
+
.map(i => i.name)).toEqual([]);
|
|
131
|
+
});
|
|
132
|
+
it("should not have any webpack-only module", () => {
|
|
133
|
+
expect(getResults()
|
|
134
|
+
.filter(i => i.type === __1.ECompareResultType.OnlyDist)
|
|
135
|
+
.map(i => i.name)).toEqual([]);
|
|
136
|
+
});
|
|
137
|
+
it(`all modules should be the same`, () => {
|
|
138
|
+
for (let result of getResults().filter(i => i.type === __1.ECompareResultType.Different)) {
|
|
139
|
+
console.log(`${result.name}:\n${result.detail}`);
|
|
140
|
+
}
|
|
141
|
+
expect(getResults().every(i => i.type === __1.ECompareResultType.Same)).toEqual(true);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
@@ -28,7 +28,8 @@ class DiffComparator {
|
|
|
28
28
|
ignoreObjectPropertySequence: true,
|
|
29
29
|
ignoreCssFilePath: true
|
|
30
30
|
}, this.options.formatOptions || {}),
|
|
31
|
-
renameModule: replace_runtime_module_name_1.replaceRuntimeModuleName
|
|
31
|
+
renameModule: replace_runtime_module_name_1.replaceRuntimeModuleName,
|
|
32
|
+
bootstrap: this.options.bootstrap
|
|
32
33
|
});
|
|
33
34
|
for (let reporter of this.options.reporters) {
|
|
34
35
|
reporter.increment(file, result.modules["modules"] || []);
|
|
@@ -38,6 +39,7 @@ class DiffComparator {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
catch (e) {
|
|
42
|
+
console.error(e);
|
|
41
43
|
for (let reporter of this.options.reporters) {
|
|
42
44
|
reporter.failure(file);
|
|
43
45
|
}
|
|
@@ -5,7 +5,9 @@ export interface ICompareOptions {
|
|
|
5
5
|
runtimeModules?: TCompareModules;
|
|
6
6
|
format: IFormatCodeOptions;
|
|
7
7
|
renameModule?: (name: string) => string;
|
|
8
|
+
bootstrap?: boolean;
|
|
9
|
+
detail?: boolean;
|
|
8
10
|
}
|
|
9
11
|
export declare function compareFile(sourceFile: string, distFile: string, compareOptions: ICompareOptions): TFileCompareResult;
|
|
10
|
-
export declare function compareModules(modules: string[], sourceModules: Map<string, string>, distModules: Map<string, string>,
|
|
11
|
-
export declare function compareContent(sourceContent: string | false, distContent: string | false): TCompareResult;
|
|
12
|
+
export declare function compareModules(modules: string[], sourceModules: Map<string, string>, distModules: Map<string, string>, compareOptions: ICompareOptions): TModuleCompareResult[];
|
|
13
|
+
export declare function compareContent(sourceContent: string | false, distContent: string | false, compareOptions: ICompareOptions): TCompareResult;
|
package/dist/compare/compare.js
CHANGED
|
@@ -39,8 +39,12 @@ function compareFile(sourceFile, distFile, compareOptions) {
|
|
|
39
39
|
// result.detail = compareContentResult.detail;
|
|
40
40
|
// result.lines = compareContentResult.lines;
|
|
41
41
|
result.type = type_1.ECompareResultType.Different;
|
|
42
|
-
const sourceModules = (0, helper_1.parseModules)(sourceContent
|
|
43
|
-
|
|
42
|
+
const sourceModules = (0, helper_1.parseModules)(sourceContent, {
|
|
43
|
+
bootstrap: compareOptions.bootstrap
|
|
44
|
+
});
|
|
45
|
+
const distModules = (0, helper_1.parseModules)(distContent, {
|
|
46
|
+
bootstrap: compareOptions.bootstrap
|
|
47
|
+
});
|
|
44
48
|
for (let type of ["modules", "runtimeModules"]) {
|
|
45
49
|
const t = type;
|
|
46
50
|
let moduleList = [];
|
|
@@ -59,28 +63,28 @@ function compareFile(sourceFile, distFile, compareOptions) {
|
|
|
59
63
|
if (typeof compareOptions.renameModule === "function") {
|
|
60
64
|
moduleList = moduleList.map(compareOptions.renameModule);
|
|
61
65
|
}
|
|
62
|
-
result.modules[t] = compareModules(moduleList, sourceModules[t], distModules[t], compareOptions
|
|
66
|
+
result.modules[t] = compareModules(moduleList, sourceModules[t], distModules[t], compareOptions);
|
|
63
67
|
}
|
|
64
68
|
return result;
|
|
65
69
|
}
|
|
66
70
|
exports.compareFile = compareFile;
|
|
67
|
-
function compareModules(modules, sourceModules, distModules,
|
|
71
|
+
function compareModules(modules, sourceModules, distModules, compareOptions) {
|
|
68
72
|
const compareResults = [];
|
|
69
73
|
for (let name of modules) {
|
|
70
74
|
const renamed = (0, replace_runtime_module_name_1.replaceRuntimeModuleName)(name);
|
|
71
75
|
const sourceContent = sourceModules.has(renamed) &&
|
|
72
|
-
(0, format_code_1.formatCode)(name, sourceModules.get(renamed),
|
|
76
|
+
(0, format_code_1.formatCode)(name, sourceModules.get(renamed), compareOptions.format);
|
|
73
77
|
const distContent = distModules.has(renamed) &&
|
|
74
|
-
(0, format_code_1.formatCode)(name, distModules.get(renamed),
|
|
78
|
+
(0, format_code_1.formatCode)(name, distModules.get(renamed), compareOptions.format);
|
|
75
79
|
compareResults.push({
|
|
76
|
-
...compareContent(sourceContent, distContent),
|
|
80
|
+
...compareContent(sourceContent, distContent, compareOptions),
|
|
77
81
|
name
|
|
78
82
|
});
|
|
79
83
|
}
|
|
80
84
|
return compareResults;
|
|
81
85
|
}
|
|
82
86
|
exports.compareModules = compareModules;
|
|
83
|
-
function compareContent(sourceContent, distContent) {
|
|
87
|
+
function compareContent(sourceContent, distContent, compareOptions) {
|
|
84
88
|
if (sourceContent) {
|
|
85
89
|
if (distContent) {
|
|
86
90
|
if (sourceContent === distContent) {
|
|
@@ -97,7 +101,9 @@ function compareContent(sourceContent, distContent) {
|
|
|
97
101
|
};
|
|
98
102
|
}
|
|
99
103
|
else {
|
|
100
|
-
const difference =
|
|
104
|
+
const difference = compareOptions.detail
|
|
105
|
+
? (0, jest_diff_1.diffStringsUnified)(sourceContent.trim(), distContent.trim())
|
|
106
|
+
: undefined;
|
|
101
107
|
const diffLines = (0, jest_diff_1.diffLinesRaw)(sourceContent.trim().split("\n"), distContent.trim().split("\n"));
|
|
102
108
|
return {
|
|
103
109
|
type: type_1.ECompareResultType.Different,
|
|
@@ -25,30 +25,40 @@ function getStringBetween(raw, position, start, end) {
|
|
|
25
25
|
remain: endFlagIndex + end.length
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function isValidModule(name) {
|
|
29
|
+
if (name.startsWith("data:")) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (name.startsWith("https:")) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
function parseModules(content, options = {}) {
|
|
29
38
|
const modules = new Map();
|
|
30
39
|
const runtimeModules = new Map();
|
|
31
40
|
let currentPosition = 0;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
if (options.bootstrap) {
|
|
42
|
+
// parse bootstrap code
|
|
43
|
+
const bootstrap = getStringBetween(content, 0, BOOTSTRAP_SPLIT_LINE, BOOTSTRAP_SPLIT_LINE);
|
|
44
|
+
if (bootstrap.result) {
|
|
45
|
+
runtimeModules.set("webpack/runtime/bootstrap", bootstrap.result);
|
|
46
|
+
}
|
|
36
47
|
}
|
|
37
48
|
// parse module & runtime module code
|
|
38
49
|
let moduleName = getStringBetween(content, currentPosition, MODULE_START_FLAG, MODULE_FLAG_END).result;
|
|
39
|
-
let totalLength = 0;
|
|
40
50
|
while (moduleName) {
|
|
41
51
|
const moduleContent = getStringBetween(content, currentPosition, `${MODULE_START_FLAG}${moduleName}${MODULE_FLAG_END}`, `${MODULE_END_FLAG}${moduleName}${MODULE_FLAG_END}`);
|
|
42
52
|
if (!moduleContent.result) {
|
|
43
53
|
throw new Error(`Module code parsed error: ${moduleName}`);
|
|
44
54
|
}
|
|
45
55
|
if (moduleName.startsWith("webpack/runtime")) {
|
|
46
|
-
totalLength += moduleContent.result.length;
|
|
47
56
|
runtimeModules.set(moduleName, moduleContent.result);
|
|
48
57
|
}
|
|
49
58
|
else {
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
if (isValidModule(moduleName)) {
|
|
60
|
+
modules.set(moduleName, moduleContent.result);
|
|
61
|
+
}
|
|
52
62
|
}
|
|
53
63
|
currentPosition = moduleContent.remain;
|
|
54
64
|
moduleName = getStringBetween(content, currentPosition, MODULE_START_FLAG, MODULE_FLAG_END).result;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Compiler, RspackPluginInstance } from "@rspack/core";
|
|
1
|
+
import { Compiler, RspackOptionsNormalized, RspackPluginInstance } from "@rspack/core";
|
|
2
2
|
export declare class RspackDiffConfigPlugin implements RspackPluginInstance {
|
|
3
|
-
private
|
|
3
|
+
private modifier?;
|
|
4
4
|
name: string;
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(modifier?: ((options: RspackOptionsNormalized) => RspackOptionsNormalized) | undefined);
|
|
6
6
|
apply(compiler: Compiler): void;
|
|
7
7
|
}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RspackDiffConfigPlugin = void 0;
|
|
4
4
|
const PLUGIN_NAME = "RspackDiffConfigPlugin";
|
|
5
5
|
class RspackDiffConfigPlugin {
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
6
|
+
constructor(modifier) {
|
|
7
|
+
this.modifier = modifier;
|
|
8
8
|
this.name = PLUGIN_NAME;
|
|
9
9
|
process.env["RSPACK_DIFF"] = "true"; // enable rspack diff
|
|
10
10
|
}
|
|
@@ -21,6 +21,9 @@ class RspackDiffConfigPlugin {
|
|
|
21
21
|
options.optimization.mangleExports = false;
|
|
22
22
|
(_b = options.experiments) !== null && _b !== void 0 ? _b : (options.experiments = {});
|
|
23
23
|
(_c = (_d = options.experiments).rspackFuture) !== null && _c !== void 0 ? _c : (_d.rspackFuture = {});
|
|
24
|
+
if (typeof this.modifier === "function") {
|
|
25
|
+
this.modifier(compiler.options);
|
|
26
|
+
}
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
exports.RspackDiffConfigPlugin = RspackDiffConfigPlugin;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Compiler } from "webpack";
|
|
1
|
+
import { Compiler, WebpackOptionsNormalized } from "webpack";
|
|
2
2
|
export declare class WebpackDiffConfigPlugin {
|
|
3
|
-
private
|
|
3
|
+
private modifier?;
|
|
4
4
|
name: string;
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(modifier?: ((options: WebpackOptionsNormalized) => WebpackOptionsNormalized) | undefined);
|
|
6
6
|
apply(compiler: Compiler): void;
|
|
7
7
|
}
|
|
@@ -4,8 +4,8 @@ exports.WebpackDiffConfigPlugin = void 0;
|
|
|
4
4
|
const webpack_module_placeholder_plugin_1 = require("./webpack-module-placeholder-plugin");
|
|
5
5
|
const PLUGIN_NAME = "WebpackDiffConfigPlugin";
|
|
6
6
|
class WebpackDiffConfigPlugin {
|
|
7
|
-
constructor(
|
|
8
|
-
this.
|
|
7
|
+
constructor(modifier) {
|
|
8
|
+
this.modifier = modifier;
|
|
9
9
|
this.name = PLUGIN_NAME;
|
|
10
10
|
}
|
|
11
11
|
apply(compiler) {
|
|
@@ -34,7 +34,10 @@ class WebpackDiffConfigPlugin {
|
|
|
34
34
|
options.output.environment.module = false;
|
|
35
35
|
options.output.environment.optionalChaining = false;
|
|
36
36
|
options.output.environment.templateLiteral = false;
|
|
37
|
-
|
|
37
|
+
if (typeof this.modifier === "function") {
|
|
38
|
+
this.modifier(compiler.options);
|
|
39
|
+
}
|
|
40
|
+
new webpack_module_placeholder_plugin_1.WebpackModulePlaceholderPlugin().apply(compiler);
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
exports.WebpackDiffConfigPlugin = WebpackDiffConfigPlugin;
|
|
@@ -4,6 +4,7 @@ exports.WebpackModulePlaceholderPlugin = void 0;
|
|
|
4
4
|
// @ts-nocheck
|
|
5
5
|
const { ConcatSource, RawSource, CachedSource, PrefixSource } = require("webpack-sources");
|
|
6
6
|
const path = require("path");
|
|
7
|
+
const which = require("which-module");
|
|
7
8
|
function createRenderRuntimeModulesFn(Template) {
|
|
8
9
|
return function renderRuntimeModules(runtimeModules, renderContext) {
|
|
9
10
|
const source = new ConcatSource();
|
|
@@ -51,13 +52,12 @@ function createRenderRuntimeModulesFn(Template) {
|
|
|
51
52
|
}
|
|
52
53
|
const caches = new WeakMap();
|
|
53
54
|
class WebpackModulePlaceholderPlugin {
|
|
54
|
-
constructor(
|
|
55
|
-
this.webpackPath = webpackPath;
|
|
56
|
-
const Template = require(path.join(path.dirname(this.webpackPath), "Template.js"));
|
|
57
|
-
Template.renderRuntimeModules = createRenderRuntimeModulesFn(Template);
|
|
58
|
-
}
|
|
55
|
+
constructor() { }
|
|
59
56
|
apply(compiler) {
|
|
60
|
-
const
|
|
57
|
+
const webpackLibPath = which(compiler.constructor).path;
|
|
58
|
+
const Template = require(path.join(webpackLibPath, "Template.js"));
|
|
59
|
+
Template.renderRuntimeModules = createRenderRuntimeModulesFn(Template);
|
|
60
|
+
const JavascriptModulesPlugin = require(path.join(webpackLibPath, "javascript/JavascriptModulesPlugin.js"));
|
|
61
61
|
compiler.hooks.compilation.tap("RuntimeDiffPlugin", compilation => {
|
|
62
62
|
const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
|
|
63
63
|
hooks.inlineInRuntimeBailout.tap("RuntimeDiffPlugin", () => "not allow inline startup");
|
package/dist/processor/diff.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface IDiffProcessorOptions extends IFormatCodeOptions {
|
|
|
6
6
|
files?: string[];
|
|
7
7
|
modules?: TCompareModules;
|
|
8
8
|
runtimeModules?: TCompareModules;
|
|
9
|
+
bootstrap?: boolean;
|
|
10
|
+
detail?: boolean;
|
|
9
11
|
onCompareFile?: (file: string, result: TFileCompareResult) => void;
|
|
10
12
|
onCompareModules?: (file: string, results: TModuleCompareResult[]) => void;
|
|
11
13
|
onCompareRuntimeModules?: (file: string, results: TModuleCompareResult[]) => void;
|
package/dist/processor/diff.js
CHANGED
|
@@ -41,7 +41,9 @@ class DiffProcessor {
|
|
|
41
41
|
modules: this.options.modules,
|
|
42
42
|
runtimeModules: this.options.runtimeModules,
|
|
43
43
|
format: this.createFormatOptions(),
|
|
44
|
-
renameModule: compare_1.replaceRuntimeModuleName
|
|
44
|
+
renameModule: compare_1.replaceRuntimeModuleName,
|
|
45
|
+
bootstrap: this.options.bootstrap,
|
|
46
|
+
detail: this.options.detail
|
|
45
47
|
});
|
|
46
48
|
if (typeof this.options.onCompareFile === "function") {
|
|
47
49
|
this.options.onCompareFile(file, result);
|
|
@@ -72,10 +74,8 @@ class DiffProcessor {
|
|
|
72
74
|
chunkFilename: "[name].chunk.js"
|
|
73
75
|
},
|
|
74
76
|
plugins: [
|
|
75
|
-
type === type_1.ECompilerType.Webpack &&
|
|
76
|
-
|
|
77
|
-
type === type_1.ECompilerType.Rspack &&
|
|
78
|
-
new plugin_1.RspackDiffConfigPlugin(this.options.rspackPath)
|
|
77
|
+
type === type_1.ECompilerType.Webpack && new plugin_1.WebpackDiffConfigPlugin(),
|
|
78
|
+
type === type_1.ECompilerType.Rspack && new plugin_1.RspackDiffConfigPlugin()
|
|
79
79
|
].filter(Boolean)
|
|
80
80
|
}, {
|
|
81
81
|
arrayMerge: (a, b) => [...a, ...b]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/test-tools",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,41 +36,40 @@
|
|
|
36
36
|
"csv-to-markdown-table": "^1.3.0",
|
|
37
37
|
"deepmerge": "^4.3.1",
|
|
38
38
|
"fs-extra": "^11.1.1",
|
|
39
|
+
"glob": "^10.3.10",
|
|
39
40
|
"jest-diff": "^29.7.0",
|
|
41
|
+
"webpack": "5.89.0",
|
|
40
42
|
"webpack-sources": "3.2.3",
|
|
41
|
-
"
|
|
43
|
+
"which-module": "2.0.1",
|
|
44
|
+
"@rspack/core": "0.5.1"
|
|
42
45
|
},
|
|
43
46
|
"devDependencies": {
|
|
44
47
|
"@arco-design/web-react": "^2.56.1",
|
|
45
48
|
"@monaco-editor/react": "^4.6.0",
|
|
49
|
+
"@swc/jest": "^0.2.29",
|
|
46
50
|
"@types/prettier": "^2.7.2",
|
|
47
51
|
"@types/react": "^18.0.25",
|
|
48
52
|
"@types/react-dom": "^18.0.8",
|
|
49
53
|
"@types/webpack": "5.28.3",
|
|
50
54
|
"@types/webpack-sources": "3.2.0",
|
|
51
55
|
"core-js": "3.25.0",
|
|
52
|
-
"
|
|
56
|
+
"jest-serializer-path": "^0.1.15",
|
|
57
|
+
"monaco-editor": "0.45.0",
|
|
58
|
+
"monaco-editor-webpack-plugin": "7.1.0",
|
|
53
59
|
"normalize.css": "^8.0.0",
|
|
54
60
|
"prettier": "^2.8.3",
|
|
55
61
|
"react": "18.0.0",
|
|
56
62
|
"react-dom": "18.0.0",
|
|
57
63
|
"react-refresh": "0.13.0",
|
|
58
64
|
"typescript": "5.1.6",
|
|
59
|
-
"
|
|
60
|
-
"@rspack/cli": "0.5.0"
|
|
65
|
+
"@rspack/cli": "0.5.1"
|
|
61
66
|
},
|
|
62
67
|
"peerDependenciesMeta": {},
|
|
63
|
-
"jest": {
|
|
64
|
-
"watchPathIgnorePatterns": [
|
|
65
|
-
"<rootDir>/dist",
|
|
66
|
-
"<rootDir>/tests/dist"
|
|
67
|
-
],
|
|
68
|
-
"testEnvironment": "../../scripts/test/patch-node-env.cjs"
|
|
69
|
-
},
|
|
70
68
|
"scripts": {
|
|
71
69
|
"build": "tsc -b ./tsconfig.build.json",
|
|
72
70
|
"build:viewer": "rspack build",
|
|
73
71
|
"dev:viewer": "rspack serve",
|
|
74
|
-
"dev": "tsc -b -w"
|
|
72
|
+
"dev": "tsc -b -w",
|
|
73
|
+
"test:diff": "cross-env RSPACK_DIFF=true NO_COLOR=1 RSPACK_DEP_WARNINGS=false node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --runInBand --logHeapUsage --testPathPattern \".diff.test.ts\""
|
|
75
74
|
}
|
|
76
75
|
}
|