Skip to content

Commit 07d2255

Browse files
robhoganmeta-codesync[bot]
authored andcommitted
Align Flow lib defs for Node.js path with v24 (#55006)
Summary: Pull Request resolved: #55006 This is an AI-assisted change to align the Flow definitions for the `path` module with the Node.js docs as at v24. **New APIs:** 1. **`matchesGlob(path, pattern)`** - Glob pattern matching (added in Node.js v22.5.0) - Returns `boolean` indicating if path matches the glob pattern - Supports standard glob syntax: `*`, `?`, `[...]`, `**`, etc. - Example: `path.matchesGlob('/foo/bar', '/foo/*')` returns `true` - https://nodejs.org/api/path.html#pathmatchesglobpath-pattern 2. **`toNamespacedPath(path)`** - Windows namespace-prefixed path conversion - On Windows: converts path to namespace-prefixed path (e.g., `\\?\C:\path`) - On POSIX: returns path unchanged - Enables access to paths longer than 260 characters on Windows - https://nodejs.org/api/path.html#pathtonamespacedpathpath **Type Safety Improvements:** 3. **Replaced `any` types** - Proper typed interfaces - Changed `posix: any` → `posix: path$PlatformPath` - Changed `win32: any` → `win32: path$PlatformPath` - Added `path$PlatformPath` type definition with all methods and properties 4. **Modern Readonly syntax for inputs** - Following readonly rules - `format()` input: Changed to `Readonly<{root?, dir?, base?, ext?, name?}>` - Allows passing readonly types safely (inputs should be readonly) 5. **Made `parse()` return type exact** - Removed spread operator - Return type is now exact: `{root: string, dir: string, base: string, ext: string, name: string}` - Previously had `...` spread operator allowing extra properties - Note: Return type is NOT readonly (outputs are mutable so consumers can modify) 6. **PlatformPath includes parse return as readonly** - Consistency - Within `path$PlatformPath` type, the parse method returns `Readonly<{...}>` - This is for the type definition itself, not the actual module export **References:** - Node.js path module docs: https://nodejs.org/api/path.html - Modern Flow syntax: exact-by-default, `Readonly<T>` for input parameters 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: D89932753 fbshipit-source-id: 9ae777b0be2fdfee8ef4a71e9d1f9fd1cd395215
1 parent 50f310d commit 07d2255

1 file changed

Lines changed: 59 additions & 23 deletions

File tree

flow-typed/environment/node.js

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ declare module 'crypto' {
814814
callback: (err: ?Error, buffer: Buffer) => void,
815815
): void;
816816
declare function randomUUID(
817-
options?: $ReadOnly<{|disableEntropyCache?: boolean|}>,
817+
options?: Readonly<{disableEntropyCache?: boolean}>,
818818
): string;
819819
declare function timingSafeEqual(
820820
a: Buffer | $TypedArray | DataView,
@@ -1701,7 +1701,7 @@ declare module 'fs' {
17011701
}>,
17021702
): void;
17031703

1704-
declare type GlobOptions<WithFileTypes: boolean> = $ReadOnly<{
1704+
declare type GlobOptions<WithFileTypes: boolean> = Readonly<{
17051705
/**
17061706
* Current working directory.
17071707
* @default process.cwd()
@@ -2593,10 +2593,45 @@ declare module 'os' {
25932593
declare var EOL: string;
25942594
}
25952595

2596+
type path$PlatformPath = {
2597+
normalize(path: string): string,
2598+
join(...parts: Array<string>): string,
2599+
resolve(...parts: Array<string>): string,
2600+
matchesGlob(path: string, pattern: string): boolean,
2601+
isAbsolute(path: string): boolean,
2602+
relative(from: string, to: string): string,
2603+
dirname(path: string): string,
2604+
basename(path: string, ext?: string): string,
2605+
extname(path: string): string,
2606+
sep: string,
2607+
delimiter: string,
2608+
parse(pathString: string): Readonly<{
2609+
root: string,
2610+
dir: string,
2611+
base: string,
2612+
ext: string,
2613+
name: string,
2614+
}>,
2615+
format(
2616+
pathObject: Readonly<{
2617+
root?: string,
2618+
dir?: string,
2619+
base?: string,
2620+
ext?: string,
2621+
name?: string,
2622+
}>,
2623+
): string,
2624+
toNamespacedPath(path: string): string,
2625+
posix: path$PlatformPath,
2626+
win32: path$PlatformPath,
2627+
...
2628+
};
2629+
25962630
declare module 'path' {
25972631
declare function normalize(path: string): string;
25982632
declare function join(...parts: Array<string>): string;
25992633
declare function resolve(...parts: Array<string>): string;
2634+
declare function matchesGlob(path: string, pattern: string): boolean;
26002635
declare function isAbsolute(path: string): boolean;
26012636
declare function relative(from: string, to: string): string;
26022637
declare function dirname(path: string): string;
@@ -2610,18 +2645,19 @@ declare module 'path' {
26102645
base: string,
26112646
ext: string,
26122647
name: string,
2613-
...
26142648
};
2615-
declare function format(pathObject: {
2616-
root?: string,
2617-
dir?: string,
2618-
base?: string,
2619-
ext?: string,
2620-
name?: string,
2621-
...
2622-
}): string;
2623-
declare var posix: any;
2624-
declare var win32: any;
2649+
declare function format(
2650+
pathObject: Readonly<{
2651+
root?: string,
2652+
dir?: string,
2653+
base?: string,
2654+
ext?: string,
2655+
name?: string,
2656+
}>,
2657+
): string;
2658+
declare function toNamespacedPath(path: string): string;
2659+
declare var posix: path$PlatformPath;
2660+
declare var win32: path$PlatformPath;
26252661
}
26262662

26272663
declare module 'punycode' {
@@ -2867,7 +2903,7 @@ declare class stream$Duplex extends stream$Readable mixins stream$Writable {
28672903
// $FlowFixMe[incompatible-exact] See above
28682904
// $FlowFixMe[incompatible-type] See above
28692905
static fromWeb(
2870-
pair: $ReadOnly<{
2906+
pair: Readonly<{
28712907
readable: ReadableStream,
28722908
writable: WritableStream,
28732909
}>,
@@ -3379,30 +3415,30 @@ type util$InspectOptions = {
33793415
};
33803416

33813417
declare type util$ParseArgsOption =
3382-
| $ReadOnly<{|
3418+
| Readonly<{
33833419
type: 'boolean',
33843420
multiple?: false,
33853421
short?: string,
33863422
default?: boolean,
3387-
|}>
3388-
| $ReadOnly<{|
3423+
}>
3424+
| Readonly<{
33893425
type: 'boolean',
33903426
multiple: true,
33913427
short?: string,
33923428
default?: Array<boolean>,
3393-
|}>
3394-
| $ReadOnly<{|
3429+
}>
3430+
| Readonly<{
33953431
type: 'string',
33963432
multiple?: false,
33973433
short?: string,
33983434
default?: string,
3399-
|}>
3400-
| $ReadOnly<{|
3435+
}>
3436+
| Readonly<{
34013437
type: 'string',
34023438
multiple: true,
34033439
short?: string,
34043440
default?: Array<string>,
3405-
|}>;
3441+
}>;
34063442

34073443
type util$ParseArgsOptionToValue<TOption> = TOption['type'] extends 'boolean'
34083444
? TOption['multiple'] extends true
@@ -3613,7 +3649,7 @@ declare module 'util' {
36133649
| Modifiers
36143650
| $ReadOnlyArray<ForegroundColors | BackgroundColors | Modifiers>,
36153651
text: string,
3616-
options?: $ReadOnly<{
3652+
options?: Readonly<{
36173653
stream?: ?stream$Stream,
36183654
validateStream?: ?boolean,
36193655
}>,

0 commit comments

Comments
 (0)