Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sm/pjson-engines-is-minimum #216

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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