Skip to content

Commit

Permalink
refactor(@angular-devkit/build-angular): remove usage of deprecated u…
Browse files Browse the repository at this point in the history
…rl methods

Use WHATWG URL API instead of the deprecated url utils.

See https://nodejs.org/api/url.html
  • Loading branch information
alan-agius4 committed Dec 8, 2021
1 parent 562dc6a commit b04cdc3
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { logging, tags } from '@angular-devkit/core';
import { existsSync, promises as fsPromises } from 'fs';
import { extname, posix, resolve } from 'path';
import * as url from 'url';
import { URL, pathToFileURL } from 'url';
import { Configuration, RuleSetRule } from 'webpack';
import { Configuration as DevServerConfiguration } from 'webpack-dev-server';
import { WebpackConfigOptions, WebpackDevServerOptions } from '../../utils/build-options';
Expand Down Expand Up @@ -72,7 +72,7 @@ export async function getDevServerConfig(
rewrites: [
{
from: new RegExp(`^(?!${servePath})/.*`),
to: (context) => url.format(context.parsedUrl),
to: (context) => context.parsedUrl.href,
},
],
},
Expand Down Expand Up @@ -198,7 +198,7 @@ async function addProxyConfig(root: string, proxyConfig: string | undefined) {
// Load the ESM configuration file using the TypeScript dynamic import workaround.
// Once TypeScript provides support for keeping the dynamic import this workaround can be
// changed to a direct dynamic import.
return (await loadEsmModule<{ default: unknown }>(url.pathToFileURL(proxyPath))).default;
return (await loadEsmModule<{ default: unknown }>(pathToFileURL(proxyPath))).default;
case '.cjs':
return require(proxyPath);
default:
Expand All @@ -211,7 +211,7 @@ async function addProxyConfig(root: string, proxyConfig: string | undefined) {
// Load the ESM configuration file using the TypeScript dynamic import workaround.
// Once TypeScript provides support for keeping the dynamic import this workaround can be
// changed to a direct dynamic import.
return (await loadEsmModule<{ default: unknown }>(url.pathToFileURL(proxyPath))).default;
return (await loadEsmModule<{ default: unknown }>(pathToFileURL(proxyPath))).default;
}

throw e;
Expand Down Expand Up @@ -300,11 +300,8 @@ function getAllowedHostsConfig(
function getPublicHostOptions(options: WebpackDevServerOptions, webSocketPath: string): string {
let publicHost: string | null | undefined = options.publicHost;
if (publicHost) {
if (!/^\w+:\/\//.test(publicHost)) {
publicHost = `https://${publicHost}`;
}

publicHost = url.parse(publicHost).host;
const hostWithProtocol = !/^\w+:\/\//.test(publicHost) ? `https://${publicHost}` : publicHost;
publicHost = new URL(hostWithProtocol).host;
}

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

0 comments on commit b04cdc3

Please sign in to comment.