Skip to content

Commit

Permalink
fix: reduced package size by removing mem package (#1027)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Sep 7, 2021
1 parent b2419f8 commit 0d55268
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 84 deletions.
90 changes: 9 additions & 81 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
},
"dependencies": {
"colorette": "^1.2.2",
"mem": "^8.1.1",
"memfs": "^3.2.2",
"mime-types": "^2.1.31",
"range-parser": "^1.2.1",
Expand Down
25 changes: 23 additions & 2 deletions src/utils/getFilenameFromUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,31 @@ import path from "path";
import { parse } from "url";
import querystring from "querystring";

import mem from "mem";

import getPaths from "./getPaths";

const cacheStore = new WeakMap();
const mem = (fn, { cache = new Map() } = {}) => {
const memoized = (...arguments_) => {
const [key] = arguments_;
const cacheItem = cache.get(key);

if (cacheItem) {
return cacheItem.data;
}

const result = fn.apply(this, arguments_);

cache.set(key, {
data: result,
});

return result;
};

cacheStore.set(memoized, cache);

return memoized;
};
const memoizedParse = mem(parse);

export default function getFilenameFromUrl(context, url) {
Expand Down

0 comments on commit 0d55268

Please sign in to comment.