diff --git a/bin/sf-prepack.js b/bin/sf-prepack.js index 8313cf13..5d52fe1a 100755 --- a/bin/sf-prepack.js +++ b/bin/sf-prepack.js @@ -10,24 +10,10 @@ const chalk = require('chalk'); const shell = require('../utils/shelljs'); const { isPlugin } = require('../utils/project-type'); const packageRoot = require('../utils/package-path'); +const { semverIsLessThan } = require('../utils/semver'); shell.exec('yarn build'); -const semverIsLessThan = (version, target) => { - const [major, minor, patch] = version.split('.').map((v) => parseInt(v, 10)); - const [targetMajor, targetMinor, targetPatch] = target.split('.').map((v) => parseInt(v, 10)); - if (major < targetMajor) { - return true; - } - if (major === targetMajor && minor < targetMinor) { - return true; - } - if (major === targetMajor && minor === targetMinor && patch < targetPatch) { - return true; - } - return false; -}; - if (isPlugin(packageRoot)) { if (shell.which('oclif')) { shell.exec('oclif manifest .'); diff --git a/utils/semver.js b/utils/semver.js new file mode 100644 index 00000000..2010c1fc --- /dev/null +++ b/utils/semver.js @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ + +exports.semverIsLessThan = (version, target) => { + const [major, minor, patch] = version.split('.').map((v) => parseInt(v, 10)); + const [targetMajor, targetMinor, targetPatch] = target.split('.').map((v) => parseInt(v, 10)); + if (major < targetMajor) { + return true; + } + if (major === targetMajor && minor < targetMinor) { + return true; + } + if (major === targetMajor && minor === targetMinor && patch < targetPatch) { + return true; + } + return false; +}; diff --git a/utils/standardize-pjson.js b/utils/standardize-pjson.js index 6e21c898..9519d5c5 100644 --- a/utils/standardize-pjson.js +++ b/utils/standardize-pjson.js @@ -8,6 +8,8 @@ const { readFileSync } = require('fs'); const { join } = require('path'); const { resolveConfig } = require('./sf-config'); +const { semverIsLessThan } = require('./semver'); + const PackageJson = require('./package-json'); module.exports = (packageRoot = require('./package-path')) => { @@ -55,7 +57,8 @@ module.exports = (packageRoot = require('./package-path')) => { tsconfig.match(/"extends"\s*:\s*".*@salesforce\/dev-config/) && pjson.contents.engines && pjson.contents.engines.node && - pjson.contents.engines.node !== engineVersion + pjson.contents.engines.node !== engineVersion && + semverIsLessThan(pjson.contents.engines.node.replace('>=', ''), engineVersion.replace('>=', '')) ) { pjson.actions.push('updating node engine'); pjson.contents.engines.node = engineVersion;