-
Notifications
You must be signed in to change notification settings - Fork 920
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
Improve encoding #882
Improve encoding #882
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pikapkg/snowpack/e8ld3l1m7 |
4199004
to
83d30e2
Compare
83d30e2
to
196dcba
Compare
export function getEncodingType(ext: string): 'utf-8' | 'binary' { | ||
return UTF8_FORMATS.includes(ext) ? 'utf-8' : 'binary'; | ||
export function getEncodingType(ext: string): 'utf-8' | undefined { | ||
return UTF8_FORMATS.includes(ext) ? 'utf-8' : undefined; |
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 the core change here; everything else is basically type changes from this
196dcba
to
f1be2f7
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.
TIL!
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.
Looks great! This should make things easier for plugins handling binary files.
@@ -184,23 +184,25 @@ export async function wrapImportProxy({ | |||
config, | |||
}: { | |||
url: string; | |||
code: string; | |||
code: string | Buffer; |
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.
WDYT about replacing all references to "code" with "content"? This should be a bit more consistent since we're no longer only handling 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.
So I agree, and tried to replace it, and realized that’s part of our plugin API now—a load()
plugin can provide a { code: string, map: string }
object if it’s generating source maps. Even though that’s still an “experimental” API, we should still double-check if we want to make that API change. Spun up an issue here: #910
f1be2f7
to
6cf09a7
Compare
c8f01bc
to
6cf09a7
Compare
Changes
Snowpack used
'binary'
as the encoding for binary files, but apparently that’s not what it means! It’s actually an alias forlatin1
meant for text files. For binary files, there’s no encoding, so nothing should be returned instead. This PR allows Snowpack to work with Buffers (binary files) more directly both inbuild
anddev
.Credit to @stramel for the find/suggestion!
Hopefully this will fix reported weirdness with binary files, such as https://www.pika.dev/npm/snowpack/discuss/505 and problems with video files @stramel noted.
Testing
Binary files work just fine in the build & dev server.