From 57e70d0e91c4af1c1b0d8e2c875a8dcedc7e0b23 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Fri, 20 Jun 2025 21:39:55 -0400 Subject: [PATCH] feat(js): deprecate simpleName option in library generator (#31673) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) ## 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) Fixes #29508 --------- Co-authored-by: Claude --- docs/generated/packages/angular/generators/library.json | 3 ++- docs/generated/packages/js/generators/library.json | 3 ++- docs/generated/packages/nest/generators/library.json | 3 ++- docs/generated/packages/react/generators/library.json | 3 ++- packages/angular/src/generators/library/library.ts | 8 ++++++++ packages/angular/src/generators/library/schema.json | 3 ++- packages/js/src/generators/library/library.ts | 8 ++++++++ packages/js/src/generators/library/schema.json | 3 ++- packages/nest/src/generators/library/library.ts | 9 +++++++++ packages/nest/src/generators/library/schema.json | 3 ++- packages/react/src/generators/library/library.ts | 9 +++++++++ packages/react/src/generators/library/schema.json | 3 ++- 12 files changed, 50 insertions(+), 8 deletions(-) diff --git a/docs/generated/packages/angular/generators/library.json b/docs/generated/packages/angular/generators/library.json index 003c2cba87..18cf21eb42 100644 --- a/docs/generated/packages/angular/generators/library.json +++ b/docs/generated/packages/angular/generators/library.json @@ -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.", diff --git a/docs/generated/packages/js/generators/library.json b/docs/generated/packages/js/generators/library.json index 1f15de9846..75cc00ac2c 100644 --- a/docs/generated/packages/js/generators/library.json +++ b/docs/generated/packages/js/generators/library.json @@ -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", diff --git a/docs/generated/packages/nest/generators/library.json b/docs/generated/packages/nest/generators/library.json index 3e60336887..bff889b650 100644 --- a/docs/generated/packages/nest/generators/library.json +++ b/docs/generated/packages/nest/generators/library.json @@ -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", diff --git a/docs/generated/packages/react/generators/library.json b/docs/generated/packages/react/generators/library.json index 0bd0ea4e5d..d74531b1fd 100644 --- a/docs/generated/packages/react/generators/library.json +++ b/docs/generated/packages/react/generators/library.json @@ -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", diff --git a/packages/angular/src/generators/library/library.ts b/packages/angular/src/generators/library/library.ts index 95597c824a..ec0f960675 100644 --- a/packages/angular/src/generators/library/library.ts +++ b/packages/angular/src/generators/library/library.ts @@ -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".` diff --git a/packages/angular/src/generators/library/schema.json b/packages/angular/src/generators/library/schema.json index 1a3fc4a809..66fe7918f6 100644 --- a/packages/angular/src/generators/library/schema.json +++ b/packages/angular/src/generators/library/schema.json @@ -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.", diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index afc2782508..74d592a311 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -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); diff --git a/packages/js/src/generators/library/schema.json b/packages/js/src/generators/library/schema.json index f7242d1e7c..5ca5f820e1 100644 --- a/packages/js/src/generators/library/schema.json +++ b/packages/js/src/generators/library/schema.json @@ -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", diff --git a/packages/nest/src/generators/library/library.ts b/packages/nest/src/generators/library/library.ts index 4d2be70f91..4ab7fdec07 100644 --- a/packages/nest/src/generators/library/library.ts +++ b/packages/nest/src/generators/library/library.ts @@ -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 { 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) diff --git a/packages/nest/src/generators/library/schema.json b/packages/nest/src/generators/library/schema.json index 46cd20eb76..5093cf38aa 100644 --- a/packages/nest/src/generators/library/schema.json +++ b/packages/nest/src/generators/library/schema.json @@ -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", diff --git a/packages/react/src/generators/library/library.ts b/packages/react/src/generators/library/library.ts index f0168729b9..191fd52728 100644 --- a/packages/react/src/generators/library/library.ts +++ b/packages/react/src/generators/library/library.ts @@ -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'; } diff --git a/packages/react/src/generators/library/schema.json b/packages/react/src/generators/library/schema.json index 40ff84a432..9eb9076828 100644 --- a/packages/react/src/generators/library/schema.json +++ b/packages/react/src/generators/library/schema.json @@ -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",