diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-03-08 14:14:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-08 14:14:28 -0500 |
commit | fee4943f760fae2c9386ceeda86c3f8fbfd8e6a0 (patch) | |
tree | 1328aa7ed36a7c47f78135dd5da4bcc83662de30 | |
parent | 8fdc376b4a3a383a3ae2fe29c6cc5ab821e5ec86 (diff) |
fix(node): resolve .css files in npm packages when type checking (#22804)
When type checking, we should just resolve css files in npm packages and
not surface a type checking error on the specifier.
-rw-r--r-- | ext/node/resolution.rs | 4 | ||||
-rw-r--r-- | tests/integration/npm_tests.rs | 16 | ||||
-rw-r--r-- | tests/testdata/npm/registry/@denotest/css-export/1.0.0/dist/index.css | 1 | ||||
-rw-r--r-- | tests/testdata/npm/registry/@denotest/css-export/1.0.0/package.json | 9 |
4 files changed, 30 insertions, 0 deletions
diff --git a/ext/node/resolution.rs b/ext/node/resolution.rs index 6f7b8c921..4590311e8 100644 --- a/ext/node/resolution.rs +++ b/ext/node/resolution.rs @@ -518,6 +518,10 @@ impl NodeResolver { return Some(path); } } + // allow resolving .css files for types resolution + if lowercase_path.ends_with(".css") { + return Some(path); + } None } diff --git a/tests/integration/npm_tests.rs b/tests/integration/npm_tests.rs index e4e06e830..7c34415da 100644 --- a/tests/integration/npm_tests.rs +++ b/tests/integration/npm_tests.rs @@ -2552,6 +2552,22 @@ console.log(getValue()); } #[test] +fn check_css_package_json_exports() { + let test_context = TestContextBuilder::for_npm().use_temp_cwd().build(); + let dir = test_context.temp_dir(); + dir.write( + "main.ts", + r#"import "npm:@denotest/css-export/dist/index.css";"#, + ); + test_context + .new_command() + .args("check main.ts") + .run() + .assert_matches_text("Download [WILDCARD]css-export\nDownload [WILDCARD]css-export/1.0.0.tgz\nCheck [WILDCARD]/main.ts\n") + .assert_exit_code(0); +} + +#[test] fn cjs_export_analysis_require_re_export() { let test_context = TestContextBuilder::for_npm().use_temp_cwd().build(); let dir = test_context.temp_dir(); diff --git a/tests/testdata/npm/registry/@denotest/css-export/1.0.0/dist/index.css b/tests/testdata/npm/registry/@denotest/css-export/1.0.0/dist/index.css new file mode 100644 index 000000000..2d91681f8 --- /dev/null +++ b/tests/testdata/npm/registry/@denotest/css-export/1.0.0/dist/index.css @@ -0,0 +1 @@ +body {}
\ No newline at end of file diff --git a/tests/testdata/npm/registry/@denotest/css-export/1.0.0/package.json b/tests/testdata/npm/registry/@denotest/css-export/1.0.0/package.json new file mode 100644 index 000000000..f7a76aec9 --- /dev/null +++ b/tests/testdata/npm/registry/@denotest/css-export/1.0.0/package.json @@ -0,0 +1,9 @@ +{ + "name": "@denotest/css-export", + "version": "1.0.0", + "type": "module", + "exports": { + ".": "./index.js", + "./dist/*": "./dist/*" + } +}
\ No newline at end of file |