Repository: RasCarlito/axios-cache-adapter
Pull request #227 (2021-02-01 14:48:54)

feat(deps): remove whatwg-url dependency
New take at removing `whatwg-url` dependency to reduce bundle size as started in #188 
Also removed `lodash` from dependencies in package.json (it was already not used anymore in source code)

Current build on master (666KB 🤘😅 gzip: 181KB)
![image](https://user-images.githubusercontent.com/407268/106474184-f1424b80-64a4-11eb-8294-9ce07ea5defb.png)

New build (132KB 😎 gzip: 39KB)
![image](https://user-images.githubusercontent.com/407268/106474589-58600000-64a5-11eb-85da-1643df0ea074.png)



codecov[bot]: # [Codecov](https://codecov.io/gh/RasCarlito/axios-cache-adapter/pull/227?src=pr&el=h1) Report
> Merging [#227](https://codecov.io/gh/RasCarlito/axios-cache-adapter/pull/227?src=pr&el=desc) (ab69de2) into [master](https://codecov.io/gh/RasCarlito/axios-cache-adapter/commit/39f0bf149bd52efff6d8b1f5d02992348dc63e11?el=desc) (39f0bf1) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/RasCarlito/axios-cache-adapter/pull/227/graphs/tree.svg?width=650&height=150&src=pr&token=puwNl25fIP)](https://codecov.io/gh/RasCarlito/axios-cache-adapter/pull/227?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##            master      #227   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           12        12           
  Lines          177       177           
=========================================
  Hits           177       177           
```


| [Impacted Files](https://codecov.io/gh/RasCarlito/axios-cache-adapter/pull/227?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/cache.js](https://codecov.io/gh/RasCarlito/axios-cache-adapter/pull/227/diff?src=pr&el=tree#diff-c3JjL2NhY2hlLmpz) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/RasCarlito/axios-cache-adapter/pull/227?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/RasCarlito/axios-cache-adapter/pull/227?src=pr&el=footer). Last update [39f0bf1...ab69de2](https://codecov.io/gh/RasCarlito/axios-cache-adapter/pull/227?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/package.json b/package.json
index 54c1c54..6fb823d 100644
--- a/package.json
+++ b/package.json
@@ -44,6 +44,7 @@
     "@babel/polyfill": "^7.0.0",
     "@babel/preset-env": "^7.1.0",
     "assert": "^1.4.1",
+    "axios": "~0.21.1",
     "babel-loader": "^8.0.4",
     "cache-control-esm": "1.0.0",
     "codecov": "^3.0.0",
@@ -61,6 +62,7 @@
     "karma-webpack": "^2.0.3",
     "localforage": "^1.7.2",
     "localforage-memoryStorageDriver": "^0.9.2",
+    "lodash": "^4.17.11",
     "mocha": "^5.0.4",
     "mockdate": "^2.0.2",
     "puppeteer": "^3.1.0",
@@ -70,14 +72,12 @@
     "snazzy": "^7.0.0",
     "standard": "^14.3.1",
     "webpack": "^4.1.1",
-    "webpack-cli": "^3.1.1",
-    "axios": "~0.21.1"
+    "webpack-bundle-analyzer": "^4.4.0",
+    "webpack-cli": "^3.1.1"
   },
   "dependencies": {
     "cache-control-esm": "1.0.0",
-    "lodash": "^4.17.11",
-    "md5": "^2.2.1",
-    "whatwg-url": "^7.1.0"
+    "md5": "^2.2.1"
   },
   "peerDependencies": {
     "axios": "~0.21.1"
diff --git a/src/cache.js b/src/cache.js
index b188bda..72ae49f 100644
--- a/src/cache.js
+++ b/src/cache.js
@@ -1,7 +1,5 @@
-import isString from 'lodash/isString'
-import isFunction from 'lodash/isFunction'
+import { isString, isFunction } from './utilities'
 import md5 from 'md5'
-import { URL } from 'whatwg-url'
 
 import serialize from './serialize'
 
@@ -71,14 +69,14 @@ function key (config) {
   let cacheKey
   if (isString(config.key)) {
     cacheKey = req => {
-      const url = new URL(req.url, req.baseURL)
-      const key = `${config.key}/${url.href}${serializeQuery(req)}`
+      const url = `${req.baseURL ? req.baseURL : ''}${req.url}`
+      const key = `${config.key}/${url}${serializeQuery(req)}`
       return req.data ? key + md5(req.data) : key
     }
   } else {
     cacheKey = req => {
-      const url = new URL(req.url, req.baseURL)
-      const key = url.href + serializeQuery(req)
+      const url = `${req.baseURL ? req.baseURL : ''}${req.url}`
+      const key = url + serializeQuery(req)
       return req.data ? key + md5(req.data) : key
     }
   }
diff --git a/webpack.config.js b/webpack.config.js
index 2278520..2cde165 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -1,6 +1,7 @@
 const path = require('path')
 const webpack = require('webpack')
 const HtmlWebpackPlugin = require('html-webpack-plugin')
+// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
 
 const cwd = process.cwd()
 
@@ -9,7 +10,9 @@ let filename = 'cache[version].js'
 let version = ['']
 
 // Start with empty list of plugins and externals and an undefined devtool
-const plugins = []
+const plugins = [
+  // new BundleAnalyzerPlugin()
+]
 let externals = {}
 
 let mode = 'development'
@@ -170,7 +173,7 @@ const test = {
     port: 3000
   },
   target: 'web',
-  devtool: 'inline-source-map'
+  devtool: 'source-map'
 }
 
 module.exports = process.env.NODE_ENV === 'test' ? test : build


Test patch:
diff --git a/test/spec/cache.spec.js b/test/spec/cache.spec.js
index 866883b..0770184 100644
--- a/test/spec/cache.spec.js
+++ b/test/spec/cache.spec.js
@@ -136,11 +136,11 @@ describe('Cache store', () => {
     let cacheKey = cache.key({ key: 'my-key' })
 
     assert.ok(isFunction(cacheKey))
-    assert.equal(cacheKey({ url: 'https://httpbin.org' }), 'my-key/https://httpbin.org/')
+    assert.equal(cacheKey({ url: 'https://httpbin.org/' }), 'my-key/https://httpbin.org/')
 
     cacheKey = cache.key({})
 
     assert.ok(isFunction(cacheKey))
-    assert.equal(cacheKey({ url: 'https://httpbin.org' }), 'https://httpbin.org/')
+    assert.equal(cacheKey({ url: 'https://httpbin.org/' }), 'https://httpbin.org/')
   })
 })
diff --git a/test/spec/index.spec.js b/test/spec/index.spec.js
index 5b3ba3a..0655dcc 100644
--- a/test/spec/index.spec.js
+++ b/test/spec/index.spec.js
@@ -322,7 +322,7 @@ describe('Integration', function () {
     const url = 'https://httpbin.org/status/404'
     const api5 = setup({
       cache: {
-        // debug: true,
+        debug: true,
         maxAge: 1,
         readOnError: (err, config) => {
           return err.response.status === 404