anki/ts/lib/runtime-require.ts
Damien Elmes 52ea7c2a05 avoid Object.fromEntries() and some instances of globalThis
Not supported on early iOS 12. This can be reverted after iOS 12
support is dropped, which should be soon.
2021-11-02 12:54:06 +10:00

20 lines
597 B
TypeScript

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
/* eslint
@typescript-eslint/no-explicit-any: "off",
*/
/// This can be extended to allow require() calls at runtime, for libraries
/// that are not included at bundling time.
export const runtimeLibraries = {};
// Export require() as a global.
(window as any).require = function (name: string): unknown {
const lib = runtimeLibraries[name];
if (lib === undefined) {
throw new Error(`Cannot require(${name}) at runtime.`);
}
return lib;
};