@optique/config 1.1.0-dev.2087 → 1.1.0-dev.2096
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/index.cjs +35 -3
- package/dist/index.js +36 -4
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -269,7 +269,30 @@ function bindConfig(parser, options) {
|
|
|
269
269
|
const annotations = (0, __optique_core_annotations.getAnnotations)(state);
|
|
270
270
|
return annotations?.[options.context.id] === phase1ConfigAnnotationMarker;
|
|
271
271
|
}
|
|
272
|
-
|
|
272
|
+
function getInnerState(state) {
|
|
273
|
+
if (!isConfigBindState(state)) return state;
|
|
274
|
+
if (state.cliState !== void 0) return state.cliState;
|
|
275
|
+
const initialState = parser.initialState;
|
|
276
|
+
if (initialState != null && typeof initialState !== "object") return initialState;
|
|
277
|
+
const annotated = (0, __optique_core_extension.inheritAnnotations)(state, initialState);
|
|
278
|
+
if (annotated === initialState && initialState != null && typeof initialState === "object") {
|
|
279
|
+
const annotations = (0, __optique_core_annotations.getAnnotations)(state);
|
|
280
|
+
return annotations == null ? initialState : (0, __optique_core_extension.withAnnotationView)(initialState, annotations);
|
|
281
|
+
}
|
|
282
|
+
return annotated;
|
|
283
|
+
}
|
|
284
|
+
function hasConfigFallback(state) {
|
|
285
|
+
if (options.default !== void 0) return true;
|
|
286
|
+
const annotations = (0, __optique_core_annotations.getAnnotations)(state);
|
|
287
|
+
const annotationValue = annotations?.[options.context.id];
|
|
288
|
+
const configData = annotationValue?.data;
|
|
289
|
+
const configMeta = annotationValue?.meta;
|
|
290
|
+
if (configData == null) return false;
|
|
291
|
+
if (typeof options.key !== "function") return configData[options.key] !== void 0;
|
|
292
|
+
const configValue = options.key(configData, configMeta);
|
|
293
|
+
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.");
|
|
294
|
+
return configValue !== void 0;
|
|
295
|
+
}
|
|
273
296
|
const boundParser = {
|
|
274
297
|
mode: parser.mode,
|
|
275
298
|
$valueType: parser.$valueType,
|
|
@@ -282,8 +305,17 @@ function bindConfig(parser, options) {
|
|
|
282
305
|
leadingNames: parser.leadingNames,
|
|
283
306
|
acceptingAnyToken: parser.acceptingAnyToken,
|
|
284
307
|
initialState: parser.initialState,
|
|
308
|
+
canSkip(state, exec) {
|
|
309
|
+
if (isConfigBindState(state)) {
|
|
310
|
+
if (state.hasCliValue) return parser.canSkip?.(state.cliState, exec) === true;
|
|
311
|
+
if (hasConfigFallback(state)) return true;
|
|
312
|
+
return parser.canSkip?.(getInnerState(state), exec) === true;
|
|
313
|
+
}
|
|
314
|
+
if (hasConfigFallback(state)) return true;
|
|
315
|
+
return parser.canSkip?.(state, exec) === true;
|
|
316
|
+
},
|
|
285
317
|
getSuggestRuntimeNodes(state, path) {
|
|
286
|
-
const innerState =
|
|
318
|
+
const innerState = getInnerState(state);
|
|
287
319
|
return (0, __optique_core_extension.delegateSuggestNodes)(parser, boundParser, state, path, innerState);
|
|
288
320
|
},
|
|
289
321
|
parse: (context) => {
|
|
@@ -332,7 +364,7 @@ function bindConfig(parser, options) {
|
|
|
332
364
|
return getConfigOrDefault(state, options, parser.mode, parser);
|
|
333
365
|
},
|
|
334
366
|
suggest: (context, prefix) => {
|
|
335
|
-
const innerState =
|
|
367
|
+
const innerState = getInnerState(context.state);
|
|
336
368
|
const innerContext = innerState !== context.state ? {
|
|
337
369
|
...context,
|
|
338
370
|
state: innerState
|
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, wrapForMode } from "@optique/core/extension";
|
|
4
|
+
import { defineTraits, delegateSuggestNodes, inheritAnnotations, injectAnnotations, mapModeValue, mapSourceMetadata, withAnnotationView, wrapForMode } from "@optique/core/extension";
|
|
5
5
|
import { message } from "@optique/core/message";
|
|
6
6
|
|
|
7
7
|
//#region src/index.ts
|
|
@@ -246,7 +246,30 @@ function bindConfig(parser, options) {
|
|
|
246
246
|
const annotations = getAnnotations(state);
|
|
247
247
|
return annotations?.[options.context.id] === phase1ConfigAnnotationMarker;
|
|
248
248
|
}
|
|
249
|
-
|
|
249
|
+
function getInnerState(state) {
|
|
250
|
+
if (!isConfigBindState(state)) return state;
|
|
251
|
+
if (state.cliState !== void 0) return state.cliState;
|
|
252
|
+
const initialState = parser.initialState;
|
|
253
|
+
if (initialState != null && typeof initialState !== "object") return initialState;
|
|
254
|
+
const annotated = inheritAnnotations(state, initialState);
|
|
255
|
+
if (annotated === initialState && initialState != null && typeof initialState === "object") {
|
|
256
|
+
const annotations = getAnnotations(state);
|
|
257
|
+
return annotations == null ? initialState : withAnnotationView(initialState, annotations);
|
|
258
|
+
}
|
|
259
|
+
return annotated;
|
|
260
|
+
}
|
|
261
|
+
function hasConfigFallback(state) {
|
|
262
|
+
if (options.default !== void 0) return true;
|
|
263
|
+
const annotations = getAnnotations(state);
|
|
264
|
+
const annotationValue = annotations?.[options.context.id];
|
|
265
|
+
const configData = annotationValue?.data;
|
|
266
|
+
const configMeta = annotationValue?.meta;
|
|
267
|
+
if (configData == null) return false;
|
|
268
|
+
if (typeof options.key !== "function") return configData[options.key] !== void 0;
|
|
269
|
+
const configValue = options.key(configData, configMeta);
|
|
270
|
+
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.");
|
|
271
|
+
return configValue !== void 0;
|
|
272
|
+
}
|
|
250
273
|
const boundParser = {
|
|
251
274
|
mode: parser.mode,
|
|
252
275
|
$valueType: parser.$valueType,
|
|
@@ -259,8 +282,17 @@ function bindConfig(parser, options) {
|
|
|
259
282
|
leadingNames: parser.leadingNames,
|
|
260
283
|
acceptingAnyToken: parser.acceptingAnyToken,
|
|
261
284
|
initialState: parser.initialState,
|
|
285
|
+
canSkip(state, exec) {
|
|
286
|
+
if (isConfigBindState(state)) {
|
|
287
|
+
if (state.hasCliValue) return parser.canSkip?.(state.cliState, exec) === true;
|
|
288
|
+
if (hasConfigFallback(state)) return true;
|
|
289
|
+
return parser.canSkip?.(getInnerState(state), exec) === true;
|
|
290
|
+
}
|
|
291
|
+
if (hasConfigFallback(state)) return true;
|
|
292
|
+
return parser.canSkip?.(state, exec) === true;
|
|
293
|
+
},
|
|
262
294
|
getSuggestRuntimeNodes(state, path) {
|
|
263
|
-
const innerState =
|
|
295
|
+
const innerState = getInnerState(state);
|
|
264
296
|
return delegateSuggestNodes(parser, boundParser, state, path, innerState);
|
|
265
297
|
},
|
|
266
298
|
parse: (context) => {
|
|
@@ -309,7 +341,7 @@ function bindConfig(parser, options) {
|
|
|
309
341
|
return getConfigOrDefault(state, options, parser.mode, parser);
|
|
310
342
|
},
|
|
311
343
|
suggest: (context, prefix) => {
|
|
312
|
-
const innerState =
|
|
344
|
+
const innerState = getInnerState(context.state);
|
|
313
345
|
const innerContext = innerState !== context.state ? {
|
|
314
346
|
...context,
|
|
315
347
|
state: innerState
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/config",
|
|
3
|
-
"version": "1.1.0-dev.
|
|
3
|
+
"version": "1.1.0-dev.2096",
|
|
4
4
|
"description": "Configuration file support for Optique with Standard Schema validation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@standard-schema/spec": "^1.1.0"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@optique/core": "1.1.0-dev.
|
|
62
|
+
"@optique/core": "1.1.0-dev.2096+8eda4929"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@standard-schema/spec": "^1.1.0",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"tsdown": "^0.13.0",
|
|
69
69
|
"typescript": "^5.8.3",
|
|
70
70
|
"zod": "^3.25.0 || ^4.0.0",
|
|
71
|
-
"@optique/env": "1.1.0-dev.
|
|
71
|
+
"@optique/env": "1.1.0-dev.2096+8eda4929"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"build": "tsdown",
|