Skip to content

Commit b27261b

Browse files
committed
Remove 'url' imports
The URL global works fine in both Node and the browser. Webpack v5 will no longer provide a polyfill for 'url' in the browser.
1 parent a8de1d4 commit b27261b

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

root/components/LinkSearchableProperty.js

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
88
*/
99

10-
import {URL} from 'url';
11-
1210
import * as React from 'react';
1311

1412
import {CatalystContext} from '../context';

root/layout/components/ExternalLinks.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
88
*/
99

10-
import URL from 'url';
11-
1210
import * as React from 'react';
1311

1412
import EntityLink from '../../static/scripts/common/components/EntityLink';
@@ -20,7 +18,7 @@ import isDisabledLink from '../../utility/isDisabledLink';
2018

2119
function faviconClass(urlEntity) {
2220
let matchingClass;
23-
const urlObject = URL.parse(urlEntity.name, false, true);
21+
const urlObject = new URL(urlEntity.name);
2422

2523
for (const key in FAVICON_CLASSES) {
2624
if ((key.indexOf('/') >= 0 && urlEntity.name.indexOf(key) >= 0) ||

root/layout/components/sidebar/ReleaseSidebar.js

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
88
*/
99

10-
import {URL} from 'url';
11-
1210
import * as React from 'react';
1311
import * as ReactDOMServer from 'react-dom/server';
1412

root/utility/uriWith.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
88
*/
99

10-
import url from 'url';
11-
1210
export default function uriWith<T: {...}>(
1311
uriString: string,
1412
params: T,
1513
): string {
16-
const u = url.parse(uriString, true);
14+
const urlObject = new URL(uriString);
15+
const searchParams = new URLSearchParams(urlObject.search);
16+
17+
for (const key of Object.keys(params)) {
18+
searchParams.set(key, params[key]);
19+
}
1720

18-
u.query = Object.assign(u.query, params);
19-
u.search = null;
21+
urlObject.search = searchParams.toString();
2022

21-
return url.format(u);
23+
return urlObject.href;
2224
}

0 commit comments

Comments
 (0)