`vm.Script`'s `importModuleDynamically` should get a reference to the `context` used to run it
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 122k
- Forks
- 37.3k
- Ø Merge
- 4 T. 2 Std.
- Gemergte PRs (30 T.)
- 283
Beschreibung
Is your feature request related to a problem? Please describe.
When implementing importModuleDynamically you don't have access to what context the script is executed with, meaning you can't pass the correct context when constructing a Module. We're also missing the filename of the Script, so resolving to the specifier passed is also not straightforward since it can be changed by .runIn*Context() calls from what I passed in to the constructor.
Describe the solution you'd like
I think adding context and filename as accessible properties on the Script instance passed to the function should work fine - it would mirror what you get when using SourceTextModule where I have access to context and identifier. It could also be passed as a third argument to the function passed in importModuleDynamically if you don't wanna change the Script instance itself.
Describe alternatives you've considered
The implementation I've gone with in the absence of such an API is to get the context again and re-use the filename passed in the constructor. This works since I also have control over how the script is executed, but that might not always be the case. Mirroring the capability of SourceTextModule would be nice, though - where in the context of the callback in importModuleDynamically there's enough information to know how to resolve the specifier being requested and in what context it should run.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, den vm.Script-Callback importModuleDynamically mit den im Issue beschriebenen APIs für den Kontext und die Kennung von SourceTextModule zu vergleichen. Verfolge, wie vm.Script über runIn*Context() ausgeführt wird, und ermittle, wo context und filename verfügbar gemacht werden könnten; abgeschlossen ist die Untersuchung, wenn der Callback beide zuverlässig identifizieren kann, um das angeforderte Modul aufzulösen und auszuführen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, node.js
- Bereich
- api, backend
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100