Skip to content

Commit

Permalink
feat(devkit): warn users the project name and root will not be derived
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Aug 18, 2023
1 parent 44b2d3f commit ca2a426
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions packages/devkit/src/generators/project-name-and-root-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ import {
} from '../utils/get-workspace-layout';
import { names } from '../utils/names';

const { joinPathFragments, normalizePath, readJson, readNxJson, updateNxJson } =
requireNx();
const {
joinPathFragments,
normalizePath,
logger,
readJson,
readNxJson,
updateNxJson,
} = requireNx();

export type ProjectNameAndRootFormat = 'as-provided' | 'derived';
export type ProjectGenerationOptions = {
Expand Down Expand Up @@ -126,7 +132,7 @@ async function determineFormat(
const derivedDescription = `Derived:
Name: ${formats['derived'].projectName}
Root: ${formats['derived'].projectRoot}`;
const derivedSelectedValue = `${formats['derived'].projectName} @ ${formats['derived'].projectRoot} (This was derived from the folder structure. Please provide the exact name and directory in the future)`;
const derivedSelectedValue = `${formats['derived'].projectName} @ ${formats['derived'].projectRoot}`;

const result = await prompt<{ format: ProjectNameAndRootFormat }>({
type: 'select',
Expand All @@ -147,19 +153,28 @@ async function determineFormat(
}).then(({ format }) =>
format === asProvidedSelectedValue ? 'as-provided' : 'derived'
);
if (result === 'as-provided' && callingGenerator) {

const deprecationWarning =
'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') {
const { saveDefault } = await prompt<{ saveDefault: boolean }>({
type: 'confirm',
message: 'Would you like to save this layout as a default?',
message: `Would you like to configure Nx to always take project name and root as provided for ${callingGenerator}?`,
name: 'saveDefault',
initial: true,
});
if (saveDefault) {
const nxJson = readNxJson(tree);
nxJson.generators ??= {};
nxJson.generators[callingGenerator] ??= {};
nxJson.generators[callingGenerator].projectNameAndRootFormat = result;
updateNxJson(tree, nxJson);
} else {
logger.warn(deprecationWarning);
}
} else {
logger.warn(deprecationWarning);
}

return result;
Expand Down

0 comments on commit ca2a426

Please sign in to comment.