Skip to content

Commit a2319fe

Browse files
committed
fixup! code review
1 parent 6f15245 commit a2319fe

File tree

11 files changed

+200
-202
lines changed

11 files changed

+200
-202
lines changed

apps/site/app/[locale]/next-data/og/[category]/[title]/route.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ type StaticParams = {
2626
export const GET = async (_: Request, props: StaticParams) => {
2727
const params = await props.params;
2828

29-
const categoryColor =
29+
const categoryColour =
3030
params.category in CATEGORY_TO_THEME_COLOUR_MAP
3131
? CATEGORY_TO_THEME_COLOUR_MAP[params.category]
3232
: CATEGORY_TO_THEME_COLOUR_MAP[DEFAULT_CATEGORY_OG_TYPE];
3333

34-
const gridBackground = `radial-gradient(circle, ${categoryColor}, transparent)`;
34+
const gridBackground = `radial-gradient(circle, ${categoryColour}, transparent)`;
3535

3636
return new ImageResponse(
3737
(

apps/site/components/Downloads/DownloadButton/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { FC, PropsWithChildren } from 'react';
77
import Button from '#site/components/Common/Button';
88
import { useClientContext } from '#site/hooks';
99
import type { NodeRelease } from '#site/types';
10-
import { getNodeDownloadUrl } from '#site/util/download';
10+
import { getNodeDownloadUrl } from '#site/util/url';
1111
import { getUserPlatform } from '#site/util/userAgent';
1212

1313
import styles from './index.module.css';

apps/site/components/Downloads/DownloadLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { FC, PropsWithChildren } from 'react';
55
import LinkWithArrow from '#site/components/LinkWithArrow';
66
import { useClientContext } from '#site/hooks';
77
import type { DownloadKind, NodeRelease } from '#site/types';
8-
import { getNodeDownloadUrl } from '#site/util/download';
8+
import { getNodeDownloadUrl } from '#site/util/url';
99
import { getUserPlatform } from '#site/util/userAgent';
1010

1111
type DownloadLinkProps = { release: NodeRelease; kind?: DownloadKind };

apps/site/components/Downloads/MinorReleasesTable/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { FC } from 'react';
77
import Link from '#site/components/Link';
88
import { BASE_CHANGELOG_URL } from '#site/next.constants.mjs';
99
import type { MinorVersion } from '#site/types';
10-
import { getNodeApiLink } from '#site/util/api';
10+
import { getNodeApiUrl } from '#site/util/url';
1111

1212
import styles from './index.module.css';
1313

@@ -50,7 +50,7 @@ export const MinorReleasesTable: FC<MinorReleasesTableProps> = ({
5050
<Separator orientation="vertical" />
5151
<Link
5252
kind="neutral"
53-
href={getNodeApiLink(`v${release.version}`)}
53+
href={getNodeApiUrl(`v${release.version}`)}
5454
>
5555
{t('actions.docs')}
5656
</Link>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { ReleaseContext } from '#site/providers/releaseProvider';
1111
import {
1212
OS_NOT_SUPPORTING_INSTALLERS,
1313
OperatingSystemLabel,
14-
getNodeDownloadUrl,
1514
} from '#site/util/download';
15+
import { getNodeDownloadUrl } from '#site/util/url';
1616

1717
// Retrieves the pure extension piece from the input string
1818
const getExtension = (input: string) => String(input.split('.').slice(-1));

apps/site/util/__tests__/api.test.mjs

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

apps/site/util/__tests__/download.test.mjs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ import {
88
INSTALL_METHODS,
99
PACKAGE_MANAGERS,
1010
PLATFORMS,
11-
getNodeDownloadUrl,
1211
} from '#site/util/download';
1312

14-
const version = 'v18.16.0';
15-
1613
describe('parseCompat', () => {
1714
it('should handle all OS, install methods, and package managers', () => {
1815
OPERATING_SYSTEMS.forEach(os => {
@@ -147,53 +144,3 @@ describe('nextItem', () => {
147144
assert.equal(nextItem('valid', items), 'valid');
148145
});
149146
});
150-
151-
describe('getNodeDownloadUrl', () => {
152-
it('should return the correct download URL for Mac', () => {
153-
const os = 'MAC';
154-
const bitness = 86;
155-
const expectedUrl = 'https://nodejs.org/dist/v18.16.0/node-v18.16.0.pkg';
156-
157-
assert.equal(getNodeDownloadUrl(version, os, bitness), expectedUrl);
158-
});
159-
160-
it('should return the correct download URL for Windows (32-bit)', () => {
161-
const os = 'WIN';
162-
const bitness = 86;
163-
const expectedUrl =
164-
'https://nodejs.org/dist/v18.16.0/node-v18.16.0-x86.msi';
165-
166-
assert.equal(getNodeDownloadUrl(version, os, bitness), expectedUrl);
167-
});
168-
169-
it('should return the correct download URL for Windows (64-bit)', () => {
170-
const os = 'WIN';
171-
const bitness = 64;
172-
const expectedUrl =
173-
'https://nodejs.org/dist/v18.16.0/node-v18.16.0-x64.msi';
174-
175-
assert.equal(getNodeDownloadUrl(version, os, bitness), expectedUrl);
176-
});
177-
178-
it('should return the default download URL for other operating systems', () => {
179-
const os = 'OTHER';
180-
const bitness = 86;
181-
const expectedUrl = 'https://nodejs.org/dist/v18.16.0/node-v18.16.0.tar.gz';
182-
183-
assert.equal(getNodeDownloadUrl(version, os, bitness), expectedUrl);
184-
});
185-
186-
describe('MAC', () => {
187-
it('should return .pkg link for installer', () => {
188-
const url = getNodeDownloadUrl('v18.0.0', 'MAC', 'x64', 'installer');
189-
assert.ok(url.includes('.pkg'));
190-
});
191-
});
192-
193-
describe('WIN', () => {
194-
it('should return an MSI link for installer', () => {
195-
const url = getNodeDownloadUrl('v18.0.0', 'WIN', 'x64', 'installer');
196-
assert.ok(url.includes('.msi'));
197-
});
198-
});
199-
});
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import assert from 'node:assert/strict';
2+
import { describe, it } from 'node:test';
3+
4+
import { getNodeDownloadUrl, getNodeApiUrl } from '../url';
5+
6+
const version = 'v18.16.0';
7+
8+
describe('getNodeApiUrl', () => {
9+
it('should return the correct API link for versions >=0.3.1 and <0.5.1', () => {
10+
const version = '0.4.0';
11+
const expectedLink = `https://nodejs.org/docs/${version}/api/`;
12+
13+
const result = getNodeApiUrl(version);
14+
15+
assert.equal(result, expectedLink);
16+
});
17+
18+
it('should return the correct URL for versions >=0.3.1 and <0.5.1', () => {
19+
const url = getNodeApiUrl('v0.4.10');
20+
assert.ok(url.includes('/api/'));
21+
});
22+
23+
it('should return the correct API link for versions >=0.1.14 and <0.3.1', () => {
24+
const version = '0.2.0';
25+
const expectedLink = `https://nodejs.org/docs/${version}/api.html`;
26+
27+
const result = getNodeApiUrl(version);
28+
29+
assert.equal(result, expectedLink);
30+
});
31+
32+
it('should return the correct API link for versions >=1.0.0 and <4.0.0', () => {
33+
const version = '2.3.0';
34+
const expectedLink = `https://iojs.org/dist/${version}/docs/api/`;
35+
36+
const result = getNodeApiUrl(version);
37+
38+
assert.equal(result, expectedLink);
39+
});
40+
41+
it('should form the correct URL for versions >=1.0.0 and <4.0.0', () => {
42+
const url = getNodeApiUrl('v1.2.3');
43+
assert.ok(url.includes('iojs.org/dist/v1.2.3/docs/api/'));
44+
});
45+
46+
it('should return the correct API link for other versions', () => {
47+
const version = '5.0.0';
48+
const expectedLink = `https://nodejs.org/dist/${version}/docs/api/`;
49+
50+
const result = getNodeApiUrl(version);
51+
52+
assert.equal(result, expectedLink);
53+
});
54+
});
55+
56+
describe('getNodeDownloadUrl', () => {
57+
it('should return the correct download URL for Mac', () => {
58+
const os = 'MAC';
59+
const bitness = 86;
60+
const expectedUrl = 'https://nodejs.org/dist/v18.16.0/node-v18.16.0.pkg';
61+
62+
assert.equal(getNodeDownloadUrl(version, os, bitness), expectedUrl);
63+
});
64+
65+
it('should return the correct download URL for Windows (32-bit)', () => {
66+
const os = 'WIN';
67+
const bitness = 86;
68+
const expectedUrl =
69+
'https://nodejs.org/dist/v18.16.0/node-v18.16.0-x86.msi';
70+
71+
assert.equal(getNodeDownloadUrl(version, os, bitness), expectedUrl);
72+
});
73+
74+
it('should return the correct download URL for Windows (64-bit)', () => {
75+
const os = 'WIN';
76+
const bitness = 64;
77+
const expectedUrl =
78+
'https://nodejs.org/dist/v18.16.0/node-v18.16.0-x64.msi';
79+
80+
assert.equal(getNodeDownloadUrl(version, os, bitness), expectedUrl);
81+
});
82+
83+
it('should return the default download URL for other operating systems', () => {
84+
const os = 'OTHER';
85+
const bitness = 86;
86+
const expectedUrl = 'https://nodejs.org/dist/v18.16.0/node-v18.16.0.tar.gz';
87+
88+
assert.equal(getNodeDownloadUrl(version, os, bitness), expectedUrl);
89+
});
90+
91+
describe('MAC', () => {
92+
it('should return .pkg link for installer', () => {
93+
const url = getNodeDownloadUrl('v18.0.0', 'MAC', 'x64', 'installer');
94+
assert.ok(url.includes('.pkg'));
95+
});
96+
});
97+
98+
describe('WIN', () => {
99+
it('should return an MSI link for installer', () => {
100+
const url = getNodeDownloadUrl('v18.0.0', 'WIN', 'x64', 'installer');
101+
assert.ok(url.includes('.msi'));
102+
});
103+
});
104+
});

apps/site/util/api.ts

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

apps/site/util/download/index.tsx

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import * as PackageManagerIcons from '@node-core/ui-components/Icons/PackageMana
55
import type { ElementType } from 'react';
66
import satisfies from 'semver/functions/satisfies';
77

8-
import { DIST_URL } from '#site/next.constants.mjs';
98
import type {
109
IntlMessageKeys,
1110
NodeReleaseStatus,
1211
UserOS,
1312
UserPlatform,
14-
DownloadKind,
1513
} from '#site/types';
1614
import type * as Types from '#site/types/release';
1715

@@ -155,74 +153,3 @@ export const PLATFORMS = Object.fromEntries(
155153
})),
156154
])
157155
) as Record<UserOS | 'LOADING', Array<DownloadDropdownItem<UserPlatform>>>;
158-
159-
export const getNodeDownloadUrl = (
160-
versionWithPrefix: string,
161-
os: UserOS | 'LOADING',
162-
platform: UserPlatform = 'x64',
163-
kind: DownloadKind = 'installer'
164-
) => {
165-
const baseURL = `${DIST_URL}${versionWithPrefix}`;
166-
167-
if (kind === 'source') {
168-
return `${baseURL}/node-${versionWithPrefix}.tar.gz`;
169-
}
170-
171-
switch (os) {
172-
case 'MAC':
173-
// Prepares a downloadable Node.js installer link for the x64, ARM64 platforms
174-
if (kind === 'installer') {
175-
return `${baseURL}/node-${versionWithPrefix}.pkg`;
176-
}
177-
178-
// Prepares a downloadable Node.js link for the ARM64 platform
179-
if (typeof platform === 'string') {
180-
return `${baseURL}/node-${versionWithPrefix}-darwin-${platform}.tar.gz`;
181-
}
182-
183-
// Prepares a downloadable Node.js link for the x64 platform.
184-
// Since the x86 platform is not officially supported, returns the x64
185-
// link as the default value.
186-
return `${baseURL}/node-${versionWithPrefix}-darwin-x64.tar.gz`;
187-
case 'WIN': {
188-
if (kind === 'installer') {
189-
// Prepares a downloadable Node.js installer link for the ARM platforms
190-
if (typeof platform === 'string') {
191-
return `${baseURL}/node-${versionWithPrefix}-${platform}.msi`;
192-
}
193-
194-
// Prepares a downloadable Node.js installer link for the x64 and x86 platforms
195-
return `${baseURL}/node-${versionWithPrefix}-x${platform}.msi`;
196-
}
197-
198-
// Prepares a downloadable Node.js link for the ARM64 platform
199-
if (typeof platform === 'string') {
200-
return `${baseURL}/node-${versionWithPrefix}-win-${platform}.zip`;
201-
}
202-
203-
// Prepares a downloadable Node.js link for the x64 and x86 platforms
204-
return `${baseURL}/node-${versionWithPrefix}-win-x${platform}.zip`;
205-
}
206-
case 'LINUX':
207-
// Prepares a downloadable Node.js link for the ARM platforms such as
208-
// ARMv7 and ARMv8
209-
if (typeof platform === 'string') {
210-
return `${baseURL}/node-${versionWithPrefix}-linux-${platform}.tar.xz`;
211-
}
212-
213-
// Prepares a downloadable Node.js link for the x64 platform.
214-
// Since the x86 platform is not officially supported, returns the x64
215-
// link as the default value.
216-
return `${baseURL}/node-${versionWithPrefix}-linux-x64.tar.xz`;
217-
case 'AIX':
218-
// Prepares a downloadable Node.js link for AIX
219-
if (typeof platform === 'string') {
220-
return `${baseURL}/node-${versionWithPrefix}-aix-${platform}.tar.gz`;
221-
}
222-
223-
return `${baseURL}/node-${versionWithPrefix}-aix-ppc64.tar.gz`;
224-
default:
225-
// Prepares a downloadable Node.js source code link
226-
return `${baseURL}/node-${versionWithPrefix}.tar.gz`;
227-
}
228-
};

0 commit comments

Comments
 (0)