Skip to content

Commit

Permalink
chore(backend): Drop fetch and crypto polyfills
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkl committed Nov 2, 2023
1 parent 5c17d22 commit 7214ceb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
9 changes: 0 additions & 9 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
26 changes: 7 additions & 19 deletions packages/backend/src/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
5 changes: 2 additions & 3 deletions packages/backend/src/runtime/node/crypto.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 7214ceb

Please sign in to comment.