1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(node): resolve file.d specifiers in npm packages (#20918)

Makes type checking octokit work.

Closes #20854
This commit is contained in:
David Sherret 2023-10-17 00:26:38 +09:00 committed by GitHub
parent bd238be4b5
commit cb70c4d0c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 1 deletions

View file

@ -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",

3
cli/tests/testdata/npm/d_ext/main.out vendored Normal file
View file

@ -0,0 +1,3 @@
Download http://localhost:4545/npm/registry/@denotest/d-ext
Download http://localhost:4545/npm/registry/@denotest/d-ext/1.0.0.tgz
Check file:///[WILDCARD]/npm/d_ext/main.ts

3
cli/tests/testdata/npm/d_ext/main.ts vendored Normal file
View file

@ -0,0 +1,3 @@
import { test } from "npm:@denotest/d-ext";
console.log(test);

View file

@ -0,0 +1 @@
export const test: typeof import("./types.d").value;

View file

@ -0,0 +1 @@
module.exports.test = 5;

View file

@ -0,0 +1,5 @@
{
"name": "d-ext",
"version": "1.0.0",
"main": "./index.js"
}

View file

@ -0,0 +1 @@
export const value: 5;

View file

@ -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() {