Skip to content

Commit

Permalink
Handle inference where electron-prebuilt-compile points to a non-version
Browse files Browse the repository at this point in the history
Fixes #975.
  • Loading branch information
malept committed Apr 16, 2019
1 parent 4dd30ab commit 4aeb521
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/infer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,24 @@ function resolvePromise (id, options) {
})
}

function rangeFromElectronVersion (electronVersion) {
try {
return new semver.Range(electronVersion)
} catch (error) {
return null
}
}

async function getVersion (opts, electronProp) {
const [depType, packageName] = electronProp.prop.split('.')
const src = electronProp.src
if (packageName === 'electron-prebuilt-compile') {
// electron-prebuilt-compile cannot be resolved because `main` does not point
// to a valid JS file.
const electronVersion = electronProp.pkg[depType][packageName]
const versionRange = new semver.Range(electronVersion)
if (versionRange.intersects(new semver.Range('< 1.6.5'))) {
const versionRange = rangeFromElectronVersion(electronVersion)
if (versionRange !== null && versionRange.intersects(new semver.Range('< 1.6.5'))) {
if (!/^\d+\.\d+\.\d+/.test(electronVersion)) {
// electron-prebuilt-compile cannot be resolved because `main` does not point
// to a valid JS file.
throw new Error('Using electron-prebuilt-compile with Electron Packager requires specifying an exact Electron version')
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"main": "main.js",
"productName": "MainJS",
"devDependencies": {
"electron-prebuilt-compile": "@scoped/electron-prebuilt-compile"
}
}
7 changes: 7 additions & 0 deletions test/infer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ test('infer using `electron-prebuilt` package', util.testSinglePlatform(inferEle
test('infer using `electron-nightly` package', util.testSinglePlatform(inferElectronVersionTest, 'infer-electron-nightly', 'electron-nightly'))
test('infer using `electron-prebuilt-compile` package', util.testSinglePlatform(inferElectronVersionTest, 'infer-electron-prebuilt-compile', 'electron-prebuilt-compile'))
test('infer using non-exact `electron-prebuilt-compile` package', util.testSinglePlatform(inferElectronVersionTest, 'infer-non-specific-electron-prebuilt-compile', 'electron-prebuilt-compile'))
test('infer when electron-prebuilt-compile dependency points to URL instead of version', util.testSinglePlatform(async (t, opts) => {
delete opts.electronVersion
opts.dir = util.fixtureSubdir('infer-non-version-electron-prebuilt-compile')

await getMetadataFromPackageJSON([], opts, opts.dir)
t.is(opts.electronVersion, '2.0.10', 'Electron version matches the value in the electron-prebuilt-compile package.json')
}))
test('infer using `electron` package only', util.testSinglePlatform(inferMissingVersionTest))
test('infer where `electron` version is preferred over `electron-prebuilt`', util.testSinglePlatform(inferElectronVersionTest, 'basic-renamed-to-electron', 'electron'))
test('infer win32metadata', util.testSinglePlatform(async (t, opts) => {
Expand Down

0 comments on commit 4aeb521

Please sign in to comment.