-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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(gatsby-source-contentful): Improve base64 placeholders #29034
Conversation
29746c1
to
d529588
Compare
) | ||
reject(e) | ||
}) | ||
const promise = new Promise(async (resolve, reject) => { |
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.
There shouldn't be a need to wrap this all in a Promise. It's an async function so it returns a promise anyway, and you can just await the fs-extra calls.
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.
We need the promise for the caching layer. Otherwise I'd have removed 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.
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.
Yeah, but async fucntions return promises anyway, so no need to wrap it like you've 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.
async function loadImage() {
..then:
const promise = loadImage()
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.
Well yeah I can make a small function that is called. I tried not to alter the code structure to much.
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.
@ascorbic done
const body = `data:image/jpeg;base64,${base64}` | ||
|
||
// TODO: against dogma, confirm whether writeFileSync is indeed slower | ||
fs.promises |
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.
You have fs-extra in the project which promisifies all of the fs calls, so you can just use that.
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.
But why go fs-extra if we have it supported in the language?
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 marked as stable api:
https://nodejs.org/dist/latest-v10.x/docs/api/fs.html#fs_fs_promises_api
This replaces the no more maintained
base64-img
package with a more native implementation.Additionally it fixes the following bug:
This should fix the security vulnerabilities from #24679