diff --git a/packages/angular/cli/models/schematic-command.ts b/packages/angular/cli/models/schematic-command.ts index a6be6add5788..af20499397d1 100644 --- a/packages/angular/cli/models/schematic-command.ts +++ b/packages/angular/cli/models/schematic-command.ts @@ -242,14 +242,17 @@ export abstract class SchematicCommand< schemaValidation: true, optionTransforms: [ // Add configuration file defaults - async (schematic, current) => ({ - ...(await getSchematicDefaults( - schematic.collection.name, - schematic.name, - getProjectName(), - )), - ...current, - }), + async (schematic, current) => { + const projectName = + typeof (current as Record).project === 'string' + ? ((current as Record).project as string) + : getProjectName(); + + return { + ...(await getSchematicDefaults(schematic.collection.name, schematic.name, projectName)), + ...current, + }; + }, ], engineHostCreator: (options) => new SchematicEngineHost(options.resolvePaths), }); @@ -446,14 +449,9 @@ export abstract class SchematicCommand< } const pathOptions = o ? this.setPathOptions(o, workingDir) : {}; - let input = { ...pathOptions, ...args }; - - // Read the default values from the workspace. - const projectName = input.project !== undefined ? '' + input.project : null; - const defaults = await getSchematicDefaults(collectionName, schematicName, projectName); - input = { - ...defaults, - ...input, + const input = { + ...pathOptions, + ...args, ...options.additionalOptions, }; diff --git a/packages/schematics/angular/app-shell/index_spec.ts b/packages/schematics/angular/app-shell/index_spec.ts index fb34c97523db..f18882ebdde7 100644 --- a/packages/schematics/angular/app-shell/index_spec.ts +++ b/packages/schematics/angular/app-shell/index_spec.ts @@ -17,7 +17,7 @@ describe('App Shell Schematic', () => { require.resolve('../collection.json'), ); const defaultOptions: AppShellOptions = { - clientProject: 'bar', + project: 'bar', }; const workspaceOptions: WorkspaceOptions = { diff --git a/tests/legacy-cli/e2e/tests/generate/schematic-defaults.ts b/tests/legacy-cli/e2e/tests/generate/schematic-defaults.ts new file mode 100644 index 000000000000..b4126339c3d1 --- /dev/null +++ b/tests/legacy-cli/e2e/tests/generate/schematic-defaults.ts @@ -0,0 +1,42 @@ +import { ng } from '../../utils/process'; +import { updateJsonFile } from '../../utils/project'; + +export default async function () { + await updateJsonFile('angular.json', (config) => { + config.projects['test-project'].schematics = { + '@schematics/angular:component': { + style: 'scss', + }, + }; + }); + + // Generate component in application to verify that it's minimal + const { stdout } = await ng('generate', 'component', 'foo'); + if (!stdout.includes('foo.component.scss')) { + console.log(stdout); + throw new Error('Expected "foo.component.scss" to exist.'); + } + + // Generate another project with different settings + await ng('generate', 'application', 'test-project-two', '--no-minimal'); + + await updateJsonFile('angular.json', (config) => { + config.projects['test-project-two'].schematics = { + '@schematics/angular:component': { + style: 'less', + }, + }; + }); + + const { stdout: stdout2 } = await ng( + 'generate', + 'component', + 'foo', + '--project', + 'test-project-two', + ); + if (!stdout2.includes('foo.component.less')) { + console.log(stdout2); + throw new Error('Expected "foo.component.less" to exist.'); + } +}