Skip to content

fix(@angular/cli): allow users to use additionalProperties in their… #16512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/angular/cli/commands/add-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { colors } from '../utilities/color';
import { getPackageManager } from '../utilities/package-manager';
import {
NgAddSaveDepedency,
PackageIdentifier,
PackageManifest,
fetchPackageManifest,
fetchPackageMetadata,
Expand All @@ -29,7 +28,6 @@ const npa = require('npm-package-arg');

export class AddCommand extends SchematicCommand<AddCommandSchema> {
readonly allowPrivateSchematics = true;
readonly allowAdditionalArgs = true;

async run(options: AddCommandSchema & Arguments) {
if (!options.collection) {
Expand Down
7 changes: 4 additions & 3 deletions packages/angular/cli/models/schematic-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export abstract class SchematicCommand<
T extends BaseSchematicSchema & BaseCommandOptions
> extends Command<T> {
readonly allowPrivateSchematics: boolean = false;
readonly allowAdditionalArgs: boolean = false;
private _host = new NodeJsSyncHost();
private _workspace: workspaces.WorkspaceDefinition;
protected _workflow: NodeWorkflow;
Expand Down Expand Up @@ -466,8 +465,10 @@ export abstract class SchematicCommand<
args = await this.parseArguments(schematicOptions || [], o);
}

// ng-add is special because we don't know all possible options at this point
if (args['--'] && !this.allowAdditionalArgs) {
const allowAdditionalProperties =
typeof schematic.description.schemaJson === 'object' && schematic.description.schemaJson.additionalProperties;

if (args['--'] && !allowAdditionalProperties) {
args['--'].forEach(additional => {
this.logger.fatal(`Unknown option: '${additional.split(/=/)[0]}'`);
});
Expand Down
10 changes: 9 additions & 1 deletion tests/legacy-cli/e2e/tests/commands/add/add-material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ export default async function () {
// forcibly remove in case another test doesn't clean itself up
await rimraf('node_modules/@angular/material');

await ng('add', '@angular/material');
try {
await ng('add', '@angular/material', '--unknown');
} catch (error) {
if (!(error.message && error.message.includes(`Unknown option: '--unknown'`))) {
throw error;
}
}

await ng('add', '@angular/material', '--theme', 'custom', '--verbose');
await expectFileToMatch('package.json', /@angular\/material/);

const output1 = await ng('add', '@angular/material');
Expand Down