99import { logging , tags } from '@angular-devkit/core' ;
1010import { existsSync , promises as fsPromises } from 'fs' ;
1111import { extname , posix , resolve } from 'path' ;
12- import * as url from 'url' ;
12+ import { URL , pathToFileURL } from 'url' ;
1313import { Configuration , RuleSetRule } from 'webpack' ;
1414import { Configuration as DevServerConfiguration } from 'webpack-dev-server' ;
1515import { 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(
300300function 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