diff --git a/src/asarUtil.ts b/src/asarUtil.ts index c8d0a273907..18214b2cdf5 100644 --- a/src/asarUtil.ts +++ b/src/asarUtil.ts @@ -384,7 +384,11 @@ function writeAsarFile(filesystem: any, dest: string, toPack: Array, cha }) } -export async function checkFileInPackage(asarFile: string, relativeFile: string) { +export async function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string) { + function error(text: string) { + return new Error(`${messagePrefix} "${relativeFile}" in the "${asarFile}" ${text}`) + } + let stat: AsarFileInfo | null try { stat = statFile(asarFile, relativeFile) @@ -392,14 +396,14 @@ export async function checkFileInPackage(asarFile: string, relativeFile: string) catch (e) { const fileStat = await statOrNull(asarFile) if (fileStat == null) { - throw new Error(`File "${asarFile}" does not exist. Seems like a wrong configuration.`) + throw error(`does not exist. Seems like a wrong configuration.`) } try { listPackage(asarFile) } catch (e) { - throw new Error(`File "${asarFile}" is corrupted: ${e}`) + throw error(`is corrupted: ${e}`) } // asar throws error on access to undefined object (info.link) @@ -407,10 +411,10 @@ export async function checkFileInPackage(asarFile: string, relativeFile: string) } if (stat == null) { - throw new Error(`Application entry file "${relativeFile}" in the "${asarFile}" does not exist. Seems like a wrong configuration.`) + throw error(`does not exist. Seems like a wrong configuration.`) } if (stat.size === 0) { - throw new Error(`Application entry file "${relativeFile}" in the "${asarFile}" is corrupted: size 0`) + throw error(`is corrupted: size 0`) } } diff --git a/src/metadata.ts b/src/metadata.ts index 2ce230676a9..82031422abe 100755 --- a/src/metadata.ts +++ b/src/metadata.ts @@ -3,6 +3,8 @@ import { ElectronPackagerOptions } from "./packager/dirPackager" export interface Metadata { readonly repository?: string | RepositoryInfo | null + + dependencies?: { [key: string]: string } } /* diff --git a/src/packager.ts b/src/packager.ts index 45a224c98da..f4005761d1f 100644 --- a/src/packager.ts +++ b/src/packager.ts @@ -168,7 +168,10 @@ export class Packager implements BuildInfo { checkNotEmpty("description", appMetadata.description) checkNotEmpty("version", appMetadata.version) + checkDependencies(this.devMetadata.dependencies) if ((appMetadata) !== this.devMetadata) { + checkDependencies(appMetadata.dependencies) + if ((appMetadata).build != null) { throw new Error(util.format(errorMessages.buildInAppSpecified, appPackageFile, devAppPackageFile)) } @@ -282,4 +285,16 @@ async function checkWineVersion(checkPromise: Promise) { if (semver.lt(wineVersion, "1.8.0")) { throw new Error(wineError(`wine 1.8+ is required, but your version is ${wineVersion}`)) } +} + +function checkDependencies(dependencies?: { [key: string]: string }) { + if (dependencies == null) { + return + } + + for (let name of ["electron", "electron-prebuilt", "electron-builder"]) { + if (name in dependencies) { + throw new Error(`${name} must be in the devDependencies`) + } + } } \ No newline at end of file diff --git a/src/platformPackager.ts b/src/platformPackager.ts index aa28d245da5..27aedd651ea 100644 --- a/src/platformPackager.ts +++ b/src/platformPackager.ts @@ -8,7 +8,7 @@ import { Packager } from "./packager" import { AsarOptions } from "asar-electron-builder" import { archiveApp } from "./targets/archive" import { Minimatch } from "minimatch" -import { checkFileInPackage, createAsarArchive } from "./asarUtil" +import { checkFileInArchive, createAsarArchive } from "./asarUtil" import { deepAssign } from "./util/deepAssign" import { warn, log, task } from "./util/log" import { AppInfo } from "./appInfo" @@ -362,25 +362,24 @@ export abstract class PlatformPackager return path.join(appOutDir, `${this.appInfo.productFilename}.app`, "Contents", "Resources") } - private async checkFileInPackage(resourcesDir: string, file: string, isAsar: boolean) { + private async checkFileInPackage(resourcesDir: string, file: string, messagePrefix: string, isAsar: boolean) { const relativeFile = path.relative(this.info.appDir, path.resolve(this.info.appDir, file)) if (isAsar) { - await checkFileInPackage(path.join(resourcesDir, "app.asar"), relativeFile) + await checkFileInArchive(path.join(resourcesDir, "app.asar"), relativeFile, messagePrefix) } else { const outStat = await statOrNull(path.join(resourcesDir, "app", relativeFile)) if (outStat == null) { - throw new Error(`Application entry file "${relativeFile}" does not exist. Seems like a wrong configuration.`) + throw new Error(`${messagePrefix} "${relativeFile}" does not exist. Seems like a wrong configuration.`) } else if (!outStat.isFile()) { - throw new Error(`Application entry file "${relativeFile}" is not a file. Seems like a wrong configuration.`) + throw new Error(`${messagePrefix} "${relativeFile}" is not a file. Seems like a wrong configuration.`) } } } private async sanityCheckPackage(appOutDir: string, isAsar: boolean): Promise { const outStat = await statOrNull(appOutDir) - if (outStat == null) { throw new Error(`Output directory "${appOutDir}" does not exist. Seems like a wrong configuration.`) } @@ -388,8 +387,9 @@ export abstract class PlatformPackager throw new Error(`Output directory "${appOutDir}" is not a directory. Seems like a wrong configuration.`) } - const mainFile = this.appInfo.metadata.main || "index.js" - await this.checkFileInPackage(this.getResourcesDir(appOutDir), mainFile, isAsar) + const resourcesDir = this.getResourcesDir(appOutDir) + await this.checkFileInPackage(resourcesDir, this.appInfo.metadata.main || "index.js", "Application entry file", isAsar) + await this.checkFileInPackage(resourcesDir, "package.json", "Application", isAsar) } protected async archiveApp(format: string, appOutDir: string, outFile: string): Promise { diff --git a/src/util/util.ts b/src/util/util.ts index a558ebce76e..ca1f6b8299b 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -204,6 +204,9 @@ export async function computeDefaultAppDirectory(projectDir: string, userAppDir: else if (!stat.isDirectory()) { throw new Error(`Application directory ${userAppDir} is not a directory`) } + else if (projectDir === absolutePath) { + warn(`Specified application directory "${userAppDir}" equals to project dir — superfluous or wrong configuration`) + } return absolutePath } @@ -238,7 +241,7 @@ let tmpDirCounter = 0 const tempDirPrefix = `${process.pid.toString(36)}-${Date.now().toString(36)}` export function getTempName(prefix?: string | n): string { - return `${prefix == null ? "" : prefix + "-"}${tempDirPrefix}-${(tmpDirCounter++).toString(36)}` + return `${prefix == null ? "" : `${prefix}-`}${tempDirPrefix}-${(tmpDirCounter++).toString(36)}` } export function isEmptyOrSpaces(s: string | n) {