Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,9 @@ function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
export function moduleResolve(specifier, base, conditions, preserveSymlinks) {
// Note: The Node code supports `base` as a string (in this internal API) too,
// we don’t.
if (conditions === undefined) {
conditions = getConditionsSet()
}
const protocol = base.protocol
const isData = protocol === 'data:'
const isRemote = isData || protocol === 'http:' || protocol === 'https:'
Expand Down
21 changes: 17 additions & 4 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import process from 'node:process'
import {URL, pathToFileURL} from 'node:url'
import test from 'node:test'
import semver from 'semver'
import {resolve} from '../index.js'
import {moduleResolve, resolve} from '../index.js'

const windows = process.platform === 'win32'
const nodeBefore18 = semver.lt(process.versions.node, '18.0.0')
Expand Down Expand Up @@ -258,9 +258,13 @@ test(
assert.fail()
} catch (error) {
const exception = /** @type {ErrnoException} */ (error)
assert.equal(
exception.code,
'ERR_NETWORK_IMPORT_DISALLOWED',
assert(
[
// Node 22+
'ERR_ASSERTION',
// Node 20-
'ERR_NETWORK_IMPORT_DISALLOWED'
].includes(/** @type {string} */ (exception.code)),
'should not support loading builtins from http'
)
}
Expand Down Expand Up @@ -690,3 +694,12 @@ test(
)
}
)

test('moduleResolve(specifier, parent, conditions?, preserveSymlinks?)', function () {
assert.equal(
moduleResolve('package-export-conditions', new URL(import.meta.url)).href,
new URL('node_modules/package-export-conditions/esm.mjs', import.meta.url)
.href,
'should resolve to the ESM entry point'
)
})
Empty file.
Empty file.
6 changes: 6 additions & 0 deletions test/node_modules/package-export-conditions/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.