From ed0c5f6f54104ede106838ae85b012110b342f37 Mon Sep 17 00:00:00 2001 From: Ian Clanton-Thuon Date: Fri, 20 Feb 2026 17:16:42 -0800 Subject: [PATCH] fix(rush-lib): replace deprecated url.parse() with WHATWG URL API in Git.normalizeGitUrlForComparison Replace the deprecated Node.js url.parse() call with the WHATWG URL constructor in Git.normalizeGitUrlForComparison(). The URL constructor is wrapped in a try/catch to gracefully handle non-URL strings (local paths, etc.) that would throw. The WHATWG URL API correctly strips default ports (e.g. port 80 for HTTP), which is more correct for URL comparison purposes. Updated the corresponding test expectation accordingly. --- ...-deprecation-warning_2026-02-21-01-15.json | 11 +++++ libraries/rush-lib/src/logic/Git.ts | 45 ++++++++++--------- libraries/rush-lib/src/logic/test/Git.test.ts | 2 +- 3 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 common/changes/@microsoft/rush/fix-url-deprecation-warning_2026-02-21-01-15.json diff --git a/common/changes/@microsoft/rush/fix-url-deprecation-warning_2026-02-21-01-15.json b/common/changes/@microsoft/rush/fix-url-deprecation-warning_2026-02-21-01-15.json new file mode 100644 index 00000000000..efcd84c45fb --- /dev/null +++ b/common/changes/@microsoft/rush/fix-url-deprecation-warning_2026-02-21-01-15.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "", + "type": "none", + "packageName": "@microsoft/rush" + } + ], + "packageName": "@microsoft/rush", + "email": "iclanton@users.noreply.github.com" +} \ No newline at end of file diff --git a/libraries/rush-lib/src/logic/Git.ts b/libraries/rush-lib/src/logic/Git.ts index 07fef282fc3..36386d4224d 100644 --- a/libraries/rush-lib/src/logic/Git.ts +++ b/libraries/rush-lib/src/logic/Git.ts @@ -3,7 +3,6 @@ import type child_process from 'node:child_process'; import * as path from 'node:path'; -import * as url from 'node:url'; import gitInfo from 'git-repo-info'; import { trueCasePathSync } from 'true-case-path'; @@ -487,25 +486,31 @@ export class Git { } } - const parsedUrl: url.UrlWithStringQuery = url.parse(result); - - // Only convert recognized schemes - - switch (parsedUrl.protocol) { - case 'http:': - case 'https:': - case 'ssh:': - case 'ftp:': - case 'ftps:': - case 'git:': - case 'git+http:': - case 'git+https:': - case 'git+ssh:': - case 'git+ftp:': - case 'git+ftps:': - // Assemble the parts we want: - result = `https://${parsedUrl.host}${parsedUrl.pathname}`; - break; + // Use the WHATWG URL API instead of the deprecated url.parse(). + // The URL constructor throws for non-standard URLs (e.g. local paths), so we + // catch and leave the result unchanged in that case. + try { + const parsedUrl: URL = new URL(result); + + // Only convert recognized schemes + switch (parsedUrl.protocol) { + case 'http:': + case 'https:': + case 'ssh:': + case 'ftp:': + case 'ftps:': + case 'git:': + case 'git+http:': + case 'git+https:': + case 'git+ssh:': + case 'git+ftp:': + case 'git+ftps:': + // Assemble the parts we want: + result = `https://${parsedUrl.host}${parsedUrl.pathname}`; + break; + } + } catch { + // Not a valid URL (e.g. a local path) -- leave result unchanged } // Trim ".git" or ".git/" from the end diff --git a/libraries/rush-lib/src/logic/test/Git.test.ts b/libraries/rush-lib/src/logic/test/Git.test.ts index 6eed35e5de7..54d4c7d0035 100644 --- a/libraries/rush-lib/src/logic/test/Git.test.ts +++ b/libraries/rush-lib/src/logic/test/Git.test.ts @@ -19,7 +19,7 @@ describe(Git.name, () => { 'https://host.xz/path/to/repo' ); expect(Git.normalizeGitUrlForComparison('http://host.xz:80/path/to/repo')).toEqual( - 'https://host.xz:80/path/to/repo' + 'https://host.xz/path/to/repo' ); expect(Git.normalizeGitUrlForComparison('host.xz:path/to/repo.git/')).toEqual( 'https://host.xz/path/to/repo'