Skip to content

Customizing import.meta #159

Open
Open
@GeoffreyBooth

Description

@GeoffreyBooth

I feel like users should be able to customize import.meta. For example, nodejs/node#48740 might very well land in core sometime soon, but it also feels like something that should be achievable via the module customization hooks. Likewise for import.meta.resolveURL, a version of import.meta.resolve that returns an URL instance instead of a string.

I assume this can be done already today by prepending some code into the source returned by the load hook, kind of like adding a polyfill but it’s one that runs for every module. Though I suppose if we create a new hook, that would also run for every module, so the performance impact is the same?

There’s also the question of adding functions/methods to import.meta. Say we create a new importMeta hook, with a signature like importMeta(url, context, next). If this runs on the separate thread with all the other hooks, what happens when the return value of the user’s hook has a function on it, like resolveURL? We can’t transfer that across the thread boundary, can we? Is there some other way to make this work, like making the return value of importMeta be a string to evaluate on the main thread; but if we do that, it’s pretty much the same as prepending to load, I’d think. Are there other approaches?

Maybe in the end the “prepend to load“ approach is the best one, and we should perhaps add an example to the docs. But I thought that this should get some discussion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions