mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-23 07:19:58 +08:00
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.
This commit is contained in:
parent
ad1d7d76fc
commit
fe1ae69339
@ -193,28 +193,22 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Determine builder option schema path (relative within package only)
|
// Determine builder option schema path (relative within package only)
|
||||||
let schemaPath = builder.schema && path.normalize(builder.schema);
|
let schemaPath = builder.schema;
|
||||||
if (!schemaPath) {
|
if (!schemaPath) {
|
||||||
throw new Error('Could not find the schema for builder ' + builderStr);
|
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(
|
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.
|
// 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.
|
if (schemaPath.startsWith('.')) {
|
||||||
try {
|
|
||||||
schemaPath = localRequire.resolve(schemaPath, {
|
|
||||||
paths: [buildersManifestDirectory],
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
if ((e as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
|
|
||||||
schemaPath = path.join(buildersManifestDirectory, schemaPath);
|
schemaPath = path.join(buildersManifestDirectory, schemaPath);
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
const manifestRequire = createRequire(buildersManifestDirectory + '/');
|
||||||
}
|
schemaPath = manifestRequire.resolve(schemaPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
const schemaText = readFileSync(schemaPath, 'utf-8');
|
const schemaText = readFileSync(schemaPath, 'utf-8');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user