Skip to content

Commit

Permalink
make query a string
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Aug 10, 2023
1 parent 83ff0f8 commit 7524638
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 196 deletions.
11 changes: 6 additions & 5 deletions crates/turbopack-cli/src/build/mod.rs
Expand Up @@ -24,7 +24,6 @@ use turbopack_core::{
resolve::{
origin::{PlainResolveOrigin, ResolveOriginExt},
parse::Request,
pattern::QueryMap,
},
};
use turbopack_env::dotenv::load_env;
Expand Down Expand Up @@ -205,11 +204,13 @@ async fn build_internal(
.map(|r| async move {
Ok(match &*r.await? {
EntryRequest::Relative(p) => {
Request::relative(Value::new(p.clone().into()), QueryMap::empty(), false)
}
EntryRequest::Module(m, p) => {
Request::module(m.clone(), Value::new(p.clone().into()), QueryMap::empty())
Request::relative(Value::new(p.clone().into()), Vc::<String>::empty(), false)
}
EntryRequest::Module(m, p) => Request::module(
m.clone(),
Value::new(p.clone().into()),
Vc::<String>::empty(),
),
})
})
.try_join()
Expand Down
12 changes: 7 additions & 5 deletions crates/turbopack-cli/src/dev/mod.rs
Expand Up @@ -23,7 +23,7 @@ use turbopack_cli_utils::issue::{ConsoleUi, LogOptions};
use turbopack_core::{
environment::ServerAddr,
issue::{IssueReporter, IssueSeverity},
resolve::{parse::Request, pattern::QueryMap},
resolve::parse::Request,
server_fs::ServerFileSystem,
};
use turbopack_dev::DevChunkingContext;
Expand Down Expand Up @@ -269,11 +269,13 @@ async fn source(
.iter()
.map(|r| match r {
EntryRequest::Relative(p) => {
Request::relative(Value::new(p.clone().into()), QueryMap::empty(), false)
}
EntryRequest::Module(m, p) => {
Request::module(m.clone(), Value::new(p.clone().into()), QueryMap::empty())
Request::relative(Value::new(p.clone().into()), Vc::<String>::empty(), false)
}
EntryRequest::Module(m, p) => Request::module(
m.clone(),
Value::new(p.clone().into()),
Vc::<String>::empty(),
),
})
.collect();

Expand Down
7 changes: 3 additions & 4 deletions crates/turbopack-core/src/file_source.rs
Expand Up @@ -5,7 +5,6 @@ use turbo_tasks_fs::{FileContent, FileSystemEntryType, FileSystemPath, LinkConte
use crate::{
asset::{Asset, AssetContent},
ident::AssetIdent,
resolve::pattern::QueryMap,
source::Source,
};

Expand All @@ -14,7 +13,7 @@ use crate::{
#[turbo_tasks::value]
pub struct FileSource {
pub path: Vc<FileSystemPath>,
pub query: Vc<QueryMap>,
pub query: Vc<String>,
}

#[turbo_tasks::value_impl]
Expand All @@ -23,12 +22,12 @@ impl FileSource {
pub fn new(path: Vc<FileSystemPath>) -> Vc<Self> {
Self::cell(FileSource {
path,
query: QueryMap::empty(),
query: Vc::<String>::empty(),
})
}

#[turbo_tasks::function]
pub fn new_with_query(path: Vc<FileSystemPath>, query: Vc<QueryMap>) -> Vc<Self> {
pub fn new_with_query(path: Vc<FileSystemPath>, query: Vc<String>) -> Vc<Self> {
Self::cell(FileSource { path, query })
}
}
Expand Down
20 changes: 10 additions & 10 deletions crates/turbopack-core/src/ident.rs
Expand Up @@ -5,15 +5,15 @@ use turbo_tasks::{Value, ValueToString, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbo_tasks_hash::{encode_hex, hash_xxh3_hash64, DeterministicHash, Xxh3Hash64Hasher};

use crate::resolve::{pattern::QueryMap, ModulePart};
use crate::resolve::ModulePart;

#[turbo_tasks::value(serialization = "auto_for_input")]
#[derive(Clone, Debug, PartialOrd, Ord, Hash)]
pub struct AssetIdent {
/// The primary path of the asset
pub path: Vc<FileSystemPath>,
/// The query string of the asset (e.g. `?foo=bar`)
pub query: Vc<QueryMap>,
pub query: Vc<String>,
/// The fragment of the asset (e.g. `#foo`)
pub fragment: Option<Vc<String>>,
/// The assets that are nested in this asset
Expand Down Expand Up @@ -50,7 +50,7 @@ impl ValueToString for AssetIdent {
async fn to_string(&self) -> Result<Vc<String>> {
let mut s = self.path.to_string().await?.clone_value();

let query = self.query.to_string().await?;
let query = self.query.await?;
if !query.is_empty() {
write!(s, "?{}", &*query)?;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ impl AssetIdent {
pub fn from_path(path: Vc<FileSystemPath>) -> Vc<Self> {
Self::new(Value::new(AssetIdent {
path,
query: QueryMap::empty(),
query: Vc::<String>::empty(),
fragment: None,
assets: Vec::new(),
modifiers: Vec::new(),
Expand All @@ -102,9 +102,9 @@ impl AssetIdent {
}

#[turbo_tasks::function]
pub fn with_query(&self, query: Vc<QueryMap>) -> Vc<Self> {
pub fn with_query(&self, query: Vc<String>) -> Vc<Self> {
let mut this = self.clone();
this.query = this.query.merge(query);
this.query = query;
Self::new(Value::new(this))
}

Expand Down Expand Up @@ -142,7 +142,7 @@ impl AssetIdent {
}

#[turbo_tasks::function]
pub fn query(&self) -> Vc<QueryMap> {
pub fn query(&self) -> Vc<String> {
self.query
}

Expand Down Expand Up @@ -188,10 +188,10 @@ impl AssetIdent {
modifiers,
part,
} = self;
for (key, value) in &*query.await? {
let query = query.await?;
if !query.is_empty() {
0_u8.deterministic_hash(&mut hasher);
key.deterministic_hash(&mut hasher);
value.deterministic_hash(&mut hasher);
query.deterministic_hash(&mut hasher);
has_hash = true;
}
if let Some(fragment) = fragment {
Expand Down

0 comments on commit 7524638

Please sign in to comment.