Skip to content

Commit

Permalink
fix(@angular/cli): resolve relative schematic from angular.json ins…
Browse files Browse the repository at this point in the history
…tead of current working directory

Relative schematics referenced in `angular.json` `schematicCollections` and `defaultCollection` were always resolved from the current working directory, which is not correct and caused the collection not to be resolved when the this is different from the location of the workspace config.

Closes #23136

(cherry picked from commit c71832f)
  • Loading branch information
alan-agius4 authored and dgp1130 committed May 17, 2022
1 parent bdf2b9b commit db0cb55
Showing 1 changed file with 9 additions and 2 deletions.
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

0 comments on commit db0cb55

Please sign in to comment.