feat(js): deprecate simpleName option in library generator (#31673)

The simpleName option is no longer useful as we've moved to using
options "as provided" without transformation. Users should provide the
exact name, directory, and import path they want to use.

## Changes
- Add x-deprecated to schema.json marking for removal in Nx 22
- Add runtime warning when simpleName is used


🤖 Generated with [Claude Code](https://claude.ai/code)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
Users are confused with `--simpleName` with using `--name` AND
`--directory`

## Expected Behavior
We should tell users that only `--name` should be used.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #29508

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Jack Hsu 2025-06-20 21:39:55 -04:00 committed by GitHub
parent 8026885128
commit 57e70d0e91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 50 additions and 8 deletions

View File

@ -47,7 +47,8 @@
"simpleName": {
"description": "Don't include the directory in the name of the module or standalone component entry of the library.",
"type": "boolean",
"default": false
"default": false,
"x-deprecated": "Use the --name option to provide the exact name instead. This option will be removed in Nx 22."
},
"addModuleSpec": {
"description": "Add a module spec file.",

View File

@ -130,7 +130,8 @@
"simpleName": {
"description": "Don't include the directory in the generated file name.",
"type": "boolean",
"default": false
"default": false,
"x-deprecated": "Use the --name option to provide the exact name instead. This option will be removed in Nx 22."
},
"useProjectJson": {
"type": "boolean",

View File

@ -132,7 +132,8 @@
"simpleName": {
"description": "Don't include the directory in the name of the module of the library.",
"type": "boolean",
"default": false
"default": false,
"x-deprecated": "Use the --name option to provide the exact name instead. This option will be removed in Nx 22."
},
"useProjectJson": {
"type": "boolean",

View File

@ -183,7 +183,8 @@
"simpleName": {
"description": "Don't include the directory in the name of the module of the library.",
"type": "boolean",
"default": false
"default": false,
"x-deprecated": "Use the --name option to provide the exact name instead. This option will be removed in Nx 22."
},
"useProjectJson": {
"type": "boolean",

View File

@ -3,6 +3,7 @@ import {
formatFiles,
GeneratorCallback,
installPackagesTask,
logger,
runTasksInSerial,
Tree,
} from '@nx/devkit';
@ -47,6 +48,13 @@ export async function libraryGenerator(
);
}
if (schema.simpleName !== undefined && schema.simpleName !== false) {
// TODO(v22): Remove simpleName as user should be using name.
logger.warn(
`The "--simpleName" option is deprecated and will be removed in Nx 22. Please use the "--name" option to provide the exact name you want for the library.`
);
}
if (schema.addTailwind && !schema.buildable && !schema.publishable) {
throw new Error(
`To use "--addTailwind" option, you have to set either "--buildable" or "--publishable".`

View File

@ -47,7 +47,8 @@
"simpleName": {
"description": "Don't include the directory in the name of the module or standalone component entry of the library.",
"type": "boolean",
"default": false
"default": false,
"x-deprecated": "Use the --name option to provide the exact name instead. This option will be removed in Nx 22."
},
"addModuleSpec": {
"description": "Add a module spec file.",

View File

@ -7,6 +7,7 @@ import {
GeneratorCallback,
installPackagesTask,
joinPathFragments,
logger,
names,
offsetFromRoot,
ProjectConfiguration,
@ -102,6 +103,13 @@ export async function libraryGeneratorInternal(
);
const options = await normalizeOptions(tree, schema);
if (schema.simpleName !== undefined && schema.simpleName !== false) {
// TODO(v22): Remove simpleName as user should be using name.
logger.warn(
`The "--simpleName" option is deprecated and will be removed in Nx 22. Please use the "--name" option to provide the exact name you want for the library.`
);
}
createFiles(tree, options);
await configureProject(tree, options);

View File

@ -130,7 +130,8 @@
"simpleName": {
"description": "Don't include the directory in the generated file name.",
"type": "boolean",
"default": false
"default": false,
"x-deprecated": "Use the --name option to provide the exact name instead. This option will be removed in Nx 22."
},
"useProjectJson": {
"type": "boolean",

View File

@ -2,6 +2,7 @@ import type { GeneratorCallback, Tree } from '@nx/devkit';
import {
formatFiles,
joinPathFragments,
logger,
readJson,
runTasksInSerial,
writeJson,
@ -37,6 +38,14 @@ export async function libraryGeneratorInternal(
rawOptions: LibraryGeneratorOptions
): Promise<GeneratorCallback> {
const options = await normalizeOptions(tree, rawOptions);
if (rawOptions.simpleName !== undefined && rawOptions.simpleName !== false) {
// TODO(v22): Remove simpleName as user should be using name.
logger.warn(
`The "--simpleName" option is deprecated and will be removed in Nx 22. Please use the "--name" option to provide the exact name you want for the library.`
);
}
const jsLibraryTask = await jsLibraryGenerator(
tree,
toJsLibraryGeneratorOptions(options)

View File

@ -132,7 +132,8 @@
"simpleName": {
"description": "Don't include the directory in the name of the module of the library.",
"type": "boolean",
"default": false
"default": false,
"x-deprecated": "Use the --name option to provide the exact name instead. This option will be removed in Nx 22."
},
"useProjectJson": {
"type": "boolean",

View File

@ -5,6 +5,7 @@ import {
GeneratorCallback,
installPackagesTask,
joinPathFragments,
logger,
readNxJson,
readProjectConfiguration,
runTasksInSerial,
@ -73,6 +74,14 @@ export async function libraryGeneratorInternal(host: Tree, schema: Schema) {
`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`
);
}
if (schema.simpleName !== undefined && schema.simpleName !== false) {
// TODO(v22): Remove simpleName as user should be using name.
logger.warn(
`The "--simpleName" option is deprecated and will be removed in Nx 22. Please use the "--name" option to provide the exact name you want for the library.`
);
}
if (!options.component) {
options.style = 'none';
}

View File

@ -189,7 +189,8 @@
"simpleName": {
"description": "Don't include the directory in the name of the module of the library.",
"type": "boolean",
"default": false
"default": false,
"x-deprecated": "Use the --name option to provide the exact name instead. This option will be removed in Nx 22."
},
"useProjectJson": {
"type": "boolean",