Align Flow lib defs for Node.js url with v24 (#55021)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55021

This is an AI-assisted change to align the Flow definitions for the `url` module with the Node.js docs as at v24.

**New Safe Parsing:**

1. **`URL.parse(input, base?)`** - Safe static parsing (added in v22.1.0)
   - Parses URL without throwing exceptions
   - Returns `URL` object on success, `null` on failure
   - Alternative to `new URL()` that doesn't require try-catch
   - Example: `const url = URL.parse(userInput); if (url) { ... }`
   - https://nodejs.org/api/url.html#urlparseinput-base

**New Pattern Matching (Experimental):**

2. **`URLPattern` class** - Web API-compatible URL pattern matching (added in v23.8.0) 🧪
   - Constructor: `new URLPattern(input?, options?)` or `new URLPattern(input, baseURL, options?)`
   - Properties: `protocol`, `username`, `password`, `hostname`, `port`, `pathname`, `search`, `hash`, `hasRegExpGroups` (all readonly)
   - Methods:
     - `test(input?, baseURL?)` - Returns boolean if URL matches pattern
     - `exec(input?, baseURL?)` - Returns match result with captured groups or null
   - Supports wildcard patterns (`*`), named groups (`:param`), and case-insensitive matching
   - Use cases: routing, URL filtering, path matching
   - https://nodejs.org/api/url.html#class-urlpattern

**Enhanced Path Conversion:**

3. **`pathToFileURL(path, options?)`** - Enhanced with options (v20.0.0)
   - New optional `options` parameter: `{windows?: boolean}`
   - Enables cross-platform path conversion testing
   - https://nodejs.org/api/url.html#urlpathtofileurlpath-options

4. **`fileURLToPath(url, options?)`** - Enhanced with options (v20.0.0)
   - New optional `options` parameter: `{windows?: boolean}`
   - Enables cross-platform URL to path conversion testing
   - https://nodejs.org/api/url.html#urlfileurltopathurl-options

**Type Definitions Added:**

5. **`url$URLPatternInit`** - Pattern initialization object
   - Optional properties for each URL component
   - Used in URLPattern constructor and exec/test methods

6. **`url$URLPatternComponentResult`** - Pattern match result for URL component
   - Contains `input` string and captured `groups` object

7. **`url$URLPatternResult`** - Complete pattern match result
   - Contains match results for all URL components
   - Includes original inputs array

**References:**
- Node.js url module docs: https://nodejs.org/api/url.html
- URLPattern Web API spec: https://urlpattern.spec.whatwg.org/

Changelog: [Internal]
 ---
> Generated by [Confucius Code Assist (CCA)](https://www.internalfb.com/wiki/Confucius/Analect/Shared_Analects/Confucius_Code_Assist_(CCA)/)
[Confucius Session](https://www.internalfb.com/confucius?host=devvm45708.cln0.facebook.com&port=8086&tab=Chat&session_id=1a3aa26e-e5a9-11f0-8d47-71a4a90f0494&entry_name=Code+Assist), [Trace](https://www.internalfb.com/confucius?session_id=1a3aa26e-e5a9-11f0-8d47-71a4a90f0494&tab=Trace)

Reviewed By: vzaidman

Differential Revision: D89943253

fbshipit-source-id: aac1f999fa12a161eb8c24229c046d70072adf8a
This commit is contained in:
Rob Hogan authored and meta-codesync[bot] committed 2026-01-02 13:48:27 -08:00
1 parent 4862cc78f8
commit cead39c6d9
1 file changed
+68 -2
+68 -2
View File
@@ -3551,8 +3551,16 @@ declare module 'url' {
declare function resolve(from: string, to: string): string;
declare function domainToASCII(domain: string): string;
declare function domainToUnicode(domain: string): string;
declare function pathToFileURL(path: string): url$urlObject;
declare function fileURLToPath(path: url$urlObject | string): string;
declare function pathToFileURL(
path: string,
options?: Readonly<{windows?: boolean}>,
): url$urlObject;
declare function fileURLToPath(
path: url$urlObject | string,
options?: Readonly<{windows?: boolean}>,
): string;
declare class URLSearchParams {
@@iterator(): Iterator<[string, string]>;
@@ -3588,6 +3596,7 @@ declare module 'url' {
}
declare class URL {
static canParse(url: string, base?: string): boolean;
static parse(input: string, base?: string): URL | null;
static createObjectURL(blob: Blob): string;
static createObjectURL(mediaSource: MediaSource): string;
static revokeObjectURL(url: string): void;
@@ -3607,6 +3616,63 @@ declare module 'url' {
toString(): string;
toJSON(): string;
}
declare type url$URLPatternInit = {
protocol?: string,
username?: string,
password?: string,
hostname?: string,
port?: string,
pathname?: string,
search?: string,
hash?: string,
baseURL?: string,
};
declare type url$URLPatternComponentResult = {
input: string,
groups: {[key: string]: string | void},
};
declare type url$URLPatternResult = {
inputs: $ReadOnlyArray<string | url$URLPatternInit>,
protocol: url$URLPatternComponentResult,
username: url$URLPatternComponentResult,
password: url$URLPatternComponentResult,
hostname: url$URLPatternComponentResult,
port: url$URLPatternComponentResult,
pathname: url$URLPatternComponentResult,
search: url$URLPatternComponentResult,
hash: url$URLPatternComponentResult,
};
declare class URLPattern {
constructor(
input?: string | url$URLPatternInit,
options?: Readonly<{ignoreCase?: boolean}>,
): void;
constructor(
input: string | url$URLPatternInit,
baseURL: string,
options?: Readonly<{ignoreCase?: boolean}>,
): void;
+hasRegExpGroups: boolean;
+hash: string;
+hostname: string;
+password: string;
+pathname: string;
+port: string;
+protocol: string;
+search: string;
+username: string;
exec(
input?: string | url$URLPatternInit,
baseURL?: string,
): url$URLPatternResult | null;
test(input?: string | url$URLPatternInit, baseURL?: string): boolean;
}
}
type util$InspectOptions = {