From b0907ec6779ad2e6b4dca4fa6688af287cdaa62f Mon Sep 17 00:00:00 2001 From: Victor Savkin Date: Wed, 16 Nov 2022 10:23:46 -0500 Subject: [PATCH] fix(core): set project names using a blog instead of project graph --- .../update-15-1-0/set-project-names.ts | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/packages/nx/src/migrations/update-15-1-0/set-project-names.ts b/packages/nx/src/migrations/update-15-1-0/set-project-names.ts index 08f8af2084eb64..480982661c72af 100644 --- a/packages/nx/src/migrations/update-15-1-0/set-project-names.ts +++ b/packages/nx/src/migrations/update-15-1-0/set-project-names.ts @@ -1,24 +1,21 @@ import { Tree } from '../../generators/tree'; -import { - getProjects, - readNxJson, - updateProjectConfiguration, -} from '../../generators/utils/project-configuration'; -import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available'; -import { join } from 'path'; +import { readNxJson } from '../../generators/utils/project-configuration'; +import { globForProjectFiles } from '../../config/workspaces'; +import { dirname } from 'path'; +import { readJson, writeJson } from '../../generators/utils/json'; export default async function (tree: Tree) { - // This looks like it does nothing, but this will actually effectively migrate over all the configs that need to be moved over, but won't touch configs that don't need to be moved - for (const [projName, projConfig] of getProjects(tree)) { - if (tree.exists(join(projConfig.root, 'project.json'))) { - if (!projConfig.name) { - projConfig.name = toProjectName(projConfig.root, readNxJson(tree)); - } - updateProjectConfiguration(tree, projName, projConfig); + const nxJson = readNxJson(tree); + const projectFiles = globForProjectFiles(tree.root, nxJson); + const projectJsons = projectFiles.filter((f) => f.endsWith('project.json')); + + for (let f of projectJsons) { + const projectJson = readJson(tree, f); + if (!projectJson.name) { + projectJson.name = toProjectName(dirname(f), nxJson); + writeJson(tree, f, projectJson); } } - - await formatChangedFilesWithPrettierIfAvailable(tree); } function toProjectName(directory: string, nxJson: any): string {