fix(core): fix project file map for root projects (#17894)
This commit is contained in:
parent
3d77b4d40e
commit
15904616df
@ -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 () => {
|
it('should dedupe configuration files', async () => {
|
||||||
const fs = new TempFs('workspace-files');
|
const fs = new TempFs('workspace-files');
|
||||||
const nxJson: NxJsonConfiguration = {};
|
const nxJson: NxJsonConfiguration = {};
|
||||||
|
|||||||
@ -46,20 +46,16 @@ pub fn get_workspace_files_native(
|
|||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
.map(|file_data| {
|
.map(|file_data| {
|
||||||
let file_path = Path::new(&file_data.file);
|
let file_path = Path::new(&file_data.file);
|
||||||
trace!(?file_path);
|
|
||||||
let mut parent = file_path.parent().unwrap_or_else(|| Path::new(""));
|
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("") {
|
while root_map.get(parent).is_none() && parent != Path::new("") {
|
||||||
return (FileLocation::Global, file_data);
|
parent = parent.parent().unwrap_or_else(|| Path::new(""));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let project_name = root_map.get(parent).unwrap();
|
match root_map.get(parent) {
|
||||||
|
Some(project_name) => (FileLocation::Project(project_name.clone()), file_data),
|
||||||
(FileLocation::Project(project_name.clone()), file_data)
|
None => (FileLocation::Global, file_data),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<(FileLocation, FileData)>>();
|
.collect::<Vec<(FileLocation, FileData)>>();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user