@rspack/test-tools 1.3.4 → 1.3.6
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 -2
- package/dist/case/cache.d.ts +1 -1
- package/dist/case/cache.js +5 -3
- package/dist/case/config.js +5 -1
- package/dist/case/new-code-splitting.js +5 -1
- package/dist/compiler.js +12 -7
- 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/plugins/hot-update.js +8 -1
- package/dist/processor/builtin.js +5 -0
- package/dist/processor/cache.d.ts +6 -3
- package/dist/processor/cache.js +22 -35
- package/dist/processor/defaults.d.ts +1 -0
- package/dist/processor/defaults.js +7 -0
- package/dist/processor/diagnostic.d.ts +1 -0
- package/dist/processor/diagnostic.js +7 -0
- package/dist/processor/hash.js +5 -0
- package/dist/processor/hook.d.ts +1 -0
- package/dist/processor/hook.js +7 -0
- package/dist/processor/hot.js +2 -2
- package/dist/processor/normal.d.ts +1 -0
- package/dist/processor/normal.js +7 -0
- package/dist/processor/stats-api.js +5 -0
- package/dist/processor/stats.js +5 -0
- package/dist/processor/treeshaking.js +5 -0
- package/dist/runner/cache.js +9 -14
- package/dist/runner/hot-step.js +4 -3
- package/dist/runner/hot.js +4 -3
- package/package.json +14 -14
- package/dist/helper/util/refreshModifyTime.d.ts +0 -1
- package/dist/helper/util/refreshModifyTime.js +0 -8
package/README.md
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<picture>
|
|
2
|
-
<
|
|
3
|
-
<img alt="Rspack Banner" src="https://assets.rspack.dev/rspack/rspack-banner-plain-light.png">
|
|
2
|
+
<img alt="Rspack Banner" src="https://assets.rspack.dev/rspack/rspack-banner.png">
|
|
4
3
|
</picture>
|
|
5
4
|
|
|
6
5
|
# @rspack/test-tools
|
package/dist/case/cache.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ECompilerType, type TCompilerOptions } from "../type";
|
|
2
|
-
export declare function createCacheCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"]): void;
|
|
2
|
+
export declare function createCacheCase(name: string, src: string, dist: string, target: TCompilerOptions<ECompilerType.Rspack>["target"], temp: string): void;
|
package/dist/case/cache.js
CHANGED
|
@@ -12,9 +12,11 @@ function getCreator(target) {
|
|
|
12
12
|
clean: true,
|
|
13
13
|
describe: true,
|
|
14
14
|
target,
|
|
15
|
-
steps: ({ name, target }) => [
|
|
15
|
+
steps: ({ name, src, target, temp }) => [
|
|
16
16
|
new cache_1.CacheProcessor({
|
|
17
17
|
name,
|
|
18
|
+
sourceDir: src,
|
|
19
|
+
tempDir: temp,
|
|
18
20
|
target: target,
|
|
19
21
|
compilerType: type_1.ECompilerType.Rspack,
|
|
20
22
|
configFiles: ["rspack.config.js", "webpack.config.js"]
|
|
@@ -26,7 +28,7 @@ function getCreator(target) {
|
|
|
26
28
|
}
|
|
27
29
|
return creators.get(target);
|
|
28
30
|
}
|
|
29
|
-
function createCacheCase(name, src, dist, target) {
|
|
31
|
+
function createCacheCase(name, src, dist, target, temp) {
|
|
30
32
|
const creator = getCreator(target);
|
|
31
|
-
creator.create(name, src, dist);
|
|
33
|
+
creator.create(name, src, dist, temp);
|
|
32
34
|
}
|
package/dist/case/config.js
CHANGED
|
@@ -24,7 +24,11 @@ const creator = new creator_1.BasicCaseCreator({
|
|
|
24
24
|
name,
|
|
25
25
|
runable: true,
|
|
26
26
|
compilerType: type_1.ECompilerType.Rspack,
|
|
27
|
-
configFiles: [
|
|
27
|
+
configFiles: [
|
|
28
|
+
"rspack.config.cjs",
|
|
29
|
+
"rspack.config.js",
|
|
30
|
+
"webpack.config.js"
|
|
31
|
+
]
|
|
28
32
|
})
|
|
29
33
|
],
|
|
30
34
|
runner: runner_1.MultipleRunnerFactory,
|
|
@@ -30,7 +30,11 @@ const configCreator = new creator_1.BasicCaseCreator({
|
|
|
30
30
|
name,
|
|
31
31
|
runable: true,
|
|
32
32
|
compilerType: type_1.ECompilerType.Rspack,
|
|
33
|
-
configFiles: [
|
|
33
|
+
configFiles: [
|
|
34
|
+
"rspack.config.cjs",
|
|
35
|
+
"rspack.config.js",
|
|
36
|
+
"webpack.config.js"
|
|
37
|
+
]
|
|
34
38
|
});
|
|
35
39
|
return [processor];
|
|
36
40
|
},
|
package/dist/compiler.js
CHANGED
|
@@ -52,13 +52,18 @@ class TestCompilerManager {
|
|
|
52
52
|
if (!this.compilerInstance)
|
|
53
53
|
throw new Error("Compiler should be created before build");
|
|
54
54
|
return new Promise((resolve, reject) => {
|
|
55
|
-
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}
|
|
62
67
|
});
|
|
63
68
|
}
|
|
64
69
|
watch(timeout = 1000) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HotUpdatePlugin } from "./plugin";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HotUpdatePlugin = void 0;
|
|
4
|
+
var plugin_1 = require("./plugin");
|
|
5
|
+
Object.defineProperty(exports, "HotUpdatePlugin", { enumerable: true, get: function () { return plugin_1.HotUpdatePlugin; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (c: string): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
function default_1(c) {
|
|
5
|
+
let content = c;
|
|
6
|
+
if (content.includes("NEXT_HMR")) {
|
|
7
|
+
content = `
|
|
8
|
+
${content}
|
|
9
|
+
let __hmr_children__ = [...module.children];
|
|
10
|
+
let __hmr_used_exports__ = __hmr_children__.reduce((res, child) => {
|
|
11
|
+
if (__webpack_module_cache__[child]) {
|
|
12
|
+
res[child] = __webpack_module_cache__[child].exports;
|
|
13
|
+
}
|
|
14
|
+
return res;
|
|
15
|
+
}, {});
|
|
16
|
+
module.hot.accept(__hmr_children__, () => {
|
|
17
|
+
__hmr_children__.forEach((child) => {
|
|
18
|
+
const reexports = __webpack_require__(child);
|
|
19
|
+
for (let key in reexports) {
|
|
20
|
+
if (!__hmr_used_exports__[child]) { continue; }
|
|
21
|
+
Object.defineProperty(__hmr_used_exports__[child], key, {
|
|
22
|
+
configurable: true,
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: () => reexports[key]
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
`;
|
|
30
|
+
}
|
|
31
|
+
return content.replace(/NEXT_HMR/g, "NEXT_HMR.bind(null, module)");
|
|
32
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Compiler } from "@rspack/core";
|
|
2
|
+
export declare class HotUpdatePlugin {
|
|
3
|
+
private projectDir;
|
|
4
|
+
private tempDir;
|
|
5
|
+
private initialized;
|
|
6
|
+
private updateIndex;
|
|
7
|
+
private files;
|
|
8
|
+
constructor(projectDir: string, tempDir: string);
|
|
9
|
+
private getModifiedFiles;
|
|
10
|
+
private getContent;
|
|
11
|
+
private updateFiles;
|
|
12
|
+
initialize(): Promise<void>;
|
|
13
|
+
getUpdateIndex(): number;
|
|
14
|
+
getTotalUpdates(): number;
|
|
15
|
+
goNext(): Promise<void>;
|
|
16
|
+
apply(compiler: Compiler): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
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.HotUpdatePlugin = void 0;
|
|
7
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
async function loopFile(dir, callback) {
|
|
10
|
+
const children = await promises_1.default.readdir(dir);
|
|
11
|
+
await Promise.all(children.map(async (filename) => {
|
|
12
|
+
const filePath = node_path_1.default.join(dir, filename);
|
|
13
|
+
const stat = await promises_1.default.stat(filePath);
|
|
14
|
+
if (stat.isFile()) {
|
|
15
|
+
const content = await promises_1.default.readFile(filePath);
|
|
16
|
+
callback(filePath, content.toString());
|
|
17
|
+
}
|
|
18
|
+
else if (stat.isDirectory()) {
|
|
19
|
+
return loopFile(filePath, callback);
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
const PLUGIN_NAME = "HotUpdatePlugin";
|
|
24
|
+
class HotUpdatePlugin {
|
|
25
|
+
constructor(projectDir, tempDir) {
|
|
26
|
+
this.projectDir = projectDir;
|
|
27
|
+
this.tempDir = tempDir;
|
|
28
|
+
this.initialized = false;
|
|
29
|
+
this.updateIndex = 0;
|
|
30
|
+
this.files = {};
|
|
31
|
+
}
|
|
32
|
+
getModifiedFiles() {
|
|
33
|
+
return Object.keys(this.files);
|
|
34
|
+
}
|
|
35
|
+
getContent(filePath, index) {
|
|
36
|
+
const contents = this.files[filePath] || [];
|
|
37
|
+
let content = contents[index] === undefined ? contents.at(-1) || "" : contents[index];
|
|
38
|
+
let command = "";
|
|
39
|
+
const matchResult = content.match(/^<(.+?)>([\w\W]*)$/);
|
|
40
|
+
if (matchResult) {
|
|
41
|
+
command = matchResult[1];
|
|
42
|
+
content = matchResult[2];
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
content,
|
|
46
|
+
command
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async updateFiles() {
|
|
50
|
+
await Promise.all(this.getModifiedFiles().map(async (filePath) => {
|
|
51
|
+
const { content, command } = this.getContent(filePath, this.updateIndex);
|
|
52
|
+
// match command
|
|
53
|
+
if (command === "delete") {
|
|
54
|
+
await promises_1.default.unlink(filePath);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (command === "force_write") {
|
|
58
|
+
await promises_1.default.writeFile(filePath, content);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// default
|
|
62
|
+
const { content: oldContent } = this.getContent(filePath, this.updateIndex - 1);
|
|
63
|
+
if (content === oldContent) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
await promises_1.default.writeFile(filePath, content);
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
async initialize() {
|
|
70
|
+
if (this.initialized) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.initialized = true;
|
|
74
|
+
await promises_1.default.rmdir(this.tempDir, { recursive: true });
|
|
75
|
+
await promises_1.default.cp(this.projectDir, this.tempDir, { recursive: true });
|
|
76
|
+
await loopFile(this.tempDir, (filePath, content) => {
|
|
77
|
+
const contents = content.split(/---+\r?\n/g);
|
|
78
|
+
if (contents.length > 1) {
|
|
79
|
+
this.files[filePath] = contents;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
await this.updateFiles();
|
|
83
|
+
}
|
|
84
|
+
getUpdateIndex() {
|
|
85
|
+
return this.updateIndex;
|
|
86
|
+
}
|
|
87
|
+
getTotalUpdates() {
|
|
88
|
+
return Object.values(this.files).reduce((max, item) => {
|
|
89
|
+
return Math.max(max, item.length);
|
|
90
|
+
}, 0);
|
|
91
|
+
}
|
|
92
|
+
async goNext() {
|
|
93
|
+
this.updateIndex++;
|
|
94
|
+
await this.updateFiles();
|
|
95
|
+
}
|
|
96
|
+
apply(compiler) {
|
|
97
|
+
const options = compiler.options;
|
|
98
|
+
options.context = this.tempDir;
|
|
99
|
+
options.module.rules ??= [];
|
|
100
|
+
options.module.rules.push({
|
|
101
|
+
test: /\.(js|css|json)/,
|
|
102
|
+
use: [
|
|
103
|
+
{
|
|
104
|
+
loader: node_path_1.default.resolve(__dirname, "./loader.js")
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
});
|
|
108
|
+
let isRebuild = false;
|
|
109
|
+
compiler.hooks.beforeRun.tap(PLUGIN_NAME, () => {
|
|
110
|
+
compiler.modifiedFiles = new Set(isRebuild ? this.getModifiedFiles() : []);
|
|
111
|
+
isRebuild = true;
|
|
112
|
+
});
|
|
113
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
|
114
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap(PLUGIN_NAME, (_chunk, set) => {
|
|
115
|
+
set.add(compiler.webpack.RuntimeGlobals.moduleCache);
|
|
116
|
+
});
|
|
117
|
+
compilation.hooks.runtimeModule.tap(PLUGIN_NAME, (module, _set) => {
|
|
118
|
+
if (module.constructorName === "DefinePropertyGettersRuntimeModule") {
|
|
119
|
+
module.source.source = Buffer.from(`
|
|
120
|
+
__webpack_require__.d = function (exports, definition) {
|
|
121
|
+
for (var key in definition) {
|
|
122
|
+
if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
123
|
+
Object.defineProperty(exports, key, { configurable: true, enumerable: true, get: definition[key] });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
`, "utf-8");
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.HotUpdatePlugin = HotUpdatePlugin;
|
|
@@ -6,9 +6,16 @@ class TestHotUpdatePlugin {
|
|
|
6
6
|
this.updateOptions = updateOptions;
|
|
7
7
|
}
|
|
8
8
|
apply(compiler) {
|
|
9
|
+
let isRebuild = false;
|
|
9
10
|
compiler.hooks.beforeRun.tap("TestHotUpdatePlugin", () => {
|
|
10
|
-
|
|
11
|
+
if (isRebuild) {
|
|
12
|
+
compiler.modifiedFiles = new Set(this.updateOptions.changedFiles);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
compiler.modifiedFiles = new Set();
|
|
16
|
+
}
|
|
11
17
|
this.updateOptions.changedFiles = [];
|
|
18
|
+
isRebuild = true;
|
|
12
19
|
});
|
|
13
20
|
compiler.hooks.compilation.tap("TestHotUpdatePlugin", compilation => {
|
|
14
21
|
compilation.hooks.additionalTreeRuntimeRequirements.tap("HMR_TEST_PLUGIN", (_chunk, set) => {
|
|
@@ -160,6 +160,11 @@ class BuiltinProcessor extends snapshot_1.SnapshotProcessor {
|
|
|
160
160
|
delete rspackDefaultOptions.builtins;
|
|
161
161
|
defaultOptions = rspackDefaultOptions;
|
|
162
162
|
}
|
|
163
|
+
if (!global.printLogger) {
|
|
164
|
+
defaultOptions.infrastructureLogging = {
|
|
165
|
+
level: "error"
|
|
166
|
+
};
|
|
167
|
+
}
|
|
163
168
|
return defaultOptions;
|
|
164
169
|
}
|
|
165
170
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HotUpdatePlugin } from "../helper/hot-update";
|
|
2
|
+
import { ECompilerType, type ITestContext, type ITestEnv, type ITestRunner, type TCompilerOptions } from "../type";
|
|
2
3
|
import { BasicProcessor, type IBasicProcessorOptions } from "./basic";
|
|
3
4
|
export interface ICacheProcessorOptions<T extends ECompilerType> extends Omit<IBasicProcessorOptions<T>, "runable"> {
|
|
4
5
|
target: TCompilerOptions<T>["target"];
|
|
6
|
+
tempDir: string;
|
|
7
|
+
sourceDir: string;
|
|
5
8
|
}
|
|
6
9
|
export declare class CacheProcessor<T extends ECompilerType> extends BasicProcessor<T> {
|
|
7
10
|
protected _cacheOptions: ICacheProcessorOptions<T>;
|
|
8
|
-
protected
|
|
11
|
+
protected updatePlugin: HotUpdatePlugin;
|
|
9
12
|
protected runner: ITestRunner | null;
|
|
10
13
|
constructor(_cacheOptions: ICacheProcessorOptions<T>);
|
|
11
|
-
|
|
14
|
+
config(context: ITestContext): Promise<void>;
|
|
12
15
|
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
13
16
|
static findBundle<T extends ECompilerType>(this: CacheProcessor<T>, context: ITestContext): string[];
|
|
14
17
|
afterAll(context: ITestContext): Promise<void>;
|
package/dist/processor/cache.js
CHANGED
|
@@ -6,17 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.CacheProcessor = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const core_1 = require("@rspack/core");
|
|
9
|
-
const
|
|
10
|
-
const plugins_1 = require("../helper/plugins");
|
|
9
|
+
const hot_update_1 = require("../helper/hot-update");
|
|
11
10
|
const type_1 = require("../type");
|
|
12
11
|
const basic_1 = require("./basic");
|
|
13
12
|
class CacheProcessor extends basic_1.BasicProcessor {
|
|
14
13
|
constructor(_cacheOptions) {
|
|
15
|
-
const fakeUpdateLoaderOptions = {
|
|
16
|
-
updateIndex: 0,
|
|
17
|
-
totalUpdates: 1,
|
|
18
|
-
changedFiles: []
|
|
19
|
-
};
|
|
20
14
|
super({
|
|
21
15
|
defaultOptions: CacheProcessor.defaultOptions,
|
|
22
16
|
overrideOptions: CacheProcessor.overrideOptions,
|
|
@@ -26,22 +20,17 @@ class CacheProcessor extends basic_1.BasicProcessor {
|
|
|
26
20
|
});
|
|
27
21
|
this._cacheOptions = _cacheOptions;
|
|
28
22
|
this.runner = null;
|
|
29
|
-
this.
|
|
23
|
+
this.updatePlugin = new hot_update_1.HotUpdatePlugin(_cacheOptions.sourceDir, _cacheOptions.tempDir);
|
|
30
24
|
}
|
|
31
|
-
async
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
experiments.cache.type === "persistent") {
|
|
38
|
-
directory = experiments.cache.storage?.directory || directory;
|
|
39
|
-
}
|
|
40
|
-
(0, fs_extra_1.removeSync)(node_path_1.default.resolve(context.getSource(), directory || "node_modules/.cache"));
|
|
41
|
-
await super.build(context);
|
|
25
|
+
async config(context) {
|
|
26
|
+
await this.updatePlugin.initialize();
|
|
27
|
+
this._options.configFiles = this._options.configFiles?.map(item => {
|
|
28
|
+
return node_path_1.default.resolve(this._cacheOptions.tempDir, item);
|
|
29
|
+
});
|
|
30
|
+
super.config(context);
|
|
42
31
|
}
|
|
43
32
|
async run(env, context) {
|
|
44
|
-
context.setValue(this._options.name, "hotUpdateContext", this.
|
|
33
|
+
context.setValue(this._options.name, "hotUpdateContext", this.updatePlugin);
|
|
45
34
|
await super.run(env, context);
|
|
46
35
|
}
|
|
47
36
|
static findBundle(context) {
|
|
@@ -73,14 +62,15 @@ class CacheProcessor extends basic_1.BasicProcessor {
|
|
|
73
62
|
}
|
|
74
63
|
async afterAll(context) {
|
|
75
64
|
await super.afterAll(context);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
65
|
+
const updateIndex = this.updatePlugin.getUpdateIndex();
|
|
66
|
+
const totalUpdates = this.updatePlugin.getTotalUpdates();
|
|
67
|
+
if (updateIndex + 1 !== totalUpdates) {
|
|
68
|
+
throw new Error(`Should run all hot steps (${updateIndex + 1} / ${totalUpdates}): ${this._options.name}`);
|
|
79
69
|
}
|
|
80
70
|
}
|
|
81
71
|
static defaultOptions(context) {
|
|
82
72
|
const options = {
|
|
83
|
-
context:
|
|
73
|
+
context: this._cacheOptions.tempDir,
|
|
84
74
|
mode: "production",
|
|
85
75
|
cache: true,
|
|
86
76
|
devtool: false,
|
|
@@ -114,6 +104,8 @@ class CacheProcessor extends basic_1.BasicProcessor {
|
|
|
114
104
|
if (!options.entry) {
|
|
115
105
|
options.entry = "./index.js";
|
|
116
106
|
}
|
|
107
|
+
// rewrite context to temp dir
|
|
108
|
+
options.context = this._cacheOptions.tempDir;
|
|
117
109
|
options.module ??= {};
|
|
118
110
|
for (const cssModuleType of ["css/auto", "css/module", "css"]) {
|
|
119
111
|
options.module.generator ??= {};
|
|
@@ -121,19 +113,14 @@ class CacheProcessor extends basic_1.BasicProcessor {
|
|
|
121
113
|
options.module.generator[cssModuleType].exportsOnly ??=
|
|
122
114
|
this._cacheOptions.target === "async-node";
|
|
123
115
|
}
|
|
124
|
-
options.module.rules ??= [];
|
|
125
|
-
options.module.rules.push({
|
|
126
|
-
test: /\.(js|css|json)/,
|
|
127
|
-
use: [
|
|
128
|
-
{
|
|
129
|
-
loader: node_path_1.default.resolve(__dirname, "../helper/loaders/hot-update.js"),
|
|
130
|
-
options: this.updateOptions
|
|
131
|
-
}
|
|
132
|
-
]
|
|
133
|
-
});
|
|
134
116
|
if (this._cacheOptions.compilerType === type_1.ECompilerType.Rspack) {
|
|
135
117
|
options.plugins ??= [];
|
|
136
|
-
options.plugins.push(
|
|
118
|
+
options.plugins.push(this.updatePlugin);
|
|
119
|
+
}
|
|
120
|
+
if (!global.printLogger) {
|
|
121
|
+
options.infrastructureLogging = {
|
|
122
|
+
level: "error"
|
|
123
|
+
};
|
|
137
124
|
}
|
|
138
125
|
}
|
|
139
126
|
}
|
|
@@ -25,5 +25,6 @@ export declare class DefaultsConfigProcessor<T extends ECompilerType> extends Si
|
|
|
25
25
|
afterAll(context: ITestContext): Promise<void>;
|
|
26
26
|
protected getCompiler(context: ITestContext): import("../type").ITestCompilerManager<T>;
|
|
27
27
|
static getDefaultConfig(cwd: string, config: TCompilerOptions<ECompilerType>): TCompilerOptions<ECompilerType>;
|
|
28
|
+
static overrideOptions<T extends ECompilerType>(options: TCompilerOptions<T>): void;
|
|
28
29
|
}
|
|
29
30
|
export {};
|
|
@@ -61,5 +61,12 @@ class DefaultsConfigProcessor extends simple_1.SimpleTaskProcessor {
|
|
|
61
61
|
process.chdir(CURRENT_CWD);
|
|
62
62
|
return normalizedConfig;
|
|
63
63
|
}
|
|
64
|
+
static overrideOptions(options) {
|
|
65
|
+
if (!global.printLogger) {
|
|
66
|
+
options.infrastructureLogging = {
|
|
67
|
+
level: "error"
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
64
71
|
}
|
|
65
72
|
exports.DefaultsConfigProcessor = DefaultsConfigProcessor;
|
|
@@ -9,4 +9,5 @@ export declare class DiagnosticProcessor<T extends ECompilerType> extends BasicP
|
|
|
9
9
|
constructor(_diagnosticOptions: IDiagnosticProcessorOptions<T>);
|
|
10
10
|
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
11
11
|
static defaultOptions<T extends ECompilerType>(context: ITestContext): TCompilerOptions<T>;
|
|
12
|
+
static overrideOptions<T extends ECompilerType>(options: TCompilerOptions<T>): void;
|
|
12
13
|
}
|
|
@@ -62,5 +62,12 @@ class DiagnosticProcessor extends basic_1.BasicProcessor {
|
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
+
static overrideOptions(options) {
|
|
66
|
+
if (!global.printLogger) {
|
|
67
|
+
options.infrastructureLogging = {
|
|
68
|
+
level: "error"
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
65
72
|
}
|
|
66
73
|
exports.DiagnosticProcessor = DiagnosticProcessor;
|
package/dist/processor/hash.js
CHANGED
|
@@ -53,6 +53,11 @@ class HashProcessor extends multi_1.MultiTaskProcessor {
|
|
|
53
53
|
if (!options.entry) {
|
|
54
54
|
options.entry = "./index.js";
|
|
55
55
|
}
|
|
56
|
+
if (!global.printLogger) {
|
|
57
|
+
options.infrastructureLogging = {
|
|
58
|
+
level: "error"
|
|
59
|
+
};
|
|
60
|
+
}
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
exports.HashProcessor = HashProcessor;
|
package/dist/processor/hook.d.ts
CHANGED
|
@@ -40,4 +40,5 @@ export declare class HookTaskProcessor<T extends ECompilerType> extends Snapshot
|
|
|
40
40
|
compiler(context: ITestContext): Promise<void>;
|
|
41
41
|
check(env: ITestEnv, context: HookCasesContext): Promise<void>;
|
|
42
42
|
static defaultOptions<T extends ECompilerType>(context: ITestContext): TCompilerOptions<T>;
|
|
43
|
+
static overrideOptions<T extends ECompilerType>(options: TCompilerOptions<T>): void;
|
|
43
44
|
}
|
package/dist/processor/hook.js
CHANGED
|
@@ -193,5 +193,12 @@ class HookTaskProcessor extends snapshot_1.SnapshotProcessor {
|
|
|
193
193
|
}
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
|
+
static overrideOptions(options) {
|
|
197
|
+
if (!global.printLogger) {
|
|
198
|
+
options.infrastructureLogging = {
|
|
199
|
+
level: "error"
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
196
203
|
}
|
|
197
204
|
exports.HookTaskProcessor = HookTaskProcessor;
|
package/dist/processor/hot.js
CHANGED
|
@@ -113,13 +113,13 @@ class HotProcessor extends basic_1.BasicProcessor {
|
|
|
113
113
|
}
|
|
114
114
|
options.module.rules ??= [];
|
|
115
115
|
options.module.rules.push({
|
|
116
|
-
test: /\.(js|css|json)/,
|
|
117
116
|
use: [
|
|
118
117
|
{
|
|
119
118
|
loader: node_path_1.default.resolve(__dirname, "../helper/loaders/hot-update.js"),
|
|
120
119
|
options: this.updateOptions
|
|
121
120
|
}
|
|
122
|
-
]
|
|
121
|
+
],
|
|
122
|
+
enforce: "pre"
|
|
123
123
|
});
|
|
124
124
|
if (this._hotOptions.compilerType === type_1.ECompilerType.Rspack) {
|
|
125
125
|
options.plugins ??= [];
|
|
@@ -8,4 +8,5 @@ export declare class NormalProcessor<T extends ECompilerType> extends BasicProce
|
|
|
8
8
|
protected _normalOptions: INormalProcessorOptions<T>;
|
|
9
9
|
constructor(_normalOptions: INormalProcessorOptions<T>);
|
|
10
10
|
static defaultOptions<T extends ECompilerType>(this: NormalProcessor<T>, context: ITestContext): TCompilerOptions<T>;
|
|
11
|
+
static overrideOptions<T extends ECompilerType>(options: TCompilerOptions<T>): void;
|
|
11
12
|
}
|
package/dist/processor/normal.js
CHANGED
|
@@ -139,5 +139,12 @@ class NormalProcessor extends basic_1.BasicProcessor {
|
|
|
139
139
|
// }
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
|
+
static overrideOptions(options) {
|
|
143
|
+
if (!global.printLogger) {
|
|
144
|
+
options.infrastructureLogging = {
|
|
145
|
+
level: "error"
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
142
149
|
}
|
|
143
150
|
exports.NormalProcessor = NormalProcessor;
|
|
@@ -14,6 +14,11 @@ class StatsAPIProcessor extends simple_1.SimpleTaskProcessor {
|
|
|
14
14
|
res.experiments.rspackFuture ??= {};
|
|
15
15
|
res.experiments.rspackFuture.bundlerInfo ??= {};
|
|
16
16
|
res.experiments.rspackFuture.bundlerInfo.force ??= false;
|
|
17
|
+
if (!global.printLogger) {
|
|
18
|
+
res.infrastructureLogging = {
|
|
19
|
+
level: "error"
|
|
20
|
+
};
|
|
21
|
+
}
|
|
17
22
|
return res;
|
|
18
23
|
},
|
|
19
24
|
build: _statsAPIOptions.build,
|
package/dist/processor/stats.js
CHANGED
|
@@ -196,6 +196,11 @@ class StatsProcessor extends multi_1.MultiTaskProcessor {
|
|
|
196
196
|
if (options.optimization.minimize === undefined) {
|
|
197
197
|
options.optimization.minimize = false;
|
|
198
198
|
}
|
|
199
|
+
if (!global.printLogger) {
|
|
200
|
+
options.infrastructureLogging = {
|
|
201
|
+
level: "error"
|
|
202
|
+
};
|
|
203
|
+
}
|
|
199
204
|
}
|
|
200
205
|
}
|
|
201
206
|
exports.StatsProcessor = StatsProcessor;
|
|
@@ -20,6 +20,11 @@ class TreeShakingProcessor extends snapshot_1.SnapshotProcessor {
|
|
|
20
20
|
options.optimization.providedExports = true;
|
|
21
21
|
options.optimization.innerGraph = true;
|
|
22
22
|
options.optimization.usedExports = true;
|
|
23
|
+
if (!global.printLogger) {
|
|
24
|
+
options.infrastructureLogging = {
|
|
25
|
+
level: "error"
|
|
26
|
+
};
|
|
27
|
+
}
|
|
23
28
|
}
|
|
24
29
|
serializeEachFile(content) {
|
|
25
30
|
return (0, placeholder_1.normalizePlaceholder)(content);
|
package/dist/runner/cache.js
CHANGED
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CacheRunnerFactory = void 0;
|
|
7
7
|
const checkArrayExpectation_1 = __importDefault(require("../helper/legacy/checkArrayExpectation"));
|
|
8
|
-
const refreshModifyTime_1 = require("../helper/util/refreshModifyTime");
|
|
9
8
|
const type_1 = require("../type");
|
|
10
9
|
const basic_1 = require("./basic");
|
|
11
10
|
const web_1 = require("./runner/web");
|
|
@@ -17,7 +16,7 @@ class CacheRunnerFactory extends basic_1.BasicRunnerFactory {
|
|
|
17
16
|
const testConfig = this.context.getTestConfig();
|
|
18
17
|
const source = this.context.getSource();
|
|
19
18
|
const dist = this.context.getDist();
|
|
20
|
-
const
|
|
19
|
+
const updatePlugin = this.context.getValue(this.name, "hotUpdateContext");
|
|
21
20
|
const getWebRunner = () => {
|
|
22
21
|
return new web_1.WebRunner({
|
|
23
22
|
dom: this.context.getValue(this.name, "documentType") ||
|
|
@@ -45,7 +44,7 @@ class CacheRunnerFactory extends basic_1.BasicRunnerFactory {
|
|
|
45
44
|
});
|
|
46
45
|
};
|
|
47
46
|
const nextHmr = async (m, options) => {
|
|
48
|
-
|
|
47
|
+
await updatePlugin.goNext();
|
|
49
48
|
const stats = await compiler.build();
|
|
50
49
|
if (!stats) {
|
|
51
50
|
throw new Error("Should generate stats during build");
|
|
@@ -53,8 +52,9 @@ class CacheRunnerFactory extends basic_1.BasicRunnerFactory {
|
|
|
53
52
|
const jsonStats = stats.toJson({
|
|
54
53
|
// errorDetails: true
|
|
55
54
|
});
|
|
56
|
-
|
|
57
|
-
await (0, checkArrayExpectation_1.default)(source, jsonStats, "
|
|
55
|
+
const updateIndex = updatePlugin.getUpdateIndex();
|
|
56
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error");
|
|
57
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning");
|
|
58
58
|
const updatedModules = await m.hot.check(options || true);
|
|
59
59
|
if (!updatedModules) {
|
|
60
60
|
throw new Error("No update available");
|
|
@@ -64,22 +64,17 @@ class CacheRunnerFactory extends basic_1.BasicRunnerFactory {
|
|
|
64
64
|
const nextStart = async () => {
|
|
65
65
|
await compiler.close();
|
|
66
66
|
compiler.createCompiler();
|
|
67
|
-
|
|
68
|
-
await Promise.all(oldChangedFiles.map(async (file) => {
|
|
69
|
-
await (0, refreshModifyTime_1.refreshModifyTime)(file);
|
|
70
|
-
}));
|
|
71
|
-
hotUpdateContext.changedFiles = [];
|
|
72
|
-
hotUpdateContext.updateIndex++;
|
|
67
|
+
await updatePlugin.goNext();
|
|
73
68
|
const stats = await compiler.build();
|
|
74
|
-
hotUpdateContext.changedFiles = oldChangedFiles;
|
|
75
69
|
if (!stats) {
|
|
76
70
|
throw new Error("Should generate stats during build");
|
|
77
71
|
}
|
|
78
72
|
const jsonStats = stats.toJson({
|
|
79
73
|
// errorDetails: true
|
|
80
74
|
});
|
|
81
|
-
|
|
82
|
-
await (0, checkArrayExpectation_1.default)(source, jsonStats, "
|
|
75
|
+
const updateIndex = updatePlugin.getUpdateIndex();
|
|
76
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, "error", `errors${updateIndex}`, "Error");
|
|
77
|
+
await (0, checkArrayExpectation_1.default)(source, jsonStats, "warning", `warnings${updateIndex}`, "Warning");
|
|
83
78
|
env.it(`NEXT_START run with compilerIndex==${compilerIndex + 1}`, async () => {
|
|
84
79
|
if (compilerIndex > MAX_COMPILER_INDEX) {
|
|
85
80
|
throw new Error("NEXT_START has been called more than the maximum times");
|
package/dist/runner/hot-step.js
CHANGED
|
@@ -67,9 +67,10 @@ class HotStepRunnerFactory extends hot_1.HotRunnerFactory {
|
|
|
67
67
|
testConfig: {
|
|
68
68
|
...testConfig,
|
|
69
69
|
moduleScope(ms, stats) {
|
|
70
|
-
const moduleScope =
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
const moduleScope = ms;
|
|
71
|
+
if (typeof testConfig.moduleScope === "function") {
|
|
72
|
+
testConfig.moduleScope(moduleScope, stats);
|
|
73
|
+
}
|
|
73
74
|
moduleScope.NEXT = next;
|
|
74
75
|
moduleScope.NEXT_HMR = nextHMR;
|
|
75
76
|
return moduleScope;
|
package/dist/runner/hot.js
CHANGED
|
@@ -64,9 +64,10 @@ class HotRunnerFactory extends basic_1.BasicRunnerFactory {
|
|
|
64
64
|
documentType: testConfig.documentType || type_1.EDocumentType.Fake,
|
|
65
65
|
...testConfig,
|
|
66
66
|
moduleScope(ms, stats) {
|
|
67
|
-
const moduleScope =
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
const moduleScope = ms;
|
|
68
|
+
if (typeof testConfig.moduleScope === "function") {
|
|
69
|
+
testConfig.moduleScope(moduleScope, stats);
|
|
70
|
+
}
|
|
70
71
|
moduleScope.NEXT = next;
|
|
71
72
|
moduleScope.NEXT_HMR = nextHMR;
|
|
72
73
|
return moduleScope;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/test-tools",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"iconv-lite": "^0.6.3",
|
|
46
46
|
"jest-diff": "^29.7.0",
|
|
47
47
|
"jest-snapshot": "29.7.0",
|
|
48
|
-
"jsdom": "^26.
|
|
48
|
+
"jsdom": "^26.1.0",
|
|
49
49
|
"loader-utils": "^2.0.4",
|
|
50
50
|
"memfs": "4.17.0",
|
|
51
51
|
"path-serializer": "0.3.4",
|
|
@@ -53,21 +53,21 @@
|
|
|
53
53
|
"rimraf": "^5.0.10",
|
|
54
54
|
"source-map": "^0.7.4",
|
|
55
55
|
"terser-webpack-plugin": "^5.3.14",
|
|
56
|
-
"webpack": "5.
|
|
56
|
+
"webpack": "5.99.6",
|
|
57
57
|
"webpack-merge": "5.10.0",
|
|
58
58
|
"webpack-sources": "3.2.3"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@rspack/plugin-preact-refresh": "1.1.2",
|
|
62
|
-
"@rspack/plugin-react-refresh": "^1.1
|
|
63
|
-
"@swc/helpers": "0.5.
|
|
64
|
-
"@swc/plugin-remove-console": "^7.0.
|
|
62
|
+
"@rspack/plugin-react-refresh": "^1.2.1",
|
|
63
|
+
"@swc/helpers": "0.5.17",
|
|
64
|
+
"@swc/plugin-remove-console": "^7.0.3",
|
|
65
65
|
"@types/babel__generator": "7.27.0",
|
|
66
66
|
"@types/babel__traverse": "7.20.7",
|
|
67
67
|
"@types/fs-extra": "11.0.4",
|
|
68
68
|
"@types/jsdom": "^21.1.7",
|
|
69
|
-
"@types/react": "^19.1.
|
|
70
|
-
"@types/react-dom": "^19.1.
|
|
69
|
+
"@types/react": "^19.1.2",
|
|
70
|
+
"@types/react-dom": "^19.1.2",
|
|
71
71
|
"@types/webpack": "5.28.5",
|
|
72
72
|
"@types/webpack-sources": "3.2.3",
|
|
73
73
|
"@webdiscus/pug-loader": "^2.11.1",
|
|
@@ -86,8 +86,8 @@
|
|
|
86
86
|
"postcss-loader": "^8.1.1",
|
|
87
87
|
"postcss-pxtorem": "^6.1.0",
|
|
88
88
|
"raw-loader": "^4.0.2",
|
|
89
|
-
"react": "^19.
|
|
90
|
-
"react-dom": "^19.
|
|
89
|
+
"react": "^19.1.0",
|
|
90
|
+
"react-dom": "^19.1.0",
|
|
91
91
|
"react-refresh": "^0.17.0",
|
|
92
92
|
"sass-loader": "^16.0.5",
|
|
93
93
|
"source-map": "^0.7.4",
|
|
@@ -97,9 +97,9 @@
|
|
|
97
97
|
"typescript": "^5.7.3",
|
|
98
98
|
"wast-loader": "^1.14.1",
|
|
99
99
|
"worker-rspack-loader": "^3.1.2",
|
|
100
|
-
"@rspack/cli": "1.3.
|
|
101
|
-
"@rspack/
|
|
102
|
-
"@rspack/
|
|
100
|
+
"@rspack/cli": "1.3.6",
|
|
101
|
+
"@rspack/core": "1.3.6",
|
|
102
|
+
"@rspack/test-tools": "1.3.6"
|
|
103
103
|
},
|
|
104
104
|
"peerDependencies": {
|
|
105
105
|
"@rspack/core": ">=1.0.0"
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"scripts": {
|
|
108
108
|
"build": "tsc -b ./tsconfig.build.json",
|
|
109
109
|
"dev": "tsc -b -w",
|
|
110
|
-
"test": "pnpm run --stream /^test:.*/",
|
|
110
|
+
"test": "cross-env RUST_BACKTRACE=full pnpm run --stream /^test:.*/",
|
|
111
111
|
"testu": "pnpm run --stream /^test:.*/ -u",
|
|
112
112
|
"test:base": "cross-env node --no-warnings --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --colors --config ./jest.config.js --passWithNoTests",
|
|
113
113
|
"test:hot": "cross-env RSPACK_HOT_TEST=true node --no-warnings --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --colors --config ./jest.config.hot.js --passWithNoTests",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function refreshModifyTime(file: string): Promise<void>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.refreshModifyTime = refreshModifyTime;
|
|
4
|
-
const fs_extra_1 = require("fs-extra");
|
|
5
|
-
async function refreshModifyTime(file) {
|
|
6
|
-
const data = await (0, fs_extra_1.readFile)(file);
|
|
7
|
-
await (0, fs_extra_1.writeFile)(file, data);
|
|
8
|
-
}
|