11exports . convert = convert ;
2+ exports . getSassProcess = getSassProcess ;
23
34var spawn = require ( 'child_process' ) . spawn ;
45var fs = require ( 'fs' ) ;
56var path = require ( 'path' ) ;
7+ var currentSassProcess = null ;
68
79function convert ( logger , projectDir , options ) {
810 return new Promise ( function ( resolve , reject ) {
@@ -12,7 +14,7 @@ function convert(logger, projectDir, options) {
1214 var sassPath = path . join ( peerSassPath , 'bin/node-sass' ) ;
1315 var appDir = path . join ( projectDir , "app" ) ;
1416 var importerPath = path . join ( __dirname , "importer.js" ) ;
15-
17+
1618 if ( fs . existsSync ( sassPath ) ) {
1719 try {
1820 logger . info ( 'Found peer node-sass' ) ;
@@ -34,16 +36,16 @@ function convert(logger, projectDir, options) {
3436 }
3537
3638 logger . trace ( process . execPath , nodeArgs . join ( ' ' ) ) ;
37- var sass = spawn ( process . execPath , nodeArgs ) ;
39+ currentSassProcess = spawn ( process . execPath , nodeArgs ) ;
3840
3941 var isResolved = false ;
4042 var watchResolveTimeout ;
41- sass . stdout . on ( 'data' , function ( data ) {
43+ currentSassProcess . stdout . on ( 'data' , function ( data ) {
4244 var stringData = data . toString ( ) ;
4345 logger . info ( stringData ) ;
4446 } ) ;
4547
46- sass . stderr . on ( 'data' , function ( err ) {
48+ currentSassProcess . stderr . on ( 'data' , function ( err ) {
4749 var message = '' ;
4850 var stringData = err . toString ( ) ;
4951
@@ -58,7 +60,7 @@ function convert(logger, projectDir, options) {
5860 logger . info ( message ) ;
5961 } ) ;
6062
61- sass . on ( 'error' , function ( err ) {
63+ currentSassProcess . on ( 'error' , function ( err ) {
6264 logger . info ( err . message ) ;
6365 if ( ! isResolved ) {
6466 isResolved = true ;
@@ -67,7 +69,8 @@ function convert(logger, projectDir, options) {
6769 } ) ;
6870
6971 // TODO: Consider using close event instead of exit
70- sass . on ( 'exit' , function ( code , signal ) {
72+ currentSassProcess . on ( 'exit' , function ( code , signal ) {
73+ currentSassProcess = null ;
7174 if ( ! isResolved ) {
7275 isResolved = true ;
7376 if ( code === 0 ) {
@@ -78,10 +81,14 @@ function convert(logger, projectDir, options) {
7881 }
7982 } ) ;
8083
81- // SASS does not recompile on watch, so directly resolve.
84+ // SASS does not recompile on watch, so directly resolve.
8285 if ( options . watch && ! isResolved ) {
8386 isResolved = true ;
8487 resolve ( ) ;
8588 }
8689 } ) ;
8790}
91+
92+ function getSassProcess ( ) {
93+ return currentSassProcess ;
94+ }
0 commit comments