@oclif/core 2.11.11 → 2.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.
@@ -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,24 @@ 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
+ if (Array.isArray(options.config.plugins) && Array.isArray(this.plugins)) {
76
+ // incoming config is v2 with plugins array and this config is v2 with plugins array
77
+ Object.assign(this, options.config);
78
+ }
79
+ else if (Array.isArray(options.config.plugins) && !Array.isArray(this.plugins)) {
80
+ // incoming config is v2 with plugins array and this config is v3 with plugin Map
81
+ Object.assign(this, options.config, { plugins: new Map(options.config.plugins.map(p => [p.name, p])) });
82
+ }
83
+ else if (!Array.isArray(options.config.plugins) && Array.isArray(this.plugins)) {
84
+ // incoming config is v3 with plugin Map and this config is v2 with plugins array
85
+ Object.assign(this, options.config, { plugins: options.config.getPluginsList() });
86
+ }
87
+ else {
88
+ // incoming config is v3 with plugin Map and this config is v3 with plugin Map
89
+ Object.assign(this, options.config);
90
+ }
91
+ }
72
92
  }
73
93
  static async load(opts = module.filename || __dirname) {
74
94
  // Handle the case when a file URL string is passed in such as 'import.meta.url'; covert to file path.
@@ -77,14 +97,33 @@ class Config {
77
97
  }
78
98
  if (typeof opts === 'string')
79
99
  opts = { root: opts };
80
- if (isConfig(opts))
100
+ if (isConfig(opts)) {
101
+ const currentConfigBase = BASE.replace('@oclif/core@', '');
102
+ const incomingConfigBase = opts._base.replace('@oclif/core@', '');
103
+ /**
104
+ * Reload the Config based on the version required by the command.
105
+ * This is needed because the command is given the Config instantiated
106
+ * by the root plugin, which may be a different version than the one
107
+ * required by the command.
108
+ *
109
+ * Doing this ensures that the command can freely use any method on Config that
110
+ * exists in the version of Config required by the command but may not exist on the
111
+ * root's instance of Config.
112
+ */
113
+ if ((0, semver_1.lt)(incomingConfigBase, currentConfigBase)) {
114
+ debug(`reloading config from ${opts._base} to ${BASE}`);
115
+ return new Config({ ...opts.options, config: opts });
116
+ }
81
117
  return opts;
118
+ }
82
119
  const config = new Config(opts);
83
120
  await config.load();
84
121
  return config;
85
122
  }
86
123
  // eslint-disable-next-line complexity
87
124
  async load() {
125
+ if (this.options.config)
126
+ return;
88
127
  settings_1.settings.performanceEnabled = (settings_1.settings.performanceEnabled === undefined ? this.options.enablePerf : settings_1.settings.performanceEnabled) ?? false;
89
128
  const plugin = new Plugin.Plugin({ root: this.options.root });
90
129
  await plugin.load();
@@ -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.11",
4
+ "version": "2.13.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {