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): fix project file map for root projects #17894

Merged
merged 1 commit into from
Jun 30, 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
50 changes: 50 additions & 0 deletions packages/nx/src/native/tests/workspace_files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,56 @@ describe('workspace files', () => {
]
`);
});

it('should assign files to the root project if it exists', async () => {
const fs = new TempFs('workspace-files');
const nxJson: NxJsonConfiguration = {};
await fs.createFiles({
'./nx.json': JSON.stringify(nxJson),
'./package.json': JSON.stringify({
name: 'repo-name',
version: '0.0.0',
dependencies: {},
}),
'./project.json': JSON.stringify({
name: 'repo-name',
}),
'./src/index.js': '',
'./jest.config.js': '',
});
const globs = ['project.json', '**/project.json', '**/package.json'];
const { globalFiles, projectFileMap } = getWorkspaceFilesNative(
fs.tempDir,
globs
);

expect(globalFiles).toEqual([]);
expect(projectFileMap['repo-name']).toMatchInlineSnapshot(`
[
{
"file": "jest.config.js",
"hash": "3244421341483603138",
},
{
"file": "nx.json",
"hash": "1389868326933519382",
},
{
"file": "package.json",
"hash": "14409636362330144230",
},
{
"file": "project.json",
"hash": "4357927788053707201",
},
{
"file": "src/index.js",
"hash": "3244421341483603138",
},
]
`);
});

it('should dedupe configuration files', async () => {
const fs = new TempFs('workspace-files');
const nxJson: NxJsonConfiguration = {};
Expand Down
16 changes: 6 additions & 10 deletions packages/nx/src/native/workspace/get_nx_workspace_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,16 @@ pub fn get_workspace_files_native(
.into_par_iter()
.map(|file_data| {
let file_path = Path::new(&file_data.file);
trace!(?file_path);
let mut parent = file_path.parent().unwrap_or_else(|| Path::new(""));
trace!(?parent);
while root_map.get(parent).is_none() {
parent = parent.parent().unwrap_or_else(|| Path::new(""));

if parent == Path::new("") {
return (FileLocation::Global, file_data);
}
while root_map.get(parent).is_none() && parent != Path::new("") {
parent = parent.parent().unwrap_or_else(|| Path::new(""));
}

let project_name = root_map.get(parent).unwrap();

(FileLocation::Project(project_name.clone()), file_data)
match root_map.get(parent) {
Some(project_name) => (FileLocation::Project(project_name.clone()), file_data),
None => (FileLocation::Global, file_data),
}
})
.collect::<Vec<(FileLocation, FileData)>>();

Expand Down