From 7214ceb32b66d79e4d10a43619fcd815e5ba8643 Mon Sep 17 00:00:00 2001 From: Dimitris Klouvas Date: Thu, 2 Nov 2023 18:40:44 +0200 Subject: [PATCH] chore(backend): Drop fetch and crypto polyfills --- packages/backend/package.json | 9 ------- packages/backend/src/runtime/index.ts | 26 ++++++--------------- packages/backend/src/runtime/node/crypto.js | 5 ++-- 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/packages/backend/package.json b/packages/backend/package.json index 767bb0cdc6b..9c64a527d17 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -19,13 +19,6 @@ "browser": "./dist/runtime/browser/crypto.mjs", "node": "./dist/runtime/node/crypto.js", "default": "./dist/runtime/browser/crypto.mjs" - }, - "#fetch": { - "edge-light": "./dist/runtime/browser/fetch.mjs", - "worker": "./dist/runtime/browser/fetch.mjs", - "browser": "./dist/runtime/browser/fetch.mjs", - "node": "./dist/runtime/node/fetch.js", - "default": "./dist/runtime/browser/fetch.mjs" } }, "main": "./dist/index.js", @@ -56,10 +49,8 @@ }, "dependencies": { "@clerk/shared": "1.0.0", - "@peculiar/webcrypto": "1.4.1", "cookie": "0.5.0", "deepmerge": "4.2.2", - "node-fetch-native": "1.0.1", "snakecase-keys": "5.4.4", "tslib": "2.4.1" }, diff --git a/packages/backend/src/runtime/index.ts b/packages/backend/src/runtime/index.ts index 89a1d7c1a77..bcfd0035dbc 100644 --- a/packages/backend/src/runtime/index.ts +++ b/packages/backend/src/runtime/index.ts @@ -14,18 +14,6 @@ // @ts-ignore - These are package subpaths import crypto from '#crypto'; -// @ts-ignore - These are package subpaths -import * as fetchApisPolyfill from '#fetch'; - -const { - RuntimeFetch, - RuntimeAbortController, - RuntimeBlob, - RuntimeFormData, - RuntimeHeaders, - RuntimeRequest, - RuntimeResponse, -} = fetchApisPolyfill; type Runtime = { crypto: Crypto; @@ -44,18 +32,18 @@ type Runtime = { // The globalThis object is supported for Node >= 12.0. // // https://github.com/supabase/supabase/issues/4417 -const globalFetch = RuntimeFetch.bind(globalThis); +const globalFetch = global.fetch.bind(globalThis); // DO NOT CHANGE: Runtime needs to be imported as a default export so that we can stub its dependencies with Sinon.js // For more information refer to https://sinonjs.org/how-to/stub-dependency/ const runtime: Runtime = { crypto, fetch: globalFetch, - AbortController: RuntimeAbortController, - Blob: RuntimeBlob, - FormData: RuntimeFormData, - Headers: RuntimeHeaders, - Request: RuntimeRequest, - Response: RuntimeResponse, + AbortController: global.AbortController, + Blob: global.Blob, + FormData: global.FormData, + Headers: global.Headers, + Request: global.Request, + Response: global.Response, }; export default runtime; diff --git a/packages/backend/src/runtime/node/crypto.js b/packages/backend/src/runtime/node/crypto.js index a4348e4b9f8..e192b979353 100644 --- a/packages/backend/src/runtime/node/crypto.js +++ b/packages/backend/src/runtime/node/crypto.js @@ -1,12 +1,11 @@ -/* eslint-disable @typescript-eslint/no-var-requires */ let webcrypto; try { webcrypto = require('node:crypto').webcrypto; if (!webcrypto) { - webcrypto = new (require('@peculiar/webcrypto').Crypto)(); + webcrypto = global.crypto; } } catch (e) { - webcrypto = new (require('@peculiar/webcrypto').Crypto)(); + webcrypto = global.crypto; } module.exports = webcrypto;