electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.68k stars 1.74k forks source link

Lost asyncTaskManager file in electron-builder project #2004

Closed isnolan closed 7 years ago

isnolan commented 7 years ago

electron-updater: v2.8.7

I'm upgrade the version, and catch an error:

Packaging for win32 ia32 using electron 1.7.6 to builds\VIPKID-win32-ia32\win-ia32-unpacked
Building NSIS installer
  Packaging NSIS installer for arch ia32
Error from `electron-builder` when building app...
{ Error: Cannot find module '../util/asyncTaskManager'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at _load_asyncTaskManager (C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\out\targets\nsis.js:85:32)
    at C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\out\targets\nsis.js:503:59
    at Generator.next (<anonymous>)
From previous event:
    at NsisTarget.computeFinalScript (C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\out\targets\nsis.js:574:11)
    at C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\out\targets\nsis.js:337:75
From previous event:
    at NsisTarget.computeScriptAndSignUninstaller (C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\out\targets\nsis.js:344:11)
    at C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\out\targets\nsis.js:305:194
From previous event:
    at NsisTarget.buildInstaller (C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\out\targets\nsis.js:309:11)
    at C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\out\targets\nsis.js:207:30
    at Generator.next (<anonymous>)
From previous event:
    at NsisTarget.finishBuild (C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\out\targets\nsis.js:211:11)
    at C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\src\packager.ts:267:36
From previous event:
    at Packager.doBuild (C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\out\packager.js:338:11)
    at C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\src\packager.ts:185:52
    at Generator.next (<anonymous>)
    at runCallback (timers.js:651:20)
    at tryOnImmediate (timers.js:624:5)
    at processImmediate [as _immediateCallback] (timers.js:596:5)
From previous event:
    at Packager.build (C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\out\packager.js:257:11)
    at Object.<anonymous> (C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\src\builder.ts:266:40)
    at Generator.next (<anonymous>)
From previous event:
    at Object.build (C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\out\builder.js:69:21)
    at build (C:\Users\zhangnan4\Sites\group-classroom-client\tasks\builder.js:43:11)
    at ChildProcess.pack.on.code (C:\Users\zhangnan4\Sites\group-classroom-client\tasks\builder.js:24:27)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12) code: 'MODULE_NOT_FOUND' }
develar commented 7 years ago

Please try: Remove node_modules and install again using yarn.

isnolan commented 7 years ago

Yes, I have tried, but the mistake still exists。 Node: v7.4.0 Yarn: 0.27.5, and mirror is https://registry.npm.taobao.org

develar commented 7 years ago

Please attach content of C:\Users\zhangnan4\Sites\group-classroom-client\node_modules\electron-builder\out\targets\nsis.js

develar commented 7 years ago

Please check electron-builder version in the node_modules\electron-builder\package.json — should be 19.26.2

isnolan commented 7 years ago

Thanks for your reply, and nsis.js is:

"use strict";

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.NsisTarget = undefined;

var _bluebirdLst;

function _load_bluebirdLst() {
    return _bluebirdLst = require("bluebird-lst");
}

var _bluebirdLst2;

function _load_bluebirdLst2() {
    return _bluebirdLst2 = _interopRequireDefault(require("bluebird-lst"));
}

var _zipBin;

function _load_zipBin() {
    return _zipBin = require("7zip-bin");
}

var _debug2;

function _load_debug() {
    return _debug2 = _interopRequireDefault(require("debug"));
}

var _electronBuilderUtil;

function _load_electronBuilderUtil() {
    return _electronBuilderUtil = require("electron-builder-util");
}

var _binDownload;

function _load_binDownload() {
    return _binDownload = require("electron-builder-util/out/binDownload");
}

var _fs;

function _load_fs() {
    return _fs = require("electron-builder-util/out/fs");
}

var _fsExtraP;

function _load_fsExtraP() {
    return _fsExtraP = require("fs-extra-p");
}

var _path = _interopRequireWildcard(require("path"));

var _sanitizeFilename;

function _load_sanitizeFilename() {
    return _sanitizeFilename = _interopRequireDefault(require("sanitize-filename"));
}

var _uuid;

function _load_uuid() {
    return _uuid = require("uuid-1345");
}

var _core;

function _load_core() {
    return _core = require("../core");
}

var _platformPackager;

function _load_platformPackager() {
    return _platformPackager = require("../platformPackager");
}

var _asyncTaskManager;

function _load_asyncTaskManager() {
    return _asyncTaskManager = require("../util/asyncTaskManager");
}

var _timer;

function _load_timer() {
    return _timer = require("../util/timer");
}

var _archive;

function _load_archive() {
    return _archive = require("./archive");
}

var _blockMap;

function _load_blockMap() {
    return _blockMap = require("./blockMap");
}

var _nsisLicense;

function _load_nsisLicense() {
    return _nsisLicense = require("./nsis/nsisLicense");
}

var _nsisUtil;

function _load_nsisUtil() {
    return _nsisUtil = require("./nsis/nsisUtil");
}

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const debug = (0, (_debug2 || _load_debug()).default)("electron-builder:nsis");
// noinspection SpellCheckingInspection
const ELECTRON_BUILDER_NS_UUID = "50e065bc-3134-11e6-9bab-38c9862bdaf3";
// noinspection SpellCheckingInspection
const nsisPathPromise = (0, (_binDownload || _load_binDownload()).getBinFromGithub)("nsis", "3.0.1.13", "2921dd404ce9b69679088a6f1409a56dd360da2077fe1019573c0712c9edf057");
// noinspection SpellCheckingInspection
const nsisResourcePathPromise = (0, (_binDownload || _load_binDownload()).getBinFromGithub)("nsis-resources", "3.1.0", "/QBlR/F8AAGInT/eQQ0eJNSF0RFR11g+L54WWViDYTgBHwTIlkcqBHgvNDKO6LQODtqOm9N2nG2AxK7UZT5bOg==");
const USE_NSIS_BUILT_IN_COMPRESSOR = false;
class NsisTarget extends (_core || _load_core()).Target {
    constructor(packager, outDir, targetName, packageHelper) {
        super(targetName);
        this.packager = packager;
        this.outDir = outDir;
        this.packageHelper = packageHelper;
        /** @private */
        this.archs = new Map();
        this.packageHelper.refCount++;
        this.options = targetName === "portable" ? Object.create(null) : Object.assign({}, this.packager.config.nsis);
        if (targetName !== "nsis") {
            Object.assign(this.options, this.packager.config[targetName === "nsis-web" ? "nsisWeb" : targetName]);
        }
        const deps = packager.info.metadata.dependencies;
        if (deps != null && deps["electron-squirrel-startup"] != null) {
            (0, (_electronBuilderUtil || _load_electronBuilderUtil()).warn)('"electron-squirrel-startup" dependency is not required for NSIS');
        }
    }
    build(appOutDir, arch) {
        var _this = this;

        return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
            _this.archs.set(arch, appOutDir);
        })();
    }
    /** @private */
    buildAppPackage(appOutDir, arch) {
        var _this2 = this;

        return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
            const options = _this2.options;
            const packager = _this2.packager;
            let isPackElevateHelper = options.packElevateHelper;
            if (isPackElevateHelper === false && options.perMachine === true) {
                isPackElevateHelper = true;
                (0, (_electronBuilderUtil || _load_electronBuilderUtil()).warn)("`packElevateHelper = false` is ignored, because `perMachine` is set to `true`");
            }
            if (isPackElevateHelper !== false) {
                yield (0, (_fs || _load_fs()).copyFile)(_path.join((yield nsisPathPromise), "elevate.exe"), _path.join(appOutDir, "resources", "elevate.exe"), false);
            }
            const isDifferentialPackage = options.differentialPackage;
            const format = isDifferentialPackage || options.useZip ? "zip" : "7z";
            const archiveFile = _path.join(_this2.outDir, `${packager.appInfo.name}-${packager.appInfo.version}-${(_electronBuilderUtil || _load_electronBuilderUtil()).Arch[arch]}.nsis.${format}`);
            const archiveOptions = { withoutDir: true, solid: !isDifferentialPackage };
            let compression = packager.config.compression;
            const timer = (0, (_timer || _load_timer()).time)(`nsis package, ${(_electronBuilderUtil || _load_electronBuilderUtil()).Arch[arch]}`);
            if (isDifferentialPackage) {
                // reduce dict size to avoid large block invalidation on change
                archiveOptions.dictSize = 16;
                archiveOptions.method = "LZMA";
                // do not allow to change compression level to avoid different packages
                compression = null;
            }
            yield (0, (_archive || _load_archive()).archive)(compression, format, archiveFile, appOutDir, archiveOptions);
            timer.end();
            if (options.differentialPackage) {
                const args = (0, (_electronBuilderUtil || _load_electronBuilderUtil()).debug7zArgs)("a");
                (0, (_archive || _load_archive()).addZipArgs)(args);
                args.push(`-mm=${archiveOptions.method}`, "-mx=9");
                args.push(archiveFile);
                const blockMap = yield (0, (_blockMap || _load_blockMap()).computeBlockMap)(appOutDir);
                const blockMapFile = _path.join(_this2.outDir, `${packager.appInfo.name}-${packager.appInfo.version}-${(_electronBuilderUtil || _load_electronBuilderUtil()).Arch[arch]}.blockMap.yml`);
                yield (0, (_fsExtraP || _load_fsExtraP()).writeFile)(blockMapFile, blockMap);
                yield (0, (_electronBuilderUtil || _load_electronBuilderUtil()).spawn)((_zipBin || _load_zipBin()).path7za, args.concat(blockMapFile), {
                    cwd: _this2.outDir
                });
            }
            return archiveFile;
        })();
    }
    // noinspection JSUnusedGlobalSymbols
    finishBuild() {
        var _this3 = this;

        return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
            (0, (_electronBuilderUtil || _load_electronBuilderUtil()).log)("Building NSIS installer");
            try {
                yield _this3.buildInstaller();
            } finally {
                yield _this3.packageHelper.finishBuild();
            }
        })();
    }
    get installerFilenamePattern() {
        // tslint:disable:no-invalid-template-strings
        return "${productName} " + (this.isPortable ? "" : "Setup ") + "${version}.${ext}";
    }
    get isPortable() {
        return this.name === "portable";
    }
    buildInstaller() {
        var _this4 = this;

        return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
            const isPortable = _this4.isPortable;
            const packager = _this4.packager;
            const appInfo = packager.appInfo;
            const version = appInfo.version;
            const options = _this4.options;
            const installerFilename = packager.expandArtifactNamePattern(options, "exe", null, _this4.installerFilenamePattern);
            const iconPath = (isPortable ? null : yield packager.getResource(options.installerIcon, "installerIcon.ico")) || (yield packager.getIconPath());
            const oneClick = options.oneClick !== false;
            const installerPath = _path.join(_this4.outDir, installerFilename);
            const guid = options.guid || (yield (_bluebirdLst2 || _load_bluebirdLst2()).default.promisify((_uuid || _load_uuid()).v5)({ namespace: ELECTRON_BUILDER_NS_UUID, name: appInfo.id }));
            const companyName = appInfo.companyName;
            const defines = {
                APP_ID: appInfo.id,
                APP_GUID: guid,
                PRODUCT_NAME: appInfo.productName,
                PRODUCT_FILENAME: appInfo.productFilename,
                DISPLAY_NAME :'VIPKID学习中心',
                APP_FILENAME: (!oneClick || options.perMachine === true) && /^[-_+0-9a-zA-Z ]+$/.test(appInfo.productFilename) ? appInfo.productFilename : appInfo.name,
                APP_DESCRIPTION: appInfo.description,
                VERSION: version,
                PROJECT_DIR: packager.projectDir,
                BUILD_RESOURCES_DIR: packager.buildResourcesDir
            };
            if (companyName != null) {
                defines.COMPANY_NAME = companyName;
            }
            // electron uses product file name as app data, define it as well to remove on uninstall
            if (defines.APP_FILENAME !== appInfo.productFilename) {
                defines.APP_PRODUCT_FILENAME = appInfo.productFilename;
            }
            const commands = {
                OutFile: `"${installerPath}"`,
                VIProductVersion: appInfo.versionInWeirdWindowsForm,
                VIAddVersionKey: _this4.computeVersionKey(),
                Unicode: _this4.isUnicodeEnabled
            };
            if (iconPath != null) {
                if (isPortable) {
                    commands.Icon = `"${iconPath}"`;
                } else {
                    defines.MUI_ICON = iconPath;
                    defines.MUI_UNICON = iconPath;
                }
            }
            if (_this4.archs.size === 1 && USE_NSIS_BUILT_IN_COMPRESSOR) {
                defines.APP_BUILD_DIR = _this4.archs.get(_this4.archs.keys().next().value);
            } else {
                yield (_bluebirdLst2 || _load_bluebirdLst2()).default.map(_this4.archs.keys(), (() => {
                    var _ref = (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* (arch) {
                        const file = yield _this4.packageHelper.packArch(arch, _this4);
                        defines[arch === (_electronBuilderUtil || _load_electronBuilderUtil()).Arch.x64 ? "APP_64" : "APP_32"] = file;
                        defines[(arch === (_electronBuilderUtil || _load_electronBuilderUtil()).Arch.x64 ? "APP_64" : "APP_32") + "_NAME"] = _path.basename(file);
                        if (_this4.isWebInstaller) {
                            packager.dispatchArtifactCreated(file, _this4, arch);
                        }
                    });

                    return function (_x) {
                        return _ref.apply(this, arguments);
                    };
                })());
            }
            _this4.configureDefinesForAllTypeOfInstaller(defines);
            if (isPortable) {
                defines.REQUEST_EXECUTION_LEVEL = options.requestExecutionLevel || "user";
            } else {
                yield _this4.configureDefines(oneClick, defines);
            }
            if (packager.config.compression === "store") {
                commands.SetCompress = "off";
            } else {
                commands.SetCompressor = "lzma";
                if (!_this4.isWebInstaller) {
                    defines.COMPRESS = "auto";
                }
            }
            debug(defines);
            debug(commands);
            if (packager.packagerOptions.effectiveOptionComputed != null && (yield packager.packagerOptions.effectiveOptionComputed([defines, commands]))) {
                return;
            }
            const script = isPortable ? yield (0, (_fsExtraP || _load_fsExtraP()).readFile)(_path.join((_nsisUtil || _load_nsisUtil()).nsisTemplatesDir, "portable.nsi"), "utf8") : yield _this4.computeScriptAndSignUninstaller(defines, commands, installerPath);
            yield _this4.executeMakensis(defines, commands, (yield _this4.computeFinalScript(script, true)));
            yield packager.sign(installerPath);
            packager.dispatchArtifactCreated(installerPath, _this4, _this4.archs.size === 1 ? _this4.archs.keys().next().value : null, _this4.generateGitHubInstallerName());
        })();
    }
    generateGitHubInstallerName() {
        const appInfo = this.packager.appInfo;
        const classifier = appInfo.name.toLowerCase() === appInfo.name ? "setup-" : "Setup-";
        return `${appInfo.name}-${this.isPortable ? "" : classifier}${appInfo.version}.exe`;
    }
    get isUnicodeEnabled() {
        return this.options.unicode == null ? true : this.options.unicode;
    }
    get isWebInstaller() {
        return false;
    }
    computeScriptAndSignUninstaller(defines, commands, installerPath) {
        var _this5 = this;

        return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
            const packager = _this5.packager;
            const customScriptPath = yield packager.getResource(_this5.options.script, "installer.nsi");
            const script = yield (0, (_fsExtraP || _load_fsExtraP()).readFile)(customScriptPath || _path.join((_nsisUtil || _load_nsisUtil()).nsisTemplatesDir, "installer.nsi"), "utf8");
            if (customScriptPath != null) {
                (0, (_electronBuilderUtil || _load_electronBuilderUtil()).log)("Custom NSIS script is used - uninstaller is not signed by electron-builder");
                return script;
            }
            const uninstallerPath = yield packager.getTempFile("uninstaller.exe");
            const isWin = process.platform === "win32";
            defines.BUILD_UNINSTALLER = null;
            defines.UNINSTALLER_OUT_FILE = isWin ? uninstallerPath : _path.win32.join("Z:", uninstallerPath);
            yield _this5.executeMakensis(defines, commands, (yield _this5.computeFinalScript(script, false)));
            yield (0, (_electronBuilderUtil || _load_electronBuilderUtil()).execWine)(installerPath, []);
            yield packager.sign(uninstallerPath, "  Signing NSIS uninstaller");
            delete defines.BUILD_UNINSTALLER;
            // platform-specific path, not wine
            defines.UNINSTALLER_OUT_FILE = uninstallerPath;
            return script;
        })();
    }
    computeVersionKey() {
        // Error: invalid VIProductVersion format, should be X.X.X.X
        // so, we must strip beta
        const localeId = this.options.language || "1033";
        const appInfo = this.packager.appInfo;
        const versionKey = [`/LANG=${localeId} ProductName "${appInfo.productName}"`, `/LANG=${localeId} ProductVersion "${appInfo.version}"`, `/LANG=${localeId} LegalCopyright "${appInfo.copyright}"`, `/LANG=${localeId} FileDescription "${appInfo.description}"`, `/LANG=${localeId} FileVersion "${appInfo.buildVersion}"`];
        (0, (_electronBuilderUtil || _load_electronBuilderUtil()).use)(this.packager.platformSpecificBuildOptions.legalTrademarks, it => versionKey.push(`/LANG=${localeId} LegalTrademarks "${it}"`));
        (0, (_electronBuilderUtil || _load_electronBuilderUtil()).use)(appInfo.companyName, it => versionKey.push(`/LANG=${localeId} CompanyName "${it}"`));
        return versionKey;
    }
    configureDefines(oneClick, defines) {
        var _this6 = this;

        return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
            const packager = _this6.packager;
            const options = _this6.options;
            if (oneClick) {
                defines.ONE_CLICK = null;
                if (options.runAfterFinish !== false) {
                    defines.RUN_AFTER_FINISH = null;
                }
                const installerHeaderIcon = yield packager.getResource(options.installerHeaderIcon, "installerHeaderIcon.ico");
                if (installerHeaderIcon != null) {
                    defines.HEADER_ICO = installerHeaderIcon;
                }
            } else {
                const installerHeader = yield packager.getResource(options.installerHeader, "installerHeader.bmp");
                if (installerHeader != null) {
                    defines.MUI_HEADERIMAGE = null;
                    defines.MUI_HEADERIMAGE_RIGHT = null;
                    defines.MUI_HEADERIMAGE_BITMAP = installerHeader;
                }
                const bitmap = (yield packager.getResource(options.installerSidebar, "installerSidebar.bmp")) || "${NSISDIR}\\Contrib\\Graphics\\Wizard\\nsis3-metro.bmp";
                defines.MUI_WELCOMEFINISHPAGE_BITMAP = bitmap;
                defines.MUI_UNWELCOMEFINISHPAGE_BITMAP = (yield packager.getResource(options.uninstallerSidebar, "uninstallerSidebar.bmp")) || bitmap;
                if (options.allowElevation !== false) {
                    defines.MULTIUSER_INSTALLMODE_ALLOW_ELEVATION = null;
                }
            }
            if (options.perMachine === true) {
                defines.INSTALL_MODE_PER_ALL_USERS = null;
            }
            if (!oneClick || options.perMachine === true) {
                defines.INSTALL_MODE_PER_ALL_USERS_REQUIRED = null;
            }
            if (options.allowToChangeInstallationDirectory) {
                if (oneClick) {
                    throw new Error("allowToChangeInstallationDirectory makes sense only for boring installer (please set oneClick to false)");
                }
                defines.allowToChangeInstallationDirectory = null;
            }
            if (options.menuCategory != null && options.menuCategory !== false) {
                let menu;
                if (options.menuCategory === true) {
                    const companyName = packager.appInfo.companyName;
                    if (companyName == null) {
                        throw new Error(`Please specify "author" in the application package.json — it is required because "menuCategory" is set to true.`);
                    }
                    menu = (0, (_sanitizeFilename || _load_sanitizeFilename()).default)(companyName);
                } else {
                    menu = options.menuCategory.split(/[\/\\]/).map(function (it) {
                        return (0, (_sanitizeFilename || _load_sanitizeFilename()).default)(it);
                    }).join("\\");
                }
                if (!(0, (_electronBuilderUtil || _load_electronBuilderUtil()).isEmptyOrSpaces)(menu)) {
                    defines.MENU_FILENAME = menu;
                }
            }
            if (options.multiLanguageInstaller == null ? _this6.isUnicodeEnabled : options.multiLanguageInstaller) {
                defines.MULTI_LANGUAGE_INSTALLER = null;
            }
            if (options.deleteAppDataOnUninstall) {
                defines.DELETE_APP_DATA_ON_UNINSTALL = null;
            }
            const uninstallerIcon = yield packager.getResource(options.uninstallerIcon, "uninstallerIcon.ico");
            if (uninstallerIcon != null) {
                // we don't need to copy MUI_UNICON (defaults to app icon), so, we have 2 defines
                defines.UNINSTALLER_ICON = uninstallerIcon;
                defines.MUI_UNICON = uninstallerIcon;
            }
            defines.UNINSTALL_DISPLAY_NAME = packager.expandMacro(options.uninstallDisplayName || "${productName} ${version}", null, {}, false);
            if (options.createDesktopShortcut === false) {
                defines.DO_NOT_CREATE_DESKTOP_SHORTCUT = null;
            }
        })();
    }
    configureDefinesForAllTypeOfInstaller(defines) {
        const options = this.options;
        if (!this.isWebInstaller && defines.APP_BUILD_DIR == null) {
            if (options.useZip) {
                defines.ZIP_COMPRESSION = null;
            }
            defines.COMPRESSION_METHOD = options.useZip ? "zip" : "7z";
        }
    }
    executeMakensis(defines, commands, script) {
        var _this7 = this;

        return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
            const args = _this7.options.warningsAsErrors === false ? [] : ["-WX"];
            for (const name of Object.keys(defines)) {
                const value = defines[name];
                if (value == null) {
                    args.push(`-D${name}`);
                } else {
                    args.push(`-D${name}=${value}`);
                }
            }
            for (const name of Object.keys(commands)) {
                const value = commands[name];
                if (Array.isArray(value)) {
                    for (const c of value) {
                        args.push(`-X${name} ${c}`);
                    }
                } else {
                    args.push(`-X${name} ${value}`);
                }
            }
            args.push("-");
            if (debug.enabled) {
                process.stdout.write("\n\nNSIS script:\n\n" + script + "\n\n---\nEnd of NSIS script.\n\n");
            }
            const nsisPath = yield nsisPathPromise;
            yield new (_bluebirdLst2 || _load_bluebirdLst2()).default(function (resolve, reject) {
                const command = _path.join(nsisPath, process.platform === "darwin" ? "mac" : process.platform === "win32" ? "Bin" : "linux", process.platform === "win32" ? "makensis.exe" : "makensis");
                const childProcess = (0, (_electronBuilderUtil || _load_electronBuilderUtil()).doSpawn)(command, args, {
                    // we use NSIS_CONFIG_CONST_DATA_PATH=no to build makensis on Linux, but in any case it doesn't use stubs as MacOS/Windows version, so, we explicitly set NSISDIR
                    // set LC_CTYPE to avoid crash https://github.com/electron-userland/electron-builder/issues/503 Even "en_DE.UTF-8" leads to error.
                    env: Object.assign({}, process.env, { NSISDIR: nsisPath, LC_CTYPE: "en_US.UTF-8", LANG: "en_US.UTF-8" }),
                    cwd: (_nsisUtil || _load_nsisUtil()).nsisTemplatesDir
                }, { isPipeInput: true, isDebugEnabled: debug.enabled });
                const timeout = setTimeout(function () {
                    return childProcess.kill();
                }, 4 * 60 * 1000);
                (0, (_electronBuilderUtil || _load_electronBuilderUtil()).handleProcess)("close", childProcess, command, function () {
                    try {
                        clearTimeout(timeout);
                    } finally {
                        resolve();
                    }
                }, function (error) {
                    try {
                        clearTimeout(timeout);
                    } finally {
                        reject(error + "\nNSIS script:\n" + script);
                    }
                });
                childProcess.stdin.end(script);
            });
        })();
    }
    computeFinalScript(originalScript, isInstaller) {
        var _this8 = this;

        return (0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
            const packager = _this8.packager;
            let scriptHeader = `!addincludedir "${_path.join(__dirname, "..", "..", "templates", "nsis", "include")}"\n`;
            const taskManager = new (_asyncTaskManager || _load_asyncTaskManager()).AsyncTaskManager(packager.info.cancellationToken);
            taskManager.add((0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
                const pluginArch = _this8.isUnicodeEnabled ? "x86-unicode" : "x86-ansi";
                let result = `!addplugindir /${pluginArch} "${_path.join((yield nsisResourcePathPromise), "plugins", pluginArch)}"\n`;
                result += `!addplugindir /${pluginArch} "${_path.join(packager.buildResourcesDir, pluginArch)}"\n`;
                return result;
            }));
            taskManager.add((0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
                // http://stackoverflow.com/questions/997456/nsis-license-file-based-on-language-selection
                const licensePage = yield (0, (_nsisLicense || _load_nsisLicense()).computeLicensePage)(packager, _this8.options);
                return licensePage || "";
            }));
            const isMultiLang = _this8.isUnicodeEnabled && _this8.options.multiLanguageInstaller !== false;
            taskManager.addTask((0, (_nsisUtil || _load_nsisUtil()).addCustomMessageFileInclude)("messages.yml", packager, isMultiLang));
            if (!_this8.isPortable) {
                if (_this8.isUnicodeEnabled && _this8.options.oneClick === false) {
                    taskManager.addTask((0, (_nsisUtil || _load_nsisUtil()).addCustomMessageFileInclude)("boringMessages.yml", packager, isMultiLang));
                }
                taskManager.add((0, (_bluebirdLst || _load_bluebirdLst()).coroutine)(function* () {
                    let result = "";
                    const customInclude = yield packager.getResource(_this8.options.include, "installer.nsh");
                    if (customInclude != null) {
                        result += `!addincludedir "${packager.buildResourcesDir}"\n`;
                        result += `!include "${customInclude}"\n\n`;
                    }
                    return result;
                }));
            }
            for (const s of yield taskManager.awaitTasks()) {
                scriptHeader += s;
            }
            if (_this8.isPortable) {
                return scriptHeader + originalScript;
            }
            const fileAssociations = packager.fileAssociations;
            if (fileAssociations.length !== 0) {
                if (_this8.options.perMachine !== true) {
                    // https://github.com/electron-userland/electron-builder/issues/772
                    throw new Error(`Please set perMachine to true — file associations works on Windows only if installed for all users`);
                }
                scriptHeader += "!include FileAssociation.nsh\n";
                if (isInstaller) {
                    let registerFileAssociationsScript = "";
                    for (const item of fileAssociations) {
                        const extensions = (0, (_electronBuilderUtil || _load_electronBuilderUtil()).asArray)(item.ext).map((_platformPackager || _load_platformPackager()).normalizeExt);
                        for (const ext of extensions) {
                            const customIcon = yield packager.getResource((0, (_electronBuilderUtil || _load_electronBuilderUtil()).getPlatformIconFileName)(item.icon, false), `${extensions[0]}.ico`);
                            let installedIconPath = "$appExe,0";
                            if (customIcon != null) {
                                installedIconPath = `$INSTDIR\\resources\\${_path.basename(customIcon)}`;
                                //noinspection SpellCheckingInspection
                                registerFileAssociationsScript += `  File "/oname=${installedIconPath}" "${customIcon}"\n`;
                            }
                            const icon = `"${installedIconPath}"`;
                            const commandText = `"Open with ${packager.appInfo.productName}"`;
                            const command = '"$appExe $\\"%1$\\""';
                            registerFileAssociationsScript += `  !insertmacro APP_ASSOCIATE "${ext}" "${item.name || ext}" "${item.description || ""}" ${icon} ${commandText} ${command}\n`;
                        }
                    }
                    scriptHeader += `!macro registerFileAssociations\n${registerFileAssociationsScript}!macroend\n`;
                } else {
                    let unregisterFileAssociationsScript = "";
                    for (const item of fileAssociations) {
                        for (const ext of (0, (_electronBuilderUtil || _load_electronBuilderUtil()).asArray)(item.ext)) {
                            unregisterFileAssociationsScript += `  !insertmacro APP_UNASSOCIATE "${(0, (_platformPackager || _load_platformPackager()).normalizeExt)(ext)}" "${item.name || ext}"\n`;
                        }
                    }
                    scriptHeader += `!macro unregisterFileAssociations\n${unregisterFileAssociationsScript}!macroend\n`;
                }
            }
            return scriptHeader + originalScript;
        })();
    }
}
exports.NsisTarget = NsisTarget; //# sourceMappingURL=nsis.js.map
isnolan commented 7 years ago

yes, it is v19.26.2

develar commented 7 years ago

File node_modules\electron-builder\out\targets\nsis.js doesn't exist anymore and if you will download module directly from npm (https://registry.npmjs.org/electron-builder/-/electron-builder-19.26.2.tgz), you can check that package is correct.

I have downloaded https://cdn.npm.taobao.org/electron-builder/-/electron-builder-19.26.2.tgz and it is also correct.

So, please

  1. remove node_modules
  2. yarn cache clean
  3. yarn
isnolan commented 7 years ago

And, I'm sure the downloaded package is not nsis.js, but it was automatically generated when it was packaged, but this error still exists.

develar commented 7 years ago

Please try 19.26.3

isnolan commented 7 years ago

Thank you for your reply. Perhaps this is our project's problem. One of our colleagues made a custom nsis.js and copied the document in the process of packaging.

develar commented 7 years ago

Just send a PR and it will be applied in a day. No need to use such hacks.

isnolan commented 7 years ago

Yes, you'r right