Skip to content

Commit 5654bce

Browse files
committed
fix: tsconfig paths should not be applied to paths inside node_modules (#760)
Found this case while working on tsconfig discovered. Still uncertain about this change but the original test returns not found. https://github.com/parcel-bundler/parcel/blob/b6224fd519f95e68d8b93ba90376fd94c8b76e69/packages/utils/node-resolver-rs/src/lib.rs#L2372-L2384 It should not pick up any tsconfig while resolving specifier inside `node_modules`. https://github.com/oxc-project/oxc-resolver/blob/19902fbd7a8f926c4a99b59552f5e7dffbafb230/fixtures/tsconfig/node_modules/tsconfig-not-used/tsconfig.json#L4 Reference: * https://github.com/aleclarson/vite-tsconfig-paths/blob/master/src/index.ts * https://github.com/jonaskello/tsconfig-paths-webpack-plugin/blob/master/src/plugin.ts The webpack plugin has no mention of `node_modules` but the vite plugin does. @sapphi-red I'm not confident with this logic overall so assigning you to review.
1 parent dc46713 commit 5654bce

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,9 @@ impl<Fs: FileSystem> ResolverGeneric<Fs> {
14531453
specifier: &str,
14541454
ctx: &mut Ctx,
14551455
) -> ResolveResult {
1456+
if cached_path.inside_node_modules() {
1457+
return Ok(None);
1458+
}
14561459
let Some(tsconfig_options) = &self.options.tsconfig else {
14571460
return Ok(None);
14581461
};

src/tests/tsconfig_paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn tsconfig_resolve() {
4545

4646
#[rustfmt::skip]
4747
let data = [
48-
(f.join("node_modules/tsconfig-not-used"), "ts-path", Ok(f.join("src/foo.js"))),
48+
(f.join("node_modules/tsconfig-not-used"), "ts-path", Err(ResolveError::NotFound("ts-path".to_string()))),
4949
];
5050

5151
let resolver = Resolver::new(ResolveOptions {

0 commit comments

Comments
 (0)