From 31a75ce224a1e4c8b37372e7adcf00ae5fb6ef49 Mon Sep 17 00:00:00 2001 From: Jonathan Cammisuli Date: Tue, 2 Aug 2022 13:05:00 -0400 Subject: [PATCH] fix: handle hyphenation when looking for generator defaults Fixes #1313 --- libs/schema/src/index.ts | 1 + libs/server/src/lib/utils/utils.ts | 4 +++- libs/vscode/tasks/src/lib/select-generator.ts | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/schema/src/index.ts b/libs/schema/src/index.ts index 36e461fa24..97c6e6fce7 100644 --- a/libs/schema/src/index.ts +++ b/libs/schema/src/index.ts @@ -13,6 +13,7 @@ export type OptionPropertyDescription = Schema['properties'][number]; export type CliOption = { name: string; + originalName?: string; positional?: number; alias?: string; hidden?: boolean; diff --git a/libs/server/src/lib/utils/utils.ts b/libs/server/src/lib/utils/utils.ts index a0a32df409..46f25a9850 100644 --- a/libs/server/src/lib/utils/utils.ts +++ b/libs/server/src/lib/utils/utils.ts @@ -186,7 +186,8 @@ export async function normalizeSchema( const nxOptions = options.map((option) => { const xPrompt: XPrompt | undefined = option['x-prompt']; - const workspaceDefault = projectDefaults && projectDefaults[option.name]; + const workspaceDefault = + projectDefaults?.[option.originalName ?? option.name]; const $default = option.$default; const nxOption: Option = { @@ -346,6 +347,7 @@ function schemaToOptions( const name = config?.hyphenate ? names(option).fileName : option; cliOptions.push({ name, + originalName: option, positional, ...currentProperty, }); diff --git a/libs/vscode/tasks/src/lib/select-generator.ts b/libs/vscode/tasks/src/lib/select-generator.ts index df18149c65..5887d1cd68 100644 --- a/libs/vscode/tasks/src/lib/select-generator.ts +++ b/libs/vscode/tasks/src/lib/select-generator.ts @@ -13,7 +13,7 @@ import { GlobalConfigurationStore } from '@nx-console/vscode/configuration'; import { nxWorkspace } from '@nx-console/vscode/nx-workspace'; import { QuickPickItem, window } from 'vscode'; -async function readWorkspaceJsonDefaults(workspacePath: string): Promise { +async function readWorkspaceJsonDefaults(): Promise { const { workspace } = await nxWorkspace(); let defaults = workspace.generators; @@ -65,7 +65,7 @@ export async function getGeneratorOptions( workspaceType: 'ng' | 'nx' ): Promise { const generatorSchema = await readAndCacheJsonFile(generatorPath); - const workspaceDefaults = await readWorkspaceJsonDefaults(workspacePath); + const workspaceDefaults = await readWorkspaceJsonDefaults(); const defaults = workspaceDefaults && workspaceDefaults[collectionName] &&