@@ -16,56 +16,48 @@ const pickle = require ("chromium-pickle-js")
16
16
const Filesystem = require ( "asar-electron-builder/lib/filesystem" )
17
17
const UINT64 = require ( "cuint" ) . UINT64
18
18
19
- const MAX_FILE_REQUESTS = 32
19
+ const MAX_FILE_REQUESTS = 8
20
20
const concurrency = { concurrency : MAX_FILE_REQUESTS }
21
21
const NODE_MODULES_PATTERN = path . sep + "node_modules" + path . sep
22
22
23
23
export async function walk ( dirPath : string , consumer ?: ( file : string , stat : Stats ) => void , filter ?: Filter , addRootToResult ?: boolean ) : Promise < Array < string > > {
24
24
const childNames = await readdir ( dirPath )
25
- const list = await BluebirdPromise . map ( childNames , name => lstat ( dirPath + path . sep + name ) , concurrency )
26
- . then ( stats => BluebirdPromise . map ( stats , ( stat , index ) : any => {
27
- const filePath = dirPath + path . sep + childNames [ index ]
28
- if ( filter != null && ! filter ( filePath , stat ) ) {
29
- return null
30
- }
31
-
32
- if ( consumer != null ) {
33
- consumer ( filePath , stat )
34
- }
35
- if ( stat . isDirectory ( ) ) {
36
- return walk ( filePath , consumer , filter , true )
37
- }
38
- return filePath
39
- } , concurrency ) )
40
-
41
- list . sort ( ( a , b ) => {
42
- // files before directories
43
- if ( Array . isArray ( a ) && Array . isArray ( b ) ) {
44
- return 0
25
+ const stats = await BluebirdPromise . map ( childNames , name => lstat ( dirPath + path . sep + name ) , concurrency )
26
+ const dirs : Array < string > = [ ]
27
+ const files : Array < string > = addRootToResult ? [ dirPath ] : [ ]
28
+ await BluebirdPromise . map ( stats , ( stat , index ) : any => {
29
+ const filePath = dirPath + path . sep + childNames [ index ]
30
+ if ( filter != null && ! filter ( filePath , stat ) ) {
31
+ return null
45
32
}
46
- else if ( a == null || Array . isArray ( a ) ) {
47
- return 1
33
+
34
+ if ( consumer != null ) {
35
+ consumer ( filePath , stat )
48
36
}
49
- else if ( b == null || Array . isArray ( b ) ) {
50
- return - 1
37
+
38
+ if ( stat . isDirectory ( ) ) {
39
+ dirs . push ( filePath )
51
40
}
52
41
else {
53
- return a . localeCompare ( b )
42
+ files . push ( filePath )
54
43
}
55
- } )
44
+ } , concurrency )
56
45
57
- const result : Array < string > = addRootToResult ? [ dirPath ] : [ ]
58
- for ( let item of list ) {
59
- if ( item != null ) {
60
- if ( Array . isArray ( item ) ) {
61
- result . push . apply ( result , item )
62
- }
63
- else {
64
- result . push ( item )
65
- }
46
+ files . sort ( )
47
+
48
+ if ( dirs . length === 0 ) {
49
+ return files
50
+ }
51
+
52
+ dirs . sort ( )
53
+ const list = await BluebirdPromise . map ( dirs , dir => walk ( dir , consumer , filter , true ) , concurrency )
54
+ for ( let subList of list ) {
55
+ for ( let file of subList ) {
56
+ files . push ( file )
66
57
}
67
58
}
68
- return result
59
+
60
+ return files
69
61
}
70
62
71
63
export async function createAsarArchive ( src : string , resourcesPath : string , options : AsarOptions , filter : Filter ) : Promise < any > {
0 commit comments