Skip to content

Commit

Permalink
fix(node): resolve file.d specifiers in npm packages (denoland#20918)
Browse files Browse the repository at this point in the history
Makes type checking octokit work.

Closes denoland#20854
  • Loading branch information
dsherret committed Oct 16, 2023
1 parent bd238be commit cb70c4d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cli/tests/integration/npm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,13 @@ itest!(types_no_types_entry {
exit_code: 1,
});

itest!(types_d_ext {
args: "check --all npm/d_ext/main.ts",
output: "npm/d_ext/main.out",
envs: env_vars_for_npm_tests(),
http_server: true,
});

itest!(typescript_file_in_package {
args: "run npm/typescript_file_in_package/main.ts",
output: "npm/typescript_file_in_package/main.out",
Expand Down
3 changes: 3 additions & 0 deletions cli/tests/testdata/npm/d_ext/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Download http:https://localhost:4545/npm/registry/@denotest/d-ext
Download http:https://localhost:4545/npm/registry/@denotest/d-ext/1.0.0.tgz
Check file:https:///[WILDCARD]/npm/d_ext/main.ts
3 changes: 3 additions & 0 deletions cli/tests/testdata/npm/d_ext/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { test } from "npm:@denotest/d-ext";

console.log(test);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const test: typeof import("./types.d").value;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports.test = 5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "d-ext",
"version": "1.0.0",
"main": "./index.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const value: 5;
4 changes: 3 additions & 1 deletion ext/node/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,9 @@ fn is_relative_specifier(specifier: &str) -> bool {
/// Alternate `PathBuf::with_extension` that will handle known extensions
/// more intelligently.
fn with_known_extension(path: &Path, ext: &str) -> PathBuf {
const NON_DECL_EXTS: &[&str] = &["cjs", "js", "json", "jsx", "mjs", "tsx"];
const NON_DECL_EXTS: &[&str] = &[
"cjs", "js", "json", "jsx", "mjs", "tsx", /* ex. types.d */ "d",
];
const DECL_EXTS: &[&str] = &["cts", "mts", "ts"];

let file_name = match path.file_name() {
Expand Down

0 comments on commit cb70c4d

Please sign in to comment.