Skip to content

Commit

Permalink
refactor: the schematics engine is really a singleton
Browse files Browse the repository at this point in the history
Using different engines in Schematics is dangerous.
  • Loading branch information
hansl authored and filipesilva committed Oct 18, 2017
1 parent e328e51 commit 3a14856
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/@angular/cli/utilities/schematics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

import {
Collection,
Engine,
Schematic,
SchematicEngine,
} from '@angular-devkit/schematics';
import {
FileSystemCollectionDesc,
FileSystemSchematicDesc,
NodeModulesEngineHost
} from '@angular-devkit/schematics/tools';
Expand All @@ -20,14 +22,22 @@ import 'rxjs/add/operator/map';

const SilentError = require('silent-error');

const engineHost = new NodeModulesEngineHost();
const engine: Engine<FileSystemCollectionDesc, FileSystemSchematicDesc>
= new SchematicEngine(engineHost);


export function getEngineHost() {
const engineHost = new NodeModulesEngineHost();
return engineHost;
}
export function getEngine(): Engine<FileSystemCollectionDesc, FileSystemSchematicDesc> {
return engine;
}


export function getCollection(collectionName: string): Collection<any, any> {
const engineHost = getEngineHost();
const engine = new SchematicEngine(engineHost);
const engine = getEngine();

// Add support for schemaJson.
engineHost.registerOptionsTransform((schematic: FileSystemSchematicDesc, options: any) => {
Expand Down

0 comments on commit 3a14856

Please sign in to comment.