diff --git a/.gitattributes b/.gitattributes index 977d61ba170..baaba2d4bd9 100755 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/src/platformPackager.ts b/src/platformPackager.ts index d8a92eb5b11..2367e8f1dd5 100644 --- a/src/platformPackager.ts +++ b/src/platformPackager.ts @@ -363,6 +363,22 @@ export abstract class PlatformPackager 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 = 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)) diff --git a/test/fixtures/test-app/app/path/app.asar b/test/fixtures/test-app/app/path/app.asar new file mode 100644 index 00000000000..3c72fc4f3fb --- /dev/null +++ b/test/fixtures/test-app/app/path/app.asar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bfcbb18758e4a800225b926145a21559c0c9b4ff2705425fa25cb2aabfdd5dfd +size 714 diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts index efb1853bde5..fb3f19d7cd4 100755 --- a/test/src/BuildTest.ts +++ b/test/src/BuildTest.ts @@ -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([ @@ -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" diff --git a/test/src/nsisUpdaterTest.ts b/test/src/nsisUpdaterTest.ts index c878acf8391..4d136459673 100644 --- a/test/src/nsisUpdaterTest.ts +++ b/test/src/nsisUpdaterTest.ts @@ -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 () => {