@optique/config 1.3.0 → 1.3.2
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 +9 -2
- package/dist/index.cjs +3 -1
- package/dist/index.js +4 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -27,6 +27,8 @@ Quick start
|
|
|
27
27
|
-----------
|
|
28
28
|
|
|
29
29
|
~~~~ typescript
|
|
30
|
+
import { homedir } from "node:os";
|
|
31
|
+
import { join } from "node:path";
|
|
30
32
|
import { z } from "zod";
|
|
31
33
|
import { createConfigContext, bindConfig } from "@optique/config";
|
|
32
34
|
import { object } from "@optique/core/constructs";
|
|
@@ -45,7 +47,10 @@ const configContext = createConfigContext({ schema: configSchema });
|
|
|
45
47
|
|
|
46
48
|
// 2. Bind parsers to config values
|
|
47
49
|
const parser = object({
|
|
48
|
-
config: withDefault(
|
|
50
|
+
config: withDefault(
|
|
51
|
+
option("--config", string()),
|
|
52
|
+
join(homedir(), ".myapp.json"),
|
|
53
|
+
),
|
|
49
54
|
host: bindConfig(option("--host", string()), {
|
|
50
55
|
context: configContext,
|
|
51
56
|
key: "host",
|
|
@@ -61,7 +66,9 @@ const parser = object({
|
|
|
61
66
|
// 3. Run with config support via contexts
|
|
62
67
|
const result = await runAsync(parser, {
|
|
63
68
|
contexts: [configContext],
|
|
64
|
-
|
|
69
|
+
contextOptions: {
|
|
70
|
+
getConfigPath: (parsed) => parsed.config,
|
|
71
|
+
},
|
|
65
72
|
args: process.argv.slice(2),
|
|
66
73
|
});
|
|
67
74
|
|
package/dist/index.cjs
CHANGED
|
@@ -295,6 +295,7 @@ function bindConfig(parser, options) {
|
|
|
295
295
|
if (configValue != null && (typeof configValue === "object" || typeof configValue === "function") && "then" in configValue && typeof configValue.then === "function") throw new TypeError("The key callback must return a synchronous value, but got a thenable.");
|
|
296
296
|
return configValue !== void 0;
|
|
297
297
|
}
|
|
298
|
+
const getCliState = (state) => isConfigBindState(state) ? state.hasCliValue ? state.cliState : (0, __optique_core_extension.inheritAnnotations)(state, parser.initialState) : state;
|
|
298
299
|
const boundParser = {
|
|
299
300
|
mode: parser.mode,
|
|
300
301
|
$valueType: parser.$valueType,
|
|
@@ -323,7 +324,7 @@ function bindConfig(parser, options) {
|
|
|
323
324
|
parse: (context) => {
|
|
324
325
|
const annotations = (0, __optique_core_annotations.getAnnotations)(context.state);
|
|
325
326
|
const hadCliValue = isConfigBindState(context.state) && context.state.hasCliValue;
|
|
326
|
-
const innerState =
|
|
327
|
+
const innerState = getCliState(context.state);
|
|
327
328
|
const innerContext = innerState !== context.state ? {
|
|
328
329
|
...context,
|
|
329
330
|
state: innerState
|
|
@@ -433,6 +434,7 @@ function bindConfig(parser, options) {
|
|
|
433
434
|
configurable: true,
|
|
434
435
|
enumerable: false
|
|
435
436
|
});
|
|
437
|
+
(0, __optique_core_extension.delegateOptionParsing)(boundParser, parser, getCliState);
|
|
436
438
|
return (0, __optique_core_fluent.fluent)(boundParser);
|
|
437
439
|
}
|
|
438
440
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { dirname, resolve } from "node:path";
|
|
3
3
|
import { getAnnotations } from "@optique/core/annotations";
|
|
4
|
-
import { defineTraits, delegateSuggestNodes, inheritAnnotations, injectAnnotations, mapModeValue, mapSourceMetadata, withAnnotationView, wrapForMode } from "@optique/core/extension";
|
|
4
|
+
import { defineTraits, delegateOptionParsing, delegateSuggestNodes, inheritAnnotations, injectAnnotations, mapModeValue, mapSourceMetadata, withAnnotationView, wrapForMode } from "@optique/core/extension";
|
|
5
5
|
import { fluent } from "@optique/core/fluent";
|
|
6
6
|
import { message } from "@optique/core/message";
|
|
7
7
|
|
|
@@ -272,6 +272,7 @@ function bindConfig(parser, options) {
|
|
|
272
272
|
if (configValue != null && (typeof configValue === "object" || typeof configValue === "function") && "then" in configValue && typeof configValue.then === "function") throw new TypeError("The key callback must return a synchronous value, but got a thenable.");
|
|
273
273
|
return configValue !== void 0;
|
|
274
274
|
}
|
|
275
|
+
const getCliState = (state) => isConfigBindState(state) ? state.hasCliValue ? state.cliState : inheritAnnotations(state, parser.initialState) : state;
|
|
275
276
|
const boundParser = {
|
|
276
277
|
mode: parser.mode,
|
|
277
278
|
$valueType: parser.$valueType,
|
|
@@ -300,7 +301,7 @@ function bindConfig(parser, options) {
|
|
|
300
301
|
parse: (context) => {
|
|
301
302
|
const annotations = getAnnotations(context.state);
|
|
302
303
|
const hadCliValue = isConfigBindState(context.state) && context.state.hasCliValue;
|
|
303
|
-
const innerState =
|
|
304
|
+
const innerState = getCliState(context.state);
|
|
304
305
|
const innerContext = innerState !== context.state ? {
|
|
305
306
|
...context,
|
|
306
307
|
state: innerState
|
|
@@ -410,6 +411,7 @@ function bindConfig(parser, options) {
|
|
|
410
411
|
configurable: true,
|
|
411
412
|
enumerable: false
|
|
412
413
|
});
|
|
414
|
+
delegateOptionParsing(boundParser, parser, getCliState);
|
|
413
415
|
return fluent(boundParser);
|
|
414
416
|
}
|
|
415
417
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/config",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Configuration file support for Optique with Standard Schema validation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -65,10 +65,10 @@
|
|
|
65
65
|
"@standard-schema/spec": "^1.1.0"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@optique/core": "1.3.
|
|
68
|
+
"@optique/core": "1.3.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@optique/env": "1.3.
|
|
71
|
+
"@optique/env": "1.3.2",
|
|
72
72
|
"@standard-schema/spec": "^1.1.0",
|
|
73
73
|
"@types/node": "^24.0.0",
|
|
74
74
|
"fast-check": "^4.7.0",
|