Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: convert from electron-download to @electron/get #1002

Merged
merged 3 commits into from
Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ calling electron-packager. This will print debug information from the specified
value of the environment variable is a comma-separated list of modules which support this logging
feature. Known modules include:

* `electron-download`
* `@electron/get:*`
* `electron-osx-sign`
* `electron-packager` (always use this one before filing an issue)
* `get-package-info`
Expand Down
15 changes: 7 additions & 8 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Not required if the [`all`](#all) option is set.
If `arch` is set to `all`, all supported architectures for the target platforms specified by [`platform`](#platform) will be built.
Arbitrary combinations of individual architectures are also supported via a comma-delimited string or array of strings.
The non-`all` values correspond to the architecture names used by [Electron releases]. This value
is not restricted to the official set if [`download.mirror`](#download) is set.
is not restricted to the official set if [`download.mirrorOptions`](#download) is set.

##### `asar`

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

*Object*

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


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

##### `prebuiltAsar`

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
},
"homepage": "https://github.com/electron-userland/electron-packager",
"dependencies": {
"@electron/get": "^1.2.0",
"asar": "^2.0.1",
"cross-zip": "^2.1.5",
"debug": "^4.0.1",
"electron-download": "^4.1.1",
"electron-notarize": "^0.1.1",
"electron-osx-sign": "^0.4.11",
"fs-extra": "^7.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ module.exports = {
boolean: [
'all',
'deref-symlinks',
'download.strictSSL',
'download.rejectUnauthorized',
'junk',
'overwrite',
'prune',
'quiet'
],
default: {
'deref-symlinks': true,
'download.strictSSL': true,
'download.rejectUnauthorized': true,
junk: true,
prune: true
},
Expand Down
6 changes: 3 additions & 3 deletions src/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

const common = require('./common')
const debug = require('debug')('electron-packager')
const download = require('electron-download')
const { promisify } = require('util')
const { downloadArtifact } = require('@electron/get')
const semver = require('semver')
const targets = require('./targets')

Expand All @@ -13,6 +12,7 @@ function createDownloadOpts (opts, platform, arch) {
common.subOptionWarning(downloadOpts, 'download', 'platform', platform, opts.quiet)
common.subOptionWarning(downloadOpts, 'download', 'arch', arch, opts.quiet)
common.subOptionWarning(downloadOpts, 'download', 'version', opts.electronVersion, opts.quiet)
common.subOptionWarning(downloadOpts, 'download', 'artifactName', 'electron', opts.quiet)

return downloadOpts
}
Expand All @@ -32,6 +32,6 @@ module.exports = {
downloadOpts.arch = 'arm'
}
debug(`Downloading Electron with options ${JSON.stringify(downloadOpts)}`)
return promisify(download)(downloadOpts)
return downloadArtifact(downloadOpts)
}
}
6 changes: 3 additions & 3 deletions src/targets.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

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

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

function usingOfficialElectronPackages (opts) {
return !opts.download || !opts.download.hasOwnProperty('mirror')
return !opts.download || !opts.download.hasOwnProperty('mirrorOptions')
}

function validOfficialPlatformArch (opts, platform, arch) {
Expand Down Expand Up @@ -107,7 +107,7 @@ module.exports = {
let list = opts[name]
if (!list) {
if (name === 'arch') {
list = hostArch()
list = getHostArch()
} else {
list = process[name]
}
Expand Down
6 changes: 3 additions & 3 deletions test/_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ async function downloadAll (version) {
async function downloadElectronZip (version, options) {
return download.downloadElectronZip({
...options,
cache: path.join(os.homedir(), '.electron'),
quiet: !!process.env.CI,
version: version
artifactName: 'electron',
cacheRoot: path.join(os.homedir(), '.electron'),
version
})
}

Expand Down
11 changes: 6 additions & 5 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const common = require('../src/common')
const download = require('../src/download')
const fs = require('fs-extra')
const hostArch = require('electron-download/lib/arch').host
const { getHostArch } = require('@electron/get')
const packager = require('..')
const path = require('path')
const sinon = require('sinon')
Expand Down Expand Up @@ -31,18 +31,19 @@ test('setting the quiet option does not print messages', t => {
t.true(console.error.notCalled, 'quieted common.info should not call console.error')
})

test('download argument test: download.{arch,platform,version} does not overwrite {arch,platform,version}', t => {
test('download argument test: download.{arch,platform,version,artifactName} does not overwrite {arch,platform,version,artifactName}', t => {
const opts = {
download: {
arch: 'ia32',
platform: 'win32',
version: '0.30.0'
version: '0.30.0',
artifactName: 'ffmpeg'
},
electronVersion: '0.36.0'
}

const downloadOpts = download.createDownloadOpts(opts, 'linux', 'x64')
t.deepEqual(downloadOpts, { arch: 'x64', platform: 'linux', version: '0.36.0' })
t.deepEqual(downloadOpts, { arch: 'x64', platform: 'linux', version: '0.36.0', artifactName: 'electron' })
})

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

const defaultOpts = {
arch: hostArch(),
arch: getHostArch(),
name: opts.name,
platform: process.platform
}
Expand Down
4 changes: 2 additions & 2 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ test('CLI argument test: --electron-version populates opts.electronVersion', t =
t.is(args.electronVersion, '1.2.3')
})

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

test('CLI argument test: --asar=true', t => {
Expand Down
4 changes: 2 additions & 2 deletions test/targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ test('platform=linux and arch=arm64 with an unsupported official Electron versio
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'))
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'))
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'))
test('unofficial arch', testMultiTarget({ arch: 'z80', platform: 'linux', download: { mirror: 'mirror' } }, 1,
test('unofficial arch', testMultiTarget({ arch: 'z80', platform: 'linux', download: { mirrorOptions: { mirror: 'mirror' } } }, 1,
'Package should be generated for non-standard arch from non-official mirror'))
test('unofficial platform', testMultiTarget({ arch: 'ia32', platform: 'minix', download: { mirror: 'mirror' } }, 1,
test('unofficial platform', testMultiTarget({ arch: 'ia32', platform: 'minix', download: { mirrorOptions: { mirror: 'mirror' } } }, 1,
'Package should be generated for non-standard platform from non-official mirror'))
15 changes: 9 additions & 6 deletions usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ asar whether to package the source code within your app into an ar
- unpackDir: unpacks the dir to the app.asar.unpacked directory whose names glob
pattern or exactly match this string. It's relative to the <sourcedir>.
build-version build version to set for the app
download a list of sub-options to pass to electron-download. They are specified via dot
notation, e.g., --download.cache=/tmp/cache
download a list of sub-options to pass to @electron/get. They are specified via dot
notation, e.g., --download.cacheRoot=/tmp/cache
Properties supported:
- cache: directory of cached Electron downloads. Defaults to `$HOME/.electron`
- mirror: alternate URL to download Electron zips
- strictSSL: whether SSL certs are required to be valid when downloading
Electron. Defaults to true, use --no-download.strictSSL to disable checks.
- cacheRoot: directory of cached Electron downloads. For default value, see
@electron/get documentation
- mirrorOptions: alternate URL options for downloading Electron zips. See
@electron/get documentation for details
- rejectUnauthorized: whether SSL certs are required to be valid when downloading
Electron. Defaults to true, use --no-download.rejectUnauthorized to disable
checks.
electron-version the version of Electron that is being packaged, see
https://github.com/electron/electron/releases
executable-name the name of the executable file, sans file extension. Defaults to appname
Expand Down