From 1155e50fb981750f16cb35a1e52ae64a95f831e3 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 16 May 2022 08:28:02 +0000 Subject: [PATCH] fix(@angular/cli): resolve relative schematic from `angular.json` instead 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 --- .../src/command-builder/schematics-command-module.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/angular/cli/src/command-builder/schematics-command-module.ts b/packages/angular/cli/src/command-builder/schematics-command-module.ts index acd79a35c737..902ead807329 100644 --- a/packages/angular/cli/src/command-builder/schematics-command-module.ts +++ b/packages/angular/cli/src/command-builder/schematics-command-module.ts @@ -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'; @@ -232,6 +233,12 @@ export abstract class SchematicsCommandModule @memoize protected async getSchematicCollections(): Promise> { + // 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 | undefined, ): Set | undefined => { @@ -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;