diff --git a/package.json b/package.json index 861b14dab7a..43692c8bca1 100644 --- a/package.json +++ b/package.json @@ -75,13 +75,13 @@ "lodash.template": "^4.3.0", "mime": "^1.3.4", "minimatch": "^3.0.2", + "normalize-package-data": "^2.3.5", "path-sort": "^0.1.0", "plist": "^1.2.0", "pretty-ms": "^2.1.0", "progress": "^1.1.8", "progress-stream": "^1.2.0", "rcedit": "^0.5.1", - "read-package-json": "^2.0.4", "sanitize-filename": "^1.6.0", "semver": "^5.3.0", "signcode-tf": "~0.7.5", diff --git a/src/install-app-deps.ts b/src/install-app-deps.ts index ea13856f2fd..61ea9c4de97 100644 --- a/src/install-app-deps.ts +++ b/src/install-app-deps.ts @@ -1,11 +1,12 @@ #! /usr/bin/env node -import { computeDefaultAppDirectory, installDependencies, getElectronVersion, readPackageJson, use } from "./util/util" +import { computeDefaultAppDirectory, installDependencies, getElectronVersion, use } from "./util/util" import { printErrorAndExit } from "./util/promise" import * as path from "path" import { Promise as BluebirdPromise } from "bluebird" import { DevMetadata } from "./metadata" import yargs = require("yargs") +import { readPackageJson } from "./util/readPackageJson" //noinspection JSUnusedLocalSymbols const __awaiter = require("./util/awaiter") diff --git a/src/packager.ts b/src/packager.ts index bfb4d9a1534..45a224c98da 100644 --- a/src/packager.ts +++ b/src/packager.ts @@ -1,7 +1,7 @@ import * as path from "path" import { - computeDefaultAppDirectory, installDependencies, getElectronVersion, readPackageJson, use, - exec, isEmptyOrSpaces + computeDefaultAppDirectory, installDependencies, getElectronVersion, use, + exec, isEmptyOrSpaces, statOrNull } from "./util/util" import { all, executeFinally } from "./util/promise" import { EventEmitter } from "events" @@ -17,6 +17,7 @@ import { warn, log } from "./util/log" import { AppInfo } from "./appInfo" import MacPackager from "./macPackager" import { createTargets } from "./targets/targetFactory" +import { readPackageJson } from "./util/readPackageJson" //noinspection JSUnusedLocalSymbols const __awaiter = require("./util/awaiter") @@ -172,11 +173,8 @@ export class Packager implements BuildInfo { throw new Error(util.format(errorMessages.buildInAppSpecified, appPackageFile, devAppPackageFile)) } - if (this.devMetadata.homepage != null) { - warn("homepage in the development package.json is deprecated, please move to the application package.json") - } if (this.devMetadata.license != null) { - warn("license in the development package.json is deprecated, please move to the application package.json") + warn(`license in the development package.json (${devAppPackageFile}) is deprecated, please move to the application package.json`) } } @@ -207,13 +205,13 @@ export class Packager implements BuildInfo { } } - private installAppDependencies(platform: Platform, arch: Arch): Promise { + private async installAppDependencies(platform: Platform, arch: Arch): Promise { if (this.isTwoPackageJsonProjectLayoutUsed) { if (this.devMetadata.build.npmRebuild === false) { log("Skip app dependencies rebuild because npmRebuild is set to false") } else if (platform.nodeName === process.platform) { - return installDependencies(this.appDir, this.electronVersion, Arch[arch], "rebuild") + await installDependencies(this.appDir, this.electronVersion, Arch[arch], (await statOrNull(path.join(this.appDir, "node_modules"))) == null ? "install" : "rebuild") } else { log("Skip app dependencies rebuild because platform is different") @@ -222,8 +220,6 @@ export class Packager implements BuildInfo { else { log("Skip app dependencies rebuild because dev and app dependencies are not separated") } - - return BluebirdPromise.resolve() } } diff --git a/src/util/readPackageJson.ts b/src/util/readPackageJson.ts new file mode 100644 index 00000000000..371aa0bd8b2 --- /dev/null +++ b/src/util/readPackageJson.ts @@ -0,0 +1,32 @@ +import * as path from "path" +import { readJson, readFile } from "fs-extra-p" + +//noinspection JSUnusedLocalSymbols +const __awaiter = require("./awaiter") + +const normalizeData = require("normalize-package-data") + +export async function readPackageJson(file: string): Promise { + const data = await readJson(file) + await authors(file, data) + normalizeData(data) + return data +} + +async function authors(file: string, data: any) { + if (data.contributors != null) { + return + } + + let authorData: string | null = null + try { + authorData = await readFile(path.resolve(path.dirname(file), "AUTHORS"), "utf8") + } + catch (ignored) { + return + } + + data.contributors = authorData + .split(/\r?\n/g) + .map(it => it.replace(/^\s*#.*$/, "").trim()) +} \ No newline at end of file diff --git a/src/util/util.ts b/src/util/util.ts index 88c12d0a84b..dc62abc19e2 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -1,7 +1,6 @@ import { execFile, spawn as _spawn, ChildProcess, SpawnOptions } from "child_process" import { Promise as BluebirdPromise } from "bluebird" -import readPackageJsonAsync = require("read-package-json") -import * as os from "os" +import { homedir } from "os" import * as path from "path" import { readJson, stat, Stats, unlink } from "fs-extra-p" import { yellow, red } from "chalk" @@ -17,10 +16,8 @@ export const debug7z = debugFactory("electron-builder:7z") const DEFAULT_APP_DIR_NAMES = ["app", "www"] -export const readPackageJson = BluebirdPromise.promisify(readPackageJsonAsync) - export function installDependencies(appDir: string, electronVersion: string, arch: string = process.arch, command: string = "install"): BluebirdPromise { - const gypHome = path.join(os.homedir(), ".electron-gyp") + const gypHome = path.join(homedir(), ".electron-gyp") return task(`${(command === "install" ? "Installing" : "Rebuilding")} app dependencies for arch ${arch} to ${appDir}`, spawnNpmProduction(command, appDir, Object.assign({}, process.env, { npm_config_disturl: "https://atom.io/download/atom-shell", npm_config_target: electronVersion,