scenv 0.2.0 → 0.2.1
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 +2 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -305,7 +305,8 @@ function scenv(name, options = {}) {
|
|
|
305
305
|
let value;
|
|
306
306
|
if (shouldPrompt(config, hadValue, hadEnv)) {
|
|
307
307
|
const defaultForPrompt = raw !== void 0 ? raw : defaultValue;
|
|
308
|
-
const
|
|
308
|
+
const callbacks = getCallbacks();
|
|
309
|
+
const fn = promptFn ?? callbacks.defaultPrompt ?? defaultPrompt;
|
|
309
310
|
value = await Promise.resolve(fn(name, defaultForPrompt));
|
|
310
311
|
wasPrompted = true;
|
|
311
312
|
} else if (raw !== void 0) {
|
package/dist/index.d.cts
CHANGED
|
@@ -20,7 +20,11 @@ interface ScenvConfig {
|
|
|
20
20
|
/** Root directory for config/context search (default: cwd) */
|
|
21
21
|
root?: string;
|
|
22
22
|
}
|
|
23
|
+
/** (name, defaultValue) => value; used when a variable has no prompt option. Overridable per variable. */
|
|
24
|
+
type DefaultPromptFn = (name: string, defaultValue: unknown) => unknown | Promise<unknown>;
|
|
23
25
|
interface ScenvCallbacks {
|
|
26
|
+
/** Default prompt when a variable does not provide its own `prompt`. Variable's `prompt` overrides this. */
|
|
27
|
+
defaultPrompt?: DefaultPromptFn;
|
|
24
28
|
/** When user was just prompted for a value and savePrompt is ask/always: (variableName, value, contextNames) => context name to save to, or null to skip */
|
|
25
29
|
onAskSaveAfterPrompt?: (name: string, value: unknown, contextNames: string[]) => Promise<string | null>;
|
|
26
30
|
/** When saveContextTo is "ask": (variableName, contextNames) => context name to save to */
|
|
@@ -86,4 +90,4 @@ declare function scenv<T>(name: string, options?: ScenvVariableOptions<T>): Scen
|
|
|
86
90
|
*/
|
|
87
91
|
declare function parseScenvArgs(argv: string[]): Partial<ScenvConfig>;
|
|
88
92
|
|
|
89
|
-
export { type PromptMode, type SavePromptMode, type ScenvCallbacks, type ScenvConfig, type ScenvVariable, configure, discoverContextPaths, getCallbacks, getContextValues, loadConfig, parseScenvArgs, resetConfig, scenv };
|
|
93
|
+
export { type DefaultPromptFn, type PromptMode, type SavePromptMode, type ScenvCallbacks, type ScenvConfig, type ScenvVariable, configure, discoverContextPaths, getCallbacks, getContextValues, loadConfig, parseScenvArgs, resetConfig, scenv };
|
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,11 @@ interface ScenvConfig {
|
|
|
20
20
|
/** Root directory for config/context search (default: cwd) */
|
|
21
21
|
root?: string;
|
|
22
22
|
}
|
|
23
|
+
/** (name, defaultValue) => value; used when a variable has no prompt option. Overridable per variable. */
|
|
24
|
+
type DefaultPromptFn = (name: string, defaultValue: unknown) => unknown | Promise<unknown>;
|
|
23
25
|
interface ScenvCallbacks {
|
|
26
|
+
/** Default prompt when a variable does not provide its own `prompt`. Variable's `prompt` overrides this. */
|
|
27
|
+
defaultPrompt?: DefaultPromptFn;
|
|
24
28
|
/** When user was just prompted for a value and savePrompt is ask/always: (variableName, value, contextNames) => context name to save to, or null to skip */
|
|
25
29
|
onAskSaveAfterPrompt?: (name: string, value: unknown, contextNames: string[]) => Promise<string | null>;
|
|
26
30
|
/** When saveContextTo is "ask": (variableName, contextNames) => context name to save to */
|
|
@@ -86,4 +90,4 @@ declare function scenv<T>(name: string, options?: ScenvVariableOptions<T>): Scen
|
|
|
86
90
|
*/
|
|
87
91
|
declare function parseScenvArgs(argv: string[]): Partial<ScenvConfig>;
|
|
88
92
|
|
|
89
|
-
export { type PromptMode, type SavePromptMode, type ScenvCallbacks, type ScenvConfig, type ScenvVariable, configure, discoverContextPaths, getCallbacks, getContextValues, loadConfig, parseScenvArgs, resetConfig, scenv };
|
|
93
|
+
export { type DefaultPromptFn, type PromptMode, type SavePromptMode, type ScenvCallbacks, type ScenvConfig, type ScenvVariable, configure, discoverContextPaths, getCallbacks, getContextValues, loadConfig, parseScenvArgs, resetConfig, scenv };
|
package/dist/index.js
CHANGED
|
@@ -278,7 +278,8 @@ function scenv(name, options = {}) {
|
|
|
278
278
|
let value;
|
|
279
279
|
if (shouldPrompt(config, hadValue, hadEnv)) {
|
|
280
280
|
const defaultForPrompt = raw !== void 0 ? raw : defaultValue;
|
|
281
|
-
const
|
|
281
|
+
const callbacks = getCallbacks();
|
|
282
|
+
const fn = promptFn ?? callbacks.defaultPrompt ?? defaultPrompt;
|
|
282
283
|
value = await Promise.resolve(fn(name, defaultForPrompt));
|
|
283
284
|
wasPrompted = true;
|
|
284
285
|
} else if (raw !== void 0) {
|