@nx/rsbuild 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.
@@ -0,0 +1 @@
1
+ export declare function waitForDevServer(configPath: string, command: 'dev' | 'preview'): Promise<void>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitForDevServer = waitForDevServer;
4
+ const dev_server_ready_check_1 = require("./src/utils/dev-server-ready-check");
5
+ async function waitForDevServer(configPath, command) {
6
+ await (0, dev_server_ready_check_1.waitForRsbuildServer)(configPath, command);
7
+ // The config or its plugins can leave handles open
8
+ process.exit(0);
9
+ }
@@ -0,0 +1 @@
1
+ export { pluginNxReadySignal } from './src/utils/ready-signal-plugin';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pluginNxReadySignal = void 0;
4
+ var ready_signal_plugin_1 = require("./src/utils/ready-signal-plugin");
5
+ Object.defineProperty(exports, "pluginNxReadySignal", { enumerable: true, get: function () { return ready_signal_plugin_1.pluginNxReadySignal; } });
@@ -1,4 +1,5 @@
1
1
  import { defineConfig } from '@rsbuild/core';
2
+ import { pluginNxReadySignal } from '@nx/rsbuild/ready-signal';
2
3
 
3
4
  export default defineConfig({
4
5
  source: {
@@ -20,5 +21,6 @@ export default defineConfig({
20
21
  distPath: {
21
22
  root: 'dist',
22
23
  },
23
- }
24
+ },
25
+ plugins: [pluginNxReadySignal()],
24
26
  });
@@ -5,6 +5,7 @@ exports.initGenerator = initGenerator;
5
5
  exports.initGeneratorInternal = initGeneratorInternal;
6
6
  const internal_1 = require("@nx/devkit/internal");
7
7
  const devkit_1 = require("@nx/devkit");
8
+ const internal_2 = require("@nx/js/internal");
8
9
  const plugin_1 = require("../../plugins/plugin");
9
10
  const versions_1 = require("../../utils/versions");
10
11
  const version_utils_1 = require("../../utils/version-utils");
@@ -24,37 +25,27 @@ function updateDependencies(tree, schema) {
24
25
  }, undefined, schema.keepExistingVersions ?? true);
25
26
  }
26
27
  function initGenerator(tree, schema) {
27
- return initGeneratorInternal(tree, { addPlugin: false, ...schema });
28
+ return initGeneratorInternal(tree, schema);
28
29
  }
29
30
  async function initGeneratorInternal(tree, schema) {
30
31
  (0, assert_supported_rsbuild_version_1.assertSupportedRsbuildVersion)(tree);
31
- const nxJson = (0, devkit_1.readNxJson)(tree);
32
- const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
33
- nxJson.useInferencePlugins !== false;
34
- schema.addPlugin ??= addPluginDefault;
35
- if (schema.addPlugin) {
36
- await (0, internal_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/rsbuild', plugin_1.createNodes, {
37
- buildTargetName: ['build', 'rsbuild:build', 'rsbuild-build'],
38
- devTargetName: ['dev', 'rsbuild:dev', 'rsbuild-dev'],
39
- previewTargetName: ['preview', 'rsbuild:preview', 'rsbuild-preview'],
40
- inspectTargetName: ['inspect', 'rsbuild:inspect', 'rsbuild-inspect'],
41
- typecheckTargetName: [
42
- 'typecheck',
43
- 'rsbuild:typecheck',
44
- 'rsbuild-typecheck',
45
- ],
46
- buildDepsTargetName: [
47
- 'build-deps',
48
- 'rsbuild:build-deps',
49
- 'rsbuild-build-deps',
50
- ],
51
- watchDepsTargetName: [
52
- 'watch-deps',
53
- 'rsbuild:watch-deps',
54
- 'rsbuild-watch-deps',
55
- ],
56
- }, schema.updatePackageScripts);
57
- }
32
+ await (0, internal_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/rsbuild', plugin_1.createNodes, {
33
+ buildTargetName: ['build', 'rsbuild:build', 'rsbuild-build'],
34
+ devTargetName: ['dev', 'rsbuild:dev', 'rsbuild-dev'],
35
+ previewTargetName: ['preview', 'rsbuild:preview', 'rsbuild-preview'],
36
+ inspectTargetName: ['inspect', 'rsbuild:inspect', 'rsbuild-inspect'],
37
+ buildDepsTargetName: [
38
+ 'build-deps',
39
+ 'rsbuild:build-deps',
40
+ 'rsbuild-build-deps',
41
+ ],
42
+ watchDepsTargetName: [
43
+ 'watch-deps',
44
+ 'rsbuild:watch-deps',
45
+ 'rsbuild-watch-deps',
46
+ ],
47
+ }, schema.updatePackageScripts);
48
+ await (0, internal_2.ensureTypescriptPlugin)(tree, schema.updatePackageScripts);
58
49
  const tasks = [];
59
50
  if (!schema.skipPackageJson) {
60
51
  tasks.push(updateDependencies(tree, schema));
@@ -1,7 +1,6 @@
1
1
  export interface InitGeneratorSchema {
2
2
  keepExistingVersions?: boolean;
3
3
  updatePackageScripts?: boolean;
4
- addPlugin?: boolean;
5
4
  skipFormat?: boolean;
6
5
  skipPackageJson?: boolean;
7
6
  }
@@ -0,0 +1,4 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function update(tree: Tree): Promise<{
3
+ skipAgentic: boolean;
4
+ }>;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = update;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const internal_1 = require("@nx/js/internal");
6
+ async function update(tree) {
7
+ if (!(0, internal_1.registerTypescriptPluginForTypecheck)(tree, '@nx/rsbuild', {
8
+ removeTypecheckTargetName: true,
9
+ })) {
10
+ return { skipAgentic: true };
11
+ }
12
+ await (0, devkit_1.formatFiles)(tree);
13
+ }
@@ -0,0 +1,42 @@
1
+ #### Register `@nx/js/typescript` for typecheck targets
2
+
3
+ `@nx/rsbuild` no longer infers a `typecheck` target in any setup, and `@nx/js/typescript` provides it instead. This migration registers `@nx/js/typescript` with only its typecheck target when the workspace uses `@nx/rsbuild` and doesn't register `@nx/js/typescript` yet, so your projects keep a `typecheck` target.
4
+
5
+ The new registration is added before the framework plugin and reuses its `typecheckTargetName`, and the migration removes that option from the `@nx/rsbuild` registration. Registrations with `typecheckTargetName: false` lose the option without registering `@nx/js/typescript`.
6
+
7
+ #### Sample code changes
8
+
9
+ ##### Before
10
+
11
+ ```json title="nx.json"
12
+ {
13
+ "plugins": [
14
+ {
15
+ "plugin": "@nx/rsbuild",
16
+ "options": {
17
+ "buildTargetName": "build",
18
+ "typecheckTargetName": "typecheck"
19
+ }
20
+ }
21
+ ]
22
+ }
23
+ ```
24
+
25
+ ##### After
26
+
27
+ ```json title="nx.json"
28
+ {
29
+ "plugins": [
30
+ {
31
+ "plugin": "@nx/js/typescript",
32
+ "options": { "typecheck": { "targetName": "typecheck" } }
33
+ },
34
+ {
35
+ "plugin": "@nx/rsbuild",
36
+ "options": {
37
+ "buildTargetName": "build"
38
+ }
39
+ }
40
+ ]
41
+ }
42
+ ```
@@ -4,7 +4,6 @@ export interface RsbuildPluginOptions {
4
4
  devTargetName?: string;
5
5
  previewTargetName?: string;
6
6
  inspectTargetName?: string;
7
- typecheckTargetName?: string;
8
7
  buildDepsTargetName?: string;
9
8
  watchDepsTargetName?: string;
10
9
  }
@@ -7,7 +7,6 @@ const internal_2 = require("@nx/js/internal");
7
7
  const js_1 = require("@nx/js");
8
8
  const fs_1 = require("fs");
9
9
  const path_1 = require("path");
10
- const minimatch_1 = require("minimatch");
11
10
  const rsbuildConfigGlob = '**/rsbuild.config.{js,ts,mjs,mts,cjs,cts}';
12
11
  exports.createNodes = [
13
12
  rsbuildConfigGlob,
@@ -15,18 +14,17 @@ exports.createNodes = [
15
14
  const optionsHash = (0, internal_1.hashObject)(options);
16
15
  const cachePath = (0, path_1.join)(internal_1.workspaceDataDirectory, `rsbuild-${optionsHash}.hash`);
17
16
  const targetsCache = new internal_1.PluginCache(cachePath);
18
- const isUsingTsSolutionSetup = (0, internal_2.isUsingTsSolutionSetup)();
19
17
  const packageManager = (0, devkit_1.detectPackageManager)(context.workspaceRoot);
20
18
  const pmc = (0, devkit_1.getPackageManagerCommand)(packageManager);
21
19
  const lockFileName = (0, js_1.getLockFileName)(packageManager);
22
20
  const normalizedOptions = normalizeOptions(options);
23
21
  try {
24
22
  const { entries, preErrors } = await filterRsbuildConfigs(configFilePaths, context);
25
- const projectHashes = await (0, internal_1.calculateHashesForCreateNodes)(entries.map((e) => e.projectRoot), { ...normalizedOptions, isUsingTsSolutionSetup }, context, entries.map(() => [lockFileName]));
23
+ const projectHashes = await (0, internal_1.calculateHashesForCreateNodes)(entries.map((e) => e.projectRoot), normalizedOptions, context, entries.map(() => [lockFileName]));
26
24
  let results = [];
27
25
  let nodeErrors = [];
28
26
  try {
29
- results = await (0, devkit_1.createNodesFromFiles)((configFile, _, ctx, idx) => createNodesInternal(configFile, normalizedOptions, ctx, targetsCache, isUsingTsSolutionSetup, pmc, entries[idx].tsConfigFiles, projectHashes[idx]), entries.map((e) => e.configFile), options, context);
27
+ results = await (0, devkit_1.createNodesFromFiles)((configFile, _, ctx, idx) => createNodesInternal(configFile, normalizedOptions, ctx, targetsCache, pmc, projectHashes[idx]), entries.map((e) => e.configFile), options, context);
30
28
  }
31
29
  catch (e) {
32
30
  if (e instanceof devkit_1.AggregateCreateNodesError) {
@@ -52,10 +50,10 @@ exports.createNodes = [
52
50
  * @deprecated Use {@link createNodes} instead. This will be removed in Nx 24.
53
51
  */
54
52
  exports.createNodesV2 = exports.createNodes;
55
- async function createNodesInternal(configFilePath, normalizedOptions, context, targetsCache, isUsingTsSolutionSetup, pmc, tsConfigFiles, hash) {
53
+ async function createNodesInternal(configFilePath, normalizedOptions, context, targetsCache, pmc, hash) {
56
54
  const projectRoot = (0, path_1.dirname)(configFilePath);
57
55
  if (!targetsCache.has(hash)) {
58
- targetsCache.set(hash, await createRsbuildTargets(configFilePath, projectRoot, normalizedOptions, tsConfigFiles, isUsingTsSolutionSetup, context, pmc));
56
+ targetsCache.set(hash, await createRsbuildTargets(configFilePath, projectRoot, normalizedOptions, context, pmc));
59
57
  }
60
58
  const { targets, metadata } = targetsCache.get(hash);
61
59
  return {
@@ -68,7 +66,7 @@ async function createNodesInternal(configFilePath, normalizedOptions, context, t
68
66
  },
69
67
  };
70
68
  }
71
- async function createRsbuildTargets(configFilePath, projectRoot, options, tsConfigFiles, isUsingTsSolutionSetup, context, pmc) {
69
+ async function createRsbuildTargets(configFilePath, projectRoot, options, context, pmc) {
72
70
  const absoluteConfigFilePath = (0, devkit_1.joinPathFragments)(context.workspaceRoot, configFilePath);
73
71
  // Required lazily: `@rsbuild/core` is an optional peer dependency, so it
74
72
  // may be absent when the plugin is loaded in a workspace that doesn't use
@@ -113,6 +111,7 @@ async function createRsbuildTargets(configFilePath, projectRoot, options, tsConf
113
111
  },
114
112
  },
115
113
  };
114
+ const signals = await loadsReadySignalPlugin(rsbuildConfig.content.plugins);
116
115
  targets[options.devTargetName] = {
117
116
  continuous: true,
118
117
  inputs: [...buildInputs],
@@ -121,6 +120,7 @@ async function createRsbuildTargets(configFilePath, projectRoot, options, tsConf
121
120
  cwd: projectRoot,
122
121
  args: ['--mode=development'],
123
122
  },
123
+ readyWhen: getServerReadyWhen(configFilePath, 'dev', signals),
124
124
  };
125
125
  targets[options.previewTargetName] = {
126
126
  continuous: true,
@@ -131,6 +131,7 @@ async function createRsbuildTargets(configFilePath, projectRoot, options, tsConf
131
131
  cwd: projectRoot,
132
132
  args: ['--mode=production'],
133
133
  },
134
+ readyWhen: getServerReadyWhen(configFilePath, 'preview', signals),
134
135
  };
135
136
  targets[options.inspectTargetName] = {
136
137
  command: `rsbuild inspect`,
@@ -138,42 +139,6 @@ async function createRsbuildTargets(configFilePath, projectRoot, options, tsConf
138
139
  cwd: projectRoot,
139
140
  },
140
141
  };
141
- if (tsConfigFiles.length) {
142
- const tsConfigToUse = ['tsconfig.app.json', 'tsconfig.lib.json', 'tsconfig.json'].find((t) => tsConfigFiles.includes(t)) ?? tsConfigFiles[0];
143
- targets[options.typecheckTargetName] = {
144
- cache: true,
145
- inputs: [
146
- ...('production' in namedInputs
147
- ? ['production', '^production']
148
- : ['default', '^default']),
149
- { externalDependencies: ['typescript'] },
150
- ],
151
- command: isUsingTsSolutionSetup
152
- ? `tsc --build --emitDeclarationOnly`
153
- : `tsc -p ${tsConfigToUse} --noEmit`,
154
- options: { cwd: (0, devkit_1.joinPathFragments)(projectRoot) },
155
- metadata: {
156
- description: `Runs type-checking for the project.`,
157
- technologies: ['typescript'],
158
- help: {
159
- command: isUsingTsSolutionSetup
160
- ? `${pmc.exec} tsc --build --help`
161
- : `${pmc.exec} tsc -p ${tsConfigToUse} --help`,
162
- example: isUsingTsSolutionSetup
163
- ? { args: ['--force'] }
164
- : { options: { noEmit: true } },
165
- },
166
- },
167
- };
168
- if (isUsingTsSolutionSetup) {
169
- targets[options.typecheckTargetName].dependsOn = [
170
- `^${options.typecheckTargetName}`,
171
- ];
172
- targets[options.typecheckTargetName].syncGenerators = [
173
- '@nx/js:typescript-sync',
174
- ];
175
- }
176
- }
177
142
  (0, internal_2.addBuildAndWatchDepsTargets)(context.workspaceRoot, projectRoot, targets, options, pmc);
178
143
  return { targets, metadata: {} };
179
144
  }
@@ -221,8 +186,7 @@ async function filterRsbuildConfigs(configFiles, context) {
221
186
  !siblingFiles.includes('project.json')) {
222
187
  return null;
223
188
  }
224
- const tsConfigFiles = siblingFiles.filter((p) => (0, minimatch_1.minimatch)(p, 'tsconfig*{.json,.*.json}')) ?? [];
225
- return { configFile, projectRoot, tsConfigFiles };
189
+ return { configFile, projectRoot };
226
190
  }
227
191
  catch (e) {
228
192
  preErrors.push([configFile, e]);
@@ -240,6 +204,31 @@ function normalizeOptions(options) {
240
204
  options.devTargetName ??= 'dev';
241
205
  options.previewTargetName ??= 'preview';
242
206
  options.inspectTargetName ??= 'inspect';
243
- options.typecheckTargetName ??= 'typecheck';
244
207
  return options;
245
208
  }
209
+ // A config that loads pluginNxReadySignal() reports when the server listens.
210
+ // Otherwise the check loads the config when the task runs, with the task's
211
+ // env and options, and waits for the server's port.
212
+ function getServerReadyWhen(configFilePath, command, signals) {
213
+ return signals
214
+ ? { signal: true }
215
+ : {
216
+ // Unquoted: the plugin's glob fixes the file name. Quote it if it ever
217
+ // becomes user-chosen, since the shell expands $, backticks and %.
218
+ command: `node -e "require('@nx/rsbuild/ready-check').waitForDevServer(process.argv[1], '${command}')" ${(0, path_1.basename)(configFilePath)}`,
219
+ // Each attempt loads the config
220
+ interval: 1000,
221
+ };
222
+ }
223
+ // Rsbuild's plugins option nests arrays and promises, and allows falsy entries
224
+ async function loadsReadySignalPlugin(plugins) {
225
+ const plugin = await plugins;
226
+ if (Array.isArray(plugin)) {
227
+ for (const entry of plugin) {
228
+ if (await loadsReadySignalPlugin(entry))
229
+ return true;
230
+ }
231
+ return false;
232
+ }
233
+ return plugin?.name === 'nx:ready-signal';
234
+ }
@@ -0,0 +1,31 @@
1
+ export interface RsbuildFlags {
2
+ port?: string;
3
+ host?: string | true;
4
+ envMode?: string;
5
+ envDir?: string;
6
+ config?: string;
7
+ configLoader?: string;
8
+ root?: string;
9
+ noEnv?: true;
10
+ }
11
+ /**
12
+ * The flags `rsbuild dev` and `rsbuild preview` take from the target's
13
+ * options: named options are forwarded as flags, unless `args`, which holds
14
+ * the rest, sets the same flag.
15
+ */
16
+ export declare function parseRsbuildFlags(options: Record<string, unknown>): RsbuildFlags;
17
+ export type ServerAddress = {
18
+ port: number;
19
+ host?: string;
20
+ };
21
+ export declare function getRsbuildServerAddress(server: {
22
+ port?: unknown;
23
+ host?: unknown;
24
+ }): ServerAddress | null;
25
+ /**
26
+ * The readyWhen of the inferred dev and preview targets when the config doesn't
27
+ * load the signal plugin. Runs in the env and with the options of the task,
28
+ * resolves the config the way the Rsbuild CLI does, plugins included, and
29
+ * waits for the server's port.
30
+ */
31
+ export declare function waitForRsbuildServer(configPath: string, command: 'dev' | 'preview'): Promise<void>;
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseRsbuildFlags = parseRsbuildFlags;
4
+ exports.getRsbuildServerAddress = getRsbuildServerAddress;
5
+ exports.waitForRsbuildServer = waitForRsbuildServer;
6
+ const internal_1 = require("@nx/devkit/internal");
7
+ const net_1 = require("net");
8
+ const path_1 = require("path");
9
+ const FLAGS = [
10
+ 'port',
11
+ 'host',
12
+ 'envMode',
13
+ 'envDir',
14
+ 'config',
15
+ 'configLoader',
16
+ 'root',
17
+ ];
18
+ const SHORT_FLAGS = { c: 'config', r: 'root' };
19
+ /**
20
+ * The flags `rsbuild dev` and `rsbuild preview` take from the target's
21
+ * options: named options are forwarded as flags, unless `args`, which holds
22
+ * the rest, sets the same flag.
23
+ */
24
+ function parseRsbuildFlags(options) {
25
+ const flags = {};
26
+ for (const key of FLAGS) {
27
+ const value = options[key];
28
+ if (typeof value === 'string' || typeof value === 'number') {
29
+ flags[key] = String(value);
30
+ }
31
+ else if (key === 'host' && value === true) {
32
+ flags.host = true;
33
+ }
34
+ }
35
+ const args = (0, internal_1.splitShellArgs)(Array.isArray(options.args)
36
+ ? options.args.join(' ')
37
+ : typeof options.args === 'string'
38
+ ? options.args
39
+ : '');
40
+ for (let i = 0; i < args.length; i++) {
41
+ const [, long, short, inline] = args[i].match(/^(?:--([^=]+)|-([a-z]))(?:=(.*))?$/) ?? [];
42
+ const key = (long
43
+ ? long.replace(/([a-z])-([a-z])/g, (_, a, b) => a + b.toUpperCase())
44
+ : SHORT_FLAGS[short]);
45
+ if (!key)
46
+ continue;
47
+ if (key === 'noEnv') {
48
+ flags.noEnv = true;
49
+ continue;
50
+ }
51
+ let value = inline;
52
+ if (value === undefined && args[i + 1] && !args[i + 1].startsWith('-')) {
53
+ value = args[++i];
54
+ }
55
+ if (key === 'host')
56
+ flags.host = value ?? true;
57
+ else if (FLAGS.includes(key) && value !== undefined)
58
+ flags[key] = value;
59
+ }
60
+ return flags;
61
+ }
62
+ function getRsbuildServerAddress(server) {
63
+ const port = Number(server.port);
64
+ if (!Number.isInteger(port) || port <= 0)
65
+ return null;
66
+ return typeof server.host === 'string' &&
67
+ !['localhost', '0.0.0.0', '::'].includes(server.host)
68
+ ? { port, host: server.host }
69
+ : { port };
70
+ }
71
+ /**
72
+ * The readyWhen of the inferred dev and preview targets when the config doesn't
73
+ * load the signal plugin. Runs in the env and with the options of the task,
74
+ * resolves the config the way the Rsbuild CLI does, plugins included, and
75
+ * waits for the server's port.
76
+ */
77
+ async function waitForRsbuildServer(configPath, command) {
78
+ let options = {};
79
+ try {
80
+ options = JSON.parse(process.env.NX_TASK_OPTIONS ?? '{}');
81
+ }
82
+ catch { }
83
+ const flags = parseRsbuildFlags(options);
84
+ const cwd = (0, path_1.resolve)(options.cwd ?? '.');
85
+ const root = (0, path_1.resolve)(cwd, flags.root ?? '.');
86
+ process.chdir(cwd);
87
+ const { createRsbuild, loadConfig, loadEnv } = require('@rsbuild/core');
88
+ // The CLI sets NODE_ENV first, then loads the env files for that mode and
89
+ // the config, whose function form reads the command from argv
90
+ process.env.NODE_ENV ||= command === 'dev' ? 'development' : 'production';
91
+ const envs = flags.noEnv
92
+ ? null
93
+ : loadEnv({
94
+ cwd: flags.envDir ? (0, path_1.resolve)(root, flags.envDir) : root,
95
+ mode: flags.envMode,
96
+ });
97
+ process.argv[2] = command;
98
+ const { content: config } = await loadConfig({
99
+ cwd: root,
100
+ // configPath is the config the CLI finds in the task's cwd, not in --root
101
+ path: flags.config ?? (flags.root ? undefined : configPath),
102
+ envMode: flags.envMode,
103
+ loader: flags.configLoader,
104
+ });
105
+ if (envs) {
106
+ config.source ??= {};
107
+ config.source.define = { ...envs.publicVars, ...config.source.define };
108
+ }
109
+ config.server ??= {};
110
+ if (flags.host !== undefined)
111
+ config.server.host = flags.host;
112
+ if (flags.port)
113
+ config.server.port = Number(flags.port);
114
+ // Rsbuild 1.0 takes the config only as rsbuildConfig
115
+ const rsbuild = await createRsbuild({ cwd: root, rsbuildConfig: config });
116
+ let server = config.server;
117
+ try {
118
+ await rsbuild.initConfigs({ action: command });
119
+ server = rsbuild.getNormalizedConfig().server;
120
+ }
121
+ catch (e) {
122
+ // The preview CLI normalizes the config without generating bundler configs,
123
+ // so a plugin hook that throws there doesn't fail `rsbuild preview`
124
+ if (command === 'dev')
125
+ throw e;
126
+ }
127
+ const address = getRsbuildServerAddress(server);
128
+ if (address)
129
+ await waitForAddress(address);
130
+ }
131
+ async function waitForAddress({ port, host }) {
132
+ const hosts = host ? [host] : ['127.0.0.1', '::1'];
133
+ while (!(await Promise.any(hosts.map((h) => connects(port, h))).catch(() => false))) {
134
+ await new Promise((r) => setTimeout(r, 250));
135
+ }
136
+ }
137
+ function connects(port, host) {
138
+ return new Promise((resolve, reject) => {
139
+ const socket = (0, net_1.createConnection)({ port, host });
140
+ socket.once('connect', () => {
141
+ socket.destroy();
142
+ resolve(true);
143
+ });
144
+ socket.once('error', (e) => {
145
+ socket.destroy();
146
+ reject(e);
147
+ });
148
+ });
149
+ }
@@ -1,2 +1,2 @@
1
1
  import { type Tree } from '@nx/devkit';
2
- export declare function getRsbuildE2EWebServerInfo(tree: Tree, projectName: string, configFilePath: string, isPluginBeingAdded: boolean, e2ePortOverride?: number): Promise<import("@nx/devkit/internal").E2EWebServerDetails>;
2
+ export declare function getRsbuildE2EWebServerInfo(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.getRsbuildE2EWebServerInfo = getRsbuildE2EWebServerInfo;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const internal_1 = require("@nx/devkit/internal");
6
- async function getRsbuildE2EWebServerInfo(tree, projectName, configFilePath, isPluginBeingAdded, e2ePortOverride) {
6
+ async function getRsbuildE2EWebServerInfo(tree, projectName, configFilePath, e2ePortOverride) {
7
7
  const nxJson = (0, devkit_1.readNxJson)(tree);
8
8
  let e2ePort = e2ePortOverride ?? 4200;
9
9
  const devPort = (0, internal_1.readTargetDefaultsForTarget)('dev', nxJson.targetDefaults)
@@ -22,5 +22,5 @@ async function getRsbuildE2EWebServerInfo(tree, projectName, configFilePath, isP
22
22
  defaultE2EWebServerAddress: `http://localhost:${e2ePort}`,
23
23
  defaultE2ECiBaseUrl: `http://localhost:${e2ePort}`,
24
24
  defaultE2EPort: e2ePort,
25
- }, isPluginBeingAdded);
25
+ });
26
26
  }
@@ -0,0 +1,6 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ /**
3
+ * Reports the dev or preview server's address to an Nx task whose readyWhen
4
+ * is `signal`, once the server listens. Does nothing outside such a task.
5
+ */
6
+ export declare function pluginNxReadySignal(): RsbuildPlugin;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pluginNxReadySignal = pluginNxReadySignal;
4
+ const net_1 = require("net");
5
+ /**
6
+ * Reports the dev or preview server's address to an Nx task whose readyWhen
7
+ * is `signal`, once the server listens. Does nothing outside such a task.
8
+ */
9
+ function pluginNxReadySignal() {
10
+ return {
11
+ name: 'nx:ready-signal',
12
+ setup(api) {
13
+ if (!process.env.NX_READY_SIGNAL_SOCKET) {
14
+ return;
15
+ }
16
+ const { signalTaskReady } = require('@nx/devkit');
17
+ const report = ({ port }) => {
18
+ const { https, host } = api.getNormalizedConfig().server;
19
+ signalTaskReady({
20
+ url: `${https ? 'https' : 'http'}://${getUrlHost(host)}:${port}/`,
21
+ });
22
+ };
23
+ api.onAfterStartDevServer(report);
24
+ // Rsbuild 1 names the preview hook onAfterStartProdServer
25
+ const onAfterStartPreviewServer = api.onAfterStartPreviewServer ??
26
+ api.onAfterStartProdServer;
27
+ onAfterStartPreviewServer(report);
28
+ },
29
+ };
30
+ }
31
+ function getUrlHost(host) {
32
+ if (!host || host === '0.0.0.0' || host === '::') {
33
+ return 'localhost';
34
+ }
35
+ return (0, net_1.isIPv6)(host) ? `[${host}]` : host;
36
+ }
package/migrations.json CHANGED
@@ -32,6 +32,12 @@
32
32
  "requires": {
33
33
  "@rsbuild/core": ">=2.0.0"
34
34
  }
35
+ },
36
+ "update-24-0-0-register-typescript-plugin-for-typecheck": {
37
+ "version": "24.0.0-beta.3",
38
+ "description": "Register @nx/js/typescript with its typecheck target in workspaces that use @nx/rsbuild without it, and remove the typecheckTargetName option from @nx/rsbuild, since @nx/rsbuild no longer infers typecheck targets.",
39
+ "implementation": "./dist/src/migrations/update-24-0-0/register-typescript-plugin-for-typecheck",
40
+ "documentation": "./dist/src/migrations/update-24-0-0/register-typescript-plugin-for-typecheck.md"
35
41
  }
36
42
  },
37
43
  "packageJsonUpdates": {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nx/rsbuild",
3
3
  "description": "The Nx Plugin for Rsbuild contains an Nx plugin, executors and utilities that support building applications using Rsbuild.",
4
- "version": "24.0.0-beta.2",
4
+ "version": "24.0.0-beta.4",
5
5
  "type": "commonjs",
6
6
  "files": [
7
7
  "dist",
@@ -47,6 +47,12 @@
47
47
  ],
48
48
  "src/*.js": [
49
49
  "dist/src/*.d.ts"
50
+ ],
51
+ "ready-check": [
52
+ "dist/ready-check.d.ts"
53
+ ],
54
+ "ready-signal": [
55
+ "dist/ready-signal.d.ts"
50
56
  ]
51
57
  }
52
58
  },
@@ -54,14 +60,14 @@
54
60
  "executors": "./executors.json",
55
61
  "dependencies": {
56
62
  "tslib": "^2.3.0",
57
- "@nx/devkit": "24.0.0-beta.2",
58
- "@nx/js": "24.0.0-beta.2",
63
+ "@nx/devkit": "24.0.0-beta.4",
64
+ "@nx/js": "24.0.0-beta.4",
59
65
  "minimatch": "10.2.5",
60
66
  "semver": "^7.6.3",
61
67
  "@phenomnomnominal/tsquery": "~6.2.0"
62
68
  },
63
69
  "devDependencies": {
64
- "nx": "24.0.0-beta.2"
70
+ "nx": "24.0.0-beta.4"
65
71
  },
66
72
  "peerDependencies": {
67
73
  "@rsbuild/core": "^1.0.0 || ^2.0.0"
@@ -97,6 +103,16 @@
97
103
  "types": "./dist/config-utils.d.ts",
98
104
  "default": "./dist/config-utils.js"
99
105
  },
106
+ "./ready-check": {
107
+ "@nx/nx-source": "./ready-check.ts",
108
+ "types": "./dist/ready-check.d.ts",
109
+ "default": "./dist/ready-check.js"
110
+ },
111
+ "./ready-signal": {
112
+ "@nx/nx-source": "./ready-signal.ts",
113
+ "types": "./dist/ready-signal.d.ts",
114
+ "default": "./dist/ready-signal.js"
115
+ },
100
116
  "./src/*": {
101
117
  "@nx/nx-source": "./src/*.ts",
102
118
  "types": "./dist/src/*.d.ts",