Skip to content

Commit

Permalink
fix(msi): Inconsistent installation folder names for NSIS & MSI build…
Browse files Browse the repository at this point in the history
…s resulting in 2 apps after msi app update

Close electron-userland#3100
  • Loading branch information
Ajeey authored and develar committed Jul 11, 2018
1 parent 3557aae commit 657b43f
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 122 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"normalize-package-data": "^2.4.0",
"parse-color": "^1.0.0",
"plist": "^3.0.1",
"read-config-file": "3.0.2",
"read-config-file": "3.1.0",
"sanitize-filename": "^1.6.1",
"sax": "^1.2.4",
"semver": "^5.5.0",
Expand Down Expand Up @@ -95,7 +95,7 @@
"electron-builder-tslint-config": "^1.1.0",
"env-paths": "^1.0.0",
"globby": "^8.0.1",
"jest-cli": "^23.3.0",
"jest-cli": "^23.4.0",
"jest-junit": "^5.1.0",
"jsdoc-to-markdown": "^4.0.1",
"path-sort": "^0.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"is-ci": "^1.1.0",
"isbinaryfile": "^3.0.2",
"js-yaml": "^3.12.0",
"read-config-file": "3.0.2",
"read-config-file": "3.1.0",
"minimatch": "^3.0.4",
"normalize-package-data": "^2.4.0",
"plist": "^3.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readJson, writeFile, writeJson } from "fs-extra-p"
import { readJson, writeFile } from "fs-extra-p"
import * as path from "path"
import { UploadTask, Arch, Packager, PackagerOptions, PublishOptions } from ".."

Expand Down Expand Up @@ -79,7 +79,8 @@ async function doBuild(data: BuildTask): Promise<void> {
},
}, info.metadata, info.devMetadata, info.repositoryInfo)

await writeJson(path.join(process.env.ELECTRON_BUILDER_TMP_DIR!!, "__build-result.json"), artifacts)
// writeJson must be not used because it adds unwanted \n as last file symbol
await writeFile(path.join(process.env.ELECTRON_BUILDER_TMP_DIR!!, "__build-result.json"), JSON.stringify(artifacts))
}

doBuild(JSON.parse(process.argv[2]))
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder-lib/src/targets/MsiTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { getTemplatePath } from "../util/pathManager"
import { VmManager } from "../vm/vm"
import { WineVmManager } from "../vm/WineVm"
import { WinPackager } from "../winPackager"
import { createStageDir } from "./targetUtil"
import { createStageDir, getWindowsInstallationDirName } from "./targetUtil"

const ELECTRON_BUILDER_UPGRADE_CODE_NS_UUID = UUID.parse("d752fe43-5d44-44d5-9fc9-6dd1bf19d5cc")
const ROOT_DIR_ID = "APPLICATIONFOLDER"
Expand Down Expand Up @@ -163,7 +163,7 @@ export default class MsiTarget extends Target {
// https://stackoverflow.com/questions/1929038/compilation-error-ice80-the-64bitcomponent-uses-32bitdirectory
programFilesId: arch === Arch.x64 ? "ProgramFiles64Folder" : "ProgramFilesFolder",
// wix in the name because special wix format can be used in the name
installationDirectoryWixName: /^[-_+0-9a-zA-Z ]+$/.test(appInfo.productFilename) ? appInfo.productFilename : appInfo.sanitizedName,
installationDirectoryWixName: getWindowsInstallationDirName(appInfo, commonOptions.isPerMachine === true),
dirs,
files,
})
Expand Down
3 changes: 2 additions & 1 deletion packages/electron-builder-lib/src/targets/nsis/NsisTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { time } from "../../util/timer"
import { WinPackager } from "../../winPackager"
import { archive, ArchiveOptions } from "../archive"
import { appendBlockmap, configureDifferentialAwareArchiveOptions, createBlockmap, createNsisWebDifferentialUpdateInfo } from "../differentialUpdateInfoBuilder"
import { getWindowsInstallationDirName } from "../targetUtil"
import { addCustomMessageFileInclude, createAddLangsMacro, LangConfigurator } from "./nsisLang"
import { computeLicensePage } from "./nsisLicense"
import { NsisOptions, PortableOptions } from "./nsisOptions"
Expand Down Expand Up @@ -145,7 +146,7 @@ export class NsisTarget extends Target {
APP_GUID: guid,
PRODUCT_NAME: appInfo.productName,
PRODUCT_FILENAME: appInfo.productFilename,
APP_FILENAME: (!oneClick || options.perMachine === true) && /^[-_+0-9a-zA-Z .]+$/.test(appInfo.productFilename) ? appInfo.productFilename : appInfo.sanitizedName,
APP_FILENAME: getWindowsInstallationDirName(appInfo, !oneClick || options.perMachine === true),
APP_DESCRIPTION: appInfo.description,
VERSION: appInfo.version,

Expand Down
8 changes: 7 additions & 1 deletion packages/electron-builder-lib/src/targets/targetUtil.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { emptyDir, remove } from "fs-extra-p"
import * as path from "path"
import { Target } from "../core"
import { Target, AppInfo } from "../"
import { Arch, debug } from "builder-util"
import { PlatformPackager } from "../platformPackager"

Expand Down Expand Up @@ -32,4 +32,10 @@ export async function createStageDirPath(target: Target, packager: PlatformPacka
const tempDir = packager.info.stageDirPathCustomizer(target, packager, arch)
await emptyDir(tempDir)
return tempDir
}

// https://github.com/electron-userland/electron-builder/issues/3100
// https://github.com/electron-userland/electron-builder/commit/2539cfba20dc639128e75c5b786651b652bb4b78
export function getWindowsInstallationDirName(appInfo: AppInfo, isTryToUseProductName: boolean): string {
return isTryToUseProductName && /^[-_+0-9a-zA-Z .]+$/.test(appInfo.productFilename) ? appInfo.productFilename : appInfo.sanitizedName
}
2 changes: 1 addition & 1 deletion packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"builder-util": "0.0.0-semantic-release",
"fs-extra-p": "^4.6.1",
"is-ci": "^1.1.0",
"read-config-file": "3.0.2",
"read-config-file": "3.1.0",
"sanitize-filename": "^1.6.1",
"update-notifier": "^2.5.0",
"yargs": "^12.0.1",
Expand Down
Loading

0 comments on commit 657b43f

Please sign in to comment.