Skip to content

Commit c71832f

Browse files
alan-agius4dgp1130
authored andcommitted
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
1 parent f00da00 commit c71832f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/angular/cli/src/command-builder/schematics-command-module.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
NodeWorkflow,
1515
} from '@angular-devkit/schematics/tools';
1616
import type { CheckboxQuestion, Question } from 'inquirer';
17+
import { resolve } from 'path';
1718
import { Argv } from 'yargs';
1819
import { getProjectByCwd, getSchematicDefaults } from '../utilities/config';
1920
import { memoize } from '../utilities/memoize';
@@ -232,6 +233,12 @@ export abstract class SchematicsCommandModule
232233

233234
@memoize
234235
protected async getSchematicCollections(): Promise<Set<string>> {
236+
// Resolve relative collections from the location of `angular.json`
237+
const resolveRelativeCollection = (collectionName: string) =>
238+
collectionName.charAt(0) === '.'
239+
? resolve(this.context.root, collectionName)
240+
: collectionName;
241+
235242
const getSchematicCollections = (
236243
configSection: Record<string, unknown> | undefined,
237244
): Set<string> | undefined => {
@@ -241,9 +248,9 @@ export abstract class SchematicsCommandModule
241248

242249
const { schematicCollections, defaultCollection } = configSection;
243250
if (Array.isArray(schematicCollections)) {
244-
return new Set(schematicCollections);
251+
return new Set(schematicCollections.map((c) => resolveRelativeCollection(c)));
245252
} else if (typeof defaultCollection === 'string') {
246-
return new Set([defaultCollection]);
253+
return new Set([resolveRelativeCollection(defaultCollection)]);
247254
}
248255

249256
return undefined;

0 commit comments

Comments
 (0)