Skip to content

Commit 6f9118d

Browse files
authored
Fix TypeError: "URL.parse is not a function" for Node.js < v22 (#13698)
1 parent d0b6701 commit 6f9118d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/cli/src/config/extensions/github.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,16 @@ export function tryParseGithubUrl(source: string): GithubRepoInfo | null {
9595
}
9696
}
9797
// Default to a github repo path, so `source` can be just an org/repo
98-
const parsedUrl = URL.parse(source, 'https://github.com');
98+
let parsedUrl: URL;
99+
try {
100+
// Use the standard URL constructor for backward compatibility.
101+
parsedUrl = new URL(source, 'https://github.com');
102+
} catch (e) {
103+
// Throw a TypeError to maintain a consistent error contract for invalid URLs.
104+
// This avoids a breaking change for consumers who might expect a TypeError.
105+
throw new TypeError(`Invalid repo URL: ${source}`, { cause: e });
106+
}
107+
99108
if (!parsedUrl) {
100109
throw new Error(`Invalid repo URL: ${source}`);
101110
}

0 commit comments

Comments
 (0)