Skip to content

Commit b04cdc3

Browse files
committed
refactor(@angular-devkit/build-angular): remove usage of deprecated url methods
Use WHATWG URL API instead of the deprecated url utils. See https://nodejs.org/api/url.html
1 parent 562dc6a commit b04cdc3

File tree

1 file changed

+6
-9
lines changed
  • packages/angular_devkit/build_angular/src/webpack/configs

1 file changed

+6
-9
lines changed

packages/angular_devkit/build_angular/src/webpack/configs/dev-server.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import { logging, tags } from '@angular-devkit/core';
1010
import { existsSync, promises as fsPromises } from 'fs';
1111
import { extname, posix, resolve } from 'path';
12-
import * as url from 'url';
12+
import { URL, pathToFileURL } from 'url';
1313
import { Configuration, RuleSetRule } from 'webpack';
1414
import { Configuration as DevServerConfiguration } from 'webpack-dev-server';
1515
import { WebpackConfigOptions, WebpackDevServerOptions } from '../../utils/build-options';
@@ -72,7 +72,7 @@ export async function getDevServerConfig(
7272
rewrites: [
7373
{
7474
from: new RegExp(`^(?!${servePath})/.*`),
75-
to: (context) => url.format(context.parsedUrl),
75+
to: (context) => context.parsedUrl.href,
7676
},
7777
],
7878
},
@@ -198,7 +198,7 @@ async function addProxyConfig(root: string, proxyConfig: string | undefined) {
198198
// Load the ESM configuration file using the TypeScript dynamic import workaround.
199199
// Once TypeScript provides support for keeping the dynamic import this workaround can be
200200
// changed to a direct dynamic import.
201-
return (await loadEsmModule<{ default: unknown }>(url.pathToFileURL(proxyPath))).default;
201+
return (await loadEsmModule<{ default: unknown }>(pathToFileURL(proxyPath))).default;
202202
case '.cjs':
203203
return require(proxyPath);
204204
default:
@@ -211,7 +211,7 @@ async function addProxyConfig(root: string, proxyConfig: string | undefined) {
211211
// Load the ESM configuration file using the TypeScript dynamic import workaround.
212212
// Once TypeScript provides support for keeping the dynamic import this workaround can be
213213
// changed to a direct dynamic import.
214-
return (await loadEsmModule<{ default: unknown }>(url.pathToFileURL(proxyPath))).default;
214+
return (await loadEsmModule<{ default: unknown }>(pathToFileURL(proxyPath))).default;
215215
}
216216

217217
throw e;
@@ -300,11 +300,8 @@ function getAllowedHostsConfig(
300300
function getPublicHostOptions(options: WebpackDevServerOptions, webSocketPath: string): string {
301301
let publicHost: string | null | undefined = options.publicHost;
302302
if (publicHost) {
303-
if (!/^\w+:\/\//.test(publicHost)) {
304-
publicHost = `https://${publicHost}`;
305-
}
306-
307-
publicHost = url.parse(publicHost).host;
303+
const hostWithProtocol = !/^\w+:\/\//.test(publicHost) ? `https://${publicHost}` : publicHost;
304+
publicHost = new URL(hostWithProtocol).host;
308305
}
309306

310307
return `auto://${publicHost || '0.0.0.0:0'}${webSocketPath}`;

0 commit comments

Comments
 (0)