Skip to content

Commit

Permalink
fix(@angular-devkit/architect): resolve builder aliases from containi…
Browse files Browse the repository at this point in the history
…ng package

When resolving a builder alias, the base path for the resolution will now
use the containing package. This prevents potential resolution failure due
to varying package manager installation strategies.
  • Loading branch information
clydin committed May 2, 2024
1 parent 41ee8ea commit 57d57b4
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
* @param builderStr The name of the builder to be used.
* @returns All the info needed for the builder itself.
*/
resolveBuilder(builderStr: string, seenBuilders?: Set<string>): Promise<NodeModulesBuilderInfo> {
resolveBuilder(
builderStr: string,
basePath = this._root,
seenBuilders?: Set<string>,
): Promise<NodeModulesBuilderInfo> {
if (seenBuilders?.has(builderStr)) {
throw new Error(
'Circular builder alias references detected: ' + [...seenBuilders, builderStr],
Expand All @@ -140,7 +144,7 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu

// Resolve and load the builders manifest from the package's `builders` field, if present
const packageJsonPath = localRequire.resolve(packageName + '/package.json', {
paths: [this._root],
paths: [basePath],
});

const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as { builders?: string };
Expand Down Expand Up @@ -170,7 +174,11 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu

// Resolve alias reference if entry is a string
if (typeof builder === 'string') {
return this.resolveBuilder(builder, (seenBuilders ?? new Set()).add(builderStr));
return this.resolveBuilder(
builder,
path.dirname(packageJsonPath),
(seenBuilders ?? new Set()).add(builderStr),
);
}

// Determine builder implementation path (relative within package only)
Expand Down

0 comments on commit 57d57b4

Please sign in to comment.