Skip to content

[patch] fix(@angular/cli): resolve relative schematic from angular.json instead of current working directory #23167

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
May 18, 2022
Merged
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
13 changes: 10 additions & 3 deletions packages/angular/cli/models/schematic-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '@angular-devkit/schematics/tools';
import * as inquirer from 'inquirer';
import * as systemPath from 'path';
import { resolve } from 'path';
import { colors } from '../utilities/color';
import { getProjectByCwd, getSchematicDefaults, getWorkspace } from '../utilities/config';
import { parseJsonSchemaToOptions } from '../utilities/json-schema';
Expand Down Expand Up @@ -373,20 +374,26 @@ export abstract class SchematicCommand<
}

protected async getDefaultSchematicCollection(): Promise<string> {
// Resolve relative collections from the location of `angular.json`
const resolveRelativeCollection = (collectionName: string) =>
collectionName.charAt(0) === '.'
? resolve(this.context.root, collectionName)
: collectionName;

let workspace = await getWorkspace('local');

if (workspace) {
const project = getProjectByCwd(workspace);
if (project && workspace.getProjectCli(project)) {
const value = workspace.getProjectCli(project)['defaultCollection'];
if (typeof value == 'string') {
return value;
return resolveRelativeCollection(value);
}
}
if (workspace.getCli()) {
const value = workspace.getCli()['defaultCollection'];
if (typeof value == 'string') {
return value;
return resolveRelativeCollection(value);
}
}
}
Expand All @@ -395,7 +402,7 @@ export abstract class SchematicCommand<
if (workspace && workspace.getCli()) {
const value = workspace.getCli()['defaultCollection'];
if (typeof value == 'string') {
return value;
return resolveRelativeCollection(value);
}
}

Expand Down