refactor(@angular-devkit/schematics): provide schematic collection description to FileSystemEngineHost resolver

The `_resolveReferenceString` abstract method of the `FileSystemEngineHostBase` class now has a third parameter
that provides the collection description of the schematic currently being resolved. This allows the resolver to
use any fields/options present within the collection description to adjust the resolution of the schematic. The
`encapsulation` optional field is also added to the `FileSystemCollectionDescription` type which will in the future
allow control of the `@angular/cli` VM context wrapping on an individual schematic collection basis.
This commit is contained in:
Charles Lyding 2022-04-07 10:19:36 -04:00 committed by Douglas Parker
parent 78b3537731
commit 9a5251cff9
4 changed files with 18 additions and 5 deletions

View File

@ -59,6 +59,8 @@ export type FileSystemCollectionDesc = CollectionDescription<FileSystemCollectio
// @public (undocumented)
export interface FileSystemCollectionDescription {
// (undocumented)
readonly encapsulation?: boolean;
// (undocumented)
readonly name: string;
// (undocumented)
@ -121,7 +123,7 @@ export abstract class FileSystemEngineHostBase implements FileSystemEngineHost_2
// (undocumented)
protected abstract _resolveCollectionPath(name: string, requester?: string): string;
// (undocumented)
protected abstract _resolveReferenceString(name: string, parentPath: string): {
protected abstract _resolveReferenceString(name: string, parentPath: string, collectionDescription: FileSystemCollectionDesc): {
ref: RuleFactory<{}>;
path: string;
} | null;
@ -183,7 +185,7 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
// (undocumented)
protected _resolveCollectionPath(name: string, requester?: string): string;
// (undocumented)
protected _resolveReferenceString(refString: string, parentPath: string): {
protected _resolveReferenceString(refString: string, parentPath: string, collectionDescription?: FileSystemCollectionDesc): {
ref: RuleFactory<{}>;
path: string;
} | null;

View File

@ -23,6 +23,7 @@ export interface FileSystemCollectionDescription {
readonly path: string;
readonly version?: string;
readonly schematics: { [name: string]: FileSystemSchematicDesc };
readonly encapsulation?: boolean;
}
export interface FileSystemSchematicJsonDescription {
@ -63,7 +64,8 @@ export declare type FileSystemSchematic = Schematic<
FileSystemCollectionDescription,
FileSystemSchematicDescription
>;
export declare type FileSystemCollectionDesc = CollectionDescription<FileSystemCollectionDescription>;
export declare type FileSystemCollectionDesc =
CollectionDescription<FileSystemCollectionDescription>;
export declare type FileSystemSchematicDesc = SchematicDescription<
FileSystemCollectionDescription,
FileSystemSchematicDescription

View File

@ -102,6 +102,7 @@ export abstract class FileSystemEngineHostBase implements FileSystemEngineHost {
protected abstract _resolveReferenceString(
name: string,
parentPath: string,
collectionDescription: FileSystemCollectionDesc,
): { ref: RuleFactory<{}>; path: string } | null;
protected abstract _transformCollectionDescription(
name: string,
@ -234,7 +235,11 @@ export abstract class FileSystemEngineHostBase implements FileSystemEngineHost {
if (!partialDesc.factory) {
throw new SchematicMissingFactoryException(name);
}
const resolvedRef = this._resolveReferenceString(partialDesc.factory, collectionPath);
const resolvedRef = this._resolveReferenceString(
partialDesc.factory,
collectionPath,
collection,
);
if (!resolvedRef) {
throw new FactoryCannotBeResolvedException(name);
}

View File

@ -98,7 +98,11 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
return collectionPath;
}
protected _resolveReferenceString(refString: string, parentPath: string) {
protected _resolveReferenceString(
refString: string,
parentPath: string,
collectionDescription?: FileSystemCollectionDesc,
) {
const ref = new ExportStringRef<RuleFactory<{}>>(refString, parentPath);
if (!ref.ref) {
return null;