@@ -4,16 +4,17 @@ import { copyDir, copyOrLinkFile, Filter, statOrNull } from "electron-builder-ut
4
4
import { mkdirs } from "fs-extra-p"
5
5
import { Minimatch } from "minimatch"
6
6
import * as path from "path"
7
+ import { Platform } from "./core"
7
8
import { Config , FilePattern , PlatformSpecificBuildOptions } from "./metadata"
8
- import { BuildInfo } from "./packagerApi "
9
+ import { PlatformPackager } from "./platformPackager "
9
10
import { createFilter , hasMagic } from "./util/filter"
10
11
11
12
/** @internal */
12
13
export class FileMatcher {
13
14
readonly from : string
14
15
readonly to : string
15
16
16
- private readonly patterns : Array < string >
17
+ readonly patterns : Array < string >
17
18
18
19
constructor ( from : string , to : string , private readonly macroExpander : ( pattern : string ) => string , patterns ?: Array < string > | string | n ) {
19
20
this . from = macroExpander ( from )
@@ -33,11 +34,6 @@ export class FileMatcher {
33
34
this . patterns . unshift ( this . normalizePattern ( pattern ) )
34
35
}
35
36
36
- addAllPattern ( ) {
37
- // must be first, see minimatchAll implementation
38
- this . patterns . unshift ( "**/*" )
39
- }
40
-
41
37
isEmpty ( ) {
42
38
return this . patterns . length === 0
43
39
}
@@ -86,31 +82,49 @@ export class FileMatcher {
86
82
}
87
83
88
84
/** @internal */
89
- export function createFileMatcher ( info : BuildInfo , appDir : string , resourcesPath : string , macroExpander : ( pattern : string ) => string , platformSpecificBuildOptions : PlatformSpecificBuildOptions , buildResourceDir : string ) {
90
- const patterns = info . isPrepackedAppAsar ? null : getFileMatchers ( info . config , "files" , appDir , path . join ( resourcesPath , "app" ) , false , macroExpander , platformSpecificBuildOptions )
85
+ export function createFileMatcher ( appDir : string , resourcesPath : string , macroExpander : ( pattern : string ) => string , platformSpecificBuildOptions : PlatformSpecificBuildOptions , packager : PlatformPackager < any > ) {
86
+ const buildResourceDir = path . resolve ( packager . info . projectDir , packager . buildResourcesDir )
87
+
88
+ const patterns = packager . info . isPrepackedAppAsar ? null : getFileMatchers ( packager . info . config , "files" , appDir , path . join ( resourcesPath , "app" ) , false , macroExpander , platformSpecificBuildOptions )
91
89
const matcher = patterns == null ? new FileMatcher ( appDir , path . join ( resourcesPath , "app" ) , macroExpander ) : patterns [ 0 ]
92
90
93
91
const relativeBuildResourceDir = path . relative ( matcher . from , buildResourceDir )
94
92
const ignoreBuildResourceDirPattern = ( relativeBuildResourceDir . length !== 0 && ! relativeBuildResourceDir . startsWith ( "." ) ) ? `!${ relativeBuildResourceDir } {,/**/*}` : null
93
+ const customFirstPatterns : Array < string > = [ ]
95
94
if ( matcher . isEmpty ( ) || matcher . containsOnlyIgnore ( ) ) {
96
95
if ( ignoreBuildResourceDirPattern != null ) {
97
96
matcher . addPattern ( ignoreBuildResourceDirPattern )
98
97
}
99
- matcher . prependPattern ( "**/*" )
98
+ customFirstPatterns . push ( "**/*" )
100
99
}
101
100
else {
102
101
if ( ignoreBuildResourceDirPattern != null ) {
103
- matcher . prependPattern ( ignoreBuildResourceDirPattern )
102
+ customFirstPatterns . push ( ignoreBuildResourceDirPattern )
104
103
}
104
+
105
105
// prependPattern - user pattern should be after to be able to override
106
- matcher . prependPattern ( "**/node_modules/**/*" )
106
+ customFirstPatterns . push ( "**/node_modules/**/*" )
107
107
matcher . addPattern ( "package.json" )
108
108
}
109
+
110
+ if ( packager . platform !== Platform . WINDOWS ) {
111
+ // https://github.com/electron-userland/electron-builder/issues/1738
112
+ customFirstPatterns . push ( "!**/node_modules/**/*.{dll,exe}" )
113
+ }
114
+
115
+ matcher . patterns . unshift ( ...customFirstPatterns )
116
+
117
+ // https://github.com/electron-userland/electron-builder/issues/1738#issuecomment-310729208
118
+ // must be before common ignore patterns (to ignore common ignores like .svn)
119
+ matcher . addPattern ( "!**/node_modules/lzma-native/build/**/*" )
120
+ matcher . addPattern ( "**/node_modules/lzma-native/build/{Release,Debug}" )
121
+ matcher . addPattern ( "!**/node_modules/lzma-native/deps/xz-*" )
122
+ matcher . addPattern ( "!**/node_modules/lzma-native/deps/doc{,/**/*}" )
123
+
109
124
matcher . addPattern ( "!**/node_modules/*/{CHANGELOG.md,ChangeLog,changelog.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}" )
110
125
matcher . addPattern ( "!**/node_modules/.bin" )
111
- matcher . addPattern ( " !**/*.{o,hprof,orig,pyc,pyo,rbc,swp}" )
126
+ matcher . addPattern ( ` !**/*.{iml, o,hprof,orig,pyc,pyo,rbc,swp,csproj,sln,xproj}` )
112
127
matcher . addPattern ( "!**/._*" )
113
- matcher . addPattern ( "!*.iml" )
114
128
//noinspection SpellCheckingInspection
115
129
matcher . addPattern ( "!**/{.git,.hg,.svn,CVS,RCS,SCCS," +
116
130
"__pycache__,.DS_Store,thumbs.db,.gitignore,.gitattributes," +
0 commit comments