@optique/core 1.0.0-dev.563 → 1.0.0-dev.565

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.
@@ -146,7 +146,9 @@ interface SourceContext<TRequiredOptions = void> {
146
146
  /**
147
147
  * Optional asynchronous cleanup method. Called by `runWith()` in a
148
148
  * `finally` block after parsing completes. Takes precedence over
149
- * `[Symbol.dispose]` in async runners.
149
+ * `[Symbol.dispose]` in async runners. `runWithSync()` also calls this
150
+ * method when `[Symbol.dispose]` is absent, but throws if it returns a
151
+ * Promise.
150
152
  */
151
153
  [Symbol.asyncDispose]?(): void | PromiseLike<void>;
152
154
  }
package/dist/context.d.ts CHANGED
@@ -146,7 +146,9 @@ interface SourceContext<TRequiredOptions = void> {
146
146
  /**
147
147
  * Optional asynchronous cleanup method. Called by `runWith()` in a
148
148
  * `finally` block after parsing completes. Takes precedence over
149
- * `[Symbol.dispose]` in async runners.
149
+ * `[Symbol.dispose]` in async runners. `runWithSync()` also calls this
150
+ * method when `[Symbol.dispose]` is absent, but throws if it returns a
151
+ * Promise.
150
152
  */
151
153
  [Symbol.asyncDispose]?(): void | PromiseLike<void>;
152
154
  }
package/dist/facade.cjs CHANGED
@@ -933,16 +933,35 @@ function collectAnnotationsSync(contexts, parsed, options) {
933
933
  * @param contexts Source contexts to dispose.
934
934
  */
935
935
  async function disposeContexts(contexts) {
936
- for (const context of contexts) if (Symbol.asyncDispose in context && typeof context[Symbol.asyncDispose] === "function") await context[Symbol.asyncDispose]();
937
- else if (Symbol.dispose in context && typeof context[Symbol.dispose] === "function") context[Symbol.dispose]();
936
+ const errors = [];
937
+ for (const context of contexts) try {
938
+ if (Symbol.asyncDispose in context && typeof context[Symbol.asyncDispose] === "function") await context[Symbol.asyncDispose]();
939
+ else if (Symbol.dispose in context && typeof context[Symbol.dispose] === "function") context[Symbol.dispose]();
940
+ } catch (error) {
941
+ errors.push(error);
942
+ }
943
+ if (errors.length === 1) throw errors[0];
944
+ if (errors.length > 1) throw new AggregateError(errors, "Failed to dispose one or more source contexts.");
938
945
  }
939
946
  /**
940
947
  * Disposes all contexts that implement `Disposable` synchronously.
948
+ * Falls back to `[Symbol.asyncDispose]` when it completes synchronously.
941
949
  *
942
950
  * @param contexts Source contexts to dispose.
943
951
  */
944
952
  function disposeContextsSync(contexts) {
945
- for (const context of contexts) if (Symbol.dispose in context && typeof context[Symbol.dispose] === "function") context[Symbol.dispose]();
953
+ const errors = [];
954
+ for (const context of contexts) try {
955
+ if (Symbol.dispose in context && typeof context[Symbol.dispose] === "function") context[Symbol.dispose]();
956
+ else if (Symbol.asyncDispose in context && typeof context[Symbol.asyncDispose] === "function") {
957
+ const result = context[Symbol.asyncDispose]();
958
+ if (typeof result === "object" && result !== null && "then" in result && typeof result.then === "function") throw new TypeError(`Context ${String(context.id)} returned a Promise from Symbol.asyncDispose in sync mode. Use runWith() or runWithAsync() for async disposal.`);
959
+ }
960
+ } catch (error) {
961
+ errors.push(error);
962
+ }
963
+ if (errors.length === 1) throw errors[0];
964
+ if (errors.length > 1) throw new AggregateError(errors, "Failed to dispose one or more source contexts.");
946
965
  }
947
966
  /**
948
967
  * Runs a parser with multiple source contexts.
@@ -1051,7 +1070,8 @@ async function runWith(parser, programName, contexts, options) {
1051
1070
  * @param contexts Source contexts to use (priority: earlier overrides later).
1052
1071
  * @param options Run options including args, help, version, etc.
1053
1072
  * @returns The parsed result.
1054
- * @throws Error if any context returns a Promise.
1073
+ * @throws Error if any context returns a Promise or if a context's
1074
+ * `[Symbol.asyncDispose]` returns a Promise.
1055
1075
  * @since 0.10.0
1056
1076
  */
1057
1077
  function runWithSync(parser, programName, contexts, options) {
package/dist/facade.d.cts CHANGED
@@ -431,7 +431,8 @@ declare function runWith<TParser extends Parser<Mode, unknown, unknown>, TContex
431
431
  * @param contexts Source contexts to use (priority: earlier overrides later).
432
432
  * @param options Run options including args, help, version, etc.
433
433
  * @returns The parsed result.
434
- * @throws Error if any context returns a Promise.
434
+ * @throws Error if any context returns a Promise or if a context's
435
+ * `[Symbol.asyncDispose]` returns a Promise.
435
436
  * @since 0.10.0
436
437
  */
437
438
  declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, TContexts extends readonly SourceContext<unknown>[], THelp = void, TError = never>(parser: TParser, programName: string, contexts: TContexts, options: RunWithOptions<THelp, TError> & ExtractRequiredOptions<TContexts, InferValue<TParser>>): InferValue<TParser>;
package/dist/facade.d.ts CHANGED
@@ -431,7 +431,8 @@ declare function runWith<TParser extends Parser<Mode, unknown, unknown>, TContex
431
431
  * @param contexts Source contexts to use (priority: earlier overrides later).
432
432
  * @param options Run options including args, help, version, etc.
433
433
  * @returns The parsed result.
434
- * @throws Error if any context returns a Promise.
434
+ * @throws Error if any context returns a Promise or if a context's
435
+ * `[Symbol.asyncDispose]` returns a Promise.
435
436
  * @since 0.10.0
436
437
  */
437
438
  declare function runWithSync<TParser extends Parser<"sync", unknown, unknown>, TContexts extends readonly SourceContext<unknown>[], THelp = void, TError = never>(parser: TParser, programName: string, contexts: TContexts, options: RunWithOptions<THelp, TError> & ExtractRequiredOptions<TContexts, InferValue<TParser>>): InferValue<TParser>;
package/dist/facade.js CHANGED
@@ -933,16 +933,35 @@ function collectAnnotationsSync(contexts, parsed, options) {
933
933
  * @param contexts Source contexts to dispose.
934
934
  */
935
935
  async function disposeContexts(contexts) {
936
- for (const context of contexts) if (Symbol.asyncDispose in context && typeof context[Symbol.asyncDispose] === "function") await context[Symbol.asyncDispose]();
937
- else if (Symbol.dispose in context && typeof context[Symbol.dispose] === "function") context[Symbol.dispose]();
936
+ const errors = [];
937
+ for (const context of contexts) try {
938
+ if (Symbol.asyncDispose in context && typeof context[Symbol.asyncDispose] === "function") await context[Symbol.asyncDispose]();
939
+ else if (Symbol.dispose in context && typeof context[Symbol.dispose] === "function") context[Symbol.dispose]();
940
+ } catch (error) {
941
+ errors.push(error);
942
+ }
943
+ if (errors.length === 1) throw errors[0];
944
+ if (errors.length > 1) throw new AggregateError(errors, "Failed to dispose one or more source contexts.");
938
945
  }
939
946
  /**
940
947
  * Disposes all contexts that implement `Disposable` synchronously.
948
+ * Falls back to `[Symbol.asyncDispose]` when it completes synchronously.
941
949
  *
942
950
  * @param contexts Source contexts to dispose.
943
951
  */
944
952
  function disposeContextsSync(contexts) {
945
- for (const context of contexts) if (Symbol.dispose in context && typeof context[Symbol.dispose] === "function") context[Symbol.dispose]();
953
+ const errors = [];
954
+ for (const context of contexts) try {
955
+ if (Symbol.dispose in context && typeof context[Symbol.dispose] === "function") context[Symbol.dispose]();
956
+ else if (Symbol.asyncDispose in context && typeof context[Symbol.asyncDispose] === "function") {
957
+ const result = context[Symbol.asyncDispose]();
958
+ if (typeof result === "object" && result !== null && "then" in result && typeof result.then === "function") throw new TypeError(`Context ${String(context.id)} returned a Promise from Symbol.asyncDispose in sync mode. Use runWith() or runWithAsync() for async disposal.`);
959
+ }
960
+ } catch (error) {
961
+ errors.push(error);
962
+ }
963
+ if (errors.length === 1) throw errors[0];
964
+ if (errors.length > 1) throw new AggregateError(errors, "Failed to dispose one or more source contexts.");
946
965
  }
947
966
  /**
948
967
  * Runs a parser with multiple source contexts.
@@ -1051,7 +1070,8 @@ async function runWith(parser, programName, contexts, options) {
1051
1070
  * @param contexts Source contexts to use (priority: earlier overrides later).
1052
1071
  * @param options Run options including args, help, version, etc.
1053
1072
  * @returns The parsed result.
1054
- * @throws Error if any context returns a Promise.
1073
+ * @throws Error if any context returns a Promise or if a context's
1074
+ * `[Symbol.asyncDispose]` returns a Promise.
1055
1075
  * @since 0.10.0
1056
1076
  */
1057
1077
  function runWithSync(parser, programName, contexts, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.563+68c9b43a",
3
+ "version": "1.0.0-dev.565+d8d53900",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",