get-node
Version:
Download a specific version of Node.js
39 lines (26 loc) • 723 B
JavaScript
import{pipeline}from"node:stream/promises";
import semver from"semver";
import{fetchNodeUrl,promiseOrFetchError,writeNodeBinary}from"../fetch.js";
export const downloadRaw=async({version,tmpFile,arch,fetchOpts})=>{
const filepath=getFilepath(version,arch);
const{response,checksumError}=await fetchNodeUrl(
version,
filepath,
fetchOpts
);
const promise=pipeline(response,writeNodeBinary(tmpFile));
await promiseOrFetchError(promise,response);
return checksumError
};
const getFilepath=(version,arch)=>{
if(semver.gte(version,NEW_URL_VERSION)){
return`win-${arch}/node.exe`
}
/* c8 ignore start */
if(arch==="x64"){
return"x64/node.exe"
}
return"node.exe";
/* c8 ignore stop */
};
const NEW_URL_VERSION="4.0.0";