Skip to content

Commit

Permalink
fix(core): do not prompt, only warn when projectNameAndRootLayout is … (
Browse files Browse the repository at this point in the history
#19037)

(cherry picked from commit 850cdb3)
  • Loading branch information
FrozenPandaz committed Sep 7, 2023
1 parent 6ac6473 commit 18acd9a
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions packages/devkit/src/generators/project-name-and-root-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ type ProjectNameAndRootFormats = {
derived?: ProjectNameAndRootOptions;
};

const deprecationWarning = stripIndents`
In Nx 18, generating projects will no longer derive the name and root.
Please provide the exact project name and root in the future.`;

export async function determineProjectNameAndRootOptions(
tree: Tree,
options: ProjectGenerationOptions
Expand All @@ -73,11 +77,18 @@ export async function determineProjectNameAndRootOptions(
> {
validateName(options.name, options.projectNameAndRootFormat);
const formats = getProjectNameAndRootFormats(tree, options);
const configuredDefault = getDefaultProjectNameAndRootFormat(tree);

if (configuredDefault === 'derived') {
logger.warn(
deprecationWarning + '\n' + getExample(options.callingGenerator, formats)
);
}

const format =
options.projectNameAndRootFormat ??
(getDefaultProjectNameAndRootFormat(tree) === 'as-provided'
? 'as-provided'
: await determineFormat(tree, formats, options.callingGenerator));
configuredDefault ??
(await determineFormat(tree, formats, options.callingGenerator));

return {
...formats[format],
Expand Down Expand Up @@ -115,6 +126,13 @@ function validateName(
}
}

function getExample(
callingGenerator: string,
formats: ProjectNameAndRootFormats
) {
return `Example: nx g ${callingGenerator} ${formats['as-provided'].projectName} --directory ${formats['as-provided'].projectRoot}`;
}

async function determineFormat(
tree: Tree,
formats: ProjectNameAndRootFormats,
Expand Down Expand Up @@ -157,10 +175,6 @@ async function determineFormat(
format === asProvidedSelectedValue ? 'as-provided' : 'derived'
);

const deprecationWarning = stripIndents`
In Nx 18, generating projects will no longer derive the name and root.
Please provide the exact project name and root in the future.`;

if (result === 'as-provided' && callingGenerator) {
const { saveDefault } = await prompt<{ saveDefault: boolean }>({
type: 'confirm',
Expand All @@ -174,7 +188,7 @@ async function determineFormat(
logger.warn(deprecationWarning);
}
} else {
const example = `Example: nx g ${callingGenerator} ${formats[result].projectName} --directory ${formats[result].projectRoot}`;
const example = getExample(callingGenerator, formats);
logger.warn(deprecationWarning + '\n' + example);
}

Expand All @@ -190,7 +204,7 @@ function setProjectNameAndRootFormatDefault(tree: Tree) {

function getDefaultProjectNameAndRootFormat(tree: Tree) {
const nxJson = readNxJson(tree);
return nxJson.workspaceLayout?.projectNameAndRootFormat ?? 'derived';
return nxJson.workspaceLayout?.projectNameAndRootFormat;
}

function getProjectNameAndRootFormats(
Expand Down

0 comments on commit 18acd9a

Please sign in to comment.