@oclif/core 2.11.10 → 2.12.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.
@@ -17,9 +17,11 @@ const performance_1 = require("../performance");
17
17
  const settings_1 = require("../settings");
18
18
  const node_os_1 = require("node:os");
19
19
  const node_path_1 = require("node:path");
20
+ const semver_1 = require("semver");
20
21
  // eslint-disable-next-line new-cap
21
22
  const debug = (0, util_2.Debug)();
22
23
  const _pjson = (0, util_3.requireJson)(__dirname, '..', '..', 'package.json');
24
+ const BASE = `${_pjson.name}@${_pjson.version}`;
23
25
  function channelFromVersion(version) {
24
26
  const m = version.match(/[^-]+(?:-([^.]+))?/);
25
27
  return (m && m[1]) || 'stable';
@@ -60,7 +62,7 @@ class Permutations extends Map {
60
62
  class Config {
61
63
  constructor(options) {
62
64
  this.options = options;
63
- this._base = `${_pjson.name}@${_pjson.version}`;
65
+ this._base = BASE;
64
66
  this.debug = 0;
65
67
  this.plugins = [];
66
68
  this.topicSeparator = ':';
@@ -69,6 +71,8 @@ class Config {
69
71
  this.topicPermutations = new Permutations();
70
72
  this._commands = new Map();
71
73
  this._topics = new Map();
74
+ if (options.config)
75
+ Object.assign(this, options.config);
72
76
  }
73
77
  static async load(opts = module.filename || __dirname) {
74
78
  // Handle the case when a file URL string is passed in such as 'import.meta.url'; covert to file path.
@@ -77,14 +81,33 @@ class Config {
77
81
  }
78
82
  if (typeof opts === 'string')
79
83
  opts = { root: opts };
80
- if (isConfig(opts))
84
+ if (isConfig(opts)) {
85
+ const currentConfigBase = BASE.replace('@oclif/core@', '');
86
+ const incomingConfigBase = opts._base.replace('@oclif/core@', '');
87
+ /**
88
+ * Reload the Config based on the version required by the command.
89
+ * This is needed because the command is given the Config instantiated
90
+ * by the root plugin, which may be a different version than the one
91
+ * required by the command.
92
+ *
93
+ * Doing this ensures that the command can freely use any method on Config that
94
+ * exists in the version of Config required by the command but may not exist on the
95
+ * root's instance of Config.
96
+ */
97
+ if ((0, semver_1.lt)(incomingConfigBase, currentConfigBase)) {
98
+ debug(`reloading config from ${opts._base} to ${BASE}`);
99
+ return new Config({ ...opts.options, config: opts });
100
+ }
81
101
  return opts;
102
+ }
82
103
  const config = new Config(opts);
83
104
  await config.load();
84
105
  return config;
85
106
  }
86
107
  // eslint-disable-next-line complexity
87
108
  async load() {
109
+ if (this.options.config)
110
+ return;
88
111
  settings_1.settings.performanceEnabled = (settings_1.settings.performanceEnabled === undefined ? this.options.enablePerf : settings_1.settings.performanceEnabled) ?? false;
89
112
  const plugin = new Plugin.Plugin({ root: this.options.root });
90
113
  await plugin.load();
package/lib/flags.js CHANGED
@@ -84,7 +84,8 @@ const help = (opts = {}) => {
84
84
  description: 'Show CLI help.',
85
85
  ...opts,
86
86
  parse: async (_, cmd) => {
87
- new help_1.Help(cmd.config).showHelp(cmd.id ? [cmd.id, ...cmd.argv] : cmd.argv);
87
+ const Help = await (0, help_1.loadHelpClass)(cmd.config);
88
+ await new Help(cmd.config, cmd.config.pjson.helpOptions).showHelp(cmd.id ? [cmd.id, ...cmd.argv] : cmd.argv);
88
89
  cmd.exit(0);
89
90
  },
90
91
  });
@@ -1,3 +1,4 @@
1
+ import { Config } from './config';
1
2
  import { Command } from '../command';
2
3
  import { PJSON } from './pjson';
3
4
  import { Topic } from './topic';
@@ -18,6 +19,7 @@ export interface Options extends PluginOptions {
18
19
  channel?: string;
19
20
  version?: string;
20
21
  enablePerf?: boolean;
22
+ config?: Config;
21
23
  }
22
24
  export interface Plugin {
23
25
  /**
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": "2.11.10",
4
+ "version": "2.12.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {