@oclif/core 1.11.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [1.13.0](https://github.com/oclif/core/compare/v1.12.1...v1.13.0) (2022-07-28)
6
+
7
+
8
+ ### Features
9
+
10
+ * drop node12, use es2020 ([ac749e3](https://github.com/oclif/core/commit/ac749e32917400386f0ee4056aa5b66a52f3d0e0))
11
+ * min/max for integer flag ([7e05ef7](https://github.com/oclif/core/commit/7e05ef7195269012055f30095552e61359fad47e))
12
+ * node14/es2020 for bigint, pr feedback ([03a50b8](https://github.com/oclif/core/commit/03a50b874a8e7ef621c23d846e63864e3850ee4a))
13
+
14
+ ### [1.12.1](https://github.com/oclif/core/compare/v1.12.0...v1.12.1) (2022-07-21)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * flag setter order ([#450](https://github.com/oclif/core/issues/450)) ([a02f86c](https://github.com/oclif/core/commit/a02f86cb1094a86ba0cd8689fd82908ff3d46386))
20
+
21
+ ## [1.12.0](https://github.com/oclif/core/compare/v1.11.0...v1.12.0) (2022-07-20)
22
+
23
+
24
+ ### Features
25
+
26
+ * improve the instantiation of global flags ([#445](https://github.com/oclif/core/issues/445)) ([d264535](https://github.com/oclif/core/commit/d2645358ccf1cddd0bb65d236e73ecf4c5ac7c0c))
27
+
5
28
  ## [1.11.0](https://github.com/oclif/core/compare/v1.10.0...v1.11.0) (2022-07-18)
6
29
 
7
30
 
@@ -11,11 +11,10 @@ function linewrap(length, s) {
11
11
  })(s).trim();
12
12
  }
13
13
  function renderList(items) {
14
- var _a, _b;
15
14
  if (items.length === 0) {
16
15
  return '';
17
16
  }
18
- const maxLength = (_b = (_a = (0, util_1.maxBy)(items, item => item[0].length)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
17
+ const maxLength = (0, util_1.maxBy)(items, item => item[0].length)?.[0].length ?? 0;
19
18
  const lines = items.map(i => {
20
19
  let left = i[0];
21
20
  let right = i[1];
@@ -46,11 +46,10 @@ function getPrompt(name, type, defaultValue) {
46
46
  return prompt;
47
47
  }
48
48
  async function single(options) {
49
- var _a;
50
49
  const raw = process.stdin.isRaw;
51
50
  if (process.stdin.setRawMode)
52
51
  process.stdin.setRawMode(true);
53
- options.required = (_a = options.required) !== null && _a !== void 0 ? _a : false;
52
+ options.required = options.required ?? false;
54
53
  const response = await normal(options);
55
54
  if (process.stdin.setRawMode)
56
55
  process.stdin.setRawMode(Boolean(raw));
@@ -11,17 +11,15 @@ const sw = require('string-width');
11
11
  const { orderBy } = require('natural-orderby');
12
12
  class Table {
13
13
  constructor(data, columns, options = {}) {
14
- var _a, _b;
15
14
  this.data = data;
16
15
  // assign columns
17
16
  this.columns = Object.keys(columns).map((key) => {
18
- var _a, _b, _c;
19
17
  const col = columns[key];
20
- const extended = (_a = col.extended) !== null && _a !== void 0 ? _a : false;
18
+ const extended = col.extended ?? false;
21
19
  // turn null and undefined into empty strings by default
22
- const get = (_b = col.get) !== null && _b !== void 0 ? _b : ((row) => { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; });
20
+ const get = col.get ?? ((row) => row[key] ?? '');
23
21
  const header = typeof col.header === 'string' ? col.header : (0, util_1.capitalize)(key.replace(/_/g, ' '));
24
- const minWidth = Math.max((_c = col.minWidth) !== null && _c !== void 0 ? _c : 0, sw(header) + 1);
22
+ const minWidth = Math.max(col.minWidth ?? 0, sw(header) + 1);
25
23
  return {
26
24
  extended,
27
25
  get,
@@ -37,9 +35,9 @@ class Table {
37
35
  output: csv ? 'csv' : output,
38
36
  extended,
39
37
  filter,
40
- 'no-header': (_a = options['no-header']) !== null && _a !== void 0 ? _a : false,
41
- 'no-truncate': (_b = options['no-truncate']) !== null && _b !== void 0 ? _b : false,
42
- printLine: printLine !== null && printLine !== void 0 ? printLine : ((s) => process.stdout.write(s + '\n')),
38
+ 'no-header': options['no-header'] ?? false,
39
+ 'no-truncate': options['no-truncate'] ?? false,
40
+ printLine: printLine ?? ((s) => process.stdout.write(s + '\n')),
43
41
  rowStart: ' ',
44
42
  sort,
45
43
  title,
@@ -133,10 +131,9 @@ class Table {
133
131
  return data.map((d) => {
134
132
  // eslint-disable-next-line unicorn/prefer-object-from-entries
135
133
  return columns.reduce((obj, col) => {
136
- var _a;
137
134
  return {
138
135
  ...obj,
139
- [col.key]: (_a = d[col.key]) !== null && _a !== void 0 ? _a : '',
136
+ [col.key]: d[col.key] ?? '',
140
137
  };
141
138
  }, {});
142
139
  });
package/lib/command.d.ts CHANGED
@@ -55,7 +55,9 @@ export default abstract class Command {
55
55
  */
56
56
  static examples: Interfaces.Example[];
57
57
  static parserOptions: {};
58
- static enableJsonFlag: boolean;
58
+ static _enableJsonFlag: boolean;
59
+ static get enableJsonFlag(): boolean;
60
+ static set enableJsonFlag(value: boolean);
59
61
  /**
60
62
  * instantiate and run the command
61
63
  * @param {Interfaces.Command.Class} this Class
package/lib/command.js CHANGED
@@ -39,20 +39,26 @@ class Command {
39
39
  this.debug = () => { };
40
40
  }
41
41
  }
42
+ static get enableJsonFlag() {
43
+ return this._enableJsonFlag;
44
+ }
45
+ static set enableJsonFlag(value) {
46
+ this._enableJsonFlag = value;
47
+ if (value)
48
+ this.globalFlags = jsonFlag;
49
+ }
42
50
  static get globalFlags() {
43
51
  return this._globalFlags;
44
52
  }
45
53
  static set globalFlags(flags) {
46
- this._globalFlags = this.enableJsonFlag ?
47
- Object.assign({}, jsonFlag, this.globalFlags, flags) :
48
- Object.assign({}, this.globalFlags, flags);
54
+ this._globalFlags = Object.assign({}, this.globalFlags, flags);
55
+ this.flags = {}; // force the flags setter to run
49
56
  }
50
57
  static get flags() {
51
58
  return this._flags;
52
59
  }
53
60
  static set flags(flags) {
54
- this.globalFlags = {};
55
- this._flags = Object.assign({}, this.globalFlags, flags);
61
+ this._flags = Object.assign({}, this._flags ?? {}, this.globalFlags, flags);
56
62
  }
57
63
  get ctor() {
58
64
  return this.constructor;
@@ -123,12 +129,11 @@ class Command {
123
129
  options = this.constructor;
124
130
  const opts = { context: this, ...options };
125
131
  // the spread operator doesn't work with getters so we have to manually add it here
126
- opts.flags = options === null || options === void 0 ? void 0 : options.flags;
132
+ opts.flags = Object.assign({}, options?.flags, options?.globalFlags);
127
133
  return Parser.parse(argv, opts);
128
134
  }
129
135
  async catch(err) {
130
- var _a, _b;
131
- process.exitCode = (_b = (_a = process.exitCode) !== null && _a !== void 0 ? _a : err.exitCode) !== null && _b !== void 0 ? _b : 1;
136
+ process.exitCode = process.exitCode ?? err.exitCode ?? 1;
132
137
  if (this.jsonEnabled()) {
133
138
  index_1.CliUx.ux.styledJSON(this.toErrorJson(err));
134
139
  }
@@ -169,7 +174,7 @@ Command.aliases = [];
169
174
  Command.strict = true;
170
175
  Command.parse = true;
171
176
  Command.parserOptions = {};
172
- Command.enableJsonFlag = false;
177
+ Command._enableJsonFlag = false;
173
178
  // eslint-disable-next-line valid-jsdoc
174
179
  /**
175
180
  * instantiate and run the command
@@ -40,8 +40,7 @@ class Permutations extends Map {
40
40
  }
41
41
  }
42
42
  get(key) {
43
- var _a;
44
- return (_a = super.get(key)) !== null && _a !== void 0 ? _a : new Set();
43
+ return super.get(key) ?? new Set();
45
44
  }
46
45
  getValid(key) {
47
46
  return this.validPermutations.get(key);
@@ -357,12 +356,11 @@ class Config {
357
356
  return [...this._topics.values()];
358
357
  }
359
358
  s3Key(type, ext, options = {}) {
360
- var _a;
361
359
  if (typeof ext === 'object')
362
360
  options = ext;
363
361
  else if (ext)
364
362
  options.ext = ext;
365
- const template = (_a = this.pjson.oclif.update.s3.templates[options.platform ? 'target' : 'vanilla'][type]) !== null && _a !== void 0 ? _a : '';
363
+ const template = this.pjson.oclif.update.s3.templates[options.platform ? 'target' : 'vanilla'][type] ?? '';
366
364
  return ejs.render(template, { ...this, ...options });
367
365
  }
368
366
  s3Url(key) {
@@ -501,7 +499,6 @@ class Config {
501
499
  return id;
502
500
  }
503
501
  loadCommands(plugin) {
504
- var _a;
505
502
  for (const command of plugin.commands) {
506
503
  if (this._commands.has(command.id)) {
507
504
  const prioritizedCommand = this.determinePriority([this._commands.get(command.id), command]);
@@ -514,7 +511,7 @@ class Config {
514
511
  for (const permutation of permutations) {
515
512
  this.commandPermutations.add(permutation, command.id);
516
513
  }
517
- for (const alias of (_a = command.aliases) !== null && _a !== void 0 ? _a : []) {
514
+ for (const alias of command.aliases ?? []) {
518
515
  if (this._commands.has(alias)) {
519
516
  const prioritizedCommand = this.determinePriority([this._commands.get(alias), command]);
520
517
  this._commands.set(prioritizedCommand.id, { ...prioritizedCommand, id: alias });
@@ -576,12 +573,10 @@ class Config {
576
573
  * @returns command instance {Command.Loadable} or undefined
577
574
  */
578
575
  determinePriority(commands) {
579
- var _a, _b;
580
- const oclifPlugins = (_b = (_a = this.pjson.oclif) === null || _a === void 0 ? void 0 : _a.plugins) !== null && _b !== void 0 ? _b : [];
576
+ const oclifPlugins = this.pjson.oclif?.plugins ?? [];
581
577
  const commandPlugins = commands.sort((a, b) => {
582
- var _a, _b;
583
- const pluginAliasA = (_a = a.pluginAlias) !== null && _a !== void 0 ? _a : 'A-Cannot-Find-This';
584
- const pluginAliasB = (_b = b.pluginAlias) !== null && _b !== void 0 ? _b : 'B-Cannot-Find-This';
578
+ const pluginAliasA = a.pluginAlias ?? 'A-Cannot-Find-This';
579
+ const pluginAliasB = b.pluginAlias ?? 'B-Cannot-Find-This';
585
580
  const aIndex = oclifPlugins.indexOf(pluginAliasA);
586
581
  const bIndex = oclifPlugins.indexOf(pluginAliasB);
587
582
  // When both plugin types are 'core' plugins sort based on index
@@ -99,7 +99,6 @@ class Plugin {
99
99
  this.warned = false;
100
100
  }
101
101
  async load() {
102
- var _a;
103
102
  this.type = this.options.type || 'core';
104
103
  this.tag = this.options.tag;
105
104
  const root = await findRoot(this.options.name, this.options.root);
@@ -109,7 +108,7 @@ class Plugin {
109
108
  this._debug('reading %s plugin %s', this.type, root);
110
109
  this.pjson = await (0, util_3.loadJSON)(path.join(root, 'package.json'));
111
110
  this.name = this.pjson.name;
112
- this.alias = (_a = this.options.name) !== null && _a !== void 0 ? _a : this.pjson.name;
111
+ this.alias = this.options.name ?? this.pjson.name;
113
112
  const pjsonPath = path.join(root, 'package.json');
114
113
  if (!this.name)
115
114
  throw new Error(`no name in ${pjsonPath}`);
@@ -14,7 +14,7 @@ function addOclifExitCode(error, options) {
14
14
  if (!('oclif' in error)) {
15
15
  error.oclif = {};
16
16
  }
17
- error.oclif.exit = (options === null || options === void 0 ? void 0 : options.exit) === undefined ? 2 : options.exit;
17
+ error.oclif.exit = options?.exit === undefined ? 2 : options.exit;
18
18
  return error;
19
19
  }
20
20
  exports.addOclifExitCode = addOclifExitCode;
@@ -9,7 +9,6 @@ const _1 = require(".");
9
9
  const clean = require("clean-stack");
10
10
  const cli_1 = require("./errors/cli");
11
11
  const handle = (err) => {
12
- var _a, _b, _c;
13
12
  try {
14
13
  if (!err)
15
14
  err = new cli_1.CLIError('no error?');
@@ -21,7 +20,7 @@ const handle = (err) => {
21
20
  if (shouldPrint) {
22
21
  console.error(pretty ? pretty : stack);
23
22
  }
24
- const exitCode = ((_a = err.oclif) === null || _a === void 0 ? void 0 : _a.exit) !== undefined && ((_b = err.oclif) === null || _b === void 0 ? void 0 : _b.exit) !== false ? (_c = err.oclif) === null || _c === void 0 ? void 0 : _c.exit : 1;
23
+ const exitCode = err.oclif?.exit !== undefined && err.oclif?.exit !== false ? err.oclif?.exit : 1;
25
24
  if (config_1.config.errorLogger && err.code !== 'EEXIT') {
26
25
  if (stack) {
27
26
  config_1.config.errorLogger.log(stack);
@@ -23,7 +23,6 @@ function exit(code = 0) {
23
23
  }
24
24
  exports.exit = exit;
25
25
  function error(input, options = {}) {
26
- var _a;
27
26
  let err;
28
27
  if (typeof input === 'string') {
29
28
  err = new cli_2.CLIError(input, options);
@@ -39,14 +38,13 @@ function error(input, options = {}) {
39
38
  const message = (0, pretty_print_1.default)(err);
40
39
  console.error(message);
41
40
  if (config_2.config.errorLogger)
42
- config_2.config.errorLogger.log((_a = err === null || err === void 0 ? void 0 : err.stack) !== null && _a !== void 0 ? _a : '');
41
+ config_2.config.errorLogger.log(err?.stack ?? '');
43
42
  }
44
43
  else
45
44
  throw err;
46
45
  }
47
46
  exports.error = error;
48
47
  function warn(input) {
49
- var _a;
50
48
  let err;
51
49
  if (typeof input === 'string') {
52
50
  err = new cli_2.CLIError.Warn(input);
@@ -60,6 +58,6 @@ function warn(input) {
60
58
  const message = (0, pretty_print_1.default)(err);
61
59
  console.error(message);
62
60
  if (config_2.config.errorLogger)
63
- config_2.config.errorLogger.log((_a = err === null || err === void 0 ? void 0 : err.stack) !== null && _a !== void 0 ? _a : '');
61
+ config_2.config.errorLogger.log(err?.stack ?? '');
64
62
  }
65
63
  exports.warn = warn;
@@ -73,10 +73,9 @@ class DocOpts {
73
73
  return new DocOpts(cmd).toString();
74
74
  }
75
75
  toString() {
76
- var _a;
77
76
  const opts = this.cmd.id === '.' || this.cmd.id === '' ? [] : ['<%= command.id %>'];
78
77
  if (this.cmd.args) {
79
- const a = ((_a = this.cmd.args) === null || _a === void 0 ? void 0 : _a.map(arg => `[${arg.name.toUpperCase()}]`)) || [];
78
+ const a = this.cmd.args?.map(arg => `[${arg.name.toUpperCase()}]`) || [];
80
79
  opts.push(...a);
81
80
  }
82
81
  try {
@@ -119,13 +118,12 @@ class DocOpts {
119
118
  return elementMap;
120
119
  }
121
120
  combineElementsToFlag(elementMap, flagName, flagNames, unionString) {
122
- var _a;
123
121
  if (!this.flagMap[flagName]) {
124
122
  return;
125
123
  }
126
- let isRequired = (_a = this.flagMap[flagName]) === null || _a === void 0 ? void 0 : _a.required;
124
+ let isRequired = this.flagMap[flagName]?.required;
127
125
  if (typeof isRequired !== 'boolean' || !isRequired) {
128
- isRequired = flagNames.reduce((required, toCombine) => { var _a; return required || ((_a = this.flagMap[toCombine]) === null || _a === void 0 ? void 0 : _a.required) || false; }, false);
126
+ isRequired = flagNames.reduce((required, toCombine) => required || this.flagMap[toCombine]?.required || false, false);
129
127
  }
130
128
  for (const toCombine of flagNames) {
131
129
  elementMap[flagName] = `${elementMap[flagName] || ''}${unionString}${elementMap[toCombine] || ''}`;
package/lib/help/index.js CHANGED
@@ -112,13 +112,12 @@ class Help extends HelpBase {
112
112
  (0, errors_1.error)(`Command ${subject} not found.`);
113
113
  }
114
114
  async showCommandHelp(command) {
115
- var _a, _b, _c, _d;
116
115
  const name = command.id;
117
116
  const depth = name.split(':').length;
118
117
  const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
119
118
  const subCommands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
120
119
  const plugin = this.config.plugins.find(p => p.name === command.pluginName);
121
- const state = ((_b = (_a = this.config.pjson) === null || _a === void 0 ? void 0 : _a.oclif) === null || _b === void 0 ? void 0 : _b.state) || ((_d = (_c = plugin === null || plugin === void 0 ? void 0 : plugin.pjson) === null || _c === void 0 ? void 0 : _c.oclif) === null || _d === void 0 ? void 0 : _d.state) || command.state;
120
+ const state = this.config.pjson?.oclif?.state || plugin?.pjson?.oclif?.state || command.state;
122
121
  if (state)
123
122
  this.log(`This command is in ${state}.\n`);
124
123
  const summary = this.summary(command);
@@ -137,10 +136,9 @@ class Help extends HelpBase {
137
136
  }
138
137
  }
139
138
  async showRootHelp() {
140
- var _a, _b;
141
139
  let rootTopics = this.sortedTopics;
142
140
  let rootCommands = this.sortedCommands;
143
- const state = (_b = (_a = this.config.pjson) === null || _a === void 0 ? void 0 : _a.oclif) === null || _b === void 0 ? void 0 : _b.state;
141
+ const state = this.config.pjson?.oclif?.state;
144
142
  if (state)
145
143
  this.log(`${this.config.bin} is in ${state}.\n`);
146
144
  this.log(this.formatRoot());
@@ -160,12 +158,11 @@ class Help extends HelpBase {
160
158
  }
161
159
  }
162
160
  async showTopicHelp(topic) {
163
- var _a, _b;
164
161
  const name = topic.name;
165
162
  const depth = name.split(':').length;
166
163
  const subTopics = this.sortedTopics.filter(t => t.name.startsWith(name + ':') && t.name.split(':').length === depth + 1);
167
164
  const commands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
168
- const state = (_b = (_a = this.config.pjson) === null || _a === void 0 ? void 0 : _a.oclif) === null || _b === void 0 ? void 0 : _b.state;
165
+ const state = this.config.pjson?.oclif?.state;
169
166
  if (state)
170
167
  this.log(`This topic is in ${state}.\n`);
171
168
  this.log(this.formatTopic(topic));
package/lib/help/util.js CHANGED
@@ -41,12 +41,11 @@ function collateSpacedCmdIDFromArgs(argv, config) {
41
41
  const isArgWithValue = (s) => s.includes('=');
42
42
  const finalizeId = (s) => s ? [...final, s].join(':') : final.join(':');
43
43
  const hasArgs = () => {
44
- var _a;
45
44
  const id = finalizeId();
46
45
  if (!id)
47
46
  return false;
48
47
  const cmd = config.findCommand(id);
49
- return Boolean(cmd && (cmd.strict === false || ((_a = cmd.args) === null || _a === void 0 ? void 0 : _a.length) > 0));
48
+ return Boolean(cmd && (cmd.strict === false || cmd.args?.length > 0));
50
49
  };
51
50
  for (const arg of argv) {
52
51
  if (idPresent(finalizeId(arg)))
@@ -87,9 +86,8 @@ function standardizeIDFromArgv(argv, config) {
87
86
  }
88
87
  exports.standardizeIDFromArgv = standardizeIDFromArgv;
89
88
  function getHelpFlagAdditions(config) {
90
- var _a;
91
89
  const helpFlags = ['--help'];
92
- const additionalHelpFlags = (_a = config.pjson.oclif.additionalHelpFlags) !== null && _a !== void 0 ? _a : [];
90
+ const additionalHelpFlags = config.pjson.oclif.additionalHelpFlags ?? [];
93
91
  return [...new Set([...helpFlags, ...additionalHelpFlags]).values()];
94
92
  }
95
93
  exports.getHelpFlagAdditions = getHelpFlagAdditions;
@@ -160,6 +160,7 @@ export declare type EnumFlagOptions<T> = Partial<OptionFlag<T>> & {
160
160
  export declare type Flag<T> = BooleanFlag<T> | OptionFlag<T>;
161
161
  export declare type Input<TFlags extends FlagOutput> = {
162
162
  flags?: FlagInput<TFlags>;
163
+ globalFlags?: FlagInput<TFlags>;
163
164
  args?: ArgInput;
164
165
  strict?: boolean;
165
166
  context?: any;
package/lib/main.js CHANGED
@@ -25,8 +25,7 @@ const helpAddition = (argv, config) => {
25
25
  };
26
26
  exports.helpAddition = helpAddition;
27
27
  const versionAddition = (argv, config) => {
28
- var _a;
29
- const additionalVersionFlags = (_a = config === null || config === void 0 ? void 0 : config.pjson.oclif.additionalVersionFlags) !== null && _a !== void 0 ? _a : [];
28
+ const additionalVersionFlags = config?.pjson.oclif.additionalVersionFlags ?? [];
30
29
  const mergedVersionFlags = [...new Set(['--version', ...additionalVersionFlags]).values()];
31
30
  if (mergedVersionFlags.includes(argv[0]))
32
31
  return true;
@@ -35,14 +34,13 @@ const versionAddition = (argv, config) => {
35
34
  exports.versionAddition = versionAddition;
36
35
  // eslint-disable-next-line default-param-last
37
36
  async function run(argv = process.argv.slice(2), options) {
38
- var _a;
39
37
  // Handle the case when a file URL string or URL is passed in such as 'import.meta.url'; covert to file path.
40
38
  if (options && ((typeof options === 'string' && options.startsWith('file://')) || options instanceof url_2.URL)) {
41
39
  options = (0, url_1.fileURLToPath)(options);
42
40
  }
43
41
  // return Main.run(argv, options)
44
42
  const config = await config_1.Config.load(options || (module.parent && module.parent.parent && module.parent.parent.filename) || __dirname);
45
- if (config.topicSeparator !== ':' && !((_a = argv[0]) === null || _a === void 0 ? void 0 : _a.includes(':')))
43
+ if (config.topicSeparator !== ':' && !argv[0]?.includes(':'))
46
44
  argv = (0, help_1.standardizeIDFromArgv)(argv, config);
47
45
  let [id, ...argvSlice] = argv;
48
46
  // run init hook
@@ -121,7 +121,6 @@ class ModuleLoader {
121
121
  * @returns {{isESM: boolean, filePath: string}} An object including file path and whether the module is ESM.
122
122
  */
123
123
  static resolvePath(config, modulePath) {
124
- var _a, _b;
125
124
  let isESM;
126
125
  let filePath;
127
126
  try {
@@ -135,7 +134,7 @@ class ModuleLoader {
135
134
  if (fs.existsSync(filePath)) {
136
135
  fileExists = true;
137
136
  try {
138
- if ((_b = (_a = fs.lstatSync(filePath)) === null || _a === void 0 ? void 0 : _a.isDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)) {
137
+ if (fs.lstatSync(filePath)?.isDirectory?.()) {
139
138
  fileExists = false;
140
139
  isDirectory = true;
141
140
  }
@@ -6,7 +6,10 @@ export declare function build<T>(defaults: {
6
6
  } & Partial<OptionFlag<T>>): Definition<T>;
7
7
  export declare function build(defaults: Partial<OptionFlag<string>>): Definition<string>;
8
8
  export declare function boolean<T = boolean>(options?: Partial<BooleanFlag<T>>): BooleanFlag<T>;
9
- export declare const integer: Definition<number>;
9
+ export declare const integer: (opts?: {
10
+ min?: number;
11
+ max?: number;
12
+ } & Partial<OptionFlag<number>>) => OptionFlag<number | undefined>;
10
13
  export declare const directory: (opts?: {
11
14
  exists?: boolean;
12
15
  } & Partial<OptionFlag<string>>) => OptionFlag<string | undefined>;
@@ -26,13 +26,22 @@ function boolean(options = {}) {
26
26
  };
27
27
  }
28
28
  exports.boolean = boolean;
29
- exports.integer = build({
30
- parse: async (input) => {
31
- if (!/^-?\d+$/.test(input))
32
- throw new Error(`Expected an integer but received: ${input}`);
33
- return Number.parseInt(input, 10);
34
- },
35
- });
29
+ const integer = (opts = {}) => {
30
+ return build({
31
+ ...opts,
32
+ parse: async (input) => {
33
+ if (!/^-?\d+$/.test(input))
34
+ throw new Error(`Expected an integer but received: ${input}`);
35
+ const num = Number.parseInt(input, 10);
36
+ if (opts.min !== undefined && num < opts.min)
37
+ throw new Error(`Expected an integer greater than or equal to ${opts.min} but received: ${input}`);
38
+ if (opts.max !== undefined && num > opts.max)
39
+ throw new Error(`Expected an integer less than or equal to ${opts.max} but received: ${input}`);
40
+ return num;
41
+ },
42
+ })();
43
+ };
44
+ exports.integer = integer;
36
45
  const directory = (opts = {}) => {
37
46
  return build({
38
47
  ...opts,
@@ -8,7 +8,10 @@ export { flagUsages } from './help';
8
8
  export declare function parse<TFlags, TArgs extends {
9
9
  [name: string]: string;
10
10
  }>(argv: string[], options: Input<TFlags>): Promise<ParserOutput<TFlags, TArgs>>;
11
- declare const boolean: typeof flags.boolean, integer: import("../interfaces").Definition<number>, url: import("../interfaces").Definition<import("url").URL>, directory: (opts?: {
11
+ declare const boolean: typeof flags.boolean, integer: (opts?: {
12
+ min?: number | undefined;
13
+ max?: number | undefined;
14
+ } & Partial<import("../interfaces").OptionFlag<number>>) => import("../interfaces").OptionFlag<number | undefined>, url: import("../interfaces").Definition<import("url").URL>, directory: (opts?: {
12
15
  exists?: boolean | undefined;
13
16
  } & Partial<import("../interfaces").OptionFlag<string>>) => import("../interfaces").OptionFlag<string | undefined>, file: (opts?: {
14
17
  exists?: boolean | undefined;
@@ -30,7 +30,6 @@ function validate(parse) {
30
30
  }
31
31
  }
32
32
  function validateAcrossFlags(flag) {
33
- var _a;
34
33
  const intersection = Object.entries(parse.input.flags)
35
34
  .map(entry => entry[0]) // array of flag names
36
35
  .filter(flagName => parse.output.flags[flagName] !== undefined) // with values
@@ -38,7 +37,7 @@ function validate(parse) {
38
37
  if (intersection.length === 0) {
39
38
  // the command's exactlyOne may or may not include itself, so we'll use Set to add + de-dupe
40
39
  throw new errors_1.CLIError(`Exactly one of the following must be provided: ${[
41
- ...new Set((_a = flag.exactlyOne) === null || _a === void 0 ? void 0 : _a.map(flag => `--${flag}`)),
40
+ ...new Set(flag.exactlyOne?.map(flag => `--${flag}`)),
42
41
  ].join(', ')}`);
43
42
  }
44
43
  }
package/lib/util.js CHANGED
@@ -40,8 +40,7 @@ function castArray(input) {
40
40
  }
41
41
  exports.castArray = castArray;
42
42
  function isProd() {
43
- var _a;
44
- return !['development', 'test'].includes((_a = process.env.NODE_ENV) !== null && _a !== void 0 ? _a : '');
43
+ return !['development', 'test'].includes(process.env.NODE_ENV ?? '');
45
44
  }
46
45
  exports.isProd = isProd;
47
46
  function maxBy(arr, fn) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/core",
3
3
  "description": "base library for oclif CLIs",
4
- "version": "1.11.0",
4
+ "version": "1.13.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -77,7 +77,7 @@
77
77
  "typescript": "4.5.5"
78
78
  },
79
79
  "engines": {
80
- "node": ">=12.0.0"
80
+ "node": ">=14.0.0"
81
81
  },
82
82
  "files": [
83
83
  "/lib",