Skip to content

Commit c289308

Browse files
authored
🔀 Merge pull request #16 from gluons/node-fetch
Polyfill fetch on Node
2 parents 8deaf4e + 91a98c9 commit c289308

File tree

6 files changed

+1573
-1806
lines changed

6 files changed

+1573
-1806
lines changed

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@
4444
},
4545
"devDependencies": {
4646
"@gluons/prettier-config": "^2.0.0",
47-
"@gluons/vue-up": "^0.4.3",
47+
"@gluons/vue-up": "^0.5.0",
4848
"@types/chai": "^4.1.7",
4949
"@types/fs-extra": "^5.0.5",
5050
"@types/karma": "^3.0.2",
5151
"@types/karma-webpack": "^2.0.6",
5252
"@types/mocha": "^5.2.6",
5353
"@types/node": "8",
54-
"@types/webpack": "^4.4.25",
54+
"@types/node-fetch": "^2.3.0",
55+
"@types/webpack": "^4.4.27",
5556
"@vue/test-utils": "^1.0.0-beta.29",
5657
"chai": "^4.2.0",
5758
"chalk": "^2.4.2",
@@ -75,18 +76,19 @@
7576
"ts-loader": "^5.3.3",
7677
"ts-node": "^8.0.3",
7778
"tsconfig-gluons": "^1.0.1",
78-
"tslint": "^5.13.1",
79+
"tslint": "^5.15.0",
7980
"tslint-config-gluons": "^2.1.0",
80-
"typescript": "^3.3.3333",
81-
"vue": "^2.6.8",
82-
"vue-class-component": "^7.0.1",
81+
"typescript": "^3.4.2",
82+
"vue": "^2.6.10",
83+
"vue-class-component": "^7.0.2",
8384
"vue-loader": "^15.7.0",
84-
"vue-property-decorator": "^8.0.0",
85-
"vue-template-compiler": "^2.6.8",
85+
"vue-property-decorator": "^8.1.0",
86+
"vue-template-compiler": "^2.6.10",
8687
"webpack": "^4.29.6"
8788
},
8889
"dependencies": {
8990
"format-thousands": "^1.1.1",
91+
"node-fetch": "^2.3.0",
9092
"tslib": "^1.9.3"
9193
}
9294
}

src/fetch.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare namespace NodeJS {
2+
interface Global {
3+
fetch: any;
4+
Headers: any;
5+
Request: any;
6+
Response: any;
7+
}
8+
}

src/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Vue from 'vue';
22

33
declare global {
44
const GH_TOKEN: string;
5+
const IS_WEB_BUNDLE: boolean;
56

67
interface Window {
78
Vue: typeof Vue;

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ import './scss/main.scss';
1212

1313
export { Options };
1414

15+
if (!IS_WEB_BUNDLE) {
16+
const nodeFetch = require('node-fetch');
17+
18+
if (global && !global.fetch) {
19+
global.fetch = nodeFetch;
20+
global.Headers = nodeFetch.Headers;
21+
global.Request = nodeFetch.Request;
22+
global.Response = nodeFetch.Response;
23+
}
24+
}
25+
1526
/**
1627
* Install Vue GitHub buttons as Vue plugin.
1728
*

webpack.config.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export default {
5151
plugins: [
5252
new VueLoaderPlugin(),
5353
new DefinePlugin({
54-
GH_TOKEN: JSON.stringify('')
54+
GH_TOKEN: JSON.stringify(''),
55+
IS_WEB_BUNDLE: JSON.stringify(false)
5556
})
5657
],
5758
devtool: 'eval-source-map',

0 commit comments

Comments
 (0)