Skip to content

Commit 165abc8

Browse files
clydinfilipesilva
authored andcommitted
fix(@angular-devkit/schematics): verify filesystem createSourceFromUrl context before use
1 parent 3f78080 commit 165abc8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ export abstract class FileSystemEngineHostBase implements FileSystemEngineHost {
119119
collection: FileSystemCollectionDesc,
120120
desc: Partial<FileSystemSchematicDesc>): FileSystemSchematicDesc;
121121

122-
private _transforms: OptionTransform<{}, {}>[] = [];
122+
// tslint:disable-next-line:no-any
123+
private _transforms: OptionTransform<any, any>[] = [];
123124
private _contextTransforms: ContextTransform[] = [];
124125
private _taskFactories = new Map<string, () => Observable<TaskExecutor>>();
125126

@@ -274,10 +275,16 @@ export abstract class FileSystemEngineHostBase implements FileSystemEngineHost {
274275
switch (url.protocol) {
275276
case null:
276277
case 'file:':
277-
return (context: FileSystemSchematicContext) => {
278+
return (context) => {
279+
// Check if context has necessary FileSystemSchematicContext path property
280+
const fileDescription = context.schematic.description as { path?: string };
281+
if (fileDescription.path === undefined) {
282+
throw new Error('Unsupported schematic context. Expected a FileSystemSchematicContext.');
283+
}
284+
278285
// Resolve all file:///a/b/c/d from the schematic's own path, and not the current
279286
// path.
280-
const root = normalize(resolve(context.schematic.description.path, url.path || ''));
287+
const root = normalize(resolve(fileDescription.path, url.path || ''));
281288

282289
return new HostCreateTree(new virtualFs.ScopedHost(new NodeJsSyncHost(), root));
283290
};

0 commit comments

Comments
 (0)