Skip to content

Commit 8975e38

Browse files
authored
test: sync enhanced-resolve#579 tsconfig paths fall-through (#212)
1 parent 64a7440 commit 8975e38

5 files changed

Lines changed: 54 additions & 0 deletions

File tree

fixtures/tsconfig/cases/scoped-pkg-fallthrough/node_modules/@sentry/react/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fixtures/tsconfig/cases/scoped-pkg-fallthrough/node_modules/@sentry/react/package.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as sentry from "@sentry/react";
2+
3+
export const helper = true;
4+
export { sentry };
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"paths": {
5+
"@*": ["./src/*"]
6+
}
7+
}
8+
}

src/tests/tsconfig_paths.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,42 @@ async fn test_template_variable() {
269269
}
270270
}
271271

272+
// https://github.com/webpack/enhanced-resolve/pull/579
273+
// https://github.com/webpack/webpack/issues/20944
274+
// When a tsconfig `paths` pattern (e.g. "@*") matches a request but the
275+
// mapped target does not exist, resolution should fall through to normal
276+
// module resolution (node_modules), matching TypeScript's native behavior.
277+
#[tokio::test]
278+
async fn tsconfig_paths_scoped_pkg_fallthrough() {
279+
let f = super::fixture_root().join("tsconfig/cases/scoped-pkg-fallthrough");
280+
281+
let resolver = Resolver::new(ResolveOptions {
282+
extensions: vec![".ts".into(), ".tsx".into(), ".js".into()],
283+
main_fields: vec!["main".into()],
284+
main_files: vec!["index".into()],
285+
tsconfig: Some(TsconfigOptions {
286+
config_file: f.join("tsconfig.json"),
287+
references: TsconfigReferences::Auto,
288+
}),
289+
..ResolveOptions::default()
290+
});
291+
292+
// "@helper" resolves via the "@*" mapping when the mapped path exists
293+
let resolved_path = resolver.resolve(&f, "@helper").await.map(|p| p.full_path());
294+
assert_eq!(resolved_path, Ok(f.join("src/helper/index.ts")));
295+
296+
// "@sentry/react" falls through to node_modules when "@*" mapping does
297+
// not resolve to an existing file.
298+
let resolved_path = resolver
299+
.resolve(&f, "@sentry/react")
300+
.await
301+
.map(|p| p.full_path());
302+
assert_eq!(
303+
resolved_path,
304+
Ok(f.join("node_modules/@sentry/react/index.js"))
305+
);
306+
}
307+
272308
#[cfg(not(target_os = "windows"))] // MemoryFS's path separator is always `/` so the test will not pass in windows.
273309
mod windows_test {
274310
use std::path::{Path, PathBuf};

0 commit comments

Comments
 (0)