Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

preferred-node-version

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

preferred-node-version - npm Package Compare versions

Comparing version 4.1.0 to 4.2.0

12

build/src/find.js

@@ -6,4 +6,8 @@ import{getVersionEnvVariable}from"./env.js";

export const findVersion=async(cwd,globalOpt)=>{
const{filePath,rawVersion}=await getVersionFile(cwd,globalOpt);
export const findVersion=async({cwd,globalOpt,files})=>{
const{filePath,rawVersion}=await getVersionFile({
cwd,
globalOpt,
files
});

@@ -18,4 +22,4 @@ if(rawVersion!==undefined){

const getVersionFile=async(cwd,globalOpt)=>{
const filePath=await getFilePath(cwd,globalOpt);
const getVersionFile=async({cwd,globalOpt,files})=>{
const filePath=await getFilePath({cwd,globalOpt,files});

@@ -22,0 +26,0 @@ if(filePath===undefined){

@@ -18,2 +18,10 @@ import{readFile}from"node:fs/promises";

const loadFunction=LOAD_FUNCTIONS[filename];
if(loadFunction===undefined){
throw new Error(
`Option "files" is invalid: ${filename}
Allowed values are: ${NODE_VERSION_FILES.join(", ")}`
)
}
const rawVersion=loadFunction(contentA);

@@ -20,0 +28,0 @@ return rawVersion

@@ -26,2 +26,10 @@ import type {

/**
* Additional files to lookup.
* Their filenames must be one of `package.json`, `.nvmrc`, etc.
*
* @default []
*/
files?: string[]
/**
* Base URL.

@@ -115,2 +123,7 @@ * Can be customized (for example `https://npmmirror.com/mirrors/node`).

* const { version } = await preferredNodeVersion({ cwd: '/path/to/cwd' })
*
* // Search for specific files
* await preferredNodeVersion({
* files: ['/path/to/.nvmrc', '/path/to/package.json'],
* })
* ```

@@ -121,1 +134,6 @@ */

): Promise<PreferredNodeVersion>
/**
* List of filenames being searched: `.nvmrc`, `package.json`, etc.
*/
export declare const NODE_VERSION_FILES: string[]

@@ -7,10 +7,13 @@ import nodeVersionAlias from"node-version-alias";

export{NODE_VERSION_FILES}from"./load.js";
const preferredNodeVersion=async(opts)=>{
const{cwd,globalOpt,nodeVersionAliasOpts}=getOpts(opts);
const{filePath,envVariable,rawVersion}=await findVersion(
const{cwd,globalOpt,files,nodeVersionAliasOpts}=getOpts(opts);
const{filePath,envVariable,rawVersion}=await findVersion({
cwd,
globalOpt
);
globalOpt,
files
});

@@ -17,0 +20,0 @@ if(rawVersion===undefined){

@@ -15,2 +15,3 @@ import{normalize}from"node:path";

global:globalOpt=false,
files=[],
fetch:fetchOpt,

@@ -21,4 +22,5 @@ mirror,

const cwdA=normalizeCwd(cwd);
validateFiles(files);
const nodeVersionAliasOpts={fetch:fetchOpt,mirror,signal};
return{cwd:cwdA,globalOpt,nodeVersionAliasOpts}
return{cwd:cwdA,globalOpt,files,nodeVersionAliasOpts}
};

@@ -38,2 +40,10 @@

const{toString:objectToString}=Object.prototype;
const{toString:objectToString}=Object.prototype;
const validateFiles=(files)=>{
if(!Array.isArray(files)||!files.every(isDefinedString)){
throw new TypeError(`Option "files" must an array of file paths: ${files}`)
}
};
const isDefinedString=(file)=>typeof file==="string"&&file!=="";

@@ -1,2 +0,2 @@

import{join}from"node:path";
import{join,resolve}from"node:path";

@@ -11,5 +11,6 @@ import pLocate from"p-locate";

export const getFilePath=(cwd,globalOpt)=>{
export const getFilePath=({cwd,globalOpt,files})=>{
const customFiles=files.map((filename)=>resolve(cwd,filename));
const searchFiles=getSearchFiles(cwd,globalOpt);
return pLocate(searchFiles,isNodeVersionFile)
return pLocate([...customFiles,...searchFiles],isNodeVersionFile)
};

@@ -16,0 +17,0 @@

{
"name": "preferred-node-version",
"version": "4.1.0",
"version": "4.2.0",
"type": "module",

@@ -5,0 +5,0 @@ "exports": {

@@ -46,2 +46,9 @@ [![Node](https://img.shields.io/badge/-Node.js-808080?logo=node.js&colorA=404040&logoColor=66cc33)](https://www.npmjs.com/package/preferred-node-version)

```js
// Search for specific files
await preferredNodeVersion({
files: ['/path/to/.nvmrc', '/path/to/package.json'],
})
```
# Install

@@ -123,2 +130,10 @@

#### files
_Type_: `string[]`\
_Default_: `[]`
Additional files to lookup. Their filenames must be one of `package.json`,
`.nvmrc`, etc.
#### mirror

@@ -153,2 +168,8 @@

## NODE_VERSION_FILES
_Type_: `string[]`
List of filenames being searched: `.nvmrc`, `package.json`, etc.
# See also

@@ -155,0 +176,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc