From 39e678333a7f2f79e6cbd840167adee1179b64db Mon Sep 17 00:00:00 2001 From: develar Date: Tue, 30 Jul 2019 09:07:31 +0200 Subject: [PATCH] fix(nsis): improve Windows installer task kill process (related to child processes) Close #2894 --- package.json | 6 +-- packages/app-builder-lib/package.json | 2 +- .../src/targets/nsis/NsisTarget.ts | 14 +++++-- .../include/allowOnlyOneInstallerInstance.nsh | 11 ++--- packages/dmg-builder/package.json | 2 +- .../package.json | 2 +- packages/electron-builder/package.json | 2 +- .../oneClickInstallerTest.js.snap | 2 +- test/src/windows/oneClickInstallerTest.ts | 6 +-- yarn.lock | 42 +++++++++---------- 10 files changed, 46 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index b2a0be04484..9a3e487e4b5 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "normalize-package-data": "^2.5.0", "pako": "^1.0.10", "read-config-file": "5.0.0", - "sanitize-filename": "^1.6.1", + "sanitize-filename": "^1.6.2", "sax": "^1.2.4", "semver": "^6.3.0", "source-map-support": "^0.5.12", @@ -91,7 +91,7 @@ "@types/ejs": "^2.6.3", "@types/fs-extra": "^8.0.0", "@types/ini": "^1.3.30", - "@types/jest": "^24.0.15", + "@types/jest": "^24.0.16", "@types/js-yaml": "^3.12.1", "@types/lodash.isequal": "^4.5.5", "@types/node-emoji": "^1.8.1", @@ -99,7 +99,7 @@ "@types/sax": "^1.2.0", "@types/source-map-support": "^0.5.0", "@types/stat-mode": "^0.2.0", - "@types/yargs": "^13.0.0", + "@types/yargs": "^13.0.1", "babel-core": "^7.0.0-bridge.0", "babel-preset-jest": "^24.6.0", "babel-preset-ts-node8": "~4.0.0", diff --git a/packages/app-builder-lib/package.json b/packages/app-builder-lib/package.json index adda391f55f..d345e98aa2e 100644 --- a/packages/app-builder-lib/package.json +++ b/packages/app-builder-lib/package.json @@ -58,7 +58,7 @@ "read-config-file": "5.0.0", "minimatch": "^3.0.4", "normalize-package-data": "^2.5.0", - "sanitize-filename": "^1.6.1", + "sanitize-filename": "^1.6.2", "@develar/schema-utils": "~2.1.0", "semver": "^6.3.0", "debug": "^4.1.1", diff --git a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts index 5372442ad44..1a013fa5ea3 100644 --- a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts +++ b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts @@ -3,7 +3,7 @@ import BluebirdPromise from "bluebird-lst" import { executeAppBuilder, Arch, asArray, AsyncTaskManager, getPlatformIconFileName, InvalidConfigurationError, log, spawnAndWrite, use, exec } from "builder-util" import { PackageFileInfo, UUID, CURRENT_APP_PACKAGE_FILE_NAME, CURRENT_APP_INSTALLER_FILE_NAME } from "builder-util-runtime" import { getBinFromUrl } from "../../binDownload" -import { statOrNull, walk } from "builder-util/out/fs" +import { statOrNull, walk, exists } from "builder-util/out/fs" import { hashFile } from "../../util/hash" import _debug from "debug" import { readFile, stat, unlink } from "fs-extra" @@ -316,16 +316,22 @@ export class NsisTarget extends Target { // https://github.com/electron-userland/electron-builder/issues/2103 // it is more safe and reliable to write uninstaller to our out dir - const uninstallerPath = path.join(this.outDir, `.__uninstaller-${this.name}-${this.packager.appInfo.sanitizedName}.exe`) + const uninstallerPath = path.join(this.outDir, `__uninstaller-${this.name}-${this.packager.appInfo.sanitizedName}.exe`) const isWin = process.platform === "win32" defines.BUILD_UNINSTALLER = null defines.UNINSTALLER_OUT_FILE = isWin ? uninstallerPath : path.win32.join("Z:", uninstallerPath) await this.executeMakensis(defines, commands, sharedHeader + await this.computeFinalScript(script, false)) // http://forums.winamp.com/showthread.php?p=3078545 - // - if (await isMacOsCatalina()) { + if (isMacOsCatalina()) { (await packager.vm.value).exec(installerPath, []) + + // Parallels VM can exit after command execution, but NSIS continue to be running + let i = 0 + while (!(await exists(uninstallerPath)) && i++ < 100) { + // noinspection JSUnusedLocalSymbols + await new Promise((resolve, _reject) => setTimeout(resolve, 300)) + } } else { await execWine(installerPath) diff --git a/packages/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh b/packages/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh index b1c2db95680..f793680cf5a 100644 --- a/packages/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh +++ b/packages/app-builder-lib/templates/nsis/include/allowOnlyOneInstallerInstance.nsh @@ -40,7 +40,7 @@ ${if} $3 != "${APP_EXECUTABLE_FILENAME}" ${if} ${isUpdated} # allow app to exit without explicit kill - Sleep 100 + Sleep 300 ${endIf} ${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0 @@ -58,16 +58,15 @@ DetailPrint `Closing running "${PRODUCT_NAME}"...` # https://github.com/electron-userland/electron-builder/issues/2516#issuecomment-372009092 - nsExec::Exec `taskkill /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` $R0 + nsExec::Exec `taskkill /t /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` $R0 # to ensure that files are not "in-use" - Sleep 100 + Sleep 300 ${nsProcess::FindProcess} "${APP_EXECUTABLE_FILENAME}" $R0 ${if} $R0 == 0 # wait to give a chance to exit gracefully Sleep 1000 - # do not use /t tree kill - app was killed softly already - nsExec::Exec `taskkill /f /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` $R0 + nsExec::Exec `taskkill /f /t /im "${APP_EXECUTABLE_FILENAME}" /fi "PID ne $pid"` $R0 ${If} $R0 != 0 DetailPrint `Waiting for "${PRODUCT_NAME}" to close (taskkill exit code $R0).` Sleep 2000 @@ -75,6 +74,4 @@ ${endIf} ${endIf} ${endIf} - - ${nsProcess::Unload} !macroend \ No newline at end of file diff --git a/packages/dmg-builder/package.json b/packages/dmg-builder/package.json index a6bf524daed..dc37d78a1b2 100644 --- a/packages/dmg-builder/package.json +++ b/packages/dmg-builder/package.json @@ -19,7 +19,7 @@ "iconv-lite": "^0.5.0", "js-yaml": "^3.13.1", "app-builder-lib": "~0.0.0-semantic-release", - "sanitize-filename": "^1.6.1" + "sanitize-filename": "^1.6.2" }, "typings": "./out/dmg.d.ts" } diff --git a/packages/electron-builder-squirrel-windows/package.json b/packages/electron-builder-squirrel-windows/package.json index f87f627b035..efa354a869c 100644 --- a/packages/electron-builder-squirrel-windows/package.json +++ b/packages/electron-builder-squirrel-windows/package.json @@ -15,7 +15,7 @@ "bluebird-lst": "^1.0.9", "fs-extra": "^8.1.0", "archiver": "^3.0.3", - "sanitize-filename": "^1.6.1" + "sanitize-filename": "^1.6.2" }, "optionalDependencies": { "7zip-bin": "~4.0.2" diff --git a/packages/electron-builder/package.json b/packages/electron-builder/package.json index 7343604859f..d9a488e8add 100644 --- a/packages/electron-builder/package.json +++ b/packages/electron-builder/package.json @@ -52,7 +52,7 @@ "fs-extra": "^8.1.0", "is-ci": "^2.0.0", "read-config-file": "5.0.0", - "sanitize-filename": "^1.6.1", + "sanitize-filename": "^1.6.2", "update-notifier": "^3.0.1", "yargs": "^13.3.0", "lazy-val": "^1.0.4", diff --git a/test/out/windows/__snapshots__/oneClickInstallerTest.js.snap b/test/out/windows/__snapshots__/oneClickInstallerTest.js.snap index 9430ecd7c38..c6304acd7ef 100644 --- a/test/out/windows/__snapshots__/oneClickInstallerTest.js.snap +++ b/test/out/windows/__snapshots__/oneClickInstallerTest.js.snap @@ -248,7 +248,7 @@ Object { }, }, Object { - "arch": "ia32", + "arch": "x64", "file": "Test App ßW Setup 1.1.0.exe", "safeArtifactName": "TestApp-Setup-1.1.0.exe", "updateInfo": Object { diff --git a/test/src/windows/oneClickInstallerTest.ts b/test/src/windows/oneClickInstallerTest.ts index c7d360cfc4e..a93c656871b 100644 --- a/test/src/windows/oneClickInstallerTest.ts +++ b/test/src/windows/oneClickInstallerTest.ts @@ -8,7 +8,7 @@ import { checkHelpers, doTest, expectUpdateMetadata } from "../helpers/winHelper const nsisTarget = Platform.WINDOWS.createTarget(["nsis"]) test("one-click", app({ - targets: Platform.WINDOWS.createTarget(["nsis"], Arch.ia32), + targets: Platform.WINDOWS.createTarget(["nsis"], Arch.x64), config: { publish: { provider: "bintray", @@ -23,9 +23,9 @@ test("one-click", app({ }, { signedWin: true, packed: async context => { - await checkHelpers(context.getResources(Platform.WINDOWS, Arch.ia32), false) + await checkHelpers(context.getResources(Platform.WINDOWS, Arch.x64), false) await doTest(context.outDir, true, "TestApp Setup", "TestApp", null, false) - await expectUpdateMetadata(context, Arch.ia32, true) + await expectUpdateMetadata(context, Arch.x64, true) } })) diff --git a/yarn.lock b/yarn.lock index 352e722f015..7c5f9b9d264 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1211,10 +1211,10 @@ resolved "https://registry.npmjs.org/@types/jest-diff/-/jest-diff-20.0.1.tgz#35cc15b9c4f30a18ef21852e255fdb02f6d59b89" integrity sha512-yALhelO3i0hqZwhjtcr6dYyaLoCHbAMshwtj6cGxTvHZAKXHsYGdff6E8EPw3xLKY0ELUTQ69Q1rQiJENnccMA== -"@types/jest@^24.0.15": - version "24.0.15" - resolved "https://registry.npmjs.org/@types/jest/-/jest-24.0.15.tgz#6c42d5af7fe3b44ffff7cc65de7bf741e8fa427f" - integrity sha512-MU1HIvWUme74stAoc3mgAi+aMlgKOudgEvQDIm1v4RkrDudBh1T+NFp5sftpBAdXdx1J0PbdpJ+M2EsSOi1djA== +"@types/jest@^24.0.16": + version "24.0.16" + resolved "https://registry.npmjs.org/@types/jest/-/jest-24.0.16.tgz#8d3e406ec0f0dc1688d6711af3062ff9bd428066" + integrity sha512-JrAiyV+PPGKZzw6uxbI761cHZ0G7QMOHXPhtSpcl08rZH6CswXaaejckn3goFKmF7M3nzEoJ0lwYCbqLMmjziQ== dependencies: "@types/jest-diff" "*" @@ -1294,10 +1294,10 @@ resolved "https://registry.npmjs.org/@types/yargs/-/yargs-12.0.12.tgz#45dd1d0638e8c8f153e87d296907659296873916" integrity sha512-SOhuU4wNBxhhTHxYaiG5NY4HBhDIDnJF60GU+2LqHAdKKer86//e4yg69aENCtQ04n0ovz+tq2YPME5t5yp4pw== -"@types/yargs@^13.0.0": - version "13.0.0" - resolved "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.0.tgz#d2acb3bec0047d8f648ebacdab6b928a900c42c4" - integrity sha512-hY0o+kcz9M6kH32NUeb6VURghqMuCVkiUx+8Btsqhj4Hhov/hVGUx9DmBJeIkzlp1uAQK4wngQBCjqWdUUkFyA== +"@types/yargs@^13.0.1": + version "13.0.1" + resolved "https://registry.npmjs.org/@types/yargs/-/yargs-13.0.1.tgz#a45b3c9faadd7adfdb40646d14a7f6b70f4e8233" + integrity sha512-7X+FaCpRQ1scFQnWUY0TnVuuNaP5ajN45IGmwHVkAbsH1g4txz4hNb6sjJeR/wLaqUdNoInOwLk7oRL5M4zVFA== dependencies: "@types/yargs-parser" "*" @@ -1828,9 +1828,9 @@ camelcase@^5.0.0, camelcase@^5.3.1: integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg== caniuse-lite@^1.0.30000984: - version "1.0.30000985" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000985.tgz#0eb40f6c8a8c219155cbe43c4975c0efb4a0f77f" - integrity sha512-1ngiwkgqAYPG0JSSUp3PUDGPKKY59EK7NrGGX+VOxaKCNzRbNc7uXMny+c3VJfZxtoK3wSImTvG9T9sXiTw2+w== + version "1.0.30000987" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000987.tgz#bc6b47217afd8226a2b1964635c6bff62cdf5738" + integrity sha512-O3VrjtRMTxoU5Cn5/QSmXeIR1gkVps4j9jqfIm4FLaQ5JzqBlVjMUG1xWnoYFv8N+H3Lp++aa05TekyIbjHL7g== capture-exit@^2.0.0: version "2.0.0" @@ -2283,9 +2283,9 @@ depcheck@^0.8.3: yargs "^13.2.2" deprecate@^1.0.0: - version "1.1.0" - resolved "https://registry.npmjs.org/deprecate/-/deprecate-1.1.0.tgz#bbd069d62b232175b4e8459b2650cd2bad51f4b8" - integrity sha512-b5dDNQYdy2vW9WXUD8+RQlfoxvqztLLhDE+T7Gd37I5E8My7nJkKu6FmhdDeRWJ8B+yjZKuwjCta8pgi8kgSqA== + version "1.1.1" + resolved "https://registry.npmjs.org/deprecate/-/deprecate-1.1.1.tgz#4632e981fc815eeaf00be945a40359c0f8bf9913" + integrity sha512-ZGDXefq1xknT292LnorMY5s8UVU08/WKdzDZCUT6t9JzsiMSP4uzUhgpqugffNVcT5WC6wMBiSQ+LFjlv3v7iQ== deps-regex@^0.1.4: version "0.1.4" @@ -2400,9 +2400,9 @@ electron-builder-tslint-config@^1.1.0: integrity sha512-m/oAwS+NYB/b182bGY8C7uj1cDy8XXnHTl5CwD98dng7wE/nZGV2mJD9NyqbFmhJ1kF61wbsYDVx2KLIN5s5tg== electron-to-chromium@^1.3.191: - version "1.3.200" - resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.200.tgz#78fb858b466269e8eb46d31a52562f00c865127f" - integrity sha512-PUurrpyDA74MuAjJRD+79ss5BqJlU3mdArRbuu4wO/dt6jc3Ic/6BDmFJxkdwbfq39cHf/XKm2vW98XSvut9Dg== + version "1.3.204" + resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.204.tgz#1ea5c6d495bab77995aa135dbcbc1d383dd4e21e" + integrity sha512-T0eXE6hfbtpzRUaI7aHI/HYJ29Ndk84aVSborRAmXfWvBvz2EuB2OWYUxNcUX9d+jtqEIjgZjWMdoxS0hp5j1g== emoji-regex@^7.0.1: version "7.0.3" @@ -5263,10 +5263,10 @@ sane@^4.0.3: minimist "^1.1.1" walker "~1.0.5" -sanitize-filename@^1.6.1: - version "1.6.1" - resolved "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.1.tgz#612da1c96473fa02dccda92dcd5b4ab164a6772a" - integrity sha1-YS2hyWRz+gLczaktzVtKsWSmdyo= +sanitize-filename@^1.6.2: + version "1.6.2" + resolved "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.2.tgz#01b4fc8809f14e9d22761fe70380fe7f3f902185" + integrity sha512-cmTzND7RMxUB+f7gI+4+KAVHWEg0lfXvQJdko+FXDP5bNbGIdx4KMP5pX6lv5jfT9jSf6OBbjyxjFtZQwYA/ig== dependencies: truncate-utf8-bytes "^1.0.0"