Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support async child process methods without callback in asar #15927

Merged
merged 2 commits into from Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/common/asar.js
Expand Up @@ -143,10 +143,10 @@
return error
}

const overrideAPISync = function (module, name, pathArgumentIndex) {
const overrideAPISync = function (module, name, pathArgumentIndex, fromAsync) {
if (pathArgumentIndex == null) pathArgumentIndex = 0
const old = module[name]
module[name] = function () {
const func = function () {
const pathArgument = arguments[pathArgumentIndex]
const { isAsar, asarPath, filePath } = splitPath(pathArgument)
if (!isAsar) return old.apply(this, arguments)
Expand All @@ -160,6 +160,10 @@
arguments[pathArgumentIndex] = newPath
return old.apply(this, arguments)
}
if (fromAsync) {
return func
}
module[name] = func
}

const overrideAPI = function (module, name, pathArgumentIndex) {
Expand All @@ -172,7 +176,7 @@

const callback = arguments[arguments.length - 1]
if (typeof callback !== 'function') {
return overrideAPISync(module, name, pathArgumentIndex)
return overrideAPISync(module, name, pathArgumentIndex, true).apply(this, arguments)
}

const archive = getOrCreateArchive(asarPath)
Expand Down
12 changes: 12 additions & 0 deletions spec/asar-spec.js
Expand Up @@ -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 () {
const output = execFileSync(echo, ['test'])
assert.strictEqual(String(output), 'test\n')
Expand Down