Skip to content

Commit b151ffc

Browse files
committed
fix: Windows installer metadata is incorrect #278
Closes #278
1 parent de216b1 commit b151ffc

File tree

10 files changed

+67
-22
lines changed

10 files changed

+67
-22
lines changed

docs/options.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ In the development `package.json` custom `build` field can be specified to custo
44
```json
55
"build": {
66
"osx": {
7-
"title": "computed name from the app package.js, you can overwrite",
87
"icon": "build/icon.icns",
98
"icon-size": 80,
109
"background": "build/background.png",
@@ -22,16 +21,13 @@ In the development `package.json` custom `build` field can be specified to custo
2221
"path": "computed path to artifact, do not specify it - will be overwritten"
2322
}
2423
]
25-
},
26-
"win": "see https://github.com/electronjs/windows-installer#usage"
24+
}
2725
}
2826
```
2927

3028
As you can see, you need to customize OS X options only if you want to provide custom `x, y`.
3129
Don't customize paths to background and icon, — just follow conventions (if you don't want to use `build` as directory of resources — please create issue to ask ability to customize it).
3230

33-
See [OS X options](https://www.npmjs.com/package/appdmg#json-specification) and [Windows options](https://github.com/electronjs/windows-installer#usage).
34-
3531
Here documented only `electron-builder` specific options:
3632

3733
<!-- do not edit. start of generated block -->
@@ -45,6 +41,7 @@ Here documented only `electron-builder` specific options:
4541
# Development `package.json`
4642
| Name | Description
4743
| --- | ---
44+
| <a class="anchor" id="user-content-DevMetadata-homepage" href="#DevMetadata-homepage" aria-hidden="true"></a>homepage | The url to the project homepage (NuGet Package `projectUrl` or Linux Package URL).
4845
| <a class="anchor" id="user-content-DevMetadata-build" href="#DevMetadata-build" aria-hidden="true"></a>build | See [BuildMetadata](#BuildMetadata).
4946
<a class="anchor" id="user-content-BuildMetadata" href="#BuildMetadata" aria-hidden="true"></a>
5047
## `.build`
@@ -53,5 +50,7 @@ Here documented only `electron-builder` specific options:
5350
| <a class="anchor" id="user-content-BuildMetadata-iconUrl" href="#BuildMetadata-iconUrl" aria-hidden="true"></a>iconUrl | <p>*windows-only.* A URL to an ICO file to use as the application icon (displayed in Control Panel &gt; Programs and Features). Defaults to the Atom icon.</p> <p>Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.</p> <ul> <li>If you don’t plan to build windows installer, you can omit it.</li> <li>If your project repository is public on GitHub, it will be <code>https://raw.githubusercontent.com/${info.user}/${info.project}/master/build/icon.ico</code> by default.</li> </ul>
5451
| <a class="anchor" id="user-content-BuildMetadata-productName" href="#BuildMetadata-productName" aria-hidden="true"></a>productName | See [AppMetadata.productName](#AppMetadata-productName).
5552
| <a class="anchor" id="user-content-BuildMetadata-extraResources" href="#BuildMetadata-extraResources" aria-hidden="true"></a>extraResources | <p>A [glob expression](https://www.npmjs.com/package/glob#glob-primer), when specified, copy the file or directory with matching names directly into the app’s directory (<code>Contents/Resources</code> for OS X).</p> <p>You can use <code>${os}</code> (expanded to osx, linux or win according to current platform) and <code>${arch}</code> in the pattern.</p> <p>If directory matched, all contents are copied. So, you can just specify <code>foo</code> to copy <code>&lt;project_dir&gt;/foo</code> directory.</p> <p>May be specified in the platform options (i.e. in the <code>build.osx</code>).</p>
53+
| <a class="anchor" id="user-content-BuildMetadata-osx" href="#BuildMetadata-osx" aria-hidden="true"></a>osx | See [OS X options](https://www.npmjs.com/package/appdmg#json-specification)
54+
| <a class="anchor" id="user-content-BuildMetadata-win" href="#BuildMetadata-win" aria-hidden="true"></a>win | See [windows-installer options](https://github.com/electronjs/windows-installer#usage)
5655

5756
<!-- end of generated block -->

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"bluebird": "^3.3.4",
5656
"command-line-args": "^2.1.6",
5757
"electron-packager": "^6.0.0",
58-
"electron-winstaller-fixed": "^2.0.6-beta.4",
58+
"electron-winstaller-fixed": "^2.0.6-beta.5",
5959
"fs-extra": "^0.26.7",
6060
"fs-extra-p": "^0.2.0",
6161
"globby": "^4.0.0",

src/metadata.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export interface AppMetadata extends Metadata {
2828
# Development `package.json`
2929
*/
3030
export interface DevMetadata extends Metadata {
31+
/**
32+
The url to the project homepage (NuGet Package `projectUrl` or Linux Package URL).
33+
*/
34+
readonly homepage?: string
35+
3136
/**
3237
See [BuildMetadata](#BuildMetadata).
3338
*/
@@ -71,10 +76,6 @@ export interface BuildMetadata {
7176
*/
7277
readonly productName?: string
7378

74-
readonly osx?: appdmg.Specification
75-
readonly win?: any,
76-
readonly linux?: any
77-
7879
/**
7980
A [glob expression](https://www.npmjs.com/package/glob#glob-primer), when specified, copy the file or directory with matching names directly into the app's directory (`Contents/Resources` for OS X).
8081
@@ -85,6 +86,18 @@ export interface BuildMetadata {
8586
May be specified in the platform options (i.e. in the `build.osx`).
8687
*/
8788
readonly extraResources?: Array<string>
89+
90+
/**
91+
See [OS X options](https://www.npmjs.com/package/appdmg#json-specification)
92+
*/
93+
readonly osx?: appdmg.Specification
94+
95+
/**
96+
See [windows-installer options](https://github.com/electronjs/windows-installer#usage)
97+
*/
98+
readonly win?: any,
99+
100+
readonly linux?: any
88101
}
89102

90103
export interface PlatformSpecificBuildOptions {

src/winPackager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export default class WinPackager extends PlatformPackager<WinBuildOptions> {
115115
const version = this.metadata.version
116116
const installerOutDir = WinPackager.computeDistOut(outDir, arch)
117117
const archSuffix = arch === "x64" ? "" : ("-" + arch)
118+
const projectUrl = this.devMetadata.homepage
118119

119120
const options = Object.assign({
120121
name: this.metadata.name,
@@ -133,7 +134,8 @@ export default class WinPackager extends PlatformPackager<WinBuildOptions> {
133134
fixUpPaths: false,
134135
usePackageJson: false,
135136
noMsi: true,
136-
extraFileSpecs: this.extraNuGetFileSources == null ? null : ("\n" + (await this.extraNuGetFileSources).join("\n"))
137+
extraFileSpecs: this.extraNuGetFileSources == null ? null : ("\n" + (await this.extraNuGetFileSources).join("\n")),
138+
extraMetadataSpecs: projectUrl == null ? null : `\n<projectUrl>${projectUrl}</projectUrl>`,
137139
}, this.customBuildOptions)
138140

139141
await require("electron-winstaller-fixed").createWindowsInstaller(options)

test/fixtures/test-app-one/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
"private": true,
33
"name": "TestApp",
44
"version": "1.0.0",
5+
"homepage": "http://foo.example.com",
56
"description": "Test Application",
67
"scripts": {
78
"start": "electron ."
89
},
910
"author": "Foo Bar <foo@example.com>",
1011
"devDependencies": {
11-
"electron-prebuilt": "^0.37.2"
12+
"electron-prebuilt": "^0.37.3"
1213
},
1314
"build": {
1415
"app-bundle-id": "your.id",

test/fixtures/test-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"start": "electron ."
55
},
66
"devDependencies": {
7-
"electron-prebuilt": "^0.37.2"
7+
"electron-prebuilt": "^0.37.3"
88
},
99
"build": {
1010
"app-bundle-id": "your.id",

test/src/BuildTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test("version from electron-prebuilt dependency", () => assertPack("test-app-one
4949
tempDirCreated: projectDir => {
5050
return BluebirdPromise.all([
5151
outputJson(path.join(projectDir, "node_modules", "electron-prebuilt", "package.json"), {
52-
version: "0.37.2"
52+
version: "0.37.3"
5353
}),
5454
modifyPackageJson(projectDir, data => {
5555
data.devDependencies = {}

test/src/helpers/packTester.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { copy, emptyDir, remove, writeJson, readJson } from "fs-extra-p"
1+
import { copy, emptyDir, remove, writeJson, readJson, readFile } from "fs-extra-p"
22
import * as assertThat from "should/as-function"
33
import * as path from "path"
44
import { parse as parsePlist } from "plist"
@@ -186,12 +186,11 @@ async function checkWindowsResult(packager: Packager, packagerOptions: PackagerO
186186
assertThat(artifacts.map(it => it.artifactName).filter(it => it != null)).deepEqual([`TestAppSetup-1.0.0${archSuffix}.exe`])
187187
}
188188

189-
const files = pathSorter((await new BluebirdPromise<Array<string>>((resolve, reject) => {
190-
const unZipper = new DecompressZip(path.join(path.dirname(artifacts[0].file), `TestApp-1.0.0${archSuffix}-full.nupkg`))
191-
unZipper.on("list", resolve)
192-
unZipper.on('error', reject)
193-
unZipper.list()
194-
})).map(it => it.replace(/\\/g, "/")).filter(it => (!it.startsWith("lib/net45/locales/") || it === "lib/net45/locales/en-US.pak") && !it.endsWith(".psmdcp")))
189+
const packageFile = path.join(path.dirname(artifacts[0].file), `TestApp-1.0.0${archSuffix}-full.nupkg`)
190+
const unZipper = new DecompressZip(packageFile)
191+
const fileDescriptors = await unZipper.getFiles()
192+
193+
const files = pathSorter(fileDescriptors.map(it => it.path.replace(/\\/g, "/")).filter(it => (!it.startsWith("lib/net45/locales/") || it === "lib/net45/locales/en-US.pak") && !it.endsWith(".psmdcp")))
195194

196195
// console.log(JSON.stringify(files, null, 2))
197196
const expectedContents = checkOptions == null || checkOptions.expectedContents == null ? expectedWinContents : checkOptions.expectedContents
@@ -203,6 +202,27 @@ async function checkWindowsResult(packager: Packager, packagerOptions: PackagerO
203202
return it
204203
}
205204
}))
205+
206+
if (checkOptions == null || checkOptions.expectedContents == null) {
207+
await unZipper.extractFile(fileDescriptors.filter(it => it.path === "TestApp.nuspec")[0], {
208+
path: path.dirname(packageFile),
209+
})
210+
assertThat((await readFile(path.join(path.dirname(packageFile), "TestApp.nuspec"), "utf8")).replace(/\r\n/g, "\n")).equal(`<?xml version="1.0"?>
211+
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
212+
<metadata>
213+
<id>TestApp</id>
214+
<version>1.0.0</version>
215+
<title>My App</title>
216+
<authors>Foo Bar</authors>
217+
<owners>Foo Bar</owners>
218+
<projectUrl>http://foo.example.com</projectUrl>
219+
<iconUrl>https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico</iconUrl>
220+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
221+
<description>Test Application</description>
222+
<copyright>Copyright © ${new Date().getFullYear()} Foo Bar</copyright>
223+
</metadata>
224+
</package>`)
225+
}
206226
}
207227

208228
async function getContents(path: string, productName: string) {

test/src/helpers/runTests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const rootDir = path.join(__dirname, "..", "..", "..")
1414
const testPackageDir = path.join(require("os").tmpdir(), "electron_builder_published")
1515
const testNodeModules = path.join(testPackageDir, "node_modules")
1616

17-
const electronVersion = "0.37.2"
17+
const electronVersion = "0.37.3"
1818

1919
BluebirdPromise.all([
2020
deleteOldElectronVersion(),

test/typings/decompress-zip.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
declare module "decompress-zip" {
22
import { EventEmitter } from "events"
33

4+
interface FileDescriptor {
5+
path: string
6+
}
7+
48
export = class DecompressZip extends EventEmitter {
59
constructor(filename: string)
610

711
list(): void
12+
13+
getFiles(): Promise<Array<FileDescriptor>>
14+
15+
extract(options: {path: string, filter?: (file: string) => boolean}): void
16+
17+
extractFile(file: FileDescriptor, options: {path: string, filter?: (file: string) => boolean}): Promise<void>
818
}
919
}

0 commit comments

Comments
 (0)