Skip to content

Commit

Permalink
fix(core): change the order of watch ignores so that nxignore is the …
Browse files Browse the repository at this point in the history
…last one added (#19801)

(cherry picked from commit d077efa)
  • Loading branch information
Cammisuli authored and FrozenPandaz committed Oct 25, 2023
1 parent 0ab6d2f commit f02b1ec
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
22 changes: 18 additions & 4 deletions packages/nx/src/native/tests/watcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': '',
Expand All @@ -20,8 +21,9 @@ describe('watcher', () => {
console.log(`watching ${temp.tempDir}`);
});

afterEach(() => {
watcher.stop();
afterEach(async () => {
await watcher.stop();
watcher = undefined;
temp.cleanup();
});

Expand Down Expand Up @@ -134,6 +136,18 @@ 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.some(({ path }) => path === '.env.local')).toBeTruthy();
done();
});

wait().then(() => {
temp.appendFile('.env.local', 'hello');
});
});
});

function wait(timeout = 500) {
Expand Down
12 changes: 9 additions & 3 deletions packages/nx/src/native/watch/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ pub(super) fn get_ignore_files<T: AsRef<str>>(root: T) -> Vec<IgnoreFile> {

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::<Vec<PathBuf>>();

ignores.sort();

ignores
.into_iter()
.map(|path| {
let parent: PathBuf = path.parent().unwrap_or(&path).into();
IgnoreFile {
path,
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/native/watch/watch_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f02b1ec

Please sign in to comment.