Skip to content
This repository was archived by the owner on Feb 28, 2023. It is now read-only.

Commit ed1a130

Browse files
feat(deps): remove whatwg-url dependency (#227)
1 parent 39f0bf1 commit ed1a130

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@babel/polyfill": "^7.0.0",
4545
"@babel/preset-env": "^7.1.0",
4646
"assert": "^1.4.1",
47+
"axios": "~0.21.1",
4748
"babel-loader": "^8.0.4",
4849
"cache-control-esm": "1.0.0",
4950
"codecov": "^3.0.0",
@@ -61,6 +62,7 @@
6162
"karma-webpack": "^2.0.3",
6263
"localforage": "^1.7.2",
6364
"localforage-memoryStorageDriver": "^0.9.2",
65+
"lodash": "^4.17.11",
6466
"mocha": "^5.0.4",
6567
"mockdate": "^2.0.2",
6668
"puppeteer": "^3.1.0",
@@ -70,14 +72,12 @@
7072
"snazzy": "^7.0.0",
7173
"standard": "^14.3.1",
7274
"webpack": "^4.1.1",
73-
"webpack-cli": "^3.1.1",
74-
"axios": "~0.21.1"
75+
"webpack-bundle-analyzer": "^4.4.0",
76+
"webpack-cli": "^3.1.1"
7577
},
7678
"dependencies": {
7779
"cache-control-esm": "1.0.0",
78-
"lodash": "^4.17.11",
79-
"md5": "^2.2.1",
80-
"whatwg-url": "^7.1.0"
80+
"md5": "^2.2.1"
8181
},
8282
"peerDependencies": {
8383
"axios": "~0.21.1"

src/cache.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import isString from 'lodash/isString'
2-
import isFunction from 'lodash/isFunction'
1+
import { isString, isFunction } from './utilities'
32
import md5 from 'md5'
4-
import { URL } from 'whatwg-url'
53

64
import serialize from './serialize'
75

@@ -71,14 +69,14 @@ function key (config) {
7169
let cacheKey
7270
if (isString(config.key)) {
7371
cacheKey = req => {
74-
const url = new URL(req.url, req.baseURL)
75-
const key = `${config.key}/${url.href}${serializeQuery(req)}`
72+
const url = `${req.baseURL ? req.baseURL : ''}${req.url}`
73+
const key = `${config.key}/${url}${serializeQuery(req)}`
7674
return req.data ? key + md5(req.data) : key
7775
}
7876
} else {
7977
cacheKey = req => {
80-
const url = new URL(req.url, req.baseURL)
81-
const key = url.href + serializeQuery(req)
78+
const url = `${req.baseURL ? req.baseURL : ''}${req.url}`
79+
const key = url + serializeQuery(req)
8280
return req.data ? key + md5(req.data) : key
8381
}
8482
}

test/spec/cache.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ describe('Cache store', () => {
136136
let cacheKey = cache.key({ key: 'my-key' })
137137

138138
assert.ok(isFunction(cacheKey))
139-
assert.equal(cacheKey({ url: 'https://httpbin.org' }), 'my-key/https://httpbin.org/')
139+
assert.equal(cacheKey({ url: 'https://httpbin.org/' }), 'my-key/https://httpbin.org/')
140140

141141
cacheKey = cache.key({})
142142

143143
assert.ok(isFunction(cacheKey))
144-
assert.equal(cacheKey({ url: 'https://httpbin.org' }), 'https://httpbin.org/')
144+
assert.equal(cacheKey({ url: 'https://httpbin.org/' }), 'https://httpbin.org/')
145145
})
146146
})

test/spec/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ describe('Integration', function () {
322322
const url = 'https://httpbin.org/status/404'
323323
const api5 = setup({
324324
cache: {
325-
// debug: true,
325+
debug: true,
326326
maxAge: 1,
327327
readOnError: (err, config) => {
328328
return err.response.status === 404

webpack.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const path = require('path')
22
const webpack = require('webpack')
33
const HtmlWebpackPlugin = require('html-webpack-plugin')
4+
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
45

56
const cwd = process.cwd()
67

@@ -9,7 +10,9 @@ let filename = 'cache[version].js'
910
let version = ['']
1011

1112
// Start with empty list of plugins and externals and an undefined devtool
12-
const plugins = []
13+
const plugins = [
14+
// new BundleAnalyzerPlugin()
15+
]
1316
let externals = {}
1417

1518
let mode = 'development'
@@ -170,7 +173,7 @@ const test = {
170173
port: 3000
171174
},
172175
target: 'web',
173-
devtool: 'inline-source-map'
176+
devtool: 'source-map'
174177
}
175178

176179
module.exports = process.env.NODE_ENV === 'test' ? test : build

0 commit comments

Comments
 (0)