Skip to content

Commit 8a4b417

Browse files
committed
chore: type organisation
1 parent 8d65b2f commit 8a4b417

4 files changed

Lines changed: 47 additions & 41 deletions

File tree

apps/site/types/download.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
1+
import type { SelectValue } from '@node-core/ui-components/Common/Select';
2+
3+
import type {
4+
IntlMessageKeys,
5+
NodeReleaseStatus,
6+
OperatingSystem,
7+
Platform,
8+
} from '#site/types';
9+
110
export interface DownloadSnippet {
211
name: string;
312
language: string;
413
content: string;
514
}
615

716
export type DownloadKind = 'installer' | 'binary' | 'source' | 'shasum';
17+
18+
type DownloadCompatibility = {
19+
os?: Array<OperatingSystem | 'LOADING'>;
20+
installMethod?: Array<string>;
21+
platform?: Array<Platform | ''>;
22+
semver?: Array<string>;
23+
releases?: Array<NodeReleaseStatus>;
24+
};
25+
26+
export type DownloadDropdownItem<T extends string> = {
27+
label: IntlMessageKeys;
28+
recommended?: boolean;
29+
url?: string;
30+
info?: IntlMessageKeys;
31+
compatibility: DownloadCompatibility;
32+
} & Omit<SelectValue<T>, 'label'>;
33+
34+
export type NodeDownloadArtifact = {
35+
file: string;
36+
kind: DownloadKind;
37+
os: OperatingSystem;
38+
architecture: string;
39+
url: string;
40+
version: string;
41+
};

apps/site/util/download/archive.tsx

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

3-
import type { DownloadKind, OperatingSystem, Platform } from '#site/types';
3+
import type {
4+
DownloadDropdownItem,
5+
DownloadKind,
6+
NodeDownloadArtifact,
7+
OperatingSystem,
8+
Platform,
9+
} from '#site/types';
410
import type { NodeRelease } from '#site/types/releases';
5-
import type { DownloadDropdownItem } from '#site/util/download';
611
import { OS_NOT_SUPPORTING_INSTALLERS, PLATFORMS } from '#site/util/download';
712
import { getNodeDownloadUrl } from '#site/util/url';
813

914
import { DIST_URL } from '#site/next.constants';
1015

11-
export type NodeDownloadArtifact = {
12-
file: string;
13-
kind: DownloadKind;
14-
os: OperatingSystem;
15-
architecture: string;
16-
url: string;
17-
version: string;
18-
};
19-
2016
/**
2117
* Checks if a download item is compatible with the given OS, platform, and version.
2218
*/

apps/site/util/download/index.tsx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { SelectValue } from '@node-core/ui-components/Common/Select';
21
import * as InstallMethodIcons from '@node-core/ui-components/Icons/InstallationMethod';
32
import * as OSIcons from '@node-core/ui-components/Icons/OperatingSystem';
43
import * as PackageManagerIcons from '@node-core/ui-components/Icons/PackageManager';
54
import type { ElementType } from 'react';
65
import satisfies from 'semver/functions/satisfies';
76

87
import type {
8+
DownloadDropdownItem,
99
IntlMessageKeys,
1010
NodeReleaseStatus,
1111
OperatingSystem,
@@ -27,23 +27,6 @@ export const OperatingSystemLabel = Object.fromEntries(
2727
Object.entries(systems).map(([key, data]) => [key, data.name])
2828
);
2929

30-
// Base types for dropdown functionality
31-
type DownloadCompatibility = {
32-
os?: Array<OperatingSystem | 'LOADING'>;
33-
installMethod?: Array<string>;
34-
platform?: Array<Platform | ''>;
35-
semver?: Array<string>;
36-
releases?: Array<NodeReleaseStatus>;
37-
};
38-
39-
export type DownloadDropdownItem<T extends string> = {
40-
label: IntlMessageKeys;
41-
recommended?: boolean;
42-
url?: string;
43-
info?: IntlMessageKeys;
44-
compatibility: DownloadCompatibility;
45-
} & Omit<SelectValue<T>, 'label'>;
46-
4730
/**
4831
* Gets the next valid item when current item is disabled/excluded
4932
*/

apps/site/util/url.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,18 @@ export const getNodeApiUrl = (version: string) => {
1818
};
1919

2020
type DownloadOptions = {
21+
/** The Node.js version string, must include the 'v' prefix (e.g., 'v20.12.2'). */
2122
version: string;
23+
/** The target operating system. Defaults to 'LOADING'. */
2224
os?: OperatingSystem | 'LOADING';
25+
/** The target platform/architecture (e.g., 'x64', 'arm64'). Defaults to 'x64'. */
2326
platform?: Platform;
27+
/** The type of download artifact. Can be 'installer', 'binary', 'source', or 'shasum'. Defaults to 'installer'. */
2428
kind?: DownloadKind;
2529
};
2630

2731
/**
28-
* Generates a Node.js download URL for the given options.
29-
*
30-
* @param options - The download options.
31-
* @param options.version - The Node.js version string, must include the 'v' prefix (e.g., 'v20.12.2').
32-
* @param options.os - The target operating system. Defaults to 'LOADING'.
33-
* @param options.platform - The target platform/architecture (e.g., 'x64', 'arm64'). Defaults to 'x64'.
34-
* @param options.kind - The type of download artifact. Can be 'installer', 'binary', 'source', or 'shasum'. Defaults to 'installer'.
35-
* @returns The fully qualified URL to the requested Node.js artifact.
36-
*
37-
* @example
38-
* getNodeDownloadUrl({ version: 'v20.12.2', os: 'MAC', platform: 'arm64', kind: 'binary' });
39-
* // => 'https://nodejs.org/dist/v20.12.2/node-v20.12.2-darwin-arm64.tar.gz'
32+
* Generates a Node.js download URL for the given options
4033
*/
4134
export const getNodeDownloadUrl = ({
4235
version,

0 commit comments

Comments
 (0)