@optique/discover 1.2.0-dev.2331 → 1.2.0-dev.2335

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/dist/cli.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  const require_chunk = require('./chunk-CUT6urMc.cjs');
3
3
  require('./command-C-NgG0KJ.cjs');
4
- require('./src-BAFFLASv.cjs');
5
- const require_generator = require('./generator-DX58yLaB.cjs');
4
+ require('./src-DL9BHbjo.cjs');
5
+ const require_generator = require('./generator-B0OvR99S.cjs');
6
6
  const require_main_check = require('./main-check-CwunSNpK.cjs');
7
7
  const __optique_core_constructs = require_chunk.__toESM(require("@optique/core/constructs"));
8
8
  const __optique_core_message = require_chunk.__toESM(require("@optique/core/message"));
@@ -15,7 +15,7 @@ const node_process = require_chunk.__toESM(require("node:process"));
15
15
 
16
16
  //#region deno.json
17
17
  var name = "@optique/discover";
18
- var version = "1.2.0-dev.2331+0f3b5a2e";
18
+ var version = "1.2.0-dev.2335+26079d6b";
19
19
  var license = "MIT";
20
20
  var exports$1 = {
21
21
  ".": "./src/index.ts",
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import "./command-9sgrJtwh.js";
3
- import "./src-Bxt-nAIP.js";
4
- import { watchCommandsModule, writeCommandsModule } from "./generator-wG1l1zon.js";
3
+ import "./src-BT2FzGqZ.js";
4
+ import { watchCommandsModule, writeCommandsModule } from "./generator-BY2Tdodb.js";
5
5
  import { isMainModuleUrl } from "./main-check-mMnKfUZs.js";
6
6
  import { object } from "@optique/core/constructs";
7
7
  import { message } from "@optique/core/message";
@@ -14,7 +14,7 @@ import process from "node:process";
14
14
 
15
15
  //#region deno.json
16
16
  var name = "@optique/discover";
17
- var version = "1.2.0-dev.2331+0f3b5a2e";
17
+ var version = "1.2.0-dev.2335+26079d6b";
18
18
  var license = "MIT";
19
19
  var exports = {
20
20
  ".": "./src/index.ts",
@@ -139,6 +139,22 @@ interface ProgramHooks<R = unknown> {
139
139
  */
140
140
  readonly onError?: (context: ProgramHookContext<R>, error: unknown) => void | Promise<void>;
141
141
  }
142
+ /**
143
+ * Lifecycle hooks that always create their own command context.
144
+ *
145
+ * @internal
146
+ */
147
+ type ProgramHooksWithBeforeEach<R> = ProgramHooks<R> & {
148
+ readonly beforeEach: NonNullable<ProgramHooks<R>["beforeEach"]>;
149
+ };
150
+ /**
151
+ * Lifecycle hooks that do not replace the program-level command context.
152
+ *
153
+ * @internal
154
+ */
155
+ type ProgramHooksWithoutBeforeEach<R> = Omit<ProgramHooks<R>, "beforeEach"> & {
156
+ readonly beforeEach?: undefined;
157
+ };
142
158
  /**
143
159
  * Input accepted by {@link defineCommand}.
144
160
  *
@@ -222,6 +238,34 @@ interface StaticCommand<M extends Mode, T, R = unknown> extends Command<M, T, R>
222
238
  */
223
239
  readonly path: CommandPath;
224
240
  }
241
+ /**
242
+ * A command whose hooks always create their own command context.
243
+ *
244
+ * @internal
245
+ */
246
+ type CommandWithBeforeEach<M extends Mode, T, R> = Command<M, T, R> & {
247
+ readonly hooks: ProgramHooksWithBeforeEach<R>;
248
+ };
249
+ /**
250
+ * A static command whose hooks always create their own command context.
251
+ *
252
+ * @internal
253
+ */
254
+ type StaticCommandWithBeforeEach<M extends Mode, T, R> = StaticCommand<M, T, R> & CommandWithBeforeEach<M, T, R>;
255
+ /**
256
+ * A command that does not create its own command context.
257
+ *
258
+ * @internal
259
+ */
260
+ type CommandWithoutBeforeEach<M extends Mode, T, R> = Omit<Command<M, T, R>, "hooks"> & {
261
+ readonly hooks?: ProgramHooksWithoutBeforeEach<R>;
262
+ };
263
+ /**
264
+ * A static command that does not create its own command context.
265
+ *
266
+ * @internal
267
+ */
268
+ type StaticCommandWithoutBeforeEach<M extends Mode, T, R> = Omit<StaticCommand<M, T, R>, "hooks"> & CommandWithoutBeforeEach<M, T, R>;
225
269
  /**
226
270
  * Lifecycle hooks whose caller-defined resource type has been erased.
227
271
  *
@@ -232,6 +276,14 @@ interface ErasedProgramHooks {
232
276
  readonly afterEach?: ProgramHooks<never>["afterEach"];
233
277
  readonly onError?: ProgramHooks<never>["onError"];
234
278
  }
279
+ /**
280
+ * Erased lifecycle hooks that always create their own command context.
281
+ *
282
+ * @internal
283
+ */
284
+ interface ErasedProgramHooksWithBeforeEach extends ErasedProgramHooks {
285
+ readonly beforeEach: NonNullable<ErasedProgramHooks["beforeEach"]>;
286
+ }
235
287
  /**
236
288
  * A command with its handler value type erased.
237
289
  *
@@ -266,6 +318,62 @@ type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler" | "hooks">
266
318
  */
267
319
  readonly handler: (value: never, context?: ProgramHookContext<never>) => void | Promise<void>;
268
320
  };
321
+ /**
322
+ * A type-erased command whose handler consumes a program-level resource.
323
+ *
324
+ * @internal
325
+ */
326
+ type ProgramResourceCommand<R> = Omit<Command<Mode, unknown, R>, "handler"> & {
327
+ readonly handler: (value: never, context?: ProgramHookContext<R>) => void | Promise<void>;
328
+ };
329
+ /**
330
+ * A type-erased command that always creates its own command context.
331
+ *
332
+ * @internal
333
+ */
334
+ type OwnResourceCommand = Omit<AnyCommand, "hooks"> & {
335
+ readonly hooks: ErasedProgramHooksWithBeforeEach;
336
+ };
337
+ /**
338
+ * A type-erased static command whose handler consumes a program-level
339
+ * resource.
340
+ *
341
+ * @internal
342
+ */
343
+ type ProgramResourceStaticCommand<R> = Omit<StaticCommand<Mode, unknown, R>, "handler"> & {
344
+ readonly handler: (value: never, context?: ProgramHookContext<R>) => void | Promise<void>;
345
+ };
346
+ /**
347
+ * A type-erased static command that always creates its own command context.
348
+ *
349
+ * @internal
350
+ */
351
+ type OwnResourceStaticCommand = Omit<AnyStaticCommand, "hooks"> & {
352
+ readonly hooks: ErasedProgramHooksWithBeforeEach;
353
+ };
354
+ /**
355
+ * A command accepted by `runProgram()` with a program-level resource type.
356
+ *
357
+ * Commands without a command-level `beforeEach` must consume `R`. A command
358
+ * that always creates its own context may use a different resource type.
359
+ * Untyped calls retain the fully erased command shape for compatibility.
360
+ *
361
+ * @template R The resource made available by program-level lifecycle hooks.
362
+ * @since 1.2.0
363
+ */
364
+ type RunProgramCommand<R = unknown> = unknown extends R ? AnyCommand : ProgramResourceCommand<R> | OwnResourceCommand;
365
+ /**
366
+ * A static command accepted by `runProgram()` with a program-level resource
367
+ * type.
368
+ *
369
+ * Commands without a command-level `beforeEach` must consume `R`. A command
370
+ * that always creates its own context may use a different resource type.
371
+ * Untyped calls retain the fully erased command shape for compatibility.
372
+ *
373
+ * @template R The resource made available by program-level lifecycle hooks.
374
+ * @since 1.2.0
375
+ */
376
+ type RunProgramStaticCommand<R = unknown> = unknown extends R ? AnyStaticCommand : ProgramResourceStaticCommand<R> | OwnResourceStaticCommand;
269
377
  /**
270
378
  * Defines a command module for `@optique/discover`.
271
379
  *
@@ -281,6 +389,22 @@ type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler" | "hooks">
281
389
  * malformed.
282
390
  * @since 1.1.0
283
391
  */
392
+ declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
393
+ readonly path: CommandPath;
394
+ } & {
395
+ readonly hooks: ProgramHooksWithBeforeEach<R>;
396
+ }): StaticCommandWithBeforeEach<M, T, R>;
397
+ declare function defineCommand<M extends Mode, T, R = unknown>(command: Omit<CommandDefinition<M, T, R>, "hooks"> & {
398
+ readonly path: CommandPath;
399
+ } & {
400
+ readonly hooks?: ProgramHooksWithoutBeforeEach<R>;
401
+ }): StaticCommandWithoutBeforeEach<M, T, R>;
402
+ declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
403
+ readonly hooks: ProgramHooksWithBeforeEach<R>;
404
+ }): CommandWithBeforeEach<M, T, R>;
405
+ declare function defineCommand<M extends Mode, T, R = unknown>(command: Omit<CommandDefinition<M, T, R>, "hooks"> & {
406
+ readonly hooks?: ProgramHooksWithoutBeforeEach<R>;
407
+ }): CommandWithoutBeforeEach<M, T, R>;
284
408
  declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
285
409
  readonly path: CommandPath;
286
410
  }): StaticCommand<M, T, R>;
@@ -306,4 +430,4 @@ declare function isCommand(value: unknown): value is AnyCommand;
306
430
  */
307
431
  declare function validateHooks(hooks: unknown, scope: "Command" | "Program"): asserts hooks is ProgramHooks;
308
432
  //#endregion
309
- export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks };
433
+ export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand, validateHooks };
@@ -139,6 +139,22 @@ interface ProgramHooks<R = unknown> {
139
139
  */
140
140
  readonly onError?: (context: ProgramHookContext<R>, error: unknown) => void | Promise<void>;
141
141
  }
142
+ /**
143
+ * Lifecycle hooks that always create their own command context.
144
+ *
145
+ * @internal
146
+ */
147
+ type ProgramHooksWithBeforeEach<R> = ProgramHooks<R> & {
148
+ readonly beforeEach: NonNullable<ProgramHooks<R>["beforeEach"]>;
149
+ };
150
+ /**
151
+ * Lifecycle hooks that do not replace the program-level command context.
152
+ *
153
+ * @internal
154
+ */
155
+ type ProgramHooksWithoutBeforeEach<R> = Omit<ProgramHooks<R>, "beforeEach"> & {
156
+ readonly beforeEach?: undefined;
157
+ };
142
158
  /**
143
159
  * Input accepted by {@link defineCommand}.
144
160
  *
@@ -222,6 +238,34 @@ interface StaticCommand<M extends Mode, T, R = unknown> extends Command<M, T, R>
222
238
  */
223
239
  readonly path: CommandPath;
224
240
  }
241
+ /**
242
+ * A command whose hooks always create their own command context.
243
+ *
244
+ * @internal
245
+ */
246
+ type CommandWithBeforeEach<M extends Mode, T, R> = Command<M, T, R> & {
247
+ readonly hooks: ProgramHooksWithBeforeEach<R>;
248
+ };
249
+ /**
250
+ * A static command whose hooks always create their own command context.
251
+ *
252
+ * @internal
253
+ */
254
+ type StaticCommandWithBeforeEach<M extends Mode, T, R> = StaticCommand<M, T, R> & CommandWithBeforeEach<M, T, R>;
255
+ /**
256
+ * A command that does not create its own command context.
257
+ *
258
+ * @internal
259
+ */
260
+ type CommandWithoutBeforeEach<M extends Mode, T, R> = Omit<Command<M, T, R>, "hooks"> & {
261
+ readonly hooks?: ProgramHooksWithoutBeforeEach<R>;
262
+ };
263
+ /**
264
+ * A static command that does not create its own command context.
265
+ *
266
+ * @internal
267
+ */
268
+ type StaticCommandWithoutBeforeEach<M extends Mode, T, R> = Omit<StaticCommand<M, T, R>, "hooks"> & CommandWithoutBeforeEach<M, T, R>;
225
269
  /**
226
270
  * Lifecycle hooks whose caller-defined resource type has been erased.
227
271
  *
@@ -232,6 +276,14 @@ interface ErasedProgramHooks {
232
276
  readonly afterEach?: ProgramHooks<never>["afterEach"];
233
277
  readonly onError?: ProgramHooks<never>["onError"];
234
278
  }
279
+ /**
280
+ * Erased lifecycle hooks that always create their own command context.
281
+ *
282
+ * @internal
283
+ */
284
+ interface ErasedProgramHooksWithBeforeEach extends ErasedProgramHooks {
285
+ readonly beforeEach: NonNullable<ErasedProgramHooks["beforeEach"]>;
286
+ }
235
287
  /**
236
288
  * A command with its handler value type erased.
237
289
  *
@@ -266,6 +318,62 @@ type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler" | "hooks">
266
318
  */
267
319
  readonly handler: (value: never, context?: ProgramHookContext<never>) => void | Promise<void>;
268
320
  };
321
+ /**
322
+ * A type-erased command whose handler consumes a program-level resource.
323
+ *
324
+ * @internal
325
+ */
326
+ type ProgramResourceCommand<R> = Omit<Command<Mode, unknown, R>, "handler"> & {
327
+ readonly handler: (value: never, context?: ProgramHookContext<R>) => void | Promise<void>;
328
+ };
329
+ /**
330
+ * A type-erased command that always creates its own command context.
331
+ *
332
+ * @internal
333
+ */
334
+ type OwnResourceCommand = Omit<AnyCommand, "hooks"> & {
335
+ readonly hooks: ErasedProgramHooksWithBeforeEach;
336
+ };
337
+ /**
338
+ * A type-erased static command whose handler consumes a program-level
339
+ * resource.
340
+ *
341
+ * @internal
342
+ */
343
+ type ProgramResourceStaticCommand<R> = Omit<StaticCommand<Mode, unknown, R>, "handler"> & {
344
+ readonly handler: (value: never, context?: ProgramHookContext<R>) => void | Promise<void>;
345
+ };
346
+ /**
347
+ * A type-erased static command that always creates its own command context.
348
+ *
349
+ * @internal
350
+ */
351
+ type OwnResourceStaticCommand = Omit<AnyStaticCommand, "hooks"> & {
352
+ readonly hooks: ErasedProgramHooksWithBeforeEach;
353
+ };
354
+ /**
355
+ * A command accepted by `runProgram()` with a program-level resource type.
356
+ *
357
+ * Commands without a command-level `beforeEach` must consume `R`. A command
358
+ * that always creates its own context may use a different resource type.
359
+ * Untyped calls retain the fully erased command shape for compatibility.
360
+ *
361
+ * @template R The resource made available by program-level lifecycle hooks.
362
+ * @since 1.2.0
363
+ */
364
+ type RunProgramCommand<R = unknown> = unknown extends R ? AnyCommand : ProgramResourceCommand<R> | OwnResourceCommand;
365
+ /**
366
+ * A static command accepted by `runProgram()` with a program-level resource
367
+ * type.
368
+ *
369
+ * Commands without a command-level `beforeEach` must consume `R`. A command
370
+ * that always creates its own context may use a different resource type.
371
+ * Untyped calls retain the fully erased command shape for compatibility.
372
+ *
373
+ * @template R The resource made available by program-level lifecycle hooks.
374
+ * @since 1.2.0
375
+ */
376
+ type RunProgramStaticCommand<R = unknown> = unknown extends R ? AnyStaticCommand : ProgramResourceStaticCommand<R> | OwnResourceStaticCommand;
269
377
  /**
270
378
  * Defines a command module for `@optique/discover`.
271
379
  *
@@ -281,6 +389,22 @@ type AnyStaticCommand = Omit<StaticCommand<Mode, unknown>, "handler" | "hooks">
281
389
  * malformed.
282
390
  * @since 1.1.0
283
391
  */
392
+ declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
393
+ readonly path: CommandPath;
394
+ } & {
395
+ readonly hooks: ProgramHooksWithBeforeEach<R>;
396
+ }): StaticCommandWithBeforeEach<M, T, R>;
397
+ declare function defineCommand<M extends Mode, T, R = unknown>(command: Omit<CommandDefinition<M, T, R>, "hooks"> & {
398
+ readonly path: CommandPath;
399
+ } & {
400
+ readonly hooks?: ProgramHooksWithoutBeforeEach<R>;
401
+ }): StaticCommandWithoutBeforeEach<M, T, R>;
402
+ declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
403
+ readonly hooks: ProgramHooksWithBeforeEach<R>;
404
+ }): CommandWithBeforeEach<M, T, R>;
405
+ declare function defineCommand<M extends Mode, T, R = unknown>(command: Omit<CommandDefinition<M, T, R>, "hooks"> & {
406
+ readonly hooks?: ProgramHooksWithoutBeforeEach<R>;
407
+ }): CommandWithoutBeforeEach<M, T, R>;
284
408
  declare function defineCommand<M extends Mode, T, R = unknown>(command: CommandDefinition<M, T, R> & {
285
409
  readonly path: CommandPath;
286
410
  }): StaticCommand<M, T, R>;
@@ -306,4 +430,4 @@ declare function isCommand(value: unknown): value is AnyCommand;
306
430
  */
307
431
  declare function validateHooks(hooks: unknown, scope: "Command" | "Program"): asserts hooks is ProgramHooks;
308
432
  //#endregion
309
- export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks };
433
+ export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand, validateHooks };
@@ -1,2 +1,2 @@
1
- import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks } from "./command-ChWCwb3x.cjs";
2
- export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks };
1
+ import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand, validateHooks } from "./command-BtjFShKT.cjs";
2
+ export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand, validateHooks };
package/dist/command.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks } from "./command-CYwk-AJC.js";
2
- export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand, validateHooks };
1
+ import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand, validateHooks } from "./command-BaFBKA4c.js";
2
+ export { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand, validateHooks };
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_src = require('./src-BAFFLASv.cjs');
2
+ const require_src = require('./src-DL9BHbjo.cjs');
3
3
  const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
4
4
  const node_path = require_chunk.__toESM(require("node:path"));
5
5
  const node_url = require_chunk.__toESM(require("node:url"));
@@ -1,4 +1,4 @@
1
- import { getDefaultExtensions } from "./src-Bxt-nAIP.js";
1
+ import { getDefaultExtensions } from "./src-BT2FzGqZ.js";
2
2
  import { mkdir, readdir, realpath, stat, writeFile } from "node:fs/promises";
3
3
  import { dirname, posix, relative, resolve } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
@@ -1,6 +1,6 @@
1
1
  require('./command-C-NgG0KJ.cjs');
2
- require('./src-BAFFLASv.cjs');
3
- const require_generator = require('./generator-DX58yLaB.cjs');
2
+ require('./src-DL9BHbjo.cjs');
3
+ const require_generator = require('./generator-B0OvR99S.cjs');
4
4
 
5
5
  exports.generateCommandsModule = require_generator.generateCommandsModule;
6
6
  exports.watchCommandsModule = require_generator.watchCommandsModule;
package/dist/generator.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./command-9sgrJtwh.js";
2
- import "./src-Bxt-nAIP.js";
3
- import { generateCommandsModule, watchCommandsModule, writeCommandsModule } from "./generator-wG1l1zon.js";
2
+ import "./src-BT2FzGqZ.js";
3
+ import { generateCommandsModule, watchCommandsModule, writeCommandsModule } from "./generator-BY2Tdodb.js";
4
4
 
5
5
  export { generateCommandsModule, watchCommandsModule, writeCommandsModule };
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  const require_command = require('./command-C-NgG0KJ.cjs');
2
- const require_src = require('./src-BAFFLASv.cjs');
2
+ const require_src = require('./src-DL9BHbjo.cjs');
3
3
 
4
4
  exports.commandsFromModules = require_src.commandsFromModules;
5
5
  exports.createProgramParser = require_src.createProgramParser;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand } from "./command-ChWCwb3x.cjs";
1
+ import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand } from "./command-BtjFShKT.cjs";
2
2
  import { Mode } from "@optique/core/parser";
3
3
  import { FluentParser } from "@optique/core/fluent";
4
4
  import { Message } from "@optique/core/message";
@@ -26,6 +26,20 @@ interface CommandEntry {
26
26
  */
27
27
  readonly command: AnyCommand;
28
28
  }
29
+ /**
30
+ * A command entry accepted by `runProgram()` with a program-level resource
31
+ * type.
32
+ *
33
+ * @template R The resource made available by program-level lifecycle hooks.
34
+ * @since 1.2.0
35
+ */
36
+ type RunProgramCommandEntry<R = unknown> = Omit<CommandEntry, "command"> & {
37
+ /**
38
+ * A command compatible with the program-level resource, or one that
39
+ * always creates its own command context.
40
+ */
41
+ readonly command: RunProgramCommand<R>;
42
+ };
29
43
  /**
30
44
  * A command found on disk.
31
45
  *
@@ -48,9 +62,15 @@ interface DiscoveredCommand extends CommandEntry {
48
62
  /**
49
63
  * A command loaded from a static module map.
50
64
  *
65
+ * @template R The program-level resource used by commands without their own
66
+ * `beforeEach` hook.
51
67
  * @since 1.2.0
52
68
  */
53
- interface ModuleCommand extends CommandEntry {
69
+ interface ModuleCommand<R = unknown> extends CommandEntry {
70
+ /**
71
+ * The command definition.
72
+ */
73
+ readonly command: RunProgramCommand<R>;
54
74
  /**
55
75
  * Module map key used to derive the command path.
56
76
  */
@@ -230,7 +250,7 @@ interface RunProgramStaticOptions<R = unknown> extends RunProgramBaseOptions<R>
230
250
  * Pass commands that declare their own `path`, or command entries returned
231
251
  * by {@link commandsFromModules}.
232
252
  */
233
- readonly commands: readonly (AnyStaticCommand | CommandEntry)[];
253
+ readonly commands: readonly (RunProgramStaticCommand<NoInfer<R>> | RunProgramCommandEntry<NoInfer<R>>)[];
234
254
  /**
235
255
  * File-system discovery cannot be used together with `commands`.
236
256
  */
@@ -277,6 +297,8 @@ declare function discoverCommands(options: DiscoverCommandsOptions): Promise<rea
277
297
  * see module maps, such as `import.meta.glob(..., { eager: true })`, while
278
298
  * still deriving command paths from file-like module keys.
279
299
  *
300
+ * @template R The program-level resource used by commands without their own
301
+ * `beforeEach` hook.
280
302
  * @param modules Static module map keyed by module path.
281
303
  * @param options Module path derivation options.
282
304
  * @returns Command entries sorted by command path.
@@ -286,7 +308,7 @@ declare function discoverCommands(options: DiscoverCommandsOptions): Promise<rea
286
308
  * `path` does not match the module-derived path.
287
309
  * @since 1.2.0
288
310
  */
289
- declare function commandsFromModules(modules: ModuleMap, options?: CommandsFromModulesOptions): readonly ModuleCommand[];
311
+ declare function commandsFromModules<R = unknown>(modules: ModuleMap, options?: CommandsFromModulesOptions): readonly ModuleCommand<R>[];
290
312
  /**
291
313
  * Builds a parser that dispatches to discovered command handlers.
292
314
  *
@@ -343,4 +365,4 @@ interface CreateProgramParserOptions extends ProgramHelpMetadata {
343
365
  readonly commandList?: RunOptions["commandList"];
344
366
  }
345
367
  //#endregion
346
- export { type AnyCommand, type AnyStaticCommand, type Command, type CommandDefinition, CommandEntry, type CommandMetadata, type CommandPath, CommandsFromModulesOptions, CreateProgramParserOptions, DiscoverCommandsOptions, DiscoveredCommand, ModuleCommand, ModuleMap, ProgramHelpMetadata, type ProgramHookContext, type ProgramHooks, type ProgramInvocation, RunProgramDiscoveryOptions, RunProgramOptions, RunProgramStaticOptions, RuntimeExtensionOptions, type StaticCommand, commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
368
+ export { type AnyCommand, type AnyStaticCommand, type Command, type CommandDefinition, CommandEntry, type CommandMetadata, type CommandPath, CommandsFromModulesOptions, CreateProgramParserOptions, DiscoverCommandsOptions, DiscoveredCommand, ModuleCommand, ModuleMap, ProgramHelpMetadata, type ProgramHookContext, type ProgramHooks, type ProgramInvocation, type RunProgramCommand, RunProgramCommandEntry, RunProgramDiscoveryOptions, RunProgramOptions, type RunProgramStaticCommand, RunProgramStaticOptions, RuntimeExtensionOptions, type StaticCommand, commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, StaticCommand, defineCommand, isCommand } from "./command-CYwk-AJC.js";
1
+ import { AnyCommand, AnyStaticCommand, Command, CommandDefinition, CommandMetadata, CommandPath, ProgramHookContext, ProgramHooks, ProgramInvocation, RunProgramCommand, RunProgramStaticCommand, StaticCommand, defineCommand, isCommand } from "./command-BaFBKA4c.js";
2
2
  import { Message } from "@optique/core/message";
3
3
  import { ProgramMetadata } from "@optique/core/program";
4
4
  import { RunOptions } from "@optique/run";
@@ -26,6 +26,20 @@ interface CommandEntry {
26
26
  */
27
27
  readonly command: AnyCommand;
28
28
  }
29
+ /**
30
+ * A command entry accepted by `runProgram()` with a program-level resource
31
+ * type.
32
+ *
33
+ * @template R The resource made available by program-level lifecycle hooks.
34
+ * @since 1.2.0
35
+ */
36
+ type RunProgramCommandEntry<R = unknown> = Omit<CommandEntry, "command"> & {
37
+ /**
38
+ * A command compatible with the program-level resource, or one that
39
+ * always creates its own command context.
40
+ */
41
+ readonly command: RunProgramCommand<R>;
42
+ };
29
43
  /**
30
44
  * A command found on disk.
31
45
  *
@@ -48,9 +62,15 @@ interface DiscoveredCommand extends CommandEntry {
48
62
  /**
49
63
  * A command loaded from a static module map.
50
64
  *
65
+ * @template R The program-level resource used by commands without their own
66
+ * `beforeEach` hook.
51
67
  * @since 1.2.0
52
68
  */
53
- interface ModuleCommand extends CommandEntry {
69
+ interface ModuleCommand<R = unknown> extends CommandEntry {
70
+ /**
71
+ * The command definition.
72
+ */
73
+ readonly command: RunProgramCommand<R>;
54
74
  /**
55
75
  * Module map key used to derive the command path.
56
76
  */
@@ -230,7 +250,7 @@ interface RunProgramStaticOptions<R = unknown> extends RunProgramBaseOptions<R>
230
250
  * Pass commands that declare their own `path`, or command entries returned
231
251
  * by {@link commandsFromModules}.
232
252
  */
233
- readonly commands: readonly (AnyStaticCommand | CommandEntry)[];
253
+ readonly commands: readonly (RunProgramStaticCommand<NoInfer<R>> | RunProgramCommandEntry<NoInfer<R>>)[];
234
254
  /**
235
255
  * File-system discovery cannot be used together with `commands`.
236
256
  */
@@ -277,6 +297,8 @@ declare function discoverCommands(options: DiscoverCommandsOptions): Promise<rea
277
297
  * see module maps, such as `import.meta.glob(..., { eager: true })`, while
278
298
  * still deriving command paths from file-like module keys.
279
299
  *
300
+ * @template R The program-level resource used by commands without their own
301
+ * `beforeEach` hook.
280
302
  * @param modules Static module map keyed by module path.
281
303
  * @param options Module path derivation options.
282
304
  * @returns Command entries sorted by command path.
@@ -286,7 +308,7 @@ declare function discoverCommands(options: DiscoverCommandsOptions): Promise<rea
286
308
  * `path` does not match the module-derived path.
287
309
  * @since 1.2.0
288
310
  */
289
- declare function commandsFromModules(modules: ModuleMap, options?: CommandsFromModulesOptions): readonly ModuleCommand[];
311
+ declare function commandsFromModules<R = unknown>(modules: ModuleMap, options?: CommandsFromModulesOptions): readonly ModuleCommand<R>[];
290
312
  /**
291
313
  * Builds a parser that dispatches to discovered command handlers.
292
314
  *
@@ -343,4 +365,4 @@ interface CreateProgramParserOptions extends ProgramHelpMetadata {
343
365
  readonly commandList?: RunOptions["commandList"];
344
366
  }
345
367
  //#endregion
346
- export { type AnyCommand, type AnyStaticCommand, type Command, type CommandDefinition, CommandEntry, type CommandMetadata, type CommandPath, CommandsFromModulesOptions, CreateProgramParserOptions, DiscoverCommandsOptions, DiscoveredCommand, ModuleCommand, ModuleMap, ProgramHelpMetadata, type ProgramHookContext, type ProgramHooks, type ProgramInvocation, RunProgramDiscoveryOptions, RunProgramOptions, RunProgramStaticOptions, RuntimeExtensionOptions, type StaticCommand, commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
368
+ export { type AnyCommand, type AnyStaticCommand, type Command, type CommandDefinition, CommandEntry, type CommandMetadata, type CommandPath, CommandsFromModulesOptions, CreateProgramParserOptions, DiscoverCommandsOptions, DiscoveredCommand, ModuleCommand, ModuleMap, ProgramHelpMetadata, type ProgramHookContext, type ProgramHooks, type ProgramInvocation, type RunProgramCommand, RunProgramCommandEntry, RunProgramDiscoveryOptions, RunProgramOptions, type RunProgramStaticCommand, RunProgramStaticOptions, RuntimeExtensionOptions, type StaticCommand, commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { defineCommand, isCommand } from "./command-9sgrJtwh.js";
2
- import { commandsFromModules, createProgramParser, discoverCommands, getDefaultExtensions, runProgram } from "./src-Bxt-nAIP.js";
2
+ import { commandsFromModules, createProgramParser, discoverCommands, getDefaultExtensions, runProgram } from "./src-BT2FzGqZ.js";
3
3
 
4
4
  export { commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
@@ -80,6 +80,8 @@ async function discoverCommands(options) {
80
80
  * see module maps, such as `import.meta.glob(..., { eager: true })`, while
81
81
  * still deriving command paths from file-like module keys.
82
82
  *
83
+ * @template R The program-level resource used by commands without their own
84
+ * `beforeEach` hook.
83
85
  * @param modules Static module map keyed by module path.
84
86
  * @param options Module path derivation options.
85
87
  * @returns Command entries sorted by command path.
@@ -188,7 +190,7 @@ async function dispatchInvocation(invocation, programHooks) {
188
190
  if (commandHooks?.beforeEach != null) return invocation.handler(invocation.value, commandContext);
189
191
  if (programHooks?.beforeEach != null) return invocation.handler(invocation.value, programContext);
190
192
  return invocation.handler(invocation.value);
191
- }));
193
+ }, programContext));
192
194
  }
193
195
  /**
194
196
  * Runs an inner step wrapped in a single set of lifecycle hooks.
@@ -196,13 +198,14 @@ async function dispatchInvocation(invocation, programHooks) {
196
198
  * @param hooks The hooks for this scope, if any.
197
199
  * @param invocation The selected command invocation passed to `beforeEach`.
198
200
  * @param inner The step to wrap; receives the context from `beforeEach`.
201
+ * @param fallbackContext The context used when `beforeEach` is absent.
199
202
  * @returns The value returned by `inner`.
200
203
  * @throws The original error thrown by `beforeEach`, `inner`, or `afterEach`,
201
204
  * re-thrown after `onError` runs. An error thrown by `onError` itself
202
205
  * is suppressed so it cannot mask the original failure.
203
206
  */
204
- async function runHookScope(hooks, invocation, inner) {
205
- let context = {};
207
+ async function runHookScope(hooks, invocation, inner, fallbackContext = {}) {
208
+ let context = fallbackContext;
206
209
  try {
207
210
  if (hooks?.beforeEach != null) context = await hooks.beforeEach(invocation) ?? {};
208
211
  const result = await inner(context);
@@ -81,6 +81,8 @@ async function discoverCommands(options) {
81
81
  * see module maps, such as `import.meta.glob(..., { eager: true })`, while
82
82
  * still deriving command paths from file-like module keys.
83
83
  *
84
+ * @template R The program-level resource used by commands without their own
85
+ * `beforeEach` hook.
84
86
  * @param modules Static module map keyed by module path.
85
87
  * @param options Module path derivation options.
86
88
  * @returns Command entries sorted by command path.
@@ -189,7 +191,7 @@ async function dispatchInvocation(invocation, programHooks) {
189
191
  if (commandHooks?.beforeEach != null) return invocation.handler(invocation.value, commandContext);
190
192
  if (programHooks?.beforeEach != null) return invocation.handler(invocation.value, programContext);
191
193
  return invocation.handler(invocation.value);
192
- }));
194
+ }, programContext));
193
195
  }
194
196
  /**
195
197
  * Runs an inner step wrapped in a single set of lifecycle hooks.
@@ -197,13 +199,14 @@ async function dispatchInvocation(invocation, programHooks) {
197
199
  * @param hooks The hooks for this scope, if any.
198
200
  * @param invocation The selected command invocation passed to `beforeEach`.
199
201
  * @param inner The step to wrap; receives the context from `beforeEach`.
202
+ * @param fallbackContext The context used when `beforeEach` is absent.
200
203
  * @returns The value returned by `inner`.
201
204
  * @throws The original error thrown by `beforeEach`, `inner`, or `afterEach`,
202
205
  * re-thrown after `onError` runs. An error thrown by `onError` itself
203
206
  * is suppressed so it cannot mask the original failure.
204
207
  */
205
- async function runHookScope(hooks, invocation, inner) {
206
- let context = {};
208
+ async function runHookScope(hooks, invocation, inner, fallbackContext = {}) {
209
+ let context = fallbackContext;
207
210
  try {
208
211
  if (hooks?.beforeEach != null) context = await hooks.beforeEach(invocation) ?? {};
209
212
  const result = await inner(context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/discover",
3
- "version": "1.2.0-dev.2331",
3
+ "version": "1.2.0-dev.2335",
4
4
  "description": "Runtime-aware command discovery for Optique CLI programs",
5
5
  "keywords": [
6
6
  "CLI",
@@ -83,8 +83,8 @@
83
83
  "optique-discover": "./dist/cli.js"
84
84
  },
85
85
  "dependencies": {
86
- "@optique/core": "1.2.0-dev.2331+0f3b5a2e",
87
- "@optique/run": "1.2.0-dev.2331+0f3b5a2e"
86
+ "@optique/run": "1.2.0-dev.2335+26079d6b",
87
+ "@optique/core": "1.2.0-dev.2335+26079d6b"
88
88
  },
89
89
  "devDependencies": {
90
90
  "@types/node": "^24.0.0",