Skip to content

Commit f56758e

Browse files
authored
feat: use new URL
1 parent a244fb0 commit f56758e

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

src/utils/getFilenameFromUrl.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const path = require("node:path");
22
const querystring = require("node:querystring");
3-
// eslint-disable-next-line n/no-deprecated-api
4-
const { parse } = require("node:url");
53

64
const getPaths = require("./getPaths");
75
const memorize = require("./memorize");
@@ -17,13 +15,25 @@ function decode(input) {
1715
return querystring.unescape(input);
1816
}
1917

20-
const memoizedParse = memorize(parse, undefined, (value) => {
21-
if (value.pathname) {
22-
value.pathname = decode(value.pathname);
23-
}
18+
// const memoizedParse = memorize(parse,
19+
// undefined,
20+
// (value) => {
21+
// console.log({encode: value.pathname});
22+
// if (value.pathname) {
23+
// value.pathname = decode(value.pathname);
24+
// }
25+
// console.log({decode: value.pathname});
26+
27+
// return value;
28+
// },
29+
// );
30+
31+
const memoizedParse = memorize((url) => {
32+
const urlObject = new URL(url, "http://localhost");
2433

25-
return value;
26-
});
34+
// We cann't change pathname in URL object directly because don't decode correctly
35+
return { ...urlObject, pathname: decode(urlObject.pathname) };
36+
}, undefined);
2737

2838
const UP_PATH_REGEXP = /(?:^|[\\/])\.\.(?:[\\/]|$)/;
2939

@@ -59,27 +69,25 @@ function getFilenameFromUrl(context, url) {
5969
let foundFilename;
6070
/** @type {number | undefined} */
6171
let errorCode;
62-
/** @type {import("node:url").Url} */
72+
/** @type {import("node:url").URL} */
6373
let urlObject;
6474

6575
try {
6676
// The `url` property of the `request` is contains only `pathname`, `search` and `hash`
67-
urlObject = memoizedParse(url, false, true);
77+
urlObject = memoizedParse(url);
6878
} catch {
6979
return { errorCode, filename: foundFilename, extra };
7080
}
7181

7282
for (const { publicPath, outputPath, assetsInfo } of paths) {
7383
/** @type {string | undefined} */
7484
let filename;
75-
/** @type {import("node:url").Url} */
85+
/** @type {import("node:url").URL} */
7686
let publicPathObject;
7787

7888
try {
7989
publicPathObject = memoizedParse(
8090
publicPath !== "auto" && publicPath ? publicPath : "/",
81-
false,
82-
true,
8391
);
8492
} catch {
8593
continue;

0 commit comments

Comments
 (0)