Bump oclif-core to v3

Change-type: patch
This commit is contained in:
Otávio Jacobi 2023-10-05 07:52:10 -03:00
parent e4624eda10
commit 72a924f00e
9 changed files with 1087 additions and 74 deletions

View File

@ -15,7 +15,7 @@ async function run() {
require('@balena/es-version').set('es2018');
// Run the CLI
await require('../build/app').run();
await require('../build/app').run(undefined, { dir: __dirname });
}
run();

View File

@ -57,7 +57,7 @@ require('ts-node').register({
project: path.join(rootDir, 'tsconfig.json'),
transpileOnly: true,
});
require('../lib/app').run();
require('../lib/app').run(undefined, { dir: __dirname, development: true });
// Modify package.json oclif paths from build/ -> lib/, or vice versa
function modifyOclifPaths(revert) {

View File

@ -24,7 +24,7 @@ import {
} from './preparser';
import { CliSettings } from './utils/bootstrap';
import { onceAsync } from './utils/lazy';
import { run as mainRun } from '@oclif/core';
import { run as mainRun, settings } from '@oclif/core';
/**
* Sentry.io setup
@ -117,7 +117,14 @@ async function oclifRun(command: string[], options: AppOptions) {
const runPromise = (async function (shouldFlush: boolean) {
let isEEXIT = false;
try {
await mainRun(command, options.configPath);
if (options.development) {
// In dev mode -> use ts-node and dev plugins
process.env.NODE_ENV = 'development';
settings.debug = true;
}
// For posteriority: We can't use default oclif 'execute' as
// We customize error handling and flushing
await mainRun(command, options.loadOptions ?? options.dir);
} catch (error) {
// oclif sometimes exits with ExitError code EEXIT 0 (not an error),
// for example the `balena help` command.
@ -151,7 +158,7 @@ async function oclifRun(command: string[], options: AppOptions) {
}
/** CLI entrypoint. Called by the `bin/balena` and `bin/balena-dev` scripts. */
export async function run(cliArgs = process.argv, options: AppOptions = {}) {
export async function run(cliArgs = process.argv, options: AppOptions) {
try {
const { setOfflineModeEnvVars, normalizeEnvVars, pkgExec } = await import(
'./utils/bootstrap'

View File

@ -50,7 +50,7 @@ export default class BalenaHelp extends Help {
const command = this.config.findCommand(subject);
if (command) {
await this.showCommandHelp(await command.load());
await this.showCommandHelp(command);
return;
}

View File

@ -15,12 +15,16 @@
* limitations under the License.
*/
import type { Interfaces } from '@oclif/core';
export let unsupportedFlag = false;
export interface AppOptions {
// Prevent the default behavior of flushing stdout after running a command
noFlush?: boolean;
configPath?: string;
development?: boolean;
dir: string;
loadOptions?: Interfaces.LoadOptions;
}
export async function preparseArgs(argv: string[]): Promise<string[]> {

1081
npm-shrinkwrap.json generated

File diff suppressed because it is too large Load Diff

View File

@ -196,7 +196,7 @@
"@balena/compose": "^3.0.5",
"@balena/dockerignore": "^1.0.2",
"@balena/es-version": "^1.0.1",
"@oclif/core": "^2.15.0",
"@oclif/core": "^3.11.0",
"@resin.io/valid-email": "^0.1.0",
"@sentry/node": "^6.16.1",
"@types/fast-levenshtein": "0.0.1",

View File

@ -1,5 +1,5 @@
diff --git a/node_modules/@oclif/core/lib/cli-ux/list.js b/node_modules/@oclif/core/lib/cli-ux/list.js
index dc6058c..64b2f85 100644
index 607d8dc..07ba1f2 100644
--- a/node_modules/@oclif/core/lib/cli-ux/list.js
+++ b/node_modules/@oclif/core/lib/cli-ux/list.js
@@ -22,7 +22,7 @@ function renderList(items) {
@ -12,20 +12,20 @@ index dc6058c..64b2f85 100644
return lines.join('\n');
}
diff --git a/node_modules/@oclif/core/lib/help/command.js b/node_modules/@oclif/core/lib/help/command.js
index 6de139b..3a13197 100644
index c528e93..2c20760 100644
--- a/node_modules/@oclif/core/lib/help/command.js
+++ b/node_modules/@oclif/core/lib/help/command.js
@@ -206,7 +206,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
if (args.filter(a => a.description).length === 0)
@@ -45,7 +45,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
if (args.filter((a) => a.description).length === 0)
return;
return args.map(a => {
return args.map((a) => {
- const name = a.name.toUpperCase();
+ const name = a.required ? `<${a.name}>` : `[${a.name}]`;
let description = a.description || '';
if (a.default)
description = `[default: ${a.default}] ${description}`;
@@ -238,14 +238,12 @@ class CommandHelp extends formatter_1.HelpFormatter {
label = labels.join(', ');
@@ -137,14 +137,12 @@ class CommandHelp extends formatter_1.HelpFormatter {
label = labels.join(flag.char ? ', ' : ' ');
}
if (flag.type === 'option') {
- let value = flag.helpValue || (this.opts.showFlagNameInTitle ? flag.name : '<value>');
@ -36,16 +36,16 @@ index 6de139b..3a13197 100644
if (flag.multiple)
- value += '...';
- if (!value.includes('|'))
- value = underline(value);
- value = chalk_1.default.underline(value);
+ value += ' ...';
label += `=${value}`;
}
return label;
diff --git a/node_modules/@oclif/core/lib/help/index.js b/node_modules/@oclif/core/lib/help/index.js
index f9ef7cc..a14c67c 100644
index 38494f5..213b8b0 100644
--- a/node_modules/@oclif/core/lib/help/index.js
+++ b/node_modules/@oclif/core/lib/help/index.js
@@ -136,11 +136,12 @@ class Help extends HelpBase {
@@ -158,11 +158,12 @@ class Help extends HelpBase {
}
this.log(this.formatCommand(command));
this.log('');
@ -58,15 +58,15 @@ index f9ef7cc..a14c67c 100644
- if (subCommands.length > 0) {
+ if (subCommands.length > 0 && !SUPPRESS_SUBTOPICS) {
const aliases = [];
const uniqueSubCommands = subCommands.filter(p => {
const uniqueSubCommands = subCommands.filter((p) => {
aliases.push(...p.aliases);
diff --git a/node_modules/@oclif/core/lib/parser/errors.js b/node_modules/@oclif/core/lib/parser/errors.js
index 07ec8e5..a4560ea 100644
index 51be624..768d589 100644
--- a/node_modules/@oclif/core/lib/parser/errors.js
+++ b/node_modules/@oclif/core/lib/parser/errors.js
@@ -10,7 +10,8 @@ var errors_2 = require("../errors");
Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return errors_2.CLIError; } });
@@ -14,7 +14,8 @@ Object.defineProperty(exports, "CLIError", { enumerable: true, get: function ()
class CLIParseError extends errors_1.CLIError {
parse;
constructor(options) {
- options.message += '\nSee more help with --help';
+ const help = options.command ? `\`${options.command} --help\`` : '--help';
@ -74,33 +74,34 @@ index 07ec8e5..a4560ea 100644
super(options.message);
this.parse = options.parse;
}
@@ -31,7 +32,8 @@ class InvalidArgsSpecError extends CLIParseError {
exports.InvalidArgsSpecError = InvalidArgsSpecError;
@@ -37,7 +38,8 @@ exports.InvalidArgsSpecError = InvalidArgsSpecError;
class RequiredArgsError extends CLIParseError {
constructor({ args, parse, flagsWithMultiple }) {
args;
constructor({ args, flagsWithMultiple, parse, }) {
- let message = `Missing ${args.length} required arg${args.length === 1 ? '' : 's'}`;
+ const command = 'balena ' + parse.input.context.id.replace(/:/g, ' ');
+ let message = `Missing ${args.length} required argument${args.length === 1 ? '' : 's'}`;
const namedArgs = args.filter(a => a.name);
const namedArgs = args.filter((a) => a.name);
if (namedArgs.length > 0) {
const list = (0, list_1.renderList)(namedArgs.map(a => [a.name, a.description]));
@@ -42,16 +44,17 @@ class RequiredArgsError extends CLIParseError {
const list = (0, list_1.renderList)(namedArgs.map((a) => [a.name, a.description]));
@@ -48,7 +50,7 @@ class RequiredArgsError extends CLIParseError {
message += `\n\nNote: ${flags} allow${flagsWithMultiple.length === 1 ? 's' : ''} multiple values. Because of this you need to provide all arguments before providing ${flagsWithMultiple.length === 1 ? 'that flag' : 'those flags'}.`;
message += '\nAlternatively, you can use "--" to signify the end of the flags and the beginning of arguments.';
}
- super({ parse, message });
+ super({ parse, message, command });
- super({ message, parse });
+ super({ message, parse, command });
this.args = args;
}
}
exports.RequiredArgsError = RequiredArgsError;
@@ -56,9 +58,10 @@ exports.RequiredArgsError = RequiredArgsError;
class RequiredFlagError extends CLIParseError {
flag;
constructor({ flag, parse }) {
+ const command = 'balena ' + parse.input.context.id.replace(/:/g, ' ');
const usage = (0, list_1.renderList)((0, help_1.flagUsages)([flag], { displayRequired: false }));
const message = `Missing required flag:\n${usage}`;
- super({ parse, message });
+ super({ parse, message, command });
- super({ message, parse });
+ super({ message, parse, command });
this.flag = flag;
}
}

View File

@ -106,7 +106,7 @@ async function runCommandInProcess(cmd: string): Promise<TestOutput> {
try {
await balenaCLI.run(preArgs.concat(cmd.split(' ').filter((c) => c)), {
configPath: path.resolve(__dirname, '..'),
dir: path.resolve(__dirname, '..'),
noFlush: true,
});
} finally {