@@ -5,10 +5,9 @@ import * as constants from "../../../lib/constants";
55import * as path from "path" ;
66import Future = require( "fibers/future" ) ;
77import * as destCopyLib from "./node-modules-dest-copy" ;
8+ import * as fiberBootstrap from "../../common/fiber-bootstrap" ;
89
9- let gulp = require ( "gulp" ) ;
10- let vinylFilterSince = require ( "vinyl-filter-since" ) ;
11- let through = require ( "through2" ) ;
10+ let glob = require ( "glob" ) ;
1211
1312export class Builder implements IBroccoliBuilder {
1413 constructor (
@@ -28,30 +27,50 @@ export class Builder implements IBroccoliBuilder {
2827 let nodeModulesPath = path . join ( projectDir , constants . NODE_MODULES_FOLDER_NAME ) ;
2928 let nodeModules : any = { } ;
3029
31- if ( lastModifiedTime ) {
32- let pipeline = gulp . src ( path . join ( projectDir , "node_modules/**" ) )
33- . pipe ( vinylFilterSince ( lastModifiedTime ) )
34- . pipe ( through . obj ( ( chunk : any , enc : any , cb : Function ) => {
35- if ( chunk . path === nodeModulesPath ) {
36- isNodeModulesModified = true ;
37- }
38-
39- if ( ! isNodeModulesModified ) {
40- let rootModuleName = chunk . path . split ( nodeModulesPath ) [ 1 ] . split ( path . sep ) [ 1 ] ;
41- let rootModuleFullPath = path . join ( nodeModulesPath , rootModuleName ) ;
42- nodeModules [ rootModuleFullPath ] = rootModuleFullPath ;
43- }
44-
45- cb ( null ) ;
46- } ) )
47- . pipe ( gulp . dest ( absoluteOutputPath ) ) ;
48-
49- let future = new Future < void > ( ) ;
50-
51- pipeline . on ( 'end' , ( err : Error , data : any ) => {
52- if ( err ) {
53- future . throw ( err ) ;
54- } else {
30+ if ( lastModifiedTime ) {
31+ let future = new Future ( ) ;
32+
33+ let match = new glob . Glob ( "node_modules/**" , {
34+ cwd : projectDir ,
35+ follow : true ,
36+ stat : true
37+ } , ( er : Error , files : string [ ] ) => {
38+ fiberBootstrap . run ( ( ) => {
39+ if ( er ) {
40+ if ( ! future . isResolved ( ) ) {
41+ future . throw ( er ) ;
42+ }
43+ match . abort ( ) ;
44+ return ;
45+ }
46+ for ( let i = 0 , l = files . length ; i < l ; i ++ ) {
47+ let file = files [ i ] ,
48+ resolvedPath = path . join ( projectDir , file ) ,
49+ relativePath = path . relative ( projectDir , resolvedPath ) ;
50+ let stat = match . statCache [ resolvedPath ] || match . statCache [ relativePath ] ;
51+ if ( ! stat ) {
52+ match . statCache [ resolvedPath ] = stat = this . $fs . getFsStats ( resolvedPath ) . wait ( ) ;
53+ }
54+
55+ if ( stat . mtime <= lastModifiedTime ) {
56+ continue ;
57+ }
58+ if ( file === constants . NODE_MODULES_FOLDER_NAME ) {
59+ isNodeModulesModified = true ;
60+ match . abort ( ) ;
61+ if ( ! future . isResolved ( ) ) {
62+ future . return ( ) ;
63+ }
64+ return ;
65+ }
66+ let rootModuleName = path . normalize ( file ) . split ( path . sep ) [ 1 ] ;
67+ let rootModuleFullPath = path . join ( nodeModulesPath , rootModuleName ) ;
68+ nodeModules [ rootModuleFullPath ] = rootModuleFullPath ;
69+ }
70+ } ) ;
71+ } ) ;
72+ match . on ( "end" , ( ) => {
73+ if ( ! future . isResolved ( ) ) {
5574 future . return ( ) ;
5675 }
5776 } ) ;
0 commit comments