Skip to content

Commit

Permalink
🔀 Merge pull request #16 from gluons/node-fetch
Browse files Browse the repository at this point in the history
Polyfill fetch on Node
  • Loading branch information
gluons authored Apr 7, 2019
2 parents 8deaf4e + 91a98c9 commit c289308
Show file tree
Hide file tree
Showing 6 changed files with 1,573 additions and 1,806 deletions.
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@
},
"devDependencies": {
"@gluons/prettier-config": "^2.0.0",
"@gluons/vue-up": "^0.4.3",
"@gluons/vue-up": "^0.5.0",
"@types/chai": "^4.1.7",
"@types/fs-extra": "^5.0.5",
"@types/karma": "^3.0.2",
"@types/karma-webpack": "^2.0.6",
"@types/mocha": "^5.2.6",
"@types/node": "8",
"@types/webpack": "^4.4.25",
"@types/node-fetch": "^2.3.0",
"@types/webpack": "^4.4.27",
"@vue/test-utils": "^1.0.0-beta.29",
"chai": "^4.2.0",
"chalk": "^2.4.2",
Expand All @@ -75,18 +76,19 @@
"ts-loader": "^5.3.3",
"ts-node": "^8.0.3",
"tsconfig-gluons": "^1.0.1",
"tslint": "^5.13.1",
"tslint": "^5.15.0",
"tslint-config-gluons": "^2.1.0",
"typescript": "^3.3.3333",
"vue": "^2.6.8",
"vue-class-component": "^7.0.1",
"typescript": "^3.4.2",
"vue": "^2.6.10",
"vue-class-component": "^7.0.2",
"vue-loader": "^15.7.0",
"vue-property-decorator": "^8.0.0",
"vue-template-compiler": "^2.6.8",
"vue-property-decorator": "^8.1.0",
"vue-template-compiler": "^2.6.10",
"webpack": "^4.29.6"
},
"dependencies": {
"format-thousands": "^1.1.1",
"node-fetch": "^2.3.0",
"tslib": "^1.9.3"
}
}
8 changes: 8 additions & 0 deletions src/fetch.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare namespace NodeJS {
interface Global {
fetch: any;
Headers: any;
Request: any;
Response: any;
}
}
1 change: 1 addition & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Vue from 'vue';

declare global {
const GH_TOKEN: string;
const IS_WEB_BUNDLE: boolean;

interface Window {
Vue: typeof Vue;
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ import './scss/main.scss';

export { Options };

if (!IS_WEB_BUNDLE) {
const nodeFetch = require('node-fetch');

if (global && !global.fetch) {
global.fetch = nodeFetch;
global.Headers = nodeFetch.Headers;
global.Request = nodeFetch.Request;
global.Response = nodeFetch.Response;
}
}

/**
* Install Vue GitHub buttons as Vue plugin.
*
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export default {
plugins: [
new VueLoaderPlugin(),
new DefinePlugin({
GH_TOKEN: JSON.stringify('')
GH_TOKEN: JSON.stringify(''),
IS_WEB_BUNDLE: JSON.stringify(false)
})
],
devtool: 'eval-source-map',
Expand Down
Loading

0 comments on commit c289308

Please sign in to comment.