Skip to content

Commit

Permalink
fix(web): file watcher should only watch files in its project nrwl#17085
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed May 19, 2023
1 parent 34bdc4f commit e1f1de9
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions packages/web/src/executors/file-server/file-server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
joinPathFragments,
parseTargetString,
readTargetOptions,
workspaceLayout,
} from '@nx/devkit';
import ignore from 'ignore';
import { copyFileSync, readFileSync, unlinkSync } from 'fs';
Expand Down Expand Up @@ -106,21 +105,15 @@ function getIgnoredGlobs(root: string) {

function createFileWatcher(
root: string,
projectRoot: string,
changeHandler: () => void
): () => void {
const ignoredGlobs = getIgnoredGlobs(root);
const layout = workspaceLayout();

const watcher = watch(
[
joinPathFragments(layout.appsDir, '**'),
joinPathFragments(layout.libsDir, '**'),
],
{
cwd: root,
ignoreInitial: true,
}
);

const watcher = watch([joinPathFragments(projectRoot, '**')], {
cwd: root,
ignoreInitial: true,
});
watcher.on('all', (_event: string, path: string) => {
if (ignoredGlobs.ignores(path)) return;
changeHandler();
Expand Down Expand Up @@ -154,7 +147,9 @@ export default async function* fileServerExecutor(

let disposeWatch: () => void;
if (options.watch) {
disposeWatch = createFileWatcher(context.root, run);
const projectRoot =
context.projectsConfigurations.projects[context.projectName].root;
disposeWatch = createFileWatcher(context.root, projectRoot, run);
}

// perform initial run
Expand Down

0 comments on commit e1f1de9

Please sign in to comment.