diff --git a/packages/nx/src/config/workspaces.spec.ts b/packages/nx/src/config/workspaces.spec.ts index 3a608dda9d83a..4b1e66930ac72 100644 --- a/packages/nx/src/config/workspaces.spec.ts +++ b/packages/nx/src/config/workspaces.spec.ts @@ -50,6 +50,9 @@ describe('Workspaces', () => { vol.fromJSON( { 'libs/lib1/project.json': JSON.stringify(standaloneConfig), + 'libs/lib2/package.json': JSON.stringify({}), + 'libs/domain/lib3/package.json': JSON.stringify({}), + 'libs/domain/lib4/project.json': JSON.stringify({}), 'workspace.json': JSON.stringify(config), }, '/root' diff --git a/packages/nx/src/config/workspaces.ts b/packages/nx/src/config/workspaces.ts index ca3fb9b3c7f08..356a1e2476071 100644 --- a/packages/nx/src/config/workspaces.ts +++ b/packages/nx/src/config/workspaces.ts @@ -77,22 +77,20 @@ export class Workspaces { return this.cachedWorkspaceConfig; } const nxJson = this.readNxJson(); + const workspace = buildWorkspaceConfigurationFromGlobs( + nxJson, + globForProjectFiles(this.root, nxJson, opts?._ignorePluginInference), + (path) => readJsonFile(join(this.root, path)) + ); + const workspaceFile = workspaceConfigName(this.root); - const workspacePath = workspaceFile - ? path.join(this.root, workspaceFile) - : null; - const workspace = - workspacePath && existsSync(workspacePath) - ? this.readFromWorkspaceJson() - : buildWorkspaceConfigurationFromGlobs( - nxJson, - globForProjectFiles( - this.root, - nxJson, - opts?._ignorePluginInference - ), - (path) => readJsonFile(join(this.root, path)) - ); + + if (workspaceFile) { + workspace.projects = { + ...workspace.projects, + ...this.readFromWorkspaceJson().projects, + }; + } assertValidWorkspaceConfiguration(nxJson); this.cachedWorkspaceConfig = {