From c57c52a53867e3351a80f3ea49a3d7fdee395cc4 Mon Sep 17 00:00:00 2001 From: develar Date: Tue, 6 Feb 2018 09:15:47 +0100 Subject: [PATCH] fix: Cannot find module 'electron-download-tf' Close #2550 --- packages/electron-builder-lib/src/index.ts | 16 ++-------------- packages/electron-builder/src/builder.ts | 15 +++++++++++++-- test/src/helpers/checkDeps.ts | 4 ++-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/packages/electron-builder-lib/src/index.ts b/packages/electron-builder-lib/src/index.ts index 8f59037c133..4dfa30a556f 100644 --- a/packages/electron-builder-lib/src/index.ts +++ b/packages/electron-builder-lib/src/index.ts @@ -1,10 +1,8 @@ -import { CancellationToken } from "builder-util-runtime" import { executeFinally } from "builder-util/out/promise" import { PublishOptions } from "electron-publish/out/publisher" import { log } from "builder-util" import { Packager } from "./packager" import { PackagerOptions } from "./packagerApi" -import BluebirdPromise from "bluebird-lst" import { PublishManager } from "./publish/PublishManager" export { Packager, BuildResult } from "./packager" @@ -32,17 +30,7 @@ export { PublishManager } from "./publish/PublishManager" export { PlatformPackager } from "./platformPackager" export { buildForge, ForgeOptions } from "./forge-maker" -export async function build(options: PackagerOptions & PublishOptions, cancellationToken: CancellationToken = new CancellationToken()): Promise> { - const packager = new Packager(options, cancellationToken) - - let electronDownloader: any = null - packager.electronDownloader = options => { - if (electronDownloader == null) { - electronDownloader = BluebirdPromise.promisify(require("electron-download-tf")) - } - return electronDownloader(options) - } - +export async function build(options: PackagerOptions & PublishOptions, packager: Packager = new Packager(options)): Promise> { // because artifact event maybe dispatched several times for different publish providers const artifactPaths = new Set() packager.artifactCreated(event => { @@ -54,7 +42,7 @@ export async function build(options: PackagerOptions & PublishOptions, cancellat const publishManager = new PublishManager(packager, options) const sigIntHandler = () => { log.warn("cancelled by SIGINT") - cancellationToken.cancel() + packager.cancellationToken.cancel() publishManager.cancelTasks() } process.once("SIGINT", sigIntHandler) diff --git a/packages/electron-builder/src/builder.ts b/packages/electron-builder/src/builder.ts index 45bd119a692..b5105f674ea 100644 --- a/packages/electron-builder/src/builder.ts +++ b/packages/electron-builder/src/builder.ts @@ -1,7 +1,8 @@ import { addValue, Arch, archFromString, InvalidConfigurationError, log, deepAssign } from "builder-util" import chalk from "chalk" -import { build as _build, Configuration, DIR_TARGET, PackagerOptions, Platform } from "electron-builder-lib" +import { Packager, build as _build, Configuration, DIR_TARGET, PackagerOptions, Platform } from "electron-builder-lib" import { PublishOptions } from "electron-publish" +import BluebirdPromise from "bluebird-lst" /** @internal */ export interface BuildOptions extends PackagerOptions, PublishOptions { @@ -214,7 +215,17 @@ export function createTargets(platforms: Array, type?: string | null, } export function build(rawOptions?: CliOptions): Promise> { - return _build(normalizeOptions(rawOptions || {})) + const buildOptions = normalizeOptions(rawOptions || {}) + const packager = new Packager(buildOptions) + + let electronDownloader: any = null + packager.electronDownloader = options => { + if (electronDownloader == null) { + electronDownloader = BluebirdPromise.promisify(require("electron-download-tf")) + } + return electronDownloader(options) + } + return _build(buildOptions, packager) } /** diff --git a/test/src/helpers/checkDeps.ts b/test/src/helpers/checkDeps.ts index a2f4043bdd3..4120d11c23e 100644 --- a/test/src/helpers/checkDeps.ts +++ b/test/src/helpers/checkDeps.ts @@ -49,8 +49,8 @@ async function check(projectDir: string, devPackageData: any): Promise } for (const name of Object.keys(result.missing)) { - if (name === "electron-builder-squirrel-windows" || name === "electron-webpack" || name === "electron-download-tf" || - (packageName === "electron-builder-lib" && name === "dmg-builder")) { + if (name === "electron-builder-squirrel-windows" || name === "electron-webpack" || + (packageName === "electron-builder-lib" && (name === "dmg-builder" || name === "electron-download-tf"))) { delete (result.missing as any)[name] } }