Skip to content

Commit

Permalink
Merge pull request #212 from forcedotcom/mdonnalley/oclif-lock
Browse files Browse the repository at this point in the history
fix: run oclif lock during prepack
  • Loading branch information
mdonnalley committed Sep 1, 2023
2 parents 7495837 + 357e113 commit 6bc9720
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions bin/sf-prepack.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,38 @@ const packageRoot = require('../utils/package-path');

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 .');
const version = shell.exec('oclif --version', { silent: true }).stdout.trim().replace('oclif/', '').split(' ')[0];
if (semverIsLessThan(version, '3.14.0')) {
// eslint-disable-next-line no-console
console.log(
chalk.yellow('Warning:'),
// eslint-disable-next-line max-len
`oclif version ${version} is less than 3.14.0. Please upgrade to 3.14.0 or higher to use generate oclif.lock file.`
);
} else {
shell.exec('oclif lock');
}
} else if (shell.which('oclif-dev')) {
// eslint-disable-next-line no-console
console.log(chalk.yellow('Warning:'), 'oclif-dev is deprecated. Please use oclif instead.');
shell.exec('oclif-dev manifest');
} else {
// eslint-disable-next-line no-console
Expand Down
2 changes: 1 addition & 1 deletion utils/shelljs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ shell.exec = function (command, ...args) {
// eslint-disable-next-line no-console
console.error(chalk.blue(command));
try {
origExec.call(shell, command, ...args);
return origExec.call(shell, command, ...args);
} catch (err) {
// Setting -e will throw an error. We are already displaying the command
// output above which has information on the problem, so don't show the
Expand Down

0 comments on commit 6bc9720

Please sign in to comment.