-
Notifications
You must be signed in to change notification settings - Fork 549
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7941ea2
commit 48f8c98
Showing
11 changed files
with
503 additions
and
51 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { PolyfilledRuntimeEnvironment } from "./types"; | ||
|
||
export const polyfill = ( | ||
environment: Record<keyof PolyfilledRuntimeEnvironment, unknown> | ||
) => { | ||
Object.entries(environment).map(([name, value]) => { | ||
Object.defineProperty(globalThis, name, { | ||
value, | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
}); | ||
}); | ||
}; |
14 changes: 14 additions & 0 deletions
14
packages/pages-shared/src/environment-polyfills/miniflare.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { | ||
fetch as miniflareFetch, | ||
Headers as MiniflareHeaders, | ||
Request as MiniflareRequest, | ||
Response as MiniflareResponse, | ||
} from "@miniflare/core"; | ||
import { polyfill } from "."; | ||
|
||
polyfill({ | ||
fetch: miniflareFetch, | ||
Headers: MiniflareHeaders, | ||
Request: MiniflareRequest, | ||
Response: MiniflareResponse, | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
Headers as MiniflareHeaders, | ||
Request as MiniflareRequest, | ||
Response as MiniflareResponse, | ||
} from "@miniflare/core"; | ||
import { HTMLRewriter as MiniflareHTMLRewriter } from "@miniflare/html-rewriter"; | ||
import type { CacheInterface as MiniflareCacheInterface } from "@miniflare/cache"; | ||
import type { fetch as miniflareFetch } from "@miniflare/core"; | ||
import type { ReadableStream as SimilarReadableStream } from "stream/web"; | ||
|
||
declare global { | ||
const fetch: typeof miniflareFetch; | ||
class Headers extends MiniflareHeaders {} | ||
class Request extends MiniflareRequest {} | ||
class Response extends MiniflareResponse {} | ||
|
||
type CacheInterface = Omit<MiniflareCacheInterface, "match"> & { | ||
match( | ||
...args: Parameters<MiniflareCacheInterface["match"]> | ||
): Promise<Response | undefined>; | ||
}; | ||
|
||
class CacheStorage { | ||
get default(): CacheInterface; | ||
open(cacheName: string): Promise<CacheInterface>; | ||
} | ||
|
||
class HTMLRewriter extends MiniflareHTMLRewriter { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
transform(response: Response): Response; | ||
} | ||
|
||
type ReadableStream = SimilarReadableStream; | ||
} | ||
|
||
export type PolyfilledRuntimeEnvironment = { | ||
fetch: typeof fetch; | ||
Headers: typeof Headers; | ||
Request: typeof Request; | ||
Response: typeof Response; | ||
}; | ||
|
||
export { fetch, Headers, Request, Response }; |
This file contains 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
This file contains 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
This file contains 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