From 19368cc81a89be8dfcd3f35f8130ca15021d1ebe Mon Sep 17 00:00:00 2001 From: inazarov Date: Tue, 15 Feb 2022 03:19:05 +0300 Subject: [PATCH 1/4] package config --- package.json | 4 ++-- src/tools/request.ts | 14 +++++++++----- tsconfig-cjs.json | 6 +++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 044a9be..8f31149 100644 --- a/package.json +++ b/package.json @@ -6,14 +6,14 @@ "scripts": { "testCommand": "jest", "prepare": "npm run build", - "build": "tsc -p ./tsconfig-es.json && tsc -p ./tsconfig-cjs.json && webpack", + "build": "rm -rf ./es && tsc -p ./tsconfig-es.json && rm -rf ./cjs && tsc -p ./tsconfig-cjs.json && webpack", "test": "node-state -e -n -m typescript -o ./test/_state.ts -r" }, "dependencies": { "@types/node-fetch": "^2.5.4", "@waves/bignumber": "^1.1.1", "@waves/ts-types": "^1.0.6-beta.7", - "node-fetch": "^3.1.1", + "cross-fetch": "^3.1.5", "typed-ts-events": "^1.1.1" }, "files": [ diff --git a/src/tools/request.ts b/src/tools/request.ts index 3853fd7..ab9bd63 100644 --- a/src/tools/request.ts +++ b/src/tools/request.ts @@ -1,8 +1,12 @@ import resolve from './resolve'; import parse from './parse'; +// import fetch, { RequestInit } from 'node-fetch'; +import fetch from 'cross-fetch'; +const request = fetch; -const request = typeof fetch === 'function' ? fetch : require('node-fetch'); +// const request = typeof globalThis.fetch === 'function' ? fetch : require('node-fetch'); +// const request = require('node-fetch'); export default function (params: IRequestParams): Promise { return request(resolve(params.url, params.base), updateHeaders(params.options)) @@ -23,7 +27,7 @@ function tryParse(message: string) { function updateHeaders(options: RequestInit = Object.create(null)) { return { - credentials: 'include', + credentials: ('include' as any), ...options }; } @@ -31,15 +35,15 @@ function updateHeaders(options: RequestInit = Object.create(null)) { export interface IRequestParams { url: string; base: string; - options?: RequestInit | undefined; + options?: any; // TODO RequestInit; } -// RequestInit is a DOM interface. It needs to be explicitly defined here for usage in nodejs environment +// // RequestInit is a DOM interface. It needs to be explicitly defined here for usage in nodejs environment export interface RequestInit { /** * A BodyInit object or null to set request's body. */ - body?: BodyInit | null; + body?: BodyInit; /** * A string indicating how the request will interact with the browser's cache to set request's cache. * Not supported in nodejs environment diff --git a/tsconfig-cjs.json b/tsconfig-cjs.json index 1764958..05c0ba6 100644 --- a/tsconfig-cjs.json +++ b/tsconfig-cjs.json @@ -1,10 +1,10 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "module": "CommonJS", - "target": "ES5", "outDir": "./cjs", - "declaration": true + "target": "es2017", + "module": "commonjs", + "declaration": true, }, "include": [ "src" From 3f2d2cf7b963fda79eefc3d661e94cdf82034e22 Mon Sep 17 00:00:00 2001 From: inazarov Date: Tue, 15 Feb 2022 03:22:11 +0300 Subject: [PATCH 2/4] clean --- src/tools/request.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/tools/request.ts b/src/tools/request.ts index ab9bd63..ee256dd 100644 --- a/src/tools/request.ts +++ b/src/tools/request.ts @@ -1,12 +1,7 @@ import resolve from './resolve'; import parse from './parse'; -// import fetch, { RequestInit } from 'node-fetch'; -import fetch from 'cross-fetch'; -const request = fetch; - -// const request = typeof globalThis.fetch === 'function' ? fetch : require('node-fetch'); -// const request = require('node-fetch'); +import request from 'cross-fetch'; export default function (params: IRequestParams): Promise { return request(resolve(params.url, params.base), updateHeaders(params.options)) @@ -38,12 +33,12 @@ export interface IRequestParams { options?: any; // TODO RequestInit; } -// // RequestInit is a DOM interface. It needs to be explicitly defined here for usage in nodejs environment +// RequestInit is a DOM interface. It needs to be explicitly defined here for usage in nodejs environment export interface RequestInit { /** * A BodyInit object or null to set request's body. */ - body?: BodyInit; + body?: BodyInit | null; /** * A string indicating how the request will interact with the browser's cache to set request's cache. * Not supported in nodejs environment From ac69d93d67992d6820ebfed6ecf09c90132faa9d Mon Sep 17 00:00:00 2001 From: inazarov Date: Tue, 15 Feb 2022 03:24:13 +0300 Subject: [PATCH 3/4] clean --- tsconfig-cjs.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tsconfig-cjs.json b/tsconfig-cjs.json index 05c0ba6..27d3def 100644 --- a/tsconfig-cjs.json +++ b/tsconfig-cjs.json @@ -1,9 +1,9 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "./cjs", + "module": "CommonJS", "target": "es2017", - "module": "commonjs", + "outDir": "./cjs", "declaration": true, }, "include": [ From f61e982c4382cfd13df0de3f142a3ef23f5d1488 Mon Sep 17 00:00:00 2001 From: inazarov Date: Tue, 15 Feb 2022 03:25:45 +0300 Subject: [PATCH 4/4] clean --- tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index b454946..9775c96 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,6 @@ "downlevelIteration": true, "lib": [ "es5", - "dom", "es2015.iterable", "es2015.promise" ]