Skip to content

Commit cf7c725

Browse files
committed
feat: convert from electron-download to @electron/get (#1002)
BREAKING CHANGE: The download options are completely different.
1 parent cc470ef commit cf7c725

File tree

11 files changed

+39
-36
lines changed

11 files changed

+39
-36
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ calling electron-packager. This will print debug information from the specified
2626
value of the environment variable is a comma-separated list of modules which support this logging
2727
feature. Known modules include:
2828

29-
* `electron-download`
29+
* `@electron/get:*`
3030
* `electron-osx-sign`
3131
* `electron-packager` (always use this one before filing an issue)
3232
* `get-package-info`

docs/api.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ Not required if the [`all`](#all) option is set.
182182
If `arch` is set to `all`, all supported architectures for the target platforms specified by [`platform`](#platform) will be built.
183183
Arbitrary combinations of individual architectures are also supported via a comma-delimited string or array of strings.
184184
The non-`all` values correspond to the architecture names used by [Electron releases]. This value
185-
is not restricted to the official set if [`download.mirror`](#download) is set.
185+
is not restricted to the official set if [`download.mirrorOptions`](#download) is set.
186186

187187
##### `asar`
188188

@@ -220,14 +220,13 @@ Whether symlinks should be dereferenced during the copying of the application so
220220

221221
*Object*
222222

223-
If present, passes custom options to [`electron-download`](https://www.npmjs.com/package/electron-download)
223+
If present, passes custom options to [`@electron/get`](https://npm.im/@electron/get)
224224
(see the link for more detailed option descriptions and the defaults). Supported parameters include,
225225
but are not limited to:
226-
- `cache` (*String*): The directory where prebuilt, pre-packaged Electron downloads are cached.
227-
- `mirror` (*String*): The URL to override the default Electron download location.
228-
- `quiet` (*Boolean* - default: `false`): Whether to show a progress bar when downloading Electron.
229-
- `strictSSL` (*Boolean* - default: `true`): Whether SSL certificates are required to be valid when
230-
downloading Electron.
226+
- `cacheRoot` (*String*): The directory where prebuilt, pre-packaged Electron downloads are cached.
227+
- `mirrorOptions` (*Object*): Options to override the default Electron download location.
228+
- `rejectUnauthorized` (*Boolean* - default: `true`): Whether SSL certificates are required to be
229+
valid when downloading Electron.
231230

232231

233232
##### `electronVersion`
@@ -352,7 +351,7 @@ Not required if the [`all`](#all) option is set.
352351
If `platform` is set to `all`, all [supported target platforms](#supported-platforms) for the target architectures specified by [`arch`](#arch) will be built.
353352
Arbitrary combinations of individual platforms are also supported via a comma-delimited string or array of strings.
354353
The non-`all` values correspond to the platform names used by [Electron releases]. This value
355-
is not restricted to the official set if [`download.mirror`](#download) is set.
354+
is not restricted to the official set if [`download.mirrorOptions`](#download) is set.
356355

357356
##### `prebuiltAsar`
358357

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
},
1818
"homepage": "https://github.com/electron-userland/electron-packager",
1919
"dependencies": {
20+
"@electron/get": "^1.2.0",
2021
"asar": "^2.0.1",
2122
"cross-zip": "^2.1.5",
2223
"debug": "^4.0.1",
23-
"electron-download": "^4.1.1",
2424
"electron-notarize": "^0.1.1",
2525
"electron-osx-sign": "^0.4.11",
2626
"fs-extra": "^7.0.0",

src/cli.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ module.exports = {
2020
boolean: [
2121
'all',
2222
'deref-symlinks',
23-
'download.strictSSL',
23+
'download.rejectUnauthorized',
2424
'junk',
2525
'overwrite',
2626
'prune',
2727
'quiet'
2828
],
2929
default: {
3030
'deref-symlinks': true,
31-
'download.strictSSL': true,
31+
'download.rejectUnauthorized': true,
3232
junk: true,
3333
prune: true
3434
},

src/download.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
const common = require('./common')
44
const debug = require('debug')('electron-packager')
5-
const download = require('electron-download')
6-
const { promisify } = require('util')
5+
const { downloadArtifact } = require('@electron/get')
76
const semver = require('semver')
87
const targets = require('./targets')
98

@@ -13,6 +12,7 @@ function createDownloadOpts (opts, platform, arch) {
1312
common.subOptionWarning(downloadOpts, 'download', 'platform', platform, opts.quiet)
1413
common.subOptionWarning(downloadOpts, 'download', 'arch', arch, opts.quiet)
1514
common.subOptionWarning(downloadOpts, 'download', 'version', opts.electronVersion, opts.quiet)
15+
common.subOptionWarning(downloadOpts, 'download', 'artifactName', 'electron', opts.quiet)
1616

1717
return downloadOpts
1818
}
@@ -32,6 +32,6 @@ module.exports = {
3232
downloadOpts.arch = 'arm'
3333
}
3434
debug(`Downloading Electron with options ${JSON.stringify(downloadOpts)}`)
35-
return promisify(download)(downloadOpts)
35+
return downloadArtifact(downloadOpts)
3636
}
3737
}

src/targets.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const common = require('./common')
4-
const hostArch = require('electron-download/lib/arch').host
4+
const { getHostArch } = require('@electron/get')
55
const semver = require('semver')
66

77
const officialArchs = ['ia32', 'x64', 'armv7l', 'arm64', 'mips64el']
@@ -61,7 +61,7 @@ function unsupportedListOption (name, value, supported) {
6161
}
6262

6363
function usingOfficialElectronPackages (opts) {
64-
return !opts.download || !opts.download.hasOwnProperty('mirror')
64+
return !opts.download || !opts.download.hasOwnProperty('mirrorOptions')
6565
}
6666

6767
function validOfficialPlatformArch (opts, platform, arch) {
@@ -107,7 +107,7 @@ module.exports = {
107107
let list = opts[name]
108108
if (!list) {
109109
if (name === 'arch') {
110-
list = hostArch()
110+
list = getHostArch()
111111
} else {
112112
list = process[name]
113113
}

test/_setup.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ async function downloadAll (version) {
3434
async function downloadElectronZip (version, options) {
3535
return download.downloadElectronZip({
3636
...options,
37-
cache: path.join(os.homedir(), '.electron'),
38-
quiet: !!process.env.CI,
39-
version: version
37+
artifactName: 'electron',
38+
cacheRoot: path.join(os.homedir(), '.electron'),
39+
version
4040
})
4141
}
4242

test/basic.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const common = require('../src/common')
44
const download = require('../src/download')
55
const fs = require('fs-extra')
6-
const hostArch = require('electron-download/lib/arch').host
6+
const { getHostArch } = require('@electron/get')
77
const packager = require('..')
88
const path = require('path')
99
const sinon = require('sinon')
@@ -31,18 +31,19 @@ test('setting the quiet option does not print messages', t => {
3131
t.true(console.error.notCalled, 'quieted common.info should not call console.error')
3232
})
3333

34-
test('download argument test: download.{arch,platform,version} does not overwrite {arch,platform,version}', t => {
34+
test('download argument test: download.{arch,platform,version,artifactName} does not overwrite {arch,platform,version,artifactName}', t => {
3535
const opts = {
3636
download: {
3737
arch: 'ia32',
3838
platform: 'win32',
39-
version: '0.30.0'
39+
version: '0.30.0',
40+
artifactName: 'ffmpeg'
4041
},
4142
electronVersion: '0.36.0'
4243
}
4344

4445
const downloadOpts = download.createDownloadOpts(opts, 'linux', 'x64')
45-
t.deepEqual(downloadOpts, { arch: 'x64', platform: 'linux', version: '0.36.0' })
46+
t.deepEqual(downloadOpts, { arch: 'x64', platform: 'linux', version: '0.36.0', artifactName: 'electron' })
4647
})
4748

4849
test('sanitize app name for use in file/directory names', t => {
@@ -98,7 +99,7 @@ test.serial('defaults', util.testSinglePlatform(async (t, opts) => {
9899
delete opts.arch
99100

100101
const defaultOpts = {
101-
arch: hostArch(),
102+
arch: getHostArch(),
102103
name: opts.name,
103104
platform: process.platform
104105
}

test/cli.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ test('CLI argument test: --electron-version populates opts.electronVersion', t =
1010
t.is(args.electronVersion, '1.2.3')
1111
})
1212

13-
test('CLI argument test: --download.strictSSL default', t => {
13+
test('CLI argument test: --download.rejectUnauthorized default', t => {
1414
const args = cli.parseArgs([])
15-
t.true(args.download.strictSSL, 'default for --download.strictSSL is true')
15+
t.true(args.download.rejectUnauthorized, 'default for --download.rejectUnauthorized is true')
1616
})
1717

1818
test('CLI argument test: --asar=true', t => {

test/targets.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ test('platform=linux and arch=arm64 with an unsupported official Electron versio
106106
test('platform=linux and arch=mips64el with a supported official Electron version', testMultiTarget({ arch: 'mips64el', platform: 'linux', electronVersion: '1.8.2-beta.5' }, 1, 'Package should be generated for mips64el'))
107107
test('platform=linux and arch=mips64el with an unsupported official Electron version', testMultiTarget({ arch: 'mips64el', platform: 'linux' }, 0, 'Package should not be generated for mips64el'))
108108
test('platform=linux and arch=mips64el with an unsupported official Electron version (2.0.0)', testMultiTarget({ arch: 'mips64el', platform: 'linux', electronVersion: '2.0.0' }, 0, 'Package should not be generated for mips64el'))
109-
test('unofficial arch', testMultiTarget({ arch: 'z80', platform: 'linux', download: { mirror: 'mirror' } }, 1,
109+
test('unofficial arch', testMultiTarget({ arch: 'z80', platform: 'linux', download: { mirrorOptions: { mirror: 'mirror' } } }, 1,
110110
'Package should be generated for non-standard arch from non-official mirror'))
111-
test('unofficial platform', testMultiTarget({ arch: 'ia32', platform: 'minix', download: { mirror: 'mirror' } }, 1,
111+
test('unofficial platform', testMultiTarget({ arch: 'ia32', platform: 'minix', download: { mirrorOptions: { mirror: 'mirror' } } }, 1,
112112
'Package should be generated for non-standard platform from non-official mirror'))

usage.txt

+9-6
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ asar whether to package the source code within your app into an ar
3636
- unpackDir: unpacks the dir to the app.asar.unpacked directory whose names glob
3737
pattern or exactly match this string. It's relative to the <sourcedir>.
3838
build-version build version to set for the app
39-
download a list of sub-options to pass to electron-download. They are specified via dot
40-
notation, e.g., --download.cache=/tmp/cache
39+
download a list of sub-options to pass to @electron/get. They are specified via dot
40+
notation, e.g., --download.cacheRoot=/tmp/cache
4141
Properties supported:
42-
- cache: directory of cached Electron downloads. Defaults to `$HOME/.electron`
43-
- mirror: alternate URL to download Electron zips
44-
- strictSSL: whether SSL certs are required to be valid when downloading
45-
Electron. Defaults to true, use --no-download.strictSSL to disable checks.
42+
- cacheRoot: directory of cached Electron downloads. For default value, see
43+
@electron/get documentation
44+
- mirrorOptions: alternate URL options for downloading Electron zips. See
45+
@electron/get documentation for details
46+
- rejectUnauthorized: whether SSL certs are required to be valid when downloading
47+
Electron. Defaults to true, use --no-download.rejectUnauthorized to disable
48+
checks.
4649
electron-version the version of Electron that is being packaged, see
4750
https://github.com/electron/electron/releases
4851
executable-name the name of the executable file, sans file extension. Defaults to appname

0 commit comments

Comments
 (0)