From 82f16d1b3d6fe163d1f1c52e5a9d05717e0e03b9 Mon Sep 17 00:00:00 2001 From: develar Date: Tue, 3 Jan 2017 09:00:26 +0100 Subject: [PATCH] fix: asarUnpack unpacks parent directory when file is specified Closes #1071 --- packages/electron-builder/src/asarUtil.ts | 6 ++++-- test/src/globTest.ts | 13 +++++++++---- test/src/helpers/runTests.ts | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/electron-builder/src/asarUtil.ts b/packages/electron-builder/src/asarUtil.ts index 5d12dbfd0e2..faca8a20627 100644 --- a/packages/electron-builder/src/asarUtil.ts +++ b/packages/electron-builder/src/asarUtil.ts @@ -162,6 +162,8 @@ class AsarPackager { await this.detectUnpackedDirs(files, metadata, unpackedDirs, unpackedDest, fileIndexToModulePackageData) } + const dirToCreateForUnpackedFiles = new Set(unpackedDirs) + const filesToUnpack: Array = [] const mainPackageJson = path.join(this.src, "package.json") const fileCopier = new FileCopier() @@ -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)) } diff --git a/test/src/globTest.ts b/test/src/globTest.ts index 802a88b1dc0..d2b3b881b4b 100644 --- a/test/src/globTest.ts +++ b/test/src/globTest.ts @@ -1,4 +1,4 @@ -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" @@ -6,13 +6,17 @@ 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({ @@ -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", () => { diff --git a/test/src/helpers/runTests.ts b/test/src/helpers/runTests.ts index 89df1a09148..544cf6e5afb 100755 --- a/test/src/helpers/runTests.ts +++ b/test/src/helpers/runTests.ts @@ -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",