get-node
Advanced tools
Comparing version 13.3.0 to 13.4.0
import{platform}from"process"; | ||
export const validateArch=function(arch){ | ||
if(arch in PLATFORMS){ | ||
return; | ||
} | ||
const availableArch=Object.keys(PLATFORMS).join(", "); | ||
throw new TypeError( | ||
`Option "arch" must not be ${arch} but one of: ${availableArch}`); | ||
}; | ||
export const getArch=function(arch){ | ||
@@ -12,9 +24,3 @@ /* c8 ignore start */ | ||
const archA=PLATFORMS[arch]; | ||
if(archA===undefined){ | ||
throw new Error(`Unsupported CPU architecture: ${arch}`); | ||
} | ||
return archA; | ||
return PLATFORMS[arch]; | ||
}; | ||
@@ -21,0 +27,0 @@ |
@@ -14,4 +14,3 @@ import{download}from"./download.js"; | ||
fetchOpts}= | ||
await getOpts({...opts,versionRange}); | ||
await getOpts(versionRange,opts); | ||
const version=await getVersion({ | ||
@@ -18,0 +17,0 @@ versionRange:versionRangeA, |
@@ -1,59 +0,45 @@ | ||
import{cwd as getCwd,arch}from"process"; | ||
import{arch as processArch}from"process"; | ||
import{excludeKeys}from"filter-obj"; | ||
import{validate,multipleValidOptions}from"jest-validate"; | ||
import semver from"semver"; | ||
import isPlainObj from"is-plain-obj"; | ||
import{addOutput}from"./output.js"; | ||
import{validateArch}from"./arch.js"; | ||
import{getDefaultOutput,validateOutput}from"./output.js"; | ||
import{DEFAULT_VERSION_RANGE,validateVersionRange}from"./version.js"; | ||
export const getOpts=async function(opts){ | ||
validate(opts,{exampleConfig:EXAMPLE_OPTS}); | ||
export const getOpts=async function( | ||
versionRange=DEFAULT_VERSION_RANGE, | ||
opts={}) | ||
{ | ||
validateVersionRange(versionRange); | ||
const optsA=excludeKeys(opts,isUndefined); | ||
const optsB={...DEFAULT_OPTS,...optsA}; | ||
if(!isPlainObj(opts)){ | ||
throw new TypeError(`Options must be a plain object: ${opts}`); | ||
} | ||
const optsC=await addOutput(optsB); | ||
const{ | ||
output=await getDefaultOutput(), | ||
arch=processArch, | ||
cwd, | ||
fetch:fetchOpt, | ||
mirror, | ||
progress=false}= | ||
opts; | ||
validateVersionRange(optsC); | ||
validateOutput(output); | ||
validateArch(arch); | ||
const{cwd,fetch:fetchOpt,mirror,progress,...optsD}=optsC; | ||
const preferredNodeOpts={cwd,fetch:fetchOpt,mirror}; | ||
const nodeVersionAliasOpts={fetch:fetchOpt,mirror}; | ||
const fetchOpts={mirror,progress}; | ||
return{...optsD,preferredNodeOpts,nodeVersionAliasOpts,fetchOpts}; | ||
}; | ||
return{ | ||
versionRange, | ||
output, | ||
arch, | ||
preferredNodeOpts, | ||
nodeVersionAliasOpts, | ||
fetchOpts}; | ||
const isUndefined=function(key,value){ | ||
return value===undefined; | ||
}; | ||
const DEFAULT_OPTS={ | ||
versionRange:"latest", | ||
progress:false, | ||
arch}; | ||
const EXAMPLE_OPTS={ | ||
...DEFAULT_OPTS, | ||
output:getCwd(), | ||
versionRange:"8", | ||
cwd:multipleValidOptions(getCwd(),new URL(".",import.meta.url)), | ||
fetch:true, | ||
mirror:"https://nodejs.org/dist"}; | ||
const validateVersionRange=function({versionRange}){ | ||
if(!ALIASES.has(versionRange)&&semver.validRange(versionRange)===null){ | ||
throw new TypeError(`Not a valid Node version range: ${versionRange}`); | ||
} | ||
}; | ||
const ALIASES=new Set(["latest","lts","global","local"]); | ||
//# sourceMappingURL=options.js.map |
import globalCacheDir from"global-cache-dir"; | ||
export const addOutput=async function(opts){ | ||
const output=await getOutput(opts); | ||
return{...opts,output}; | ||
export const getDefaultOutput=async function(){ | ||
return await globalCacheDir(CACHE_DIR); | ||
}; | ||
const getOutput=async function({output}){ | ||
if(output!==undefined){ | ||
return output; | ||
const CACHE_DIR="nve"; | ||
export const validateOutput=function(output){ | ||
if(typeof output!=="string"){ | ||
throw new TypeError(`Option "output" must be a string: ${output}`); | ||
} | ||
const outputA=await globalCacheDir(CACHE_DIR); | ||
return outputA; | ||
}; | ||
const CACHE_DIR="nve"; | ||
//# sourceMappingURL=output.js.map |
@@ -8,5 +8,23 @@ import{version as processVersion}from"process"; | ||
export const DEFAULT_VERSION_RANGE="latest"; | ||
export const validateVersionRange=function(versionRange){ | ||
if(typeof versionRange!=="string"){ | ||
throw new TypeError(`Node version range must be a string: ${versionRange}`); | ||
} | ||
if(!ALIASES.has(versionRange)&&semver.validRange(versionRange)===null){ | ||
throw new TypeError(`Not a valid Node version range: ${versionRange}`); | ||
} | ||
}; | ||
const ALIASES=new Set(["latest","lts","global","local"]); | ||
export const getVersion=async function({ | ||
@@ -13,0 +31,0 @@ versionRange, |
{ | ||
"name": "get-node", | ||
"version": "13.3.0", | ||
"version": "13.4.0", | ||
"type": "module", | ||
@@ -50,14 +50,13 @@ "exports": "./build/src/main.js", | ||
"execa": "^6.1.0", | ||
"fetch-node-website": "^7.1.0", | ||
"filter-obj": "^5.1.0", | ||
"fetch-node-website": "^7.2.0", | ||
"get-stream": "^6.0.0", | ||
"global-cache-dir": "^4.2.0", | ||
"jest-validate": "^29.0.1", | ||
"global-cache-dir": "^4.3.1", | ||
"is-plain-obj": "^4.1.0", | ||
"jszip": "^3.10.1", | ||
"mem": "^9.0.2", | ||
"move-file": "^3.0.0", | ||
"node-version-alias": "^3.2.0", | ||
"node-version-alias": "^3.3.0", | ||
"path-exists": "^5.0.0", | ||
"path-key": "^4.0.0", | ||
"preferred-node-version": "^3.2.0", | ||
"preferred-node-version": "^3.4.0", | ||
"semver": "^7.3.7", | ||
@@ -68,7 +67,7 @@ "tar-fs": "^2.1.1", | ||
"devDependencies": { | ||
"@ehmicky/dev-tasks": "^1.0.91", | ||
"@ehmicky/dev-tasks": "^1.0.94", | ||
"@types/node": "^17.0.31", | ||
"is-ci": "^3.0.1", | ||
"sinon": "^14.0.0", | ||
"test-each": "^5.4.0" | ||
"test-each": "^5.4.1" | ||
}, | ||
@@ -75,0 +74,0 @@ "engines": { |
43240
15
6628
709
0
+ Addedis-plain-obj@^4.1.0
- Removedfilter-obj@^5.1.0
- Removedjest-validate@^29.0.1
- Removed@jest/schemas@29.6.3(transitive)
- Removed@jest/types@29.6.3(transitive)
- Removed@sinclair/typebox@0.27.8(transitive)
- Removed@types/istanbul-lib-coverage@2.0.6(transitive)
- Removed@types/istanbul-lib-report@3.0.3(transitive)
- Removed@types/istanbul-reports@3.0.4(transitive)
- Removed@types/node@20.12.12(transitive)
- Removed@types/yargs@17.0.32(transitive)
- Removed@types/yargs-parser@21.0.3(transitive)
- Removedansi-styles@4.3.05.2.0(transitive)
- Removedcamelcase@6.3.0(transitive)
- Removedchalk@4.1.2(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedjest-get-type@29.6.3(transitive)
- Removedjest-validate@29.7.0(transitive)
- Removedleven@3.1.0(transitive)
- Removedpretty-format@29.7.0(transitive)
- Removedreact-is@18.3.1(transitive)
- Removedsupports-color@7.2.0(transitive)
- Removedundici-types@5.26.5(transitive)
Updatedfetch-node-website@^7.2.0
Updatedglobal-cache-dir@^4.3.1
Updatednode-version-alias@^3.3.0