@inquirer/core
Advanced tools
Comparing version 9.0.6 to 9.0.7
@@ -31,2 +31,3 @@ "use strict"; | ||
const readline = __importStar(require("node:readline")); | ||
const node_async_hooks_1 = require("node:async_hooks"); | ||
const type_1 = require("@inquirer/type"); | ||
@@ -54,3 +55,3 @@ const mute_stream_1 = __importDefault(require("mute-stream")); | ||
const answer = new type_1.CancelablePromise((resolve, reject) => { | ||
(0, hook_engine_mjs_1.withHooks)(rl, (store) => { | ||
(0, hook_engine_mjs_1.withHooks)(rl, (cycle) => { | ||
function checkCursorPos() { | ||
@@ -63,7 +64,5 @@ screen.checkCursorPos(); | ||
}); | ||
function onExit() { | ||
const onExit = node_async_hooks_1.AsyncResource.bind(() => { | ||
try { | ||
store.hooksCleanup.forEach((cleanFn) => { | ||
cleanFn === null || cleanFn === void 0 ? void 0 : cleanFn(); | ||
}); | ||
hook_engine_mjs_1.effectScheduler.clearAll(); | ||
} | ||
@@ -81,4 +80,4 @@ catch (error) { | ||
removeExitListener(); | ||
store.rl.input.removeListener('keypress', checkCursorPos); | ||
} | ||
rl.input.removeListener('keypress', checkCursorPos); | ||
}); | ||
cancel = () => { | ||
@@ -96,4 +95,3 @@ onExit(); | ||
} | ||
function workLoop() { | ||
store.index = 0; | ||
cycle(() => { | ||
try { | ||
@@ -109,5 +107,3 @@ const nextView = view(config, done); | ||
} | ||
} | ||
store.handleChange = () => workLoop(); | ||
workLoop(); | ||
}); | ||
// Re-renders only happen when the state change; but the readline cursor could change position | ||
@@ -117,3 +113,3 @@ // and that also requires a re-render (and a manual one because we mute the streams). | ||
// by a state change sets the cursor to the right position. | ||
store.rl.input.on('keypress', checkCursorPos); | ||
rl.input.on('keypress', checkCursorPos); | ||
}); | ||
@@ -120,0 +116,0 @@ }); |
@@ -28,3 +28,10 @@ "use strict"; | ||
return hookStorage.run(store, () => { | ||
cb(store); | ||
function cycle(render) { | ||
store.handleChange = () => { | ||
store.index = 0; | ||
render(); | ||
}; | ||
store.handleChange(); | ||
} | ||
cb(cycle); | ||
}); | ||
@@ -105,2 +112,10 @@ } | ||
}, | ||
clearAll() { | ||
const store = getStore(); | ||
store.hooksCleanup.forEach((cleanFn) => { | ||
cleanFn === null || cleanFn === void 0 ? void 0 : cleanFn(); | ||
}); | ||
store.hooksEffect.length = 0; | ||
store.hooksCleanup.length = 0; | ||
}, | ||
}; |
import type { InquirerReadline } from '@inquirer/type'; | ||
type HookStore = { | ||
rl: InquirerReadline; | ||
hooks: any[]; | ||
hooksCleanup: Array<void | (() => void)>; | ||
hooksEffect: Array<() => void>; | ||
index: number; | ||
handleChange: () => void; | ||
}; | ||
export declare function withHooks(rl: InquirerReadline, cb: (store: HookStore) => void): void; | ||
export declare function withHooks(rl: InquirerReadline, cb: (cycle: (render: () => void) => void) => void): void; | ||
export declare function readline(): InquirerReadline; | ||
@@ -29,3 +21,4 @@ export declare function withUpdates<T extends (...args: any) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>; | ||
run(): void; | ||
clearAll(): void; | ||
}; | ||
export {}; |
{ | ||
"name": "@inquirer/core", | ||
"version": "9.0.6", | ||
"version": "9.0.7", | ||
"engines": { | ||
@@ -63,3 +63,3 @@ "node": ">=18" | ||
"@types/mute-stream": "^0.0.4", | ||
"@types/node": "^20.14.13", | ||
"@types/node": "^22.0.0", | ||
"@types/wrap-ansi": "^3.0.0", | ||
@@ -76,3 +76,3 @@ "ansi-escapes": "^4.3.2", | ||
"devDependencies": { | ||
"@inquirer/testing": "^2.1.29" | ||
"@inquirer/testing": "^2.1.30" | ||
}, | ||
@@ -101,3 +101,3 @@ "scripts": { | ||
"sideEffects": false, | ||
"gitHead": "7a061f13e053dd64ef7373b08e8a10130131ea59" | ||
"gitHead": "b89972b992a65005afd6397b57aa4635010a5ef7" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91826
1907
+ Added@types/node@22.5.5(transitive)
- Removed@types/node@20.16.5(transitive)
Updated@types/node@^22.0.0