diff --git a/.travis.yml b/.travis.yml index 16fdca4c80d..8e1459bf16d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,23 +4,23 @@ language: node_js matrix: include: - os: osx - #env: TEST_FILES=BuildTest,extraMetadataTest,globTest,filesTest,ignoreTest,linux.*,windows.* - env: TEST_FILES=oneClickInstallerTest.* + env: TEST_FILES=BuildTest,extraMetadataTest,globTest,filesTest,ignoreTest,linux.*,windows.* +# env: TEST_FILES=oneClickInstallerTest.* node_js: "8" -# - os: osx -# env: TEST_FILES=mac.* -# node_js: "8" + - os: osx + env: TEST_FILES=mac.* + node_js: "8" -# - os: osx -# env: TEST_FILES=mac.* NODE_VERSION=6 + - os: osx + env: TEST_FILES=mac.* + node_js: "6" cache: yarn: true directories: - node_modules - $HOME/Library/Caches/electron - - $HOME/Library/Caches/electron-builder - /tmp/jest-electron-builder-tests install: diff --git a/README.md b/README.md index e3d8094bd59..e332f150edc 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ _Note: Platform specific `7zip-bin-*` packages are `optionalDependencies`, which ``` Then you can run `npm run dist` (to package in a distributable format (e.g. dmg, windows installer, deb package)) or `npm run pack` (only generates the package directory without really packaging it. This is useful for testing purposes). - To ensure your native dependencies are always matched electron version, simply add `"postinstall": "install-app-deps"` to your `package.json`. + To ensure your native dependencies are always matched electron version, simply add script `"postinstall": "electron-builder install-app-deps"` to your `package.json`. 5. If you have native addons of your own that are part of the application (not as a dependency), add `"nodeGypRebuild": true` to the `build` section of your development `package.json`. :bulb: Don't [use](https://github.com/electron-userland/electron-builder/issues/683#issuecomment-241214075) [npm](http://electron.atom.io/docs/tutorial/using-native-node-modules/#using-npm) (neither `.npmrc`) for configuring electron headers. Use [node-gyp-rebuild](https://github.com/electron-userland/electron-builder/issues/683#issuecomment-241488783) bin instead. diff --git a/packages/electron-builder-util/src/util.ts b/packages/electron-builder-util/src/util.ts index 6ec5a7a0e49..70ba8dd5f3a 100644 --- a/packages/electron-builder-util/src/util.ts +++ b/packages/electron-builder-util/src/util.ts @@ -10,7 +10,7 @@ import { statOrNull } from "./fs" import { log, warn } from "./log" export { TmpDir } from "./tmp" -export { log, warn, task } from "./log" +export { log, warn, task, subTask } from "./log" export const debug = _debug("electron-builder") export const debug7z = _debug("electron-builder:7z") diff --git a/packages/electron-builder/src/cli/cli.ts b/packages/electron-builder/src/cli/cli.ts index e3f9dc1aed5..373242df14d 100644 --- a/packages/electron-builder/src/cli/cli.ts +++ b/packages/electron-builder/src/cli/cli.ts @@ -9,7 +9,7 @@ import * as path from "path" import updateNotifier from "update-notifier" import yargs from "yargs" import { build, configureBuildCommand } from "../builder" -import { getElectronVersion, loadConfig } from "../util/config" +import { getConfig, getElectronVersion } from "../util/config" import { getGypEnv } from "../util/yarn" import { createSelfSignedCert } from "./create-self-signed-cert" import { configureInstallAppDepsCommand, installAppDeps } from "./install-app-deps" @@ -64,7 +64,7 @@ function checkIsOutdated() { async function rebuildAppNativeCode(args: any) { const projectDir = process.cwd() - const config = await loadConfig(projectDir) + const config = await getConfig(projectDir, null, null, null) log(`Execute node-gyp rebuild for ${args.platform}:${args.arch}`) // this script must be used only for electron await exec(process.platform === "win32" ? "node-gyp.cmd" : "node-gyp", ["rebuild"], { diff --git a/packages/electron-builder/src/cli/install-app-deps.ts b/packages/electron-builder/src/cli/install-app-deps.ts index 61ec988cc03..e31eb04580e 100644 --- a/packages/electron-builder/src/cli/install-app-deps.ts +++ b/packages/electron-builder/src/cli/install-app-deps.ts @@ -4,7 +4,7 @@ import BluebirdPromise from "bluebird-lst" import { computeDefaultAppDirectory, log, use, warn } from "electron-builder-util" import { printErrorAndExit } from "electron-builder-util/out/promise" import yargs from "yargs" -import { getElectronVersion, loadConfig } from "../util/config" +import { getConfig, getElectronVersion } from "../util/config" import { installOrRebuild } from "../util/yarn" declare const PACKAGE_VERSION: string @@ -39,7 +39,7 @@ export async function installAppDeps(args: any) { } const projectDir = process.cwd() - const config = (await loadConfig(projectDir)) || {} + const config = (await getConfig(projectDir, null, null, null)) || {} const muonVersion = config.muonVersion const results = await BluebirdPromise.all([ computeDefaultAppDirectory(projectDir, use(config.directories, it => it!.app)), diff --git a/packages/electron-builder/src/packager.ts b/packages/electron-builder/src/packager.ts index 539a950efda..b8d0ac4cd3d 100644 --- a/packages/electron-builder/src/packager.ts +++ b/packages/electron-builder/src/packager.ts @@ -14,7 +14,7 @@ import { AfterPackContext, Config, Metadata } from "./metadata" import { ArtifactCreated, BuildInfo, PackagerOptions } from "./packagerApi" import { PlatformPackager } from "./platformPackager" import { computeArchToTargetNamesMap, createTargets, NoOpTarget } from "./targets/targetFactory" -import { computeFinalConfig, getElectronVersion, validateConfig } from "./util/config" +import { getConfig, getElectronVersion, validateConfig } from "./util/config" import { checkMetadata, readPackageJson } from "./util/packageMetadata" import { getRepositoryInfo } from "./util/repositoryInfo" import { getGypEnv, installOrRebuild } from "./util/yarn" @@ -122,7 +122,7 @@ export class Packager implements BuildInfo { this.devMetadata = await orNullIfFileNotExist(readPackageJson(devPackageFile)) const devMetadata = this.devMetadata - const config = await computeFinalConfig(projectDir, configPath, devMetadata, configFromOptions) + const config = await getConfig(projectDir, configPath, devMetadata, configFromOptions) if (debug.enabled) { debug(`Effective config: ${safeStringifyJson(config)}`) } diff --git a/packages/electron-builder/src/targets/ArchiveTarget.ts b/packages/electron-builder/src/targets/ArchiveTarget.ts index eef72f3947c..a7476d3603e 100644 --- a/packages/electron-builder/src/targets/ArchiveTarget.ts +++ b/packages/electron-builder/src/targets/ArchiveTarget.ts @@ -1,4 +1,4 @@ -import { log } from "electron-builder-util/out/log" +import { log } from "electron-builder-util" import * as path from "path" import { Arch, Platform, Target } from "../core" import { PlatformPackager } from "../platformPackager" diff --git a/packages/electron-builder/src/targets/dmg.ts b/packages/electron-builder/src/targets/dmg.ts index f422e1c1120..643f81829bd 100644 --- a/packages/electron-builder/src/targets/dmg.ts +++ b/packages/electron-builder/src/targets/dmg.ts @@ -1,8 +1,7 @@ import BluebirdPromise from "bluebird-lst" -import { debug, exec, isEmptyOrSpaces, spawn } from "electron-builder-util" +import { debug, exec, isEmptyOrSpaces, log, spawn, warn } from "electron-builder-util" import { deepAssign } from "electron-builder-util/out/deepAssign" import { copyFile, exists, statOrNull } from "electron-builder-util/out/fs" -import { log, warn } from "electron-builder-util/out/log" import { executeFinally } from "electron-builder-util/out/promise" import { outputFile, readFile, remove, unlink } from "fs-extra-p" import * as path from "path" diff --git a/packages/electron-builder/src/targets/fpm.ts b/packages/electron-builder/src/targets/fpm.ts index 70004c0ed84..8b0dd40f236 100644 --- a/packages/electron-builder/src/targets/fpm.ts +++ b/packages/electron-builder/src/targets/fpm.ts @@ -1,8 +1,7 @@ import BluebirdPromise from "bluebird-lst" -import { debug, exec, smarten, TmpDir, use } from "electron-builder-util" +import { debug, exec, log, smarten, TmpDir, use, warn } from "electron-builder-util" import { getBin } from "electron-builder-util/out/binDownload" import { unlinkIfExists } from "electron-builder-util/out/fs" -import { log, warn } from "electron-builder-util/out/log" import { ensureDir, outputFile, readFile } from "fs-extra-p" import * as path from "path" import { Arch, Target, toLinuxArchString } from "../core" diff --git a/packages/electron-builder/src/targets/nsis.ts b/packages/electron-builder/src/targets/nsis.ts index d91d3af36a1..40a374f515e 100644 --- a/packages/electron-builder/src/targets/nsis.ts +++ b/packages/electron-builder/src/targets/nsis.ts @@ -1,9 +1,8 @@ import BluebirdPromise from "bluebird-lst" import _debug from "debug" -import { asArray, debug, doSpawn, getPlatformIconFileName, handleProcess, isEmptyOrSpaces, use } from "electron-builder-util" +import { asArray, debug, doSpawn, getPlatformIconFileName, handleProcess, isEmptyOrSpaces, log, subTask, use, warn } from "electron-builder-util" import { getBinFromGithub } from "electron-builder-util/out/binDownload" import { copyFile } from "electron-builder-util/out/fs" -import { log, subTask, warn } from "electron-builder-util/out/log" import { asyncAll } from "electron-builder-util/out/promise" import { outputFile, readFile, unlink } from "fs-extra-p" import { safeLoad } from "js-yaml" diff --git a/packages/electron-builder/src/targets/snap.ts b/packages/electron-builder/src/targets/snap.ts index 52b9cbdde86..6d5d83262b5 100644 --- a/packages/electron-builder/src/targets/snap.ts +++ b/packages/electron-builder/src/targets/snap.ts @@ -1,6 +1,5 @@ -import { replaceDefault, spawn } from "electron-builder-util" +import { log, replaceDefault, spawn } from "electron-builder-util" import { copyFile } from "electron-builder-util/out/fs" -import { log } from "electron-builder-util/out/log" import { emptyDir, outputFile } from "fs-extra-p" import { safeDump } from "js-yaml" import { homedir } from "os" diff --git a/packages/electron-builder/src/util/asarUtil.ts b/packages/electron-builder/src/util/asarUtil.ts index 06a5d6c9c8a..f5def512b55 100644 --- a/packages/electron-builder/src/util/asarUtil.ts +++ b/packages/electron-builder/src/util/asarUtil.ts @@ -1,7 +1,6 @@ import BluebirdPromise from "bluebird-lst" -import { debug } from "electron-builder-util" +import { debug, log } from "electron-builder-util" import { CONCURRENCY, FileCopier, FileTransformer, Filter, MAX_FILE_REQUESTS, statOrNull, walk } from "electron-builder-util/out/fs" -import { log } from "electron-builder-util/out/log" import { createReadStream, createWriteStream, ensureDir, readFile, readlink, stat, Stats, writeFile } from "fs-extra-p" import * as path from "path" import { AsarFilesystem, Node, readAsar } from "../asar" diff --git a/packages/electron-builder/src/util/config.ts b/packages/electron-builder/src/util/config.ts index 4da037642c2..3be52f41fc0 100644 --- a/packages/electron-builder/src/util/config.ts +++ b/packages/electron-builder/src/util/config.ts @@ -1,9 +1,7 @@ import Ajv from "ajv" import { CancellationToken } from "electron-builder-http" -import { debug } from "electron-builder-util" +import { debug, log, warn } from "electron-builder-util" import { deepAssign } from "electron-builder-util/out/deepAssign" -import { statOrNull } from "electron-builder-util/out/fs" -import { log, warn } from "electron-builder-util/out/log" import { httpExecutor } from "electron-builder-util/out/nodeHttpExecutor" import { orNullIfFileNotExist } from "electron-builder-util/out/promise" import { readFile, readJson } from "fs-extra-p" @@ -16,12 +14,11 @@ import AdditionalPropertiesParams = ajv.AdditionalPropertiesParams import ErrorObject = ajv.ErrorObject import TypeParams = ajv.TypeParams -function getConfigFromPackageData(metadata: any) { - return metadata.build +function getConfigFromPackageData(metadata: any | null) { + return metadata == null ? null : metadata.build } -/** @internal */ -export async function doLoadConfig(configFile: string, projectDir: string): Promise { +async function doLoadConfig(configFile: string, projectDir: string): Promise { const data = await readFile(configFile, "utf8") let result if (configFile.endsWith(".json5") || configFile.endsWith(".json")) { @@ -39,30 +36,24 @@ export async function doLoadConfig(configFile: string, projectDir: string): Prom return result } -/** @internal */ -export async function loadConfig(projectDir: string, packageMetadata?: any): Promise { - for (const configFile of ["electron-builder.yml", "electron-builder.yaml", "electron-builder.json", "electron-builder.json5", "electron-builder.toml"]) { - const data = await orNullIfFileNotExist(doLoadConfig(path.join(projectDir, configFile), projectDir)) - if (data != null) { - return data - } - } - - const data = getConfigFromPackageData(packageMetadata || (await orNullIfFileNotExist(readJson(path.join(projectDir, "package.json"))))) +async function loadConfig(projectDir: string, packageMetadata?: any): Promise { + let data = getConfigFromPackageData(packageMetadata || (await orNullIfFileNotExist(readJson(path.join(projectDir, "package.json"))))) if (data != null) { return data } - if ((await statOrNull(path.join(projectDir, "app.asar"))) != null) { - // prepacked, do not throw error, just ignore - return null + for (const configFile of ["electron-builder.yml", "electron-builder.yaml", "electron-builder.json", "electron-builder.json5", "electron-builder.toml"]) { + data = await orNullIfFileNotExist(doLoadConfig(path.join(projectDir, configFile), projectDir)) + if (data != null) { + return data + } } - throw new Error(`Cannot find package.json in the ${projectDir}`) + return null } /** @internal */ -export async function computeFinalConfig(projectDir: string, configPath: string | null, packageMetadata: any | null, configFromOptions: Config | null | undefined): Promise { +export async function getConfig(projectDir: string, configPath: string | null, packageMetadata: any | null, configFromOptions: Config | null | undefined): Promise { let fileOrPackageConfig if (configPath == null) { fileOrPackageConfig = packageMetadata == null ? null : await loadConfig(projectDir, packageMetadata) diff --git a/packages/electron-builder/src/util/packageMetadata.ts b/packages/electron-builder/src/util/packageMetadata.ts index 1c42dd9de47..3119418286c 100644 --- a/packages/electron-builder/src/util/packageMetadata.ts +++ b/packages/electron-builder/src/util/packageMetadata.ts @@ -71,7 +71,7 @@ export function checkMetadata(metadata: Metadata, devMetadata: any | null, appPa const devDependencies = (metadata).devDependencies if (devDependencies != null && "electron-rebuild" in devDependencies) { - log("electron-rebuild not required if you use electron-builder, please consider to remove excess dependency from devDependencies") + log('electron-rebuild not required if you use electron-builder, please consider to remove excess dependency from devDependencies\n\nTo ensure your native dependencies are always matched electron version, simply add script `"postinstall": "electron-builder install-app-deps" to your `package.json`') } if (errors.length > 0) { diff --git a/packages/electron-builder/src/util/yarn.ts b/packages/electron-builder/src/util/yarn.ts index 0b85fda88bf..a67696d3f39 100644 --- a/packages/electron-builder/src/util/yarn.ts +++ b/packages/electron-builder/src/util/yarn.ts @@ -1,7 +1,6 @@ import BluebirdPromise from "bluebird-lst" -import { asArray, spawn } from "electron-builder-util" +import { asArray, log, spawn, warn } from "electron-builder-util" import { exists } from "electron-builder-util/out/fs" -import { log, warn } from "electron-builder-util/out/log" import { homedir } from "os" import * as path from "path" import { Config } from "../metadata" diff --git a/packages/electron-publish/src/BintrayPublisher.ts b/packages/electron-publish/src/BintrayPublisher.ts index c9279c4d3ff..f2d296f2b28 100644 --- a/packages/electron-publish/src/BintrayPublisher.ts +++ b/packages/electron-publish/src/BintrayPublisher.ts @@ -2,8 +2,7 @@ import BluebirdPromise from "bluebird-lst" import { configureRequestOptions, HttpError } from "electron-builder-http" import { BintrayClient, Version } from "electron-builder-http/out/bintray" import { BintrayOptions } from "electron-builder-http/out/publishOptions" -import { debug, isEmptyOrSpaces } from "electron-builder-util" -import { log } from "electron-builder-util/out/log" +import { debug, isEmptyOrSpaces, log } from "electron-builder-util" import { httpExecutor } from "electron-builder-util/out/nodeHttpExecutor" import { ClientRequest } from "http" import { HttpPublisher, PublishContext, PublishOptions } from "./publisher" diff --git a/packages/electron-publish/src/gitHubPublisher.ts b/packages/electron-publish/src/gitHubPublisher.ts index 56193f15982..843e990e295 100644 --- a/packages/electron-publish/src/gitHubPublisher.ts +++ b/packages/electron-publish/src/gitHubPublisher.ts @@ -1,8 +1,7 @@ import BluebirdPromise from "bluebird-lst" import { configureRequestOptions, HttpError } from "electron-builder-http" import { GithubOptions } from "electron-builder-http/out/publishOptions" -import { debug, isEmptyOrSpaces } from "electron-builder-util" -import { log, warn } from "electron-builder-util/out/log" +import { debug, isEmptyOrSpaces, log, warn } from "electron-builder-util" import { httpExecutor } from "electron-builder-util/out/nodeHttpExecutor" import { ClientRequest } from "http" import mime from "mime" diff --git a/packages/electron-publish/src/publisher.ts b/packages/electron-publish/src/publisher.ts index 348e50ee806..9aa50bd62d8 100644 --- a/packages/electron-publish/src/publisher.ts +++ b/packages/electron-publish/src/publisher.ts @@ -1,6 +1,6 @@ import { green } from "chalk" import { CancellationToken, ProgressCallbackTransform } from "electron-builder-http" -import { log } from "electron-builder-util/out/log" +import { log } from "electron-builder-util" import { createReadStream, stat, Stats } from "fs-extra-p" import { ClientRequest } from "http" import { basename } from "path" diff --git a/test/out/mac/__snapshots__/macArchiveTest.js.snap b/test/out/mac/__snapshots__/macArchiveTest.js.snap index c9b688b13c9..6bba889a0ee 100644 --- a/test/out/mac/__snapshots__/macArchiveTest.js.snap +++ b/test/out/mac/__snapshots__/macArchiveTest.js.snap @@ -420,7 +420,6 @@ Object { "versStr": "1.1.0", }, Object { - "customLocation": "/Applications", "id": "org.electron-builder.testApp", "pkg-ref": Object { "id": "org.electron-builder.testApp", diff --git a/test/src/helpers/packTester.ts b/test/src/helpers/packTester.ts index 048105eccc9..4e478fab260 100644 --- a/test/src/helpers/packTester.ts +++ b/test/src/helpers/packTester.ts @@ -3,9 +3,8 @@ import DecompressZip from "decompress-zip" import { Arch, ArtifactCreated, DIR_TARGET, getArchSuffix, MacOsTargetName, Packager, PackagerOptions, Platform, Target } from "electron-builder" import { CancellationToken } from "electron-builder-http" import { convertVersion } from "electron-builder-squirrel-windows/out/squirrelPack" -import { addValue, exec, getTempName, spawn } from "electron-builder-util" +import { addValue, exec, getTempName, log, spawn, warn } from "electron-builder-util" import { copyDir, FileCopier } from "electron-builder-util/out/fs" -import { log, warn } from "electron-builder-util/out/log" import { PublishManager } from "electron-builder/out/publish/PublishManager" import { computeArchToTargetNamesMap } from "electron-builder/out/targets/targetFactory" import { getLinuxToolsPath } from "electron-builder/out/util/bundledTool"