Skip to content

Commit 2759b68

Browse files
committed
chore: review updates
1 parent 1e6e0f4 commit 2759b68

File tree

5 files changed

+25
-31
lines changed

5 files changed

+25
-31
lines changed

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +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 { chunk } from '#site/util/arrayUtils';
1011
import { getNodeApiLink } from '#site/util/getNodeApiLink';
1112

1213
import styles from './index.module.css';
@@ -15,21 +16,14 @@ type MinorReleasesTableProps = {
1516
releases: Array<MinorVersion>;
1617
};
1718

18-
const chunkedReleases = (releases: Array<MinorVersion>, size: number) => {
19-
const count = Math.ceil(releases.length / size);
20-
21-
return Array.from({ length: count }, (_, index) =>
22-
releases.slice(index * size, (index + 1) * size)
23-
);
24-
};
25-
2619
export const MinorReleasesTable: FC<MinorReleasesTableProps> = ({
2720
releases,
2821
}) => {
2922
const t = useTranslations('components.minorReleasesTable');
23+
3024
// Chunk minor releases into groups of 8 for scrollable display.
3125
// This is to ensure that the table does not become too wide and remains user-friendly
32-
const releaseGroups = chunkedReleases(releases, 8);
26+
const releaseGroups = chunk(releases, 8);
3327

3428
return (
3529
<div className={styles.scrollable}>

apps/site/components/withDownloadArchive.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const WithDownloadArchive: FC<WithDownloadArchiveProps> = async ({
2222
children: Component,
2323
}) => {
2424
const { pathname } = getClientContext();
25-
const releaseData = await getReleaseData();
2625

2726
// Extract version from pathname
2827
const version = extractVersionFromPath(pathname);
@@ -32,6 +31,7 @@ const WithDownloadArchive: FC<WithDownloadArchiveProps> = async ({
3231
}
3332

3433
// Find the release data for the given version
34+
const releaseData = await getReleaseData();
3535
const release = findReleaseByVersion(releaseData, version);
3636

3737
if (!release) {

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,36 @@ const version = 'v18.16.0';
88
describe('getNodeDownloadUrl', () => {
99
it('should return the correct download URL for Mac', () => {
1010
const os = 'MAC';
11-
const bitness = 86;
11+
const platform = 86;
1212
const expectedUrl = 'https://nodejs.org/dist/v18.16.0/node-v18.16.0.pkg';
1313

14-
assert.equal(
15-
getNodeDownloadUrl({ version: version, os: os, platform: bitness }),
16-
expectedUrl
17-
);
14+
assert.equal(getNodeDownloadUrl({ version, os, platform }), expectedUrl);
1815
});
1916

2017
it('should return the correct download URL for Windows (32-bit)', () => {
2118
const os = 'WIN';
22-
const bitness = 86;
19+
const platform = 86;
2320
const expectedUrl =
2421
'https://nodejs.org/dist/v18.16.0/node-v18.16.0-x86.msi';
2522

26-
assert.equal(
27-
getNodeDownloadUrl({ version: version, os: os, platform: bitness }),
28-
expectedUrl
29-
);
23+
assert.equal(getNodeDownloadUrl({ version, os, platform }), expectedUrl);
3024
});
3125

3226
it('should return the correct download URL for Windows (64-bit)', () => {
3327
const os = 'WIN';
34-
const bitness = 64;
28+
const platform = 64;
3529
const expectedUrl =
3630
'https://nodejs.org/dist/v18.16.0/node-v18.16.0-x64.msi';
3731

38-
assert.equal(
39-
getNodeDownloadUrl({ version: version, os: os, platform: bitness }),
40-
expectedUrl
41-
);
32+
assert.equal(getNodeDownloadUrl({ version, os, platform }), expectedUrl);
4233
});
4334

4435
it('should return the default download URL for other operating systems', () => {
4536
const os = 'OTHER';
46-
const bitness = 86;
37+
const platform = 86;
4738
const expectedUrl = 'https://nodejs.org/dist/v18.16.0/node-v18.16.0.tar.gz';
4839

49-
assert.equal(
50-
getNodeDownloadUrl({ version: version, os: os, platform: bitness }),
51-
expectedUrl
52-
);
40+
assert.equal(getNodeDownloadUrl({ version, os, platform }), expectedUrl);
5341
});
5442

5543
describe('MAC', () => {

apps/site/util/arrayUtils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Splits an array into smaller chunks of a specified size.
3+
*/
4+
export const chunk = <T>(array: Array<T>, size: number): Array<Array<T>> => {
5+
// Number of chunks needed
6+
const count = Math.ceil(array.length / size);
7+
8+
// Create an array of chunks by slicing the original array
9+
return Array.from({ length: count }, (_, index) =>
10+
array.slice(index * size, (index + 1) * size)
11+
);
12+
};

apps/site/util/downloadUtils/archive.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export const extractVersionFromPath = (pathname: string | undefined) => {
141141
const version = segments.pop();
142142

143143
// Check version format like (v22.0.4 or 'archive')
144-
if (!version || (!version.match(/^v\d+(\.\d+)*$/) && version !== 'archive')) {
144+
if (!version || !version.match(/^v\d+(\.\d+)*|archive$/)) {
145145
return null;
146146
}
147147

0 commit comments

Comments
 (0)