Skip to content

Commit 4ca5684

Browse files
committed
feat(watcher): enable rspack native watcher in watch mode
Turn on experiments.nativeWatcher now that rsbuild 2.1's safeTime baseline suppresses the stale-FSEvent reruns that used to flake macOS watch e2e. - watch aggregateTimeout 5 -> 100ms (macOS FSEvent/vnode cache cycle) - poll config files for restart (chokidar v5 dropped fsevents) - await chokidar 'ready' so pre-ready events are not dropped
1 parent 5610b74 commit 4ca5684

10 files changed

Lines changed: 15 additions & 46 deletions

File tree

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
import { defineConfig } from '@rstest/core';
22

3-
export default defineConfig({
4-
tools: {
5-
rspack: {
6-
watchOptions: {
7-
aggregateTimeout: 10,
8-
},
9-
},
10-
},
11-
});
3+
export default defineConfig({});
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
import { defineConfig } from '@rstest/core';
22

3-
export default defineConfig({
4-
tools: {
5-
rspack: {
6-
watchOptions: {
7-
aggregateTimeout: 10,
8-
},
9-
},
10-
},
11-
});
3+
export default defineConfig({});

e2e/watch/fixtures-setup/rstest.config.mts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,4 @@ export default defineConfig({
44
passWithNoTests: true,
55
setupFiles: ['./rstest.setup.ts'],
66
exclude: ['**/node_modules/**', '**/dist/**'],
7-
tools: {
8-
rspack: {
9-
watchOptions: {
10-
aggregateTimeout: 10,
11-
},
12-
},
13-
},
147
});

e2e/watch/fixtures-shortcuts/rstest.config.mts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,4 @@ process.stdin.setRawMode = () => process.stdin;
66
export default defineConfig({
77
reporters: ['default'],
88
disableConsoleIntercept: true,
9-
tools: {
10-
rspack: {
11-
watchOptions: {
12-
aggregateTimeout: 10,
13-
},
14-
},
15-
},
169
});
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
import { defineConfig } from '@rstest/core';
22

3-
export default defineConfig({
4-
tools: {
5-
rspack: {
6-
watchOptions: {
7-
aggregateTimeout: 10,
8-
},
9-
},
10-
},
11-
});
3+
export default defineConfig({});

packages/core/src/cli/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ export const runRest = async ({
921921
process.off('unhandledRejection', unexpectedlyExitHandler);
922922
});
923923

924-
watchFilesForRestart({
924+
await watchFilesForRestart({
925925
rstest,
926926
options,
927927
filters,

packages/core/src/core/plugins/entry.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ export const pluginEntryWatch: (params: {
5656
};
5757

5858
config.watchOptions ??= {};
59-
// FIXME: Temporarily default to 5 to debounce rerun in watch mode.
60-
config.watchOptions.aggregateTimeout = 5;
59+
config.watchOptions.aggregateTimeout = 100;
6160
// TODO: rspack should support `(string | RegExp)[]` type
6261
// https://github.com/web-infra-dev/rspack/issues/10596
6362
config.watchOptions.ignored = castArray(
@@ -79,6 +78,9 @@ export const pluginEntryWatch: (params: {
7978
'**/*.snap',
8079
);
8180

81+
config.experiments ??= {};
82+
config.experiments.nativeWatcher = true;
83+
8284
const configFilePath = context.projects.find(
8385
(project) => project.environmentName === environment.name,
8486
)?.configFilePath;

packages/core/src/core/restart.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export async function watchFilesForRestart({
9393
ignoreInitial: true,
9494
// If watching fails due to read permissions, the errors will be suppressed silently.
9595
ignorePermissionErrors: true,
96+
usePolling: true,
97+
interval: 100,
9698
...watchOptions,
9799
});
98100

packages/core/src/utils/watchFiles.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,7 @@ export async function createChokidar(
3535
}
3636
}
3737

38-
return chokidar.watch(Array.from(watchFiles), options);
38+
const watcher = chokidar.watch(Array.from(watchFiles), options);
39+
await new Promise<void>((resolve) => watcher.once('ready', () => resolve()));
40+
return watcher;
3941
}

packages/core/tests/core/__snapshots__/rsbuild.test.ts.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,7 @@ exports[`prepareRsbuild > should generate rspack config correctly in watch mode
19441944
"entry": [Function],
19451945
"experiments": {
19461946
"asyncWebAssembly": false,
1947+
"nativeWatcher": true,
19471948
"sourceImport": true,
19481949
},
19491950
"externals": [
@@ -2565,7 +2566,7 @@ exports[`prepareRsbuild > should generate rspack config correctly in watch mode
25652566
},
25662567
"target": "node",
25672568
"watchOptions": {
2568-
"aggregateTimeout": 5,
2569+
"aggregateTimeout": 100,
25692570
"ignored": [
25702571
"**/.git",
25712572
"**/node_modules",

0 commit comments

Comments
 (0)