Work-around for Jest + dynamic imports (#1594)
* Work-around for Jest + dynamic imports * CHANGELOG * 10.0.2
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
@@ -25,7 +25,7 @@
|
||||
"@ledgerhq/hw-transport": "^6.27.1",
|
||||
"@ledgerhq/hw-transport-webhid": "^6.27.1",
|
||||
"@ledgerhq/hw-transport-webusb": "^6.27.1",
|
||||
"@polkadot/util": "10.0.2-1-x"
|
||||
"@polkadot/util": "10.0.2"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@ledgerhq/hw-transport-node-hid-singleton": "^6.27.2"
|
||||
|
||||
@@ -19,13 +19,13 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.6",
|
||||
"@ledgerhq/hw-transport": "^6.27.1",
|
||||
"@polkadot/hw-ledger-transports": "10.0.2-1-x",
|
||||
"@polkadot/util": "10.0.2-1-x",
|
||||
"@polkadot/hw-ledger-transports": "10.0.2",
|
||||
"@polkadot/util": "10.0.2",
|
||||
"@zondax/ledger-substrate": "^0.32.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,15 +20,15 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.6",
|
||||
"@polkadot/util": "10.0.2-1-x",
|
||||
"@polkadot/util-crypto": "10.0.2-1-x"
|
||||
"@polkadot/util": "10.0.2",
|
||||
"@polkadot/util-crypto": "10.0.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "10.0.2-1-x",
|
||||
"@polkadot/util-crypto": "10.0.2-1-x"
|
||||
"@polkadot/util": "10.0.2",
|
||||
"@polkadot/util-crypto": "10.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.6",
|
||||
"@polkadot/util": "10.0.2-1-x",
|
||||
"@polkadot/util": "10.0.2",
|
||||
"@substrate/ss58-registry": "^1.23.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/hw-ledger": "10.0.2-1-x",
|
||||
"@polkadot/x-fetch": "10.0.2-1-x"
|
||||
"@polkadot/hw-ledger": "10.0.2",
|
||||
"@polkadot/x-fetch": "10.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"browser": {
|
||||
"crypto": false,
|
||||
"stream": false
|
||||
@@ -32,11 +32,11 @@
|
||||
"@babel/runtime": "^7.18.6",
|
||||
"@noble/hashes": "1.1.2",
|
||||
"@noble/secp256k1": "1.6.0",
|
||||
"@polkadot/networks": "10.0.2-1-x",
|
||||
"@polkadot/util": "10.0.2-1-x",
|
||||
"@polkadot/networks": "10.0.2",
|
||||
"@polkadot/util": "10.0.2",
|
||||
"@polkadot/wasm-crypto": "^6.2.3",
|
||||
"@polkadot/x-bigint": "10.0.2-1-x",
|
||||
"@polkadot/x-randomvalues": "10.0.2-1-x",
|
||||
"@polkadot/x-bigint": "10.0.2",
|
||||
"@polkadot/x-randomvalues": "10.0.2",
|
||||
"@scure/base": "1.1.1",
|
||||
"ed2curve": "^0.3.0",
|
||||
"tweetnacl": "^1.0.3"
|
||||
@@ -45,6 +45,6 @@
|
||||
"@types/ed2curve": "^0.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@polkadot/util": "10.0.2-1-x"
|
||||
"@polkadot/util": "10.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,18 +34,18 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.6",
|
||||
"@polkadot/x-bigint": "10.0.2-1-x",
|
||||
"@polkadot/x-global": "10.0.2-1-x",
|
||||
"@polkadot/x-textdecoder": "10.0.2-1-x",
|
||||
"@polkadot/x-textencoder": "10.0.2-1-x",
|
||||
"@polkadot/x-bigint": "10.0.2",
|
||||
"@polkadot/x-global": "10.0.2",
|
||||
"@polkadot/x-textdecoder": "10.0.2",
|
||||
"@polkadot/x-textencoder": "10.0.2",
|
||||
"@types/bn.js": "^5.1.0",
|
||||
"bn.js": "^5.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/x-randomvalues": "10.0.2-1-x"
|
||||
"@polkadot/x-randomvalues": "10.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
"./shim.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.6",
|
||||
"@polkadot/x-global": "10.0.2-1-x"
|
||||
"@polkadot/x-global": "10.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.6",
|
||||
"@polkadot/util": "10.0.2-1-x",
|
||||
"@polkadot/util": "10.0.2",
|
||||
"buffer-es6": "^4.9.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.6",
|
||||
"@polkadot/x-global": "10.0.2-1-x",
|
||||
"@polkadot/x-global": "10.0.2",
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
"node-fetch": "^3.2.6"
|
||||
}
|
||||
|
||||
@@ -5,17 +5,28 @@ import { extractGlobal } from '@polkadot/x-global';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
let resolvedFetch: null | typeof fetch = null;
|
||||
// This is an ESM module, use the async import(...) syntax to pull it
|
||||
// in. Logically we would like it in nodeFetch(...) itself, however
|
||||
// while it is all-ok on Node itself, it does create issues in Jest,
|
||||
// possibly due to the Jest 28 need for --experimental-vm-modules
|
||||
const importFetch = import('node-fetch').catch(() => null);
|
||||
|
||||
// keep track of the resolved import value
|
||||
let resolvedFetch: typeof fetch | null = null;
|
||||
|
||||
async function nodeFetch (...args: Parameters<typeof fetch>): Promise<Response> {
|
||||
if (!resolvedFetch) {
|
||||
// we use the async import here to resolve on-demand
|
||||
// (this allows us to use the latest ESM version of the package)
|
||||
const mod = await import('node-fetch');
|
||||
|
||||
resolvedFetch = mod.default as unknown as typeof fetch;
|
||||
if (resolvedFetch) {
|
||||
return resolvedFetch(...args);
|
||||
}
|
||||
|
||||
const mod = await importFetch;
|
||||
|
||||
if (!mod || !mod.default) {
|
||||
throw new Error('Unable to import node-fetch in this environment');
|
||||
}
|
||||
|
||||
resolvedFetch = mod.default as unknown as typeof fetch;
|
||||
|
||||
return resolvedFetch(...args);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.6"
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.6",
|
||||
"@polkadot/x-global": "10.0.2-1-x"
|
||||
"@polkadot/x-global": "10.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react-native": "^0.69.2"
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.6",
|
||||
"@polkadot/x-global": "10.0.2-1-x"
|
||||
"@polkadot/x-global": "10.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.6",
|
||||
"@polkadot/x-global": "10.0.2-1-x"
|
||||
"@polkadot/x-global": "10.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"version": "10.0.2-1-x",
|
||||
"version": "10.0.2",
|
||||
"browser": "browser.js",
|
||||
"main": "node.js",
|
||||
"react-native": "react-native.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.6",
|
||||
"@polkadot/x-global": "10.0.2-1-x",
|
||||
"@polkadot/x-global": "10.0.2",
|
||||
"@types/websocket": "^1.0.5",
|
||||
"websocket": "^1.0.34"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user