Skip to content

Commit

Permalink
next-core: ResolvedVc<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Nov 29, 2024
1 parent a2c6b99 commit 2138fe1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
70 changes: 41 additions & 29 deletions crates/next-core/src/app_segment_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ impl NextSegmentConfig {
/// An issue that occurred while parsing the app segment config.
#[turbo_tasks::value(shared)]
pub struct NextSegmentConfigParsingIssue {
ident: Vc<AssetIdent>,
ident: ResolvedVc<AssetIdent>,
detail: ResolvedVc<StyledString>,
source: Vc<IssueSource>,
source: ResolvedVc<IssueSource>,
}

#[turbo_tasks::value_impl]
Expand Down Expand Up @@ -315,49 +315,54 @@ fn issue_source(source: Vc<Box<dyn Source>>, span: Span) -> Vc<IssueSource> {
IssueSource::from_swc_offsets(source, span.lo.to_usize(), span.hi.to_usize())
}

fn parse_config_value(
async fn parse_config_value(
source: Vc<Box<dyn Source>>,
config: &mut NextSegmentConfig,
ident: &Ident,
init: &Expr,
eval_context: &EvalContext,
) {
) -> Result<()> {
let span = init.span();
let invalid_config = |detail: &str, value: &JsValue| {
let (explainer, hints) = value.explain(2, 0);
let detail =
StyledString::Text(format!("{detail} Got {explainer}.{hints}").into()).resolved_cell();

NextSegmentConfigParsingIssue {
ident: source.ident(),
detail,
source: issue_source(source, span),
async move {
NextSegmentConfigParsingIssue {
ident: source.ident().to_resolved().await?,
detail,
source: issue_source(source, span).to_resolved().await?,
}
.cell()
.emit();

anyhow::Ok(())
}
.cell()
.emit();
};

match &*ident.sym {
"dynamic" => {
let value = eval_context.eval(init);
let Some(val) = value.as_str() else {
invalid_config("`dynamic` needs to be a static string", &value);
return;
invalid_config("`dynamic` needs to be a static string", &value).await?;
return Ok(());
};

config.dynamic = match serde_json::from_value(Value::String(val.to_string())) {
Ok(dynamic) => Some(dynamic),
Err(err) => {
invalid_config(&format!("`dynamic` has an invalid value: {}", err), &value);
return;
invalid_config(&format!("`dynamic` has an invalid value: {}", err), &value)
.await?;
return Ok(());
}
};
}
"dynamicParams" => {
let value = eval_context.eval(init);
let Some(val) = value.as_bool() else {
invalid_config("`dynamicParams` needs to be a static boolean", &value);
return;
invalid_config("`dynamicParams` needs to be a static boolean", &value).await?;
return Ok(());
};

config.dynamic_params = Some(val);
Expand Down Expand Up @@ -385,8 +390,8 @@ fn parse_config_value(
"fetchCache" => {
let value = eval_context.eval(init);
let Some(val) = value.as_str() else {
invalid_config("`fetchCache` needs to be a static string", &value);
return;
invalid_config("`fetchCache` needs to be a static string", &value).await?;
return Ok(());
};

config.fetch_cache = match serde_json::from_value(Value::String(val.to_string())) {
Expand All @@ -395,23 +400,25 @@ fn parse_config_value(
invalid_config(
&format!("`fetchCache` has an invalid value: {}", err),
&value,
);
return;
)
.await?;
return Ok(());
}
};
}
"runtime" => {
let value = eval_context.eval(init);
let Some(val) = value.as_str() else {
invalid_config("`runtime` needs to be a static string", &value);
return;
invalid_config("`runtime` needs to be a static string", &value).await?;
return Ok(());
};

config.runtime = match serde_json::from_value(Value::String(val.to_string())) {
Ok(runtime) => Some(runtime),
Err(err) => {
invalid_config(&format!("`runtime` has an invalid value: {}", err), &value);
return;
invalid_config(&format!("`runtime` has an invalid value: {}", err), &value)
.await?;
return Ok(());
}
};
}
Expand All @@ -432,7 +439,9 @@ fn parse_config_value(
invalid_config(
"Values of the `preferredRegion` array need to static strings",
&item,
);
)
.await?;
return Ok(());
}
}
regions
Expand All @@ -441,8 +450,9 @@ fn parse_config_value(
invalid_config(
"`preferredRegion` needs to be a static string or array of static strings",
&value,
);
return;
)
.await?;
return Ok(());
}
};

Expand All @@ -459,14 +469,16 @@ fn parse_config_value(
"experimental_ppr" => {
let value = eval_context.eval(init);
let Some(val) = value.as_bool() else {
invalid_config("`experimental_ppr` needs to be a static boolean", &value);
return;
invalid_config("`experimental_ppr` needs to be a static boolean", &value).await?;
return Ok(());
};

config.experimental_ppr = Some(val);
}
_ => {}
}

Ok(())
}

#[turbo_tasks::function]
Expand Down
14 changes: 8 additions & 6 deletions crates/next-core/src/app_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,22 +538,22 @@ fn match_parallel_route(name: &str) -> Option<&str> {
name.strip_prefix('@')
}

fn conflict_issue(
async fn conflict_issue(
app_dir: Vc<FileSystemPath>,
e: &OccupiedEntry<AppPath, Entrypoint>,
e: &'_ OccupiedEntry<'_, AppPath, Entrypoint>,
a: &str,
b: &str,
value_a: &AppPage,
value_b: &AppPage,
) {
) -> Result<()> {
let item_names = if a == b {
format!("{}s", a)
} else {
format!("{} and {}", a, b)
};

DirectoryTreeIssue {
app_dir,
app_dir: app_dir.to_resolved().await?,
message: StyledString::Text(
format!(
"Conflicting {} at {}: {a} at {value_a} and {b} at {value_b}",
Expand All @@ -567,6 +567,8 @@ fn conflict_issue(
}
.cell()
.emit();

Ok(())
}

fn add_app_page(
Expand Down Expand Up @@ -1419,7 +1421,7 @@ pub async fn get_global_metadata(
#[turbo_tasks::value(shared)]
struct DirectoryTreeIssue {
pub severity: ResolvedVc<IssueSeverity>,
pub app_dir: Vc<FileSystemPath>,
pub app_dir: ResolvedVc<FileSystemPath>,
pub message: ResolvedVc<StyledString>,
}

Expand All @@ -1442,7 +1444,7 @@ impl Issue for DirectoryTreeIssue {

#[turbo_tasks::function]
fn file_path(&self) -> Vc<FileSystemPath> {
self.app_dir
*self.app_dir
}

#[turbo_tasks::function]
Expand Down
5 changes: 3 additions & 2 deletions crates/next-core/src/next_font/local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl BeforeResolvePlugin for NextFontLocalResolvePlugin {
let font_fallbacks = get_font_fallbacks(lookup_path, options_vc);
let properties = get_font_css_properties(options_vc, font_fallbacks).await;

let lookup_path = lookup_path.to_resolved().await?;
if let Err(e) = &properties {
for source_error in e.chain() {
if let Some(FontError::FontFileNotFound(font_path)) =
Expand Down Expand Up @@ -319,7 +320,7 @@ async fn font_file_options_from_query_map(
#[turbo_tasks::value(shared)]
struct FontResolvingIssue {
font_path: ResolvedVc<RcStr>,
origin_path: Vc<FileSystemPath>,
origin_path: ResolvedVc<FileSystemPath>,
}

#[turbo_tasks::value_impl]
Expand All @@ -331,7 +332,7 @@ impl Issue for FontResolvingIssue {

#[turbo_tasks::function]
fn file_path(&self) -> Vc<FileSystemPath> {
self.origin_path
*self.origin_path
}

#[turbo_tasks::function]
Expand Down

0 comments on commit 2138fe1

Please sign in to comment.