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 0000000000..efcd84c45f --- /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 07fef282fc..36386d4224 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 6eed35e5de..54d4c7d003 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'