Skip to content

Commit

Permalink
feat: use dynamic import to load cross fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Oct 12, 2023
1 parent 4f4ffb2 commit c0c2c88
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lib/build/utils.js

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

10 changes: 7 additions & 3 deletions lib/ts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ import NormalisedURLPath from "./normalisedURLPath";
import type { BaseRequest, BaseResponse } from "./framework";
import { logDebugMessage } from "./logger";
import { HEADER_FDI, HEADER_RID } from "./constants";
import crossFetch from "cross-fetch";
import { User } from "./user";
import { SessionContainer } from "./recipe/session";

export const doFetch: typeof fetch = (...args) => {
let crossFetchImport: Promise<typeof import("cross-fetch")> | undefined;
export const doFetch: typeof fetch = async (...args) => {
if (typeof fetch !== "undefined") {
return fetch(...args);
}
return crossFetch(...args);
if (crossFetchImport === undefined) {
crossFetchImport = import("cross-fetch");
}
const crossFetch = await crossFetchImport;
return crossFetch.fetch(...args);
};

export function getLargestVersionFromIntersection(v1: string[], v2: string[]): string | undefined {
Expand Down

0 comments on commit c0c2c88

Please sign in to comment.