Skip to content

Commit

Permalink
Merge pull request #216 from forcedotcom/sm/pjson-engines-is-minimum
Browse files Browse the repository at this point in the history
Sm/pjson-engines-is-minimum
  • Loading branch information
mshanemc authored Oct 9, 2023
2 parents 1784d12 + 1349a95 commit eb5e890
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
16 changes: 1 addition & 15 deletions bin/sf-prepack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 .');
Expand Down
21 changes: 21 additions & 0 deletions utils/semver.js
Original file line number Diff line number Diff line change
@@ -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;
};
5 changes: 4 additions & 1 deletion utils/standardize-pjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) => {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit eb5e890

Please sign in to comment.