Skip to content

Commit

Permalink
fix(nsis): Must be error if file association is set, but perMachine not
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jan 24, 2017
1 parent eb6a453 commit 96c8ed9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
6 changes: 4 additions & 2 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Don't customize paths to background and icon, — just follow conventions.
* [appx](#AppXOptions)
* [directories](#MetadataDirectories)
* [dmg macOS DMG Options](#DmgOptions)
* [fileAssociations File Associations](#FileAssociation)
* [fileAssociations File Associations](#FileAssociation)
* [linux Linux Specific Options](#LinuxBuildOptions)
* [mac macOS Specific Options](#MacOptions)
* [mas MAS (Mac Application Store) Specific Options](#MasBuildOptions)
Expand Down Expand Up @@ -103,10 +103,12 @@ Please see [Windows AppX docs](https://msdn.microsoft.com/en-us/library/windows/
| window | <a name="DmgOptions-window"></a>The DMG windows position and size. See [dmg.window](#DmgWindow).

<a name="FileAssociation"></a>
### `fileAssociations` File Associations
### `fileAssociations` File Associations

macOS (corresponds to [CFBundleDocumentTypes](https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-101685)) and NSIS only. Array of option objects.

On Windows works only if [nsis.perMachine](https://github.com/electron-userland/electron-builder/wiki/Options#NsisOptions-perMachine) is set to `true`.

| Name | Description
| --- | ---
| **ext** | <a name="FileAssociation-ext"></a>The extension (minus the leading period). e.g. `png`.
Expand Down
4 changes: 3 additions & 1 deletion packages/electron-builder/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,11 @@ export interface BeforeBuildContext {
}

/*
### `fileAssociations` File Associations
### `fileAssociations` File Associations
macOS (corresponds to [CFBundleDocumentTypes](https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/20001431-101685)) and NSIS only. Array of option objects.
On Windows works only if [nsis.perMachine](https://github.com/electron-userland/electron-builder/wiki/Options#NsisOptions-perMachine) is set to `true`.
*/
export interface FileAssociation {
/*
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/packager/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export async function createApp(packager: PlatformPackager<any>, appOutDir: stri

const resourcesPath = path.join(contentsPath, "Resources")

const fileAssociations = packager.getFileAssociations()
const fileAssociations = packager.fileAssociations
if (fileAssociations.length > 0) {
appPlist.CFBundleDocumentTypes = await BluebirdPromise.map(fileAssociations, async fileAssociation => {
const extensions = asArray(fileAssociation.ext).map(normalizeExt)
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return this.info.tempDirManager.getTempFile(suffix)
}

getFileAssociations(): Array<FileAssociation> {
get fileAssociations(): Array<FileAssociation> {
return asArray(this.config.fileAssociations).concat(asArray(this.platformSpecificBuildOptions.fileAssociations))
}

Expand Down
7 changes: 6 additions & 1 deletion packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,13 @@ export default class NsisTarget extends Target {
script = `!include "${customInclude}"\n!addincludedir "${packager.buildResourcesDir}"\n${script}`
}

const fileAssociations = packager.getFileAssociations()
const fileAssociations = packager.fileAssociations
if (fileAssociations.length !== 0) {
if (this.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`)
}

script = "!include FileAssociation.nsh\n" + script
if (isInstaller) {
let registerFileAssociationsScript = ""
Expand Down
14 changes: 13 additions & 1 deletion test/src/windows/nsisTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Platform, Arch } from "electron-builder"
import { assertPack, app, copyTestAsset, modifyPackageJson } from "../helpers/packTester"
import { assertPack, app, copyTestAsset, modifyPackageJson, appThrows } from "../helpers/packTester"
import { outputFile, readFile } from "fs-extra-p"
import * as path from "path"
import BluebirdPromise from "bluebird-lst-c"
Expand Down Expand Up @@ -208,4 +208,16 @@ test("menuCategory", app({
packed: async(context) => {
await doTest(context.outDir, false, "Test Menu Category", "test-menu-category", "Foo Bar")
}
}))

test.ifDevOrLinuxCi("file associations only perMachine", appThrows(/Please set perMachine to true/, {
targets: Platform.WINDOWS.createTarget(["nsis"], Arch.ia32),
config: {
fileAssociations: [
{
ext: "foo",
name: "Test Foo",
}
],
},
}))
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.5.29.tgz#29f4dd9314fbccb080d8bd84b9c23811ec5090c2"

"@types/node@*":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.0.tgz#c081147b109da5f9c57af70571771be97ce9c0ba"
version "7.0.3"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.3.tgz#6bc1d23929bd426eabd409b5898537076bbbdeff"

"@types/source-map-support@^0.2.28":
version "0.2.28"
Expand Down

0 comments on commit 96c8ed9

Please sign in to comment.