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
  • Loading branch information
Cammisuli committed Oct 23, 2023
1 parent cc8d8e8 commit bf697d1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
25 changes: 23 additions & 2 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 @@ -22,6 +23,7 @@ describe('watcher', () => {

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

Expand Down Expand Up @@ -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) {
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 bf697d1

Please sign in to comment.