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

Provide a way to dynamically change loader hook #33903

Open
sloonz opened this issue Jun 16, 2020 · 2 comments
Open

Provide a way to dynamically change loader hook #33903

sloonz opened this issue Jun 16, 2020 · 2 comments
Labels
esm Issues and PRs related to the ECMAScript Modules implementation.

Comments

@sloonz
Copy link

sloonz commented Jun 16, 2020

I am looking at the possibility at doing something like mitogen in node.

How it would work, in really broad strokes, is :

  • Spawn an child node process through sudo/ssh/whatever. Initial code is passed with -e.
  • This initial code reads commands from stdin, push results on stdout
  • One command is EVAL, which just evals a javascript string
  • ESM modules imported by the evaluated code are expected to be imported from the parent context. It therefore needs a loader hook which would communicate (via stdin/stdout) to get the module from the parent

However, it's impossible generally to pass a meaningful --loader argument to the child : think of the case of a read-only file-system where we cannot write a temporary loader.mjs that does the job, for example.

In the Python world, mitogen just dynamically add a module loader. It would be nice if we could do the same thing, something in the lines of :

import.meta.hooks = {
  async resolve() { ... },
  ...
}
@devsnek
Copy link
Member

devsnek commented Jun 16, 2020

I'm planning to add support for this after chaining is figured out.

@sloonz
Copy link
Author

sloonz commented Jun 16, 2020

Amazing 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation.
Projects
None yet
Development

No branches or pull requests

3 participants