Skip to content

Commit fd58a05

Browse files
committed
chore: drop memoize
1 parent 2187903 commit fd58a05

File tree

4 files changed

+15
-22
lines changed

4 files changed

+15
-22
lines changed

package-lock.json

Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
},
4242
"dependencies": {
4343
"colorette": "^1.2.2",
44-
"fast-memoize": "^2.5.2",
4544
"memfs": "^3.2.2",
4645
"mime-types": "^2.1.31",
4746
"range-parser": "^1.2.1",

src/utils/getFilenameFromUrl.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import path from "path";
2-
import { parse } from "url";
2+
import { URL } from "url";
33
import querystring from "querystring";
44

5-
import memoize from "fast-memoize";
6-
75
import getPaths from "./getPaths";
86

9-
const memoizedParse = memoize(parse);
7+
const urlCache = new Map();
8+
const parseUrl = (url) => {
9+
if (urlCache.has(url)) {
10+
return urlCache.get(url);
11+
}
12+
13+
const parsed = new URL(url, "http://localhost/");
14+
urlCache.set(url, parsed);
15+
return parsed;
16+
};
1017

1118
export default function getFilenameFromUrl(context, url) {
1219
const { options } = context;
@@ -17,7 +24,7 @@ export default function getFilenameFromUrl(context, url) {
1724

1825
try {
1926
// The `url` property of the `request` is contains only `pathname`, `search` and `hash`
20-
urlObject = memoizedParse(url, false, true);
27+
urlObject = parseUrl(url);
2128
} catch (_ignoreError) {
2229
return;
2330
}
@@ -27,10 +34,8 @@ export default function getFilenameFromUrl(context, url) {
2734
let publicPathObject;
2835

2936
try {
30-
publicPathObject = memoizedParse(
31-
publicPath !== "auto" && publicPath ? publicPath : "/",
32-
false,
33-
true
37+
publicPathObject = parseUrl(
38+
publicPath !== "auto" && publicPath ? publicPath : "/"
3439
);
3540
} catch (_ignoreError) {
3641
// eslint-disable-next-line no-continue

test/middleware.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ describe.each([
300300
output: {
301301
filename: "bundle.js",
302302
path: outputPath,
303-
publicPath: "https://test:malfor%5Med@test.example.com",
303+
publicPath: "https://malformed:test.example.com",
304304
},
305305
});
306306

0 commit comments

Comments
 (0)