@optique/discover 1.2.0-dev.2167 → 1.2.0-dev.2179
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.
- package/README.md +42 -17
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/cli.cjs +144 -0
- package/dist/cli.d.cts +10 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.js +143 -0
- package/dist/command.cjs +1 -1
- package/dist/command.d.ts +1 -1
- package/dist/generator-C12pIuFe.js +270 -0
- package/dist/generator-e4RwnDKG.cjs +288 -0
- package/dist/generator.cjs +7 -0
- package/dist/generator.d.cts +136 -0
- package/dist/generator.d.ts +136 -0
- package/dist/generator.js +5 -0
- package/dist/index.cjs +7 -694
- package/dist/index.d.cts +92 -4
- package/dist/index.d.ts +95 -7
- package/dist/index.js +2 -667
- package/dist/main-check-CwunSNpK.cjs +60 -0
- package/dist/main-check-mMnKfUZs.js +48 -0
- package/dist/main-check.cjs +4 -0
- package/dist/main-check.d.cts +72 -0
- package/dist/main-check.d.ts +72 -0
- package/dist/main-check.js +3 -0
- package/dist/src-BYGxdHGJ.cjs +784 -0
- package/dist/src-Ci75oZo-.js +754 -0
- package/package.json +18 -3
- /package/dist/{command-B0lV6NBO.cjs → command-CUn2_NIA.cjs} +0 -0
- /package/dist/{command-DyiVIMUh.d.ts → command-DrmNW0HO.d.ts} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -28,12 +28,31 @@ interface ProgramInvocation {
|
|
|
28
28
|
*/
|
|
29
29
|
readonly handler: (value: unknown) => void | Promise<void>;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* A command paired with its command path.
|
|
33
|
+
*
|
|
34
|
+
* `createProgramParser()` accepts command entries directly, and
|
|
35
|
+
* `runProgram({ commands })` accepts them alongside commands that declare
|
|
36
|
+
* their own `path` field.
|
|
37
|
+
*
|
|
38
|
+
* @since 1.2.0
|
|
39
|
+
*/
|
|
40
|
+
interface CommandEntry {
|
|
41
|
+
/**
|
|
42
|
+
* Command path used to place the command in the program tree.
|
|
43
|
+
*/
|
|
44
|
+
readonly path: CommandPath;
|
|
45
|
+
/**
|
|
46
|
+
* The command definition.
|
|
47
|
+
*/
|
|
48
|
+
readonly command: AnyCommand;
|
|
49
|
+
}
|
|
31
50
|
/**
|
|
32
51
|
* A command found on disk.
|
|
33
52
|
*
|
|
34
53
|
* @since 1.1.0
|
|
35
54
|
*/
|
|
36
|
-
interface DiscoveredCommand {
|
|
55
|
+
interface DiscoveredCommand extends CommandEntry {
|
|
37
56
|
/**
|
|
38
57
|
* Command path derived from the module's relative path.
|
|
39
58
|
*/
|
|
@@ -47,6 +66,26 @@ interface DiscoveredCommand {
|
|
|
47
66
|
*/
|
|
48
67
|
readonly command: AnyCommand;
|
|
49
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* A command loaded from a static module map.
|
|
71
|
+
*
|
|
72
|
+
* @since 1.2.0
|
|
73
|
+
*/
|
|
74
|
+
interface ModuleCommand extends CommandEntry {
|
|
75
|
+
/**
|
|
76
|
+
* Module map key used to derive the command path.
|
|
77
|
+
*/
|
|
78
|
+
readonly modulePath: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Static module map accepted by {@link commandsFromModules}.
|
|
82
|
+
*
|
|
83
|
+
* This matches eager glob import APIs such as Vite's
|
|
84
|
+
* `import.meta.glob(..., { eager: true })`.
|
|
85
|
+
*
|
|
86
|
+
* @since 1.2.0
|
|
87
|
+
*/
|
|
88
|
+
type ModuleMap = Readonly<Record<string, unknown>>;
|
|
50
89
|
/**
|
|
51
90
|
* Options for {@link discoverCommands}.
|
|
52
91
|
*
|
|
@@ -75,6 +114,35 @@ interface DiscoverCommandsOptions {
|
|
|
75
114
|
*/
|
|
76
115
|
readonly entryFileName?: string | false;
|
|
77
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Options for {@link commandsFromModules}.
|
|
119
|
+
*
|
|
120
|
+
* @since 1.2.0
|
|
121
|
+
*/
|
|
122
|
+
interface CommandsFromModulesOptions {
|
|
123
|
+
/**
|
|
124
|
+
* Base module path to strip before deriving command paths.
|
|
125
|
+
*
|
|
126
|
+
* @default `"."`
|
|
127
|
+
*/
|
|
128
|
+
readonly base?: string;
|
|
129
|
+
/**
|
|
130
|
+
* Module suffixes to include. Compound suffixes such as `.cmd.ts` are
|
|
131
|
+
* supported.
|
|
132
|
+
*
|
|
133
|
+
* @default Runtime-aware extension defaults from {@link getDefaultExtensions}
|
|
134
|
+
*/
|
|
135
|
+
readonly extensions?: readonly string[];
|
|
136
|
+
/**
|
|
137
|
+
* File name that maps to the containing command path after extension
|
|
138
|
+
* stripping. For example, `stash/index.ts` maps to `stash`, and root
|
|
139
|
+
* `index.ts` maps to the root command. Pass `false` to treat matching files
|
|
140
|
+
* as ordinary command names.
|
|
141
|
+
*
|
|
142
|
+
* @default `"index"`
|
|
143
|
+
*/
|
|
144
|
+
readonly entryFileName?: string | false;
|
|
145
|
+
}
|
|
78
146
|
/**
|
|
79
147
|
* Runtime hint for {@link getDefaultExtensions}.
|
|
80
148
|
*
|
|
@@ -165,8 +233,11 @@ interface RunProgramDiscoveryOptions extends RunProgramBaseOptions {
|
|
|
165
233
|
interface RunProgramStaticOptions extends RunProgramBaseOptions {
|
|
166
234
|
/**
|
|
167
235
|
* Commands to compose without file-system discovery.
|
|
236
|
+
*
|
|
237
|
+
* Pass commands that declare their own `path`, or command entries returned
|
|
238
|
+
* by {@link commandsFromModules}.
|
|
168
239
|
*/
|
|
169
|
-
readonly commands: readonly AnyStaticCommand[];
|
|
240
|
+
readonly commands: readonly (AnyStaticCommand | CommandEntry)[];
|
|
170
241
|
/**
|
|
171
242
|
* File-system discovery cannot be used together with `commands`.
|
|
172
243
|
*/
|
|
@@ -205,6 +276,23 @@ declare function getDefaultExtensions(options?: RuntimeExtensionOptions): readon
|
|
|
205
276
|
* @since 1.1.0
|
|
206
277
|
*/
|
|
207
278
|
declare function discoverCommands(options: DiscoverCommandsOptions): Promise<readonly DiscoveredCommand[]>;
|
|
279
|
+
/**
|
|
280
|
+
* Converts a static module map into command entries.
|
|
281
|
+
*
|
|
282
|
+
* This is useful for bundlers and single-file packagers that can statically
|
|
283
|
+
* see module maps, such as `import.meta.glob(..., { eager: true })`, while
|
|
284
|
+
* still deriving command paths from file-like module keys.
|
|
285
|
+
*
|
|
286
|
+
* @param modules Static module map keyed by module path.
|
|
287
|
+
* @param options Module path derivation options.
|
|
288
|
+
* @returns Command entries sorted by command path.
|
|
289
|
+
* @throws {TypeError} If options are invalid, no command modules are found,
|
|
290
|
+
* command paths are duplicated, a module does not default-export a
|
|
291
|
+
* command created with `defineCommand()`, or an explicit command
|
|
292
|
+
* `path` does not match the module-derived path.
|
|
293
|
+
* @since 1.2.0
|
|
294
|
+
*/
|
|
295
|
+
declare function commandsFromModules(modules: ModuleMap, options?: CommandsFromModulesOptions): readonly ModuleCommand[];
|
|
208
296
|
/**
|
|
209
297
|
* Builds a parser that dispatches to discovered command handlers.
|
|
210
298
|
*
|
|
@@ -215,7 +303,7 @@ declare function discoverCommands(options: DiscoverCommandsOptions): Promise<rea
|
|
|
215
303
|
* duplicated.
|
|
216
304
|
* @since 1.1.0
|
|
217
305
|
*/
|
|
218
|
-
declare function createProgramParser(commands: readonly
|
|
306
|
+
declare function createProgramParser(commands: readonly CommandEntry[], metadata?: ProgramHelpMetadata): Parser<Mode, ProgramInvocation, unknown>;
|
|
219
307
|
/**
|
|
220
308
|
* Discovers and runs a command program.
|
|
221
309
|
*
|
|
@@ -246,4 +334,4 @@ interface ProgramHelpMetadata {
|
|
|
246
334
|
readonly footer?: Message;
|
|
247
335
|
}
|
|
248
336
|
//#endregion
|
|
249
|
-
export { type AnyCommand, type AnyStaticCommand, type Command, type CommandDefinition, type CommandMetadata, type CommandPath, DiscoverCommandsOptions, DiscoveredCommand, ProgramHelpMetadata, ProgramInvocation, RunProgramDiscoveryOptions, RunProgramOptions, RunProgramStaticOptions, RuntimeExtensionOptions, type StaticCommand, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
|
|
337
|
+
export { type AnyCommand, type AnyStaticCommand, type Command, type CommandDefinition, CommandEntry, type CommandMetadata, type CommandPath, CommandsFromModulesOptions, DiscoverCommandsOptions, DiscoveredCommand, ModuleCommand, ModuleMap, ProgramHelpMetadata, ProgramInvocation, RunProgramDiscoveryOptions, RunProgramOptions, RunProgramStaticOptions, RuntimeExtensionOptions, type StaticCommand, commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, StaticCommand, defineCommand, isCommand } from "./command-
|
|
2
|
-
import { RunOptions } from "@optique/run";
|
|
3
|
-
import { Mode, Parser } from "@optique/core/parser";
|
|
1
|
+
import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, StaticCommand, defineCommand, isCommand } from "./command-DrmNW0HO.js";
|
|
4
2
|
import { Message } from "@optique/core/message";
|
|
5
3
|
import { ProgramMetadata } from "@optique/core/program";
|
|
4
|
+
import { RunOptions } from "@optique/run";
|
|
5
|
+
import { Mode, Parser } from "@optique/core/parser";
|
|
6
6
|
|
|
7
7
|
//#region src/index.d.ts
|
|
8
8
|
|
|
@@ -28,12 +28,31 @@ interface ProgramInvocation {
|
|
|
28
28
|
*/
|
|
29
29
|
readonly handler: (value: unknown) => void | Promise<void>;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* A command paired with its command path.
|
|
33
|
+
*
|
|
34
|
+
* `createProgramParser()` accepts command entries directly, and
|
|
35
|
+
* `runProgram({ commands })` accepts them alongside commands that declare
|
|
36
|
+
* their own `path` field.
|
|
37
|
+
*
|
|
38
|
+
* @since 1.2.0
|
|
39
|
+
*/
|
|
40
|
+
interface CommandEntry {
|
|
41
|
+
/**
|
|
42
|
+
* Command path used to place the command in the program tree.
|
|
43
|
+
*/
|
|
44
|
+
readonly path: CommandPath;
|
|
45
|
+
/**
|
|
46
|
+
* The command definition.
|
|
47
|
+
*/
|
|
48
|
+
readonly command: AnyCommand;
|
|
49
|
+
}
|
|
31
50
|
/**
|
|
32
51
|
* A command found on disk.
|
|
33
52
|
*
|
|
34
53
|
* @since 1.1.0
|
|
35
54
|
*/
|
|
36
|
-
interface DiscoveredCommand {
|
|
55
|
+
interface DiscoveredCommand extends CommandEntry {
|
|
37
56
|
/**
|
|
38
57
|
* Command path derived from the module's relative path.
|
|
39
58
|
*/
|
|
@@ -47,6 +66,26 @@ interface DiscoveredCommand {
|
|
|
47
66
|
*/
|
|
48
67
|
readonly command: AnyCommand;
|
|
49
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* A command loaded from a static module map.
|
|
71
|
+
*
|
|
72
|
+
* @since 1.2.0
|
|
73
|
+
*/
|
|
74
|
+
interface ModuleCommand extends CommandEntry {
|
|
75
|
+
/**
|
|
76
|
+
* Module map key used to derive the command path.
|
|
77
|
+
*/
|
|
78
|
+
readonly modulePath: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Static module map accepted by {@link commandsFromModules}.
|
|
82
|
+
*
|
|
83
|
+
* This matches eager glob import APIs such as Vite's
|
|
84
|
+
* `import.meta.glob(..., { eager: true })`.
|
|
85
|
+
*
|
|
86
|
+
* @since 1.2.0
|
|
87
|
+
*/
|
|
88
|
+
type ModuleMap = Readonly<Record<string, unknown>>;
|
|
50
89
|
/**
|
|
51
90
|
* Options for {@link discoverCommands}.
|
|
52
91
|
*
|
|
@@ -75,6 +114,35 @@ interface DiscoverCommandsOptions {
|
|
|
75
114
|
*/
|
|
76
115
|
readonly entryFileName?: string | false;
|
|
77
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Options for {@link commandsFromModules}.
|
|
119
|
+
*
|
|
120
|
+
* @since 1.2.0
|
|
121
|
+
*/
|
|
122
|
+
interface CommandsFromModulesOptions {
|
|
123
|
+
/**
|
|
124
|
+
* Base module path to strip before deriving command paths.
|
|
125
|
+
*
|
|
126
|
+
* @default `"."`
|
|
127
|
+
*/
|
|
128
|
+
readonly base?: string;
|
|
129
|
+
/**
|
|
130
|
+
* Module suffixes to include. Compound suffixes such as `.cmd.ts` are
|
|
131
|
+
* supported.
|
|
132
|
+
*
|
|
133
|
+
* @default Runtime-aware extension defaults from {@link getDefaultExtensions}
|
|
134
|
+
*/
|
|
135
|
+
readonly extensions?: readonly string[];
|
|
136
|
+
/**
|
|
137
|
+
* File name that maps to the containing command path after extension
|
|
138
|
+
* stripping. For example, `stash/index.ts` maps to `stash`, and root
|
|
139
|
+
* `index.ts` maps to the root command. Pass `false` to treat matching files
|
|
140
|
+
* as ordinary command names.
|
|
141
|
+
*
|
|
142
|
+
* @default `"index"`
|
|
143
|
+
*/
|
|
144
|
+
readonly entryFileName?: string | false;
|
|
145
|
+
}
|
|
78
146
|
/**
|
|
79
147
|
* Runtime hint for {@link getDefaultExtensions}.
|
|
80
148
|
*
|
|
@@ -165,8 +233,11 @@ interface RunProgramDiscoveryOptions extends RunProgramBaseOptions {
|
|
|
165
233
|
interface RunProgramStaticOptions extends RunProgramBaseOptions {
|
|
166
234
|
/**
|
|
167
235
|
* Commands to compose without file-system discovery.
|
|
236
|
+
*
|
|
237
|
+
* Pass commands that declare their own `path`, or command entries returned
|
|
238
|
+
* by {@link commandsFromModules}.
|
|
168
239
|
*/
|
|
169
|
-
readonly commands: readonly AnyStaticCommand[];
|
|
240
|
+
readonly commands: readonly (AnyStaticCommand | CommandEntry)[];
|
|
170
241
|
/**
|
|
171
242
|
* File-system discovery cannot be used together with `commands`.
|
|
172
243
|
*/
|
|
@@ -205,6 +276,23 @@ declare function getDefaultExtensions(options?: RuntimeExtensionOptions): readon
|
|
|
205
276
|
* @since 1.1.0
|
|
206
277
|
*/
|
|
207
278
|
declare function discoverCommands(options: DiscoverCommandsOptions): Promise<readonly DiscoveredCommand[]>;
|
|
279
|
+
/**
|
|
280
|
+
* Converts a static module map into command entries.
|
|
281
|
+
*
|
|
282
|
+
* This is useful for bundlers and single-file packagers that can statically
|
|
283
|
+
* see module maps, such as `import.meta.glob(..., { eager: true })`, while
|
|
284
|
+
* still deriving command paths from file-like module keys.
|
|
285
|
+
*
|
|
286
|
+
* @param modules Static module map keyed by module path.
|
|
287
|
+
* @param options Module path derivation options.
|
|
288
|
+
* @returns Command entries sorted by command path.
|
|
289
|
+
* @throws {TypeError} If options are invalid, no command modules are found,
|
|
290
|
+
* command paths are duplicated, a module does not default-export a
|
|
291
|
+
* command created with `defineCommand()`, or an explicit command
|
|
292
|
+
* `path` does not match the module-derived path.
|
|
293
|
+
* @since 1.2.0
|
|
294
|
+
*/
|
|
295
|
+
declare function commandsFromModules(modules: ModuleMap, options?: CommandsFromModulesOptions): readonly ModuleCommand[];
|
|
208
296
|
/**
|
|
209
297
|
* Builds a parser that dispatches to discovered command handlers.
|
|
210
298
|
*
|
|
@@ -215,7 +303,7 @@ declare function discoverCommands(options: DiscoverCommandsOptions): Promise<rea
|
|
|
215
303
|
* duplicated.
|
|
216
304
|
* @since 1.1.0
|
|
217
305
|
*/
|
|
218
|
-
declare function createProgramParser(commands: readonly
|
|
306
|
+
declare function createProgramParser(commands: readonly CommandEntry[], metadata?: ProgramHelpMetadata): Parser<Mode, ProgramInvocation, unknown>;
|
|
219
307
|
/**
|
|
220
308
|
* Discovers and runs a command program.
|
|
221
309
|
*
|
|
@@ -246,4 +334,4 @@ interface ProgramHelpMetadata {
|
|
|
246
334
|
readonly footer?: Message;
|
|
247
335
|
}
|
|
248
336
|
//#endregion
|
|
249
|
-
export { type AnyCommand, type AnyStaticCommand, type Command, type CommandDefinition, type CommandMetadata, type CommandPath, DiscoverCommandsOptions, DiscoveredCommand, ProgramHelpMetadata, ProgramInvocation, RunProgramDiscoveryOptions, RunProgramOptions, RunProgramStaticOptions, RuntimeExtensionOptions, type StaticCommand, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
|
|
337
|
+
export { type AnyCommand, type AnyStaticCommand, type Command, type CommandDefinition, CommandEntry, type CommandMetadata, type CommandPath, CommandsFromModulesOptions, DiscoverCommandsOptions, DiscoveredCommand, ModuleCommand, ModuleMap, ProgramHelpMetadata, ProgramInvocation, RunProgramDiscoveryOptions, RunProgramOptions, RunProgramStaticOptions, RuntimeExtensionOptions, type StaticCommand, commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
|