fix: allow renaming electron.exe (#15173)

This commit is contained in:
Jeremy Apthorp 2018-10-15 17:26:34 -07:00 коммит произвёл GitHub
Родитель 0c711f690e
Коммит 30ccb6aea5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 39 добавлений и 0 удалений

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

@ -789,6 +789,16 @@ if (is_mac) {
"/DELAYLOAD:api-ms-win-core-winrt-l1-1-0.dll",
"/DELAYLOAD:api-ms-win-core-winrt-string-l1-1-0.dll",
]
# This is to support renaming of electron.exe. node-gyp has hard-coded
# executable names which it will recognise as node. This module definition
# file claims that the electron executable is in fact named "node.exe",
# which is one of the executable names that node-gyp recognizes.
# See https://github.com/nodejs/node-gyp/commit/52ceec3a6d15de3a8f385f43dbe5ecf5456ad07a
ldflags += [ "/DEF:" + rebase_path("build/electron.def", root_build_dir) ]
inputs = [
"build/electron.def",
]
}
if (is_linux) {
ldflags = [ "-pie" ]

6
build/electron.def Normal file
Просмотреть файл

@ -0,0 +1,6 @@
; This is to support renaming of electron.exe. node-gyp has hard-coded
; executable names which it will recognise as node. This module definition
; file claims that the electron executable is in fact named "node.exe",
; which is one of the executable names that node-gyp recognizes.
; See https://github.com/nodejs/node-gyp/commit/52ceec3a6d15de3a8f385f43dbe5ecf5456ad07a
NAME node.exe

6
spec/fixtures/module/runas-renamed.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
try {
require('runas')
} catch (e) {
process.exit(1)
}
process.exit(0)

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

@ -1,6 +1,7 @@
const assert = require('assert')
const Module = require('module')
const path = require('path')
const fs = require('fs')
const { remote } = require('electron')
const { BrowserWindow } = remote
const { closeWindow } = require('./window-helpers')
@ -24,6 +25,22 @@ describe('modules support', () => {
done()
})
})
if (process.platform === 'win32') {
it('can be required if electron.exe is renamed', () => {
const { execPath } = remote.process
const testExecPath = path.join(path.dirname(execPath), 'test.exe')
fs.copyFileSync(execPath, testExecPath)
try {
const runasFixture = path.join(fixtures, 'module', 'runas-renamed.js')
assert.ok(fs.existsSync(runasFixture))
const child = require('child_process').spawnSync(testExecPath, [runasFixture])
assert.strictEqual(child.status, 0)
} finally {
fs.unlinkSync(testExecPath)
}
})
}
})
// TODO(alexeykuzmin): Disabled during the Chromium 62 (Node.js 9) upgrade.