@oclif/core 5.1.8 → 5.1.9

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.
@@ -242,7 +242,11 @@ class Config {
242
242
  displayWarnings();
243
243
  (0, logger_1.setLogger)(this.options);
244
244
  const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'config.load');
245
- this.pluginLoader = new plugin_loader_1.default({ plugins: this.options.plugins, root: this.options.root });
245
+ this.pluginLoader = new plugin_loader_1.default({
246
+ ignoreManifest: this.options.ignoreManifest,
247
+ plugins: this.options.plugins,
248
+ root: this.options.root,
249
+ });
246
250
  this.rootPlugin = await this.pluginLoader.loadRoot({ pjson: this.options.pjson });
247
251
  // Cache the root plugin so that we can reference it later when determining if
248
252
  // we should skip ts-node registration for an ESM plugin.
@@ -1,6 +1,7 @@
1
1
  import { type PJSON } from '../interfaces';
2
2
  import { type Plugin as IPlugin } from '../interfaces/plugin';
3
3
  type PluginLoaderOptions = {
4
+ ignoreManifest?: boolean | undefined;
4
5
  plugins?: IPlugin[] | PluginsMap | undefined;
5
6
  root: string;
6
7
  };
@@ -40,7 +40,12 @@ class PluginLoader {
40
40
  }
41
41
  else {
42
42
  const marker = performance_1.Performance.mark(performance_1.OCLIF_MARKER_OWNER, 'plugin.load#root');
43
- rootPlugin = new plugin_1.Plugin({ isRoot: true, pjson, root: this.options.root });
43
+ rootPlugin = new plugin_1.Plugin({
44
+ ignoreManifest: this.options.ignoreManifest,
45
+ isRoot: true,
46
+ pjson,
47
+ root: this.options.root,
48
+ });
44
49
  await rootPlugin.load();
45
50
  marker?.addDetails({
46
51
  commandCount: rootPlugin.commands.length,
@@ -118,6 +123,7 @@ class PluginLoader {
118
123
  try {
119
124
  const name = typeof plugin === 'string' ? plugin : plugin.name;
120
125
  const opts = {
126
+ ignoreManifest: this.options.ignoreManifest,
121
127
  name,
122
128
  root,
123
129
  type,
package/lib/execute.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- import { type LoadOptions } from './interfaces';
1
+ import type { LoadOptions, Options } from './interfaces';
2
+ type ExecuteOptions = Omit<Options, 'root'> & {
3
+ root?: string;
4
+ };
2
5
  /**
3
6
  * Load and run oclif CLI
4
7
  *
@@ -36,9 +39,15 @@ import { type LoadOptions } from './interfaces';
36
39
  * })()
37
40
  * ```
38
41
  */
39
- export declare function execute(options: {
42
+ type ExecuteArguments = {
40
43
  args?: string[];
41
44
  development?: boolean;
45
+ };
46
+ export declare function execute(options: (ExecuteArguments & {
47
+ dir: string;
48
+ loadOptions?: LoadOptions | ExecuteOptions;
49
+ }) | (ExecuteArguments & {
42
50
  dir?: string;
43
- loadOptions?: LoadOptions;
44
- }): Promise<unknown>;
51
+ loadOptions: Exclude<LoadOptions, undefined>;
52
+ })): Promise<unknown>;
53
+ export {};
package/lib/execute.js CHANGED
@@ -1,48 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.execute = execute;
4
+ const node_url_1 = require("node:url");
4
5
  const errors_1 = require("./errors");
5
6
  const handle_1 = require("./errors/handle");
6
7
  const flush_1 = require("./flush");
7
8
  const main_1 = require("./main");
8
9
  const settings_1 = require("./settings");
9
- /**
10
- * Load and run oclif CLI
11
- *
12
- * @example For ESM dev.js
13
- * ```
14
- * #!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
15
- * import { execute } from '@oclif/core'
16
- *
17
- * await execute({development: true, dir: import.meta.url})
18
- * ```
19
- *
20
- * @example For ESM run.js
21
- * ```
22
- * #!/usr/bin/env node
23
- * import { execute } from '@oclif/core'
24
- *
25
- * await execute({dir: import.meta.url})
26
- * ```
27
- *
28
- * @example For CJS dev.js
29
- * ```
30
- * #!/usr/bin/env ts-node
31
- * void (async () => {
32
- * const oclif = await import('@oclif/core')
33
- * await oclif.execute({development: true, dir: __dirname})
34
- * })()
35
- * ```
36
- *
37
- * @example For CJS run.js
38
- * ```
39
- * #!/usr/bin/env node
40
- * void (async () => {
41
- * const oclif = await import('@oclif/core')
42
- * await oclif.execute({dir: __dirname})
43
- * })()
44
- * ```
45
- */
10
+ function isOptions(loadOptions) {
11
+ return typeof loadOptions === 'object' && loadOptions !== null && !('runCommand' in loadOptions);
12
+ }
13
+ function normalizeLoadOptions(dir, loadOptions) {
14
+ if (!loadOptions || !isOptions(loadOptions))
15
+ return loadOptions ?? dir;
16
+ const root = loadOptions.root ?? (dir?.startsWith('file://') ? (0, node_url_1.fileURLToPath)(dir) : dir);
17
+ if (!root)
18
+ throw new errors_1.CLIError('dir or loadOptions.root is required.');
19
+ return { ...loadOptions, root };
20
+ }
46
21
  async function execute(options) {
47
22
  if (!options.dir && !options.loadOptions) {
48
23
  throw new errors_1.CLIError('dir or loadOptions is required.');
@@ -52,10 +27,12 @@ async function execute(options) {
52
27
  process.env.NODE_ENV = 'development';
53
28
  settings_1.settings.debug = true;
54
29
  }
55
- return (0, main_1.run)(options.args ?? process.argv.slice(2), options.loadOptions ?? options.dir)
56
- .then(async (result) => {
57
- (0, flush_1.flush)();
30
+ try {
31
+ const result = await (0, main_1.run)(options.args ?? process.argv.slice(2), normalizeLoadOptions(options.dir, options.loadOptions));
32
+ await (0, flush_1.flush)();
58
33
  return result;
59
- })
60
- .catch(async (error) => (0, handle_1.handle)(error));
34
+ }
35
+ catch (error) {
36
+ return (0, handle_1.handle)(error instanceof Error ? error : new Error(String(error)));
37
+ }
61
38
  }
@@ -42,7 +42,9 @@ const readStdin = async () => {
42
42
  const lines = [];
43
43
  const ac = new AbortController();
44
44
  const { signal } = ac;
45
- const timeout = setTimeout(() => { ac.abort(); }, Number(process.env.OCLIF_STDIN_TIMEOUT_MS) || 10);
45
+ const timeout = setTimeout(() => {
46
+ ac.abort();
47
+ }, Number(process.env.OCLIF_STDIN_TIMEOUT_MS) || 10);
46
48
  const rl = (0, node_readline_1.createInterface)({
47
49
  input: stdin,
48
50
  output: stdout,
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": "5.1.8",
4
+ "version": "5.1.9",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {