@@ -9,6 +9,7 @@ import * as path from "path"
9
9
import { log } from "./util/log"
10
10
import { Minimatch } from "minimatch"
11
11
import { deepAssign } from "./util/deepAssign"
12
+ import { Filter } from "./util/filter"
12
13
13
14
const isBinaryFile : any = BluebirdPromise . promisify ( require ( "isbinaryfile" ) )
14
15
const pickle = require ( "chromium-pickle-js" )
@@ -22,27 +23,25 @@ const MAX_FILE_REQUESTS = 32
22
23
const concurrency = { concurrency : MAX_FILE_REQUESTS }
23
24
const NODE_MODULES_PATTERN = path . sep + "node_modules" + path . sep
24
25
25
- export function walk ( dirPath : string , consumer ?: ( file : string , stat : Stats ) => void , filter ?: ( file : string ) => boolean , addRootToResult ?: boolean ) : BluebirdPromise < Array < string > > {
26
+ export function walk ( dirPath : string , consumer ?: ( file : string , stat : Stats ) => void , filter ?: Filter , addRootToResult ?: boolean ) : BluebirdPromise < Array < string > > {
26
27
return readdir ( dirPath )
27
- . then ( names => {
28
- return BluebirdPromise . map ( names , name => {
29
- const filePath = dirPath + path . sep + name
30
- if ( filter != null && ! filter ( filePath ) ) {
31
- return < any > null
32
- }
28
+ . then ( names => BluebirdPromise . map ( names , name => {
29
+ const filePath = dirPath + path . sep + name
30
+ return lstat ( filePath )
31
+ . then ( ( stat ) : any => {
32
+ if ( filter != null && ! filter ( filePath , stat ) ) {
33
+ return null
34
+ }
33
35
34
- return lstat ( filePath )
35
- . then ( ( stat ) : any => {
36
- if ( consumer != null ) {
37
- consumer ( filePath , stat )
38
- }
39
- if ( stat . isDirectory ( ) ) {
40
- return walk ( filePath , consumer , filter , true )
41
- }
42
- return filePath
43
- } )
44
- } , concurrency )
45
- } )
36
+ if ( consumer != null ) {
37
+ consumer ( filePath , stat )
38
+ }
39
+ if ( stat . isDirectory ( ) ) {
40
+ return walk ( filePath , consumer , filter , true )
41
+ }
42
+ return filePath
43
+ } )
44
+ } , concurrency ) )
46
45
. then ( list => {
47
46
list . sort ( ( a , b ) => {
48
47
// files before directories
@@ -75,7 +74,7 @@ export function walk(dirPath: string, consumer?: (file: string, stat: Stats) =>
75
74
} )
76
75
}
77
76
78
- export async function createAsarArchive ( src : string , resourcesPath : string , options : AsarOptions , filter : ( file : string ) => boolean ) : Promise < any > {
77
+ export async function createAsarArchive ( src : string , resourcesPath : string , options : AsarOptions , filter : Filter ) : Promise < any > {
79
78
// sort files to minimize file change (i.e. asar file is not changed dramatically on small change)
80
79
await new AsarPackager ( src , resourcesPath , options ) . pack ( filter )
81
80
}
@@ -96,7 +95,7 @@ class AsarPackager {
96
95
this . outFile = path . join ( this . resourcesPath , "app.asar" )
97
96
}
98
97
99
- async pack ( filter : ( file : string ) => boolean ) {
98
+ async pack ( filter : Filter ) {
100
99
const metadata = new Map < string , Stats > ( )
101
100
const files = await walk ( this . src , ( it , stat ) => {
102
101
metadata . set ( it , stat )
0 commit comments