Skip to content

Commit da204d4

Browse files
committed
refactor(download): extract constants to JSON and reorganize download utils
Moved constants.json and index.tsx into a dedicated subdirectory. Reorganized constants such as PLATFORMS into constants.json using object destructuring. Refactored INSTALL_METHODS to use object destructuring and removed explicit any types. Similarly for OS_NOT_SUPPORTING_INSTALLERS, OperatingSystems Fixes: nodejs#7561 Signed-off-by: vishal <vishalkumarvkvk988@gmail.com>
1 parent 60dcdd6 commit da204d4

11 files changed

+282
-210
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
nextItem,
1313
INSTALL_METHODS,
1414
parseCompat,
15-
} from '../../../downloadUtils/index';
15+
} from '../../../util/downloadUtils/index';
1616

1717
const InstallationMethodDropdown: FC = () => {
1818
const release = useContext(ReleaseContext);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
nextItem,
1414
OPERATING_SYSTEMS,
1515
parseCompat,
16-
} from '../../../downloadUtils/index';
16+
} from '../../../util/downloadUtils/index';
1717

1818
type OperatingSystemDropdownProps = { exclude?: Array<UserOS> };
1919

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
nextItem,
1313
PACKAGE_MANAGERS,
1414
parseCompat,
15-
} from '../../../downloadUtils/index';
15+
} from '../../../util/downloadUtils/index';
1616

1717
const PackageManagerDropdown: FC = () => {
1818
const release = useContext(ReleaseContext);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import { ReleaseContext } from '#site/providers/releaseProvider';
1010
import type { UserPlatform } from '#site/types/userOS';
1111
import { getUserPlatform } from '#site/util/getUserPlatform';
1212

13-
import { PLATFORMS, nextItem, parseCompat } from '../../../downloadUtils/index';
13+
import {
14+
PLATFORMS,
15+
nextItem,
16+
parseCompat,
17+
} from '../../../util/downloadUtils/index';
1418

1519
const PlatformDropdown: FC = () => {
1620
const { architecture, bitness } = useClientContext();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getNodeDownloadUrl } from '#site/util/getNodeDownloadUrl';
1313
import {
1414
OS_NOT_SUPPORTING_INSTALLERS,
1515
OperatingSystemLabel,
16-
} from '../../../downloadUtils/index';
16+
} from '../../../util/downloadUtils/index';
1717
// Retrieves the pure extension piece from the input string
1818
const getExtension = (input: string) => String(input.split('.').slice(-1));
1919

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import {
1515
ReleasesContext,
1616
} from '#site/providers/releaseProvider';
1717
import type { ReleaseContextType } from '#site/types/release';
18+
import { INSTALL_METHODS } from '#site/util/downloadUtils/index';
1819
import { highlightToHtml } from '#site/util/getHighlighter';
1920

20-
import { INSTALL_METHODS } from '../../../downloadUtils/index';
21-
2221
// Creates a minimal JavaScript interpreter for parsing the JavaScript code from the snippets
2322
// Note: that the code runs inside a sandboxed environment and cannot interact with any code outside of the sandbox
2423
// It also does not have access to any Global or Window objects, nor it can execute code on the end-user's browser

apps/site/downloadUtils/constants.json

Lines changed: 0 additions & 38 deletions
This file was deleted.

apps/site/tsconfig.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@
1515
"jsx": "preserve",
1616
"incremental": true,
1717
"plugins": [{ "name": "next" }],
18-
"baseUrl": "."
18+
"baseUrl": ".",
19+
"paths": {
20+
"#site/*": ["apps/site/*"]
21+
}
1922
},
2023
"include": [
2124
"next-env.d.ts",
2225
"global.d.ts",
2326
"**/*.mdx",
2427
"**/*.ts",
2528
"**/*.tsx",
26-
".next/types/**/*.ts"
29+
".next/types/**/*.ts",
30+
"util/downloadUtils/index.tsx"
2731
],
2832
"exclude": ["node_modules", ".next"]
2933
}

apps/site/types/userOS.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { OperatingSystemLabel } from '../downloadUtils/constants.json';
2-
import type downloadConstants from '../downloadUtils/constants.json';
1+
import type { OperatingSystemLabel } from '../util/downloadUtils/constants.json';
2+
import type downloadConstants from '../util/downloadUtils/constants.json';
33

44
// This infers the keys from OperatingSystemLabel as the UserOS type.
55
export type UserOS = keyof typeof OperatingSystemLabel;
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
{
2+
"OperatingSystemLabel": {
3+
"WIN": "Windows",
4+
"MAC": "macOS",
5+
"LINUX": "Linux",
6+
"AIX": "AIX",
7+
"OTHER": "Other",
8+
"LOADING": "N/A"
9+
},
10+
"OS_NOT_SUPPORTING_INSTALLERS": ["LINUX", "AIX", "OTHER", "LOADING"],
11+
12+
"OperatingSystems": [
13+
{
14+
"value": "WIN",
15+
"label": "Windows",
16+
"compatibility": {}
17+
},
18+
{
19+
"value": "MAC",
20+
"label": "macOS",
21+
"compatibility": {}
22+
},
23+
{
24+
"value": "LINUX",
25+
"label": "Linux",
26+
"compatibility": {}
27+
},
28+
{
29+
"value": "AIX",
30+
"label": "AIX",
31+
"compatibility": {
32+
"installMethod": [""],
33+
"semver": [">= 6.7.0"]
34+
}
35+
}
36+
],
37+
"InstallationMethodLabel": {
38+
"NVM": "nvm",
39+
"FNM": "fnm",
40+
"BREW": "Brew",
41+
"CHOCO": "Chocolatey",
42+
"DEVBOX": "Devbox",
43+
"DOCKER": "Docker",
44+
"N": "n",
45+
"VOLTA": "Volta"
46+
},
47+
"installMethods": [
48+
{
49+
"key": "NVM",
50+
"label": "NVM",
51+
"value": "NVM",
52+
"compatibility": { "os": ["MAC", "LINUX", "OTHER"] },
53+
"recommended": true,
54+
"url": "https://github.com/nvm-sh/nvm",
55+
"info": "layouts.download.codeBox.platformInfo.nvm"
56+
},
57+
{
58+
"key": "FNM",
59+
"label": "FNM",
60+
"value": "FNM",
61+
"compatibility": { "os": ["MAC", "LINUX", "WIN"] },
62+
"recommended": true,
63+
"url": "https://github.com/Schniz/fnm",
64+
"info": "layouts.download.codeBox.platformInfo.fnm"
65+
},
66+
{
67+
"key": "BREW",
68+
"label": "BREW",
69+
"value": "BREW",
70+
"compatibility": {
71+
"os": ["MAC", "LINUX"],
72+
"releases": ["Current", "LTS"]
73+
},
74+
"url": "https://brew.sh/",
75+
"info": "layouts.download.codeBox.platformInfo.brew"
76+
},
77+
{
78+
"key": "DEVBOX",
79+
"label": "DEVBOX",
80+
"value": "DEVBOX",
81+
"compatibility": { "os": ["MAC", "LINUX"] },
82+
"url": "https://jetify.com/devbox/",
83+
"info": "layouts.download.codeBox.platformInfo.devbox"
84+
},
85+
{
86+
"key": "CHOCO",
87+
"label": "CHOCO",
88+
"value": "CHOCO",
89+
"compatibility": { "os": ["WIN"] },
90+
"url": "https://chocolatey.org/",
91+
"info": "layouts.download.codeBox.platformInfo.choco"
92+
},
93+
{
94+
"key": "DOCKER",
95+
"label": "DOCKER",
96+
"value": "DOCKER",
97+
"compatibility": { "os": ["WIN", "MAC", "LINUX"] },
98+
"recommended": true,
99+
"url": "https://docs.docker.com/get-started/get-docker/",
100+
"info": "layouts.download.codeBox.platformInfo.docker"
101+
},
102+
{
103+
"key": "N",
104+
"label": "N",
105+
"value": "N",
106+
"compatibility": { "os": ["MAC", "LINUX"] },
107+
"url": "https://github.com/tj/n",
108+
"info": "layouts.download.codeBox.platformInfo.n"
109+
},
110+
{
111+
"key": "VOLTA",
112+
"label": "VOLTA",
113+
"value": "VOLTA",
114+
"compatibility": { "os": ["WIN", "MAC", "LINUX"] },
115+
"url": "https://docs.volta.sh/guide/getting-started",
116+
"info": "layouts.download.codeBox.platformInfo.volta"
117+
}
118+
],
119+
"Platforms": {
120+
"WIN": [
121+
{
122+
"label": "x64",
123+
"value": "x64",
124+
"compatibility": {}
125+
},
126+
{
127+
"label": "x86",
128+
"value": "x86",
129+
"compatibility": { "semver": ["< 23.0.0"] }
130+
},
131+
{
132+
"label": "ARM64",
133+
"value": "arm64",
134+
"compatibility": { "semver": [">= 19.9.0"] }
135+
}
136+
],
137+
"MAC": [
138+
{
139+
"label": "x64",
140+
"value": "x64",
141+
"compatibility": {}
142+
},
143+
{
144+
"label": "ARM64",
145+
"value": "arm64",
146+
"compatibility": { "semver": [">= 19.9.0"] }
147+
}
148+
],
149+
"LINUX": [
150+
{
151+
"label": "x64",
152+
"value": "x64",
153+
"compatibility": {}
154+
},
155+
{
156+
"label": "ARMv7",
157+
"value": "armv7l",
158+
"compatibility": { "semver": [">= 4.0.0"] }
159+
},
160+
{
161+
"label": "ARM64",
162+
"value": "arm64",
163+
"compatibility": { "semver": [">= 4.0.0"] }
164+
},
165+
{
166+
"label": "Power LE",
167+
"value": "ppc64le",
168+
"compatibility": { "semver": [">= 4.4.0"] }
169+
},
170+
{
171+
"label": "System Z",
172+
"value": "s390x",
173+
"compatibility": { "semver": [">= 6.6.0"] }
174+
}
175+
],
176+
"AIX": [
177+
{
178+
"label": "Power",
179+
"value": "ppc64",
180+
"compatibility": { "semver": [">= 6.7.0"] }
181+
}
182+
],
183+
"OTHER": [],
184+
"LOADING": []
185+
},
186+
"PackageManagerLabel": {
187+
"NPM": "npm",
188+
"YARN": "Yarn",
189+
"PNPM": "pnpm"
190+
},
191+
"UserPlatform": [
192+
"arm64",
193+
"armv7l",
194+
"ppc64le",
195+
"ppc64",
196+
"s390x",
197+
"ppc64",
198+
"x64",
199+
"x86"
200+
],
201+
"UserBitness": ["64", "32"],
202+
"UserArchitecture": ["arm", "x86"]
203+
}

0 commit comments

Comments
 (0)