Skip to content

Commit

Permalink
fix(devkit): fix extractLayoutDirectory typescript types to better re…
Browse files Browse the repository at this point in the history
…flect allowed params and return value (#15339)
  • Loading branch information
kdawgwilk authored Jan 29, 2024
1 parent 2cb241a commit 8274f34
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
16 changes: 8 additions & 8 deletions docs/generated/devkit/extractLayoutDirectory.md
Original file line number Diff line number Diff line change
@@ -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` |
26 changes: 25 additions & 1 deletion packages/devkit/src/utils/get-workspace-layout.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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,
});
});
});
6 changes: 3 additions & 3 deletions packages/devkit/src/utils/get-workspace-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

1 comment on commit 8274f34

@vercel
Copy link

@vercel vercel bot commented on 8274f34 Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.