Skip to content

Commit

Permalink
fix(web): file watcher should only watch files in its project #17085 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 authored May 22, 2023
1 parent 78b709e commit 28df418
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 @@ -103,21 +102,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 @@ -151,7 +144,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

1 comment on commit 28df418

@vercel
Copy link

@vercel vercel bot commented on 28df418 May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.