Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions cli/rt/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, is there a policy on style guide or idk? Too many things are used by absolute paths and it feels sloppy

I did not add anything single-use here, but idk if I should, my finger itches to perform "replace with use" code action.

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,
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
5 changes: 5 additions & 0 deletions libs/resolver/cache/deno_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ impl<TSys: DiskCacheSys> DenoDir<TSys> {
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")
Expand Down
31 changes: 31 additions & 0 deletions tests/specs/compile/storage_apis/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
}
11 changes: 11 additions & 0 deletions tests/specs/compile/storage_apis/main.ts
Original file line number Diff line number Diff line change
@@ -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());
Loading