Skip to content

Commit 8084fe6

Browse files
robhoganmeta-codesync[bot]
authored andcommitted
Align Flow lib defs for Node.js os with v24 (#55014)
Summary: Pull Request resolved: #55014 This is an AI-assisted change to align the Flow definitions for the `os` module with the Node.js docs as at v24. **New APIs:** 1. **`machine()`** - Returns machine type (added in v18.9.0, v16.18.0) - Returns hardware name: `'x86_64'`, `'arm64'`, `'aarch64'`, etc. - Different from `arch()` which returns the architecture Node.js was compiled for - https://nodejs.org/api/os.html#osmachine 2. **`version()`** - Returns kernel version string (added in v13.11.0, v12.17.0) - Example: `'Linux 5.15.0-1234-generic'`, `'Darwin Kernel Version 21.6.0'` - https://nodejs.org/api/os.html#osversion 3. **`setPriority([pid,] priority)`** / **`getPriority([pid])`** - Process priority management - Set/get scheduling priority for processes - Priority constants available in `os.constants.priority` - https://nodejs.org/api/os.html#ossetprioritypid-priority - https://nodejs.org/api/os.html#osgetprioritypid 4. **`devNull` constant** - Path to null device (`'/dev/null'` on POSIX, `'\\\\.\\nul'` on Windows) - https://nodejs.org/api/os.html#osdevnull 5. **`constants` object** - OS constants (signals, errno, priority, dlopen) - `constants.signals` - Process signal constants - `constants.errno` - Error number constants - `constants.priority` - Process priority constants (PRIORITY_LOW, PRIORITY_HIGH, etc.) - Readonly - `constants.dlopen` - Dynamic library loading constants - https://nodejs.org/api/os.html#os-constants **Type Safety Improvements:** 6. **`arch()` return type** - Now includes all 10 supported architectures: - Added: `'loong64'` (LoongArch - newer Chinese CPU architecture) - Complete list: `'arm'`, `'arm64'`, `'ia32'`, `'loong64'`, `'mips'`, `'mipsel'`, `'ppc64'`, `'riscv64'`, `'s390x'`, `'x64'` - https://nodejs.org/api/os.html#osarch 7. **`platform()` return type** - Now union of 10 specific platforms instead of generic `string`: - `'aix'`, `'android'`, `'darwin'`, `'freebsd'`, `'haiku'`, `'linux'`, `'openbsd'`, `'sunos'`, `'win32'`, `'cygwin'` - https://nodejs.org/api/os.html#osplatform 8. **Output type definitions made exact** - Removed spread operators (outputs are mutable) - `os$CPU` - Removed spread operators from main type and nested `times` object - `os$NetIFAddr` - Added missing `scopeid?` and `cidr` properties, removed spread operator - `os$UserInfo$*` - Types are mutable (not readonly) so consumers can modify returned values - `networkInterfaces()` return type - Removed spread operator for exact type 9. **Input types use Readonly** - Following readonly rules - `userInfo()` options: Changed to `Readonly<{encoding: 'buffer' | 'utf8'}>` - Allows passing readonly types safely **References:** - Node.js os module docs: https://nodejs.org/api/os.html 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: D89940756 fbshipit-source-id: 29a91c49716bc08eb2c94892e3648db9e40b06d4
1 parent 83b21bb commit 8084fe6

1 file changed

Lines changed: 53 additions & 16 deletions

File tree

flow-typed/environment/node.js

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,9 +2682,7 @@ type os$CPU = {
26822682
nice: number,
26832683
sys: number,
26842684
user: number,
2685-
...
26862685
},
2687-
...
26882686
};
26892687

26902688
type os$NetIFAddr = {
@@ -2693,7 +2691,8 @@ type os$NetIFAddr = {
26932691
internal: boolean,
26942692
mac: string,
26952693
netmask: string,
2696-
...
2694+
scopeid?: number,
2695+
cidr: ?string,
26972696
};
26982697

26992698
type os$UserInfo$buffer = {
@@ -2702,7 +2701,6 @@ type os$UserInfo$buffer = {
27022701
username: Buffer,
27032702
homedir: Buffer,
27042703
shell: ?Buffer,
2705-
...
27062704
};
27072705

27082706
type os$UserInfo$string = {
@@ -2711,37 +2709,76 @@ type os$UserInfo$string = {
27112709
username: string,
27122710
homedir: string,
27132711
shell: ?string,
2714-
...
27152712
};
27162713

27172714
declare module 'os' {
2718-
declare function arch(): 'x64' | 'arm' | 'ia32';
2715+
declare function arch():
2716+
| 'arm'
2717+
| 'arm64'
2718+
| 'ia32'
2719+
| 'loong64'
2720+
| 'mips'
2721+
| 'mipsel'
2722+
| 'ppc64'
2723+
| 'riscv64'
2724+
| 's390x'
2725+
| 'x64';
27192726
declare function availableParallelism(): number;
27202727
declare function cpus(): Array<os$CPU>;
27212728
declare function endianness(): 'BE' | 'LE';
27222729
declare function freemem(): number;
2730+
declare function getPriority(pid?: number): number;
27232731
declare function homedir(): string;
27242732
declare function hostname(): string;
27252733
declare function loadavg(): [number, number, number];
2734+
declare function machine(): string;
27262735
declare function networkInterfaces(): {
27272736
[ifName: string]: Array<os$NetIFAddr>,
2728-
...
27292737
};
2730-
declare function platform(): string;
2738+
declare function platform():
2739+
| 'aix'
2740+
| 'android'
2741+
| 'darwin'
2742+
| 'freebsd'
2743+
| 'haiku'
2744+
| 'linux'
2745+
| 'openbsd'
2746+
| 'sunos'
2747+
| 'win32'
2748+
| 'cygwin';
27312749
declare function release(): string;
2750+
declare function setPriority(priority: number): void;
2751+
declare function setPriority(pid: number, priority: number): void;
27322752
declare function tmpdir(): string;
27332753
declare function totalmem(): number;
27342754
declare function type(): string;
27352755
declare function uptime(): number;
2736-
declare function userInfo(options: {
2737-
encoding: 'buffer',
2738-
...
2739-
}): os$UserInfo$buffer;
2740-
declare function userInfo(options?: {
2741-
encoding: 'utf8',
2742-
...
2743-
}): os$UserInfo$string;
2756+
declare function userInfo(
2757+
options: Readonly<{
2758+
encoding: 'buffer',
2759+
}>,
2760+
): os$UserInfo$buffer;
2761+
declare function userInfo(
2762+
options?: Readonly<{
2763+
encoding: 'utf8',
2764+
}>,
2765+
): os$UserInfo$string;
2766+
declare function version(): string;
27442767
declare var EOL: string;
2768+
declare var devNull: string;
2769+
declare var constants: Readonly<{
2770+
signals: {[key: string]: number, ...},
2771+
errno: {[key: string]: number, ...},
2772+
priority: Readonly<{
2773+
PRIORITY_LOW: number,
2774+
PRIORITY_BELOW_NORMAL: number,
2775+
PRIORITY_NORMAL: number,
2776+
PRIORITY_ABOVE_NORMAL: number,
2777+
PRIORITY_HIGH: number,
2778+
PRIORITY_HIGHEST: number,
2779+
}>,
2780+
dlopen: {[key: string]: number, ...},
2781+
}>;
27452782
}
27462783

27472784
type path$PlatformPath = {

0 commit comments

Comments
 (0)