-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repo): remove projectNameAndRoot nx.json option (nrwl#19218)
- Loading branch information
1 parent
d9b3115
commit 67715b7
Showing
13 changed files
with
113 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/nx/src/migrations/update-16-9-0/remove-project-name-and-root-format.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { readJson, writeJson } from '../../generators/utils/json'; | ||
import { createTree } from '../../generators/testing-utils/create-tree'; | ||
import removeProjectNameAndRootFormat from './remove-project-name-and-root-format'; | ||
import { NxJsonConfiguration } from '../../config/nx-json'; | ||
|
||
describe('removeProjectNameAndRootFormat', () => { | ||
let tree; | ||
beforeEach(() => { | ||
tree = createTree(); | ||
}); | ||
|
||
it('should not error if nx.json is not present', async () => { | ||
await removeProjectNameAndRootFormat(tree); | ||
}); | ||
|
||
it('should not update nx.json if projectNameAndRoot is not present', async () => { | ||
const nxJson: NxJsonConfiguration = {}; | ||
writeJson(tree, 'nx.json', nxJson); | ||
await removeProjectNameAndRootFormat(tree); | ||
expect(readJson(tree, 'nx.json')).toEqual(nxJson); | ||
}); | ||
|
||
it('should remove projectNameAndRoot if it is present', async () => { | ||
const nxJson: any = { | ||
workspaceLayout: { | ||
libsDir: 'libs', | ||
projectNameAndRootFormat: 'as-provided', | ||
}, | ||
}; | ||
writeJson(tree, 'nx.json', nxJson); | ||
await removeProjectNameAndRootFormat(tree); | ||
expect(readJson(tree, 'nx.json').workspaceLayout).toEqual({ | ||
libsDir: 'libs', | ||
}); | ||
}); | ||
|
||
it('should remove workspaceLayout if it is present', async () => { | ||
const nxJson: any = { | ||
workspaceLayout: { | ||
projectNameAndRootFormat: 'as-provided', | ||
}, | ||
}; | ||
writeJson(tree, 'nx.json', nxJson); | ||
await removeProjectNameAndRootFormat(tree); | ||
expect(readJson(tree, 'nx.json').workspaceLayout).not.toBeDefined(); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
packages/nx/src/migrations/update-16-9-0/remove-project-name-and-root-format.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Tree } from '../../generators/tree'; | ||
import { updateJson } from '../../generators/utils/json'; | ||
import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; | ||
|
||
export default async function removeProjectNameAndRootFormat(tree: Tree) { | ||
if (!tree.exists('nx.json')) { | ||
return; | ||
} | ||
|
||
updateJson(tree, 'nx.json', (nxJson) => { | ||
if (!nxJson.workspaceLayout) { | ||
return nxJson; | ||
} | ||
|
||
delete nxJson.workspaceLayout.projectNameAndRootFormat; | ||
|
||
if (Object.keys(nxJson.workspaceLayout).length === 0) { | ||
delete nxJson.workspaceLayout; | ||
} | ||
|
||
return nxJson; | ||
}); | ||
|
||
await formatChangedFilesWithPrettierIfAvailable(tree); | ||
} |
Oops, something went wrong.