Sha256: 645c07e4c8cbb980f6f6525b4af02887e4867d9ac92b66d27c10a8fff69de807

Contents?: true

Size: 1.3 KB

Versions: 43

Compression:

Stored size: 1.3 KB

Contents

/**
 * @author Toru Nagashima <https://github.com/mysticatea>
 * See LICENSE file in root directory for full license.
 */
"use strict"

const { Range } = require("semver") //eslint-disable-line no-unused-vars
const getPackageJson = require("./get-package-json")
const getSemverRange = require("./get-semver-range")

/**
 * Get the `engines.node` field of package.json.
 * @param {string} filename The path to the current linting file.
 * @returns {Range|null} The range object of the `engines.node` field.
 */
function getEnginesNode(filename) {
    const info = getPackageJson(filename)
    return getSemverRange(info && info.engines && info.engines.node)
}

/**
 * Gets version configuration.
 *
 * 1. Parse a given version then return it if it's valid.
 * 2. Look package.json up and parse `engines.node` then return it if it's valid.
 * 3. Return `>=6.0.0`.
 *
 * @param {string|undefined} version The version range text.
 * @param {string} filename The path to the current linting file.
 * This will be used to look package.json up if `version` is not a valid version range.
 * @returns {Range} The configured version range.
 */
module.exports = function getConfiguredNodeVersion(version, filename) {
    return (
        getSemverRange(version) ||
        getEnginesNode(filename) ||
        getSemverRange(">=6.0.0")
    )
}

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.21.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.20.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.19.1 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.19.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.18.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.17.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.16.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.15.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.14.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.13.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.12.2 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.12.1 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.12.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.11.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.10.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.9.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.8.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.7.0 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js
govuk_publishing_components-17.6.1 node_modules/eslint-plugin-node/lib/util/get-configured-node-version.js