@@ -6,6 +6,7 @@ import { excludedNames, FileMatcher } from "../fileMatcher"
6
6
import { Packager } from "../packager"
7
7
import { resolveFunction } from "../platformPackager"
8
8
import { FileCopyHelper } from "./AppFileWalker"
9
+ import { NodeModuleInfo } from "./packageDependencies"
9
10
10
11
const excludedFiles = new Set (
11
12
[ ".DS_Store" , "node_modules" /* already in the queue */ , "CHANGELOG.md" , "ChangeLog" , "changelog.md" , "Changelog.md" , "Changelog" , "binding.gyp" , ".npmignore" ] . concat (
@@ -37,108 +38,107 @@ export class NodeModuleCopyHelper extends FileCopyHelper {
37
38
super ( matcher , matcher . isEmpty ( ) ? null : matcher . createFilter ( ) , packager )
38
39
}
39
40
40
- async collectNodeModules ( baseDir : string , moduleNames : Iterable < string > , nodeModuleExcludedExts : Array < string > ) : Promise < Array < string > > {
41
+ async collectNodeModules ( moduleInfo : NodeModuleInfo , nodeModuleExcludedExts : Array < string > ) : Promise < Array < string > > {
41
42
const filter = this . filter
42
43
const metadata = this . metadata
43
44
44
45
const onNodeModuleFile = await resolveFunction ( this . packager . appInfo . type , this . packager . config . onNodeModuleFile , "onNodeModuleFile" )
45
46
46
47
const result : Array < string > = [ ]
47
48
const queue : Array < string > = [ ]
48
- for ( const moduleName of moduleNames ) {
49
- const tmpPath = baseDir + path . sep + moduleName
50
- queue . length = 1
51
- // The path should be corrected in Windows that when the moduleName is Scoped packages named.
52
- const depPath = path . normalize ( tmpPath )
53
- queue [ 0 ] = depPath
54
-
55
- while ( queue . length > 0 ) {
56
- const dirPath = queue . pop ( ) !
57
-
58
- const childNames = await readdir ( dirPath )
59
- childNames . sort ( )
60
-
61
- const isTopLevel = dirPath === depPath
62
- const dirs : Array < string > = [ ]
63
- // our handler is async, but we should add sorted files, so, we add file to result not in the mapper, but after map
64
- const sortedFilePaths = await BluebirdPromise . map (
65
- childNames ,
66
- name => {
67
- const filePath = dirPath + path . sep + name
68
-
69
- const forceIncluded = onNodeModuleFile != null && ! ! onNodeModuleFile ( filePath )
70
-
71
- if ( excludedFiles . has ( name ) || name . startsWith ( "._" ) ) {
72
- return null
73
- }
74
-
75
- if ( ! forceIncluded ) {
76
- for ( const ext of nodeModuleExcludedExts ) {
77
- if ( name . endsWith ( ext ) ) {
78
- return null
79
- }
80
- }
49
+ const tmpPath = moduleInfo . dir
50
+ const moduleName = moduleInfo . name
51
+ queue . length = 1
52
+ // The path should be corrected in Windows that when the moduleName is Scoped packages named.
53
+ const depPath = path . normalize ( tmpPath )
54
+ queue [ 0 ] = depPath
55
+
56
+ while ( queue . length > 0 ) {
57
+ const dirPath = queue . pop ( ) !
58
+
59
+ const childNames = await readdir ( dirPath )
60
+ childNames . sort ( )
61
+
62
+ const isTopLevel = dirPath === depPath
63
+ const dirs : Array < string > = [ ]
64
+ // our handler is async, but we should add sorted files, so, we add file to result not in the mapper, but after map
65
+ const sortedFilePaths = await BluebirdPromise . map (
66
+ childNames ,
67
+ name => {
68
+ const filePath = dirPath + path . sep + name
69
+
70
+ const forceIncluded = onNodeModuleFile != null && ! ! onNodeModuleFile ( filePath )
71
+
72
+ if ( excludedFiles . has ( name ) || name . startsWith ( "._" ) ) {
73
+ return null
74
+ }
81
75
82
- // noinspection SpellCheckingInspection
83
- if ( isTopLevel && ( topLevelExcludedFiles . has ( name ) || ( moduleName === "libui-node" && ( name === "build" || name === "docs" || name === "src" ) ) ) ) {
76
+ if ( ! forceIncluded ) {
77
+ for ( const ext of nodeModuleExcludedExts ) {
78
+ if ( name . endsWith ( ext ) ) {
84
79
return null
85
80
}
81
+ }
86
82
87
- if ( dirPath . endsWith ( "build" ) ) {
88
- if ( name === "gyp-mac-tool" || name === "Makefile" || name . endsWith ( ".mk" ) || name . endsWith ( ".gypi" ) || name . endsWith ( ".Makefile" ) ) {
89
- return null
90
- }
91
- } else if ( dirPath . endsWith ( "Release" ) && ( name === ".deps" || name === "obj.target" ) ) {
92
- return null
93
- } else if ( name === "src" && ( dirPath . endsWith ( "keytar" ) || dirPath . endsWith ( "keytar-prebuild" ) ) ) {
94
- return null
95
- } else if ( dirPath . endsWith ( "lzma-native" ) && ( name === "build" || name === "deps" ) ) {
96
- return null
97
- }
83
+ // noinspection SpellCheckingInspection
84
+ if ( isTopLevel && ( topLevelExcludedFiles . has ( name ) || ( moduleName === "libui-node" && ( name === "build" || name === "docs" || name === "src" ) ) ) ) {
85
+ return null
98
86
}
99
87
100
- return lstat ( filePath ) . then ( stat => {
101
- if ( filter != null && ! filter ( filePath , stat ) ) {
88
+ if ( dirPath . endsWith ( "build" ) ) {
89
+ if ( name === "gyp-mac-tool" || name === "Makefile" || name . endsWith ( ".mk" ) || name . endsWith ( ".gypi" ) || name . endsWith ( ".Makefile" ) ) {
102
90
return null
103
91
}
92
+ } else if ( dirPath . endsWith ( "Release" ) && ( name === ".deps" || name === "obj.target" ) ) {
93
+ return null
94
+ } else if ( name === "src" && ( dirPath . endsWith ( "keytar" ) || dirPath . endsWith ( "keytar-prebuild" ) ) ) {
95
+ return null
96
+ } else if ( dirPath . endsWith ( "lzma-native" ) && ( name === "build" || name === "deps" ) ) {
97
+ return null
98
+ }
99
+ }
104
100
105
- if ( ! stat . isDirectory ( ) ) {
106
- metadata . set ( filePath , stat )
101
+ return lstat ( filePath ) . then ( stat => {
102
+ if ( filter != null && ! filter ( filePath , stat ) ) {
103
+ return null
104
+ }
105
+
106
+ if ( ! stat . isDirectory ( ) ) {
107
+ metadata . set ( filePath , stat )
108
+ }
109
+ const consumerResult = this . handleFile ( filePath , dirPath , stat )
110
+ if ( consumerResult == null ) {
111
+ if ( stat . isDirectory ( ) ) {
112
+ dirs . push ( name )
113
+ return null
114
+ } else {
115
+ return filePath
107
116
}
108
- const consumerResult = this . handleFile ( filePath , dirPath , stat )
109
- if ( consumerResult == null ) {
110
- if ( stat . isDirectory ( ) ) {
117
+ } else {
118
+ return consumerResult . then ( it => {
119
+ // asarUtil can return modified stat (symlink handling)
120
+ if ( ( it == null ? stat : it ) . isDirectory ( ) ) {
111
121
dirs . push ( name )
112
122
return null
113
123
} else {
114
124
return filePath
115
125
}
116
- } else {
117
- return consumerResult . then ( it => {
118
- // asarUtil can return modified stat (symlink handling)
119
- if ( ( it == null ? stat : it ) . isDirectory ( ) ) {
120
- dirs . push ( name )
121
- return null
122
- } else {
123
- return filePath
124
- }
125
- } )
126
- }
127
- } )
128
- } ,
129
- CONCURRENCY
130
- )
131
-
132
- for ( const child of sortedFilePaths ) {
133
- if ( child != null ) {
134
- result . push ( child )
135
- }
126
+ } )
127
+ }
128
+ } )
129
+ } ,
130
+ CONCURRENCY
131
+ )
132
+
133
+ for ( const child of sortedFilePaths ) {
134
+ if ( child != null ) {
135
+ result . push ( child )
136
136
}
137
+ }
137
138
138
- dirs . sort ( )
139
- for ( const child of dirs ) {
140
- queue . push ( dirPath + path . sep + child )
141
- }
139
+ dirs . sort ( )
140
+ for ( const child of dirs ) {
141
+ queue . push ( dirPath + path . sep + child )
142
142
}
143
143
}
144
144
return result
0 commit comments