Skip to content

Commit

Permalink
Merge branch 'canary' into check-test-binary-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Mar 27, 2023
2 parents 4212318 + e3875d7 commit 4716990
Show file tree
Hide file tree
Showing 16 changed files with 1,030 additions and 84 deletions.
3 changes: 1 addition & 2 deletions packages/next-swc/crates/next-build/Cargo.toml
Expand Up @@ -7,7 +7,6 @@ edition = "2021"
autobenches = false

[features]
next-font-local = ["next-core/next-font-local"]
native-tls = ["next-core/native-tls"]
rustls-tls = ["next-core/rustls-tls"]
custom_allocator = ["turbo-malloc/custom_allocator"]
Expand All @@ -24,4 +23,4 @@ turbo-tasks-build = { workspace = true }
vergen = { version = "7.3.2", default-features = false, features = [
"cargo",
"build",
] }
] }
1 change: 0 additions & 1 deletion packages/next-swc/crates/next-core/Cargo.toml
Expand Up @@ -43,7 +43,6 @@ swc_core = { workspace = true, features = ["ecma_ast", "common"] }
turbo-tasks-build = { workspace = true }

[features]
next-font-local = []
native-tls = ["turbo-tasks-fetch/native-tls"]
rustls-tls = ["turbo-tasks-fetch/rustls-tls"]
# Internal only. Enabled when building for the Next.js integration test suite.
Expand Down
Expand Up @@ -34,6 +34,7 @@ pub(crate) struct AutomaticFontFallback {
pub adjustment: Option<FontAdjustment>,
}

#[derive(Debug)]
#[turbo_tasks::value(shared)]
pub(crate) enum FontFallback {
Automatic(AutomaticFontFallbackVc),
Expand All @@ -45,7 +46,7 @@ pub(crate) enum FontFallback {
}

#[turbo_tasks::value(transparent)]
pub(crate) struct FontFallbacks(Vec<FontFallback>);
pub(crate) struct FontFallbacks(Vec<FontFallbackVc>);

#[derive(Debug, PartialEq, Serialize, Deserialize, TraceRawVcs)]
pub(crate) struct FontAdjustment {
Expand Down
Expand Up @@ -382,7 +382,7 @@ async fn get_mock_stylesheet(
) -> Result<Option<String>> {
use std::{collections::HashMap, path::Path};

use turbo_tasks::{CompletionVc, Value};
use turbo_tasks::CompletionVc;
use turbo_tasks_env::{CommandLineProcessEnvVc, ProcessEnv};
use turbo_tasks_fs::{
json::parse_json_with_source_context, DiskFileSystemVc, File, FileSystem,
Expand Down Expand Up @@ -418,7 +418,7 @@ async fn get_mock_stylesheet(
let ExecutionContext {
env,
project_path,
intermediate_output_path,
chunking_context,
} = *execution_context.await?;
let context = node_evaluate_asset_context(project_path, None, None);
let loader_path = mock_fs.root().join("loader.js");
Expand Down Expand Up @@ -449,7 +449,7 @@ async fn get_mock_stylesheet(
env,
AssetIdentVc::from_path(loader_path),
context,
intermediate_output_path,
chunking_context,
None,
vec![],
CompletionVc::immutable(),
Expand Down
@@ -1,9 +1,11 @@
use anyhow::Result;
use indoc::formatdoc;
use turbo_tasks::primitives::{OptionStringVc, StringVc};

use super::FontCssPropertiesVc;
use crate::next_font::{font_fallback::FontFallbackVc, stylesheet::build_fallback_definition};
use crate::next_font::{
font_fallback::{FontFallbackVc, FontFallbacksVc},
stylesheet::{build_fallback_definition, build_font_class_rules},
};

#[turbo_tasks::function]
pub(super) async fn build_stylesheet(
Expand All @@ -15,51 +17,9 @@ pub(super) async fn build_stylesheet(
let mut stylesheet = base_stylesheet
.as_ref()
.map_or_else(|| "".to_owned(), |s| s.to_owned());
if let Some(definition) = &*build_fallback_definition(font_fallback).await? {
stylesheet.push_str(definition);
}

stylesheet
.push_str(&build_fallback_definition(FontFallbacksVc::cell(vec![font_fallback])).await?);
stylesheet.push_str(&build_font_class_rules(font_css_properties).await?);
Ok(StringVc::cell(stylesheet))
}

#[turbo_tasks::function]
async fn build_font_class_rules(properties: FontCssPropertiesVc) -> Result<StringVc> {
let properties = &*properties.await?;
let font_family = &*properties.font_family.await?;

let mut result = formatdoc!(
r#"
.className {{
font-family: {};
{}{}
}}
"#,
font_family,
properties
.weight
.await?
.as_ref()
.map(|w| format!("font-weight: {};\n", w))
.unwrap_or_else(|| "".to_owned()),
properties
.style
.await?
.as_ref()
.map(|s| format!("font-style: {};\n", s))
.unwrap_or_else(|| "".to_owned()),
);

if let Some(variable) = &*properties.variable.await? {
result.push_str(&formatdoc!(
r#"
.variable {{
{}: {};
}}
"#,
variable,
font_family,
))
}

Ok(StringVc::cell(result))
}
@@ -0,0 +1,54 @@
use anyhow::Result;
use turbo_tasks::primitives::{StringVc, StringsVc, U32Vc};

use super::{options::NextFontLocalOptionsVc, request::AdjustFontFallback};
use crate::next_font::{
font_fallback::{AutomaticFontFallback, FontFallback, FontFallbacksVc},
util::{get_scoped_font_family, FontFamilyType},
};

#[turbo_tasks::function]
pub(super) async fn get_font_fallbacks(
options_vc: NextFontLocalOptionsVc,
request_hash: U32Vc,
) -> Result<FontFallbacksVc> {
let options = &*options_vc.await?;
let mut font_fallbacks = vec![];
let scoped_font_family = get_scoped_font_family(
FontFamilyType::Fallback.cell(),
options_vc.font_family(),
request_hash,
);

match options.adjust_font_fallback {
AdjustFontFallback::Arial => font_fallbacks.push(
FontFallback::Automatic(
AutomaticFontFallback {
scoped_font_family,
local_font_family: StringVc::cell("Arial".to_owned()),
adjustment: None,
}
.cell(),
)
.into(),
),
AdjustFontFallback::TimesNewRoman => font_fallbacks.push(
FontFallback::Automatic(
AutomaticFontFallback {
scoped_font_family,
local_font_family: StringVc::cell("Times New Roman".to_owned()),
adjustment: None,
}
.cell(),
)
.into(),
),
AdjustFontFallback::None => (),
};

if let Some(fallback) = &options.fallback {
font_fallbacks.push(FontFallback::Manual(StringsVc::cell(fallback.clone())).into());
}

Ok(FontFallbacksVc::cell(font_fallbacks))
}

0 comments on commit 4716990

Please sign in to comment.