From 02b480b171847a736cca9d396481c4693c3cfe4a Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 25 Nov 2024 17:08:06 -0500 Subject: [PATCH] fix(compile): do not error embedding same symlink via multiple methods (#27015) Closes https://github.com/denoland/deno/issues/27012 --- cli/standalone/virtual_fs.rs | 4 +-- .../include/symlink_twice/__test__.jsonc | 27 +++++++++++++++++++ .../compile/include/symlink_twice/setup.js | 3 +++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/specs/compile/include/symlink_twice/__test__.jsonc create mode 100644 tests/specs/compile/include/symlink_twice/setup.js diff --git a/cli/standalone/virtual_fs.rs b/cli/standalone/virtual_fs.rs index 5b8076549d..b630f629c5 100644 --- a/cli/standalone/virtual_fs.rs +++ b/cli/standalone/virtual_fs.rs @@ -329,7 +329,7 @@ impl VfsBuilder { let dir = self.add_dir(path.parent().unwrap())?; let name = path.file_name().unwrap().to_string_lossy(); match dir.entries.binary_search_by(|e| e.name().cmp(&name)) { - Ok(_) => unreachable!(), + Ok(_) => Ok(()), // previously inserted Err(insert_index) => { dir.entries.insert( insert_index, @@ -341,9 +341,9 @@ impl VfsBuilder { .collect::>(), }), ); + Ok(()) } } - Ok(()) } pub fn into_dir_and_files(self) -> (VirtualDirectory, Vec>) { diff --git a/tests/specs/compile/include/symlink_twice/__test__.jsonc b/tests/specs/compile/include/symlink_twice/__test__.jsonc new file mode 100644 index 0000000000..ebdf824f43 --- /dev/null +++ b/tests/specs/compile/include/symlink_twice/__test__.jsonc @@ -0,0 +1,27 @@ +{ + "tempDir": true, + "steps": [{ + "args": "run -A setup.js", + "output": "[WILDCARD]" + }, { + "if": "unix", + "args": "compile --allow-read=data --include . --output main link.js", + "output": "[WILDCARD]" + }, { + "if": "unix", + "commandName": "./main", + "args": [], + "output": "1\n", + "exitCode": 0 + }, { + "if": "windows", + "args": "compile --allow-read=data --include . --output main.exe link.js", + "output": "[WILDCARD]" + }, { + "if": "windows", + "commandName": "./main.exe", + "args": [], + "output": "1\n", + "exitCode": 0 + }] +} diff --git a/tests/specs/compile/include/symlink_twice/setup.js b/tests/specs/compile/include/symlink_twice/setup.js new file mode 100644 index 0000000000..3e713dd63e --- /dev/null +++ b/tests/specs/compile/include/symlink_twice/setup.js @@ -0,0 +1,3 @@ +Deno.mkdirSync("data"); +Deno.writeTextFileSync("index.js", "console.log(1);"); +Deno.symlinkSync("index.js", "link.js");