Skip to content

Commit fe1ae69

Browse files
committedDec 17, 2024·
fix(@angular-devkit/architect): avoid Node.js resolution for relative 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.
1 parent ad1d7d7 commit fe1ae69

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed
 

‎packages/angular_devkit/architect/node/node-modules-architect-host.ts

+8-14
Original file line numberDiff line numberDiff line change
@@ -193,28 +193,22 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
193193
}
194194

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

206206
// The file could be either a package reference or in the local manifest directory.
207-
// Node resolution is tried first then reading the file from the manifest directory if resolution fails.
208-
try {
209-
schemaPath = localRequire.resolve(schemaPath, {
210-
paths: [buildersManifestDirectory],
211-
});
212-
} catch (e) {
213-
if ((e as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
214-
schemaPath = path.join(buildersManifestDirectory, schemaPath);
215-
} else {
216-
throw e;
217-
}
207+
if (schemaPath.startsWith('.')) {
208+
schemaPath = path.join(buildersManifestDirectory, schemaPath);
209+
} else {
210+
const manifestRequire = createRequire(buildersManifestDirectory + '/');
211+
schemaPath = manifestRequire.resolve(schemaPath);
218212
}
219213

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

0 commit comments

Comments
 (0)
Please sign in to comment.