Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/js/src/executors/node/node.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,16 @@ export async function* nodeExecutor(
includeDependentProjects: true,
},
async (err, data) => {
if (err === 'closed') {
logger.error(`Watch error: Daemon closed the connection`);
if (err === 'reconnecting') {
// Silent - daemon restarts automatically on lockfile changes
return;
} else if (err === 'reconnected') {
// Silent - reconnection succeeded
return;
} else if (err === 'closed') {
logger.error(
`Failed to reconnect to daemon after multiple attempts`
);
process.exit(1);
} else if (err) {
logger.error(`Watch error: ${err?.message ?? 'Unknown'}`);
Expand Down
20 changes: 16 additions & 4 deletions packages/js/src/executors/tsc/lib/batch/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ export async function watchTaskProjectsPackageJsonFileChanges(
const unregisterFileWatcher = await daemonClient.registerFileWatcher(
{ watchProjects: projects },
(err, data) => {
if (err === 'closed') {
logger.error(`Watch error: Daemon closed the connection`);
if (err === 'reconnecting') {
// Silent - daemon restarts automatically on lockfile changes
return;
} else if (err === 'reconnected') {
// Silent - reconnection succeeded
return;
} else if (err === 'closed') {
logger.error(`Failed to reconnect to daemon after multiple attempts`);
process.exit(1);
} else if (err) {
logger.error(`Watch error: ${err?.message ?? 'Unknown'}`);
Expand Down Expand Up @@ -50,8 +56,14 @@ export async function watchTaskProjectsFileChangesForAssets(
includeGlobalWorkspaceFiles: true,
},
(err, data) => {
if (err === 'closed') {
logger.error(`Watch error: Daemon closed the connection`);
if (err === 'reconnecting') {
// Silent - daemon restarts automatically on lockfile changes
return;
} else if (err === 'reconnected') {
// Silent - reconnection succeeded
return;
} else if (err === 'closed') {
logger.error(`Failed to reconnect to daemon after multiple attempts`);
process.exit(1);
} else if (err) {
logger.error(`Watch error: ${err?.message ?? 'Unknown'}`);
Expand Down
10 changes: 8 additions & 2 deletions packages/js/src/utils/assets/copy-assets-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,14 @@ export class CopyAssetsHandler {
includeGlobalWorkspaceFiles: true,
},
(err, data) => {
if (err === 'closed') {
logger.error(`Watch error: Daemon closed the connection`);
if (err === 'reconnecting') {
// Silent - daemon restarts automatically on lockfile changes
return;
} else if (err === 'reconnected') {
// Silent - reconnection succeeded
return;
} else if (err === 'closed') {
logger.error(`Failed to reconnect to daemon after multiple attempts`);
process.exit(1);
} else if (err) {
logger.error(`Watch error: ${err?.message ?? 'Unknown'}`);
Expand Down
10 changes: 8 additions & 2 deletions packages/js/src/utils/watch-for-single-file-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ export async function watchForSingleFileChanges(
const unregisterFileWatcher = await daemonClient.registerFileWatcher(
{ watchProjects: [projectName] },
(err, data) => {
if (err === 'closed') {
logger.error(`Watch error: Daemon closed the connection`);
if (err === 'reconnecting') {
// Silent - daemon restarts automatically on lockfile changes
return;
} else if (err === 'reconnected') {
// Silent - reconnection succeeded
return;
} else if (err === 'closed') {
logger.error(`Failed to reconnect to daemon after multiple attempts`);
process.exit(1);
} else if (err) {
logger.error(`Watch error: ${err?.message ?? 'Unknown'}`);
Expand Down
12 changes: 10 additions & 2 deletions packages/nx/src/command-line/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,16 @@ function createFileWatcher() {
allowPartialGraph: true,
},
debounce(async (error, changes) => {
if (error === 'closed') {
output.error({ title: `Watch error: Daemon closed the connection` });
if (error === 'reconnecting') {
// Silent - daemon restarts automatically on lockfile changes
return;
} else if (error === 'reconnected') {
// Silent - reconnection succeeded
return;
} else if (error === 'closed') {
output.error({
title: `Failed to reconnect to daemon after multiple attempts`,
});
process.exit(1);
} else if (error) {
output.error({ title: `Watch error: ${error?.message ?? 'Unknown'}` });
Expand Down
20 changes: 14 additions & 6 deletions packages/nx/src/command-line/watch/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,16 @@ export async function watch(args: WatchArguments) {
includeGlobalWorkspaceFiles: args.includeGlobalWorkspaceFiles,
},
async (err, data) => {
if (err === 'closed') {
if (err === 'reconnecting') {
// Silent - daemon restarts automatically on lockfile changes
return;
} else if (err === 'reconnected') {
// Silent - reconnection succeeded
return;
} else if (err === 'closed') {
output.error({
title: 'Watch connection closed',
bodyLines: [
'The daemon has closed the connection to this watch process.',
'Please restart your watch command.',
],
title: 'Failed to reconnect to daemon after multiple attempts',
bodyLines: ['Please restart your watch command.'],
});
process.exit(1);
} else if (err !== null) {
Expand All @@ -238,4 +241,9 @@ export async function watch(args: WatchArguments) {
}
);
args.verbose && output.logSingleLine('watch process waiting...');

// Keep the process alive while watching for file changes
// The file watcher callbacks will handle incoming events
// The process will exit when Ctrl+C is pressed or if the connection closes
await new Promise(() => {});
}
Loading
Loading