feat(devkit): warn users the project name and root will not be derived (#18718)
This commit is contained in:
parent
1bb9c116e1
commit
b309d8386c
@ -322,7 +322,7 @@ describe('determineProjectNameAndRootOptions', () => {
|
|||||||
message: `Derived:
|
message: `Derived:
|
||||||
Name: shared-lib-name
|
Name: shared-lib-name
|
||||||
Root: shared/lib-name`,
|
Root: shared/lib-name`,
|
||||||
name: 'shared-lib-name @ shared/lib-name (This was derived from the folder structure. Please provide the exact name and directory in the future)',
|
name: 'shared-lib-name @ shared/lib-name',
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -680,7 +680,7 @@ describe('determineProjectNameAndRootOptions', () => {
|
|||||||
message: `Derived:
|
message: `Derived:
|
||||||
Name: shared-lib-name
|
Name: shared-lib-name
|
||||||
Root: libs/shared/lib-name`,
|
Root: libs/shared/lib-name`,
|
||||||
name: 'shared-lib-name @ libs/shared/lib-name (This was derived from the folder structure. Please provide the exact name and directory in the future)',
|
name: 'shared-lib-name @ libs/shared/lib-name',
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@ -8,8 +8,14 @@ import {
|
|||||||
} from '../utils/get-workspace-layout';
|
} from '../utils/get-workspace-layout';
|
||||||
import { names } from '../utils/names';
|
import { names } from '../utils/names';
|
||||||
|
|
||||||
const { joinPathFragments, normalizePath, readJson, readNxJson, updateNxJson } =
|
const {
|
||||||
requireNx();
|
joinPathFragments,
|
||||||
|
normalizePath,
|
||||||
|
logger,
|
||||||
|
readJson,
|
||||||
|
readNxJson,
|
||||||
|
updateNxJson,
|
||||||
|
} = requireNx();
|
||||||
|
|
||||||
export type ProjectNameAndRootFormat = 'as-provided' | 'derived';
|
export type ProjectNameAndRootFormat = 'as-provided' | 'derived';
|
||||||
export type ProjectGenerationOptions = {
|
export type ProjectGenerationOptions = {
|
||||||
@ -109,7 +115,7 @@ function validateName(
|
|||||||
async function determineFormat(
|
async function determineFormat(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
formats: ProjectNameAndRootFormats,
|
formats: ProjectNameAndRootFormats,
|
||||||
callingGenerator: string
|
callingGenerator: string | null
|
||||||
): Promise<ProjectNameAndRootFormat> {
|
): Promise<ProjectNameAndRootFormat> {
|
||||||
if (!formats.derived) {
|
if (!formats.derived) {
|
||||||
return 'as-provided';
|
return 'as-provided';
|
||||||
@ -126,7 +132,7 @@ async function determineFormat(
|
|||||||
const derivedDescription = `Derived:
|
const derivedDescription = `Derived:
|
||||||
Name: ${formats['derived'].projectName}
|
Name: ${formats['derived'].projectName}
|
||||||
Root: ${formats['derived'].projectRoot}`;
|
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 }>({
|
const result = await prompt<{ format: ProjectNameAndRootFormat }>({
|
||||||
type: 'select',
|
type: 'select',
|
||||||
@ -147,11 +153,16 @@ async function determineFormat(
|
|||||||
}).then(({ format }) =>
|
}).then(({ format }) =>
|
||||||
format === asProvidedSelectedValue ? 'as-provided' : 'derived'
|
format === asProvidedSelectedValue ? 'as-provided' : 'derived'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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' && callingGenerator) {
|
if (result === 'as-provided' && callingGenerator) {
|
||||||
const { saveDefault } = await prompt<{ saveDefault: boolean }>({
|
const { saveDefault } = await prompt<{ saveDefault: boolean }>({
|
||||||
type: 'confirm',
|
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',
|
name: 'saveDefault',
|
||||||
|
initial: true,
|
||||||
});
|
});
|
||||||
if (saveDefault) {
|
if (saveDefault) {
|
||||||
const nxJson = readNxJson(tree);
|
const nxJson = readNxJson(tree);
|
||||||
@ -159,7 +170,11 @@ async function determineFormat(
|
|||||||
nxJson.generators[callingGenerator] ??= {};
|
nxJson.generators[callingGenerator] ??= {};
|
||||||
nxJson.generators[callingGenerator].projectNameAndRootFormat = result;
|
nxJson.generators[callingGenerator].projectNameAndRootFormat = result;
|
||||||
updateNxJson(tree, nxJson);
|
updateNxJson(tree, nxJson);
|
||||||
|
} else {
|
||||||
|
logger.warn(deprecationWarning);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
logger.warn(deprecationWarning);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user