Adjust for available ESM-only dependencies (#1581)
* Adjust for available ESM-only dependencies * Flags for jest (sadly, still required mid-2022)
This commit is contained in:
@@ -28,6 +28,6 @@
|
||||
"@polkadot/util": "9.7.3-6-x"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@ledgerhq/hw-transport-node-hid-singleton": "^6.27.1"
|
||||
"@ledgerhq/hw-transport-node-hid-singleton": "^6.27.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,6 @@
|
||||
"@ledgerhq/hw-transport": "^6.27.1",
|
||||
"@polkadot/hw-ledger-transports": "9.7.3-6-x",
|
||||
"@polkadot/util": "9.7.3-6-x",
|
||||
"@zondax/ledger-substrate": "^0.31.0"
|
||||
"@zondax/ledger-substrate": "^0.32.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@
|
||||
"@polkadot/x-textdecoder": "9.7.3-6-x",
|
||||
"@polkadot/x-textencoder": "9.7.3-6-x",
|
||||
"@types/bn.js": "^5.1.0",
|
||||
"bn.js": "^5.2.1",
|
||||
"ip-regex": "^4.3.0"
|
||||
"bn.js": "^5.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/x-randomvalues": "9.7.3-6-x"
|
||||
|
||||
@@ -1,9 +1,34 @@
|
||||
// Copyright 2017-2022 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import ipRegex from 'ip-regex';
|
||||
// The regex patterns below were copied as-is from the ip-regex package 5.0.0,
|
||||
// https://github.com/sindresorhus/ip-regex/blob/a2a44dfa7f776528158c2a5ff9d8a1be435ec1b9/index.js#L1
|
||||
//
|
||||
// MIT License
|
||||
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
//
|
||||
// Changes made:
|
||||
// - boundary support option has been dropped
|
||||
// - only exact matching is used (isIp always passed exact: true)
|
||||
// - the newest ip-regex is ESM-only, we compile to all platforms
|
||||
const v4 = '(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}';
|
||||
const v6s = '[a-fA-F\\d]{1,4}';
|
||||
const v6 = `
|
||||
(?:
|
||||
(?:${v6s}:){7}(?:${v6s}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
|
||||
(?:${v6s}:){6}(?:${v4}|:${v6s}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
|
||||
(?:${v6s}:){5}(?::${v4}|(?::${v6s}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
|
||||
(?:${v6s}:){4}(?:(?::${v6s}){0,1}:${v4}|(?::${v6s}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
|
||||
(?:${v6s}:){3}(?:(?::${v6s}){0,2}:${v4}|(?::${v6s}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
|
||||
(?:${v6s}:){2}(?:(?::${v6s}){0,3}:${v4}|(?::${v6s}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
|
||||
(?:${v6s}:){1}(?:(?::${v6s}){0,4}:${v4}|(?::${v6s}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
||||
(?::(?:(?::${v6s}){0,5}:${v4}|(?::${v6s}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
||||
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
||||
`.replace(/\s*\/\/.*$/gm, '').replace(/\n/g, '').trim();
|
||||
|
||||
type IpTypes = 'v4' | 'v6';
|
||||
const v46Exact = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`);
|
||||
const v4exact = new RegExp(`^${v4}$`);
|
||||
const v6exact = new RegExp(`^${v6}$`);
|
||||
|
||||
/**
|
||||
* @name isIp
|
||||
@@ -22,12 +47,10 @@ type IpTypes = 'v4' | 'v6';
|
||||
* isIp('1:2:3:4:5:6:7:8', 'v4'); // => false
|
||||
* ```
|
||||
*/
|
||||
export function isIp (value: string, type?: IpTypes): boolean {
|
||||
if (type === 'v4') {
|
||||
return ipRegex.v4({ exact: true }).test(value);
|
||||
} else if (type === 'v6') {
|
||||
return ipRegex.v6({ exact: true }).test(value);
|
||||
export function isIp (value: string, type?: 'v4' | 'v6'): boolean {
|
||||
switch (type) {
|
||||
case 'v4': return v4exact.test(value);
|
||||
case 'v6': return v6exact.test(value);
|
||||
default: return v46Exact.test(value);
|
||||
}
|
||||
|
||||
return ipRegex({ exact: true }).test(value);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,6 @@
|
||||
"@babel/runtime": "^7.18.6",
|
||||
"@polkadot/x-global": "9.7.3-6-x",
|
||||
"@types/node-fetch": "^2.6.2",
|
||||
"node-fetch": "^2.6.7"
|
||||
"node-fetch": "^3.2.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
// Copyright 2017-2022 @polkadot/x-fetch authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import nodeFetch from 'node-fetch';
|
||||
|
||||
import { extractGlobal } from '@polkadot/x-global';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
let resolvedFetch: null | typeof fetch = 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;
|
||||
}
|
||||
|
||||
return resolvedFetch(...args);
|
||||
}
|
||||
|
||||
export const fetch = extractGlobal('fetch', nodeFetch);
|
||||
|
||||
Reference in New Issue
Block a user