Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): do not prompt, only warn when projectNameAndRootLayout is … #19037

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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