@@ -4,13 +4,13 @@ import EventEmitter = NodeJS.EventEmitter
4
4
import { Promise as BluebirdPromise } from "bluebird"
5
5
import * as path from "path"
6
6
import { pack , ElectronPackagerOptions , userIgnoreFilter } from "electron-packager-tf"
7
- import { readdir , copy , unlink , lstat , remove , realpath } from "fs-extra-p"
7
+ import { readdir , copy , unlink , remove , realpath } from "fs-extra-p"
8
8
import { statOrNull , use , warn , log , exec } from "./util"
9
9
import { Packager } from "./packager"
10
- import { listPackage , statFile , AsarFileMetadata , createPackageFromFiles , AsarOptions } from "asar"
10
+ import { AsarOptions } from "asar"
11
11
import { archiveApp } from "./targets/archive"
12
- import { Glob } from "glob"
13
12
import { Minimatch } from "minimatch"
13
+ import { checkFileInPackage , createAsarArchive } from "./asarUtil"
14
14
import deepAssign = require( "deep-assign" )
15
15
16
16
//noinspection JSUnusedLocalSymbols
@@ -200,7 +200,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
200
200
}
201
201
202
202
if ( asarOptions != null ) {
203
- await this . createAsarArchive ( appPath , resourcesPath , asarOptions )
203
+ await createAsarArchive ( appPath , resourcesPath , asarOptions )
204
204
}
205
205
}
206
206
await pack ( options )
@@ -289,58 +289,6 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
289
289
}
290
290
}
291
291
292
- private async createAsarArchive ( src : string , resourcesPath : string , options : AsarOptions ) : Promise < any > {
293
- // dot: true as in the asar by default by we use glob default - do not copy hidden files
294
- let glob : Glob | null = null
295
- const files = ( await new BluebirdPromise < Array < string > > ( ( resolve , reject ) => {
296
- glob = new Glob ( "**/*" , {
297
- cwd : src ,
298
- } , ( error , matches ) => {
299
- if ( error == null ) {
300
- resolve ( matches )
301
- }
302
- else {
303
- reject ( error )
304
- }
305
- } )
306
- } ) ) . map ( it => path . join ( src , it ) )
307
-
308
- const metadata : { [ key : string ] : AsarFileMetadata ; } = { }
309
-
310
- const stats = await BluebirdPromise . map ( files , it => {
311
- if ( glob ! . symlinks [ it ] ) {
312
- // asar doesn't use stat for link
313
- metadata [ it ] = {
314
- type : "link" ,
315
- }
316
- }
317
- else if ( glob ! . cache [ it ] === "FILE" ) {
318
- const stat = glob ! . statCache [ it ]
319
- return stat == null ? lstat ( it ) : < any > stat
320
- }
321
- else {
322
- // asar doesn't use stat for dir
323
- metadata [ it ] = {
324
- type : "directory" ,
325
- }
326
- }
327
- return null
328
- } )
329
-
330
- for ( let i = 0 , n = files . length ; i < n ; i ++ ) {
331
- const stat = stats [ i ]
332
- if ( stat != null ) {
333
- metadata [ files [ i ] ] = {
334
- type : "file" ,
335
- stat : stat ,
336
- }
337
- }
338
- }
339
-
340
- await BluebirdPromise . promisify ( createPackageFromFiles ) ( src , path . join ( resourcesPath , "app.asar" ) , files , metadata , options )
341
- await remove ( src )
342
- }
343
-
344
292
private expandPattern ( pattern : string , arch : Arch ) : string {
345
293
return pattern
346
294
. replace ( / \$ \{ a r c h } / g, Arch [ arch ] )
@@ -406,33 +354,19 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
406
354
return path . join ( appOutDir , `${ this . appName } .app` , "Contents" , "Resources" )
407
355
}
408
356
409
- private async statFileInPackage ( resourcesDir : string , packageFile : string , isAsar : boolean ) : Promise < any > {
410
- const relativeFile = path . relative ( this . info . appDir , path . resolve ( this . info . appDir , packageFile ) )
357
+ private async checkFileInPackage ( resourcesDir : string , file : string , isAsar : boolean ) {
358
+ const relativeFile = path . relative ( this . info . appDir , path . resolve ( this . info . appDir , file ) )
411
359
if ( isAsar ) {
412
- try {
413
- return statFile ( path . join ( resourcesDir , "app.asar" ) , relativeFile ) != null
414
- }
415
- catch ( e ) {
416
- const asarFile = path . join ( resourcesDir , "app.asar" )
417
- const fileStat = await statOrNull ( asarFile )
418
- if ( fileStat == null ) {
419
- throw new Error ( `File "${ asarFile } " does not exist. Seems like a wrong configuration.` )
420
- }
421
-
422
- try {
423
- listPackage ( asarFile )
424
- }
425
- catch ( e ) {
426
- throw new Error ( `File "${ asarFile } " is corrupted: ${ e } ` )
427
- }
428
-
429
- // asar throws error on access to undefined object (info.link)
430
- return false
431
- }
360
+ await checkFileInPackage ( path . join ( resourcesDir , "app.asar" ) , relativeFile )
432
361
}
433
362
else {
434
363
const outStat = await statOrNull ( path . join ( resourcesDir , "app" , relativeFile ) )
435
- return outStat != null && outStat . isFile ( )
364
+ if ( outStat == null ) {
365
+ throw new Error ( `Application entry file "${ relativeFile } " does not exist. Seems like a wrong configuration.` )
366
+ }
367
+ else if ( ! outStat . isFile ( ) ) {
368
+ throw new Error ( `Application entry file "${ relativeFile } " is not a file. Seems like a wrong configuration.` )
369
+ }
436
370
}
437
371
}
438
372
@@ -446,12 +380,8 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
446
380
throw new Error ( `Output directory "${ appOutDir } " is not a directory. Seems like a wrong configuration.` )
447
381
}
448
382
449
- const resourcesDir = this . getResourcesDir ( appOutDir )
450
383
const mainFile = this . metadata . main || "index.js"
451
- const mainFileExists = await this . statFileInPackage ( resourcesDir , mainFile , isAsar )
452
- if ( ! mainFileExists ) {
453
- throw new Error ( `Application entry file ${ mainFile } could not be found in package. Seems like a wrong configuration.` )
454
- }
384
+ await this . checkFileInPackage ( this . getResourcesDir ( appOutDir ) , mainFile , isAsar )
455
385
}
456
386
457
387
protected async archiveApp ( format : string , appOutDir : string , outFile : string ) : Promise < any > {
0 commit comments