Unverified Commit 67aceea7 authored by Will Binns-Smith's avatar Will Binns-Smith Committed by GitHub

Align on next-transform-font (#47179)

fix NEXT-827 ([link](https://linear.app/vercel/issue/NEXT-827))

This aligns use of the next/font transform across the workspace under a
single crate, now called `next-transform-font`.
parent 8c98a207
...@@ -16,7 +16,7 @@ type FontOptions = { ...@@ -16,7 +16,7 @@ type FontOptions = {
subsets: string[] subsets: string[]
} }
/** /**
* Validate the data recieved from next-swc next_font_loaders on next/font/google calls * Validate the data recieved from next-swc next-transform-font on next/font/google calls
*/ */
export function validateGoogleFontFunctionCall( export function validateGoogleFontFunctionCall(
functionName: string, functionName: string,
......
...@@ -29,7 +29,7 @@ type FontOptions = { ...@@ -29,7 +29,7 @@ type FontOptions = {
} }
/** /**
* Validate the data recieved from next-swc next_font_loaders on next/font/local calls * Validate the data recieved from next-swc next-transform-font on next/font/local calls
*/ */
export function validateLocalFontFunctionCall( export function validateLocalFontFunctionCall(
functionName: string, functionName: string,
......
...@@ -3130,8 +3130,8 @@ dependencies = [ ...@@ -3130,8 +3130,8 @@ dependencies = [
"indexmap", "indexmap",
"indoc", "indoc",
"mime", "mime",
"next-font",
"next-transform-dynamic", "next-transform-dynamic",
"next-transform-font",
"next-transform-strip-page-exports", "next-transform-strip-page-exports",
"once_cell", "once_cell",
"qstring", "qstring",
...@@ -3232,16 +3232,6 @@ dependencies = [ ...@@ -3232,16 +3232,6 @@ dependencies = [
"webbrowser", "webbrowser",
] ]
[[package]]
name = "next-font"
version = "0.1.0"
dependencies = [
"rustc-hash",
"serde",
"serde_json",
"swc_core",
]
[[package]] [[package]]
name = "next-swc" name = "next-swc"
version = "0.0.0" version = "0.0.0"
...@@ -3252,6 +3242,7 @@ dependencies = [ ...@@ -3252,6 +3242,7 @@ dependencies = [
"fxhash", "fxhash",
"hex", "hex",
"next-binding", "next-binding",
"next-transform-font",
"once_cell", "once_cell",
"pathdiff", "pathdiff",
"regex", "regex",
...@@ -3297,6 +3288,16 @@ dependencies = [ ...@@ -3297,6 +3288,16 @@ dependencies = [
"testing", "testing",
] ]
[[package]]
name = "next-transform-font"
version = "0.1.0"
dependencies = [
"rustc-hash",
"serde",
"serde_json",
"swc_core",
]
[[package]] [[package]]
name = "next-transform-strip-page-exports" name = "next-transform-strip-page-exports"
version = "0.1.0" version = "0.1.0"
......
...@@ -8,7 +8,7 @@ members = [ ...@@ -8,7 +8,7 @@ members = [
"crates/next-core", "crates/next-core",
"crates/next-dev", "crates/next-dev",
"crates/next-dev-tests", "crates/next-dev-tests",
"crates/next-font", "crates/next-transform-font",
"crates/next-transform-dynamic", "crates/next-transform-dynamic",
"crates/next-transform-strip-page-exports", "crates/next-transform-strip-page-exports",
] ]
...@@ -29,7 +29,7 @@ next-binding = { path = "crates/next-binding" } ...@@ -29,7 +29,7 @@ next-binding = { path = "crates/next-binding" }
next-core = { path = "crates/next-core", default-features = false } next-core = { path = "crates/next-core", default-features = false }
next-dev = { path = "crates/next-dev" } next-dev = { path = "crates/next-dev" }
next-dev-tests = { path = "crates/next-dev-tests" } next-dev-tests = { path = "crates/next-dev-tests" }
next-font = { path = "crates/next-font" } next-transform-font = { path = "crates/next-transform-font" }
next-transform-dynamic = { path = "crates/next-transform-dynamic" } next-transform-dynamic = { path = "crates/next-transform-dynamic" }
next-transform-strip-page-exports = { path = "crates/next-transform-strip-page-exports" } next-transform-strip-page-exports = { path = "crates/next-transform-strip-page-exports" }
......
...@@ -14,6 +14,7 @@ either = "1" ...@@ -14,6 +14,7 @@ either = "1"
fxhash = "0.2.1" fxhash = "0.2.1"
hex = "0.4.3" hex = "0.4.3"
once_cell = "1.13.0" once_cell = "1.13.0"
next-transform-font = {"workspace" = true}
pathdiff = "0.2.0" pathdiff = "0.2.0"
regex = "1.5" regex = "1.5"
serde = "1" serde = "1"
......
...@@ -34,6 +34,7 @@ use auto_cjs::contains_cjs; ...@@ -34,6 +34,7 @@ use auto_cjs::contains_cjs;
use either::Either; use either::Either;
use fxhash::FxHashSet; use fxhash::FxHashSet;
use next_transform_font::next_font_loaders;
use serde::Deserialize; use serde::Deserialize;
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
...@@ -51,7 +52,6 @@ pub mod amp_attributes; ...@@ -51,7 +52,6 @@ pub mod amp_attributes;
mod auto_cjs; mod auto_cjs;
pub mod disallow_re_export_all_in_page; pub mod disallow_re_export_all_in_page;
pub mod next_dynamic; pub mod next_dynamic;
pub mod next_font_loaders;
pub mod next_ssg; pub mod next_ssg;
pub mod page_config; pub mod page_config;
pub mod react_remove_properties; pub mod react_remove_properties;
...@@ -125,7 +125,7 @@ pub struct TransformOptions { ...@@ -125,7 +125,7 @@ pub struct TransformOptions {
pub modularize_imports: Option<next_binding::swc::custom_transform::modularize_imports::Config>, pub modularize_imports: Option<next_binding::swc::custom_transform::modularize_imports::Config>,
#[serde(default)] #[serde(default)]
pub font_loaders: Option<next_font_loaders::Config>, pub font_loaders: Option<next_transform_font::Config>,
#[serde(default)] #[serde(default)]
pub server_actions: Option<server_actions::Config>, pub server_actions: Option<server_actions::Config>,
...@@ -257,7 +257,7 @@ where ...@@ -257,7 +257,7 @@ where
None => Either::Right(noop()), None => Either::Right(noop()),
}, },
match &opts.font_loaders { match &opts.font_loaders {
Some(config) => Either::Left(next_font_loaders::next_font_loaders(config.clone())), Some(config) => Either::Left(next_font_loaders(config.clone())),
None => Either::Right(noop()), None => Either::Right(noop()),
}, },
match &opts.server_actions { match &opts.server_actions {
......
...@@ -14,11 +14,11 @@ use next_binding::swc::{ ...@@ -14,11 +14,11 @@ use next_binding::swc::{
use next_swc::{ use next_swc::{
disallow_re_export_all_in_page::disallow_re_export_all_in_page, disallow_re_export_all_in_page::disallow_re_export_all_in_page,
next_dynamic::next_dynamic, next_dynamic::next_dynamic,
next_font_loaders::{next_font_loaders, Config as FontLoaderConfig},
next_ssg::next_ssg, next_ssg::next_ssg,
react_server_components::server_components, react_server_components::server_components,
server_actions::{self, server_actions}, server_actions::{self, server_actions},
}; };
use next_transform_font::{next_font_loaders, Config as FontLoaderConfig};
use std::path::PathBuf; use std::path::PathBuf;
fn syntax() -> Syntax { fn syntax() -> Syntax {
......
...@@ -11,7 +11,6 @@ use next_binding::swc::{ ...@@ -11,7 +11,6 @@ use next_binding::swc::{
use next_swc::{ use next_swc::{
amp_attributes::amp_attributes, amp_attributes::amp_attributes,
next_dynamic::next_dynamic, next_dynamic::next_dynamic,
next_font_loaders::{next_font_loaders, Config as FontLoaderConfig},
next_ssg::next_ssg, next_ssg::next_ssg,
page_config::page_config_test, page_config::page_config_test,
react_remove_properties::remove_properties, react_remove_properties::remove_properties,
...@@ -21,6 +20,7 @@ use next_swc::{ ...@@ -21,6 +20,7 @@ use next_swc::{
server_actions::{self, server_actions}, server_actions::{self, server_actions},
shake_exports::{shake_exports, Config as ShakeExportsConfig}, shake_exports::{shake_exports, Config as ShakeExportsConfig},
}; };
use next_transform_font::{next_font_loaders, Config as FontLoaderConfig};
use std::path::PathBuf; use std::path::PathBuf;
fn syntax() -> Syntax { fn syntax() -> Syntax {
......
...@@ -31,7 +31,7 @@ turbopack-ecmascript = { workspace = true } ...@@ -31,7 +31,7 @@ turbopack-ecmascript = { workspace = true }
turbopack-env = { workspace = true } turbopack-env = { workspace = true }
turbopack-node = { workspace = true } turbopack-node = { workspace = true }
next-transform-strip-page-exports = { workspace = true } next-transform-strip-page-exports = { workspace = true }
next-font = { workspace = true } next-transform-font = { workspace = true }
next-transform-dynamic = { workspace = true } next-transform-dynamic = { workspace = true }
swc_core = { workspace = true, features = ["ecma_ast", "common"] } swc_core = { workspace = true, features = ["ecma_ast", "common"] }
......
...@@ -147,7 +147,7 @@ struct NextJsFont { ...@@ -147,7 +147,7 @@ struct NextJsFont {
impl CustomTransformer for NextJsFont { impl CustomTransformer for NextJsFont {
fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Option<Program> { fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Option<Program> {
let mut next_font = next_font::next_font_loaders(next_font::Config { let mut next_font = next_transform_font::next_font_loaders(next_transform_font::Config {
font_loaders: self.font_loaders.clone(), font_loaders: self.font_loaders.clone(),
relative_file_path_from_root: ctx.file_name_str.into(), relative_file_path_from_root: ctx.file_name_str.into(),
}); });
......
[package]
name = "next-transform-font"
version = "0.1.0"
description = "TBD"
license = "MPL-2.0"
edition = "2021"
[lib]
bench = false
[dependencies]
rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
swc_core = { workspace = true }
use next_binding::swc::core::common::errors::HANDLER; use swc_core::{
use next_binding::swc::core::ecma::ast::*; common::errors::HANDLER,
use next_binding::swc::core::ecma::visit::noop_visit_type; ecma::{
use next_binding::swc::core::ecma::visit::Visit; ast::*,
visit::{noop_visit_type, Visit},
},
};
pub struct FindFunctionsOutsideModuleScope<'a> { pub struct FindFunctionsOutsideModuleScope<'a> {
pub state: &'a super::State, pub state: &'a super::State,
} }
......
use next_binding::swc::core::common::errors::HANDLER; use swc_core::{
use next_binding::swc::core::ecma::ast::*; common::errors::HANDLER,
use next_binding::swc::core::ecma::atoms::JsWord; ecma::{
use next_binding::swc::core::ecma::visit::noop_visit_type; ast::*,
use next_binding::swc::core::ecma::visit::Visit; atoms::JsWord,
visit::{noop_visit_type, Visit},
},
};
pub struct FontFunctionsCollector<'a> { pub struct FontFunctionsCollector<'a> {
pub font_loaders: &'a [JsWord], pub font_loaders: &'a [JsWord],
......
use next_binding::swc::core::common::errors::HANDLER;
use next_binding::swc::core::common::{Spanned, DUMMY_SP};
use next_binding::swc::core::ecma::ast::*;
use next_binding::swc::core::ecma::atoms::JsWord;
use next_binding::swc::core::ecma::visit::{noop_visit_type, Visit};
use serde_json::Value; use serde_json::Value;
use swc_core::{
common::{errors::HANDLER, Spanned, DUMMY_SP},
ecma::{
ast::*,
atoms::JsWord,
visit::{noop_visit_type, Visit},
},
};
pub struct FontImportsGenerator<'a> { pub struct FontImportsGenerator<'a> {
pub state: &'a mut super::State, pub state: &'a mut super::State,
......
use fxhash::FxHashSet; use rustc_hash::FxHashSet;
use next_binding::swc::core::{ use serde::Deserialize;
use swc_core::{
common::{collections::AHashMap, BytePos, Spanned}, common::{collections::AHashMap, BytePos, Spanned},
ecma::{ ecma::{
ast::Id, ast::{Id, ModuleItem},
atoms::JsWord,
visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitWith}, visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitWith},
}, },
ecma::{ast::ModuleItem, atoms::JsWord},
}; };
use serde::Deserialize;
mod find_functions_outside_module_scope; mod find_functions_outside_module_scope;
mod font_functions_collector; mod font_functions_collector;
......
...@@ -13,7 +13,7 @@ export default async function nextFontLoader(this: any) { ...@@ -13,7 +13,7 @@ export default async function nextFontLoader(this: any) {
const callback = this.async() const callback = this.async()
/** /**
* The next-swc plugin next_font_loaders turns font function calls into CSS imports. * The next-swc plugin next-transform-font turns font function calls into CSS imports.
* At the end of the import, it adds the call arguments and some additional data as a resourceQuery. * At the end of the import, it adds the call arguments and some additional data as a resourceQuery.
* e.g: * e.g:
* const inter = Inter({ subset: ['latin'] }) * const inter = Inter({ subset: ['latin'] })
......
...@@ -15,7 +15,7 @@ export function getNextFontError( ...@@ -15,7 +15,7 @@ export function getNextFontError(
} }
// Parse the query and get the path of the file where the font function was called. // Parse the query and get the path of the file where the font function was called.
// provided by next-swc next_font_loaders // provided by next-swc next-transform-font
const file = JSON.parse(resourceResolveData.query.slice(1)).path const file = JSON.parse(resourceResolveData.query.slice(1)).path
if (err.name === 'NextFontError') { if (err.name === 'NextFontError') {
......
...@@ -87,7 +87,7 @@ function getFormattedFileName( ...@@ -87,7 +87,7 @@ function getFormattedFileName(
) )
) { ) {
// Parse the query and get the path of the file where the font function was called. // Parse the query and get the path of the file where the font function was called.
// provided by next-swc next_font_loaders // provided by next-swc next-transform-font
return JSON.parse(module.resourceResolveData.query.slice(1)).path return JSON.parse(module.resourceResolveData.query.slice(1)).path
} else { } else {
let formattedFileName: string = chalk.cyan(fileName) let formattedFileName: string = chalk.cyan(fileName)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment