@@ -9,7 +9,7 @@ import { copy } from "fs-extra-p"
9
9
import { statOrNull , use } from "./util"
10
10
import { Packager } from "./packager"
11
11
import deepAssign = require( "deep-assign" )
12
- import { statFile } from "asar"
12
+ import { listPackage , statFile } from "asar"
13
13
import ElectronPackagerOptions = ElectronPackager . ElectronPackagerOptions
14
14
15
15
//noinspection JSUnusedLocalSymbols
@@ -201,13 +201,16 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
201
201
return this . devMetadata . build [ "build-version" ] || process . env . TRAVIS_BUILD_NUMBER || process . env . APPVEYOR_BUILD_NUMBER || process . env . CIRCLE_BUILD_NUM || process . env . BUILD_NUMBER
202
202
}
203
203
204
+ private getResourcesDir ( appOutDir : string ) : string {
205
+ return this . platform === Platform . OSX ? this . getOSXResourcesDir ( appOutDir ) : path . join ( appOutDir , "resources" )
206
+ }
207
+
204
208
private getOSXResourcesDir ( appOutDir : string ) : string {
205
209
return path . join ( appOutDir , this . appName + ".app" , "Contents" , "Resources" )
206
210
}
207
211
208
- private async statFileInPackage ( appOutDir : string , packageFile : string , isAsar : boolean ) : Promise < any > {
212
+ private async statFileInPackage ( resourcesDir : string , packageFile : string , isAsar : boolean ) : Promise < any > {
209
213
const relativeFile = path . relative ( this . info . appDir , path . resolve ( this . info . appDir , packageFile ) )
210
- const resourcesDir = this . platform === Platform . OSX ? this . getOSXResourcesDir ( appOutDir ) : path . join ( appOutDir , "resources" )
211
214
if ( isAsar ) {
212
215
try {
213
216
return statFile ( path . join ( resourcesDir , "app.asar" ) , relativeFile ) != null
@@ -223,17 +226,38 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
223
226
}
224
227
}
225
228
226
- private async sanityCheckPackage ( appOutDir : string , asar : boolean ) : Promise < any > {
229
+ private async sanityCheckAsar ( asarFile : string ) : Promise < any > {
230
+ const outStat = await statOrNull ( asarFile )
231
+
232
+ if ( outStat == null ) {
233
+ throw new Error ( `Package file ${ asarFile } was not created.` )
234
+ }
235
+
236
+ try {
237
+ listPackage ( asarFile )
238
+ }
239
+ catch ( e ) {
240
+ throw new Error ( `Package file ${ asarFile } is corrupted.` )
241
+ }
242
+ }
243
+
244
+ private async sanityCheckPackage ( appOutDir : string , isAsar : boolean ) : Promise < any > {
227
245
const outStat = await statOrNull ( appOutDir )
246
+
228
247
if ( outStat == null ) {
229
248
throw new Error ( `Output directory ${ appOutDir } does not exists. Seems like a wrong configuration.` )
230
249
}
231
250
else if ( ! outStat . isDirectory ( ) ) {
232
251
throw new Error ( `Output directory ${ appOutDir } is not a directory. Seems like a wrong configuration.` )
233
252
}
234
253
254
+ const resourcesDir = this . getResourcesDir ( appOutDir )
255
+ if ( isAsar ) {
256
+ await this . sanityCheckAsar ( path . join ( resourcesDir , "app.asar" ) )
257
+ }
258
+
235
259
const mainFile = this . metadata . main || "index.js"
236
- const mainFileExists = await this . statFileInPackage ( appOutDir , mainFile , asar )
260
+ const mainFileExists = await this . statFileInPackage ( resourcesDir , mainFile , isAsar )
237
261
if ( ! mainFileExists ) {
238
262
throw new Error ( `Application entry file ${ mainFile } could not be found in package. Seems like a wrong configuration.` )
239
263
}
0 commit comments