@@ -4,16 +4,17 @@ import { copyDir, copyOrLinkFile, Filter, statOrNull } from "electron-builder-ut
44import { mkdirs } from "fs-extra-p"
55import { Minimatch } from "minimatch"
66import * as path from "path"
7+ import { Platform } from "./core"
78import { Config , FilePattern , PlatformSpecificBuildOptions } from "./metadata"
8- import { BuildInfo } from "./packagerApi "
9+ import { PlatformPackager } from "./platformPackager "
910import { createFilter , hasMagic } from "./util/filter"
1011
1112/** @internal */
1213export class FileMatcher {
1314 readonly from : string
1415 readonly to : string
1516
16- private readonly patterns : Array < string >
17+ readonly patterns : Array < string >
1718
1819 constructor ( from : string , to : string , private readonly macroExpander : ( pattern : string ) => string , patterns ?: Array < string > | string | n ) {
1920 this . from = macroExpander ( from )
@@ -33,11 +34,6 @@ export class FileMatcher {
3334 this . patterns . unshift ( this . normalizePattern ( pattern ) )
3435 }
3536
36- addAllPattern ( ) {
37- // must be first, see minimatchAll implementation
38- this . patterns . unshift ( "**/*" )
39- }
40-
4137 isEmpty ( ) {
4238 return this . patterns . length === 0
4339 }
@@ -86,31 +82,49 @@ export class FileMatcher {
8682}
8783
8884/** @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 )
9189 const matcher = patterns == null ? new FileMatcher ( appDir , path . join ( resourcesPath , "app" ) , macroExpander ) : patterns [ 0 ]
9290
9391 const relativeBuildResourceDir = path . relative ( matcher . from , buildResourceDir )
9492 const ignoreBuildResourceDirPattern = ( relativeBuildResourceDir . length !== 0 && ! relativeBuildResourceDir . startsWith ( "." ) ) ? `!${ relativeBuildResourceDir } {,/**/*}` : null
93+ const customFirstPatterns : Array < string > = [ ]
9594 if ( matcher . isEmpty ( ) || matcher . containsOnlyIgnore ( ) ) {
9695 if ( ignoreBuildResourceDirPattern != null ) {
9796 matcher . addPattern ( ignoreBuildResourceDirPattern )
9897 }
99- matcher . prependPattern ( "**/*" )
98+ customFirstPatterns . push ( "**/*" )
10099 }
101100 else {
102101 if ( ignoreBuildResourceDirPattern != null ) {
103- matcher . prependPattern ( ignoreBuildResourceDirPattern )
102+ customFirstPatterns . push ( ignoreBuildResourceDirPattern )
104103 }
104+
105105 // prependPattern - user pattern should be after to be able to override
106- matcher . prependPattern ( "**/node_modules/**/*" )
106+ customFirstPatterns . push ( "**/node_modules/**/*" )
107107 matcher . addPattern ( "package.json" )
108108 }
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+
109124 matcher . addPattern ( "!**/node_modules/*/{CHANGELOG.md,ChangeLog,changelog.md,README.md,README,readme.md,readme,test,__tests__,tests,powered-test,example,examples,*.d.ts}" )
110125 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}` )
112127 matcher . addPattern ( "!**/._*" )
113- matcher . addPattern ( "!*.iml" )
114128 //noinspection SpellCheckingInspection
115129 matcher . addPattern ( "!**/{.git,.hg,.svn,CVS,RCS,SCCS," +
116130 "__pycache__,.DS_Store,thumbs.db,.gitignore,.gitattributes," +
0 commit comments