@oclif/core 3.10.4 → 3.10.6

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.
@@ -43,6 +43,7 @@ const os_1 = require("../util/os");
43
43
  const util_2 = require("../util/util");
44
44
  const cache_1 = __importDefault(require("./cache"));
45
45
  const plugin_loader_1 = __importDefault(require("./plugin-loader"));
46
+ const ts_node_1 = require("./ts-node");
46
47
  const util_3 = require("./util");
47
48
  // eslint-disable-next-line new-cap
48
49
  const debug = (0, util_3.Debug)();
@@ -458,7 +459,7 @@ class Config {
458
459
  const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `config.runHook#${p.name}(${hook})`);
459
460
  try {
460
461
  /* eslint-disable no-await-in-loop */
461
- const { filePath, isESM, module } = await (0, module_loader_1.loadWithData)(p, hook);
462
+ const { filePath, isESM, module } = await (0, module_loader_1.loadWithData)(p, await (0, ts_node_1.tsPath)(p.root, hook, p));
462
463
  debug('start', isESM ? '(import)' : '(require)', filePath);
463
464
  const result = timeout
464
465
  ? await withTimeout(timeout, search(module).call(context, { ...opts, config: this, context }))
@@ -56,6 +56,7 @@ class Plugin {
56
56
  alreadyLoaded = false;
57
57
  children = [];
58
58
  commandIDs = [];
59
+ // This will be initialized in the _manifest() method, which gets called in the load() method.
59
60
  commands;
60
61
  commandsDir;
61
62
  hasManifest = false;
@@ -88,7 +89,8 @@ class Plugin {
88
89
  plugin: this.name,
89
90
  });
90
91
  const fetch = async () => {
91
- if (!this.commandsDir)
92
+ const commandsDir = await this.getCommandsDir();
93
+ if (!commandsDir)
92
94
  return;
93
95
  let module;
94
96
  let isESM;
@@ -97,7 +99,7 @@ class Plugin {
97
99
  ;
98
100
  ({ filePath, isESM, module } = cachedCommandCanBeUsed(this.manifest, id)
99
101
  ? await (0, module_loader_1.loadWithDataFromManifest)(this.manifest.commands[id], this.root)
100
- : await (0, module_loader_1.loadWithData)(this, (0, node_path_1.join)(this.commandsDir ?? this.pjson.oclif.commands, ...id.split(':'))));
102
+ : await (0, module_loader_1.loadWithData)(this, (0, node_path_1.join)(commandsDir ?? this.pjson.oclif.commands, ...id.split(':'))));
101
103
  this._debug(isESM ? '(import)' : '(require)', filePath);
102
104
  }
103
105
  catch (error) {
@@ -142,8 +144,6 @@ class Plugin {
142
144
  const pjsonPath = (0, node_path_1.join)(root, 'package.json');
143
145
  if (!this.name)
144
146
  throw new errors_1.CLIError(`no name in ${pjsonPath}`);
145
- if (!(0, util_1.isProd)() && !this.pjson.files)
146
- this.warn(`files attribute must be specified in ${pjsonPath}`);
147
147
  // eslint-disable-next-line new-cap
148
148
  this._debug = (0, util_2.Debug)(this.name);
149
149
  this.version = this.pjson.version;
@@ -153,12 +153,7 @@ class Plugin {
153
153
  else {
154
154
  this.pjson.oclif = this.pjson['cli-engine'] || {};
155
155
  }
156
- this.commandsDir = await this.getCommandsDir();
157
- this.commandIDs = await this.getCommandIDs();
158
- this.hooks = Object.fromEntries(await Promise.all(Object.entries(this.pjson.oclif.hooks ?? {}).map(async ([k, v]) => [
159
- k,
160
- await Promise.all((0, util_1.castArray)(v).map(async (i) => (0, ts_node_1.tsPath)(this.root, i, this))),
161
- ])));
156
+ this.hooks = Object.fromEntries(Object.entries(this.pjson.oclif.hooks ?? {}).map(([k, v]) => [k, (0, util_1.castArray)(v)]));
162
157
  this.manifest = await this._manifest();
163
158
  this.commands = Object.entries(this.manifest.commands)
164
159
  .map(([id, c]) => ({
@@ -202,9 +197,11 @@ class Plugin {
202
197
  if (manifest) {
203
198
  marker?.addDetails({ commandCount: Object.keys(manifest.commands).length, fromCache: true });
204
199
  marker?.stop();
200
+ this.commandIDs = Object.keys(manifest.commands);
205
201
  return manifest;
206
202
  }
207
203
  }
204
+ this.commandIDs = await this.getCommandIDs();
208
205
  const manifest = {
209
206
  commands: (await Promise.all(this.commandIDs.map(async (id) => {
210
207
  try {
@@ -249,11 +246,12 @@ class Plugin {
249
246
  return err;
250
247
  }
251
248
  async getCommandIDs() {
252
- if (!this.commandsDir)
249
+ const commandsDir = await this.getCommandsDir();
250
+ if (!commandsDir)
253
251
  return [];
254
252
  const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, `plugin.getCommandIDs#${this.name}`, { plugin: this.name });
255
- this._debug(`loading IDs from ${this.commandsDir}`);
256
- const files = await (0, globby_1.default)(GLOB_PATTERNS, { cwd: this.commandsDir });
253
+ this._debug(`loading IDs from ${commandsDir}`);
254
+ const files = await (0, globby_1.default)(GLOB_PATTERNS, { cwd: commandsDir });
257
255
  const ids = processCommandIds(files);
258
256
  this._debug('found commands', ids);
259
257
  marker?.addDetails({ count: ids.length });
@@ -261,7 +259,8 @@ class Plugin {
261
259
  return ids;
262
260
  }
263
261
  async getCommandsDir() {
264
- return (0, ts_node_1.tsPath)(this.root, this.pjson.oclif.commands, this);
262
+ this.commandsDir = await (0, ts_node_1.tsPath)(this.root, this.pjson.oclif.commands, this);
263
+ return this.commandsDir;
265
264
  }
266
265
  warn(err, scope) {
267
266
  if (this.warned)
@@ -176,7 +176,7 @@ async function tsPath(root, orig, plugin) {
176
176
  }
177
177
  const isProduction = (0, util_1.isProd)();
178
178
  if (cannotTranspileEsm(rootPlugin, plugin, isProduction)) {
179
- debug(`Skipping ts-node registration for ${root} because it's an ESM module (NODE_ENV: ${process.env.NODE_ENV}, root plugin module type: ${rootPlugin?.moduleType})))`);
179
+ debug(`Skipping ts-node registration for ${root} because it's an ESM module (NODE_ENV: ${process.env.NODE_ENV}, root plugin module type: ${rootPlugin?.moduleType})`);
180
180
  if (plugin?.type === 'link')
181
181
  (0, errors_1.memoizedWarn)(`${plugin?.name} is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.`);
182
182
  return orig;
@@ -25,12 +25,13 @@ function* up(from) {
25
25
  async function findPluginRoot(root, name) {
26
26
  // If we know the plugin name then we just need to traverse the file
27
27
  // system until we find the directory that matches the plugin name.
28
+ debug.extend(name ?? 'root-plugin')(`Finding root starting at ${root}`);
28
29
  if (name) {
29
- debug.extend(name)(`Finding root starting at ${root}`);
30
30
  for (const next of up(root)) {
31
- debug.extend(name)(`Checking ${next}`);
32
- if (next.endsWith((0, node_path_1.basename)(name)))
31
+ if (next.endsWith((0, node_path_1.basename)(name))) {
32
+ debug.extend(name)('Found root based on plugin name!');
33
33
  return next;
34
+ }
34
35
  }
35
36
  }
36
37
  // If there's no plugin name (typically just the root plugin), then we need
@@ -43,9 +44,11 @@ async function findPluginRoot(root, name) {
43
44
  }
44
45
  try {
45
46
  const cur = (0, node_path_1.join)(next, 'package.json');
46
- debug.extend('root-plugin')(`Checking ${cur}`);
47
- if (await (0, fs_1.safeReadJson)(cur))
47
+ debug.extend(name ?? 'root-plugin')(`Checking ${cur}`);
48
+ if (await (0, fs_1.safeReadJson)(cur)) {
49
+ debug.extend(name ?? 'root-plugin')('Found root by traversing up from starting point!');
48
50
  return (0, node_path_1.dirname)(cur);
51
+ }
49
52
  }
50
53
  catch { }
51
54
  }
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": "3.10.4",
4
+ "version": "3.10.6",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {