Add electronVersion option & deprecate version

This commit is contained in:
Mark Lee 2017-01-02 18:30:40 -08:00
Родитель e2d69c823f
Коммит b633f8935c
15 изменённых файлов: 94 добавлений и 35 удалений

Просмотреть файл

@ -32,6 +32,7 @@ function parseCLIArgs (argv) {
prune: true
},
string: [
'electron-version',
'out'
]
})
@ -52,6 +53,10 @@ function parseCLIArgs (argv) {
args.out = null
}
// Transform hyphenated keys into camelCase
args.electronVersion = args['electron-version']
delete args['electron-version']
// Overrides for multi-typed arguments, because minimist doesn't support it
// asar: `Object` or `true`
@ -140,7 +145,7 @@ function createDownloadOpts (opts, platform, arch) {
subOptionWarning(downloadOpts, 'download', 'platform', platform, opts.quiet)
subOptionWarning(downloadOpts, 'download', 'arch', arch, opts.quiet)
subOptionWarning(downloadOpts, 'download', 'version', opts.version, opts.quiet)
subOptionWarning(downloadOpts, 'download', 'version', opts.electronVersion, opts.quiet)
return downloadOpts
}
@ -173,6 +178,19 @@ module.exports = {
return combinations
},
deprecatedParameter: function deprecatedParameter (properties, oldName, newName, extraCondition/* optional */) {
if (extraCondition === undefined) {
extraCondition = true
}
if (properties.hasOwnProperty(oldName) && extraCondition) {
warning(`The ${oldName} parameter is deprecated, use ${newName} instead`)
if (!properties.hasOwnProperty(newName)) {
properties[newName] = properties[oldName]
}
delete properties[oldName]
}
},
downloadElectronZip: function downloadElectronZip (downloadOpts, cb) {
// armv7l builds have only been backfilled for Electron >= 1.0.0.
// See: https://github.com/electron/electron/pull/6986
@ -226,7 +244,7 @@ module.exports = {
function (cb) {
var afterCopyHooks = (opts.afterCopy || []).map(function (afterCopyFn) {
return function (cb) {
afterCopyFn(appPath, opts.version, opts.platform, opts.arch, cb)
afterCopyFn(appPath, opts.electronVersion, opts.platform, opts.arch, cb)
}
})
series(afterCopyHooks, cb)

Просмотреть файл

@ -116,6 +116,15 @@ but are not limited to:
- `strictSSL` (*Boolean* - default: `true`): Whether SSL certificates are required to be valid when
downloading Electron.
##### `electronVersion`
*String*
The Electron version with which the app is built (without the leading 'v') - for example,
[`1.4.13`](https://github.com/electron/electron/releases/tag/v1.4.13). See [Electron releases] for
valid versions. If omitted, it will use the version of the nearest local installation of
`electron` or `electron-prebuilt`, defined in `package.json` in either `dependencies` or `devDependencies`.
##### `icon`
*String*
@ -215,12 +224,8 @@ The base directory to use as a temp directory. Set to `false` to disable use of
##### `version`
*String*
The Electron version with which the app is built (without the leading 'v') - for example,
[`0.33.9`](https://github.com/electron/electron/releases/tag/v0.33.9). See [Electron releases] for
valid versions. If omitted, it will use the version of the nearest local installation of
`electron` or `electron-prebuilt`, defined in `package.json` in either `dependencies` or `devDependencies`.
*String* (**deprecated** and will be removed in a future major version, please use the
[`electronVersion`](#electronversion) parameter instead)
#### OS X/Mac App Store targets only

Просмотреть файл

@ -23,7 +23,7 @@ function getMetadata (opts, dir, cb) {
var props = []
if (!opts.name) props.push(['productName', 'name'])
if (!opts['app-version']) props.push('version')
if (!opts.version) {
if (!opts.electronVersion) {
props.push([
'dependencies.electron',
'devDependencies.electron',
@ -106,7 +106,7 @@ function getVersion (opts, packageName, src, cb) {
}, (err, res, pkg) => {
if (err) return cb(err)
debug(`Inferring target Electron version from ${packageName} in ${src}`)
opts.version = pkg.version
opts.electronVersion = pkg.version
return cb(null)
})
}
@ -239,11 +239,13 @@ module.exports = function packager (opts, cb) {
debug(`Target Platforms: ${platforms.join(', ')}`)
debug(`Target Architectures: ${archs.join(', ')}`)
common.deprecatedParameter(opts, 'version', 'electronVersion')
getMetadata(opts, path.resolve(process.cwd(), opts.dir) || process.cwd(), function (err) {
if (err) return cb(err)
debug(`Application name: ${opts.name}`)
debug(`Target Electron version: ${opts.version}`)
debug(`Target Electron version: ${opts.electronVersion}`)
ignore.generateIgnores(opts)

2
mac.js
Просмотреть файл

@ -195,7 +195,7 @@ class MacApp {
enqueueAppSigningIfSpecified () {
let osxSignOpt = this.opts['osx-sign']
let platform = this.opts.platform
let version = this.opts.version
let version = this.opts.electronVersion
if ((platform === 'all' || platform === 'mas') &&
osxSignOpt === undefined) {

Просмотреть файл

@ -15,7 +15,7 @@ function createDefaultAppAsarTest (opts) {
opts.name = 'el0374Test'
opts.dir = path.join(__dirname, 'fixtures', 'el-0374')
opts.version = '0.37.4'
opts.electronVersion = '0.37.4'
var resourcesPath

Просмотреть файл

@ -210,7 +210,7 @@ function createInferElectronPrebuiltTest (opts) {
t.timeoutAfter(config.timeout)
// Don't specify name or version
delete opts.version
delete opts.electronVersion
opts.dir = path.join(__dirname, 'fixtures', 'basic')
var finalPath
@ -252,7 +252,7 @@ function createInferElectronTest (opts) {
t.timeoutAfter(config.timeout)
// Don't specify name or version
delete opts.version
delete opts.electronVersion
opts.dir = path.join(__dirname, 'fixtures', 'basic-renamed-to-electron')
var packageJSON = require(path.join(opts.dir, 'package.json'))
@ -290,7 +290,7 @@ function createInferFailureTest (opts, fixtureSubdir) {
copyFixtureToTempDir(fixtureSubdir, (err, dir) => {
if (err) return t.end(err)
delete opts.version
delete opts.electronVersion
opts.dir = dir
packager(opts, function (err, paths) {
@ -307,7 +307,7 @@ function createInferMissingVersionTest (opts) {
copyFixtureToTempDir('infer-missing-version-only', (err, dir) => {
if (err) return t.end(err)
delete opts.version
delete opts.electronVersion
opts.dir = dir
let packageJSON = require(path.join(opts.dir, 'package.json'))
@ -450,7 +450,7 @@ test('download argument test: download.{arch,platform,version} does not overwrit
platform: 'win32',
version: '0.30.0'
},
version: '0.36.0'
electronVersion: '0.36.0'
}
var downloadOpts = common.createDownloadOpts(opts, 'linux', 'x64')
@ -496,7 +496,7 @@ util.packagerTest('building for Linux target sanitizes binary name', (t) => {
let opts = {
name: '@username/package-name',
dir: path.join(__dirname, 'fixtures', 'el-0374'),
version: '0.37.4',
electronVersion: '0.37.4',
arch: 'ia32',
platform: 'linux'
}
@ -544,7 +544,7 @@ util.packagerTest('fails with invalid version', (t) => {
let opts = {
name: 'invalidElectronTest',
dir: path.join(__dirname, 'fixtures', 'el-0374'),
version: '0.0.1',
electronVersion: '0.0.1',
arch: 'x64',
platform: 'linux',
download: {
@ -558,11 +558,36 @@ util.packagerTest('fails with invalid version', (t) => {
})
})
util.packagerTest('electronVersion overrides deprecated version', (t) => {
const opts = {
electronVersion: '0.1.2',
version: '1.2.3'
}
common.deprecatedParameter(opts, 'version', 'electronVersion')
t.equal(opts.electronVersion, '0.1.2', 'electronVersion should not change')
t.equal(opts.version, undefined, 'version should be deleted')
t.end()
})
util.packagerTest('version used if electronVersion not set', (t) => {
const opts = {
version: '1.2.3'
}
common.deprecatedParameter(opts, 'version', 'electronVersion')
t.equal(opts.electronVersion, '1.2.3', 'electronVersion have version value')
t.equal(opts.version, undefined, 'version should be deleted')
t.end()
})
util.packagerTest('dir argument test: should work with relative path', (t) => {
let opts = {
name: 'ElectronTest',
dir: path.join('..', 'fixtures', 'el-0374'),
version: '0.37.4',
electronVersion: '0.37.4',
arch: 'x64',
platform: 'linux'
}

Просмотреть файл

@ -3,6 +3,14 @@
const common = require('../common')
const test = require('tape')
test('CLI argument test: --electron-version populates opts.electronVersion', (t) => {
let args = common.parseCLIArgs([])
t.equal(args.electronVersion, undefined)
args = common.parseCLIArgs(['--electron-version=1.2.3'])
t.equal(args.electronVersion, '1.2.3')
t.end()
})
test('CLI argument test: --download.strictSSL default', function (t) {
var args = common.parseCLIArgs([])
t.true(args.download.strictSSL, 'default for --download.strictSSL is true')

Просмотреть файл

@ -6,7 +6,7 @@ const path = require('path')
var baseOpts = {
name: 'basicTest',
dir: path.join(__dirname, 'fixtures', 'basic'),
version: config.version,
electronVersion: config.version,
arch: 'x64',
platform: 'darwin'
}

Просмотреть файл

@ -13,14 +13,14 @@ function createHookTest (hookName) {
var opts = {
name: 'basicTest',
dir: util.fixtureSubdir('basic'),
version: config.version,
electronVersion: config.version,
arch: 'ia32',
platform: 'all'
}
opts[hookName] = [function testHook (buildPath, electronVersion, platform, arch, callback) {
hookCalled = true
t.equal(electronVersion, opts.version, hookName + ' electronVersion should be the same as the options object')
t.equal(electronVersion, opts.electronVersion, hookName + ' electronVersion should be the same as the options object')
t.equal(arch, opts.arch, hookName + ' arch should be the same as the options object')
callback()
}]

Просмотреть файл

@ -527,7 +527,7 @@ module.exports = (baseOpts) => {
let el0374Opts = {
name: 'el0374Test',
dir: util.fixtureSubdir('el-0374'),
version: '0.37.4',
electronVersion: '0.37.4',
arch: 'x64',
platform: 'darwin'
}

Просмотреть файл

@ -6,7 +6,7 @@ const util = require('./util')
var baseOpts = {
name: 'basicTest',
dir: util.fixtureSubdir('basic'),
version: config.version,
electronVersion: config.version,
arch: 'x64',
platform: 'mas'
}

Просмотреть файл

@ -14,7 +14,7 @@ function createMultiTest (arch, platform) {
var opts = {
name: 'basicTest',
dir: util.fixtureSubdir('basic'),
version: config.version,
electronVersion: config.version,
arch: arch,
platform: platform
}
@ -41,7 +41,7 @@ util.packagerTest('all test', (t) => {
var opts = {
name: 'basicTest',
dir: util.fixtureSubdir('basic'),
version: config.version,
electronVersion: config.version,
all: true
}
@ -79,7 +79,7 @@ util.packagerTest('platform=all test (one arch)', function (t) {
var opts = {
name: 'basicTest',
dir: util.fixtureSubdir('basic'),
version: config.version,
electronVersion: config.version,
arch: 'ia32',
platform: 'all'
}
@ -106,7 +106,7 @@ util.packagerTest('arch=all test (one platform)', (t) => {
var opts = {
name: 'basicTest',
dir: util.fixtureSubdir('basic'),
version: config.version,
electronVersion: config.version,
arch: 'all',
platform: 'linux'
}

Просмотреть файл

@ -26,7 +26,7 @@ exports.areFilesEqual = function areFilesEqual (file1, file2, callback) {
}
exports.downloadAll = function downloadAll (version, callback) {
let combinations = common.createDownloadCombos({version: config.version}, common.platforms, common.archs, (platform, arch) => {
let combinations = common.createDownloadCombos({electronVersion: config.version}, common.platforms, common.archs, (platform, arch) => {
// Skip testing darwin/mas target on Windows since electron-packager itself skips it
// (see https://github.com/electron-userland/electron-packager/issues/71)
return common.isPlatformMac(platform) && process.platform === 'win32'
@ -87,7 +87,7 @@ exports.packagerTest = function packagerTest (name, testFunction) {
exports.testSinglePlatform = function testSinglePlatform (name, createTest /*, ...createTestArgs */) {
var args = slice.call(arguments, 2)
exports.packagerTest(name, createTest.apply(null, [{platform: 'linux', arch: 'x64', version: config.version}].concat(args)))
exports.packagerTest(name, createTest.apply(null, [{platform: 'linux', arch: 'x64', electronVersion: config.version}].concat(args)))
}
exports.verifyPackageExistence = function verifyPackageExistence (finalPaths, callback) {

Просмотреть файл

@ -13,7 +13,7 @@ const win32 = require('../win32')
const baseOpts = {
name: 'basicTest',
dir: util.fixtureSubdir('basic'),
version: config.version,
electronVersion: config.version,
arch: 'x64',
platform: 'win32'
}

Просмотреть файл

@ -39,6 +39,8 @@ download a list of sub-options to pass to electron-download. They are
- mirror: alternate URL to download Electron zips
- strictSSL: whether SSL certs are required to be valid when downloading
Electron. Defaults to true, use --download.strictSSL=false to disable checks.
electron-version the version of Electron that is being packaged, see
https://github.com/electron/electron/releases
icon the local path to an icon file to use as the icon for the app.
Note: Format depends on platform.
ignore do not copy files into app whose filenames regex .match this string. See also:
@ -53,8 +55,7 @@ platform all, or one or more of: darwin, linux, mas, win32 (comma-deli
quiet Do not print informational or warning messages
tmpdir temp directory. Defaults to system temp directory, use --tmpdir=false to disable
use of a temporary directory.
version the version of Electron that is being packaged, see
https://github.com/electron/electron/releases
version an alias for electron-version (deprecated)
* darwin/mas target platforms only *