Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable top-level await in yarn rw console #1613

Open
jtoar opened this issue Jan 7, 2021 · 1 comment
Open

Enable top-level await in yarn rw console #1613

jtoar opened this issue Jan 7, 2021 · 1 comment

Comments

@jtoar
Copy link
Contributor

jtoar commented Jan 7, 2021

Update (05.28.2021)

Right now we abstract away the need for top-level await in Redwood console by automatically resolving promises. This works but it'd I think it'd still be super nice to have top level await.


Original

Right now the console command requires the NODE_OPTIONS env var be set to --experimental-repl-await. This isn't an ideal workflow, especially since the console command will be in the tutorial II, so I tried to fix this by using execa (see this PR: #1603). But now the repl is starting on every command. It seems that yargs is executing the asyncRepl.js file no matter what.

The only reason I abstracted the code to start the repl into another file was, you have to pass files to the node CLI: node --experimental-repl-await asyncRepl.js. Maybe you can just pass a giant string to be evaled (I didn't try) but that doesn't seem sustainable, especially once we add all the services to the repl's context.

Another option is to hack the eval the repl uses: nodejs/node#13209 (comment).

Note that the console command breaks if the prisma client isn't generated. This definitely has to be fixed, but isn't the same problem.

@jtoar
Copy link
Contributor Author

jtoar commented Jan 8, 2021

@peterp at the contributor's meetup today, @mojombo suggested we resolve promises automatically. that could be a lot easier than enabling top-level await. I think we'd have to override the repl's eval, but there's examples for that.

to be more explicit, using the console would just be like:

> db.user.findMany()

// resolve promise automatically

[ { id: 1, email: ... } ]

so everyone typing at the console would never have to type await db.user.findMany().


update: this might not be mutually exclusive with enabling top-level await, but just seems like it could be done sooner.

@jtoar jtoar changed the title Fix top-level await in yarn rw console Enable top-level await in yarn rw console May 18, 2021
@jtoar jtoar added the hopper label May 18, 2021
@jtoar jtoar added next and removed hopper labels Dec 11, 2021
@jtoar jtoar added this to Triage Dec 11, 2021
@jtoar jtoar moved this to Todo in Triage Dec 11, 2021
@jtoar jtoar removed the next label Apr 15, 2022
@jtoar jtoar added this to Main May 5, 2022
@jtoar jtoar moved this to Backlog in Main May 5, 2022
@jtoar jtoar removed this from Triage May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

2 participants