Skip to content

Commit

Permalink
fix(core): correctly dedup projects with different names
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Oct 25, 2022
1 parent f1eaa97 commit d2bec05
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
7 changes: 6 additions & 1 deletion packages/nx/src/config/workspaces.spec.ts
Expand Up @@ -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);
Expand Down
26 changes: 22 additions & 4 deletions packages/nx/src/config/workspaces.ts
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit d2bec05

Please sign in to comment.