@@ -119,7 +119,7 @@ export interface CommandModule {
119119 * strategy, the CLI can offer to install the referenced command if
120120 * necessary, and we can reuse the error handling code in the CLI core.
121121 */
122- getCommand ( opts : GetCommandsOptions ) : Command | Promise < Command > ;
122+ getCommand : GetCommandFunction ;
123123}
124124
125125/**
@@ -134,14 +134,31 @@ export interface GetCommandsOptions {
134134 requestedCommand ?: string ;
135135}
136136
137+ /**
138+ * The type of the getCommand function in a command module.
139+ *
140+ * Note that this can return a ReferenceToCommand, which the CLI will
141+ * further resolve.
142+ *
143+ * If your module is deferring to another in a different npm package, it's
144+ * generally preferable to return a ReferenceToCommand rather than doing the
145+ * dynamic import yourself. That way we use a consistent module resolution
146+ * strategy, the CLI can offer to install the referenced command if
147+ * necessary, and we can reuse the error handling code in the CLI core.
148+ */
149+ export interface GetCommandFunction {
150+ ( opts : GetCommandsOptions ) :
151+ | undefined
152+ | Command
153+ | Promise < Partial < Command > | undefined > ;
154+ }
155+
137156/**
138157 * Like CommandModule, only we're not certain that the module obeys the
139158 * contract correctly.
140159 *
141160 * This is the type we should use internally when loading a module.
142161 */
143162export interface MaybeCommandModule {
144- getCommand ?(
145- opts : GetCommandsOptions
146- ) : undefined | Command | Promise < Partial < Command > | undefined > ;
163+ getCommand ?: GetCommandFunction ;
147164}
0 commit comments