@oclif/core 3.0.0-beta.2 → 3.0.0-beta.20

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.
Files changed (112) hide show
  1. package/README.md +10 -6
  2. package/flush.js +1 -1
  3. package/handle.js +1 -1
  4. package/lib/args.d.ts +1 -1
  5. package/lib/args.js +17 -18
  6. package/lib/cli-ux/action/base.d.ts +3 -5
  7. package/lib/cli-ux/action/base.js +32 -26
  8. package/lib/cli-ux/action/simple.js +13 -18
  9. package/lib/cli-ux/action/spinner.d.ts +4 -2
  10. package/lib/cli-ux/action/spinner.js +27 -19
  11. package/lib/cli-ux/action/spinners.js +1 -1
  12. package/lib/cli-ux/action/types.d.ts +5 -0
  13. package/lib/cli-ux/action/types.js +2 -0
  14. package/lib/cli-ux/config.d.ts +0 -1
  15. package/lib/cli-ux/config.js +17 -21
  16. package/lib/cli-ux/exit.d.ts +1 -1
  17. package/lib/cli-ux/exit.js +4 -1
  18. package/lib/cli-ux/flush.d.ts +1 -0
  19. package/lib/cli-ux/flush.js +28 -0
  20. package/lib/cli-ux/index.d.ts +10 -30
  21. package/lib/cli-ux/index.js +32 -75
  22. package/lib/cli-ux/list.js +3 -3
  23. package/lib/cli-ux/prompt.js +32 -22
  24. package/lib/cli-ux/stream.js +1 -0
  25. package/lib/cli-ux/styled/index.d.ts +5 -6
  26. package/lib/cli-ux/styled/index.js +11 -11
  27. package/lib/cli-ux/styled/json.js +8 -5
  28. package/lib/cli-ux/styled/object.js +7 -9
  29. package/lib/cli-ux/styled/table.d.ts +4 -4
  30. package/lib/cli-ux/styled/table.js +61 -64
  31. package/lib/cli-ux/styled/tree.js +1 -3
  32. package/lib/cli-ux/wait.js +3 -5
  33. package/lib/command.d.ts +15 -19
  34. package/lib/command.js +117 -96
  35. package/lib/config/config.d.ts +16 -23
  36. package/lib/config/config.js +180 -334
  37. package/lib/config/index.d.ts +1 -1
  38. package/lib/config/index.js +1 -2
  39. package/lib/config/plugin-loader.d.ts +30 -0
  40. package/lib/config/plugin-loader.js +145 -0
  41. package/lib/config/plugin.d.ts +6 -11
  42. package/lib/config/plugin.js +112 -78
  43. package/lib/config/ts-node.d.ts +2 -1
  44. package/lib/config/ts-node.js +64 -51
  45. package/lib/config/util.d.ts +1 -11
  46. package/lib/config/util.js +6 -59
  47. package/lib/errors/config.js +1 -1
  48. package/lib/errors/errors/cli.d.ts +1 -1
  49. package/lib/errors/errors/cli.js +18 -14
  50. package/lib/errors/errors/exit.d.ts +0 -3
  51. package/lib/errors/errors/exit.js +1 -1
  52. package/lib/errors/errors/module-load.d.ts +0 -3
  53. package/lib/errors/errors/module-load.js +1 -1
  54. package/lib/errors/errors/pretty-print.js +11 -9
  55. package/lib/errors/handle.d.ts +12 -2
  56. package/lib/errors/handle.js +28 -18
  57. package/lib/errors/index.d.ts +2 -2
  58. package/lib/errors/index.js +20 -19
  59. package/lib/errors/logger.js +9 -8
  60. package/lib/execute.d.ts +49 -0
  61. package/lib/execute.js +63 -0
  62. package/lib/flags.d.ts +102 -31
  63. package/lib/flags.js +81 -46
  64. package/lib/help/command.d.ts +2 -0
  65. package/lib/help/command.js +68 -53
  66. package/lib/help/docopts.js +9 -13
  67. package/lib/help/formatter.d.ts +1 -1
  68. package/lib/help/formatter.js +35 -24
  69. package/lib/help/index.d.ts +7 -3
  70. package/lib/help/index.js +77 -55
  71. package/lib/help/root.js +7 -9
  72. package/lib/help/util.d.ts +1 -7
  73. package/lib/help/util.js +8 -28
  74. package/lib/index.d.ts +19 -18
  75. package/lib/index.js +36 -48
  76. package/lib/interfaces/config.d.ts +30 -30
  77. package/lib/interfaces/errors.d.ts +1 -1
  78. package/lib/interfaces/hooks.d.ts +3 -3
  79. package/lib/interfaces/index.d.ts +14 -14
  80. package/lib/interfaces/parser.d.ts +188 -116
  81. package/lib/interfaces/pjson.d.ts +2 -1
  82. package/lib/interfaces/plugin.d.ts +10 -1
  83. package/lib/main.d.ts +0 -48
  84. package/lib/main.js +11 -66
  85. package/lib/module-loader.d.ts +68 -79
  86. package/lib/module-loader.js +183 -150
  87. package/lib/parser/errors.d.ts +3 -3
  88. package/lib/parser/errors.js +17 -10
  89. package/lib/parser/help.js +5 -5
  90. package/lib/parser/parse.d.ts +3 -0
  91. package/lib/parser/parse.js +114 -115
  92. package/lib/parser/validate.js +45 -25
  93. package/lib/performance.d.ts +5 -1
  94. package/lib/performance.js +40 -19
  95. package/lib/util/aggregate-flags.d.ts +2 -0
  96. package/lib/util/aggregate-flags.js +13 -0
  97. package/lib/util/cache-command.d.ts +3 -0
  98. package/lib/util/cache-command.js +109 -0
  99. package/lib/util/cache-default-value.d.ts +2 -0
  100. package/lib/util/cache-default-value.js +28 -0
  101. package/lib/util/ensure-arg-object.d.ts +12 -0
  102. package/lib/util/ensure-arg-object.js +14 -0
  103. package/lib/util/fs.d.ts +7 -0
  104. package/lib/util/fs.js +54 -0
  105. package/lib/util/os.d.ts +19 -0
  106. package/lib/util/os.js +28 -0
  107. package/lib/{util.d.ts → util/util.d.ts} +6 -15
  108. package/lib/util/util.js +98 -0
  109. package/package.json +32 -34
  110. package/lib/cli-ux/action/pride-spinner.d.ts +0 -4
  111. package/lib/cli-ux/action/pride-spinner.js +0 -30
  112. package/lib/util.js +0 -126
@@ -3,7 +3,7 @@ export type CommandError = Error & {
3
3
  };
4
4
  export interface OclifError {
5
5
  oclif: {
6
- exit?: number | false;
6
+ exit?: number;
7
7
  };
8
8
  }
9
9
  export interface PrettyPrintableError {
@@ -43,14 +43,14 @@ export interface Hooks {
43
43
  };
44
44
  return: void;
45
45
  };
46
- 'command_not_found': {
46
+ command_not_found: {
47
47
  options: {
48
48
  id: string;
49
49
  argv?: string[];
50
50
  };
51
51
  return: unknown;
52
52
  };
53
- 'command_incomplete': {
53
+ command_incomplete: {
54
54
  options: {
55
55
  id: string;
56
56
  argv: string[];
@@ -58,7 +58,7 @@ export interface Hooks {
58
58
  };
59
59
  return: unknown;
60
60
  };
61
- 'jit_plugin_not_installed': {
61
+ jit_plugin_not_installed: {
62
62
  options: {
63
63
  id: string;
64
64
  argv: string[];
@@ -1,14 +1,14 @@
1
- export { AlphabetLowercase, AlphabetUppercase } from './alphabet';
2
- export { Config, ArchTypes, PlatformTypes, LoadOptions, VersionDetails, PluginVersionDetail } from './config';
3
- export { OclifError, PrettyPrintableError, CommandError } from './errors';
4
- export { HelpOptions } from './help';
5
- export { Hook, Hooks } from './hooks';
6
- export { Manifest } from './manifest';
7
- export { S3Manifest } from './s3-manifest';
8
- export { BooleanFlag, Flag, OptionFlag, Deprecation } from './parser';
9
- export { PJSON } from './pjson';
10
- export { Plugin, PluginOptions, Options } from './plugin';
11
- export { Topic } from './topic';
12
- export { TSConfig } from './ts-config';
13
- export { InferredFlags } from './flags';
14
- export { InferredArgs } from './args';
1
+ export type { AlphabetLowercase, AlphabetUppercase } from './alphabet';
2
+ export type { Config, ArchTypes, PlatformTypes, LoadOptions, VersionDetails, PluginVersionDetail } from './config';
3
+ export type { OclifError, PrettyPrintableError, CommandError } from './errors';
4
+ export type { HelpOptions } from './help';
5
+ export type { Hook, Hooks } from './hooks';
6
+ export type { Manifest } from './manifest';
7
+ export type { S3Manifest } from './s3-manifest';
8
+ export type { Arg, BooleanFlag, CustomOptions, Deprecation, Flag, FlagDefinition, OptionFlag } from './parser';
9
+ export type { PJSON } from './pjson';
10
+ export type { Plugin, PluginOptions, Options } from './plugin';
11
+ export type { Topic } from './topic';
12
+ export type { TSConfig } from './ts-config';
13
+ export type { InferredFlags } from './flags';
14
+ export type { InferredArgs } from './args';
@@ -1,6 +1,5 @@
1
- import { Command } from '../command';
2
1
  import { AlphabetLowercase, AlphabetUppercase } from './alphabet';
3
- import { Config } from './config';
2
+ import { Command } from '../command';
4
3
  export type FlagOutput = {
5
4
  [name: string]: any;
6
5
  };
@@ -62,88 +61,26 @@ export type DefaultContext<T> = {
62
61
  /**
63
62
  * Type to define a default value for a flag.
64
63
  * @param context The context of the flag.
65
- * @param isWritingManifest Informs the function that a manifest file is being written.
66
- * The manifest file is used to store the flag definitions, with a default value if present, for a command and is published to npm.
67
- * When a manifest file is being written, the default value may contain data that should not be included in the manifest.
68
- * The plugin developer can use isWritingManifest to determine if the default value should be omitted from the manifest.
69
- * in the function's implementation.
70
- * @example
71
- * static flags = {
72
- * foo: flags.string({
73
- * defaultHelp: async (context, isWritingManifest) => {
74
- * if (isWritingManifest) {
75
- * return undefined
76
- * }
77
- * return 'value that is used outside a manifest'
78
- * },
79
- * }),
80
- * }
81
64
  */
82
- export type FlagDefault<T, P = CustomOptions> = T | ((context: DefaultContext<P & OptionFlag<T, P>>, isWritingManifest?: boolean) => Promise<T>);
65
+ export type FlagDefault<T, P = CustomOptions> = T | ((context: DefaultContext<P & OptionFlag<T, P>>) => Promise<T>);
83
66
  /**
84
67
  * Type to define a defaultHelp value for a flag.
85
68
  * The defaultHelp value is used in the help output for the flag and when writing a manifest.
86
69
  * It is also can be used to provide a value for the flag when issuing certain error messages.
87
70
  *
88
71
  * @param context The context of the flag.
89
- * @param isWritingManifest Informs the function that a manifest file is being written.
90
- * The manifest file is used to store the flag definitions, with a default value if present via defaultHelp, for a command and is published to npm.
91
- * When a manifest file is being written, the default value may contain data that should not be included in the manifest.
92
- * The plugin developer can use isWritingManifest to determine if the defaultHelp value should be omitted from the manifest.
93
- * in the function's implementation.
94
- * @example
95
- * static flags = {
96
- * foo: flags.string({
97
- * defaultHelp: async (context, isWritingManifest) => {
98
- * if (isWritingManifest) {
99
- * return undefined
100
- * }
101
- * return 'value that is used outside a manifest'
102
- * },
103
- * }),
104
- * }
105
72
  */
106
- export type FlagDefaultHelp<T, P = CustomOptions> = T | ((context: DefaultContext<P & OptionFlag<T, P>>, isWritingManifest?: boolean) => Promise<string | undefined>);
73
+ export type FlagDefaultHelp<T, P = CustomOptions> = T | ((context: DefaultContext<P & OptionFlag<T, P>>) => Promise<string | undefined>);
107
74
  /**
108
75
  * Type to define a default value for an arg.
109
76
  * @param context The context of the arg.
110
- * @param isWritingManifest Informs the function that a manifest file is being written.
111
- * The manifest file is used to store the arg definitions, with a default value if present, for a command and is published to npm.
112
- * When a manifest file is being written, the default value may contain data that should not be included in the manifest.
113
- * The plugin developer can use isWritingManifest to determine if the default value should be omitted from the manifest.
114
- * in the function's implementation.
115
- * @example
116
- * public static readonly args = {
117
- * one: Args.string({
118
- * default: async (context, isWritingManifest) => {
119
- * if (isWritingManifest) {
120
- * return undefined
121
- * }
122
- * return 'value that is used outside a manifest'
123
- * }),
124
- * };
125
77
  */
126
- export type ArgDefault<T, P = CustomOptions> = T | ((context: DefaultContext<Arg<T, P>>, isWritingManifest?: boolean) => Promise<T>);
78
+ export type ArgDefault<T, P = CustomOptions> = T | ((context: DefaultContext<Arg<T, P>>) => Promise<T>);
127
79
  /**
128
80
  * Type to define a defaultHelp value for an arg.
129
81
  * @param context The context of the arg.
130
- * @param isWritingManifest Informs the function that a manifest file is being written.
131
- * The manifest file is used to store the arg definitions, with a default value if present via defaultHelp, for a command and is published to npm.
132
- * When a manifest file is being written, the default value may contain data that should not be included in the manifest.
133
- * The plugin developer can use isWritingManifest to determine if the default value should be omitted from the manifest.
134
- * in the function's implementation.
135
- * @example
136
- * public static readonly args = {
137
- * one: Args.string({
138
- * defaultHelp: async (context, isWritingManifest) => {
139
- * if (isWritingManifest) {
140
- * return undefined
141
- * }
142
- * return 'value that is used outside a manifest'
143
- * }),
144
- * };
145
82
  */
146
- export type ArgDefaultHelp<T, P = CustomOptions> = T | ((context: DefaultContext<Arg<T, P>>, isWritingManifest?: boolean) => Promise<string | undefined>);
83
+ export type ArgDefaultHelp<T, P = CustomOptions> = T | ((context: DefaultContext<Arg<T, P>>) => Promise<string | undefined>);
147
84
  export type FlagRelationship = string | {
148
85
  name: string;
149
86
  when: (flags: Record<string, unknown>) => Promise<boolean>;
@@ -216,16 +153,19 @@ export type FlagProps = {
216
153
  * Alternate names that can be used for this flag.
217
154
  */
218
155
  aliases?: string[];
156
+ /**
157
+ * Alternate short chars that can be used for this flag.
158
+ */
159
+ charAliases?: (AlphabetLowercase | AlphabetUppercase)[];
219
160
  /**
220
161
  * Emit deprecation warning when a flag alias is provided
221
162
  */
222
163
  deprecateAliases?: boolean;
223
164
  /**
224
- * Delimiter to separate the values for a multiple value flag.
225
- * Only respected if multiple is set to true. Default behavior is to
226
- * separate on spaces.
165
+ * If true, the value returned by defaultHelp will not be cached in the oclif.manifest.json.
166
+ * This is helpful if the default value contains sensitive data that shouldn't be published to npm.
227
167
  */
228
- delimiter?: ',';
168
+ noCacheDefault?: boolean;
229
169
  };
230
170
  export type ArgProps = {
231
171
  name: string;
@@ -245,6 +185,11 @@ export type ArgProps = {
245
185
  required?: boolean;
246
186
  options?: string[];
247
187
  ignoreStdin?: boolean;
188
+ /**
189
+ * If true, the value returned by defaultHelp will not be cached in the oclif.manifest.json.
190
+ * This is helpful if the default value contains sensitive data that shouldn't be published to npm.
191
+ */
192
+ noCacheDefault?: boolean;
248
193
  };
249
194
  export type BooleanFlagProps = FlagProps & {
250
195
  type: 'boolean';
@@ -253,13 +198,19 @@ export type BooleanFlagProps = FlagProps & {
253
198
  export type OptionFlagProps = FlagProps & {
254
199
  type: 'option';
255
200
  helpValue?: string;
256
- options?: string[];
201
+ options?: readonly string[];
257
202
  multiple?: boolean;
203
+ /**
204
+ * Delimiter to separate the values for a multiple value flag.
205
+ * Only respected if multiple is set to true. Default behavior is to
206
+ * separate on spaces.
207
+ */
208
+ delimiter?: ',';
258
209
  };
259
210
  export type FlagParserContext = Command & {
260
211
  token: FlagToken;
261
212
  };
262
- export type FlagParser<T, I extends string | boolean, P = CustomOptions> = (input: I, context: FlagParserContext, opts: P & OptionFlag<T, P>) => Promise<T>;
213
+ export type FlagParser<T, I extends string | boolean, P = CustomOptions> = (input: I, context: FlagParserContext, opts: P & OptionFlag<T, P>) => T extends Array<infer U> ? Promise<U | undefined> : Promise<T | undefined>;
263
214
  export type ArgParserContext = Command & {
264
215
  token: ArgToken;
265
216
  };
@@ -286,45 +237,185 @@ export type BooleanFlag<T> = FlagProps & BooleanFlagProps & {
286
237
  default?: FlagDefault<boolean>;
287
238
  parse: (input: boolean, context: FlagParserContext, opts: FlagProps & BooleanFlagProps) => Promise<T>;
288
239
  };
289
- export type OptionFlagDefaults<T, P = CustomOptions, M = false> = FlagProps & OptionFlagProps & {
290
- parse: FlagParser<T, string, P>;
291
- defaultHelp?: FlagDefaultHelp<T>;
292
- input: string[];
293
- default?: M extends true ? FlagDefault<T[] | undefined, P> : FlagDefault<T | undefined, P>;
294
- };
295
240
  export type OptionFlag<T, P = CustomOptions> = FlagProps & OptionFlagProps & {
296
- parse: FlagParser<T, string, P>;
241
+ parse: FlagParser<T | undefined, string, P>;
297
242
  defaultHelp?: FlagDefaultHelp<T, P>;
298
243
  input: string[];
299
- } & ({
300
244
  default?: FlagDefault<T | undefined, P>;
245
+ };
246
+ type ReturnTypeSwitches = {
247
+ multiple: boolean;
248
+ requiredOrDefaulted: boolean;
249
+ };
250
+ /**
251
+ * The logic here is as follows:
252
+ * - If requiredOrDefaulted is true && multiple is true, then the return type is T[]
253
+ * - It's possible that T extends an Array, if so we want to return T so that the return isn't T[][]
254
+ * - If requiredOrDefaulted is true && multiple is false, then the return type is T
255
+ * - If requiredOrDefaulted is false && multiple is true, then the return type is T[] | undefined
256
+ * - It's possible that T extends an Array, if so we want to return T so that the return isn't T[][]
257
+ * - If requiredOrDefaulted is false && multiple is false, then the return type is T | undefined
258
+ */
259
+ type FlagReturnType<T, R extends ReturnTypeSwitches> = R['requiredOrDefaulted'] extends true ? R['multiple'] extends true ? [T] extends [Array<unknown>] ? T : T[] : T : R['multiple'] extends true ? [T] extends [Array<unknown>] ? T | undefined : T[] | undefined : T | undefined;
260
+ /**
261
+ * FlagDefinition types a function that takes `options` and returns an OptionFlag<T>.
262
+ *
263
+ * This is returned by `Flags.custom()` and `Flags.option()`, which each take a `defaults` object
264
+ * that mirrors the OptionFlag interface.
265
+ *
266
+ * The `T` in the `OptionFlag<T>` return type is determined by a combination of the provided defaults for
267
+ * `multiple`, `required`, and `default` and the provided options for those same properties. If these properties
268
+ * are provided in the options, they override the defaults.
269
+ *
270
+ * no options or defaults -> T | undefined
271
+ * `required` -> T
272
+ * `default` -> T
273
+ * `multiple` -> T[] | undefined
274
+ * `required` + `multiple` -> T[]
275
+ * `default` + `multiple` -> T[]
276
+ */
277
+ export type FlagDefinition<T, P = CustomOptions, R extends ReturnTypeSwitches = {
301
278
  multiple: false;
302
- } | {
303
- default?: FlagDefault<T[] | undefined, P>;
304
- multiple: true;
305
- });
306
- export type FlagDefinition<T, P = CustomOptions> = {
279
+ requiredOrDefaulted: false;
280
+ }> = {
307
281
  (options: P & {
282
+ multiple: false;
283
+ required: true;
284
+ } & Partial<OptionFlag<FlagReturnType<T, {
285
+ multiple: false;
286
+ requiredOrDefaulted: true;
287
+ }>, P>>): OptionFlag<FlagReturnType<T, {
288
+ multiple: false;
289
+ requiredOrDefaulted: true;
290
+ }>>;
291
+ (options: P & {
292
+ multiple: true;
293
+ required: false;
294
+ } & Partial<OptionFlag<FlagReturnType<T, {
308
295
  multiple: true;
296
+ requiredOrDefaulted: false;
297
+ }>, P>>): OptionFlag<FlagReturnType<T, {
298
+ multiple: true;
299
+ requiredOrDefaulted: false;
300
+ }>>;
301
+ (options: P & {
302
+ multiple: false;
303
+ required: false;
304
+ } & Partial<OptionFlag<FlagReturnType<T, {
305
+ multiple: false;
306
+ requiredOrDefaulted: false;
307
+ }>, P>>): OptionFlag<FlagReturnType<T, {
308
+ multiple: false;
309
+ requiredOrDefaulted: false;
310
+ }>>;
311
+ (options: R['multiple'] extends true ? // `multiple` is defaulted to true and either `required=true` or `default` are provided in options
312
+ P & ({
313
+ required: true;
314
+ } | {
315
+ default: OptionFlag<FlagReturnType<T, {
316
+ multiple: R['multiple'];
317
+ requiredOrDefaulted: true;
318
+ }>, P>['default'];
319
+ }) & Partial<OptionFlag<FlagReturnType<T, {
320
+ multiple: R['multiple'];
321
+ requiredOrDefaulted: true;
322
+ }>, P>> : // `multiple` is NOT defaulted to true and either `required=true` or `default` are provided in options
323
+ P & {
324
+ multiple?: false | undefined;
309
325
  } & ({
310
326
  required: true;
311
327
  } | {
312
- default: FlagDefault<T[]>;
313
- }) & Partial<OptionFlag<T, P>>): OptionFlag<T[]>;
314
- (options: P & {
328
+ default: OptionFlag<FlagReturnType<T, {
329
+ multiple: R['multiple'];
330
+ requiredOrDefaulted: true;
331
+ }>, P>['default'];
332
+ }) & Partial<OptionFlag<FlagReturnType<T, {
333
+ multiple: R['multiple'];
334
+ requiredOrDefaulted: true;
335
+ }>, P>>): OptionFlag<FlagReturnType<T, {
336
+ multiple: R['multiple'];
337
+ requiredOrDefaulted: true;
338
+ }>>;
339
+ (options: R['multiple'] extends true ? // `multiple` is defaulted to true and either `required=true` or `default` are provided in options
340
+ P & ({
341
+ required: true;
342
+ } | {
343
+ default: OptionFlag<FlagReturnType<T, {
344
+ multiple: true;
345
+ requiredOrDefaulted: true;
346
+ }>, P>['default'];
347
+ }) & Partial<OptionFlag<FlagReturnType<T, {
315
348
  multiple: true;
316
- } & Partial<OptionFlag<T>>): OptionFlag<T[] | undefined>;
317
- (options: P & ({
349
+ requiredOrDefaulted: true;
350
+ }>, P>> : // `multiple` is NOT defaulted to true but `multiple=true` and either `required=true` or `default` are provided in options
351
+ P & {
352
+ multiple: true;
353
+ } & ({
318
354
  required: true;
319
355
  } | {
320
- default: FlagDefault<T>;
321
- }) & Partial<OptionFlag<T>>): OptionFlag<T>;
322
- (options?: P & Partial<OptionFlag<T>>): OptionFlag<T | undefined>;
356
+ default: OptionFlag<FlagReturnType<T, {
357
+ multiple: true;
358
+ requiredOrDefaulted: true;
359
+ }>, P>['default'];
360
+ }) & Partial<OptionFlag<FlagReturnType<T, {
361
+ multiple: true;
362
+ requiredOrDefaulted: true;
363
+ }>, P>>): OptionFlag<FlagReturnType<T, {
364
+ multiple: true;
365
+ requiredOrDefaulted: true;
366
+ }>>;
367
+ (options: P & {
368
+ multiple?: false | undefined;
369
+ } & ({
370
+ required: true;
371
+ } | {
372
+ default: OptionFlag<FlagReturnType<T, {
373
+ multiple: R['multiple'];
374
+ requiredOrDefaulted: true;
375
+ }>, P>['default'];
376
+ }) & Partial<OptionFlag<FlagReturnType<T, {
377
+ multiple: R['multiple'];
378
+ requiredOrDefaulted: true;
379
+ }>, P>>): OptionFlag<FlagReturnType<T, {
380
+ multiple: R['multiple'];
381
+ requiredOrDefaulted: true;
382
+ }>>;
383
+ (options: P & {
384
+ required: false;
385
+ } & Partial<OptionFlag<FlagReturnType<T, {
386
+ multiple: R['multiple'];
387
+ requiredOrDefaulted: false;
388
+ }>, P>>): OptionFlag<FlagReturnType<T, {
389
+ multiple: R['multiple'];
390
+ requiredOrDefaulted: false;
391
+ }>>;
392
+ (options: P & {
393
+ multiple: false;
394
+ } & Partial<OptionFlag<FlagReturnType<T, {
395
+ multiple: false;
396
+ requiredOrDefaulted: R['requiredOrDefaulted'];
397
+ }>, P>>): OptionFlag<FlagReturnType<T, {
398
+ multiple: false;
399
+ requiredOrDefaulted: R['requiredOrDefaulted'];
400
+ }>>;
401
+ (options?: P & {
402
+ multiple?: false | undefined;
403
+ } & Partial<OptionFlag<FlagReturnType<T, R>, P>>): OptionFlag<FlagReturnType<T, R>>;
404
+ (options: P & {
405
+ multiple: true;
406
+ } & Partial<OptionFlag<FlagReturnType<T, {
407
+ multiple: true;
408
+ requiredOrDefaulted: R['requiredOrDefaulted'];
409
+ }>, P>>): OptionFlag<FlagReturnType<T, {
410
+ multiple: true;
411
+ requiredOrDefaulted: R['requiredOrDefaulted'];
412
+ }>>;
323
413
  };
324
414
  export type Flag<T> = BooleanFlag<T> | OptionFlag<T>;
325
415
  export type Input<TFlags extends FlagOutput, BFlags extends FlagOutput, AFlags extends ArgOutput> = {
326
416
  flags?: FlagInput<TFlags>;
327
417
  baseFlags?: FlagInput<BFlags>;
418
+ enableJsonFlag?: true | false;
328
419
  args?: ArgInput<AFlags>;
329
420
  strict?: boolean;
330
421
  context?: ParserContext;
@@ -341,33 +432,14 @@ export type ParserInput = {
341
432
  export type ParserContext = Command & {
342
433
  token?: FlagToken | ArgToken;
343
434
  };
344
- export type CompletionContext = {
345
- args?: {
346
- [name: string]: string;
347
- };
348
- flags?: {
349
- [name: string]: string;
350
- };
351
- argv?: string[];
352
- config: Config;
353
- };
354
- export type Completion = {
355
- skipCache?: boolean;
356
- cacheDuration?: number;
357
- cacheKey?(ctx: CompletionContext): Promise<string>;
358
- options(ctx: CompletionContext): Promise<string[]>;
359
- };
360
- export type CompletableOptionFlag<T> = OptionFlag<T> & {
361
- completion?: Completion;
362
- };
363
- export type CompletableFlag<T> = BooleanFlag<T> | CompletableOptionFlag<T>;
364
435
  export type FlagInput<T extends FlagOutput = {
365
436
  [flag: string]: any;
366
437
  }> = {
367
- [P in keyof T]: CompletableFlag<T[P]>;
438
+ [P in keyof T]: Flag<T[P]>;
368
439
  };
369
440
  export type ArgInput<T extends ArgOutput = {
370
441
  [arg: string]: any;
371
442
  }> = {
372
443
  [P in keyof T]: Arg<T[P]>;
373
444
  };
445
+ export {};
@@ -1,6 +1,7 @@
1
1
  import { HelpOptions } from './help';
2
2
  export interface PJSON {
3
3
  [k: string]: any;
4
+ version: string;
4
5
  dependencies?: {
5
6
  [name: string]: string;
6
7
  };
@@ -25,7 +26,7 @@ export declare namespace PJSON {
25
26
  topicSeparator?: ':' | ' ';
26
27
  flexibleTaxonomy?: boolean;
27
28
  hooks?: {
28
- [name: string]: (string | string[]);
29
+ [name: string]: string | string[];
29
30
  };
30
31
  commands?: string;
31
32
  default?: string;
@@ -8,8 +8,11 @@ export interface PluginOptions {
8
8
  tag?: string;
9
9
  ignoreManifest?: boolean;
10
10
  errorOnManifestCreate?: boolean;
11
+ respectNoCacheDefault?: boolean;
11
12
  parent?: Plugin;
12
13
  children?: Plugin[];
14
+ flexibleTaxonomy?: boolean;
15
+ isRoot?: boolean;
13
16
  }
14
17
  export interface Options extends PluginOptions {
15
18
  devPlugins?: boolean;
@@ -18,6 +21,7 @@ export interface Options extends PluginOptions {
18
21
  channel?: string;
19
22
  version?: string;
20
23
  enablePerf?: boolean;
24
+ plugins?: Map<string, Plugin>;
21
25
  }
22
26
  export interface Plugin {
23
27
  /**
@@ -66,17 +70,22 @@ export interface Plugin {
66
70
  * if it appears to be an npm package but does not look like it's really a CLI plugin, this is set to false
67
71
  */
68
72
  valid: boolean;
73
+ /**
74
+ * True if the plugin is the root plugin.
75
+ */
76
+ isRoot: boolean;
69
77
  commands: Command.Loadable[];
70
78
  hooks: {
71
79
  [k: string]: string[];
72
80
  };
73
81
  readonly commandIDs: string[];
74
82
  readonly topics: Topic[];
83
+ readonly hasManifest: boolean;
75
84
  findCommand(id: string, opts: {
76
85
  must: true;
77
86
  }): Promise<Command.Class>;
78
87
  findCommand(id: string, opts?: {
79
88
  must: boolean;
80
89
  }): Promise<Command.Class> | undefined;
81
- load(isWritingManifest: boolean): Promise<void>;
90
+ load(): Promise<void>;
82
91
  }
package/lib/main.d.ts CHANGED
@@ -3,51 +3,3 @@ import { Config } from './config';
3
3
  export declare const helpAddition: (argv: string[], config: Interfaces.Config) => boolean;
4
4
  export declare const versionAddition: (argv: string[], config?: Interfaces.Config) => boolean;
5
5
  export declare function run(argv?: string[], options?: Interfaces.LoadOptions): Promise<unknown>;
6
- /**
7
- * Load and run oclif CLI
8
- *
9
- * @param options - options to load the CLI
10
- * @returns Promise<void>
11
- *
12
- * @example For ESM dev.js
13
- * ```
14
- * #!/usr/bin/env node
15
- * (async () => {
16
- * const oclif = await import('@oclif/core')
17
- * await oclif.execute({development: true, dir: import.meta.url})
18
- * })()
19
- * ```
20
- *
21
- * @example For ESM run.js
22
- * ```
23
- * #!/usr/bin/env node
24
- * (async () => {
25
- * const oclif = await import('@oclif/core')
26
- * await oclif.execute({dir: import.meta.url})
27
- * })()
28
- * ```
29
- *
30
- * @example For CJS dev.js
31
- * ```
32
- * #!/usr/bin/env node
33
- * (async () => {
34
- * const oclif = await import('@oclif/core')
35
- * await oclif.execute({development: true, dir: __dirname})
36
- * })()
37
- * ```
38
- *
39
- * @example For CJS run.js
40
- * ```
41
- * #!/usr/bin/env node
42
- * (async () => {
43
- * const oclif = await import('@oclif/core')
44
- * await oclif.execute({dir: __dirname})
45
- * })()
46
- * ```
47
- */
48
- export declare function execute(options: {
49
- dir: string;
50
- args?: string[];
51
- loadOptions?: Interfaces.LoadOptions;
52
- development?: boolean;
53
- }): Promise<void>;
package/lib/main.js CHANGED
@@ -1,19 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.execute = exports.run = exports.versionAddition = exports.helpAddition = void 0;
4
- const url_1 = require("url");
5
- const util_1 = require("util");
6
- const url_2 = require("url");
7
- const config_1 = require("./config");
3
+ exports.run = exports.versionAddition = exports.helpAddition = void 0;
4
+ const node_url_1 = require("node:url");
5
+ const node_util_1 = require("node:util");
8
6
  const help_1 = require("./help");
9
- const settings_1 = require("./settings");
10
- const _1 = require(".");
11
- const stream_1 = require("./cli-ux/stream");
7
+ const config_1 = require("./config");
12
8
  const performance_1 = require("./performance");
9
+ const stream_1 = require("./cli-ux/stream");
13
10
  const debug = require('debug')('oclif:main');
14
11
  const log = (message = '', ...args) => {
15
- message = typeof message === 'string' ? message : (0, util_1.inspect)(message);
16
- stream_1.stdout.write((0, util_1.format)(message, ...args) + '\n');
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');
17
14
  };
18
15
  const helpAddition = (argv, config) => {
19
16
  if (argv.length === 0 && !config.pjson.oclif.default)
@@ -41,7 +38,8 @@ async function run(argv, options) {
41
38
  const initMarker = performance_1.Performance.mark('main.run#init');
42
39
  const collectPerf = async () => {
43
40
  marker?.stop();
44
- initMarker?.stop();
41
+ if (!initMarker?.stopped)
42
+ initMarker?.stop();
45
43
  await performance_1.Performance.collect();
46
44
  performance_1.Performance.debug();
47
45
  };
@@ -50,8 +48,8 @@ async function run(argv, options) {
50
48
  debug('process.argv: %O', process.argv);
51
49
  argv = argv ?? process.argv.slice(2);
52
50
  // Handle the case when a file URL string or URL is passed in such as 'import.meta.url'; covert to file path.
53
- if (options && ((typeof options === 'string' && options.startsWith('file://')) || options instanceof url_2.URL)) {
54
- options = (0, url_1.fileURLToPath)(options);
51
+ if (options && ((typeof options === 'string' && options.startsWith('file://')) || options instanceof node_url_1.URL)) {
52
+ options = (0, node_url_1.fileURLToPath)(options);
55
53
  }
56
54
  const config = await config_1.Config.load(options ?? require.main?.filename ?? __dirname);
57
55
  let [id, ...argvSlice] = (0, help_1.normalizeArgv)(config, argv);
@@ -96,56 +94,3 @@ async function run(argv, options) {
96
94
  }
97
95
  }
98
96
  exports.run = run;
99
- /**
100
- * Load and run oclif CLI
101
- *
102
- * @param options - options to load the CLI
103
- * @returns Promise<void>
104
- *
105
- * @example For ESM dev.js
106
- * ```
107
- * #!/usr/bin/env node
108
- * (async () => {
109
- * const oclif = await import('@oclif/core')
110
- * await oclif.execute({development: true, dir: import.meta.url})
111
- * })()
112
- * ```
113
- *
114
- * @example For ESM run.js
115
- * ```
116
- * #!/usr/bin/env node
117
- * (async () => {
118
- * const oclif = await import('@oclif/core')
119
- * await oclif.execute({dir: import.meta.url})
120
- * })()
121
- * ```
122
- *
123
- * @example For CJS dev.js
124
- * ```
125
- * #!/usr/bin/env node
126
- * (async () => {
127
- * const oclif = await import('@oclif/core')
128
- * await oclif.execute({development: true, dir: __dirname})
129
- * })()
130
- * ```
131
- *
132
- * @example For CJS run.js
133
- * ```
134
- * #!/usr/bin/env node
135
- * (async () => {
136
- * const oclif = await import('@oclif/core')
137
- * await oclif.execute({dir: __dirname})
138
- * })()
139
- * ```
140
- */
141
- async function execute(options) {
142
- if (options.development) {
143
- // In dev mode -> use ts-node and dev plugins
144
- process.env.NODE_ENV = 'development';
145
- settings_1.settings.debug = true;
146
- }
147
- await run(options.args ?? process.argv.slice(2), options.loadOptions ?? options.dir)
148
- .then(async () => (0, _1.flush)())
149
- .catch(_1.Errors.handle);
150
- }
151
- exports.execute = execute;