@optique/discover 1.2.0-dev.2333 → 1.2.0-dev.2337

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
- require('./command-C-NgG0KJ.cjs');
4
- require('./src-Bb2ONs5m.cjs');
5
- const require_generator = require('./generator-4mV9w1F0.cjs');
3
+ require('./command-CfkGTUEa.cjs');
4
+ require('./src-DbaTtwIl.cjs');
5
+ const require_generator = require('./generator-CNhp71NK.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.2333+f7f47e8b";
18
+ var version = "1.2.0-dev.2337+36ffc4e1";
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
- import "./command-9sgrJtwh.js";
3
- import "./src-Ddp18zFp.js";
4
- import { watchCommandsModule, writeCommandsModule } from "./generator-CJiusCJb.js";
2
+ import "./command-CfQmeg9P.js";
3
+ import "./src-BSEAgsAL.js";
4
+ import { watchCommandsModule, writeCommandsModule } from "./generator-BIhI-TjS.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.2333+f7f47e8b";
17
+ var version = "1.2.0-dev.2337+36ffc4e1";
18
18
  var license = "MIT";
19
19
  var exports = {
20
20
  ".": "./src/index.ts",
@@ -1,6 +1,8 @@
1
1
  //#region src/command.ts
2
2
  const commandBrand = Symbol.for("@optique/discover/command");
3
3
  function defineCommand(command) {
4
+ if (Array.isArray(command)) throw new TypeError("Expected object, got array.");
5
+ if (command == null || typeof command !== "object") throw new TypeError("Expected object.");
4
6
  if (!isParser(command.parser)) throw new TypeError("Command parser must be an Optique parser.");
5
7
  if (command.path != null) validateCommandPath(command.path);
6
8
  if (typeof command.handler !== "function") throw new TypeError("Command handler must be a function.");
@@ -2,6 +2,8 @@
2
2
  //#region src/command.ts
3
3
  const commandBrand = Symbol.for("@optique/discover/command");
4
4
  function defineCommand(command) {
5
+ if (Array.isArray(command)) throw new TypeError("Expected object, got array.");
6
+ if (command == null || typeof command !== "object") throw new TypeError("Expected object.");
5
7
  if (!isParser(command.parser)) throw new TypeError("Command parser must be an Optique parser.");
6
8
  if (command.path != null) validateCommandPath(command.path);
7
9
  if (typeof command.handler !== "function") throw new TypeError("Command handler must be a function.");
package/dist/command.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_command = require('./command-C-NgG0KJ.cjs');
1
+ const require_command = require('./command-CfkGTUEa.cjs');
2
2
 
3
3
  exports.defineCommand = require_command.defineCommand;
4
4
  exports.isCommand = require_command.isCommand;
package/dist/command.js CHANGED
@@ -1,3 +1,3 @@
1
- import { defineCommand, isCommand, validateHooks } from "./command-9sgrJtwh.js";
1
+ import { defineCommand, isCommand, validateHooks } from "./command-CfQmeg9P.js";
2
2
 
3
3
  export { defineCommand, isCommand, validateHooks };
@@ -1,4 +1,4 @@
1
- import { getDefaultExtensions } from "./src-Ddp18zFp.js";
1
+ import { getDefaultExtensions } from "./src-BSEAgsAL.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,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_src = require('./src-Bb2ONs5m.cjs');
2
+ const require_src = require('./src-DbaTtwIl.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,6 +1,6 @@
1
- require('./command-C-NgG0KJ.cjs');
2
- require('./src-Bb2ONs5m.cjs');
3
- const require_generator = require('./generator-4mV9w1F0.cjs');
1
+ require('./command-CfkGTUEa.cjs');
2
+ require('./src-DbaTtwIl.cjs');
3
+ const require_generator = require('./generator-CNhp71NK.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
- import "./command-9sgrJtwh.js";
2
- import "./src-Ddp18zFp.js";
3
- import { generateCommandsModule, watchCommandsModule, writeCommandsModule } from "./generator-CJiusCJb.js";
1
+ import "./command-CfQmeg9P.js";
2
+ import "./src-BSEAgsAL.js";
3
+ import { generateCommandsModule, watchCommandsModule, writeCommandsModule } from "./generator-BIhI-TjS.js";
4
4
 
5
5
  export { generateCommandsModule, watchCommandsModule, writeCommandsModule };
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
- const require_command = require('./command-C-NgG0KJ.cjs');
2
- const require_src = require('./src-Bb2ONs5m.cjs');
1
+ const require_command = require('./command-CfkGTUEa.cjs');
2
+ const require_src = require('./src-DbaTtwIl.cjs');
3
3
 
4
4
  exports.commandsFromModules = require_src.commandsFromModules;
5
5
  exports.createProgramParser = require_src.createProgramParser;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineCommand, isCommand } from "./command-9sgrJtwh.js";
2
- import { commandsFromModules, createProgramParser, discoverCommands, getDefaultExtensions, runProgram } from "./src-Ddp18zFp.js";
1
+ import { defineCommand, isCommand } from "./command-CfQmeg9P.js";
2
+ import { commandsFromModules, createProgramParser, discoverCommands, getDefaultExtensions, runProgram } from "./src-BSEAgsAL.js";
3
3
 
4
4
  export { commandsFromModules, createProgramParser, defineCommand, discoverCommands, getDefaultExtensions, isCommand, runProgram };
@@ -1,4 +1,4 @@
1
- import { isCommand, validateHooks } from "./command-9sgrJtwh.js";
1
+ import { isCommand, validateHooks } from "./command-CfQmeg9P.js";
2
2
  import { longestMatch, or } from "@optique/core/constructs";
3
3
  import { map } from "@optique/core/modifiers";
4
4
  import { command } from "@optique/core/primitives";
@@ -92,7 +92,8 @@ async function discoverCommands(options) {
92
92
  * @since 1.2.0
93
93
  */
94
94
  function commandsFromModules(modules, options = {}) {
95
- if (modules == null || typeof modules !== "object") throw new TypeError("commandsFromModules() requires a module map object.");
95
+ if (Array.isArray(modules)) throw new TypeError("Expected object, got array.");
96
+ if (modules == null || typeof modules !== "object") throw new TypeError("Expected object.");
96
97
  const base = normalizeModuleBase(options.base);
97
98
  const extensions = normalizeExtensions(options.extensions ?? getDefaultExtensions());
98
99
  const entryFileName = normalizeEntryFileName(options.entryFileName);
@@ -154,6 +155,8 @@ function createProgramParser(commands, options = {}) {
154
155
  * @since 1.1.0
155
156
  */
156
157
  async function runProgram(options) {
158
+ if (Array.isArray(options)) throw new TypeError("Expected object, got array.");
159
+ if (options == null || typeof options !== "object") throw new TypeError("Expected object.");
157
160
  if (options.hooks != null) validateHooks(options.hooks, "Program");
158
161
  let commands;
159
162
  if (isStaticRunProgramOptions(options)) commands = staticCommandsToEntries(options.commands);
@@ -190,7 +193,7 @@ async function dispatchInvocation(invocation, programHooks) {
190
193
  if (commandHooks?.beforeEach != null) return invocation.handler(invocation.value, commandContext);
191
194
  if (programHooks?.beforeEach != null) return invocation.handler(invocation.value, programContext);
192
195
  return invocation.handler(invocation.value);
193
- }));
196
+ }, programContext));
194
197
  }
195
198
  /**
196
199
  * Runs an inner step wrapped in a single set of lifecycle hooks.
@@ -198,13 +201,14 @@ async function dispatchInvocation(invocation, programHooks) {
198
201
  * @param hooks The hooks for this scope, if any.
199
202
  * @param invocation The selected command invocation passed to `beforeEach`.
200
203
  * @param inner The step to wrap; receives the context from `beforeEach`.
204
+ * @param fallbackContext The context used when `beforeEach` is absent.
201
205
  * @returns The value returned by `inner`.
202
206
  * @throws The original error thrown by `beforeEach`, `inner`, or `afterEach`,
203
207
  * re-thrown after `onError` runs. An error thrown by `onError` itself
204
208
  * is suppressed so it cannot mask the original failure.
205
209
  */
206
- async function runHookScope(hooks, invocation, inner) {
207
- let context = {};
210
+ async function runHookScope(hooks, invocation, inner, fallbackContext = {}) {
211
+ let context = hooks?.beforeEach == null ? fallbackContext : {};
208
212
  try {
209
213
  if (hooks?.beforeEach != null) context = await hooks.beforeEach(invocation) ?? {};
210
214
  const result = await inner(context);
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_command = require('./command-C-NgG0KJ.cjs');
2
+ const require_command = require('./command-CfkGTUEa.cjs');
3
3
  const __optique_core_constructs = require_chunk.__toESM(require("@optique/core/constructs"));
4
4
  const __optique_core_modifiers = require_chunk.__toESM(require("@optique/core/modifiers"));
5
5
  const __optique_core_primitives = require_chunk.__toESM(require("@optique/core/primitives"));
@@ -93,7 +93,8 @@ async function discoverCommands(options) {
93
93
  * @since 1.2.0
94
94
  */
95
95
  function commandsFromModules(modules, options = {}) {
96
- if (modules == null || typeof modules !== "object") throw new TypeError("commandsFromModules() requires a module map object.");
96
+ if (Array.isArray(modules)) throw new TypeError("Expected object, got array.");
97
+ if (modules == null || typeof modules !== "object") throw new TypeError("Expected object.");
97
98
  const base = normalizeModuleBase(options.base);
98
99
  const extensions = normalizeExtensions(options.extensions ?? getDefaultExtensions());
99
100
  const entryFileName = normalizeEntryFileName(options.entryFileName);
@@ -155,6 +156,8 @@ function createProgramParser(commands, options = {}) {
155
156
  * @since 1.1.0
156
157
  */
157
158
  async function runProgram(options) {
159
+ if (Array.isArray(options)) throw new TypeError("Expected object, got array.");
160
+ if (options == null || typeof options !== "object") throw new TypeError("Expected object.");
158
161
  if (options.hooks != null) require_command.validateHooks(options.hooks, "Program");
159
162
  let commands;
160
163
  if (isStaticRunProgramOptions(options)) commands = staticCommandsToEntries(options.commands);
@@ -191,7 +194,7 @@ async function dispatchInvocation(invocation, programHooks) {
191
194
  if (commandHooks?.beforeEach != null) return invocation.handler(invocation.value, commandContext);
192
195
  if (programHooks?.beforeEach != null) return invocation.handler(invocation.value, programContext);
193
196
  return invocation.handler(invocation.value);
194
- }));
197
+ }, programContext));
195
198
  }
196
199
  /**
197
200
  * Runs an inner step wrapped in a single set of lifecycle hooks.
@@ -199,13 +202,14 @@ async function dispatchInvocation(invocation, programHooks) {
199
202
  * @param hooks The hooks for this scope, if any.
200
203
  * @param invocation The selected command invocation passed to `beforeEach`.
201
204
  * @param inner The step to wrap; receives the context from `beforeEach`.
205
+ * @param fallbackContext The context used when `beforeEach` is absent.
202
206
  * @returns The value returned by `inner`.
203
207
  * @throws The original error thrown by `beforeEach`, `inner`, or `afterEach`,
204
208
  * re-thrown after `onError` runs. An error thrown by `onError` itself
205
209
  * is suppressed so it cannot mask the original failure.
206
210
  */
207
- async function runHookScope(hooks, invocation, inner) {
208
- let context = {};
211
+ async function runHookScope(hooks, invocation, inner, fallbackContext = {}) {
212
+ let context = hooks?.beforeEach == null ? fallbackContext : {};
209
213
  try {
210
214
  if (hooks?.beforeEach != null) context = await hooks.beforeEach(invocation) ?? {};
211
215
  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.2333",
3
+ "version": "1.2.0-dev.2337",
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.2333+f7f47e8b",
87
- "@optique/run": "1.2.0-dev.2333+f7f47e8b"
86
+ "@optique/core": "1.2.0-dev.2337+36ffc4e1",
87
+ "@optique/run": "1.2.0-dev.2337+36ffc4e1"
88
88
  },
89
89
  "devDependencies": {
90
90
  "@types/node": "^24.0.0",