Skip to content

loader: return package format from defaultResolve if known

This is a proposed modification of defaultResolve to return the package format in case it has been found during package resolution. The format will be returned as described in the documentation: https://nodejs.org/api/esm.html#resolvespecifier-context-defaultresolve There is one new unit test as well: test/es-module/test-esm-resolve-type.js

Please consider this PR as a discussion base if this feature is correctly implemented. The approach was to only return the format from defaultResolve if a package.json file has been found and parsed. All other cases only return url as before.

All unit tests are green, the new test passes as well.

The modification for recomputing the format type found in lib/internal/modules/esm/load.js is a temporary solution for the make test because highlight.js seems to be a dual package but declares type: commonjs in its package.json: https://github.com/highlightjs/highlight.js/blob/main/package.json#L35

Merge request reports

Loading