Skip to content

Commit

Permalink
fix(core): fix exclude for empty array (#22951)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8ded380)
  • Loading branch information
FrozenPandaz committed Apr 25, 2024
1 parent f07ac05 commit 9b5a1cb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
46 changes: 46 additions & 0 deletions packages/nx/src/native/tests/workspace_files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,52 @@ describe('workspace files', () => {
`);
});

describe('globbing', () => {
let context: WorkspaceContext;
let fs: TempFs;

beforeEach(async () => {
fs = new TempFs('workspace-files');

await fs.createFiles({
'file.txt': '',
'file.css': '',
'file.js': '',
});

context = new WorkspaceContext(
fs.tempDir,
cacheDirectoryForWorkspace(fs.tempDir)
);
});

afterEach(() => {
context = null;
fs.reset();
});

it('should glob', () => {
const results = context.glob(['**/*.txt']);
expect(results).toContain('file.txt');
expect(results).not.toContain('file.css');
expect(results).not.toContain('file.js');
});

it('should glob and exclude patterns', () => {
const results = context.glob(['**/*'], ['**/*.txt']);
expect(results).not.toContain('file.txt');
expect(results).toContain('file.css');
expect(results).toContain('file.js');
});

it('should glob and not exclude if exclude is empty', () => {
const results = context.glob(['**/*'], []);
expect(results).toContain('file.txt');
expect(results).toContain('file.css');
expect(results).toContain('file.js');
});
});

// describe('errors', () => {
// it('it should infer names of configuration files without a name', async () => {
// const fs = new TempFs('workspace-files');
Expand Down
13 changes: 10 additions & 3 deletions packages/nx/src/native/workspace/config_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ pub(super) fn glob_files(
) -> napi::Result<impl ParallelIterator<Item = &FileData>> {
let globs = build_glob_set(&globs)?;

let exclude_glob_set = exclude
.map(|exclude| build_glob_set(&exclude))
.transpose()?;
let exclude_glob_set = match exclude {
Some(exclude) => {
if exclude.is_empty() {
None
} else {
Some(build_glob_set(&exclude)?)
}
}
None => None,
};

Ok(files.par_iter().filter(move |file_data| {
let path = &file_data.file;
Expand Down

0 comments on commit 9b5a1cb

Please sign in to comment.