dop251 / goja_nodejs

Nodejs compatibility library for Goja
MIT License
329 stars 78 forks source link

Support For Custom Extensions Module Loading #76

Closed kudla closed 5 months ago

kudla commented 5 months ago

Hi. This allows to customize file extensions to be loaded for the Registry.

As an alternative it is really possible to handle this on a srcLoader level.
Still it could be useful to address this in general for the cases like

WithLoadExtensions(".mjs", ".js", ".json"),
WithLoader(func(name string) ([]byte, error) {
        if /* some custom condition */ {
            // some custom implementation
        }
        // Fallback. for default loader
        return require.DefaultSourceLoader(name)
}),
dop251 commented 5 months ago

Hi. Thanks for the submission.

The current loading mechanism tries to follow the standard as close as possible. Any customisations or modifications should be left external.