1
- import { log } from "builder-util"
1
+ import { log , FilterStats } from "builder-util"
2
2
import { isBinaryFileSync } from "isbinaryfile"
3
3
import * as path from "path"
4
- import { NODE_MODULES_PATTERN } from "../fileTransformer"
5
- import { getDestinationPath , ResolvedFileSet } from "../util/appFileCopier"
6
-
7
- function addValue ( map : Map < string , Array < string > > , key : string , value : string ) {
8
- let list = map . get ( key )
9
- if ( list == null ) {
10
- list = [ value ]
11
- map . set ( key , list )
12
- } else {
13
- list . push ( value )
14
- }
15
- }
4
+ import { ResolvedFileSet } from "../util/appFileCopier"
16
5
17
6
export function isLibOrExe ( file : string ) : boolean {
18
7
// https://github.com/electron-userland/electron-builder/issues/3038
19
8
return file . endsWith ( ".dll" ) || file . endsWith ( ".exe" ) || file . endsWith ( ".dylib" ) || file . endsWith ( ".so" ) || file . endsWith ( ".node" )
20
9
}
21
10
22
11
/** @internal */
23
- export function detectUnpackedDirs ( fileSet : ResolvedFileSet , autoUnpackDirs : Set < string > , defaultDestination : string ) {
24
- const dirToCreate = new Map < string , Array < string > > ( )
12
+ export function detectUnpackedDirs ( fileSet : ResolvedFileSet , autoUnpackDirs : Set < string > ) {
25
13
const metadata = fileSet . metadata
26
14
27
- function addParents ( child : string , root : string ) {
28
- child = path . dirname ( child )
29
- if ( autoUnpackDirs . has ( child ) ) {
30
- return
31
- }
32
-
33
- do {
34
- autoUnpackDirs . add ( child )
35
- const p = path . dirname ( child )
36
- // create parent dir to be able to copy file later without directory existence check
37
- addValue ( dirToCreate , p , path . basename ( child ) )
38
-
39
- if ( child === root || p === root || autoUnpackDirs . has ( p ) ) {
40
- break
41
- }
42
- child = p
43
- } while ( true )
44
-
45
- autoUnpackDirs . add ( root )
46
- }
47
-
48
15
for ( let i = 0 , n = fileSet . files . length ; i < n ; i ++ ) {
49
16
const file = fileSet . files [ i ]
50
- const index = file . lastIndexOf ( NODE_MODULES_PATTERN )
51
- if ( index < 0 ) {
17
+ const stat : FilterStats = metadata . get ( file ) !
18
+ if ( ! stat . moduleRootPath || autoUnpackDirs . has ( stat . moduleRootPath ) ) {
52
19
continue
53
20
}
54
21
55
- let nextSlashIndex = file . indexOf ( path . sep , index + NODE_MODULES_PATTERN . length + 1 )
56
- if ( nextSlashIndex < 0 ) {
57
- continue
58
- }
59
-
60
- if ( file [ index + NODE_MODULES_PATTERN . length ] === "@" ) {
61
- nextSlashIndex = file . indexOf ( path . sep , nextSlashIndex + 1 )
62
- }
63
-
64
- if ( ! metadata . get ( file ) ! . isFile ( ) ) {
65
- continue
66
- }
67
-
68
- const packageDir = file . substring ( 0 , nextSlashIndex )
69
- const packageDirPathInArchive = path . relative ( defaultDestination , getDestinationPath ( packageDir , fileSet ) )
70
- const pathInArchive = path . relative ( defaultDestination , getDestinationPath ( file , fileSet ) )
71
- if ( autoUnpackDirs . has ( packageDirPathInArchive ) ) {
72
- // if package dir is unpacked, any file also unpacked
73
- addParents ( pathInArchive , packageDirPathInArchive )
22
+ if ( ! stat . isFile ( ) ) {
74
23
continue
75
24
}
76
25
77
26
// https://github.com/electron-userland/electron-builder/issues/2679
78
27
let shouldUnpack = false
79
28
// ffprobe-static and ffmpeg-static are known packages to always unpack
80
- const moduleName = path . basename ( packageDir )
29
+ const moduleName = stat . moduleName
81
30
const fileBaseName = path . basename ( file )
82
31
const hasExtension = path . extname ( fileBaseName )
83
32
if ( moduleName === "ffprobe-static" || moduleName === "ffmpeg-static" || isLibOrExe ( file ) ) {
@@ -91,9 +40,8 @@ export function detectUnpackedDirs(fileSet: ResolvedFileSet, autoUnpackDirs: Set
91
40
}
92
41
93
42
if ( log . isDebugEnabled ) {
94
- log . debug ( { file : pathInArchive , reason : "contains executable code" } , "not packed into asar archive" )
43
+ log . debug ( { file : stat . moduleFullFilePath , reason : "contains executable code" } , "not packed into asar archive" )
95
44
}
96
-
97
- addParents ( pathInArchive , packageDirPathInArchive )
45
+ autoUnpackDirs . add ( stat . moduleRootPath )
98
46
}
99
47
}
0 commit comments