-
Notifications
You must be signed in to change notification settings - Fork 92
fix: add Buffer shim if is not globally available, adjust process and AsyncLocalStorage shims to only be applied when not available #3222
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
Conversation
… AsyncLocalStorage shims to only be applied when not available
📊 Package size report 0.01%↑
Unchanged files
🤖 This report was automatically generated by pkg-size-action |
| if (typeof process === 'undefined') { | ||
| globalThis.process = (await import('node:process')).default | ||
| } |
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.
process is available in deno 2, not in deno 1
| if (typeof AsyncLocalStorage === 'undefined') { | ||
| globalThis.AsyncLocalStorage = (await import('node:async_hooks')).AsyncLocalStorage | ||
| } |
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 overall not globally available - it seems like Next.js quirk to expect it to be globally defined, checked if it is available just to be in line with other shims here
| if (typeof Buffer === 'undefined') { | ||
| globalThis.Buffer = (await import('node:buffer')).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.
this is fun one - Buffer is not globally defined in deno 1.39.0, 1.46.3 or 2.2.4 (from tested versions), but is available in 2.4.2
Description
We discovered some problems when trying to bump deno version in #3221 which seemed to require adding
Bufferglobal shim. While doing so I figured it might make sense to only try to apply global shims conditionally if they things are not globally available already