-
-
Notifications
You must be signed in to change notification settings - Fork 283
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: replace pify
with simpler promise helpers
#221
fix: replace pify
with simpler promise helpers
#221
Conversation
src/utils/readFilePromise.js
Outdated
@@ -0,0 +1,10 @@ | |||
export default function readFilePromise(inputFileSystem, path) { |
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.
src/utils/promisify.js
export const stat = ...
export const readFile = ...
import { stat, readFile } from './utils/promisify';
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.
On it.
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.
Done.
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.
Thanks for help!
pify
with a simpler promise helpers
pify
with a simpler promise helperspify
with simpler promise helpers
`pify` seems to not be working correctly when a decorated file system is used as `inputFileSystem`. Fix #217
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.
@filipesilva Thx
Thank you for the fix! |
New version 4.4.1 did it! Thanks! Deploy to Heroku works as well. |
@evilebottnawi looked a bit more into why For the decorated file system in Angular CLI we used a TypeScript class, which downlevels to a ES6 class. It seems |
I don't understand why the fix is so overcomplicated though. You could have just used |
@sindresorhus in hindsight, that would have been a great solution. At the time I did not know only one of the We were looking at getting a fix in since it was affecting a lot of users in angular/angular-cli#9550. After fixing the issue proper I went to report the issue on |
inputFileSystem.stat(path, (err, stats) => { | ||
if (err) { | ||
reject(err); | ||
} |
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.
Without an else
or early return
statement, resolve
will even be called in the case of a rejection. Same is the case for readFile
below.
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.
@ronkorving reject already do early exit, no necessary return
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.
How can it? To my knowledge, the only way to return early in JS is return
or throw
.
reject(err)
is just a function call.
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.
@ronkorving reject()
=== throw
inside promise
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.
It is true that resolve(stats)
will still be called, but the stats
value will not be passed on to anything. Even if there is another promise waiting for the resolve value, the rejection path will be taken instead.
It's a still a bug though, in the sense that it was never intended for the resolve
to run in the first place.
@evilebottnawi WDYT of me doing another PR that adds back pify
with the alternative syntax that works on ES6 classes?
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.
@ronkorving IMHO, return
here need only for easy reading and understanding code. Feel free to PR if this confusing for you
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.
@evilebottnawi I don't think I'm confused. As @filipesilva also pointed out, resolve(stats)
will still be called.
I'll leave it to you both to figure out the way forward, given that there seems to be a desire to put pify
back in anyway.
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 tried #228 but just using pify
on the single method doesn't seem to work well either, this
seems to be undefined when doing that so class members aren't accessible.
@ronkorving would you like to make a PR to change the if
to a if ... else
?
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.
if (err) reject(err) // I'm not 100% here, but this should be === (x) => x (return)
resolve(x)
if (err) {
return reject(err)
}
resolve(x)
if (err) {
reject(err)
// eventually to guard against 'runaway' promises
return null
}
resolve(x)
Please no extra lib, it's not necessary to promisify
two callback functions :)
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.
@ronkorving Thx. Nice catch :)
I noticed what I believe to be a bug in this PR and left a comment. |
pify
seems to not be working correctly when a decorated file system is used asinputFileSystem
.Fix #217