summaryrefslogtreecommitdiff
path: root/cli/main.rs
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2021-10-27 11:10:27 +1100
committerGitHub <noreply@github.com>2021-10-27 11:10:27 +1100
commit1c739470b590ea13dc0aa67c0ecc7ea6f49b5746 (patch)
treea7e6cb862cde74cc7861bc7124c540e62fa951b0 /cli/main.rs
parent6268703487da02d66552d1e1a42858aa273def90 (diff)
feat(ext/webstorage): use implied origin when --location not set (#12548)
Closes #11882 BREAKING CHANGE: Previously when `--location` was set, the unique storage key was derived from the the URL of the location instead of just the origin. This change correctly uses just the origin. This may cause previously persisted storage to change its key and data to not be available with the same location as before.
Diffstat (limited to 'cli/main.rs')
-rw-r--r--cli/main.rs35
1 files changed, 27 insertions, 8 deletions
diff --git a/cli/main.rs b/cli/main.rs
index f4d4046df..67b59a443 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -204,6 +204,32 @@ pub fn create_main_worker(
let create_web_worker_cb = create_web_worker_callback(ps.clone());
+ let maybe_storage_key = if let Some(location) = &ps.flags.location {
+ // if a location is set, then the ascii serialization of the location is
+ // used, unless the origin is opaque, and then no storage origin is set, as
+ // we can't expect the origin to be reproducible
+ let storage_origin = location.origin().ascii_serialization();
+ if storage_origin == "null" {
+ None
+ } else {
+ Some(storage_origin)
+ }
+ } else if let Some(config_file) = &ps.maybe_config_file {
+ // otherwise we will use the path to the config file
+ config_file.path.to_str().map(|s| s.to_string())
+ } else {
+ // otherwise we will use the path to the main module
+ Some(main_module.to_string())
+ };
+
+ let origin_storage_dir = maybe_storage_key.map(|key| {
+ ps.dir
+ .root
+ // TODO(@crowlKats): change to origin_data for 2.0
+ .join("location_data")
+ .join(checksum::gen(&[key.as_bytes()]))
+ });
+
let options = WorkerOptions {
bootstrap: BootstrapOptions {
apply_source_maps: true,
@@ -231,14 +257,7 @@ pub fn create_main_worker(
should_break_on_first_statement,
module_loader,
get_error_class_fn: Some(&crate::errors::get_error_class_name),
- origin_storage_dir: ps.flags.location.clone().map(|loc| {
- ps.dir
- .root
- .clone()
- // TODO(@crowlKats): change to origin_data for 2.0
- .join("location_data")
- .join(checksum::gen(&[loc.to_string().as_bytes()]))
- }),
+ origin_storage_dir,
blob_store: ps.blob_store.clone(),
broadcast_channel: ps.broadcast_channel.clone(),
shared_array_buffer_store: Some(ps.shared_array_buffer_store.clone()),