Adjust some usages to not require @types/node (#1576)

This commit is contained in:
Jaco
2022-07-04 10:20:24 +03:00
committed by GitHub
parent 7e01b2b256
commit 80eb70a382
4 changed files with 26 additions and 2 deletions
+7
View File
@@ -1,5 +1,12 @@
# CHANGELOG
## master
Changes:
- Allow for usage without `@types/node` installed
## 9.7.2 Jul 4, 2022
Changes:
+9
View File
@@ -3,6 +3,15 @@
import { BigInt } from '@polkadot/x-bigint';
// Since we run in very different environments, we have to ensure we have all
// the types used here for detection (some of these may require Node definitions,
// which are not available in Deno/browser)
declare const __dirname: unknown;
declare const Buffer: unknown;
declare const module: unknown;
declare const process: unknown;
declare const require: unknown;
/** true if the environment has proper BigInt support */
export const hasBigInt = typeof BigInt === 'function' && typeof BigInt.asIntN === 'function';
+2
View File
@@ -13,6 +13,8 @@ import { u8aToHex } from './u8a/toHex';
import { u8aToU8a } from './u8a/toU8a';
import { hasProcess } from './has';
declare const process: { env: Record<string, string> };
type ConsoleType = 'error' | 'log' | 'warn';
type LogType = ConsoleType | 'debug';
+8 -2
View File
@@ -3,11 +3,17 @@
export { packageInfo } from './packageInfo';
// Ensure that we are able to run this without any @types/node definitions
// and without having lib: ['dom'] in our TypeScript configuration
// (may not be available in all environments, e.g. Deno springs to mind)
declare const global: typeof globalThis;
declare const self: typeof globalThis;
type GlobalThis = typeof globalThis;
type GlobalNames = keyof typeof window;
type GlobalNames = keyof GlobalThis;
type GlobalType<T extends keyof typeof window> = typeof window[T];
type GlobalType<T extends GlobalNames> = typeof globalThis[T];
function evaluateThis (fn: (code: string) => unknown): GlobalThis {
return fn('return this') as GlobalThis;