Skip to content

Commit

Permalink
fix(@angular-devkit/architect): avoid Node.js resolution for relative…
Browse files Browse the repository at this point in the history
… builder schema

To avoid the need to perform Node.js resolution for the typical case of a relative
builder schema, a check is now performed to determine if a schema path within the
build manifest appears to be relative.
  • Loading branch information
clydin committed Dec 17, 2024
1 parent ad1d7d7 commit fe1ae69
Showing 1 changed file with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,28 +193,22 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
}

// Determine builder option schema path (relative within package only)
let schemaPath = builder.schema && path.normalize(builder.schema);
let schemaPath = builder.schema;
if (!schemaPath) {
throw new Error('Could not find the schema for builder ' + builderStr);
}
if (path.isAbsolute(schemaPath) || schemaPath.startsWith('..')) {
if (path.isAbsolute(schemaPath) || path.normalize(schemaPath).startsWith('..')) {
throw new Error(
`Package "${packageName}" has an invalid builder implementation path: "${builderName}" --> "${builder.schema}"`,
`Package "${packageName}" has an invalid builder schema path: "${builderName}" --> "${builder.schema}"`,
);
}

// The file could be either a package reference or in the local manifest directory.
// Node resolution is tried first then reading the file from the manifest directory if resolution fails.
try {
schemaPath = localRequire.resolve(schemaPath, {
paths: [buildersManifestDirectory],
});
} catch (e) {
if ((e as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
schemaPath = path.join(buildersManifestDirectory, schemaPath);
} else {
throw e;
}
if (schemaPath.startsWith('.')) {
schemaPath = path.join(buildersManifestDirectory, schemaPath);
} else {
const manifestRequire = createRequire(buildersManifestDirectory + '/');
schemaPath = manifestRequire.resolve(schemaPath);
}

const schemaText = readFileSync(schemaPath, 'utf-8');
Expand Down

0 comments on commit fe1ae69

Please sign in to comment.