diff --git a/docs/generated/manifests/menus.json b/docs/generated/manifests/menus.json index a6706327bb9084..34f0298b52202e 100644 --- a/docs/generated/manifests/menus.json +++ b/docs/generated/manifests/menus.json @@ -10241,9 +10241,9 @@ "disableCollapsible": false }, { - "id": "convert-to-inferred", - "path": "/nx-api/workspace/generators/convert-to-inferred", - "name": "convert-to-inferred", + "id": "infer-targets", + "path": "/nx-api/workspace/generators/infer-targets", + "name": "infer-targets", "children": [], "isExternal": false, "disableCollapsible": false diff --git a/docs/generated/manifests/nx-api.json b/docs/generated/manifests/nx-api.json index b58f5780ff55ff..0a6a39e9697c8b 100644 --- a/docs/generated/manifests/nx-api.json +++ b/docs/generated/manifests/nx-api.json @@ -3424,13 +3424,13 @@ "path": "/nx-api/workspace/generators/ci-workflow", "type": "generator" }, - "/nx-api/workspace/generators/convert-to-inferred": { - "description": "convert-to-inferred generator", - "file": "generated/packages/workspace/generators/convert-to-inferred.json", + "/nx-api/workspace/generators/infer-targets": { + "description": "Convert Nx projects to use inferred targets.", + "file": "generated/packages/workspace/generators/infer-targets.json", "hidden": false, - "name": "convert-to-inferred", - "originalFilePath": "/packages/workspace/src/generators/convert-to-inferred/schema.json", - "path": "/nx-api/workspace/generators/convert-to-inferred", + "name": "infer-targets", + "originalFilePath": "/packages/workspace/src/generators/infer-targets/schema.json", + "path": "/nx-api/workspace/generators/infer-targets", "type": "generator" } }, diff --git a/docs/generated/packages-metadata.json b/docs/generated/packages-metadata.json index 8c05550a9644a7..d467ec0eeaec60 100644 --- a/docs/generated/packages-metadata.json +++ b/docs/generated/packages-metadata.json @@ -3389,12 +3389,12 @@ "type": "generator" }, { - "description": "convert-to-inferred generator", - "file": "generated/packages/workspace/generators/convert-to-inferred.json", + "description": "Convert Nx projects to use inferred targets.", + "file": "generated/packages/workspace/generators/infer-targets.json", "hidden": false, - "name": "convert-to-inferred", - "originalFilePath": "/packages/workspace/src/generators/convert-to-inferred/schema.json", - "path": "workspace/generators/convert-to-inferred", + "name": "infer-targets", + "originalFilePath": "/packages/workspace/src/generators/infer-targets/schema.json", + "path": "workspace/generators/infer-targets", "type": "generator" } ], diff --git a/docs/generated/packages/workspace/generators/convert-to-inferred.json b/docs/generated/packages/workspace/generators/infer-targets.json similarity index 54% rename from docs/generated/packages/workspace/generators/convert-to-inferred.json rename to docs/generated/packages/workspace/generators/infer-targets.json index 8503b88914b15f..be3c388c33f2fb 100644 --- a/docs/generated/packages/workspace/generators/convert-to-inferred.json +++ b/docs/generated/packages/workspace/generators/infer-targets.json @@ -1,9 +1,9 @@ { - "name": "convert-to-inferred", - "factory": "./src/generators/convert-to-inferred/generator", + "name": "infer-targets", + "factory": "./src/generators/infer-targets/infer-targets", "schema": { "$schema": "https://json-schema.org/schema", - "$id": "ConvertToInferred", + "$id": "InferTargets", "title": "", "type": "object", "properties": { @@ -12,9 +12,9 @@ "description": "The project to convert to use inferred targets.", "x-priority": "important" }, - "exclude": { + "plugins": { "type": "array", - "description": "List of plugins whose convert-to-inferred generators should not be run.", + "description": "Which plugins' convert-to-inferred generators to look for. For example @nx/eslint or @nx/jest", "items": { "type": "string" } }, "skipFormat": { @@ -25,10 +25,10 @@ }, "presets": [] }, - "description": "convert-to-inferred generator", - "implementation": "/packages/workspace/src/generators/convert-to-inferred/generator.ts", + "description": "Convert Nx projects to use inferred targets.", + "implementation": "/packages/workspace/src/generators/infer-targets/infer-targets.ts", "aliases": [], "hidden": false, - "path": "/packages/workspace/src/generators/convert-to-inferred/schema.json", + "path": "/packages/workspace/src/generators/infer-targets/schema.json", "type": "generator" } diff --git a/docs/shared/reference/sitemap.md b/docs/shared/reference/sitemap.md index 587f8dc97523fb..70fc443a486599 100644 --- a/docs/shared/reference/sitemap.md +++ b/docs/shared/reference/sitemap.md @@ -743,4 +743,4 @@ - [fix-configuration](/nx-api/workspace/generators/fix-configuration) - [npm-package](/nx-api/workspace/generators/npm-package) - [ci-workflow](/nx-api/workspace/generators/ci-workflow) - - [convert-to-inferred](/nx-api/workspace/generators/convert-to-inferred) + - [infer-targets](/nx-api/workspace/generators/infer-targets) diff --git a/packages/devkit/src/generators/project-name-and-root-utils.ts b/packages/devkit/src/generators/project-name-and-root-utils.ts index 548dff421504a7..48538953475e01 100644 --- a/packages/devkit/src/generators/project-name-and-root-utils.ts +++ b/packages/devkit/src/generators/project-name-and-root-utils.ts @@ -156,7 +156,7 @@ async function determineFormat( } const result = await prompt<{ format: ProjectNameAndRootFormat }>({ - type: 'array', + type: 'select', name: 'format', message: 'What should be the project name and where should it be generated?', @@ -171,7 +171,7 @@ async function determineFormat( }, ], initial: 0, - } as any).then(({ format }) => + }).then(({ format }) => format === asProvidedSelectedValue ? 'as-provided' : 'derived' ); diff --git a/packages/workspace/generators.json b/packages/workspace/generators.json index dfd129e3fe49a7..8ef6a398dbe3e1 100644 --- a/packages/workspace/generators.json +++ b/packages/workspace/generators.json @@ -55,10 +55,10 @@ "schema": "./src/generators/ci-workflow/schema.json", "description": "Generate a CI workflow." }, - "convert-many-to-inferred": { - "factory": "./src/generators/convert-many-to-inferred/convert-many-to-inferred", - "schema": "./src/generators/convert-many-to-inferred/schema.json", - "description": "convert-to-inferred generator" + "infer-targets": { + "factory": "./src/generators/infer-targets/infer-targets", + "schema": "./src/generators/infer-targets/schema.json", + "description": "Convert Nx projects to use inferred targets." } } } diff --git a/packages/workspace/src/generators/convert-many-to-inferred/convert-many-to-inferred.spec.ts b/packages/workspace/src/generators/infer-targets/infer-targets.spec.ts similarity index 100% rename from packages/workspace/src/generators/convert-many-to-inferred/convert-many-to-inferred.spec.ts rename to packages/workspace/src/generators/infer-targets/infer-targets.spec.ts diff --git a/packages/workspace/src/generators/convert-many-to-inferred/convert-many-to-inferred.ts b/packages/workspace/src/generators/infer-targets/infer-targets.ts similarity index 71% rename from packages/workspace/src/generators/convert-many-to-inferred/convert-many-to-inferred.ts rename to packages/workspace/src/generators/infer-targets/infer-targets.ts index d3cfe1280beead..62718af79205af 100644 --- a/packages/workspace/src/generators/convert-many-to-inferred/convert-many-to-inferred.ts +++ b/packages/workspace/src/generators/infer-targets/infer-targets.ts @@ -21,22 +21,20 @@ interface Schema { } export async function convertToInferredGenerator(tree: Tree, options: Schema) { - const generatorChoices = await getPossibleConvertToInferredGenerators(); + const generatorCollectionChoices = + await getPossibleConvertToInferredGenerators(); let generatorsToRun: string[]; - if (process.argv.includes('--no-interactive')) { - generatorsToRun = Array.from(generatorChoices.keys()); - } else if (options.plugins && options.plugins.length > 0) { - generatorsToRun = Array.from(generatorChoices.values()) + if (options.plugins && options.plugins.filter((p) => !!p).length > 0) { + generatorsToRun = Array.from(generatorCollectionChoices.values()) .filter((generator) => options.plugins.includes(generator.resolvedCollectionName) ) - .map( - (generator) => - `${generator.resolvedCollectionName}:${generator.normalizedGeneratorName}` - ); + .map((generator) => generator.resolvedCollectionName); + } else if (process.argv.includes('--no-interactive')) { + generatorsToRun = Array.from(generatorCollectionChoices.keys()); } else { - const allChoices = Array.from(generatorChoices.keys()); + const allChoices = Array.from(generatorCollectionChoices.keys()); generatorsToRun = ( await prompt<{ generatorsToRun: string[] }>({ @@ -47,7 +45,7 @@ export async function convertToInferredGenerator(tree: Tree, options: Schema) { initial: allChoices, validate: (result: string[]) => { if (result.length === 0) { - return 'Please select at least one convert-to-inferred generator to run'; + return 'Please select at least one plugin.'; } return true; }, @@ -57,14 +55,14 @@ export async function convertToInferredGenerator(tree: Tree, options: Schema) { if (generatorsToRun.length === 0) { output.error({ - title: 'Please select at least one convert-to-inferred generator to run', + title: 'Please select at least one plugin.', }); return; } - for (const generatorName of generatorsToRun) { + for (const generatorCollection of generatorsToRun) { try { - const generator = generatorChoices.get(generatorName); + const generator = generatorCollectionChoices.get(generatorCollection); if (generator) { const generatorFactory = generator.implementationFactory(); const callback = await generatorFactory(tree, { @@ -75,17 +73,17 @@ export async function convertToInferredGenerator(tree: Tree, options: Schema) { await callback(); } output.success({ - title: `${generatorName} - Success`, + title: `${generatorCollection}:convert-to-inferred - Success`, }); } } catch (e) { if (e instanceof NoTargetsToMigrateError) { output.note({ - title: `${generatorName} - Skipped (No targets to migrate)`, + title: `${generatorCollection}:convert-to-inferred - Skipped (No targets to migrate)`, }); } else { output.error({ - title: `${generatorName} - Failed`, + title: `${generatorCollection}:convert-to-inferred - Failed`, }); throw e; } @@ -122,11 +120,8 @@ async function getPossibleConvertToInferredGenerators() { ) { continue; } - const generatorName = `${generator.resolvedCollectionName}:${generator.normalizedGeneratorName}`; - if (generatorName === '@nx/workspace:convert-to-inferred') { - continue; - } - choices.set(generatorName, generator); + + choices.set(generator.resolvedCollectionName, generator); } catch { // this just means that no convert-to-inferred generator exists for a given collection, ignore } diff --git a/packages/workspace/src/generators/convert-many-to-inferred/schema.json b/packages/workspace/src/generators/infer-targets/schema.json similarity index 94% rename from packages/workspace/src/generators/convert-many-to-inferred/schema.json rename to packages/workspace/src/generators/infer-targets/schema.json index c2b7b5ae3c98d7..6006dc41347433 100644 --- a/packages/workspace/src/generators/convert-many-to-inferred/schema.json +++ b/packages/workspace/src/generators/infer-targets/schema.json @@ -1,6 +1,6 @@ { "$schema": "https://json-schema.org/schema", - "$id": "ConvertManyToInferred", + "$id": "InferTargets", "title": "", "type": "object", "properties": {