From 6822dd9e6b859c458f1c81eb42e7e02fe797c051 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Wed, 30 Aug 2023 16:16:32 -0600 Subject: [PATCH 1/2] fix: run oclif lock during prepack --- bin/sf-prepack.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/sf-prepack.js b/bin/sf-prepack.js index f7ad5154..42dce110 100755 --- a/bin/sf-prepack.js +++ b/bin/sf-prepack.js @@ -16,7 +16,10 @@ shell.exec('yarn build'); if (isPlugin(packageRoot)) { if (shell.which('oclif')) { shell.exec('oclif manifest .'); + 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 From 357e113fd5fe0d3a17710eab8c1f9b0efe9074f3 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 1 Sep 2023 11:31:01 -0600 Subject: [PATCH 2/2] fix: check oclif version before running lock command --- bin/sf-prepack.js | 27 ++++++++++++++++++++++++++- utils/shelljs.js | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/bin/sf-prepack.js b/bin/sf-prepack.js index 42dce110..8313cf13 100755 --- a/bin/sf-prepack.js +++ b/bin/sf-prepack.js @@ -13,10 +13,35 @@ 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 .'); - shell.exec('oclif lock'); + 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.'); diff --git a/utils/shelljs.js b/utils/shelljs.js index 302d9777..7a7dc396 100644 --- a/utils/shelljs.js +++ b/utils/shelljs.js @@ -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