Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): change the order of watch ignores so that nxignore is the last one added #19801

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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