Skip to content

Commit

Permalink
feat: upgrade to rcedit@^3.0.1 (#1260)
Browse files Browse the repository at this point in the history
  • Loading branch information
malept authored Jul 16, 2021
1 parent c30e584 commit 569c6bd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 41 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ npm install electron-packager -g
### Building Windows apps from non-Windows platforms

Building an Electron app for the Windows target platform requires editing the `Electron.exe` file.
Currently, Electron Packager uses [node-rcedit](https://github.com/atom/node-rcedit) to accomplish
Currently, Electron Packager uses [`node-rcedit`](https://github.com/atom/node-rcedit) to accomplish
this. A Windows executable is bundled in that Node package and needs to be run in order for this
functionality to work, so on non-Windows host platforms, [Wine](https://www.winehq.org/) 1.6 or
later needs to be installed. On macOS, it is installable via [Homebrew](http://brew.sh/).
functionality to work, so on non-Windows host platforms (not including WSL),
[Wine](https://www.winehq.org/) 1.6 or later needs to be installed. On macOS, it is installable
via [Homebrew](http://brew.sh/).

## Usage

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"@electron/get": "^1.6.0",
"asar": "^3.0.0",
"cross-spawn-windows-exe": "^1.2.0",
"debug": "^4.0.1",
"electron-notarize": "^1.0.0",
"electron-osx-sign": "^0.5.0",
Expand All @@ -39,7 +40,7 @@
"junk": "^3.1.0",
"parse-author": "^2.0.0",
"plist": "^3.0.0",
"rcedit": "^2.0.0",
"rcedit": "^3.0.1",
"resolve": "^1.1.6",
"semver": "^7.1.3",
"yargs-parser": "^20.0.0"
Expand Down
22 changes: 10 additions & 12 deletions src/win32.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

const debug = require('debug')('electron-packager')
const path = require('path')
const { WrapperError } = require('cross-spawn-windows-exe')

const App = require('./platform')
const common = require('./common')

function updateWineMissingException (err) {
if (err && err.code === 'ENOENT' && ['spawn wine', 'spawn wine64'].includes(err.syscall)) {
const binary = err.syscall.split(' ')[1]
err.message = `Could not find "${binary}" on your system.\n\n` +
if (err instanceof WrapperError) {
err.message += '\n\n' +
'Wine is required to use the appCopyright, appVersion, buildVersion, icon, and \n' +
'win32metadata parameters for Windows targets.\n\n' +
`Make sure that the "${binary}" executable is in your PATH.\n\n` +
'See https://github.com/electron/electron-packager#building-windows-apps-from-non-windows-platforms for details.'
}

Expand Down Expand Up @@ -85,17 +84,16 @@ class WindowsApp extends App {

const rcOpts = this.generateRceditOptionsSansIcon()

try {
const icon = await this.getIconPath()
if (icon) {
rcOpts.icon = icon
}
// Icon might be omitted or only exist in one OS's format, so skip it if normalizeExt reports an error
const icon = await this.getIconPath()
if (icon) {
rcOpts.icon = icon
}

debug(`Running rcedit with the options ${JSON.stringify(rcOpts)}`)
debug(`Running rcedit with the options ${JSON.stringify(rcOpts)}`)
try {
await require('rcedit')(this.electronBinaryPath, rcOpts)
} catch (err) {
// Icon might be omitted or only exist in one OS's format, so skip it if normalizeExt reports an error
/* istanbul ignore next */
throw updateWineMissingException(err)
}
}
Expand Down
55 changes: 30 additions & 25 deletions test/win32.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const path = require('path')
const test = require('ava')
const util = require('./_util')
const win32 = require('../src/win32')
const { WrapperError } = require('cross-spawn-windows-exe')

const win32Opts = {
name: 'basicTest',
Expand Down Expand Up @@ -134,36 +135,40 @@ function setCompanyNameTest (companyName) {
'Company name should match win32metadata value')
}

for (const wineBinary of ['wine', 'wine64']) {
test(`better error message when ${wineBinary} is not found`, t => {
let err = Error(`spawn ${wineBinary} ENOENT`)
err.code = 'ENOENT'
err.syscall = `spawn ${wineBinary}`
test('better error message when wine is not found', t => {
const err = new WrapperError('wine-nonexistent')

t.is(err.message, `spawn ${wineBinary} ENOENT`)
err = win32.updateWineMissingException(err)
t.not(err.message, `spawn ${wineBinary} ENOENT`)
})
}

test('error message unchanged when error not about wine/wine64', t => {
let errNotEnoent = Error('unchanged')
errNotEnoent.code = 'ESOMETHINGELSE'
errNotEnoent.syscall = 'spawn wine'

t.is(errNotEnoent.message, 'unchanged')
errNotEnoent = win32.updateWineMissingException(errNotEnoent)
t.is(errNotEnoent.message, 'unchanged')
t.notRegex(err.message, /win32metadata/)
const augmentedError = win32.updateWineMissingException(err)
t.regex(augmentedError.message, /win32metadata/)
})

let errNotSpawnWine = Error('unchanged')
errNotSpawnWine.code = 'ENOENT'
errNotSpawnWine.syscall = 'spawn foo'
test('error message unchanged when error not about wine missing', t => {
const notWrapperError = Error('Not a wrapper error')

t.is(errNotSpawnWine.message, 'unchanged')
errNotSpawnWine = win32.updateWineMissingException(errNotSpawnWine)
t.is(errNotSpawnWine.message, 'unchanged')
const returnedError = win32.updateWineMissingException(notWrapperError)
t.is(returnedError.message, 'Not a wrapper error')
})

// Wine-using platforms only; macOS exhibits a strange behavior in CI,
// so we're disabling it there as well.
if (process.platform === 'linux') {
test.serial('win32 integration: catches a missing wine executable', util.packagerTest(async (t, opts) => {
process.env.WINE_BINARY = 'wine-nonexistent'
try {
await t.throwsAsync(() => packager({
...opts,
...win32Opts
}), {
instanceOf: WrapperError,
message: /wine-nonexistent.*win32metadata/ms
})
} finally {
delete process.env.WINE_BINARY
}
}))
}

test('win32metadata defaults', t => {
const opts = { name: 'Win32 App' }
const rcOpts = generateRceditOptionsSansIcon(opts)
Expand Down

0 comments on commit 569c6bd

Please sign in to comment.