Skip to content

Commit

Permalink
Add global crypto to @astrojs/webapi (#6981)
Browse files Browse the repository at this point in the history
* add crypto to be polyfilled

* chore: changeset

* chore: update deps for node types

---------

Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
Co-authored-by: Princesseuh <princssdev@gmail.com>
  • Loading branch information
3 people authored May 26, 2023
1 parent 52af9ad commit bf63f61
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-months-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/webapi': minor
---

Add polyfill for `crypto`
2 changes: 1 addition & 1 deletion packages/telemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/dlv": "^1.1.2",
"@types/node": "^14.18.21",
"@types/node": "^18.7.21",
"@types/which-pm-runs": "^1.0.0",
"astro-scripts": "workspace:*",
"chai": "^4.3.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/webapi/mod.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// organize-imports-ignore
export { pathToPosix } from './lib/utils';
export { alert, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, } from './mod.js';
export { alert, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, crypto, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, } from './mod.js';
export declare const polyfill: {
(target: any, options?: PolyfillOptions): any;
internals(target: any, name: string): any;
Expand Down
2 changes: 1 addition & 1 deletion packages/webapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@rollup/plugin-typescript": "^8.3.2",
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
"@types/node": "^14.18.21",
"@types/node": "^18.7.21",
"@ungap/structured-clone": "^0.3.4",
"chai": "^4.3.6",
"event-target-shim": "^6.0.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/webapi/src/polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
clearTimeout,
Comment,
CountQueuingStrategy,
crypto,
CSSStyleSheet,
CustomElementRegistry,
CustomEvent,
Expand Down Expand Up @@ -87,6 +88,7 @@ export {
clearTimeout,
Comment,
CountQueuingStrategy,
crypto,
CSSStyleSheet,
CustomElementRegistry,
CustomEvent,
Expand Down Expand Up @@ -211,6 +213,7 @@ export const polyfill = (target: any, options?: PolyfillOptions) => {
cancelAnimationFrame,
cancelIdleCallback,
clearTimeout,
crypto,
fetch,
requestAnimationFrame,
requestIdleCallback,
Expand Down
2 changes: 2 additions & 0 deletions packages/webapi/src/ponyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
WritableStreamDefaultController,
WritableStreamDefaultWriter,
} from 'node:stream/web' // Remove when Node 16 is dropped for Node 18.
import { webcrypto as crypto } from 'node:crypto' // Remove when Node 18 is dropped for Node 20
import { fetch, File, FormData, Headers, Request, Response } from 'undici' // Remove when Node 16 is dropped for Node 18.
import { URLPattern } from 'urlpattern-polyfill'
import {
Expand Down Expand Up @@ -133,6 +134,7 @@ export {
cancelAnimationFrame,
cancelIdleCallback,
clearTimeout,
crypto,
fetch,
requestAnimationFrame,
requestIdleCallback,
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bf63f61

Please sign in to comment.