diff --git a/packages/nx/src/native/tests/watcher.spec.ts b/packages/nx/src/native/tests/watcher.spec.ts index 954b593facdeea..80c95aa604f93d 100644 --- a/packages/nx/src/native/tests/watcher.spec.ts +++ b/packages/nx/src/native/tests/watcher.spec.ts @@ -7,8 +7,9 @@ describe('watcher', () => { beforeEach(() => { temp = new TempFs('watch-dir'); temp.createFilesSync({ - '.gitignore': 'node_modules/', - '.nxignore': 'app2/', + '.gitignore': 'node_modules/\n.env.local', + '.nxignore': 'app2/\n!.env.local', + '.env.local': '', 'app1/main.js': '', 'app1/main.css': '', 'app2/main.js': '', @@ -22,6 +23,7 @@ describe('watcher', () => { afterEach(() => { watcher.stop(); + watcher = undefined; temp.cleanup(); }); @@ -134,6 +136,25 @@ describe('watcher', () => { temp.createFileSync('boo.txt', ''); }); }); + + it('should include files that are negated in nxignore but are ignored in gitignore', (done) => { + watcher = new Watcher(temp.tempDir); + watcher.watch((err, paths) => { + expect(paths).toMatchInlineSnapshot(` + [ + { + "path": ".env.local", + "type": "update", + }, + ] + `); + done(); + }); + + wait(1000).then(() => { + temp.appendFile('.env.local', 'hello'); + }); + }); }); function wait(timeout = 500) { diff --git a/packages/nx/src/native/watch/utils.rs b/packages/nx/src/native/watch/utils.rs index 568afd8a55d4b5..968cd60d012169 100644 --- a/packages/nx/src/native/watch/utils.rs +++ b/packages/nx/src/native/watch/utils.rs @@ -15,14 +15,20 @@ pub(super) fn get_ignore_files>(root: T) -> Vec { let node_folder = PathBuf::from(root).join("node_modules"); walker.filter_entry(move |entry| !entry.path().starts_with(&node_folder)); - walker + let mut ignores = walker .build() .flatten() .filter(|result| { result.path().ends_with(".nxignore") || result.path().ends_with(".gitignore") }) - .map(|result| { - let path: PathBuf = result.path().into(); + .map(|result| result.path().into()) + .collect::>(); + + ignores.sort(); + + ignores + .into_iter() + .map(|path| { let parent: PathBuf = path.parent().unwrap_or(&path).into(); IgnoreFile { path, diff --git a/packages/nx/src/native/watch/watch_config.rs b/packages/nx/src/native/watch/watch_config.rs index 353c20d95f808a..7ed93a29af2318 100644 --- a/packages/nx/src/native/watch/watch_config.rs +++ b/packages/nx/src/native/watch/watch_config.rs @@ -28,7 +28,7 @@ pub(super) async fn create_runtime( .map_err(anyhow::Error::from)?; filter - .add_globs(&additional_globs, Some(&origin.into())) + .add_globs(additional_globs, Some(&origin.into())) .map_err(anyhow::Error::from)?; let mut runtime = RuntimeConfig::default();