diff --git a/docs/generated/devkit/extractLayoutDirectory.md b/docs/generated/devkit/extractLayoutDirectory.md index fd5b06fc80675..7b460e9934dc6 100644 --- a/docs/generated/devkit/extractLayoutDirectory.md +++ b/docs/generated/devkit/extractLayoutDirectory.md @@ -1,20 +1,20 @@ # Function: extractLayoutDirectory -▸ **extractLayoutDirectory**(`directory`): `Object` +▸ **extractLayoutDirectory**(`directory?`): `Object` Experimental #### Parameters -| Name | Type | -| :---------- | :------- | -| `directory` | `string` | +| Name | Type | +| :----------- | :------- | +| `directory?` | `string` | #### Returns `Object` -| Name | Type | -| :----------------- | :------- | -| `layoutDirectory` | `string` | -| `projectDirectory` | `string` | +| Name | Type | +| :------------------ | :----------------- | +| `layoutDirectory` | `string` \| `null` | +| `projectDirectory?` | `string` | diff --git a/packages/devkit/src/utils/get-workspace-layout.spec.ts b/packages/devkit/src/utils/get-workspace-layout.spec.ts index 2766632f458ff..79d8bd13e5a63 100644 --- a/packages/devkit/src/utils/get-workspace-layout.spec.ts +++ b/packages/devkit/src/utils/get-workspace-layout.spec.ts @@ -1,5 +1,8 @@ import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports'; -import { getWorkspaceLayout } from './get-workspace-layout'; +import { + getWorkspaceLayout, + extractLayoutDirectory, +} from './get-workspace-layout'; describe('getWorkspaceLayout', () => { it('should return selected values', () => { @@ -59,3 +62,24 @@ describe('getWorkspaceLayout', () => { }); }); }); + +describe('extractLayoutDirectory', () => { + it('should extract layout directory', () => { + expect(extractLayoutDirectory('apps/my-app')).toEqual({ + layoutDirectory: 'apps', + projectDirectory: 'my-app', + }); + expect(extractLayoutDirectory('libs/my-lib')).toEqual({ + layoutDirectory: 'libs', + projectDirectory: 'my-lib', + }); + expect(extractLayoutDirectory('packages/my-package')).toEqual({ + layoutDirectory: 'packages', + projectDirectory: 'my-package', + }); + expect(extractLayoutDirectory(undefined)).toEqual({ + layoutDirectory: null, + projectDirectory: undefined, + }); + }); +}); diff --git a/packages/devkit/src/utils/get-workspace-layout.ts b/packages/devkit/src/utils/get-workspace-layout.ts index a173c5d193cc1..4bb41e3ce6519 100644 --- a/packages/devkit/src/utils/get-workspace-layout.ts +++ b/packages/devkit/src/utils/get-workspace-layout.ts @@ -34,9 +34,9 @@ export function getWorkspaceLayout(tree: Tree): { /** * Experimental */ -export function extractLayoutDirectory(directory: string): { - layoutDirectory: string; - projectDirectory: string; +export function extractLayoutDirectory(directory?: string): { + layoutDirectory: string | null; + projectDirectory?: string; } { if (directory) { directory = directory.startsWith('/') ? directory.substring(1) : directory;