UNPKG

1 kBTypeScriptView Raw
1import type { CommonLogger } from '@naturalcycles/js-lib';
2export interface RunScriptOptions {
3 /**
4 * @default false
5 * Set to true to NOT call process.exit(0) after function is completed.
6 * Currently it exists because of `jest --maxWorkers=1` behavior. To be investigated more..
7 */
8 noExit?: boolean;
9 /**
10 * Default to `console`
11 */
12 logger?: CommonLogger;
13}
14/**
15 * Use it in your top-level scripts like this:
16 *
17 * runScript(async () => {
18 * await lalala()
19 * // my script goes on....
20 * })
21 *
22 * Advantages:
23 * - Works kind of like top-level await
24 * - No need to add `void`
25 * - No need to add `.then(() => process.exit()` (e.g to close DB connections)
26 * - No need to add `.catch(err => { console.error(err); process.exit(1) })`
27 *
28 * This function is kept light, dependency-free, exported separately.
29 *
30 * Set env DEBUG_RUN_SCRIPT for extra debugging.
31 */
32export declare function runScript(fn: (...args: any[]) => any, opt?: RunScriptOptions): void;