ensure we look at the extension from the "parent" file

If you have a file `./a.js`, and you import `./b`, then `./b` should be
resolved based on the `./a.js` extension and use the
`jsResolutionOrder`.
This commit is contained in:
Robin Malfait 2023-03-20 19:02:52 +01:00
parent e046a37dbc
commit 439fdadb3a
No known key found for this signature in database
GPG key ID: 92F53D68B9041AFE

View file

@ -37,9 +37,7 @@ function resolveWithExtension(file, extensions) {
return null
}
function* _getModuleDependencies(filename, base, seen) {
let ext = path.extname(filename)
function* _getModuleDependencies(filename, base, seen, ext = path.extname(filename)) {
// Try to find the file
let absoluteFile = resolveWithExtension(
path.resolve(base, filename),
@ -56,6 +54,7 @@ function* _getModuleDependencies(filename, base, seen) {
// Resolve new base for new imports/requires
base = path.dirname(absoluteFile)
ext = path.extname(absoluteFile)
let contents = fs.readFileSync(absoluteFile, 'utf-8')
@ -68,7 +67,7 @@ function* _getModuleDependencies(filename, base, seen) {
// Bail out if it's not a relative file
if (!match[1].startsWith('.')) continue
yield* _getModuleDependencies(match[1], base, seen)
yield* _getModuleDependencies(match[1], base, seen, ext)
}
}