Skip to content

Commit

Permalink
feat: support asar in package.json's main even when not packaging t…
Browse files Browse the repository at this point in the history
…o asar during the build

Closes #759
  • Loading branch information
develar committed Sep 19, 2016
1 parent 70abaa3 commit d9bc4e0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ vendor/**/* filter=lfs diff=lfs merge=lfs -text
*.gif filter=lfs diff=lfs merge=lfs -text
*.keychain filter=lfs diff=lfs merge=lfs -text
*.bmp filter=lfs diff=lfs merge=lfs -text
*.asar filter=lfs diff=lfs merge=lfs -text
16 changes: 16 additions & 0 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,22 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
const relativeFile = path.relative(this.info.appDir, path.resolve(this.info.appDir, file))
if (isAsar) {
await checkFileInArchive(path.join(resourcesDir, "app.asar"), relativeFile, messagePrefix)
return
}

const pathParsed = path.parse(file)
// Even when packaging to asar is disabled, it does not imply that the main file can not be inside an .asar archive.
// This may occur when the packaging is done manually before processing with electron-builder.
if (pathParsed.dir.includes(".asar")) {
// The path needs to be split to the part with an asar archive which acts like a directory and the part with
// the path to main file itself. (e.g. path/arch.asar/dir/index.js -> path/arch.asar, dir/index.js)
const pathSplit: Array<string> = pathParsed.dir.split(path.sep)
let partWithAsarIndex = 0
pathSplit.some((pathPart: string, index: number) => (partWithAsarIndex = index, pathPart.endsWith(".asar")))
const asarPath = path.join.apply(path, pathSplit.slice(0, partWithAsarIndex + 1))
let mainPath = (pathSplit.length > partWithAsarIndex + 1) ? path.join.apply(pathSplit.slice(partWithAsarIndex + 1)) : ""
mainPath += path.join(mainPath, pathParsed.base)
await checkFileInArchive(path.join(resourcesDir, "app", asarPath), mainPath, messagePrefix)
}
else {
const outStat = await statOrNull(path.join(resourcesDir, "app", relativeFile))
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/test-app/app/path/app.asar
Git LFS file not shown
26 changes: 26 additions & 0 deletions test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ test("invalid main in the app package.json (no asar)", t => t.throws(assertPack(
}
}), `Application entry file "main.js" does not exist. Seems like a wrong configuration.`))

test("invalid main in the app package.json (custom asar)", t => t.throws(assertPack("test-app", allPlatforms(false), {
projectDirCreated: projectDir => {
return BluebirdPromise.all([
modifyPackageJson(projectDir, data => {
data.main = "path/app.asar/main.js"
}, true),
modifyPackageJson(projectDir, data => {
data.build.asar = false
})
])
}
}), /Application entry file "main.js" in the ("[^"]*") does not exist\. Seems like a wrong configuration\./))

test("main in the app package.json (no asar)", () => assertPack("test-app", allPlatforms(false), {
projectDirCreated: projectDir => {
return BluebirdPromise.all([
Expand All @@ -140,6 +153,19 @@ test("main in the app package.json (no asar)", () => assertPack("test-app", allP
}
}))

test("main in the app package.json (custom asar)", () => assertPack("test-app", allPlatforms(false), {
projectDirCreated: projectDir => {
return BluebirdPromise.all([
modifyPackageJson(projectDir, data => {
data.main = "path/app.asar/index.js"
}, true),
modifyPackageJson(projectDir, data => {
data.build.asar = false
})
])
}
}))

test("relative index", () => assertPack("test-app", allPlatforms(false), {
projectDirCreated: projectDir => modifyPackageJson(projectDir, data => {
data.main = "./index.js"
Expand Down
4 changes: 1 addition & 3 deletions test/src/nsisUpdaterTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ test("cannot find suitable file for version", async (t) => {
package: "incorrect-file-version",
})

const updateCheckResult = await updater.checkForUpdates()
assertThat(updateCheckResult.downloadPromise).isNotNull()
t.throws(updateCheckResult.downloadPromise, /Cannot find suitable file for version 1.0.0 in/)
t.throws(updater.checkForUpdates(), /Cannot find suitable file for version 1.0.0 in/)
})

test("file url", async () => {
Expand Down

0 comments on commit d9bc4e0

Please sign in to comment.