@@ -5,10 +5,9 @@ import * as constants from "../../../lib/constants";
5
5
import * as path from "path" ;
6
6
import Future = require( "fibers/future" ) ;
7
7
import * as destCopyLib from "./node-modules-dest-copy" ;
8
+ import * as fiberBootstrap from "../../common/fiber-bootstrap" ;
8
9
9
- let gulp = require ( "gulp" ) ;
10
- let vinylFilterSince = require ( "vinyl-filter-since" ) ;
11
- let through = require ( "through2" ) ;
10
+ let glob = require ( "glob" ) ;
12
11
13
12
export class Builder implements IBroccoliBuilder {
14
13
constructor (
@@ -28,30 +27,50 @@ export class Builder implements IBroccoliBuilder {
28
27
let nodeModulesPath = path . join ( projectDir , constants . NODE_MODULES_FOLDER_NAME ) ;
29
28
let nodeModules : any = { } ;
30
29
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 ( ) ) {
55
74
future . return ( ) ;
56
75
}
57
76
} ) ;
0 commit comments