diff --git a/lib/common/asar.js b/lib/common/asar.js index 20385da135967..52078f80a6bcd 100644 --- a/lib/common/asar.js +++ b/lib/common/asar.js @@ -3,6 +3,7 @@ const {Buffer} = require('buffer') const childProcess = require('child_process') const path = require('path') + const util = require('util') const hasProp = {}.hasOwnProperty @@ -680,18 +681,27 @@ // called by `childProcess.{exec,execSync}`, causing // Electron to consider the full command as a single path // to an archive. - ['exec', 'execSync'].forEach(function (functionName) { - const old = childProcess[functionName] - childProcess[functionName] = function () { - const processNoAsarOriginalValue = process.noAsar - process.noAsar = true - try { - return old.apply(this, arguments) - } finally { - process.noAsar = processNoAsarOriginalValue + for (const functionName of ['exec', 'execSync']) { + childProcess[functionName] = wrap(childProcess[functionName], function (func) { + return function () { + const processNoAsarOriginalValue = process.noAsar + process.noAsar = true + try { + return func.apply(this, arguments) + } finally { + process.noAsar = processNoAsarOriginalValue + } } + }) + } + + function wrap (func, wrapper) { + const wrapped = wrapper(func) + if (func[util.promisify.custom]) { + wrapped[util.promisify.custom] = wrapper(func[util.promisify.custom]) } - }) + return wrapped + } overrideAPI(fs, 'open') overrideAPI(childProcess, 'execFile') diff --git a/spec/asar-spec.js b/spec/asar-spec.js index 131619d5f2198..cc477093849d2 100644 --- a/spec/asar-spec.js +++ b/spec/asar-spec.js @@ -2,6 +2,7 @@ const assert = require('assert') const ChildProcess = require('child_process') const fs = require('fs') const path = require('path') +const util = require('util') const {closeWindow} = require('./window-helpers') const nativeImage = require('electron').nativeImage @@ -644,6 +645,13 @@ describe('asar package', function () { done() }) }) + + it('can be promisified', (done) => { + util.promisify(ChildProcess.exec)('echo ' + echo + ' foo bar').then(({ stdout }) => { + assert.equal(stdout.toString().replace(/\r/g, ''), echo + ' foo bar\n') + done() + }) + }) }) describe('child_process.execSync', function () {