Skip to content

Commit f4486f7

Browse files
committed
Update repl.ts
1 parent da11576 commit f4486f7

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

packages/cli/src/commands/repl.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ export async function startRepl(configPath?: string) {
5555
useColors: true
5656
});
5757

58+
// Enable Auto-Await for Promises
59+
const defaultEval = r.eval;
60+
(r as any).eval = (cmd: string, context: any, filename: string, callback: any) => {
61+
defaultEval.call(r, cmd, context, filename, async (err: Error | null, result: any) => {
62+
if (err) return callback(err, null);
63+
if (result && typeof result.then === 'function') {
64+
try {
65+
const value = await result;
66+
callback(null, value);
67+
} catch (e: any) {
68+
callback(e, null);
69+
}
70+
} else {
71+
callback(null, result);
72+
}
73+
});
74+
};
75+
5876
// 4. Inject Context
5977
r.context.app = app;
6078
r.context.object = (name: string) => app.getObject(name);
@@ -89,7 +107,7 @@ export async function startRepl(configPath?: string) {
89107
}
90108

91109
console.log(`\nAvailable Objects: ${objects.map((o: any) => o.name).join(', ')}`);
92-
console.log(`Usage: await tasks.find()`);
110+
console.log(`Usage: tasks.find() (Auto-await enabled)`);
93111

94112
} catch (error) {
95113
console.error("Failed to load or start:", error);

0 commit comments

Comments
 (0)