Skip to content

Commit 0f1fc4d

Browse files
committed
fix: electron-builder not generating "latest.yml" file
Closes #925
1 parent fdc3eba commit 0f1fc4d

File tree

9 files changed

+64
-45
lines changed

9 files changed

+64
-45
lines changed

.idea/rc-producer.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ language: c
1414
cache:
1515
directories:
1616
- node_modules
17+
- packages/electron-builder/node_modules
18+
- packages/electron-builder-util/node_modules
1719
- $HOME/.electron
1820
- /tmp/jest-electron-builder-tests
1921

packages/electron-auto-updater/src/GitHubProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class GitHubProvider implements Provider<VersionInfo> {
5151
async getUpdateFile(versionInfo: UpdateInfo): Promise<FileInfo> {
5252
const basePath = this.getBasePath()
5353
// space is not supported on GitHub
54-
const name = path.posix.basename(versionInfo.path).replace(/ /g, "-")
54+
const name = versionInfo.githubArtifactName || path.posix.basename(versionInfo.path).replace(/ /g, "-")
5555
return {
5656
name: name,
5757
url: `https://github.com${basePath}/download/v${versionInfo.version}/${name}`,

packages/electron-builder-http/src/publishOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface VersionInfo {
4949

5050
export interface UpdateInfo extends VersionInfo {
5151
readonly path: string
52+
readonly githubArtifactName?: string | null
5253
readonly sha2: string
5354
}
5455

packages/electron-builder/src/builder.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,7 @@ function publishManager(packager: Packager, publishTasks: Array<BluebirdPromise<
291291
if (it == null) {
292292
return null
293293
}
294-
295-
if (event.file == null) {
296-
return publishTasks.push(<BluebirdPromise<any>>it.uploadData(event.data!, event.artifactName!))
297-
}
298-
else {
299-
return publishTasks.push(<BluebirdPromise<any>>it.upload(event.file!, event.artifactName))
300-
}
294+
return publishTasks.push(<BluebirdPromise<any>>it.upload(event.file, event.artifactName))
301295
})
302296
}
303297
}

packages/electron-builder/src/platformPackager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,7 @@ export interface RepositoryInfo {
541541
export interface ArtifactCreated {
542542
readonly packager: PlatformPackager<any>
543543

544-
readonly file?: string
545-
readonly data?: Buffer
544+
readonly file: string
546545

547546
readonly artifactName?: string
548547

@@ -586,6 +585,7 @@ export function getPublishConfigs(packager: PlatformPackager<any>, platformSpeci
586585

587586
if (publishers == null) {
588587
publishers = packager.config.publish
588+
// triple equals - if explicitly set to null
589589
if (publishers === null) {
590590
return null
591591
}

packages/electron-builder/src/targets/nsis.ts

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { safeDump } from "js-yaml"
1414
import { createHash } from "crypto"
1515
import { Target, Arch } from "electron-builder-core"
1616
import sanitizeFileName from "sanitize-filename"
17+
import { unlinkIfExists } from "electron-builder-util/out/fs"
1718

1819
const NSIS_VERSION = "3.0.4"
1920
//noinspection SpellCheckingInspection
@@ -42,14 +43,25 @@ export default class NsisTarget extends Target {
4243
}
4344
}
4445

45-
private computePublishConfigs(): Promise<Array<PublishConfiguration> | null> {
46-
const publishConfigs = getPublishConfigs(this.packager, this.options)
47-
if (publishConfigs != null && publishConfigs.length > 0) {
48-
return BluebirdPromise.map(publishConfigs, it => getResolvedPublishConfig(this.packager.info, it, true))
46+
private async computePublishConfigs(): Promise<Array<PublishConfiguration> | null> {
47+
let publishConfigs = getPublishConfigs(this.packager, this.options)
48+
if (publishConfigs == null) {
49+
return null
4950
}
50-
else {
51-
return BluebirdPromise.resolve(null)
51+
52+
if (publishConfigs.length === 0) {
53+
// https://github.com/electron-userland/electron-builder/issues/925#issuecomment-261732378
54+
// default publish config is github, file should be generated regardless of publish state (user can test installer locally or manage the release process manually)
55+
const repositoryInfo = await this.packager.getRepositoryInfo()
56+
if (repositoryInfo != null && repositoryInfo.type === "github") {
57+
publishConfigs = [{provider: "github"}]
58+
}
59+
else {
60+
return null
61+
}
5262
}
63+
64+
return await BluebirdPromise.map(publishConfigs, it => <Promise<PublishConfiguration>>getResolvedPublishConfig(this.packager.info, it, true))
5365
}
5466

5567
build(appOutDir: string, arch: Arch) {
@@ -226,36 +238,36 @@ export default class NsisTarget extends Target {
226238
const publishConfigs = await this.publishConfigs
227239
const githubArtifactName = `${appInfo.name}-Setup-${version}.exe`
228240
if (publishConfigs != null) {
229-
let sha2: string | null = null
230241
for (const publishConfig of publishConfigs) {
231-
if (publishConfig.provider === "generic" || publishConfig.provider === "github") {
232-
if (sha2 == null) {
233-
sha2 = await sha256(installerPath)
234-
}
242+
if (!(publishConfig.provider === "generic" || publishConfig.provider === "github")) {
243+
continue
244+
}
235245

236-
const channel = (<GenericServerOptions>publishConfig).channel || "latest"
237-
if (publishConfig.provider === "generic") {
238-
await writeFile(path.join(this.outDir, `${channel}.yml`), safeDump(<UpdateInfo>{
239-
version: version,
240-
path: installerFilename,
241-
sha2: sha2,
242-
}))
243-
}
244-
else {
245-
packager.info.eventEmitter.emit("artifactCreated", <ArtifactCreated>{
246-
data: new Buffer(safeDump(<UpdateInfo>{
247-
version: version,
248-
path: githubArtifactName,
249-
sha2: sha2,
250-
})),
251-
artifactName: `${channel}.yml`,
252-
packager: packager,
253-
publishConfig: publishConfig,
254-
})
255-
}
246+
const sha2 = await sha256(installerPath)
247+
const channel = (<GenericServerOptions>publishConfig).channel || "latest"
248+
const updateInfoFile = path.join(this.outDir, `${channel}.yml`)
249+
await writeFile(updateInfoFile, safeDump(<UpdateInfo>{
250+
version: version,
251+
githubArtifactName: githubArtifactName,
252+
path: installerFilename,
253+
sha2: sha2,
254+
}))
255+
256+
const githubPublishConfig = publishConfigs.find(it => it.provider === "github")
257+
if (githubPublishConfig != null) {
258+
packager.info.eventEmitter.emit("artifactCreated", <ArtifactCreated>{
259+
file: updateInfoFile,
260+
packager: packager,
261+
publishConfig: githubPublishConfig,
262+
})
256263
}
264+
265+
break
257266
}
258267
}
268+
else {
269+
await unlinkIfExists(path.join(this.outDir, `latest.yml`))
270+
}
259271

260272
packager.dispatchArtifactCreated(installerPath, githubArtifactName)
261273
}

packages/electron-builder/src/winPackager.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,18 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
7878
switch (name) {
7979
case "nsis":
8080
return require("./targets/nsis").default
81+
8182
case "squirrel":
82-
return require("electron-builder-squirrel-windows").default
83+
try {
84+
return require("electron-builder-squirrel-windows").default
85+
}
86+
catch (e) {
87+
throw new Error(`Since electron-builder 11, module electron-builder-squirrel-windows must be installed in addition to build Squirrel.Windows: ${e.stack || e}`)
88+
}
89+
8390
case "appx":
8491
return require("./targets/appx").default
92+
8593
default:
8694
return null
8795
}

test/src/helpers/packTester.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOp
344344
}
345345
}
346346

347-
assertThat(getFileNames(artifacts)).containsAll(expectedFileNames)
347+
// we test latest.yml separately, don't want to complicate general assert
348+
assertThat(getFileNames(artifacts).filter(it => it !== "latest.yml")).containsAll(expectedFileNames)
348349

349350
if (!squirrel) {
350351
return
@@ -356,7 +357,8 @@ async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOp
356357
const unZipper = new DecompressZip(packageFile)
357358
const fileDescriptors = await unZipper.getFiles()
358359

359-
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")))
360+
// we test app-update.yml separately, don't want to complicate general assert (yes, it is not good that we write app-update.yml for squirrel.windows if we build nsis and squirrel.windows in parallel, but as squirrel.windows is deprecated, it is ok)
361+
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") && !it.endsWith("app-update.yml")))
360362

361363
// console.log(JSON.stringify(files, null, 2))
362364
const expectedContents = checkOptions == null || checkOptions.expectedContents == null ? expectedWinContents : checkOptions.expectedContents

0 commit comments

Comments
 (0)