From f173001a411acb39c0d2ebb11d17ea90d70ec784 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 15 May 2018 09:02:57 -0400 Subject: [PATCH] polyfill fetch globals on nodeapi --- package-lock.json | 9 +++++++++ package.json | 3 ++- src/services/nodeApi.service.ts | 7 +++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e4490a13ee..0899866723 100644 --- a/package-lock.json +++ b/package-lock.json @@ -108,6 +108,15 @@ "integrity": "sha512-VRQB+Q0L3YZWs45uRdpN9oWr82meL/8TrJ6faoKT5tp0uub2l/aRMhtm5fo68h7kjYKH60f9/bay1nF7ZpTW5g==", "dev": true }, + "@types/node-fetch": { + "version": "1.6.9", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-1.6.9.tgz", + "integrity": "sha512-n2r6WLoY7+uuPT7pnEtKJCmPUGyJ+cbyBR8Avnu4+m1nzz7DwBVuyIvvlBzCZ/nrpC7rIgb3D6pNavL7rFEa9g==", + "dev": true, + "requires": { + "@types/node": "8.0.19" + } + }, "@types/node-forge": { "version": "0.7.1", "resolved": "https://registry.npmjs.org/@types/node-forge/-/node-forge-0.7.1.tgz", diff --git a/package.json b/package.json index e3984ee5c4..4dde128f73 100644 --- a/package.json +++ b/package.json @@ -28,15 +28,16 @@ "@types/keytar": "^4.0.1", "@types/lunr": "2.1.5", "@types/node": "8.0.19", + "@types/node-fetch": "^1.6.9", "@types/node-forge": "0.7.1", "@types/papaparse": "4.1.31", "@types/webcrypto": "0.0.28", "concurrently": "3.5.1", "electron": "1.8.4", "jasmine": "^3.1.0", - "jasmine-ts-console-reporter": "^3.1.1", "jasmine-core": "^2.8.0", "jasmine-spec-reporter": "^4.2.1", + "jasmine-ts-console-reporter": "^3.1.1", "karma": "^1.7.1", "karma-chrome-launcher": "^2.2.0", "karma-cli": "^1.0.1", diff --git a/src/services/nodeApi.service.ts b/src/services/nodeApi.service.ts index d75ff1fdac..7803eafdc8 100644 --- a/src/services/nodeApi.service.ts +++ b/src/services/nodeApi.service.ts @@ -1,11 +1,14 @@ -import { Utils } from '../misc/utils'; +import * as fe from 'node-fetch'; import { ApiService } from './api.service'; import { PlatformUtilsService } from '../abstractions/platformUtils.service'; import { TokenService } from '../abstractions/token.service'; -import * as fetch from 'node-fetch'; +(global as any).fetch = fe.default; +(global as any).Request = fe.Request; +(global as any).Response = fe.Response; +(global as any).Headers = fe.Headers; export class NodeApiService extends ApiService { constructor(tokenService: TokenService, platformUtilsService: PlatformUtilsService,