chore: fix import / require module
This commit is contained in:
@@ -36,10 +36,26 @@ exports.methods = {
|
|||||||
crypto_aead_xchacha20poly1305_ietf_decrypt: NoLib,
|
crypto_aead_xchacha20poly1305_ietf_decrypt: NoLib,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function importModule(name, usingImport = false) {
|
||||||
|
try {
|
||||||
|
if (usingImport) {
|
||||||
|
return await import(name);
|
||||||
|
} else {
|
||||||
|
return require(name);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (e.code == 'ERR_REQUIRE_ESM') {
|
||||||
|
return importModule(name, true);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
for (const libName of Object.keys(libs)) {
|
for (const libName of Object.keys(libs)) {
|
||||||
try {
|
try {
|
||||||
const lib = await import(libName);
|
const lib = await importModule(libName);
|
||||||
if (libName === 'libsodium-wrappers' && lib.ready) await lib.ready; // eslint-disable-line no-await-in-loop
|
if (libName === 'libsodium-wrappers' && lib.ready) await lib.ready; // eslint-disable-line no-await-in-loop
|
||||||
exports.methods = libs[libName](lib);
|
exports.methods = libs[libName](lib);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user