fix: use local version of ky-universal (#111)

master
pooya parsa 2020-06-12 17:43:59 +02:00 committed by GitHub
parent 4152f874a1
commit e7cb647047
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 2655 additions and 1902 deletions

1
ky-universal/browser.js Normal file
View File

@ -0,0 +1 @@
export { default } from 'ky'

9
ky-universal/license Normal file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

32
ky-universal/node.js Normal file
View File

@ -0,0 +1,32 @@
const fetch = require('node-fetch')
const AbortController = require('abort-controller')
const TEN_MEGABYTES = 1000 * 1000 * 10
if (!global.fetch) {
global.fetch = (url, options) => fetch(url, { highWaterMark: TEN_MEGABYTES, ...options })
}
if (!global.Headers) {
global.Headers = fetch.Headers
}
if (!global.Request) {
global.Request = fetch.Request
}
if (!global.Response) {
global.Response = fetch.Response
}
if (!global.AbortController) {
global.AbortController = AbortController
}
if (!global.ReadableStream) {
try {
global.ReadableStream = require('web-streams-polyfill/ponyfill/es2018')
} catch (_) { }
}
module.exports = require('ky/umd')

View File

@ -1,6 +1,5 @@
const path = require('path')
const consola = require('consola')
const semver = require('semver')
const logger = consola.withScope('nuxt:http')
@ -119,16 +118,13 @@ function httpModule (_moduleOptions) {
])
}
// Add `ky` to build.transpile
this.options.build = this.options.build || {}
// Alias ky-universal
this.options.alias['ky-universal'] = path.resolve(__dirname, '../ky-universal')
// Transpile ky and ky-universal
this.options.build.transpile = this.options.build.transpile || {}
// transpile only for non-modern build
/* istanbul ignore next */
if (semver.gte(semver.coerce(this.nuxt.constructor.version), '2.9.0')) {
this.options.build.transpile.push(({ isLegacy }) => isLegacy && 'ky')
} else {
this.options.build.transpile.push('ky')
}
this.options.build.transpile.push('@nuxt/http')
// Set _HTTP_BASE_URL_ for dynamic SSR baseURL
process.env._HTTP_BASE_URL_ = options.baseURL

View File

@ -1,6 +1,7 @@
import KY from 'ky-universal'
import defu from 'defu'
const KY = process.server ? require('ky-universal/node') : require('ky-universal/browser').default
class HTTP {
constructor(defaults, ky = KY) {
this._defaults = {

View File

@ -9,6 +9,7 @@
"types": "types/index.d.ts",
"files": [
"lib",
"ky-universal",
"types/*.d.ts"
],
"scripts": {
@ -19,10 +20,11 @@
},
"dependencies": {
"@nuxtjs/proxy": "^2.0.0",
"abort-controller": "^3.0.0",
"consola": "^2.12.2",
"ky": "^0.20.0",
"ky-universal": "^0.7.0",
"semver": "^7.3.2"
"node-fetch": "^2.6.0",
"web-streams-polyfill": "^2.1.1"
},
"devDependencies": {
"@babel/core": "latest",

4490
yarn.lock

File diff suppressed because it is too large Load Diff