@oclif/core 3.3.3-dev.0 → 3.4.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.
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ActionBase = void 0;
4
4
  const node_util_1 = require("node:util");
5
5
  const util_1 = require("../../util/util");
6
- const stream_1 = require("../stream");
7
6
  class ActionBase {
8
7
  std = 'stderr';
9
8
  stdmocks;
10
9
  type;
11
10
  stdmockOrigs = {
12
- stderr: stream_1.stderr.write,
13
- stdout: stream_1.stdout.write,
11
+ stderr: process.stderr.write,
12
+ stdout: process.stdout.write,
14
13
  };
15
14
  get output() {
16
15
  return this.globals.output;
@@ -125,15 +124,15 @@ class ActionBase {
125
124
  if (this.stdmocks)
126
125
  return;
127
126
  this.stdmockOrigs = {
128
- stderr: stream_1.stderr.write,
129
- stdout: stream_1.stdout.write,
127
+ stderr: process.stderr.write,
128
+ stdout: process.stdout.write,
130
129
  };
131
130
  this.stdmocks = [];
132
- stream_1.stdout.write = (...args) => {
131
+ process.stdout.write = (...args) => {
133
132
  this.stdmocks.push(['stdout', args]);
134
133
  return true;
135
134
  };
136
- stream_1.stderr.write = (...args) => {
135
+ process.stderr.write = (...args) => {
137
136
  this.stdmocks.push(['stderr', args]);
138
137
  return true;
139
138
  };
@@ -143,8 +142,8 @@ class ActionBase {
143
142
  return;
144
143
  // this._write('stderr', '\nresetstdmock\n\n\n')
145
144
  delete this.stdmocks;
146
- stream_1.stdout.write = this.stdmockOrigs.stdout;
147
- stream_1.stderr.write = this.stdmockOrigs.stderr;
145
+ process.stdout.write = this.stdmockOrigs.stdout;
146
+ process.stderr.write = this.stdmockOrigs.stderr;
148
147
  }
149
148
  }
150
149
  catch (error) {
@@ -161,11 +160,11 @@ class ActionBase {
161
160
  _write(std, s) {
162
161
  switch (std) {
163
162
  case 'stdout': {
164
- this.stdmockOrigs.stdout.apply(stream_1.stdout, (0, util_1.castArray)(s));
163
+ this.stdmockOrigs.stdout.apply(process.stdout, (0, util_1.castArray)(s));
165
164
  break;
166
165
  }
167
166
  case 'stderr': {
168
- this.stdmockOrigs.stderr.apply(stream_1.stderr, (0, util_1.castArray)(s));
167
+ this.stdmockOrigs.stderr.apply(process.stderr, (0, util_1.castArray)(s));
169
168
  break;
170
169
  }
171
170
  default: {
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.flush = void 0;
4
4
  const errors_1 = require("../errors");
5
- const stream_1 = require("./stream");
6
5
  function timeout(p, ms) {
7
6
  function wait(ms, unref = false) {
8
7
  return new Promise((resolve) => {
@@ -15,9 +14,9 @@ function timeout(p, ms) {
15
14
  }
16
15
  async function _flush() {
17
16
  const p = new Promise((resolve) => {
18
- stream_1.stdout.once('drain', () => resolve(null));
17
+ process.stdout.once('drain', () => resolve(null));
19
18
  });
20
- const flushed = stream_1.stdout.write('');
19
+ const flushed = process.stdout.write('');
21
20
  if (flushed)
22
21
  return;
23
22
  return p;
@@ -1,11 +1,10 @@
1
1
  import * as Errors from '../errors';
2
2
  import { ActionBase } from './action/base';
3
- import { Config } from './config';
4
3
  import * as uxPrompt from './prompt';
5
4
  import * as styled from './styled';
6
5
  import uxWait from './wait';
7
6
  export declare class ux {
8
- static config: Config;
7
+ static config: import("./config").Config;
9
8
  static get action(): ActionBase;
10
9
  static annotation(text: string, annotation: string): void;
11
10
  /**
@@ -18,6 +17,7 @@ export declare class ux {
18
17
  static flush(ms?: number): Promise<void>;
19
18
  static info(format: string, ...args: string[]): void;
20
19
  static log(format?: string, ...args: string[]): void;
20
+ static logToStderr(format?: string, ...args: string[]): void;
21
21
  static get progress(): typeof styled.progress;
22
22
  static get prompt(): typeof uxPrompt.prompt;
23
23
  static styledHeader(header: string): void;
@@ -29,11 +29,12 @@ export declare class ux {
29
29
  static url(text: string, uri: string, params?: {}): void;
30
30
  static get wait(): typeof uxWait;
31
31
  }
32
- declare const action: ActionBase, annotation: typeof ux.annotation, anykey: typeof uxPrompt.anykey, confirm: typeof uxPrompt.confirm, debug: typeof ux.debug, done: typeof ux.done, flush: typeof ux.flush, info: typeof ux.info, log: typeof ux.log, progress: typeof styled.progress, prompt: typeof uxPrompt.prompt, styledHeader: typeof ux.styledHeader, styledJSON: typeof ux.styledJSON, styledObject: typeof ux.styledObject, table: typeof styled.Table.table, trace: typeof ux.trace, tree: typeof styled.tree, url: typeof ux.url, wait: (ms?: number) => Promise<void>;
32
+ declare const action: ActionBase, annotation: typeof ux.annotation, anykey: typeof uxPrompt.anykey, confirm: typeof uxPrompt.confirm, debug: typeof ux.debug, done: typeof ux.done, flush: typeof ux.flush, info: typeof ux.info, log: typeof ux.log, logToStderr: typeof ux.logToStderr, progress: typeof styled.progress, prompt: typeof uxPrompt.prompt, styledHeader: typeof ux.styledHeader, styledJSON: typeof ux.styledJSON, styledObject: typeof ux.styledObject, table: typeof styled.Table.table, trace: typeof ux.trace, tree: typeof styled.tree, url: typeof ux.url, wait: (ms?: number) => Promise<void>;
33
33
  declare const error: typeof Errors.error, exit: typeof Errors.exit, warn: typeof Errors.warn;
34
- export { action, annotation, anykey, confirm, debug, done, error, exit, flush, info, log, progress, prompt, styledHeader, styledJSON, styledObject, table, trace, tree, url, wait, warn, };
34
+ export { action, annotation, anykey, confirm, debug, done, error, exit, flush, info, log, logToStderr, progress, prompt, styledHeader, styledJSON, styledObject, table, trace, tree, url, wait, warn, };
35
35
  export { ActionBase } from './action/base';
36
36
  export { Config, config } from './config';
37
37
  export { ExitError } from './exit';
38
38
  export { IPromptOptions } from './prompt';
39
+ export { makeStubs } from './stub';
39
40
  export { Table } from './styled';
@@ -26,16 +26,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Table = exports.ExitError = exports.config = exports.Config = exports.ActionBase = exports.warn = exports.wait = exports.url = exports.tree = exports.trace = exports.table = exports.styledObject = exports.styledJSON = exports.styledHeader = exports.prompt = exports.progress = exports.log = exports.info = exports.flush = exports.exit = exports.error = exports.done = exports.debug = exports.confirm = exports.anykey = exports.annotation = exports.action = exports.ux = void 0;
29
+ exports.Table = exports.makeStubs = exports.ExitError = exports.config = exports.Config = exports.ActionBase = exports.warn = exports.wait = exports.url = exports.tree = exports.trace = exports.table = exports.styledObject = exports.styledJSON = exports.styledHeader = exports.prompt = exports.progress = exports.logToStderr = exports.log = exports.info = exports.flush = exports.exit = exports.error = exports.done = exports.debug = exports.confirm = exports.anykey = exports.annotation = exports.action = exports.ux = void 0;
30
30
  const chalk_1 = __importDefault(require("chalk"));
31
31
  const node_util_1 = require("node:util");
32
32
  const Errors = __importStar(require("../errors"));
33
33
  const config_1 = require("./config");
34
34
  const flush_1 = require("./flush");
35
35
  const uxPrompt = __importStar(require("./prompt"));
36
- const stream_1 = require("./stream");
37
36
  const styled = __importStar(require("./styled"));
38
37
  const wait_1 = __importDefault(require("./wait"));
38
+ const write_1 = __importDefault(require("./write"));
39
39
  const hyperlinker = require('hyperlinker');
40
40
  class ux {
41
41
  static config = config_1.config;
@@ -63,7 +63,7 @@ class ux {
63
63
  }
64
64
  static debug(format, ...args) {
65
65
  if (['debug', 'trace'].includes(this.config.outputLevel)) {
66
- stream_1.stdout.write((0, node_util_1.format)(format, ...args) + '\n');
66
+ this.info((0, node_util_1.format)(format, ...args) + '\n');
67
67
  }
68
68
  }
69
69
  static async done() {
@@ -73,11 +73,14 @@ class ux {
73
73
  await (0, flush_1.flush)(ms);
74
74
  }
75
75
  static info(format, ...args) {
76
- stream_1.stdout.write((0, node_util_1.format)(format, ...args) + '\n');
76
+ write_1.default.stdout((0, node_util_1.format)(format, ...args) + '\n');
77
77
  }
78
78
  static log(format, ...args) {
79
79
  this.info(format || '', ...args);
80
80
  }
81
+ static logToStderr(format, ...args) {
82
+ write_1.default.stderr((0, node_util_1.format)(format, ...args) + '\n');
83
+ }
81
84
  static get progress() {
82
85
  return styled.progress;
83
86
  }
@@ -90,7 +93,7 @@ class ux {
90
93
  static styledJSON(obj) {
91
94
  const json = JSON.stringify(obj, null, 2);
92
95
  if (!chalk_1.default.level) {
93
- info(json);
96
+ this.info(json);
94
97
  return;
95
98
  }
96
99
  const cardinal = require('cardinal');
@@ -105,7 +108,7 @@ class ux {
105
108
  }
106
109
  static trace(format, ...args) {
107
110
  if (this.config.outputLevel === 'trace') {
108
- stream_1.stdout.write((0, node_util_1.format)(format, ...args) + '\n');
111
+ this.info((0, node_util_1.format)(format, ...args) + '\n');
109
112
  }
110
113
  }
111
114
  static get tree() {
@@ -125,7 +128,7 @@ class ux {
125
128
  }
126
129
  }
127
130
  exports.ux = ux;
128
- const { action, annotation, anykey, confirm, debug, done, flush, info, log, progress, prompt, styledHeader, styledJSON, styledObject, table, trace, tree, url, wait, } = ux;
131
+ const { action, annotation, anykey, confirm, debug, done, flush, info, log, logToStderr, progress, prompt, styledHeader, styledJSON, styledObject, table, trace, tree, url, wait, } = ux;
129
132
  exports.action = action;
130
133
  exports.annotation = annotation;
131
134
  exports.anykey = anykey;
@@ -135,6 +138,7 @@ exports.done = done;
135
138
  exports.flush = flush;
136
139
  exports.info = info;
137
140
  exports.log = log;
141
+ exports.logToStderr = logToStderr;
138
142
  exports.progress = progress;
139
143
  exports.prompt = prompt;
140
144
  exports.styledHeader = styledHeader;
@@ -171,5 +175,7 @@ Object.defineProperty(exports, "Config", { enumerable: true, get: function () {
171
175
  Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_2.config; } });
172
176
  var exit_1 = require("./exit");
173
177
  Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_1.ExitError; } });
178
+ var stub_1 = require("./stub");
179
+ Object.defineProperty(exports, "makeStubs", { enumerable: true, get: function () { return stub_1.makeStubs; } });
174
180
  var styled_1 = require("./styled");
175
181
  Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return styled_1.Table; } });
@@ -30,7 +30,6 @@ exports.anykey = exports.confirm = exports.prompt = void 0;
30
30
  const chalk_1 = __importDefault(require("chalk"));
31
31
  const Errors = __importStar(require("../errors"));
32
32
  const config_1 = require("./config");
33
- const stream_1 = require("./stream");
34
33
  function normal(options, retries = 100) {
35
34
  if (retries < 0)
36
35
  throw new Error('no input');
@@ -44,7 +43,7 @@ function normal(options, retries = 100) {
44
43
  timer.unref();
45
44
  }
46
45
  process.stdin.setEncoding('utf8');
47
- stream_1.stderr.write(options.prompt);
46
+ process.stderr.write(options.prompt);
48
47
  process.stdin.resume();
49
48
  process.stdin.once('data', (b) => {
50
49
  if (timer)
@@ -83,7 +82,7 @@ async function single(options) {
83
82
  }
84
83
  function replacePrompt(prompt) {
85
84
  const ansiEscapes = require('ansi-escapes');
86
- stream_1.stderr.write(ansiEscapes.cursorHide +
85
+ process.stderr.write(ansiEscapes.cursorHide +
87
86
  ansiEscapes.cursorUp(1) +
88
87
  ansiEscapes.cursorLeft +
89
88
  prompt +
@@ -176,7 +175,7 @@ async function anykey(message) {
176
175
  }
177
176
  const char = await prompt(message, { required: false, type: 'single' });
178
177
  if (tty)
179
- stream_1.stderr.write('\n');
178
+ process.stderr.write('\n');
180
179
  if (char === 'q')
181
180
  Errors.error('quit');
182
181
  if (char === '\u0003')
@@ -12,6 +12,12 @@ declare class Stream {
12
12
  read(): boolean;
13
13
  write(data: string): boolean;
14
14
  }
15
+ /**
16
+ * @deprecated Use process.stdout directly. This will be removed in the next major version
17
+ */
15
18
  export declare const stdout: Stream;
19
+ /**
20
+ * @deprecated Use process.stderr directly. This will be removed in the next major version
21
+ */
16
22
  export declare const stderr: Stream;
17
23
  export {};
@@ -33,5 +33,11 @@ class Stream {
33
33
  return process[this.channel].write(data);
34
34
  }
35
35
  }
36
+ /**
37
+ * @deprecated Use process.stdout directly. This will be removed in the next major version
38
+ */
36
39
  exports.stdout = new Stream('stdout');
40
+ /**
41
+ * @deprecated Use process.stderr directly. This will be removed in the next major version
42
+ */
37
43
  exports.stderr = new Stream('stderr');
@@ -0,0 +1,32 @@
1
+ import type { SinonSandbox, SinonStub } from 'sinon';
2
+ type Stubs = {
3
+ stderr: SinonStub;
4
+ stdout: SinonStub;
5
+ };
6
+ /**
7
+ * Create sinon stubs for writing to stdout and stderr.
8
+ *
9
+ * @example
10
+ * import {ux} from '@oclif/core'
11
+ *
12
+ * describe('example', () => {
13
+ * let sandbox: SinonSandbox
14
+ * let stubs: ReturnType<typeof ux.makeStubs>
15
+ *
16
+ * beforeEach(() => {
17
+ * sandbox = createSandbox()
18
+ * stubs = ux.makeStubs(sandbox)
19
+ * })
20
+ *
21
+ * afterEach(() => {
22
+ * sandbox.restore()
23
+ * })
24
+ *
25
+ * it('should log text to the console', () => {
26
+ * ux.log('Hello, world!')
27
+ * expect(stubs.stdout.firstCall.firstArg).to.equal('Hello, world!\n')
28
+ * })
29
+ * })
30
+ */
31
+ export declare function makeStubs(sandbox: SinonSandbox): Stubs;
32
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.makeStubs = void 0;
7
+ const write_1 = __importDefault(require("./write"));
8
+ /**
9
+ * Create sinon stubs for writing to stdout and stderr.
10
+ *
11
+ * @example
12
+ * import {ux} from '@oclif/core'
13
+ *
14
+ * describe('example', () => {
15
+ * let sandbox: SinonSandbox
16
+ * let stubs: ReturnType<typeof ux.makeStubs>
17
+ *
18
+ * beforeEach(() => {
19
+ * sandbox = createSandbox()
20
+ * stubs = ux.makeStubs(sandbox)
21
+ * })
22
+ *
23
+ * afterEach(() => {
24
+ * sandbox.restore()
25
+ * })
26
+ *
27
+ * it('should log text to the console', () => {
28
+ * ux.log('Hello, world!')
29
+ * expect(stubs.stdout.firstCall.firstArg).to.equal('Hello, world!\n')
30
+ * })
31
+ * })
32
+ */
33
+ function makeStubs(sandbox) {
34
+ return {
35
+ stderr: sandbox.stub(write_1.default, 'stderr'),
36
+ stdout: sandbox.stub(write_1.default, 'stdout'),
37
+ };
38
+ }
39
+ exports.makeStubs = makeStubs;
@@ -36,7 +36,7 @@ const string_width_1 = __importDefault(require("string-width"));
36
36
  const F = __importStar(require("../../flags"));
37
37
  const screen_1 = require("../../screen");
38
38
  const util_1 = require("../../util/util");
39
- const stream_1 = require("../stream");
39
+ const write_1 = __importDefault(require("../write"));
40
40
  class Table {
41
41
  data;
42
42
  columns;
@@ -68,7 +68,7 @@ class Table {
68
68
  'no-header': options['no-header'] ?? false,
69
69
  'no-truncate': options['no-truncate'] ?? false,
70
70
  output: csv ? 'csv' : output,
71
- printLine: printLine ?? ((s) => stream_1.stdout.write(s + '\n')),
71
+ printLine: printLine ?? ((s) => write_1.default.stdout(s + '\n')),
72
72
  rowStart: ' ',
73
73
  sort,
74
74
  title,
@@ -116,7 +116,7 @@ class Table {
116
116
  this.columns = this.filterColumnsFromHeaders(filters);
117
117
  }
118
118
  else if (!this.options.extended) {
119
- // show extented columns/properties
119
+ // show extended columns/properties
120
120
  this.columns = this.columns.filter((c) => !c.extended);
121
121
  }
122
122
  this.data = rows;
@@ -188,7 +188,7 @@ class Table {
188
188
  // truncation logic
189
189
  const shouldShorten = () => {
190
190
  // don't shorten if full mode
191
- if (options['no-truncate'] || (!stream_1.stdout.isTTY && !process.env.CLI_UX_SKIP_TTY_CHECK))
191
+ if (options['no-truncate'] || (!process.stdout.isTTY && !process.env.CLI_UX_SKIP_TTY_CHECK))
192
192
  return;
193
193
  // don't shorten if there is enough screen width
194
194
  const dataMaxWidth = (0, util_1.sumBy)(columns, (c) => c.width);
@@ -0,0 +1,5 @@
1
+ declare const _default: {
2
+ stderr: (msg: string) => void;
3
+ stdout: (msg: string) => void;
4
+ };
5
+ export default _default;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const stdout = (msg) => {
4
+ process.stdout.write(msg);
5
+ };
6
+ const stderr = (msg) => {
7
+ process.stderr.write(msg);
8
+ };
9
+ exports.default = {
10
+ stderr,
11
+ stdout,
12
+ };
package/lib/command.js CHANGED
@@ -31,7 +31,6 @@ const chalk_1 = __importDefault(require("chalk"));
31
31
  const node_url_1 = require("node:url");
32
32
  const node_util_1 = require("node:util");
33
33
  const cli_ux_1 = require("./cli-ux");
34
- const stream_1 = require("./cli-ux/stream");
35
34
  const config_1 = require("./config");
36
35
  const Errors = __importStar(require("./errors"));
37
36
  const util_1 = require("./help/util");
@@ -44,7 +43,7 @@ const pjson = (0, fs_1.requireJson)(__dirname, '..', 'package.json');
44
43
  * swallows stdout epipe errors
45
44
  * this occurs when stdout closes such as when piping to head
46
45
  */
47
- stream_1.stdout.on('error', (err) => {
46
+ process.stdout.on('error', (err) => {
48
47
  if (err && err.code === 'EPIPE')
49
48
  return;
50
49
  throw err;
@@ -223,7 +222,7 @@ class Command {
223
222
  log(message = '', ...args) {
224
223
  if (!this.jsonEnabled()) {
225
224
  message = typeof message === 'string' ? message : (0, node_util_1.inspect)(message);
226
- stream_1.stdout.write((0, node_util_1.format)(message, ...args) + '\n');
225
+ cli_ux_1.ux.info(message, ...args);
227
226
  }
228
227
  }
229
228
  logJson(json) {
@@ -232,7 +231,7 @@ class Command {
232
231
  logToStderr(message = '', ...args) {
233
232
  if (!this.jsonEnabled()) {
234
233
  message = typeof message === 'string' ? message : (0, node_util_1.inspect)(message);
235
- stream_1.stderr.write((0, node_util_1.format)(message, ...args) + '\n');
234
+ cli_ux_1.ux.logToStderr(message, ...args);
236
235
  }
237
236
  }
238
237
  async parse(options, argv = this.argv) {
@@ -32,8 +32,7 @@ const is_wsl_1 = __importDefault(require("is-wsl"));
32
32
  const node_os_1 = require("node:os");
33
33
  const node_path_1 = require("node:path");
34
34
  const node_url_1 = require("node:url");
35
- const node_util_1 = require("node:util");
36
- const stream_1 = require("../cli-ux/stream");
35
+ const cli_ux_1 = require("../cli-ux");
37
36
  const errors_1 = require("../errors");
38
37
  const util_1 = require("../help/util");
39
38
  const module_loader_1 = require("../module-loader");
@@ -448,7 +447,7 @@ class Config {
448
447
  (0, errors_1.exit)(code);
449
448
  },
450
449
  log(message, ...args) {
451
- stream_1.stdout.write((0, node_util_1.format)(message, ...args) + '\n');
450
+ cli_ux_1.ux.info(message, ...args);
452
451
  },
453
452
  warn(message) {
454
453
  (0, errors_1.warn)(message);
@@ -473,7 +472,14 @@ class Config {
473
472
  catch (error) {
474
473
  final.failures.push({ error: error, plugin: p });
475
474
  debug(error);
476
- if (!captureErrors && error.oclif?.exit !== undefined)
475
+ // Do not throw the error if
476
+ // captureErrors is set to true
477
+ // error.oclif.exit is undefined or 0
478
+ // error.code is MODULE_NOT_FOUND
479
+ if (!captureErrors &&
480
+ error.oclif?.exit !== undefined &&
481
+ error.oclif?.exit !== 0 &&
482
+ error.code !== 'MODULE_NOT_FOUND')
477
483
  throw error;
478
484
  }
479
485
  marker?.addDetails({
@@ -680,15 +686,6 @@ class Config {
680
686
  insertLegacyPlugins(plugins) {
681
687
  for (const plugin of plugins) {
682
688
  this.plugins.set(plugin.name, plugin);
683
- // Delete all commands from the legacy plugin so that we can re-add them.
684
- // This is necessary because this.determinePriority will pick the initial
685
- // command that was added, which won't have been converted by PluginLegacy yet.
686
- for (const cmd of plugin.commands ?? []) {
687
- this._commands.delete(cmd.id);
688
- for (const alias of [...(cmd.aliases ?? []), ...(cmd.hiddenAliases ?? [])]) {
689
- this._commands.delete(alias);
690
- }
691
- }
692
689
  this.loadCommands(plugin);
693
690
  }
694
691
  }
@@ -110,6 +110,7 @@ class PluginLoader {
110
110
  if (typeof plugin !== 'string') {
111
111
  opts.tag = plugin.tag || opts.tag;
112
112
  opts.root = plugin.root || opts.root;
113
+ opts.url = plugin.url;
113
114
  }
114
115
  if (parent) {
115
116
  opts.parent = parent;
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.tsPath = exports.TS_CONFIGS = void 0;
7
- const node_fs_1 = require("node:fs");
8
7
  const node_path_1 = require("node:path");
9
8
  const errors_1 = require("../errors");
10
9
  const settings_1 = require("../settings");
@@ -34,7 +33,7 @@ function loadTSConfig(root) {
34
33
  return;
35
34
  }
36
35
  }
37
- if ((0, node_fs_1.existsSync)(tsconfigPath) && typescript) {
36
+ if ((0, fs_1.existsSync)(tsconfigPath) && typescript) {
38
37
  const tsconfig = typescript.parseConfigFileTextToJson(tsconfigPath, (0, fs_1.readJsonSync)(tsconfigPath, false)).config;
39
38
  if (!tsconfig || !tsconfig.compilerOptions) {
40
39
  throw new Error(`Could not read and parse tsconfig.json at ${tsconfigPath}, or it ` +
@@ -166,7 +165,7 @@ function determinePath(root, orig) {
166
165
  debug(`lib dir: ${lib}`);
167
166
  debug(`src dir: ${src}`);
168
167
  debug(`src commands dir: ${out}`);
169
- if ((0, node_fs_1.existsSync)(out) || (0, node_fs_1.existsSync)(out + '.ts')) {
168
+ if ((0, fs_1.existsSync)(out) || (0, fs_1.existsSync)(out + '.ts')) {
170
169
  debug(`Found source file for ${orig} at ${out}`);
171
170
  return out;
172
171
  }
@@ -176,7 +175,7 @@ function determinePath(root, orig) {
176
175
  return orig;
177
176
  }
178
177
  function tsPath(root, orig, plugin) {
179
- const rootPlugin = cache_1.default.getInstance().get('rootPlugin');
178
+ const rootPlugin = plugin?.options.isRoot ? plugin : cache_1.default.getInstance().get('rootPlugin');
180
179
  if (!orig)
181
180
  return orig;
182
181
  orig = orig.startsWith(root) ? orig : (0, node_path_1.join)(root, orig);
@@ -190,9 +189,12 @@ function tsPath(root, orig, plugin) {
190
189
  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})))`);
191
190
  if (plugin?.type === 'link')
192
191
  (0, errors_1.memoizedWarn)(`${plugin?.name} is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.`);
192
+ if (plugin?.options.url)
193
+ (0, errors_1.memoizedWarn)(`${plugin?.name} is an ESM module installed from github and cannot be auto-transpiled. Existing compiled source will be used instead.`);
193
194
  return orig;
194
195
  }
195
- if (settings_1.settings.tsnodeEnabled === undefined && isProduction && plugin?.type !== 'link') {
196
+ // Do not skip ts-node registration if the plugin is linked or installed from github
197
+ if (settings_1.settings.tsnodeEnabled === undefined && isProduction && plugin?.type !== 'link' && !plugin?.options.url) {
196
198
  debug(`Skipping ts-node registration for ${root} because NODE_ENV is NOT "test" or "development"`);
197
199
  return orig;
198
200
  }
package/lib/help/index.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.loadHelpClass = exports.Help = exports.HelpBase = exports.standardizeIDFromArgv = exports.normalizeArgv = exports.getHelpFlagAdditions = exports.CommandHelp = void 0;
7
7
  const node_util_1 = require("node:util");
8
8
  const strip_ansi_1 = __importDefault(require("strip-ansi"));
9
- const stream_1 = require("../cli-ux/stream");
9
+ const write_1 = __importDefault(require("../cli-ux/write"));
10
10
  const errors_1 = require("../errors");
11
11
  const module_loader_1 = require("../module-loader");
12
12
  const cache_default_value_1 = require("../util/cache-default-value");
@@ -133,7 +133,7 @@ class Help extends HelpBase {
133
133
  return new this.CommandHelpClass(command, this.config, this.opts);
134
134
  }
135
135
  log(...args) {
136
- stream_1.stdout.write(node_util_1.format.apply(this, args) + '\n');
136
+ write_1.default.stdout(node_util_1.format.apply(this, args) + '\n');
137
137
  }
138
138
  async showCommandHelp(command) {
139
139
  const name = command.id;
package/lib/index.js CHANGED
@@ -22,16 +22,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.settings = exports.Performance = exports.Parser = exports.run = exports.Interfaces = exports.toStandardizedId = exports.toConfiguredId = exports.loadHelpClass = exports.HelpBase = exports.Help = exports.CommandHelp = exports.Flags = exports.execute = exports.handle = exports.Errors = exports.Plugin = exports.Config = exports.Command = exports.stdout = exports.stderr = exports.flush = exports.ux = exports.Args = void 0;
27
- const stream_1 = require("./cli-ux/stream");
30
+ const write_1 = __importDefault(require("./cli-ux/write"));
28
31
  function checkCWD() {
29
32
  try {
30
33
  process.cwd();
31
34
  }
32
35
  catch (error) {
33
36
  if (error.code === 'ENOENT') {
34
- stream_1.stderr.write('WARNING: current directory does not exist\n');
37
+ write_1.default.stderr('WARNING: current directory does not exist\n');
35
38
  }
36
39
  }
37
40
  }
@@ -40,9 +43,10 @@ exports.Args = __importStar(require("./args"));
40
43
  exports.ux = __importStar(require("./cli-ux"));
41
44
  var flush_1 = require("./cli-ux/flush");
42
45
  Object.defineProperty(exports, "flush", { enumerable: true, get: function () { return flush_1.flush; } });
43
- var stream_2 = require("./cli-ux/stream");
44
- Object.defineProperty(exports, "stderr", { enumerable: true, get: function () { return stream_2.stderr; } });
45
- Object.defineProperty(exports, "stdout", { enumerable: true, get: function () { return stream_2.stdout; } });
46
+ // Remove these in the next major version
47
+ var stream_1 = require("./cli-ux/stream");
48
+ Object.defineProperty(exports, "stderr", { enumerable: true, get: function () { return stream_1.stderr; } });
49
+ Object.defineProperty(exports, "stdout", { enumerable: true, get: function () { return stream_1.stdout; } });
46
50
  var command_1 = require("./command");
47
51
  Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return command_1.Command; } });
48
52
  var config_1 = require("./config");
@@ -102,6 +102,7 @@ export declare namespace PJSON {
102
102
  nsisCustomization?: string;
103
103
  schema?: number;
104
104
  scope?: string;
105
+ pluginPrefix?: string;
105
106
  'warn-if-update-available'?: {
106
107
  authorization: string;
107
108
  message: string;
@@ -13,6 +13,7 @@ export interface PluginOptions {
13
13
  root: string;
14
14
  tag?: string;
15
15
  type?: string;
16
+ url?: string;
16
17
  }
17
18
  export interface Options extends PluginOptions {
18
19
  channel?: string;
@@ -57,6 +58,8 @@ export interface Plugin {
57
58
  * name from package.json
58
59
  */
59
60
  name: string;
61
+ readonly options: Options;
62
+ parent?: Plugin;
60
63
  /**
61
64
  * full package.json
62
65
  *
package/lib/main.js CHANGED
@@ -2,16 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.run = exports.versionAddition = exports.helpAddition = void 0;
4
4
  const node_url_1 = require("node:url");
5
- const node_util_1 = require("node:util");
6
- const stream_1 = require("./cli-ux/stream");
5
+ const cli_ux_1 = require("./cli-ux");
7
6
  const config_1 = require("./config");
8
7
  const help_1 = require("./help");
9
8
  const performance_1 = require("./performance");
10
9
  const debug = require('debug')('oclif:main');
11
- const log = (message = '', ...args) => {
12
- message = typeof message === 'string' ? message : (0, node_util_1.inspect)(message);
13
- stream_1.stdout.write((0, node_util_1.format)(message, ...args) + '\n');
14
- };
15
10
  const helpAddition = (argv, config) => {
16
11
  if (argv.length === 0 && !config.pjson.oclif.default)
17
12
  return true;
@@ -57,7 +52,7 @@ async function run(argv, options) {
57
52
  await config.runHook('init', { argv: argvSlice, id });
58
53
  // display version if applicable
59
54
  if ((0, exports.versionAddition)(argv, config)) {
60
- log(config.userAgent);
55
+ cli_ux_1.ux.log(config.userAgent);
61
56
  await collectPerf();
62
57
  return;
63
58
  }
@@ -6,6 +6,7 @@ const node_path_1 = require("node:path");
6
6
  const node_url_1 = require("node:url");
7
7
  const ts_node_1 = require("./config/ts-node");
8
8
  const errors_1 = require("./errors");
9
+ const fs_1 = require("./util/fs");
9
10
  const getPackageType = require('get-package-type');
10
11
  /**
11
12
  * Defines file extension resolution when source files do not have an extension.
@@ -166,7 +167,7 @@ function resolvePath(config, modulePath) {
166
167
  (isPlugin(config) ? (0, ts_node_1.tsPath)(config.root, modulePath, config) : (0, ts_node_1.tsPath)(config.root, modulePath)) ?? modulePath;
167
168
  let fileExists = false;
168
169
  let isDirectory = false;
169
- if ((0, node_fs_1.existsSync)(filePath)) {
170
+ if ((0, fs_1.existsSync)(filePath)) {
170
171
  fileExists = true;
171
172
  try {
172
173
  if ((0, node_fs_1.lstatSync)(filePath)?.isDirectory?.()) {
@@ -202,7 +203,7 @@ function findFile(filePath) {
202
203
  // eslint-disable-next-line camelcase
203
204
  for (const extension of s_EXTENSIONS) {
204
205
  const testPath = `${filePath}${extension}`;
205
- if ((0, node_fs_1.existsSync)(testPath)) {
206
+ if ((0, fs_1.existsSync)(testPath)) {
206
207
  return testPath;
207
208
  }
208
209
  }
package/lib/screen.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.errtermwidth = exports.stdtermwidth = void 0;
4
- const stream_1 = require("./cli-ux/stream");
5
4
  const settings_1 = require("./settings");
6
5
  function termwidth(stream) {
7
6
  if (!stream.isTTY) {
@@ -17,5 +16,5 @@ function termwidth(stream) {
17
16
  return width;
18
17
  }
19
18
  const columns = Number.parseInt(process.env.OCLIF_COLUMNS, 10) || settings_1.settings.columns;
20
- exports.stdtermwidth = columns || termwidth(stream_1.stdout);
21
- exports.errtermwidth = columns || termwidth(stream_1.stderr);
19
+ exports.stdtermwidth = columns || termwidth(process.stdout);
20
+ exports.errtermwidth = columns || termwidth(process.stderr);
package/lib/util/fs.d.ts CHANGED
@@ -17,3 +17,4 @@ export declare function readJson<T = unknown>(path: string): Promise<T>;
17
17
  export declare function readJsonSync(path: string, parse: false): string;
18
18
  export declare function readJsonSync<T = unknown>(path: string, parse?: true): T;
19
19
  export declare function safeReadJson<T>(path: string): Promise<T | undefined>;
20
+ export declare function existsSync(path: string): boolean;
package/lib/util/fs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.safeReadJson = exports.readJsonSync = exports.readJson = exports.fileExists = exports.dirExists = exports.requireJson = void 0;
3
+ exports.existsSync = exports.safeReadJson = exports.readJsonSync = exports.readJson = exports.fileExists = exports.dirExists = exports.requireJson = void 0;
4
4
  const node_fs_1 = require("node:fs");
5
5
  const promises_1 = require("node:fs/promises");
6
6
  const node_path_1 = require("node:path");
@@ -67,3 +67,7 @@ async function safeReadJson(path) {
67
67
  catch { }
68
68
  }
69
69
  exports.safeReadJson = safeReadJson;
70
+ function existsSync(path) {
71
+ return (0, node_fs_1.existsSync)(path);
72
+ }
73
+ exports.existsSync = existsSync;
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.3.3-dev.0",
4
+ "version": "3.4.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -72,7 +72,7 @@
72
72
  "nyc": "^15.1.0",
73
73
  "prettier": "^3.0.3",
74
74
  "shx": "^0.3.4",
75
- "sinon": "^11.1.2",
75
+ "sinon": "^16.1.0",
76
76
  "ts-node": "^10.9.1",
77
77
  "tsd": "^0.29.0",
78
78
  "typescript": "^5"