From 30ccb6aea52b913fcc9e1640b0eeccc452e8536d Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Mon, 15 Oct 2018 17:26:34 -0700 Subject: [PATCH] fix: allow renaming electron.exe (#15173) --- BUILD.gn | 10 ++++++++++ build/electron.def | 6 ++++++ spec/fixtures/module/runas-renamed.js | 6 ++++++ spec/modules-spec.js | 17 +++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 build/electron.def create mode 100644 spec/fixtures/module/runas-renamed.js diff --git a/BUILD.gn b/BUILD.gn index 67296aaf76..16479b4ed6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -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" ] diff --git a/build/electron.def b/build/electron.def new file mode 100644 index 0000000000..311ad202e6 --- /dev/null +++ b/build/electron.def @@ -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 diff --git a/spec/fixtures/module/runas-renamed.js b/spec/fixtures/module/runas-renamed.js new file mode 100644 index 0000000000..98b3dd89fa --- /dev/null +++ b/spec/fixtures/module/runas-renamed.js @@ -0,0 +1,6 @@ +try { + require('runas') +} catch (e) { + process.exit(1) +} +process.exit(0) diff --git a/spec/modules-spec.js b/spec/modules-spec.js index ba8004c5eb..89844f59f6 100644 --- a/spec/modules-spec.js +++ b/spec/modules-spec.js @@ -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.