fix(core): correctly dedup projects with different names
This commit is contained in:
parent
f1eaa97310
commit
d2bec05e6c
@ -79,13 +79,18 @@ describe('Workspaces', () => {
|
||||
}),
|
||||
'libs/domain/lib4/project.json': JSON.stringify(domainLibConfig),
|
||||
'libs/domain/lib4/package.json': JSON.stringify({}),
|
||||
'workspace.json': JSON.stringify({
|
||||
projects: { 'lib1-workspace': 'libs/lib1' },
|
||||
}),
|
||||
},
|
||||
'/root'
|
||||
);
|
||||
|
||||
const workspaces = new Workspaces('/root');
|
||||
const { projects } = workspaces.readWorkspaceConfiguration();
|
||||
expect(projects.lib1).toEqual(lib1Config);
|
||||
// projects got deduped so the workspace one remained
|
||||
expect(projects['lib1-workspace']).toEqual(lib1Config);
|
||||
expect(projects['lib1']).toBeUndefined();
|
||||
expect(projects.lib2).toEqual(lib2Config);
|
||||
expect(projects['domain-lib3']).toEqual(domainPackageConfig);
|
||||
expect(projects['domain-lib4']).toEqual(domainLibConfig);
|
||||
|
||||
@ -86,10 +86,10 @@ export class Workspaces {
|
||||
const workspaceFile = workspaceConfigName(this.root);
|
||||
|
||||
if (workspaceFile) {
|
||||
workspace.projects = {
|
||||
...workspace.projects,
|
||||
...this.readFromWorkspaceJson().projects,
|
||||
};
|
||||
workspace.projects = this.mergeWorkspaceJsonAndGlobProjects(
|
||||
this.readFromWorkspaceJson().projects,
|
||||
workspace.projects
|
||||
);
|
||||
}
|
||||
|
||||
assertValidWorkspaceConfiguration(nxJson);
|
||||
@ -100,6 +100,24 @@ export class Workspaces {
|
||||
return this.cachedWorkspaceConfig;
|
||||
}
|
||||
|
||||
private mergeWorkspaceJsonAndGlobProjects(
|
||||
workspaceJsonProjects: { [name: string]: any },
|
||||
globProjects: { [name: string]: any }
|
||||
) {
|
||||
const res = workspaceJsonProjects;
|
||||
const folders = new Set();
|
||||
for (let k of Object.keys(res)) {
|
||||
folders.add(res[k].root);
|
||||
}
|
||||
|
||||
for (let k of Object.keys(globProjects)) {
|
||||
if (!folders.has(globProjects[k].root)) {
|
||||
res[k] = globProjects[k];
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private mergeTargetDefaultsIntoProjectDescriptions(
|
||||
config: ProjectsConfigurations,
|
||||
nxJson: NxJsonConfiguration
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user