From 2252a55519449c87bf6adc8ea480f81bb284437d Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 9 Oct 2023 13:56:41 -0500 Subject: [PATCH 1/3] refactor: share semverLt function --- bin/sf-prepack.js | 16 +--------------- utils/semver.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 utils/semver.js 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; +}; From 6758da088be0d10fd4ff416f71e4913b5a9141ea Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 9 Oct 2023 13:57:06 -0500 Subject: [PATCH 2/3] feat: don't downgrade engines if already higher --- utils/standardize-pjson.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/standardize-pjson.js b/utils/standardize-pjson.js index 6e21c898..8cbeb080 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, engineVersion) ) { pjson.actions.push('updating node engine'); pjson.contents.engines.node = engineVersion; From 1349a95ce194e20058c1e5f2558c02e632bf6929 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 9 Oct 2023 14:08:46 -0500 Subject: [PATCH 3/3] fix: semver strip >= --- utils/standardize-pjson.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/standardize-pjson.js b/utils/standardize-pjson.js index 8cbeb080..9519d5c5 100644 --- a/utils/standardize-pjson.js +++ b/utils/standardize-pjson.js @@ -58,7 +58,7 @@ module.exports = (packageRoot = require('./package-path')) => { pjson.contents.engines && pjson.contents.engines.node && pjson.contents.engines.node !== engineVersion && - semverIsLessThan(pjson.contents.engines.node, engineVersion) + semverIsLessThan(pjson.contents.engines.node.replace('>=', ''), engineVersion.replace('>=', '')) ) { pjson.actions.push('updating node engine'); pjson.contents.engines.node = engineVersion;