fix(aws-lambda): add globalThis.crypto polyfill#5024
Open
naveentehrpariya wants to merge 1 commit into
Open
Conversation
The lambda-edge adapter already ships this polyfill so handlers can use Web Crypto APIs (randomUUID, getRandomValues, subtle) without importing node:crypto explicitly. The aws-lambda adapter was missing it. Closes item 3 of honojs#5010.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
aws-lambdaadapter is missing theglobalThis.crypto ??= cryptopolyfill that
lambda-edgealready ships (added inlambda-edge/handler.ts:1,8).Without it, handlers that call Web Crypto APIs
(
crypto.randomUUID(),crypto.getRandomValues(),crypto.subtle.*)will throw on Lambda runtimes where
globalThis.cryptois not yetnatively available.
Closes item 3 of #5010.
Changes
src/adapter/aws-lambda/handler.ts— importnode:cryptoand setglobalThis.crypto ??= crypto(same two lines aslambda-edge)src/adapter/aws-lambda/handler.test.ts— add aglobalThis.crypto polyfilldescribe block verifying the global isdefined and
randomUUID()returns a valid v4 UUIDChecklist
npx vitest run src/adapter/aws-lambda/handler.test.ts→ 34/34)bun run format)npx tsc --noEmit)npx eslint src/adapter/aws-lambda/handler.ts src/adapter/aws-lambda/handler.test.ts)