fix: support async child process methods without callback in asar (#15927)
* fix: support async child process methods without callback in asar * fix: support async child process methods without callback in asar (improved)
This commit is contained in:
parent
6c998aa4f2
commit
dc93d94bc8
2 changed files with 19 additions and 3 deletions
|
@ -143,10 +143,10 @@
|
||||||
return error
|
return error
|
||||||
}
|
}
|
||||||
|
|
||||||
const overrideAPISync = function (module, name, pathArgumentIndex) {
|
const overrideAPISync = function (module, name, pathArgumentIndex, fromAsync) {
|
||||||
if (pathArgumentIndex == null) pathArgumentIndex = 0
|
if (pathArgumentIndex == null) pathArgumentIndex = 0
|
||||||
const old = module[name]
|
const old = module[name]
|
||||||
module[name] = function () {
|
const func = function () {
|
||||||
const pathArgument = arguments[pathArgumentIndex]
|
const pathArgument = arguments[pathArgumentIndex]
|
||||||
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
|
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
|
||||||
if (!isAsar) return old.apply(this, arguments)
|
if (!isAsar) return old.apply(this, arguments)
|
||||||
|
@ -160,6 +160,10 @@
|
||||||
arguments[pathArgumentIndex] = newPath
|
arguments[pathArgumentIndex] = newPath
|
||||||
return old.apply(this, arguments)
|
return old.apply(this, arguments)
|
||||||
}
|
}
|
||||||
|
if (fromAsync) {
|
||||||
|
return func
|
||||||
|
}
|
||||||
|
module[name] = func
|
||||||
}
|
}
|
||||||
|
|
||||||
const overrideAPI = function (module, name, pathArgumentIndex) {
|
const overrideAPI = function (module, name, pathArgumentIndex) {
|
||||||
|
@ -172,7 +176,7 @@
|
||||||
|
|
||||||
const callback = arguments[arguments.length - 1]
|
const callback = arguments[arguments.length - 1]
|
||||||
if (typeof callback !== 'function') {
|
if (typeof callback !== 'function') {
|
||||||
return overrideAPISync(module, name, pathArgumentIndex)
|
return overrideAPISync(module, name, pathArgumentIndex, true).apply(this, arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
const archive = getOrCreateArchive(asarPath)
|
const archive = getOrCreateArchive(asarPath)
|
||||||
|
|
|
@ -912,6 +912,18 @@ describe('asar package', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('executes binaries without callback', function (done) {
|
||||||
|
const process = execFile(echo, ['test'])
|
||||||
|
process.on('close', function (code) {
|
||||||
|
assert.strictEqual(code, 0)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
process.on('error', function () {
|
||||||
|
assert.fail()
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('execFileSync executes binaries', function () {
|
it('execFileSync executes binaries', function () {
|
||||||
const output = execFileSync(echo, ['test'])
|
const output = execFileSync(echo, ['test'])
|
||||||
assert.strictEqual(String(output), 'test\n')
|
assert.strictEqual(String(output), 'test\n')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue