Skip to content

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

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 17, 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
NodeWorkflow,
} from '@angular-devkit/schematics/tools';
import type { CheckboxQuestion, Question } from 'inquirer';
import { resolve } from 'path';
import { Argv } from 'yargs';
import { getProjectByCwd, getSchematicDefaults } from '../utilities/config';
import { memoize } from '../utilities/memoize';
Expand Down Expand Up @@ -232,6 +233,12 @@ export abstract class SchematicsCommandModule

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

const getSchematicCollections = (
configSection: Record<string, unknown> | undefined,
): Set<string> | undefined => {
Expand All @@ -241,9 +248,9 @@ export abstract class SchematicsCommandModule

const { schematicCollections, defaultCollection } = configSection;
if (Array.isArray(schematicCollections)) {
return new Set(schematicCollections);
return new Set(schematicCollections.map((c) => resolveRelativeCollection(c)));
} else if (typeof defaultCollection === 'string') {
return new Set([defaultCollection]);
return new Set([resolveRelativeCollection(defaultCollection)]);
}

return undefined;
Expand Down