-
Notifications
You must be signed in to change notification settings - Fork 15k
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: some APIs modified for ASAR support cannot be util.promisify'ed #13845
Conversation
53fd254
to
ac480ad
Compare
ac480ad
to
f5708dc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
lib/common/asar.js
Outdated
@@ -27,6 +28,12 @@ | |||
return archive | |||
} | |||
|
|||
function assertNoCustomPromisify (func) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel as though these assertions should live inside tests, not runtime code 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something along the lines of
for (const key in originalFs) {
if (originalFs[key][util.promisify.custom] && !fs[key][util.promisify.custom]) {
// fail the test
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarshallOfSound that's a really good point. I didn't notice the originalFs
can be accessed in the tests. Done
lib/common/asar.js
Outdated
} | ||
const archive = getOrCreateArchive(asarPath) | ||
if (!archive) { | ||
return Promise.resolve(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inconsistent with the fs.exists
behavior above, in the case of an invalid archive it throws / calls back with an error. This method will fail transparently with a resolved false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarshallOfSound original fs.exists
never throws, it always returns either true
or false
. I can make it reject in this case though.
|
||
const archive = getOrCreateArchive(asarPath) | ||
if (!archive) { | ||
return new Promise(() => invalidArchiveError(asarPath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be return Promise.reject(invalidArchiveError(asarPath))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarshallOfSound that won't work, invalidArchiveError
throws the error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, this will result in a rejected promise right? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
|
||
const newPath = archive.copyFileOut(filePath) | ||
if (!newPath) { | ||
return new Promise(() => notFoundError(asarPath, filePath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be return Promise.reject(notFoundError(asarPath, filePath))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarshallOfSound that won't work, notFoundError
throws the error
spec/asar-spec.js
Outdated
@@ -644,6 +699,13 @@ describe('asar package', function () { | |||
done() | |||
}) | |||
}) | |||
|
|||
it('can be promisified', (done) => { | |||
util.promisify(ChildProcess.exec)('echo ' + echo + ' foo bar').then(({ stdout }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a promise so we don't need to use the done
technique. We can just return the promise in the test and the test will finish when the promise is resolved or rejected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarshallOfSound done
var p = path.join(fixtures, 'asar', 'a.asar', 'file1') | ||
// eslint-disable-next-line | ||
fs.exists(p, function (exists) { | ||
assert.equal(exists, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use expect
from the chair
package instead of assert
please, it will help the work that @codebytere is doing to improve our test suite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarshallOfSound I don't want that to be back-ported to 2.0. It's small amount of code compared to the rest of the tests.
93191f4
to
c0afb79
Compare
c0afb79
to
c2cb29a
Compare
An error occurred while attempting to backport this PR to "2-0-x", you will need to perform this backport manually |
We have automatically backported this PR to "3-0-x", please check out #13902 |
☝️ if you want to get this into a |
Fixes #13458
Promisification of the following functions is being fixed:
fs.exists()
child_process.exec()
child_process.execFile()
Checklist
npm test
passes