@nx/rspack 24.0.0-beta.2 → 24.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ready-check.d.ts +1 -0
- package/dist/ready-check.js +9 -0
- package/dist/ready-signal.d.ts +1 -0
- package/dist/ready-signal.js +5 -0
- package/dist/src/executors/dev-server/dev-server.impl.js +0 -2
- package/dist/src/executors/rspack/lib/config.js +18 -8
- package/dist/src/generators/configuration/configuration.js +5 -29
- package/dist/src/generators/configuration/schema.json +2 -2
- package/dist/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +78 -45
- package/dist/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.d.ts +1 -0
- package/dist/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.js +31 -2
- package/dist/src/generators/convert-config-to-rspack-plugin/schema.json +2 -2
- package/dist/src/generators/convert-to-inferred/convert-to-inferred.js +5 -4
- package/dist/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +13 -5
- package/dist/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +8 -14
- package/dist/src/generators/convert-webpack/convert-webpack.js +20 -74
- package/dist/src/generators/convert-webpack/lib/transform-plugin-config.d.ts +1 -1
- package/dist/src/generators/convert-webpack/lib/transform-plugin-config.js +47 -69
- package/dist/src/generators/init/init.js +38 -44
- package/dist/src/generators/init/schema.d.ts +0 -1
- package/dist/src/migrations/update-24-0-0/finish-inferred-conversion.md +11 -0
- package/dist/src/migrations/update-24-0-0/inventory.d.ts +9 -0
- package/dist/src/migrations/update-24-0-0/inventory.js +53 -0
- package/dist/src/migrations/update-24-0-0/migrate-compose-plugins.d.ts +10 -0
- package/dist/src/migrations/update-24-0-0/migrate-compose-plugins.js +60 -0
- package/dist/src/migrations/update-24-0-0/migrate-compose-plugins.md +95 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.d.ts +6 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.js +36 -0
- package/dist/src/migrations/update-24-0-0/remove-deprecated-executors.md +90 -0
- package/dist/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.d.ts +2 -0
- package/dist/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +10 -1
- package/dist/src/plugins/plugin.js +21 -0
- package/dist/src/utils/config.d.ts +10 -14
- package/dist/src/utils/config.js +17 -70
- package/dist/src/utils/deprecation.d.ts +1 -6
- package/dist/src/utils/deprecation.js +4 -23
- package/dist/src/utils/dev-server-ready-check.d.ts +48 -0
- package/dist/src/utils/dev-server-ready-check.js +339 -0
- package/dist/src/utils/dev-server-ready-signal.d.ts +29 -0
- package/dist/src/utils/dev-server-ready-signal.js +60 -0
- package/dist/src/utils/e2e-web-server-info-utils.d.ts +1 -1
- package/dist/src/utils/e2e-web-server-info-utils.js +2 -2
- package/dist/src/utils/generator-utils.d.ts +1 -2
- package/dist/src/utils/generator-utils.js +69 -185
- package/dist/src/utils/read-rspack-options.d.ts +1 -1
- package/dist/src/utils/read-rspack-options.js +4 -4
- package/dist/src/utils/with-nx.d.ts +5 -9
- package/dist/src/utils/with-nx.js +5 -32
- package/dist/src/utils/with-react.d.ts +5 -8
- package/dist/src/utils/with-react.js +5 -15
- package/dist/src/utils/with-web.d.ts +5 -8
- package/dist/src/utils/with-web.js +5 -44
- package/executors.json +0 -25
- package/migrations.json +13 -0
- package/package.json +39 -26
- package/dist/module-federation.d.ts +0 -4
- package/dist/module-federation.js +0 -9
- package/dist/src/executors/module-federation-dev-server/lib/index.d.ts +0 -2
- package/dist/src/executors/module-federation-dev-server/lib/index.js +0 -5
- package/dist/src/executors/module-federation-dev-server/lib/normalize-options.d.ts +0 -4
- package/dist/src/executors/module-federation-dev-server/lib/normalize-options.js +0 -19
- package/dist/src/executors/module-federation-dev-server/lib/start-remotes.d.ts +0 -5
- package/dist/src/executors/module-federation-dev-server/lib/start-remotes.js +0 -33
- package/dist/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +0 -6
- package/dist/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +0 -74
- package/dist/src/executors/module-federation-dev-server/schema.d.ts +0 -25
- package/dist/src/executors/module-federation-dev-server/schema.json +0 -104
- package/dist/src/executors/module-federation-ssr-dev-server/lib/index.d.ts +0 -2
- package/dist/src/executors/module-federation-ssr-dev-server/lib/index.js +0 -5
- package/dist/src/executors/module-federation-ssr-dev-server/lib/normalize-options.d.ts +0 -4
- package/dist/src/executors/module-federation-ssr-dev-server/lib/normalize-options.js +0 -23
- package/dist/src/executors/module-federation-ssr-dev-server/lib/start-remotes.d.ts +0 -5
- package/dist/src/executors/module-federation-ssr-dev-server/lib/start-remotes.js +0 -34
- package/dist/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +0 -5
- package/dist/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +0 -65
- package/dist/src/executors/module-federation-ssr-dev-server/schema.d.ts +0 -29
- package/dist/src/executors/module-federation-ssr-dev-server/schema.json +0 -85
- package/dist/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +0 -12
- package/dist/src/executors/module-federation-static-server/module-federation-static-server.impl.js +0 -237
- package/dist/src/executors/module-federation-static-server/schema.d.ts +0 -3
- package/dist/src/executors/module-federation-static-server/schema.json +0 -16
- package/dist/src/executors/rspack/rspack.impl.d.ts +0 -7
- package/dist/src/executors/rspack/rspack.impl.js +0 -127
- package/dist/src/executors/rspack/schema.json +0 -410
- package/dist/src/generators/convert-webpack/lib/transform-cjs.d.ts +0 -2
- package/dist/src/generators/convert-webpack/lib/transform-cjs.js +0 -263
- package/dist/src/generators/convert-webpack/lib/transform-esm.d.ts +0 -2
- package/dist/src/generators/convert-webpack/lib/transform-esm.js +0 -263
- package/dist/src/utils/has-plugin.d.ts +0 -2
- package/dist/src/utils/has-plugin.js +0 -10
- package/dist/src/utils/module-federation-deprecation.d.ts +0 -6
- package/dist/src/utils/module-federation-deprecation.js +0 -30
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseServeFlags = parseServeFlags;
|
|
4
|
+
exports.parseServeArgv = parseServeArgv;
|
|
5
|
+
exports.getDevServerAddress = getDevServerAddress;
|
|
6
|
+
exports.waitForAddresses = waitForAddresses;
|
|
7
|
+
exports.readTaskOptions = readTaskOptions;
|
|
8
|
+
exports.enterTaskCwd = enterTaskCwd;
|
|
9
|
+
exports.waitForRspackDevServer = waitForRspackDevServer;
|
|
10
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
11
|
+
const fs_1 = require("fs");
|
|
12
|
+
const net_1 = require("net");
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const semver_1 = require("semver");
|
|
15
|
+
const url_1 = require("url");
|
|
16
|
+
/**
|
|
17
|
+
* The flags `rspack serve` takes from the target's options. run-commands
|
|
18
|
+
* forwards named options, then `args`, then overrides, and a later source wins.
|
|
19
|
+
*/
|
|
20
|
+
function parseServeFlags(options) {
|
|
21
|
+
const args = parseArgs(splitArgs(options.args));
|
|
22
|
+
// run-commands doesn't forward `--env` overrides, since `env` is its own option
|
|
23
|
+
const overrides = parseArgs(overrideArgs(options.__unparsed__));
|
|
24
|
+
const option = (...keys) => keys
|
|
25
|
+
.map((key) => options[key])
|
|
26
|
+
.find((value) => typeof value === 'string' || typeof value === 'number')
|
|
27
|
+
?.toString();
|
|
28
|
+
// Repeated `--config-name` flags add up, and replace a named configName
|
|
29
|
+
const configNames = [...args.configNames, ...overrides.configNames];
|
|
30
|
+
const configName = option('configName', 'config-name');
|
|
31
|
+
return {
|
|
32
|
+
port: overrides.port ?? args.port ?? option('port'),
|
|
33
|
+
host: overrides.host ?? args.host ?? option('host'),
|
|
34
|
+
nodeEnv: overrides.nodeEnv ?? args.nodeEnv ?? option('nodeEnv', 'node-env'),
|
|
35
|
+
config: overrides.config ?? args.config ?? option('config', 'c'),
|
|
36
|
+
configNames: configNames.length > 0 ? configNames : configName ? [configName] : [],
|
|
37
|
+
env: args.env,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// run-commands leaves `args` for the shell to split, and quotes each override
|
|
41
|
+
// so it stays one argument
|
|
42
|
+
function splitArgs(value) {
|
|
43
|
+
return (0, internal_1.splitShellArgs)(Array.isArray(value)
|
|
44
|
+
? value.join(' ')
|
|
45
|
+
: typeof value === 'string'
|
|
46
|
+
? value
|
|
47
|
+
: '');
|
|
48
|
+
}
|
|
49
|
+
function overrideArgs(value) {
|
|
50
|
+
return Array.isArray(value) ? value.map(String) : [];
|
|
51
|
+
}
|
|
52
|
+
function parseArgs(args) {
|
|
53
|
+
const flags = { configNames: [], env: [] };
|
|
54
|
+
for (let i = 0; i < args.length; i++) {
|
|
55
|
+
const [, name, inline] = args[i].match(/^--([^=]+)(?:=(.*))?$/) ??
|
|
56
|
+
args[i].match(/^-(c)(?:=(.*))?$/) ??
|
|
57
|
+
[];
|
|
58
|
+
if (!name)
|
|
59
|
+
continue;
|
|
60
|
+
let value = inline;
|
|
61
|
+
if (value === undefined && args[i + 1] && !args[i + 1].startsWith('-')) {
|
|
62
|
+
value = args[++i];
|
|
63
|
+
}
|
|
64
|
+
if (name === 'port')
|
|
65
|
+
flags.port = value;
|
|
66
|
+
else if (name === 'host')
|
|
67
|
+
flags.host = value;
|
|
68
|
+
else if (name === 'node-env')
|
|
69
|
+
flags.nodeEnv = value;
|
|
70
|
+
else if (name === 'config' || name === 'c')
|
|
71
|
+
flags.config = value;
|
|
72
|
+
else if (name === 'config-name' && value)
|
|
73
|
+
flags.configNames.push(value);
|
|
74
|
+
else if (name === 'env' && value)
|
|
75
|
+
flags.env.push(value);
|
|
76
|
+
}
|
|
77
|
+
return flags;
|
|
78
|
+
}
|
|
79
|
+
const SHORT_FLAGS = {
|
|
80
|
+
c: 'config',
|
|
81
|
+
d: 'devtool',
|
|
82
|
+
m: 'mode',
|
|
83
|
+
o: 'output-path',
|
|
84
|
+
w: 'watch',
|
|
85
|
+
};
|
|
86
|
+
const ARRAY_FLAGS = new Set(['config-name', 'entry']);
|
|
87
|
+
// Named options run-commands forwards that the check reads
|
|
88
|
+
const NAMED_FLAGS = [
|
|
89
|
+
['port', 'port'],
|
|
90
|
+
['host', 'host'],
|
|
91
|
+
['mode', 'mode'],
|
|
92
|
+
['node-env', 'nodeEnv', 'node-env'],
|
|
93
|
+
['config', 'config', 'c'],
|
|
94
|
+
['config-name', 'configName', 'config-name'],
|
|
95
|
+
];
|
|
96
|
+
/**
|
|
97
|
+
* The `argv` @rspack/cli passes to a function config: its parsed options,
|
|
98
|
+
* with `env` set by the caller. Values follow its mri parser: a numeric value
|
|
99
|
+
* is a number, a bare flag is true, `--no-x` is false, a repeated flag is an
|
|
100
|
+
* array.
|
|
101
|
+
*/
|
|
102
|
+
function parseServeArgv(options, env) {
|
|
103
|
+
const tokens = [
|
|
104
|
+
...splitArgs(options.args),
|
|
105
|
+
...overrideArgs(options.__unparsed__),
|
|
106
|
+
];
|
|
107
|
+
const given = new Set(tokens.map((token) => token.match(/^--([^=]+)/)?.[1]));
|
|
108
|
+
const named = NAMED_FLAGS.flatMap(([flag, ...keys]) => {
|
|
109
|
+
const value = keys
|
|
110
|
+
.map((key) => options[key])
|
|
111
|
+
.find((v) => typeof v === 'string' || typeof v === 'number');
|
|
112
|
+
return value === undefined || given.has(flag) ? [] : [`--${flag}=${value}`];
|
|
113
|
+
});
|
|
114
|
+
const argv = {};
|
|
115
|
+
const all = [...named, ...tokens];
|
|
116
|
+
for (let i = 0; i < all.length; i++) {
|
|
117
|
+
const [, dashes, rawName, inline] = all[i].match(/^(--?)([^=]+)(?:=(.*))?$/) ?? [];
|
|
118
|
+
if (!rawName)
|
|
119
|
+
continue;
|
|
120
|
+
const flag = dashes === '-' ? SHORT_FLAGS[rawName] : rawName;
|
|
121
|
+
if (!flag)
|
|
122
|
+
continue;
|
|
123
|
+
const negated = flag.startsWith('no-');
|
|
124
|
+
const base = negated ? flag.slice(3) : flag;
|
|
125
|
+
const name = base.replace(/([a-z])-([a-z])/g, (_, a, b) => a + b.toUpperCase());
|
|
126
|
+
if (negated) {
|
|
127
|
+
argv[name] = false;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const next = inline ?? (all[i + 1] && !all[i + 1].startsWith('-') ? all[++i] : '');
|
|
131
|
+
if (flag === 'env')
|
|
132
|
+
continue;
|
|
133
|
+
const value = next === '' ? true : Number.isFinite(Number(next)) ? Number(next) : next;
|
|
134
|
+
const previous = argv[name];
|
|
135
|
+
argv[name] =
|
|
136
|
+
previous === undefined
|
|
137
|
+
? ARRAY_FLAGS.has(flag)
|
|
138
|
+
? [value]
|
|
139
|
+
: value
|
|
140
|
+
: [previous, value].flat();
|
|
141
|
+
}
|
|
142
|
+
return { ...argv, env };
|
|
143
|
+
}
|
|
144
|
+
const UNSAFE_ENV_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
145
|
+
/** The env object `rspack serve` builds from its `--env` values. */
|
|
146
|
+
function parseEnv(values) {
|
|
147
|
+
const env = {};
|
|
148
|
+
for (const value of values) {
|
|
149
|
+
const [allKeys, val] = value.split(/=(.+)/, 2);
|
|
150
|
+
const keys = allKeys.split(/\.(?!$)/);
|
|
151
|
+
if (keys.some((key) => UNSAFE_ENV_KEYS.has(key.replace(/=$/, '')))) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
let ref = env;
|
|
155
|
+
for (const [index, key] of keys.entries()) {
|
|
156
|
+
if (key.endsWith('=')) {
|
|
157
|
+
ref[key.slice(0, -1)] = undefined;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (!ref[key] || typeof ref[key] === 'string')
|
|
161
|
+
ref[key] = {};
|
|
162
|
+
if (index === keys.length - 1) {
|
|
163
|
+
ref[key] = typeof val === 'string' ? val : true;
|
|
164
|
+
}
|
|
165
|
+
ref = ref[key];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return env;
|
|
169
|
+
}
|
|
170
|
+
// `rspack serve` loads the @rspack/dev-server its own @rspack/cli resolves
|
|
171
|
+
function getDevServerMajorVersion() {
|
|
172
|
+
let cliPackageJsonPath;
|
|
173
|
+
try {
|
|
174
|
+
cliPackageJsonPath = (0, internal_1.readModulePackageJson)('@rspack/cli', [
|
|
175
|
+
process.cwd(),
|
|
176
|
+
]).path;
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
const version = (0, internal_1.getInstalledPackageVersion)('@rspack/dev-server', [
|
|
182
|
+
(0, path_1.dirname)(cliPackageJsonPath),
|
|
183
|
+
]);
|
|
184
|
+
return version ? (0, semver_1.major)(version) : null;
|
|
185
|
+
}
|
|
186
|
+
const CONFIG_EXTENSIONS = ['.ts', '.js', '.mts', '.mjs', '.cts', '.cjs'];
|
|
187
|
+
function resolveExtendedConfig(request, baseDir) {
|
|
188
|
+
if (request.startsWith('file://'))
|
|
189
|
+
return (0, url_1.fileURLToPath)(request);
|
|
190
|
+
if (request.startsWith('.') ||
|
|
191
|
+
request.startsWith('/') ||
|
|
192
|
+
request.includes(':\\')) {
|
|
193
|
+
const path = (0, path_1.resolve)(baseDir, request);
|
|
194
|
+
const found = (0, path_1.extname)(path)
|
|
195
|
+
? path
|
|
196
|
+
: CONFIG_EXTENSIONS.map((ext) => path + ext).find(fs_1.existsSync);
|
|
197
|
+
if (!found) {
|
|
198
|
+
throw new Error(`Extended configuration file "${path}" not found.`);
|
|
199
|
+
}
|
|
200
|
+
return found;
|
|
201
|
+
}
|
|
202
|
+
return require.resolve(request, { paths: [baseDir, process.cwd()] });
|
|
203
|
+
}
|
|
204
|
+
/** Applies `extends` the way `rspack serve` does. */
|
|
205
|
+
async function applyExtends(config, configPath, load, extending = []) {
|
|
206
|
+
if (extending.includes(configPath)) {
|
|
207
|
+
throw new Error(`Recursive configuration detected. Config file "${configPath}" extends itself.`);
|
|
208
|
+
}
|
|
209
|
+
let merged = config;
|
|
210
|
+
for (const request of config.extends ? [config.extends].flat() : []) {
|
|
211
|
+
const path = resolveExtendedConfig(request, (0, path_1.dirname)(configPath));
|
|
212
|
+
const base = await load(path);
|
|
213
|
+
merged = mergeExtendedConfig(isPlainObject(base)
|
|
214
|
+
? await applyExtends(base, path, load, [...extending, configPath])
|
|
215
|
+
: {}, merged);
|
|
216
|
+
}
|
|
217
|
+
return merged;
|
|
218
|
+
}
|
|
219
|
+
// Merges the fields read here as both @rspack/cli majors do: the extending
|
|
220
|
+
// config wins unless undefined, and devServer objects merge by key
|
|
221
|
+
function mergeExtendedConfig(base, config) {
|
|
222
|
+
const merged = mergeDefined(base, config);
|
|
223
|
+
if (isPlainObject(base.devServer) && isPlainObject(config.devServer)) {
|
|
224
|
+
merged.devServer = mergeDefined(base.devServer, config.devServer);
|
|
225
|
+
}
|
|
226
|
+
return merged;
|
|
227
|
+
}
|
|
228
|
+
function mergeDefined(base, value) {
|
|
229
|
+
const merged = { ...base };
|
|
230
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
231
|
+
if (entry !== undefined)
|
|
232
|
+
merged[key] = entry;
|
|
233
|
+
}
|
|
234
|
+
return merged;
|
|
235
|
+
}
|
|
236
|
+
function isPlainObject(value) {
|
|
237
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Where a dev server listens, or null when it picks its port or listens on a
|
|
241
|
+
* socket. Returns null for those, since nothing can be probed ahead of them.
|
|
242
|
+
*/
|
|
243
|
+
function getDevServerAddress(devServer, flags, basePort) {
|
|
244
|
+
if (devServer?.ipc)
|
|
245
|
+
return null;
|
|
246
|
+
const port = flags.port ?? devServer?.port ?? basePort ?? 8080;
|
|
247
|
+
if (port === 'auto' || String(port) === '0')
|
|
248
|
+
return null;
|
|
249
|
+
const number = Number(port);
|
|
250
|
+
if (!Number.isInteger(number) || number <= 0)
|
|
251
|
+
return null;
|
|
252
|
+
const configured = flags.host ?? devServer?.host;
|
|
253
|
+
const host = typeof configured === 'string' ? (0, internal_1.resolveStartupHost)(configured) : undefined;
|
|
254
|
+
return host && !LOOPBACK_HOSTS.has(host)
|
|
255
|
+
? { port: number, host }
|
|
256
|
+
: { port: number };
|
|
257
|
+
}
|
|
258
|
+
// The probe reaches these on loopback. `local-ip` and friends resolve to an
|
|
259
|
+
// interface address first, the way the dev server resolves them.
|
|
260
|
+
const LOOPBACK_HOSTS = new Set(['localhost', '0.0.0.0', '::']);
|
|
261
|
+
/** Resolves once every address accepts a TCP connection. */
|
|
262
|
+
async function waitForAddresses(addresses) {
|
|
263
|
+
await Promise.all(addresses.map(waitForAddress));
|
|
264
|
+
}
|
|
265
|
+
async function waitForAddress({ port, host }) {
|
|
266
|
+
const hosts = host ? [host] : ['127.0.0.1', '::1'];
|
|
267
|
+
while (!(await Promise.any(hosts.map((h) => connects(port, h))).catch(() => false))) {
|
|
268
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function connects(port, host) {
|
|
272
|
+
return new Promise((resolve, reject) => {
|
|
273
|
+
const socket = (0, net_1.createConnection)({ port, host });
|
|
274
|
+
socket.once('connect', () => {
|
|
275
|
+
socket.destroy();
|
|
276
|
+
resolve(true);
|
|
277
|
+
});
|
|
278
|
+
socket.once('error', (e) => {
|
|
279
|
+
socket.destroy();
|
|
280
|
+
reject(e);
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
function readTaskOptions() {
|
|
285
|
+
try {
|
|
286
|
+
return JSON.parse(process.env.NX_TASK_OPTIONS ?? '{}');
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
return {};
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// The serve command runs from the target's cwd, so its config does too
|
|
293
|
+
function enterTaskCwd(options) {
|
|
294
|
+
if (options.cwd)
|
|
295
|
+
process.chdir((0, path_1.resolve)(options.cwd));
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* The readyWhen of the inferred serve targets when the config doesn't load the
|
|
299
|
+
* signal plugin. Runs in the env and with the options of the serve task, reads
|
|
300
|
+
* the config the way `rspack serve` does, and waits for the dev server it
|
|
301
|
+
* starts.
|
|
302
|
+
*/
|
|
303
|
+
async function waitForRspackDevServer(configPath) {
|
|
304
|
+
const options = readTaskOptions();
|
|
305
|
+
const flags = parseServeFlags(options);
|
|
306
|
+
// The config's file name, in the cwd of the serve task
|
|
307
|
+
const absoluteConfigPath = (0, path_1.resolve)(options.cwd ?? '.', flags.config ?? configPath);
|
|
308
|
+
enterTaskCwd(options);
|
|
309
|
+
// `rspack serve` sets it before it loads the config
|
|
310
|
+
process.env.NODE_ENV ??= flags.nodeEnv ?? 'development';
|
|
311
|
+
// Dev server 1.x reads the webpack-dev-server names
|
|
312
|
+
const devServerEnv = getDevServerMajorVersion() === 1 ? 'WEBPACK' : 'RSPACK';
|
|
313
|
+
// The dev server sets it on import, which `rspack serve` does before it
|
|
314
|
+
// loads the config
|
|
315
|
+
process.env[`${devServerEnv}_SERVE`] ||= 'true';
|
|
316
|
+
// Skips NxAppRspackPlugin's option normalization, which nothing here uses
|
|
317
|
+
global.NX_GRAPH_CREATION = true;
|
|
318
|
+
const { getRootTsConfigPath } = require('@nx/js');
|
|
319
|
+
const { resolveUserDefinedRspackConfig } = require('./resolve-user-defined-rspack-config');
|
|
320
|
+
const { readRspackOptions } = require('./read-rspack-options');
|
|
321
|
+
const env = parseEnv(flags.env);
|
|
322
|
+
if (!('RSPACK_SERVE' in env))
|
|
323
|
+
env.RSPACK_SERVE = true;
|
|
324
|
+
const argv = parseServeArgv(options, env);
|
|
325
|
+
const tsConfig = getRootTsConfigPath();
|
|
326
|
+
const load = async (path) => {
|
|
327
|
+
const config = await resolveUserDefinedRspackConfig(path, tsConfig);
|
|
328
|
+
return typeof config === 'function' ? await config(env, argv) : config;
|
|
329
|
+
};
|
|
330
|
+
const configs = (await Promise.all((await readRspackOptions(await resolveUserDefinedRspackConfig(absoluteConfigPath, tsConfig), env, argv)).map((config) => applyExtends(config, absoluteConfigPath, load)))).filter((config) => flags.configNames.length === 0 || flags.configNames.includes(config.name));
|
|
331
|
+
// `rspack serve` starts one dev server, for the first config with devServer,
|
|
332
|
+
// and serves a `devServer: false` config with the defaults
|
|
333
|
+
const config = configs.find((c) => c.devServer) ?? configs[0];
|
|
334
|
+
if (!config)
|
|
335
|
+
return;
|
|
336
|
+
const address = getDevServerAddress((config.devServer || undefined), flags, process.env[`${devServerEnv}_DEV_SERVER_BASE_PORT`]);
|
|
337
|
+
if (address)
|
|
338
|
+
await waitForAddresses([address]);
|
|
339
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AddressInfo } from 'net';
|
|
2
|
+
import type { Compiler } from '@rspack/core';
|
|
3
|
+
export declare const READY_SIGNAL_PLUGIN: unique symbol;
|
|
4
|
+
/** Whether the dev server of this config will report its readiness. */
|
|
5
|
+
export declare function sendsReadySignal(config: {
|
|
6
|
+
devServer?: unknown;
|
|
7
|
+
plugins?: unknown[];
|
|
8
|
+
}): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Reports the dev server's address to an Nx task whose readyWhen is `signal`.
|
|
11
|
+
* `rspack serve` reads `devServer` from the compiler after plugins apply,
|
|
12
|
+
* so wrapping `onListening` here reaches the server it starts.
|
|
13
|
+
*/
|
|
14
|
+
export declare function applyDevServerReadySignal(compiler: Compiler): void;
|
|
15
|
+
/** Reports the dev server's address to an Nx task whose readyWhen is `signal`. */
|
|
16
|
+
export declare class NxReadySignalPlugin {
|
|
17
|
+
readonly [READY_SIGNAL_PLUGIN] = true;
|
|
18
|
+
apply(compiler: Compiler): void;
|
|
19
|
+
}
|
|
20
|
+
export declare function getDevServerUrl(server: {
|
|
21
|
+
server?: {
|
|
22
|
+
address(): AddressInfo | string | null;
|
|
23
|
+
};
|
|
24
|
+
options?: {
|
|
25
|
+
server?: string | {
|
|
26
|
+
type?: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}): string | undefined;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.NxReadySignalPlugin = exports.READY_SIGNAL_PLUGIN = void 0;
|
|
5
|
+
exports.sendsReadySignal = sendsReadySignal;
|
|
6
|
+
exports.applyDevServerReadySignal = applyDevServerReadySignal;
|
|
7
|
+
exports.getDevServerUrl = getDevServerUrl;
|
|
8
|
+
// Set on the plugins that report readiness, so inference can find them in a
|
|
9
|
+
// config it has loaded
|
|
10
|
+
exports.READY_SIGNAL_PLUGIN = Symbol.for('@nx/ready-signal-plugin');
|
|
11
|
+
/** Whether the dev server of this config will report its readiness. */
|
|
12
|
+
function sendsReadySignal(config) {
|
|
13
|
+
return (typeof config.devServer === 'object' &&
|
|
14
|
+
!!config.devServer &&
|
|
15
|
+
!!config.plugins?.some((plugin) => plugin?.[exports.READY_SIGNAL_PLUGIN]));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Reports the dev server's address to an Nx task whose readyWhen is `signal`.
|
|
19
|
+
* `rspack serve` reads `devServer` from the compiler after plugins apply,
|
|
20
|
+
* so wrapping `onListening` here reaches the server it starts.
|
|
21
|
+
*/
|
|
22
|
+
function applyDevServerReadySignal(compiler) {
|
|
23
|
+
const devServer = compiler.options.devServer;
|
|
24
|
+
if (!devServer || !process.env.NX_READY_SIGNAL_SOCKET) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const { signalTaskReady } = require('@nx/devkit');
|
|
28
|
+
const onListening = devServer.onListening;
|
|
29
|
+
devServer.onListening = (server) => {
|
|
30
|
+
onListening?.(server);
|
|
31
|
+
signalTaskReady({ url: getDevServerUrl(server) });
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Reports the dev server's address to an Nx task whose readyWhen is `signal`. */
|
|
35
|
+
class NxReadySignalPlugin {
|
|
36
|
+
constructor() {
|
|
37
|
+
this[_a] = true;
|
|
38
|
+
}
|
|
39
|
+
apply(compiler) {
|
|
40
|
+
applyDevServerReadySignal(compiler);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.NxReadySignalPlugin = NxReadySignalPlugin;
|
|
44
|
+
_a = exports.READY_SIGNAL_PLUGIN;
|
|
45
|
+
function getDevServerUrl(server) {
|
|
46
|
+
const address = server.server?.address();
|
|
47
|
+
if (!address || typeof address === 'string') {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const type = typeof server.options?.server === 'string'
|
|
51
|
+
? server.options.server
|
|
52
|
+
: server.options?.server?.type;
|
|
53
|
+
const protocol = type && type !== 'http' ? 'https' : 'http';
|
|
54
|
+
const host = address.address === '::' || address.address === '0.0.0.0'
|
|
55
|
+
? 'localhost'
|
|
56
|
+
: address.family === 'IPv6'
|
|
57
|
+
? `[${address.address}]`
|
|
58
|
+
: address.address;
|
|
59
|
+
return `${protocol}://${host}:${address.port}/`;
|
|
60
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type Tree } from '@nx/devkit';
|
|
2
|
-
export declare function getRspackE2EWebServerInfo(tree: Tree, projectName: string, configFilePath: string,
|
|
2
|
+
export declare function getRspackE2EWebServerInfo(tree: Tree, projectName: string, configFilePath: string, e2ePortOverride?: number): Promise<import("@nx/devkit/internal").E2EWebServerDetails>;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getRspackE2EWebServerInfo = getRspackE2EWebServerInfo;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const internal_1 = require("@nx/devkit/internal");
|
|
6
|
-
async function getRspackE2EWebServerInfo(tree, projectName, configFilePath,
|
|
6
|
+
async function getRspackE2EWebServerInfo(tree, projectName, configFilePath, e2ePortOverride) {
|
|
7
7
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
8
8
|
let e2ePort = e2ePortOverride ?? 4200;
|
|
9
9
|
const servePort = (0, internal_1.readTargetDefaultsForTarget)('serve', nxJson.targetDefaults)
|
|
@@ -26,5 +26,5 @@ async function getRspackE2EWebServerInfo(tree, projectName, configFilePath, isPl
|
|
|
26
26
|
defaultE2ECiBaseUrl: `http://localhost:${e2ePort}`,
|
|
27
27
|
defaultE2EPort: e2ePort,
|
|
28
28
|
e2EPortIsExplicit: e2ePortOverride != null,
|
|
29
|
-
}
|
|
29
|
+
});
|
|
30
30
|
}
|
|
@@ -13,8 +13,7 @@ export declare function findExistingTargetsInProject(targets: {
|
|
|
13
13
|
userProvidedTargetIsUnsupported: TargetFlags;
|
|
14
14
|
alreadyHasNxRspackTargets: TargetFlags;
|
|
15
15
|
};
|
|
16
|
-
export declare function
|
|
17
|
-
export declare function addOrChangeServeTarget(tree: Tree, options: ConfigurationSchema, target: string): void;
|
|
16
|
+
export declare function assertNoRemovedExecutorTargets(projectName: string, targets: Record<string, TargetConfiguration> | undefined): void;
|
|
18
17
|
export declare function writeRspackConfigFile(tree: Tree, options: ConfigurationSchema, stylePreprocessorOptions?: {
|
|
19
18
|
includePaths?: string[];
|
|
20
19
|
}): void;
|