@@ -8,20 +8,21 @@ var Cache = require('./Cache');
88var _ = require ( 'underscore' ) ;
99var workerFarm = require ( 'worker-farm' ) ;
1010
11- var workers = workerFarm ( require . resolve ( './worker' ) ) ;
12- warmupWorkers ( ) ;
13-
1411var readFile = q . nfbind ( fs . readFile ) ;
1512
1613module . exports = Transformer ;
1714Transformer . TransformError = TransformError ;
1815
1916function Transformer ( projectConfig ) {
2017 this . _cache = new Cache ( projectConfig ) ;
18+ this . _workers = workerFarm (
19+ { autoStart : true } ,
20+ projectConfig . transformModulePath
21+ ) ;
2122}
2223
2324Transformer . prototype . kill = function ( ) {
24- workerFarm . end ( workers ) ;
25+ workerFarm . end ( this . _workers ) ;
2526 return this . _cache . end ( ) ;
2627} ;
2728
@@ -36,6 +37,7 @@ Transformer.prototype.loadFileAndTransform = function(
3637 filePath ,
3738 options
3839) {
40+ var workers = this . _workers ;
3941 return this . _cache . get ( filePath , function ( ) {
4042 return readFile ( filePath )
4143 . then ( function ( buffer ) {
@@ -62,19 +64,6 @@ Transformer.prototype.loadFileAndTransform = function(
6264 } ) ;
6365} ;
6466
65- // worker-farm module starts workers lazily. But we want them to take time
66- // to initialize so we send a dummy request.
67- // see https://github.com/rvagg/node-worker-farm/issues/23
68- function warmupWorkers ( ) {
69- os . cpus ( ) . forEach ( function ( ) {
70- workers ( {
71- transformSets : [ 'es6' ] ,
72- sourceCode : '\n' ,
73- options : { }
74- } , function ( ) { } ) ;
75- } ) ;
76- }
77-
7867function TransformError ( ) { }
7968TransformError . __proto__ = SyntaxError . prototype ;
8069
0 commit comments