Skip to content

Commit d1f85dd

Browse files
authored
fix: issue#246
#246
1 parent 2346fe5 commit d1f85dd

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const fileSystem = fs as FileSystem
102102
const JS_EXT_PATTERN = /\.(?:[cm]js|jsx?)$/
103103
const RELATIVE_PATH_PATTERN = /^\.{1,2}(?:\/.*)?$/
104104

105+
let packageJsonPaths: string[] = []
105106
let previousOptionsHash: string
106107
let optionsHash: string
107108
let cachedOptions: InternalResolverOptions | undefined
@@ -169,6 +170,7 @@ export function resolve(
169170
}
170171
}
171172

173+
packageJsonPaths = fastGlob.sync(["**/package.json", "!**/node_modules/**"]);
172174
initMappers(cachedOptions)
173175

174176
const mappedPath = getMappedPath(source, file, cachedOptions.extensions, true)
@@ -271,6 +273,11 @@ function getMappedPath(
271273
paths = [resolved]
272274
}
273275
} else {
276+
const packageJsonPath = packageJsonPaths.find((p) => {
277+
const { dir } = path.parse(p)
278+
return !!dir && file.includes(dir)
279+
})
280+
274281
paths = mappers!
275282
.map(mapper =>
276283
mapper?.(source).map(item => [
@@ -299,6 +306,7 @@ function getMappedPath(
299306

300307
return false
301308
})
309+
.filter((item) => item.includes(packageJsonPath))
302310
}
303311

304312
if (retry && paths.length === 0) {

0 commit comments

Comments
 (0)