@@ -18,9 +18,8 @@ export class Builder implements IBroccoliBuilder {
1818 private $projectData : IProjectData ,
1919 private $projectDataService : IProjectDataService ,
2020 private $injector : IInjector ,
21- private $logger : ILogger
22- ) {
23- }
21+ private $logger : ILogger ,
22+ private $lockfile : ILockFile ) { }
2423
2524 public getChangedNodeModules ( absoluteOutputPath : string , platform : string , lastModifiedTime ?: Date ) : IFuture < any > {
2625 return ( ( ) => {
@@ -38,10 +37,13 @@ export class Builder implements IBroccoliBuilder {
3837 stat : true
3938 } , ( er : Error , files : string [ ] ) => {
4039 fiberBootstrap . run ( ( ) => {
40+ this . $lockfile . lock ( ) . wait ( ) ;
4141 if ( er ) {
4242 if ( ! future . isResolved ( ) ) {
4343 future . throw ( er ) ;
4444 }
45+
46+ this . $lockfile . unlock ( ) . wait ( ) ;
4547 match . abort ( ) ;
4648 return ;
4749 }
@@ -59,6 +61,7 @@ export class Builder implements IBroccoliBuilder {
5961 }
6062 if ( file === constants . NODE_MODULES_FOLDER_NAME ) {
6163 isNodeModulesModified = true ;
64+ this . $lockfile . unlock ( ) . wait ( ) ;
6265 match . abort ( ) ;
6366 if ( ! future . isResolved ( ) ) {
6467 future . return ( ) ;
@@ -69,29 +72,38 @@ export class Builder implements IBroccoliBuilder {
6972 let rootModuleFullPath = path . join ( nodeModulesPath , rootModuleName ) ;
7073 nodeModules [ rootModuleFullPath ] = rootModuleFullPath ;
7174 }
75+
76+ this . $lockfile . unlock ( ) . wait ( ) ;
7277 } ) ;
7378 } ) ;
7479 match . on ( "end" , ( ) => {
7580 if ( ! future . isResolved ( ) ) {
76- future . return ( ) ;
81+ let intervalId = setInterval ( ( ) => {
82+ fiberBootstrap . run ( ( ) => {
83+ if ( ! this . $lockfile . check ( ) . wait ( ) ) {
84+ future . return ( ) ;
85+ clearInterval ( intervalId ) ;
86+ }
87+ } ) ;
88+ } , 100 ) ;
7789 }
7890 } ) ;
7991
8092 future . wait ( ) ;
8193 }
8294
83- if ( isNodeModulesModified && this . $fs . exists ( absoluteOutputPath ) . wait ( ) ) {
95+ if ( isNodeModulesModified && this . $fs . exists ( absoluteOutputPath ) . wait ( ) ) {
8496 let currentPreparedTnsModules = this . $fs . readDirectory ( absoluteOutputPath ) . wait ( ) ;
8597 let tnsModulesPath = path . join ( projectDir , constants . APP_FOLDER_NAME , constants . TNS_MODULES_FOLDER_NAME ) ;
86- if ( ! this . $fs . exists ( tnsModulesPath ) . wait ( ) ) {
98+ if ( ! this . $fs . exists ( tnsModulesPath ) . wait ( ) ) {
8799 tnsModulesPath = path . join ( projectDir , constants . NODE_MODULES_FOLDER_NAME , constants . TNS_CORE_MODULES_NAME ) ;
88100 }
89101 let tnsModulesInApp = this . $fs . readDirectory ( tnsModulesPath ) . wait ( ) ;
90102 let modulesToDelete = _ . difference ( currentPreparedTnsModules , tnsModulesInApp ) ;
91103 _ . each ( modulesToDelete , moduleName => this . $fs . deleteDirectory ( path . join ( absoluteOutputPath , moduleName ) ) . wait ( ) ) ;
92104 }
93105
94- if ( ! lastModifiedTime || isNodeModulesModified ) {
106+ if ( ! lastModifiedTime || isNodeModulesModified ) {
95107 this . listModules ( nodeModulesPath , nodeModules ) ;
96108 }
97109
0 commit comments