├── .gitignore ├── .nvmrc ├── .travis.yml ├── CHANGELOG.md ├── README.md ├── bin └── cli.js ├── package.json ├── src ├── api-commonjs.js ├── api.js ├── cli.js ├── minimum-node-version.js └── version-data.js ├── test └── minimum-node-version-test.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | /.idea/ 3 | /*.log 4 | .*.swp 5 | /.esm-cache/ 6 | /*.tgz 7 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 10.13.0 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "10.13.0" 5 | - "10" 6 | - "12.0.0" 7 | - "12" 8 | - "14.0.0" 9 | - "14" 10 | - "stable" 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 7 | 8 | ## [Unreleased] 9 | 10 | _New unreleased changes are listed here, and moved down to a release number when released._ 11 | 12 | ## [3.0.0] - 2020-12-12 13 | 14 | ### Security 15 | 16 | - Upgrade dependencies. 17 | 18 | ### Changed 19 | 20 | - **BREAKING** Require Node.js version `^10.13.0 || >=12.0.0` 21 | - Upgrade dependencies. 22 | 23 | ## [2.0.2] - 2019-07-13 24 | 25 | ### Changed 26 | 27 | - Upgrade dependencies. 28 | - Require more specific Node.js version `^8.12.0 || ^10.13.0 || >=11.10.1`. 29 | 30 | ## [2.0.1] - 2019-06-14 31 | 32 | ### Changed 33 | 34 | - Upgrade dependencies. 35 | 36 | ## [2.0.0] - 2019-05-03 37 | 38 | ### Changed 39 | 40 | - **BREAKING** Require Node.js version `8.* || >= 10.*` 41 | - Upgrade dependencies. 42 | 43 | ## [1.0.1] - 2017-12-08 44 | 45 | ### Changed 46 | 47 | - Use `semver.minSatisfying()`. 48 | 49 | ## [1.0.0] - 2017-12-08 50 | 51 | ### Added 52 | 53 | - Use [nodejs-example-cli](https://github.com/hugojosefson/nodejs-example-cli/) as template. 54 | - First implementation. 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # minimum-node-version 2 | 3 | [![Build Status](https://travis-ci.org/hugojosefson/minimum-node-version.svg?branch=master)](https://travis-ci.org/hugojosefson/minimum-node-version) 4 | [![npm page](https://img.shields.io/npm/v/minimum-node-version.svg)](https://npmjs.com/package/minimum-node-version) 5 | [![License ISC](https://img.shields.io/npm/l/minimum-node-version.svg)](https://tldrlegal.com/license/-isc-license) 6 | [![SemVer 2.0.0](https://img.shields.io/badge/SemVer-2.0.0-lightgrey.svg)](http://semver.org/spec/v2.0.0.html) 7 | [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) 8 | 9 | ## Introduction 10 | 11 | Figures out the lowest version of Node.js that satisfies `engines.node` in `package.json`. 12 | 13 | Can be quite useful for which `node` version to configure `babel-preset-env` for. 14 | 15 | ## Prerequisite 16 | 17 | Node.js, at least `v8.0.0`, but not `v9`. 18 | 19 | Recommended to install latest via [nvm](https://github.com/nvm-sh/nvm#readme): 20 | 21 | ```bash 22 | nvm install stable 23 | ``` 24 | 25 | ## Installation 26 | 27 | ```bash 28 | npm install -g minimum-node-version 29 | ``` 30 | 31 | ## CLI Usage 32 | 33 | ```bash 34 | minimum-node-version 35 | ``` 36 | 37 | Will print the Node.js version. 38 | 39 | ## Programmatic access 40 | 41 | You can also `import` or `require` the module, and use it programmatically. 42 | 43 | ```js 44 | import minimumNodeVersion from 'minimum-node-version' 45 | 46 | minimumNodeVersion().then( 47 | version => console.log(version) 48 | ) 49 | ``` 50 | 51 | ### API 52 | 53 | 54 | 55 | ##### Table of Contents 56 | 57 | - [minimumNodeVersion](#minimumnodeversion) 58 | 59 | #### minimumNodeVersion 60 | 61 | Figures out the minimum Node.js version that satisfies the project's configuration. 62 | 63 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** A Promise of the lowest compatible Node.js version. 64 | -------------------------------------------------------------------------------- /bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('engine-check')() 4 | require('esm')(module)('../src/cli') 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minimum-node-version", 3 | "version": "3.0.0", 4 | "description": "Figures out the lowest version of Node.js that satisfies package.json engines.node", 5 | "main": "src/api-commonjs.js", 6 | "module": "src/api.js", 7 | "files": [ 8 | "bin", 9 | "src" 10 | ], 11 | "bin": { 12 | "minimum-node-version": "bin/cli.js" 13 | }, 14 | "scripts": { 15 | "start": "bin/cli.js", 16 | "test": "run-s lint mocha", 17 | "mocha": "mocha --require esm 'test/**/*-test.{m,}js'", 18 | "mocha-watch": "mocha --watch --require esm 'test/**/*-test.{m,}js'", 19 | "lint": "standard", 20 | "lint-fix": "standard --fix", 21 | "prepare": "run-s documentation", 22 | "documentation": "documentation readme --section=API --shallow --format=md src/api.js" 23 | }, 24 | "lint-staged": { 25 | "*.{mjs,js,jsx}": [ 26 | "standard --fix", 27 | "git add" 28 | ] 29 | }, 30 | "repository": "hugojosefson/minimum-node-version", 31 | "keywords": [ 32 | "node", 33 | "nodejs", 34 | "version", 35 | "minimum", 36 | "semver", 37 | "babel-preset-env", 38 | "satisfies" 39 | ], 40 | "author": "Hugo Josefson (https://www.hugojosefson.com/)", 41 | "license": "ISC", 42 | "comment-engines.node": "Not using babel, code seems to work from v6.0.0 and up.", 43 | "engines": { 44 | "node": "^10.13.0 || >=12.0.0" 45 | }, 46 | "comment-esm.cjs": "Allow destructuring import from common-js modules.", 47 | "esm": { 48 | "cjs": true 49 | }, 50 | "devDependencies": { 51 | "documentation": "^13.1.0", 52 | "husky": "^4.3.5", 53 | "lint-staged": "^10.5.3", 54 | "mocha": "^8.2.1", 55 | "npm-run-all": "^4.1.2", 56 | "standard": "^16.0.3" 57 | }, 58 | "dependencies": { 59 | "engine-check": "^1.0.1", 60 | "esm": "^3.2.25", 61 | "expected-node-version": "^1.0.2", 62 | "node-version-data": "^1.0.1", 63 | "pify": "^5.0.0", 64 | "semver": "^7.3.4" 65 | }, 66 | "husky": { 67 | "hooks": { 68 | "pre-commit": "lint-staged" 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/api-commonjs.js: -------------------------------------------------------------------------------- 1 | module.exports = require('esm')(module)('./api') 2 | -------------------------------------------------------------------------------- /src/api.js: -------------------------------------------------------------------------------- 1 | import minimumNodeVersion from './minimum-node-version' 2 | 3 | /** 4 | * Figures out the minimum Node.js version that satisfies the project's configuration. 5 | * 6 | * @returns {Promise.} A Promise of the lowest compatible Node.js version. 7 | * @name minimumNodeVersion 8 | */ 9 | export default minimumNodeVersion 10 | -------------------------------------------------------------------------------- /src/cli.js: -------------------------------------------------------------------------------- 1 | import { basename } from 'path' 2 | import minimumNodeVersion from './api' 3 | 4 | if (process.argv.length !== 2) { 5 | console.error(`Usage: ${basename(process.argv[1])}`) 6 | process.exit(1) 7 | } 8 | 9 | minimumNodeVersion() 10 | .then(version => console.log(version)) 11 | .catch(err => { 12 | console.error('Caught error:', err.stack) 13 | process.exit(1) 14 | }) 15 | -------------------------------------------------------------------------------- /src/minimum-node-version.js: -------------------------------------------------------------------------------- 1 | import { clean, minSatisfying } from 'semver' 2 | 3 | import versionData from './version-data' 4 | import expectedNodeVersion from 'expected-node-version' 5 | 6 | export default () => { 7 | const expected = expectedNodeVersion() 8 | 9 | return versionData().then(records => { 10 | const versions = records 11 | .filter(record => record.name === 'Node.js') 12 | .map(record => record.version) 13 | .map(version => clean(version)) 14 | 15 | return minSatisfying(versions, expected) 16 | }) 17 | } 18 | -------------------------------------------------------------------------------- /src/version-data.js: -------------------------------------------------------------------------------- 1 | import pify from 'pify' 2 | import versionData from 'node-version-data' 3 | 4 | export default pify(versionData) 5 | -------------------------------------------------------------------------------- /test/minimum-node-version-test.js: -------------------------------------------------------------------------------- 1 | /* eslint-env mocha */ 2 | 3 | import assert from 'assert' 4 | import minimumNodeVersion from '../src/api' 5 | 6 | const VERSION_STRING = /^[0-9]+\.[0-9]+\.[0-9]+$/ 7 | 8 | describe('minimumNodeVersion', () => { 9 | it('is a function', () => 10 | assert.ok(typeof minimumNodeVersion === 'function') 11 | ) 12 | 13 | it('should return a Promise', () => 14 | assert.ok(typeof minimumNodeVersion().then === 'function') 15 | ) 16 | 17 | it('should resolve to a version string', () => 18 | minimumNodeVersion() 19 | .then(version => assert.ok(VERSION_STRING.test(version))) 20 | ) 21 | 22 | it('should resolve to 10.13.0 for this project', () => 23 | minimumNodeVersion() 24 | .then(version => assert.strictEqual(version, '10.13.0')) 25 | ) 26 | }) 27 | --------------------------------------------------------------------------------