Skip to content

esm: allow `resolve` to optionally return import assertions

As part of #44710 @targos discovered that our test fixture loader for “assertionless” JSON imports—import data from './file.json' where there’s no assert { type: 'json' }—was only working because it mutated the context.importAssertions object, which doesn’t work on the “loaders off-thread” branch. But it arguably shouldn’t work on main either, as mutating function input is a poor way for a hook to return information.

This PR adds an optional importAssertions property to the object returned by the resolve hook, to enable the use case where a module is cached with different import assertions than were present in the original source. I think this is the “correct” way that user hooks should inform the internal module loader what assertion type to use as part of the module cache key, rather than relying on input mutation.

cc @nodejs/loaders

Merge request reports

Loading