From 7fdc3c8f1fc27be2ca7d4ff62b9fd8ecb3d24e61 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 6 Dec 2023 16:25:24 -0500 Subject: fix(compile/npm): ignore symlinks to non-existent paths in node_modules directory (#21479) Part of https://github.com/denoland/deno/issues/21476 --- cli/tests/integration/compile_tests.rs | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'cli/tests/integration') diff --git a/cli/tests/integration/compile_tests.rs b/cli/tests/integration/compile_tests.rs index 9963a044b..95d214429 100644 --- a/cli/tests/integration/compile_tests.rs +++ b/cli/tests/integration/compile_tests.rs @@ -1062,6 +1062,44 @@ fn compile_node_modules_symlink_outside() { output.assert_matches_file("compile/node_modules_symlink_outside/main.out"); } +#[test] +fn compile_node_modules_symlink_non_existent() { + let context = TestContextBuilder::for_npm().use_temp_cwd().build(); + let temp_dir = context.temp_dir().path(); + temp_dir.join("main.ts").write( + r#"import { getValue, setValue } from "npm:@denotest/esm-basic"; +setValue(4); +console.log(getValue());"#, + ); + let node_modules_dir = temp_dir.join("node_modules"); + node_modules_dir.create_dir_all(); + // create a symlink that points to a non_existent file + node_modules_dir.symlink_dir("non_existent", "folder"); + // compile folder + let output = context + .new_command() + .args("compile --allow-read --node-modules-dir --output bin main.ts") + .run(); + output.assert_exit_code(0); + output.assert_matches_text( + r#"Download http://localhost:4545/npm/registry/@denotest/esm-basic +Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz +Initialize @denotest/esm-basic@1.0.0 +Check file:///[WILDCARD]/main.ts +Compile file:///[WILDCARD]/main.ts to [WILDCARD] +Warning Failed resolving symlink. Ignoring. + Path: [WILDCARD] + Message: [WILDCARD]) +"#, + ); + + // run + let binary_path = + temp_dir.join(if cfg!(windows) { "bin.exe" } else { "bin" }); + let output = context.new_command().name(binary_path).run(); + output.assert_matches_text("4\n"); +} + #[test] fn dynamic_imports_tmp_lit() { let context = TestContextBuilder::new().build(); -- cgit v1.2.3