Skip to content

Commit

Permalink
fix(lsp): do sloppy resolution for node-to-node imports in byonm (den…
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed Jul 9, 2024
1 parent c11e2c7 commit 0087402
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cli/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,9 @@ impl Resolver for CliGraphResolver {
}
}
}
} else if referrer.scheme() == "file" {
}

if referrer.scheme() == "file" {
if let Some(node_resolver) = &self.node_resolver {
let node_result = node_resolver.resolve_if_in_npm_package(
specifier,
Expand Down
40 changes: 40 additions & 0 deletions tests/integration/lsp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14275,6 +14275,46 @@ fn sloppy_imports_not_enabled() {
client.shutdown();
}

// Regression test for https://github.com/denoland/deno/issues/24457.
#[test]
fn lsp_byonm_js_import_resolves_to_dts() {
let context = TestContextBuilder::new()
.use_http_server()
.use_temp_cwd()
.add_npm_env_vars()
.build();
let temp_dir = context.temp_dir();
temp_dir.write(
"deno.json",
json!({
"unstable": ["byonm"],
})
.to_string(),
);
temp_dir.write(
"package.json",
json!({
"dependencies": {
"postcss": "*",
},
})
.to_string(),
);
context.run_npm("install");
let mut client = context.new_lsp_command().build();
client.initialize_default();
let diagnostics = client.did_open(json!({
"textDocument": {
"uri": temp_dir.uri().join("node_modules/postcss/lib/comment.d.ts").unwrap(),
"languageId": "typescript",
"version": 1,
"text": temp_dir.path().join("node_modules/postcss/lib/comment.d.ts").read_to_string(),
}
}));
assert_eq!(json!(diagnostics.all()), json!([]));
client.shutdown();
}

#[test]
fn decorators_tc39() {
let context = TestContextBuilder::new().use_temp_cwd().build();
Expand Down

0 comments on commit 0087402

Please sign in to comment.