-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): read project name from package json if not set in project …
…json
- Loading branch information
1 parent
b54f5c3
commit 22eb068
Showing
4 changed files
with
52 additions
and
3 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
28 changes: 28 additions & 0 deletions
28
packages/nx/src/migrations/update-19-2-1/set-project-name.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,28 @@ | ||
import { toProjectName } from '../../config/to-project-name'; | ||
import { ProjectConfiguration } from '../../config/workspace-json-project-json'; | ||
import { Tree } from '../../generators/tree'; | ||
import { readJson, writeJson } from '../../generators/utils/json'; | ||
import { getProjects } from '../../generators/utils/project-configuration'; | ||
|
||
export default function setProjectName(tree: Tree) { | ||
// We are explicitly looking for project.json files here, so getProjects is fine. | ||
const projects = getProjects(tree); | ||
|
||
for (const { root } of projects.values()) { | ||
if (!tree.exists(`${root}/project.json`)) { | ||
continue; | ||
} | ||
const projectJson: ProjectConfiguration = readJson( | ||
tree, | ||
`${root}/project.json` | ||
); | ||
// In Nx 19.1+, the way the project name is inferred is different. | ||
// For existing projects, if the name is not set, we can inline it | ||
// based on the existing logic. This makes sure folks aren't caught | ||
// off guard by the new behavior. | ||
if (!projectJson.name) { | ||
projectJson.name = toProjectName(root); | ||
writeJson(tree, `${root}/project.json`, projectJson); | ||
} | ||
} | ||
} |
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