Skip to content

Commit e20964c

Browse files
alan-agius4clydin
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 b9a8e91 commit e20964c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/angular/cli/models/schematic-command.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from '@angular-devkit/schematics/tools';
2222
import * as inquirer from 'inquirer';
2323
import * as systemPath from 'path';
24+
import { resolve } from 'path';
2425
import { colors } from '../utilities/color';
2526
import { getProjectByCwd, getSchematicDefaults, getWorkspace } from '../utilities/config';
2627
import { parseJsonSchemaToOptions } from '../utilities/json-schema';
@@ -373,20 +374,26 @@ export abstract class SchematicCommand<
373374
}
374375

375376
protected async getDefaultSchematicCollection(): Promise<string> {
377+
// Resolve relative collections from the location of `angular.json`
378+
const resolveRelativeCollection = (collectionName: string) =>
379+
collectionName.charAt(0) === '.'
380+
? resolve(this.context.root, collectionName)
381+
: collectionName;
382+
376383
let workspace = await getWorkspace('local');
377384

378385
if (workspace) {
379386
const project = getProjectByCwd(workspace);
380387
if (project && workspace.getProjectCli(project)) {
381388
const value = workspace.getProjectCli(project)['defaultCollection'];
382389
if (typeof value == 'string') {
383-
return value;
390+
return resolveRelativeCollection(value);
384391
}
385392
}
386393
if (workspace.getCli()) {
387394
const value = workspace.getCli()['defaultCollection'];
388395
if (typeof value == 'string') {
389-
return value;
396+
return resolveRelativeCollection(value);
390397
}
391398
}
392399
}
@@ -395,7 +402,7 @@ export abstract class SchematicCommand<
395402
if (workspace && workspace.getCli()) {
396403
const value = workspace.getCli()['defaultCollection'];
397404
if (typeof value == 'string') {
398-
return value;
405+
return resolveRelativeCollection(value);
399406
}
400407
}
401408

0 commit comments

Comments
 (0)