Skip to content

Commit

Permalink
TRY: Dynamic imports using require
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinnl committed May 7, 2020
1 parent a8f649f commit 1c766c4
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ export const fetch: typeof window.fetch = (resource, init) => {
// Implementation note: it's up to the client application to resolve these module names to the
// respective npm packages. At least one commonly used tool (Webpack) is only able to do that if
// the module names are literal strings.
const fetcherPromise = import(
// TypeScript cannot find the module - which is correct, since the consumer app should/can
let fetch;

try {
fetch = require(// TypeScript cannot find the module - which is correct, since the consumer app should/can
// provide it:
// @ts-ignore
"@inrupt/solid-auth-fetcher"
)
.catch(() =>
import(
// TypeScript cannot find the module - which is correct, since the consumer app should/can
// provide it:
// @ts-ignore
"solid-auth-client"
)
)
.catch(() => import("cross-fetch"));
"@inrupt/solid-auth-fetcher").fetch;
} catch (e) {
try {
fetch = require(// TypeScript cannot find the module - which is correct, since the consumer app should/can
// provide it:
// @ts-ignore
"solid-auth-client");
} catch (e) {
fetch = require("cross-fetch");
}
}

return fetcherPromise.then(({ fetch }) => fetch(resource, init));
return fetch(resource, init);
};

0 comments on commit 1c766c4

Please sign in to comment.