Skip to content

Commit

Permalink
test: cleanup after 355
Browse files Browse the repository at this point in the history
we should use statFile instead of listPackage
  • Loading branch information
develar committed Apr 26, 2016
1 parent a6e7119 commit 171148a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 18 additions & 13 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -212,14 +211,21 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return path.join(appOutDir, this.appName + ".app", "Contents", "Resources")
}

private async statPackageFile(appOutDir: string, packageFile: string, isAsar: boolean): Promise<any> {
const fpath = path.resolve("/", packageFile)
private async statFileInPackage(appOutDir: string, packageFile: string, isAsar: boolean): Promise<any> {
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()
}
}
Expand All @@ -233,13 +239,12 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
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) {
Expand Down
15 changes: 4 additions & 11 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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)],
Expand All @@ -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"))
Expand Down
1 change: 1 addition & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions typings/asar.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare module "asar" {
interface Info {
offset: number
size: number
}

export function listPackage(archive: string): Array<string>

// followLinks defaults to true
export function statFile(archive: string, filename: string, followLinks?: boolean): Info
}

0 comments on commit 171148a

Please sign in to comment.