forked from nrwl/nx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(js): use the daemon watcher instead of parcel/watcher (nrwl#13413)
- Loading branch information
Showing
9 changed files
with
140 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,30 @@ | ||
import { logger } from '@nrwl/devkit'; | ||
import { daemonClient } from 'nx/src/daemon/client/client'; | ||
import { join } from 'path'; | ||
|
||
export async function watchForSingleFileChanges( | ||
watchDir: string, | ||
projectName: string, | ||
projectRoot: string, | ||
relativeFilePath: string, | ||
callback: () => void | ||
) { | ||
const watcher = await import('@parcel/watcher'); | ||
const subscription = await watcher.subscribe(watchDir, (err, events) => { | ||
const file = join(watchDir, relativeFilePath); | ||
if (err) { | ||
logger.error(`Watch error: ${err?.message ?? 'Unknown'}`); | ||
} else { | ||
for (const event of events) { | ||
if (event.path === file) { | ||
callback(); | ||
break; | ||
} | ||
): Promise<() => void> { | ||
const unregisterFileWatcher = await daemonClient.registerFileWatcher( | ||
{ watchProjects: [projectName] }, | ||
(err, data) => { | ||
if (err === 'closed') { | ||
logger.error(`Watch error: Daemon closed the connection`); | ||
process.exit(1); | ||
} else if (err) { | ||
logger.error(`Watch error: ${err?.message ?? 'Unknown'}`); | ||
} else if ( | ||
data.changedFiles.some( | ||
(file) => file.path == join(projectRoot, relativeFilePath) | ||
) | ||
) { | ||
callback(); | ||
} | ||
} | ||
}); | ||
); | ||
|
||
return () => subscription.unsubscribe(); | ||
return () => unregisterFileWatcher(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters