diff --git a/cli/rt/run.rs b/cli/rt/run.rs index 68f7b95a448546..00306b3086b5b9 100644 --- a/cli/rt/run.rs +++ b/cli/rt/run.rs @@ -1075,6 +1075,27 @@ pub async fn run( } checker }); + let (storage_key_resolver, origin_data_folder_path) = + match metadata.location.as_ref() { + Some(location) => { + let deno_dir = deno_resolver::cache::DenoDir::new( + sys_traits::impls::RealSys, + deno_cache_dir::resolve_deno_dir( + &sys_traits::impls::RealSys, + deno_cache_dir::ResolveDenoDirOptions { + maybe_initial_cwd: None, + maybe_custom_root: None, + }, + )? + .into_owned(), + ); + ( + StorageKeyResolver::from_flag(location), + Some(deno_dir.compile_origin_data_folder_path()), + ) + } + None => (StorageKeyResolver::empty(), None), + }; let lib_main_worker_options = LibMainWorkerOptions { argv: metadata.argv, log_level: WorkerLogLevel::Info, @@ -1095,7 +1116,7 @@ pub async fn run( node_debug: std::env::var("NODE_DEBUG").ok(), node_cluster_unique_id: std::env::var("NODE_UNIQUE_ID").ok(), node_cluster_sched_policy: std::env::var("NODE_CLUSTER_SCHED_POLICY").ok(), - origin_data_folder_path: None, + origin_data_folder_path, seed: metadata.seed, unsafely_ignore_certificate_errors: metadata .unsafely_ignore_certificate_errors, @@ -1123,7 +1144,7 @@ pub async fn run( create_npm_process_state_provider(&npm_resolver), pkg_json_resolver, root_cert_store_provider, - StorageKeyResolver::empty(), + storage_key_resolver, sys.clone(), lib_main_worker_options, Default::default(), diff --git a/libs/resolver/cache/deno_dir.rs b/libs/resolver/cache/deno_dir.rs index 0a54581ced3469..d99ec25a63f9b4 100644 --- a/libs/resolver/cache/deno_dir.rs +++ b/libs/resolver/cache/deno_dir.rs @@ -140,6 +140,11 @@ impl DenoDir { self.root.join("location_data") } + /// Path to the origin data folder used by `deno compile` binaries. + pub fn compile_origin_data_folder_path(&self) -> PathBuf { + self.root.join("origin_data") + } + /// File used for the upgrade checker. pub fn upgrade_check_file_path(&self) -> PathBuf { self.root.join("latest.txt") diff --git a/tests/specs/compile/storage_apis/__test__.jsonc b/tests/specs/compile/storage_apis/__test__.jsonc new file mode 100644 index 00000000000000..8f050f3f338bdf --- /dev/null +++ b/tests/specs/compile/storage_apis/__test__.jsonc @@ -0,0 +1,31 @@ +{ + "tempDir": true, + "tests": { + "with_location": { + "steps": [ + { + "if": "unix", + "args": "compile --location https://example.com/main --output main main.ts", + "output": "[WILDCARD]" + }, + { + "if": "unix", + "commandName": "main", + "args": [], + "output": "A\nB\n" + }, + { + "if": "windows", + "args": "compile --location https://example.com/main --output main.exe main.ts", + "output": "[WILDCARD]" + }, + { + "if": "windows", + "commandName": "./main.exe", + "args": [], + "output": "A\nB\n" + } + ] + } + } +} diff --git a/tests/specs/compile/storage_apis/main.ts b/tests/specs/compile/storage_apis/main.ts new file mode 100644 index 00000000000000..03ee409723d1ca --- /dev/null +++ b/tests/specs/compile/storage_apis/main.ts @@ -0,0 +1,11 @@ +localStorage.setItem("a", "A"); +console.log(localStorage.getItem("a")); + +const cache = await caches.open("v1"); +await cache.put( + new Request("https://example.com/b"), + new Response("B"), +); +const res = await cache.match(new Request("https://example.com/b")); +if (!res) throw new Error("unreachable: cache entry was just set"); +console.log(await res.text());