Skip to content

Commit 9a5251c

Browse files
clydindgp1130
authored andcommitted
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.
1 parent 78b3537 commit 9a5251c

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

goldens/public-api/angular_devkit/schematics/tools/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export type FileSystemCollectionDesc = CollectionDescription<FileSystemCollectio
5959

6060
// @public (undocumented)
6161
export interface FileSystemCollectionDescription {
62+
// (undocumented)
63+
readonly encapsulation?: boolean;
6264
// (undocumented)
6365
readonly name: string;
6466
// (undocumented)
@@ -121,7 +123,7 @@ export abstract class FileSystemEngineHostBase implements FileSystemEngineHost_2
121123
// (undocumented)
122124
protected abstract _resolveCollectionPath(name: string, requester?: string): string;
123125
// (undocumented)
124-
protected abstract _resolveReferenceString(name: string, parentPath: string): {
126+
protected abstract _resolveReferenceString(name: string, parentPath: string, collectionDescription: FileSystemCollectionDesc): {
125127
ref: RuleFactory<{}>;
126128
path: string;
127129
} | null;
@@ -183,7 +185,7 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
183185
// (undocumented)
184186
protected _resolveCollectionPath(name: string, requester?: string): string;
185187
// (undocumented)
186-
protected _resolveReferenceString(refString: string, parentPath: string): {
188+
protected _resolveReferenceString(refString: string, parentPath: string, collectionDescription?: FileSystemCollectionDesc): {
187189
ref: RuleFactory<{}>;
188190
path: string;
189191
} | null;

packages/angular_devkit/schematics/tools/description.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface FileSystemCollectionDescription {
2323
readonly path: string;
2424
readonly version?: string;
2525
readonly schematics: { [name: string]: FileSystemSchematicDesc };
26+
readonly encapsulation?: boolean;
2627
}
2728

2829
export interface FileSystemSchematicJsonDescription {
@@ -63,7 +64,8 @@ export declare type FileSystemSchematic = Schematic<
6364
FileSystemCollectionDescription,
6465
FileSystemSchematicDescription
6566
>;
66-
export declare type FileSystemCollectionDesc = CollectionDescription<FileSystemCollectionDescription>;
67+
export declare type FileSystemCollectionDesc =
68+
CollectionDescription<FileSystemCollectionDescription>;
6769
export declare type FileSystemSchematicDesc = SchematicDescription<
6870
FileSystemCollectionDescription,
6971
FileSystemSchematicDescription

packages/angular_devkit/schematics/tools/file-system-engine-host-base.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export abstract class FileSystemEngineHostBase implements FileSystemEngineHost {
102102
protected abstract _resolveReferenceString(
103103
name: string,
104104
parentPath: string,
105+
collectionDescription: FileSystemCollectionDesc,
105106
): { ref: RuleFactory<{}>; path: string } | null;
106107
protected abstract _transformCollectionDescription(
107108
name: string,
@@ -234,7 +235,11 @@ export abstract class FileSystemEngineHostBase implements FileSystemEngineHost {
234235
if (!partialDesc.factory) {
235236
throw new SchematicMissingFactoryException(name);
236237
}
237-
const resolvedRef = this._resolveReferenceString(partialDesc.factory, collectionPath);
238+
const resolvedRef = this._resolveReferenceString(
239+
partialDesc.factory,
240+
collectionPath,
241+
collection,
242+
);
238243
if (!resolvedRef) {
239244
throw new FactoryCannotBeResolvedException(name);
240245
}

packages/angular_devkit/schematics/tools/node-module-engine-host.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ export class NodeModulesEngineHost extends FileSystemEngineHostBase {
9898
return collectionPath;
9999
}
100100

101-
protected _resolveReferenceString(refString: string, parentPath: string) {
101+
protected _resolveReferenceString(
102+
refString: string,
103+
parentPath: string,
104+
collectionDescription?: FileSystemCollectionDesc,
105+
) {
102106
const ref = new ExportStringRef<RuleFactory<{}>>(refString, parentPath);
103107
if (!ref.ref) {
104108
return null;

0 commit comments

Comments
 (0)