Skip to content

Commit cdc98e8

Browse files
committed
Add a type for the getCommand function in localize
This is adding some more circularity than we've had in the past. I'm not sure whether or not it's going to work in CI
1 parent f73e089 commit cdc98e8

4 files changed

Lines changed: 28 additions & 7 deletions

File tree

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/labs/cli-localize/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
"@lit/localize-tools": "^0.6.3"
6464
},
6565
"devDependencies": {
66-
"typescript": "~4.6.2"
66+
"typescript": "~4.6.2",
67+
"@lit-labs/cli": "^0.1.0"
6768
},
6869
"engines": {
6970
"node": ">=14.8.0"

packages/labs/cli-localize/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* Copyright 2022 Google LLC
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
6-
6+
import type {GetCommandFunction} from '@lit-labs/cli/lib/command';
77
/**
88
* Defines our interface within the Lit CLI.
99
*/
10-
export const getCommand = () => {
10+
export const getCommand: GetCommandFunction = () => {
1111
return {
1212
kind: 'resolved',
1313
name: 'localize',

packages/labs/cli/src/lib/command.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
143162
export interface MaybeCommandModule {
144-
getCommand?(
145-
opts: GetCommandsOptions
146-
): undefined | Command | Promise<Partial<Command> | undefined>;
163+
getCommand?: GetCommandFunction;
147164
}

0 commit comments

Comments
 (0)