UNPKG

get-node

Version:

Download a specific version of Node.js

61 lines (43 loc) 1.2 kB
import{platform}from"node:process"; import{downloadGz}from"./gz.js"; import{shouldUse7z,download7z}from"./p7z.js"; import{downloadRaw}from"./raw.js"; import{shouldUseXz,downloadXz}from"./xz.js"; import{shouldUseZip,downloadZip}from"./zip.js"; export const downloadRuntime=({version,tmpFile,arch,fetchOpts})=>{ if(platform==="win32"){ return downloadWindowsNode({version,tmpFile,arch,fetchOpts}) } if(SUPPORTED_UNIX.has(platform)){ return downloadUnixNode({version,tmpFile,arch,fetchOpts}) } /* c8 ignore start */ throw new Error(`Unsupported platform: ${platform}`); /* c8 ignore stop */ }; const SUPPORTED_UNIX=new Set(["linux","darwin","aix","sunos"]); export const downloadWindowsNode=async({ version, tmpFile, arch, fetchOpts })=>{ if(await shouldUse7z(version)){ return download7z({version,tmpFile,arch,fetchOpts}) } if(shouldUseZip(version)){ return downloadZip({version,tmpFile,arch,fetchOpts}) } return downloadRaw({version,tmpFile,arch,fetchOpts}) }; export const downloadUnixNode=async({ version, tmpFile, arch, fetchOpts })=>{ if(await shouldUseXz(version)){ return downloadXz({version,tmpFile,arch,fetchOpts}) } return downloadGz({version,tmpFile,arch,fetchOpts}) };