Skip to content

Commit 21de0c1

Browse files
committed
Fixed lint issues and failing tests
1 parent c9b2a33 commit 21de0c1

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/get-exports.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function resolvePackageImports (specifier, fromUrl) {
5555

5656
// Look for path inside packageJson
5757
let resolvedPath
58-
if (typeof imports == 'object') {
58+
if (Object.prototype.toString.call(imports) === '[object Object]') {
5959
const requireSpecifier = imports.require
6060
const importSpecifier = imports.import
6161
// look for the possibility of require and import which is standard for CJS/ESM
@@ -65,12 +65,12 @@ function resolvePackageImports (specifier, fromUrl) {
6565
} else if (imports.node || imports.default) {
6666
resolvedPath = imports.node || imports.default
6767
}
68-
} else if (typeof imports == 'string') {
68+
} else if (typeof imports === 'string') {
6969
resolvedPath = imports
7070
}
7171

72-
if (existsSync(resolvedPath)) {
73-
return resolvedPath
72+
if (resolvedPath) {
73+
return pathToFileURL(require.resolve(resolvedPath, { paths: [dirname(fileURLToPath(fromUrl))] })).href
7474
}
7575
}
7676
// return if we find a package.json but did not find an import
@@ -108,16 +108,16 @@ async function getCjsExports (url, context, parentLoad, source) {
108108
let newUrl
109109
// Entries in the import field should always start with #
110110
if (re.startsWith('#')) {
111-
re = resolvePackageImports(re, url)
112-
if (!re) {
111+
newUrl = resolvePackageImports(re, url)
112+
if (!newUrl) {
113113
// Unable to resolve specifier import
114114
return
115115
}
116+
} else {
117+
// Resolve the re-exported module relative to the current module.
118+
newUrl = pathToFileURL(require.resolve(re, { paths: [dirname(fileURLToPath(url))] })).href
116119
}
117120

118-
// Resolve the re-exported module relative to the current module.
119-
newUrl = pathToFileURL(require.resolve(re, { paths: [dirname(fileURLToPath(url))] })).href
120-
121121
if (newUrl.endsWith('.node') || newUrl.endsWith('.json')) {
122122
return
123123
}

0 commit comments

Comments
 (0)