Skip to content

Commit

Permalink
fix(misc): set project names used the old logic including dirs
Browse files Browse the repository at this point in the history
(cherry picked from commit 4ba4bd0)
  • Loading branch information
vsavkin authored and FrozenPandaz committed Nov 8, 2022
1 parent 345ab18 commit 098903f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/nx/src/migrations/update-15-1-0/set-project-names.ts
@@ -1,6 +1,7 @@
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';
Expand All @@ -10,10 +11,23 @@ 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'))) {
projConfig.name ??= projName;
if (!projConfig.name) {
projConfig.name = toProjectName(projConfig.root, readNxJson(tree));
}
updateProjectConfiguration(tree, projName, projConfig);
}
}

await formatChangedFilesWithPrettierIfAvailable(tree);
}

function toProjectName(directory: string, nxJson: any): string {
let { appsDir, libsDir } = nxJson?.workspaceLayout || {};
appsDir ??= 'apps';
libsDir ??= 'libs';
const parts = directory.split(/[\/\\]/g);
if ([appsDir, libsDir].includes(parts[0])) {
parts.splice(0, 1);
}
return parts.join('-').toLowerCase();
}

0 comments on commit 098903f

Please sign in to comment.