9
9
import { logging , tags } from '@angular-devkit/core' ;
10
10
import { existsSync , promises as fsPromises } from 'fs' ;
11
11
import { extname , posix , resolve } from 'path' ;
12
- import * as url from 'url' ;
12
+ import { URL , pathToFileURL } from 'url' ;
13
13
import { Configuration , RuleSetRule } from 'webpack' ;
14
14
import { Configuration as DevServerConfiguration } from 'webpack-dev-server' ;
15
15
import { WebpackConfigOptions , WebpackDevServerOptions } from '../../utils/build-options' ;
@@ -72,7 +72,7 @@ export async function getDevServerConfig(
72
72
rewrites : [
73
73
{
74
74
from : new RegExp ( `^(?!${ servePath } )/.*` ) ,
75
- to : ( context ) => url . format ( context . parsedUrl ) ,
75
+ to : ( context ) => context . parsedUrl . href ,
76
76
} ,
77
77
] ,
78
78
} ,
@@ -198,7 +198,7 @@ async function addProxyConfig(root: string, proxyConfig: string | undefined) {
198
198
// Load the ESM configuration file using the TypeScript dynamic import workaround.
199
199
// Once TypeScript provides support for keeping the dynamic import this workaround can be
200
200
// 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 ;
202
202
case '.cjs' :
203
203
return require ( proxyPath ) ;
204
204
default :
@@ -211,7 +211,7 @@ async function addProxyConfig(root: string, proxyConfig: string | undefined) {
211
211
// Load the ESM configuration file using the TypeScript dynamic import workaround.
212
212
// Once TypeScript provides support for keeping the dynamic import this workaround can be
213
213
// 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 ;
215
215
}
216
216
217
217
throw e ;
@@ -300,11 +300,8 @@ function getAllowedHostsConfig(
300
300
function getPublicHostOptions ( options : WebpackDevServerOptions , webSocketPath : string ) : string {
301
301
let publicHost : string | null | undefined = options . publicHost ;
302
302
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 ;
308
305
}
309
306
310
307
return `auto://${ publicHost || '0.0.0.0:0' } ${ webSocketPath } ` ;
0 commit comments