summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-10-17 00:26:38 +0900
committerGitHub <noreply@github.com>2023-10-17 00:26:38 +0900
commitcb70c4d0c4c97999deef0c13eaf91db635957517 (patch)
tree68d78653dbb1a3b6536eef652a86deb995b6dbab
parentbd238be4b5f26126fee8820d2a64c6660dfd6b6b (diff)
fix(node): resolve file.d specifiers in npm packages (#20918)
Makes type checking octokit work. Closes #20854
-rw-r--r--cli/tests/integration/npm_tests.rs7
-rw-r--r--cli/tests/testdata/npm/d_ext/main.out3
-rw-r--r--cli/tests/testdata/npm/d_ext/main.ts3
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/index.d.ts1
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/index.js1
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/package.json5
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/types.d.ts1
-rw-r--r--ext/node/resolution.rs4
8 files changed, 24 insertions, 1 deletions
diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs
index 25a39b68d..ddbc79cec 100644
--- a/cli/tests/integration/npm_tests.rs
+++ b/cli/tests/integration/npm_tests.rs
@@ -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",
diff --git a/cli/tests/testdata/npm/d_ext/main.out b/cli/tests/testdata/npm/d_ext/main.out
new file mode 100644
index 000000000..e96c6e392
--- /dev/null
+++ b/cli/tests/testdata/npm/d_ext/main.out
@@ -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
diff --git a/cli/tests/testdata/npm/d_ext/main.ts b/cli/tests/testdata/npm/d_ext/main.ts
new file mode 100644
index 000000000..c92dbe065
--- /dev/null
+++ b/cli/tests/testdata/npm/d_ext/main.ts
@@ -0,0 +1,3 @@
+import { test } from "npm:@denotest/d-ext";
+
+console.log(test);
diff --git a/cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/index.d.ts b/cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/index.d.ts
new file mode 100644
index 000000000..47326c0f6
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/index.d.ts
@@ -0,0 +1 @@
+export const test: typeof import("./types.d").value;
diff --git a/cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/index.js b/cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/index.js
new file mode 100644
index 000000000..62b353f3d
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/index.js
@@ -0,0 +1 @@
+module.exports.test = 5;
diff --git a/cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/package.json
new file mode 100644
index 000000000..a0702a56b
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "d-ext",
+ "version": "1.0.0",
+ "main": "./index.js"
+} \ No newline at end of file
diff --git a/cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/types.d.ts b/cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/types.d.ts
new file mode 100644
index 000000000..dedc54b03
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/d-ext/1.0.0/types.d.ts
@@ -0,0 +1 @@
+export const value: 5;
diff --git a/ext/node/resolution.rs b/ext/node/resolution.rs
index 22ab47ce6..cbe9f643f 100644
--- a/ext/node/resolution.rs
+++ b/ext/node/resolution.rs
@@ -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() {