@rspack/test-tools 1.0.4 → 1.0.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.
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ECompilerType, TCompilerOptions } from "../type";
|
|
2
|
-
export declare function readConfigFile<T extends ECompilerType>(files: string[]): TCompilerOptions<T>[];
|
|
2
|
+
export declare function readConfigFile<T extends ECompilerType>(files: string[], functionApply?: (config: (TCompilerOptions<T> | ((...args: unknown[]) => TCompilerOptions<T>))[]) => TCompilerOptions<T>[]): TCompilerOptions<T>[];
|
|
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.readConfigFile = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
-
function readConfigFile(files) {
|
|
8
|
+
function readConfigFile(files, functionApply) {
|
|
9
9
|
const existsFile = files.find(i => fs_extra_1.default.existsSync(i));
|
|
10
10
|
const fileConfig = existsFile ? require(existsFile) : {};
|
|
11
|
-
|
|
11
|
+
const configArr = Array.isArray(fileConfig) ? fileConfig : [fileConfig];
|
|
12
|
+
return functionApply ? functionApply(configArr) : configArr;
|
|
12
13
|
}
|
|
13
14
|
exports.readConfigFile = readConfigFile;
|
package/dist/processor/multi.js
CHANGED
|
@@ -43,7 +43,18 @@ class MultiTaskProcessor extends basic_1.BasicProcessor {
|
|
|
43
43
|
async config(context) {
|
|
44
44
|
this.multiCompilerOptions = [];
|
|
45
45
|
const caseOptions = Array.isArray(this._multiOptions.configFiles)
|
|
46
|
-
? (0, helper_1.readConfigFile)(this._multiOptions.configFiles.map(i => context.getSource(i))
|
|
46
|
+
? (0, helper_1.readConfigFile)(this._multiOptions.configFiles.map(i => context.getSource(i)), configs => {
|
|
47
|
+
return configs.flatMap(c => {
|
|
48
|
+
if (typeof c === "function") {
|
|
49
|
+
const options = {
|
|
50
|
+
testPath: context.getDist(),
|
|
51
|
+
env: undefined
|
|
52
|
+
};
|
|
53
|
+
return c(options.env, options);
|
|
54
|
+
}
|
|
55
|
+
return c;
|
|
56
|
+
});
|
|
57
|
+
})
|
|
47
58
|
: [{}];
|
|
48
59
|
for (const [index, options] of caseOptions.entries()) {
|
|
49
60
|
const compilerOptions = (0, webpack_merge_1.merge)(typeof this._multiOptions.defaultOptions === "function"
|
|
@@ -17,7 +17,9 @@ export declare class WatchProcessor<T extends ECompilerType> extends MultiTaskPr
|
|
|
17
17
|
build(context: ITestContext): Promise<void>;
|
|
18
18
|
run(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
19
19
|
check(env: ITestEnv, context: ITestContext): Promise<void>;
|
|
20
|
+
config(context: ITestContext): Promise<void>;
|
|
20
21
|
static overrideOptions<T extends ECompilerType>({ tempDir, name, experiments, optimization }: IWatchProcessorOptions<T>): (index: number, context: ITestContext, options: TCompilerOptions<ECompilerType>) => void;
|
|
22
|
+
static findBundle<T extends ECompilerType>(index: number, context: ITestContext, options: TCompilerOptions<T>): string | string[];
|
|
21
23
|
}
|
|
22
24
|
export interface IWatchStepProcessorOptions<T extends ECompilerType> extends Omit<IWatchProcessorOptions<T>, "experiments" | "optimization"> {
|
|
23
25
|
}
|
package/dist/processor/watch.js
CHANGED
|
@@ -6,9 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.WatchStepProcessor = exports.WatchProcessor = void 0;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const webpack_merge_1 = require("webpack-merge");
|
|
9
10
|
const compiler_1 = require("../compiler");
|
|
11
|
+
const helper_1 = require("../helper");
|
|
10
12
|
const copyDiff_1 = __importDefault(require("../helper/legacy/copyDiff"));
|
|
11
|
-
const config_1 = require("./config");
|
|
12
13
|
const multi_1 = require("./multi");
|
|
13
14
|
// This file is used to port step number to rspack.config.js/webpack.config.js
|
|
14
15
|
const currentWatchStepModulePath = node_path_1.default.resolve(__dirname, "../helper/util/currentWatchStep");
|
|
@@ -16,7 +17,7 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
|
|
|
16
17
|
constructor(_watchOptions) {
|
|
17
18
|
super({
|
|
18
19
|
overrideOptions: WatchProcessor.overrideOptions(_watchOptions),
|
|
19
|
-
findBundle: (
|
|
20
|
+
findBundle: (WatchProcessor.findBundle),
|
|
20
21
|
..._watchOptions
|
|
21
22
|
});
|
|
22
23
|
this._watchOptions = _watchOptions;
|
|
@@ -56,6 +57,26 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
|
|
|
56
57
|
node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.txt"), node_path_1.default.join(context.getDist(), `stats.${this._watchOptions.stepName}.txt`));
|
|
57
58
|
node_fs_1.default.renameSync(node_path_1.default.join(context.getDist(), "stats.json"), node_path_1.default.join(context.getDist(), `stats.${this._watchOptions.stepName}.json`));
|
|
58
59
|
}
|
|
60
|
+
async config(context) {
|
|
61
|
+
this.multiCompilerOptions = [];
|
|
62
|
+
const caseOptions = Array.isArray(this._multiOptions.configFiles)
|
|
63
|
+
? (0, helper_1.readConfigFile)(this._multiOptions.configFiles.map(i => context.getSource(i)))
|
|
64
|
+
: [{}];
|
|
65
|
+
for (const [index, options] of caseOptions.entries()) {
|
|
66
|
+
const compilerOptions = (0, webpack_merge_1.merge)(typeof this._multiOptions.defaultOptions === "function"
|
|
67
|
+
? this._multiOptions.defaultOptions(index, context)
|
|
68
|
+
: {}, options);
|
|
69
|
+
if (typeof this._multiOptions.overrideOptions === "function") {
|
|
70
|
+
this._multiOptions.overrideOptions(index, context, compilerOptions);
|
|
71
|
+
}
|
|
72
|
+
this.multiCompilerOptions.push(compilerOptions);
|
|
73
|
+
}
|
|
74
|
+
const compilerOptions = this.multiCompilerOptions.length === 1
|
|
75
|
+
? this.multiCompilerOptions[0]
|
|
76
|
+
: this.multiCompilerOptions;
|
|
77
|
+
const compiler = this.getCompiler(context);
|
|
78
|
+
compiler.setOptions(compilerOptions);
|
|
79
|
+
}
|
|
59
80
|
static overrideOptions({ tempDir, name, experiments, optimization }) {
|
|
60
81
|
return (index, context, options) => {
|
|
61
82
|
if (!options.mode)
|
|
@@ -66,6 +87,8 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
|
|
|
66
87
|
options.entry = "./index.js";
|
|
67
88
|
if (!options.target)
|
|
68
89
|
options.target = "async-node";
|
|
90
|
+
if (!options.devtool)
|
|
91
|
+
options.devtool = false;
|
|
69
92
|
if (!options.output)
|
|
70
93
|
options.output = {};
|
|
71
94
|
if (!options.output.path)
|
|
@@ -103,6 +126,13 @@ class WatchProcessor extends multi_1.MultiTaskProcessor {
|
|
|
103
126
|
options.experiments.rspackFuture.bundlerInfo.force ??= false;
|
|
104
127
|
};
|
|
105
128
|
}
|
|
129
|
+
static findBundle(index, context, options) {
|
|
130
|
+
const testConfig = context.getTestConfig();
|
|
131
|
+
if (typeof testConfig.findBundle === "function") {
|
|
132
|
+
return testConfig.findBundle(index, options);
|
|
133
|
+
}
|
|
134
|
+
return "./bundle.js";
|
|
135
|
+
}
|
|
106
136
|
}
|
|
107
137
|
exports.WatchProcessor = WatchProcessor;
|
|
108
138
|
class WatchStepProcessor extends WatchProcessor {
|
|
@@ -18,6 +18,7 @@ class WatchRunner extends fake_1.FakeDocumentWebRunner {
|
|
|
18
18
|
moduleScope.document = this.globalContext.document;
|
|
19
19
|
moduleScope.STATE = this.state;
|
|
20
20
|
moduleScope.WATCH_STEP = this._watchOptions.stepName;
|
|
21
|
+
moduleScope.STATS_JSON = this._options.stats;
|
|
21
22
|
return moduleScope;
|
|
22
23
|
}
|
|
23
24
|
run(file) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/test-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Test tools for rspack",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -58,6 +58,8 @@
|
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@arco-design/web-react": "^2.56.1",
|
|
60
60
|
"@monaco-editor/react": "^4.6.0",
|
|
61
|
+
"@rspack/plugin-preact-refresh": "1.0.0",
|
|
62
|
+
"@rspack/plugin-react-refresh": "1.0.0",
|
|
61
63
|
"@swc/helpers": "0.5.8",
|
|
62
64
|
"@swc/plugin-remove-console": "^2.0.8",
|
|
63
65
|
"@types/babel__generator": "7.6.8",
|
|
@@ -100,8 +102,8 @@
|
|
|
100
102
|
"terser": "5.27.2",
|
|
101
103
|
"typescript": "5.0.2",
|
|
102
104
|
"wast-loader": "^1.12.1",
|
|
103
|
-
"@rspack/
|
|
104
|
-
"@rspack/
|
|
105
|
+
"@rspack/core": "1.0.6",
|
|
106
|
+
"@rspack/cli": "1.0.6"
|
|
105
107
|
},
|
|
106
108
|
"peerDependencies": {
|
|
107
109
|
"@rspack/core": ">=0.7.0"
|
|
@@ -112,7 +114,7 @@
|
|
|
112
114
|
"dev:viewer": "rspack serve",
|
|
113
115
|
"dev": "tsc -b -w",
|
|
114
116
|
"test": "sh -c 'run-s \"test:* -- $*\"' sh",
|
|
115
|
-
"testu": "sh -c 'run-s \"test:* -u
|
|
117
|
+
"testu": "sh -c 'run-s \"test:* -- -u $*\"' sh",
|
|
116
118
|
"test:base": "cross-env NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --colors --config ./jest.config.js --passWithNoTests",
|
|
117
119
|
"test:hot": "cross-env RSPACK_HOT_TEST=true NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --colors --config ./jest.config.hot.js --passWithNoTests",
|
|
118
120
|
"test:diff": "cross-env RSPACK_DIFF=true NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ../../node_modules/jest-cli/bin/jest --logHeapUsage --colors --config ./jest.config.diff.js --passWithNoTests",
|