hex/src/personal_commands/util.js
Dax 152763f336
Transforms get fetch and node:child_process behind a trust prompt (#888)
* Transforms get fetch and node:child_process behind a trust prompt

* Avoid fetch_update, deprecated on newer Rust

* Give the output-trust scene a playground path
2026-11-01 15:00:05 -05:00

25 lines
967 B
JavaScript

// `node:util` for scripts: `promisify`, honoring `promisify.custom` as Node
// does, so `promisify(execFile)` resolves `{ stdout, stderr }`.
const custom = Symbol.for("nodejs.util.promisify.custom")
export function promisify(original) {
if (typeof original !== "function") throw new TypeError('The "original" argument must be of type function')
if (original[custom] !== undefined) {
const promised = original[custom]
if (typeof promised !== "function") throw new TypeError('The "util.promisify.custom" property must be of type function')
return promised
}
function promised(...args) {
return new Promise((resolve, reject) => {
original.call(this, ...args, (error, value) => (error ? reject(error) : resolve(value)))
})
}
Object.setPrototypeOf(promised, Object.getPrototypeOf(original))
Object.defineProperty(promised, custom, { value: promised })
return promised
}
promisify.custom = custom
export default { promisify }