Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update getNodeDownloadUrl.ts #7242

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 38 additions & 57 deletions apps/site/util/getNodeDownloadUrl.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the comparison, I think the switch statement is much cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any good paths I could take into making this better than the switch cases ? (;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with the switch statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah true ig.
Thx anyway for review

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem! Feel free to look at the issues tab for things that need to be fixed. "Help wanted" and "good first issue" are places to start.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the comparison, I think the switch statement is much cleaner.

Same feeling

Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,45 @@ export const getNodeDownloadUrl = (
const baseURL = `${DIST_URL}${versionWithPrefix}`;

if (kind === 'source') {
// Prepares a downloadable Node.js source code link
return `${baseURL}/node-${versionWithPrefix}.tar.gz`;
}

switch (os) {
case 'MAC':
// Prepares a downloadable Node.js installer link for the x64, ARM64 platforms
if (kind === 'installer') {
return `${baseURL}/node-${versionWithPrefix}.pkg`;
}

// Prepares a downloadable Node.js link for the ARM64 platform
if (typeof bitness === 'string') {
return `${baseURL}/node-${versionWithPrefix}-darwin-${bitness}.tar.gz`;
}

// Prepares a downloadable Node.js link for the x64 platform.
// Since the x86 platform is not officially supported, returns the x64
// link as the default value.
return `${baseURL}/node-${versionWithPrefix}-darwin-x64.tar.gz`;
case 'WIN': {
if (kind === 'installer') {
// Prepares a downloadable Node.js installer link for the ARM platforms
if (typeof bitness === 'string') {
return `${baseURL}/node-${versionWithPrefix}-${bitness}.msi`;
}

// Prepares a downloadable Node.js installer link for the x64 and x86 platforms
return `${baseURL}/node-${versionWithPrefix}-x${bitness}.msi`;
}

// Prepares a downloadable Node.js link for the ARM64 platform
if (typeof bitness === 'string') {
return `${baseURL}/node-${versionWithPrefix}-win-${bitness}.zip`;
}

// Prepares a downloadable Node.js link for the x64 and x86 platforms
return `${baseURL}/node-${versionWithPrefix}-win-x${bitness}.zip`;
}
case 'LINUX':
// Prepares a downloadable Node.js link for the ARM platforms such as
// ARMv7 and ARMv8
if (typeof bitness === 'string') {
return `${baseURL}/node-${versionWithPrefix}-linux-${bitness}.tar.xz`;
}

// Prepares a downloadable Node.js link for the x64 platform.
// Since the x86 platform is not officially supported, returns the x64
// link as the default value.
return `${baseURL}/node-${versionWithPrefix}-linux-x64.tar.xz`;
case 'AIX':
// Prepares a downloadable Node.js link for AIX
if (typeof bitness === 'string') {
return `${baseURL}/node-${versionWithPrefix}-aix-${bitness}.tar.gz`;
}

return `${baseURL}/node-${versionWithPrefix}-aix-ppc64.tar.gz`;
default:
// Prepares a downloadable Node.js source code link
return `${baseURL}/node-${versionWithPrefix}.tar.gz`;
}
// Map of OS-specific logic for generating download URLs
const osUrlMap: Record<UserOS, (bitness: string | number, kind: string) => string> = {
MAC: (bitness, kind) =>
kind === 'installer'
? // Prepares a downloadable Node.js installer link for the macOS platform
`${baseURL}/node-${versionWithPrefix}.pkg`
: // Prepares a downloadable Node.js link for the macOS platform (ARM64 or x64)
// Since ARM and x64 are supported, returns the platform-specific binary link
`${baseURL}/node-${versionWithPrefix}-darwin-${typeof bitness === 'string' ? bitness : 'x64'}.tar.gz`,

WIN: (bitness, kind) =>
kind === 'installer'
? // Prepares a downloadable Node.js installer link for the Windows platform
// Supports both ARM and x86/x64 architecture, choosing based on bitness
`${baseURL}/node-${versionWithPrefix}-${typeof bitness === 'string' ? bitness : `x${bitness}`}.msi`
: // Prepares a downloadable Node.js link for Windows platform (ARM64 or x86/x64)
// Returns the zip format for both ARM and x86/x64 platforms
`${baseURL}/node-${versionWithPrefix}-win-${typeof bitness === 'string' ? bitness : `x${bitness}`}.zip`,

LINUX: (bitness) =>
// Prepares a downloadable Node.js link for the Linux platform
// Supports ARM platforms (ARMv7/ARMv8) and x64 platforms.
// Returns ARM or x64 based on the bitness provided.
`${baseURL}/node-${versionWithPrefix}-linux-${typeof bitness === 'string' ? bitness : 'x64'}.tar.xz`,

AIX: (bitness) =>
// Prepares a downloadable Node.js link for the AIX platform
// Supports the PPC64 architecture. Returns the appropriate binary based on bitness.
`${baseURL}/node-${versionWithPrefix}-aix-${typeof bitness === 'string' ? bitness : 'ppc64'}.tar.gz`,

OTHER: () =>
// Prepares a downloadable Node.js source code link as a fallback for unsupported OS
`${baseURL}/node-${versionWithPrefix}.tar.gz`,
};

// Return the URL based on the detected OS
return osUrlMap[os]?.(bitness, kind) || osUrlMap.OTHER();
};