Skip to content

Commit

Permalink
fix(@angular/cli): correctly parse and resolve relative schematic col…
Browse files Browse the repository at this point in the history
…lection names on Windows

Previously, the logic incorrectly extracted the drive letter as the collection name when the schematic collection was specified as relative on Windows. This fix ensures that relative paths are parsed and resolved correctly, preventing the drive letter from being mistakenly treated as the collection name.

Closes #29559

(cherry picked from commit 8c7c7ac)
  • Loading branch information
alan-agius4 committed Feb 13, 2025
1 parent 90cf0f8 commit f76cee6
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
FileSystemSchematicDescription,
NodeWorkflow,
} from '@angular-devkit/schematics/tools';
import { relative, resolve } from 'path';
import { relative } from 'path';
import { Argv } from 'yargs';
import { isPackageNameSafeForAnalytics } from '../analytics/analytics';
import { EventCustomDimension } from '../analytics/analytics-parameters';
Expand Down Expand Up @@ -277,12 +277,6 @@ 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 @@ -292,7 +286,7 @@ export abstract class SchematicsCommandModule

const { schematicCollections } = configSection;
if (Array.isArray(schematicCollections)) {
return new Set(schematicCollections.map((c) => resolveRelativeCollection(c)));
return new Set(schematicCollections);
}

return undefined;
Expand Down Expand Up @@ -399,6 +393,10 @@ export abstract class SchematicsCommandModule

private getResolvePaths(collectionName: string): string[] {
const { workspace, root } = this.context;
if (collectionName[0] === '.') {
// Resolve relative collections from the location of `angular.json`
return [root];
}

return workspace
? // Workspace
Expand Down

0 comments on commit f76cee6

Please # to comment.