Skip to content

Commit

Permalink
fix: asarUnpack unpacks parent directory when file is specified
Browse files Browse the repository at this point in the history
Closes #1071
  • Loading branch information
develar committed Jan 3, 2017
1 parent a602210 commit 82f16d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions packages/electron-builder/src/asarUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ class AsarPackager {
await this.detectUnpackedDirs(files, metadata, unpackedDirs, unpackedDest, fileIndexToModulePackageData)
}

const dirToCreateForUnpackedFiles = new Set<string>(unpackedDirs)

const filesToUnpack: Array<UnpackedFileTask> = []
const mainPackageJson = path.join(this.src, "package.json")
const fileCopier = new FileCopier()
Expand Down Expand Up @@ -189,8 +191,8 @@ class AsarPackager {
if (dirNode.unpacked || (this.unpackPattern != null && this.unpackPattern(file, stat))) {
node.unpacked = true

if (!dirNode.unpacked && !unpackedDirs.has(fileParent)) {
unpackedDirs.add(fileParent)
if (!dirNode.unpacked && !dirToCreateForUnpackedFiles.has(fileParent)) {
dirToCreateForUnpackedFiles.add(fileParent)
await ensureDir(fileParent.replace(this.src, unpackedDest))
}

Expand Down
13 changes: 9 additions & 4 deletions test/src/globTest.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { outputFile, symlink, writeFile } from "fs-extra-p"
import { outputFile, symlink, writeFile, mkdirs } from "fs-extra-p"
import { assertPack, modifyPackageJson, app, PackedContext } from "./helpers/packTester"
import BluebirdPromise from "bluebird-lst-c"
import * as path from "path"
import { assertThat } from "./helpers/fileAssert"
import { Platform, DIR_TARGET } from "electron-builder"
import { statFile } from "asar-electron-builder"

function createFiles(appDir: string) {
return BluebirdPromise.all([
async function createFiles(appDir: string) {
await BluebirdPromise.all([
outputFile(path.join(appDir, "assets", "file"), "data"),
outputFile(path.join(appDir, "b2", "file"), "data"),
outputFile(path.join(appDir, "do-not-unpack-dir", "file.json"), "{}")
.then(() => writeFile(path.join(appDir, "do-not-unpack-dir", "must-be-not-unpacked"), "{}")),
.then(() => writeFile(path.join(appDir, "do-not-unpack-dir", "must-be-not-unpacked"), "{}"))
])

const dir = path.join(appDir, "do-not-unpack-dir", "dir-2", "dir-3", "dir-3")
await mkdirs(dir)
await writeFile(path.join(dir, "file-in-asar"), "{}")
}

test.ifDevOrLinuxCi("unpackDir one", app({
Expand All @@ -31,6 +35,7 @@ function assertDirs(context: PackedContext) {
assertThat(path.join(context.getResources(Platform.LINUX), "app.asar.unpacked", "b2")).isDirectory(),
assertThat(path.join(context.getResources(Platform.LINUX), "app.asar.unpacked", "do-not-unpack-dir", "file.json")).isFile(),
assertThat(path.join(context.getResources(Platform.LINUX), "app.asar.unpacked", "do-not-unpack-dir", "must-be-not-unpacked")).doesNotExist(),
assertThat(path.join(context.getResources(Platform.LINUX), "app.asar.unpacked", "do-not-unpack-dir", "dir-2")).doesNotExist(),
])
}
test.ifDevOrLinuxCi("unpackDir", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/src/helpers/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async function runTests() {

require("jest-cli").runCLI({
verbose: true,
updateSnapshot: true,
updateSnapshot: false,
config: config,
bail: process.env.TEST_BAIL === "true",
runInBand: process.env.RUN_IN_BAND === "true",
Expand Down

0 comments on commit 82f16d1

Please sign in to comment.