@optique/env 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 CHANGED
@@ -124,6 +124,17 @@ function bindEnv(parser, options) {
124
124
  return value != null && typeof value === "object" && envBindStateKey in value;
125
125
  }
126
126
  const deferPromptUntilConfigResolves = parser.shouldDeferCompletion;
127
+ function hasEnvFallback(state) {
128
+ if (options.default !== void 0) return true;
129
+ const annotations = (0, __optique_core_annotations.getAnnotations)(state);
130
+ const sourceData = annotations?.[options.context.id];
131
+ if (sourceData == null) return false;
132
+ return sourceData.source(`${sourceData.prefix}${options.key}`) !== void 0;
133
+ }
134
+ function getInnerState(state) {
135
+ if (!isEnvBindState(state)) return state;
136
+ return state.cliState === void 0 ? (0, __optique_core_extension.inheritAnnotations)(state, parser.initialState) : state.cliState;
137
+ }
127
138
  const boundParser = {
128
139
  mode: parser.mode,
129
140
  $valueType: parser.$valueType,
@@ -136,8 +147,17 @@ function bindEnv(parser, options) {
136
147
  leadingNames: parser.leadingNames,
137
148
  acceptingAnyToken: parser.acceptingAnyToken,
138
149
  initialState: parser.initialState,
150
+ canSkip(state, exec) {
151
+ if (isEnvBindState(state)) {
152
+ if (state.hasCliValue) return parser.canSkip?.(state.cliState, exec) === true;
153
+ if (hasEnvFallback(state)) return true;
154
+ return parser.canSkip?.(getInnerState(state), exec) === true;
155
+ }
156
+ if (hasEnvFallback(state)) return true;
157
+ return parser.canSkip?.(state, exec) === true;
158
+ },
139
159
  getSuggestRuntimeNodes(state, path) {
140
- const innerState = isEnvBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
160
+ const innerState = getInnerState(state);
141
161
  return (0, __optique_core_extension.delegateSuggestNodes)(parser, boundParser, state, path, innerState);
142
162
  },
143
163
  parse: (context) => {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getAnnotations } from "@optique/core/annotations";
2
- import { defineTraits, delegateSuggestNodes, dispatchByMode, getTraits, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, wrapForMode } from "@optique/core/extension";
2
+ import { defineTraits, delegateSuggestNodes, dispatchByMode, getTraits, inheritAnnotations, injectAnnotations, isInjectedAnnotationState, mapModeValue, mapSourceMetadata, wrapForMode } from "@optique/core/extension";
3
3
  import { envVar, message, valueSet } from "@optique/core/message";
4
4
  import { ensureNonEmptyString, isValueParser } from "@optique/core/valueparser";
5
5
 
@@ -101,6 +101,17 @@ function bindEnv(parser, options) {
101
101
  return value != null && typeof value === "object" && envBindStateKey in value;
102
102
  }
103
103
  const deferPromptUntilConfigResolves = parser.shouldDeferCompletion;
104
+ function hasEnvFallback(state) {
105
+ if (options.default !== void 0) return true;
106
+ const annotations = getAnnotations(state);
107
+ const sourceData = annotations?.[options.context.id];
108
+ if (sourceData == null) return false;
109
+ return sourceData.source(`${sourceData.prefix}${options.key}`) !== void 0;
110
+ }
111
+ function getInnerState(state) {
112
+ if (!isEnvBindState(state)) return state;
113
+ return state.cliState === void 0 ? inheritAnnotations(state, parser.initialState) : state.cliState;
114
+ }
104
115
  const boundParser = {
105
116
  mode: parser.mode,
106
117
  $valueType: parser.$valueType,
@@ -113,8 +124,17 @@ function bindEnv(parser, options) {
113
124
  leadingNames: parser.leadingNames,
114
125
  acceptingAnyToken: parser.acceptingAnyToken,
115
126
  initialState: parser.initialState,
127
+ canSkip(state, exec) {
128
+ if (isEnvBindState(state)) {
129
+ if (state.hasCliValue) return parser.canSkip?.(state.cliState, exec) === true;
130
+ if (hasEnvFallback(state)) return true;
131
+ return parser.canSkip?.(getInnerState(state), exec) === true;
132
+ }
133
+ if (hasEnvFallback(state)) return true;
134
+ return parser.canSkip?.(state, exec) === true;
135
+ },
116
136
  getSuggestRuntimeNodes(state, path) {
117
- const innerState = isEnvBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
137
+ const innerState = getInnerState(state);
118
138
  return delegateSuggestNodes(parser, boundParser, state, path, innerState);
119
139
  },
120
140
  parse: (context) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/env",
3
- "version": "1.1.0-dev.2087",
3
+ "version": "1.1.0-dev.2096",
4
4
  "description": "Environment variable support for Optique",
5
5
  "keywords": [
6
6
  "CLI",
@@ -54,7 +54,7 @@
54
54
  },
55
55
  "sideEffects": false,
56
56
  "dependencies": {
57
- "@optique/core": "1.1.0-dev.2087+a3bd6720"
57
+ "@optique/core": "1.1.0-dev.2096+8eda4929"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/node": "^24.0.0",