Skip to content

Commit cbd7e9b

Browse files
committed
code review
1 parent a2319fe commit cbd7e9b

9 files changed

Lines changed: 55 additions & 53 deletions

File tree

apps/site/components/Downloads/Release/OperatingSystemDropdown.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import type { FC } from 'react';
77

88
import { useClientContext } from '#site/hooks';
99
import { ReleaseContext } from '#site/providers/releaseProvider';
10-
import type { UserOS } from '#site/types/userAgent';
10+
import type { OperatingSystem } from '#site/types/userAgent';
1111
import { nextItem, OPERATING_SYSTEMS, parseCompat } from '#site/util/download';
1212

13-
type OperatingSystemDropdownProps = { exclude?: Array<UserOS> };
13+
type OperatingSystemDropdownProps = { exclude?: Array<OperatingSystem> };
1414

1515
const OperatingSystemDropdown: FC<OperatingSystemDropdownProps> = () => {
1616
const { os } = useClientContext();
@@ -49,7 +49,7 @@ const OperatingSystemDropdown: FC<OperatingSystemDropdownProps> = () => {
4949
);
5050

5151
return (
52-
<Select<UserOS>
52+
<Select<OperatingSystem>
5353
values={parsedOperatingSystems}
5454
defaultValue={release.os !== 'LOADING' ? release.os : undefined}
5555
loading={release.os === 'LOADING'}

apps/site/components/Downloads/Release/PlatformDropdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useEffect, useContext, useMemo } from 'react';
77

88
import { useClientContext } from '#site/hooks';
99
import { ReleaseContext } from '#site/providers/releaseProvider';
10-
import type { UserPlatform } from '#site/types/userAgent';
10+
import type { Platform } from '#site/types/userAgent';
1111
import { PLATFORMS, nextItem, parseCompat } from '#site/util/download';
1212
import { getUserPlatform } from '#site/util/userAgent';
1313

@@ -57,7 +57,7 @@ const PlatformDropdown: FC = () => {
5757
);
5858

5959
return (
60-
<Select<UserPlatform>
60+
<Select<Platform>
6161
values={parsedPlatforms}
6262
defaultValue={release.platform !== '' ? release.platform : undefined}
6363
loading={release.os === 'LOADING' || release.platform === ''}

apps/site/hooks/react-client/useDetectOS.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import { useEffect, useState } from 'react';
44

55
import type {
6-
UserArchitecture,
7-
UserBitness,
8-
UserOS,
6+
Architecture,
7+
Bitness,
8+
OperatingSystem,
99
} from '#site/types/userAgent';
1010
import { getHighEntropyValues, detectOS } from '#site/util/userAgent';
1111

1212
type UserOSState = {
13-
os: UserOS | 'LOADING';
14-
bitness: UserBitness | '';
15-
architecture: UserArchitecture | '';
13+
os: OperatingSystem | 'LOADING';
14+
bitness: Bitness | '';
15+
architecture: Architecture | '';
1616
};
1717

1818
const useDetectOS = () => {
@@ -45,8 +45,8 @@ const useDetectOS = () => {
4545
}) => {
4646
setUserOSState(current => ({
4747
...current,
48-
bitness: bitness as UserBitness,
49-
architecture: architecture as UserArchitecture,
48+
bitness: bitness as Bitness,
49+
architecture: architecture as Architecture,
5050
}));
5151
}
5252
);

apps/site/types/release.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DownloadSnippet } from '#site/types/download';
22
import type { NodeRelease } from '#site/types/releases';
3-
import type { UserOS, UserPlatform } from '#site/types/userAgent';
3+
import type { OperatingSystem, Platform } from '#site/types/userAgent';
44

55
export type InstallationMethod =
66
| 'NVM'
@@ -17,23 +17,23 @@ export type PackageManager = 'NPM' | 'YARN' | 'PNPM';
1717
// during runtime and do not have necessarily a consistent initial value
1818
export interface ReleaseState {
1919
version: string;
20-
os: UserOS | 'LOADING';
21-
platform: UserPlatform | '';
20+
os: OperatingSystem | 'LOADING';
21+
platform: Platform | '';
2222
installMethod: InstallationMethod | '';
2323
packageManager: PackageManager;
2424
}
2525

2626
export type ReleaseAction =
2727
| { type: 'SET_VERSION'; payload: string }
28-
| { type: 'SET_OS'; payload: UserOS }
29-
| { type: 'SET_PLATFORM'; payload: UserPlatform }
28+
| { type: 'SET_OS'; payload: OperatingSystem }
29+
| { type: 'SET_PLATFORM'; payload: Platform }
3030
| { type: 'SET_INSTALL_METHOD'; payload: InstallationMethod }
3131
| { type: 'SET_MANAGER'; payload: PackageManager };
3232

3333
export interface ReleaseDispatchActions {
3434
setVersion: (version: string) => void;
35-
setOS: (os: UserOS) => void;
36-
setPlatform: (bitness: UserPlatform) => void;
35+
setOS: (os: OperatingSystem) => void;
36+
setPlatform: (bitness: Platform) => void;
3737
setInstallMethod: (installMethod: InstallationMethod) => void;
3838
setPackageManager: (packageManager: PackageManager) => void;
3939
}

apps/site/types/userAgent.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import type constants from '../util/download/constants.json';
22

33
// Extract OS key type from the systems object
4-
export type UserOS = keyof typeof constants.systems;
4+
export type OperatingSystem = keyof typeof constants.systems;
55

66
// Derive the union type of UserPlatform from the userOptions
7-
export type UserPlatform = (typeof constants.userOptions.platforms)[number];
7+
export type Platform = (typeof constants.userOptions.platforms)[number];
88

99
// Derive the union type of UserBitness from the userOptions
10-
export type UserBitness = (typeof constants.userOptions.bitness)[number];
10+
export type Bitness = (typeof constants.userOptions.bitness)[number];
1111

1212
// Derive the union type of UserArchitecture from the userOptions
13-
export type UserArchitecture =
14-
(typeof constants.userOptions.architecture)[number];
13+
export type Architecture = (typeof constants.userOptions.architecture)[number];

apps/site/util/download/index.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import satisfies from 'semver/functions/satisfies';
88
import type {
99
IntlMessageKeys,
1010
NodeReleaseStatus,
11-
UserOS,
12-
UserPlatform,
11+
OperatingSystem,
12+
Platform,
1313
} from '#site/types';
1414
import type * as Types from '#site/types/release';
1515

@@ -29,9 +29,9 @@ export const OperatingSystemLabel = Object.fromEntries(
2929

3030
// Base types for dropdown functionality
3131
type DownloadCompatibility = {
32-
os?: Array<UserOS | 'LOADING'>;
32+
os?: Array<OperatingSystem | 'LOADING'>;
3333
installMethod?: Array<string>;
34-
platform?: Array<UserPlatform | ''>;
34+
platform?: Array<Platform | ''>;
3535
semver?: Array<string>;
3636
releases?: Array<NodeReleaseStatus>;
3737
};
@@ -107,7 +107,7 @@ export const OPERATING_SYSTEMS = Object.entries(systems as ActualSystems)
107107
.filter(([key]) => key !== 'LOADING' && key !== 'OTHER')
108108
.map(([key, data]) => ({
109109
label: data.name as IntlMessageKeys,
110-
value: key as UserOS,
110+
value: key as OperatingSystem,
111111
compatibility: data.compatibility,
112112
iconImage: createIcon(OSIcons, data.icon),
113113
}));
@@ -123,7 +123,7 @@ export const INSTALL_METHODS = installMethods.map(method => ({
123123
info: method.info as IntlMessageKeys,
124124
compatibility: {
125125
...method.compatibility,
126-
os: method.compatibility?.os?.map(os => os as UserOS),
126+
os: method.compatibility?.os?.map(os => os as OperatingSystem),
127127
releases: method.compatibility?.releases?.map(
128128
release => release as NodeReleaseStatus
129129
),
@@ -148,8 +148,8 @@ export const PLATFORMS = Object.fromEntries(
148148
key,
149149
data.platforms.map(platform => ({
150150
label: platform.label,
151-
value: platform.value as UserPlatform,
151+
value: platform.value as Platform,
152152
compatibility: platform.compatibility || {},
153153
})),
154154
])
155-
) as Record<UserOS | 'LOADING', Array<DownloadDropdownItem<UserPlatform>>>;
155+
) as Record<OperatingSystem | 'LOADING', Array<DownloadDropdownItem<Platform>>>;

apps/site/util/objects.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
type DebounceFunction<T = unknown> = (...args: Array<T>) => void;
22

3-
let timeoutId: NodeJS.Timeout;
3+
export const debounce = <T extends DebounceFunction>(
4+
func: T,
5+
delay: number
6+
): ((...args: Parameters<T>) => void) => {
7+
let timeoutId: NodeJS.Timeout;
48

5-
export const debounce =
6-
<T extends DebounceFunction>(
7-
func: T,
8-
delay: number
9-
): ((...args: Parameters<T>) => void) =>
10-
(...args: Parameters<T>) => {
9+
return (...args: Parameters<T>) => {
1110
clearTimeout(timeoutId);
1211

1312
timeoutId = setTimeout(() => {
1413
func(...args);
1514
}, delay);
1615
};
16+
};
1717

1818
export function deepMerge<Obj1 extends object, Obj2 extends object>(
1919
obj1: Obj1,

apps/site/util/url.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { satisfies } from 'semver';
22

33
import { DOCS_URL, DIST_URL } from '#site/next.constants.mjs';
4-
import type { UserOS, UserPlatform, DownloadKind } from '#site/types';
4+
import type { OperatingSystem, Platform, DownloadKind } from '#site/types';
55

66
export const getNodeApiUrl = (version: string) => {
77
if (satisfies(version, '>=0.3.1 <0.5.1')) {
@@ -19,8 +19,8 @@ export const getNodeApiUrl = (version: string) => {
1919

2020
export const getNodeDownloadUrl = (
2121
versionWithPrefix: string,
22-
os: UserOS | 'LOADING',
23-
platform: UserPlatform = 'x64',
22+
os: OperatingSystem | 'LOADING',
23+
platform: Platform = 'x64',
2424
kind: DownloadKind = 'installer'
2525
) => {
2626
const baseURL = `${DIST_URL}${versionWithPrefix}`;

apps/site/util/userAgent.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/// <reference types="user-agent-data-types" />
22

33
import type {
4-
UserOS,
5-
UserArchitecture,
6-
UserBitness,
7-
UserPlatform,
4+
OperatingSystem,
5+
Architecture,
6+
Bitness,
7+
Platform,
88
} from '#site/types';
99

1010
// Constants for better maintainability
@@ -16,27 +16,30 @@ const EMPTY_UA_DATA: UADataValues = {};
1616
* @param userAgent - The user agent string to parse
1717
* @returns The detected OS or 'OTHER' if not recognized
1818
*/
19-
export const detectOsInUserAgent = (userAgent: string | undefined): UserOS => {
19+
export const detectOsInUserAgent = (
20+
userAgent: string | undefined
21+
): OperatingSystem => {
2022
const osMatch = userAgent?.match(OS_PATTERNS);
21-
return osMatch ? (osMatch[1].toUpperCase() as UserOS) : 'OTHER';
23+
return osMatch ? (osMatch[1].toUpperCase() as OperatingSystem) : 'OTHER';
2224
};
2325

2426
/**
2527
* Detects operating system using navigator.userAgent
2628
* Note: navigator.appVersion is deprecated, so we use userAgent instead
2729
* @see https://developer.mozilla.org/en-US/docs/Web/API/Navigator/appVersion
2830
*/
29-
export const detectOS = (): UserOS => detectOsInUserAgent(navigator?.userAgent);
31+
export const detectOS = (): OperatingSystem =>
32+
detectOsInUserAgent(navigator?.userAgent);
3033

3134
/**
3235
* Determines user platform based on architecture and bitness
3336
* Used for automatic platform detection with `useDetectOS`
3437
* @see https://developer.mozilla.org/en-US/docs/Web/API/NavigatorUAData/getHighEntropyValues
3538
*/
3639
export const getUserPlatform = (
37-
userArchitecture: UserArchitecture | '',
38-
userBitness: UserBitness | ''
39-
): UserPlatform => {
40+
userArchitecture: Architecture | '',
41+
userBitness: Bitness | ''
42+
): Platform => {
4043
if (userArchitecture === 'arm' && userBitness === '64') {
4144
return 'arm64';
4245
}

0 commit comments

Comments
 (0)