Skip to content

Commit 0248f1d

Browse files
alan-agius4vikerman
authored andcommitted
fix(@angular/cli): inform user and error if schematics package is in unreachable location (#16466)
This is a workaround for the schematics runtime to support the requirement of packages containing migrations (or other schematics) to not have a direct/runtime dependency on the schematics package. Closes: #16392
1 parent 2162fe2 commit 0248f1d

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

packages/angular/cli/commands/add-impl.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { colors } from '../utilities/color';
1818
import { getPackageManager } from '../utilities/package-manager';
1919
import {
2020
NgAddSaveDepedency,
21-
PackageIdentifier,
2221
PackageManifest,
2322
fetchPackageManifest,
2423
fetchPackageMetadata,
@@ -29,7 +28,6 @@ const npa = require('npm-package-arg');
2928

3029
export class AddCommand extends SchematicCommand<AddCommandSchema> {
3130
readonly allowPrivateSchematics = true;
32-
readonly allowAdditionalArgs = true;
3331

3432
async run(options: AddCommandSchema & Arguments) {
3533
if (!options.collection) {

packages/angular/cli/models/schematic-command.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export abstract class SchematicCommand<
7373
T extends BaseSchematicSchema & BaseCommandOptions
7474
> extends Command<T> {
7575
readonly allowPrivateSchematics: boolean = false;
76-
readonly allowAdditionalArgs: boolean = false;
7776
private _host = new NodeJsSyncHost();
7877
private _workspace: workspaces.WorkspaceDefinition;
7978
protected _workflow: NodeWorkflow;
@@ -466,8 +465,10 @@ export abstract class SchematicCommand<
466465
args = await this.parseArguments(schematicOptions || [], o);
467466
}
468467

469-
// ng-add is special because we don't know all possible options at this point
470-
if (args['--'] && !this.allowAdditionalArgs) {
468+
const allowAdditionalProperties =
469+
typeof schematic.description.schemaJson === 'object' && schematic.description.schemaJson.additionalProperties;
470+
471+
if (args['--'] && !allowAdditionalProperties) {
471472
args['--'].forEach(additional => {
472473
this.logger.fatal(`Unknown option: '${additional.split(/=/)[0]}'`);
473474
});

tests/legacy-cli/e2e/tests/commands/add/add-material.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ export default async function () {
66
// forcibly remove in case another test doesn't clean itself up
77
await rimraf('node_modules/@angular/material');
88

9-
await ng('add', '@angular/material');
9+
try {
10+
await ng('add', '@angular/material', '--unknown');
11+
} catch (error) {
12+
if (!(error.message && error.message.includes(`Unknown option: '--unknown'`))) {
13+
throw error;
14+
}
15+
}
16+
17+
await ng('add', '@angular/material', '--theme', 'custom', '--verbose');
1018
await expectFileToMatch('package.json', /@angular\/material/);
1119

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

0 commit comments

Comments
 (0)