diff --git a/package.json b/package.json index caa8fbfcbec..13a48c05e61 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "signcode": "^0.4.0", "source-map-support": "^0.4.0", "tmp": "0.0.28", - "typescript": "^1.9.0-dev.20160423" + "typescript": "^1.9.0-dev.20160425" }, "optionalDependencies": { "appdmg": "^0.3.7" diff --git a/src/platformPackager.ts b/src/platformPackager.ts index 84906279594..ea953c3b2e8 100644 --- a/src/platformPackager.ts +++ b/src/platformPackager.ts @@ -9,14 +9,13 @@ import { copy } from "fs-extra-p" import { statOrNull, use } from "./util" import { Packager } from "./packager" import deepAssign = require("deep-assign") +import { statFile } from "asar" //noinspection JSUnusedLocalSymbols const __awaiter = require("./awaiter") const pack = BluebirdPromise.promisify(packager) -const asar = require("asar") - export interface PackagerOptions { arch?: string @@ -212,14 +211,21 @@ export abstract class PlatformPackager return path.join(appOutDir, this.appName + ".app", "Contents", "Resources") } - private async statPackageFile(appOutDir: string, packageFile: string, isAsar: boolean): Promise { - const fpath = path.resolve("/", packageFile) + private async statFileInPackage(appOutDir: string, packageFile: string, isAsar: boolean): Promise { + const relativeFile = path.relative(this.info.appDir, path.resolve(this.info.appDir, packageFile)) const resourcesDir = this.platform === Platform.OSX ? this.getOSXResourcesDir(appOutDir) : path.join(appOutDir, "resources") if (isAsar) { - const appPackage = path.join(resourcesDir, "app.asar") - return asar.listPackage(appPackage).indexOf(fpath) !== -1 - } else { - const outStat = await statOrNull(path.join(resourcesDir, fpath)) + try { + const fsAsar = statFile(path.join(resourcesDir, "app.asar"), relativeFile) + return fsAsar != null + } + catch (e) { + // asar throws error on access to undefined object (info.link) + return false + } + } + else { + const outStat = await statOrNull(path.join(resourcesDir, relativeFile)) return outStat != null && outStat.isFile() } } @@ -233,13 +239,12 @@ export abstract class PlatformPackager throw new Error(`Output directory ${appOutDir} is not a directory. Seems like a wrong configuration.`) } - const main = this.metadata.main || "index.js" - const mainExists = await this.statPackageFile(appOutDir, main, asar) - if (!mainExists) { - throw new Error(`Application entry file ` + main + ` could not be found in package. Seems like a wrong configuration.`) + const mainFile = this.metadata.main || "index.js" + const mainFileExists = await this.statFileInPackage(appOutDir, mainFile, asar) + if (!mainFileExists) { + throw new Error(`Application entry file ${mainFile} could not be found in package. Seems like a wrong configuration.`) } } - } function checkConflictingOptions(options: any) { diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts index 4fa46107893..3d3d1625189 100755 --- a/test/src/BuildTest.ts +++ b/test/src/BuildTest.ts @@ -45,19 +45,13 @@ test("build in the app package.json", t => t.throws(assertPack("test-app", allPl }, true) }), /'build' in the application package\.json .+/)) -test("invalid main in the app package.json", t => t.throws(assertPack("test-app", { - platform: [Platform.fromString(process.platform)], - dist: true -}, { +test("invalid main in the app package.json", t => t.throws(assertPack("test-app", allPlatformsAndCurrentArch(false), { tempDirCreated: projectDir => modifyPackageJson(projectDir, data => { data.main = "main.js" }, true) -}), /Application entry file main.js could not be found in package+/)) +}), "Application entry file main.js could not be found in package. Seems like a wrong configuration.")) -test("invalid main in the app package.json (no asar)", t => t.throws(assertPack("test-app", { - platform: [Platform.fromString(process.platform)], - dist: true -}, { +test("invalid main in the app package.json (no asar)", t => t.throws(assertPack("test-app", allPlatformsAndCurrentArch(false), { tempDirCreated: projectDir => { return BluebirdPromise.all([ modifyPackageJson(projectDir, data => { @@ -68,7 +62,7 @@ test("invalid main in the app package.json (no asar)", t => t.throws(assertPack( }) ]) } -}), /Application entry file main.js could not be found in package+/)) +}), "Application entry file main.js could not be found in package. Seems like a wrong configuration.")) test("version from electron-prebuilt dependency", () => assertPack("test-app-one", { platform: [Platform.fromString(process.platform)], @@ -88,7 +82,6 @@ test("version from electron-prebuilt dependency", () => assertPack("test-app-one test("www as default dir", () => assertPack("test-app", { platform: [Platform.fromString(process.platform)], - dist: true }, { tempDirCreated: projectDir => BluebirdPromise.all([ move(path.join(projectDir, "app"), path.join(projectDir, "www")) diff --git a/test/tsconfig.json b/test/tsconfig.json index e76bf91b7fa..def47da9f34 100755 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -28,6 +28,7 @@ ], "files": [ "../typings/appdmg.d.ts", + "../typings/asar.d.ts", "../typings/command-line-args.d.ts", "../typings/deep-assign.d.ts", "../typings/electron-packager.d.ts", diff --git a/tsconfig.json b/tsconfig.json index 8a3da7e9bdb..33429fd1f1c 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -33,6 +33,7 @@ ], "files": [ "typings/appdmg.d.ts", + "typings/asar.d.ts", "typings/command-line-args.d.ts", "typings/deep-assign.d.ts", "typings/electron-packager.d.ts", diff --git a/typings/asar.d.ts b/typings/asar.d.ts new file mode 100644 index 00000000000..85ba24efb64 --- /dev/null +++ b/typings/asar.d.ts @@ -0,0 +1,11 @@ +declare module "asar" { + interface Info { + offset: number + size: number + } + + export function listPackage(archive: string): Array + + // followLinks defaults to true + export function statFile(archive: string, filename: string, followLinks?: boolean): Info +} \ No newline at end of file