Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions crates/napi/src/next_api/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ pub struct NapiProjectOptions {
/// The contents of next.config.js, serialized to JSON.
pub next_config: RcStr,

/// The contents of ts/config read by load-jsconfig, serialized to JSON.
pub js_config: RcStr,

/// A map of environment variables to use when compiling code.
pub env: Vec<NapiEnvVar>,

Expand Down Expand Up @@ -204,9 +201,6 @@ pub struct NapiPartialProjectOptions {
/// The contents of next.config.js, serialized to JSON.
pub next_config: Option<RcStr>,

/// The contents of ts/config read by load-jsconfig, serialized to JSON.
pub js_config: Option<RcStr>,

/// A map of environment variables to use when compiling code.
pub env: Option<Vec<NapiEnvVar>>,

Expand Down Expand Up @@ -276,7 +270,6 @@ impl From<NapiProjectOptions> for ProjectOptions {
project_path: val.project_path,
watch: val.watch.into(),
next_config: val.next_config,
js_config: val.js_config,
env: val
.env
.into_iter()
Expand All @@ -301,7 +294,6 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions {
project_path: val.project_path,
watch: val.watch.map(From::from),
next_config: val.next_config,
js_config: val.js_config,
env: val
.env
.map(|env| env.into_iter().map(|var| (var.name, var.value)).collect()),
Expand Down
1 change: 0 additions & 1 deletion crates/next-api/benches/hmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ impl HmrBenchmark {
root_path: RcStr::from(root_path),
project_path: RcStr::from(project_path.clone()),
next_config: load_next_config(),
js_config: rcstr!("{}"),
env: vec![],
define_env: DefineEnv {
client: vec![],
Expand Down
38 changes: 1 addition & 37 deletions crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use next_core::{
next_client::{
ClientChunkingContextOptions, get_client_chunking_context, get_client_compile_time_info,
},
next_config::{JsConfig, ModuleIds as ModuleIdStrategyConfig, NextConfig},
next_config::{ModuleIds as ModuleIdStrategyConfig, NextConfig},
next_edge::context::EdgeChunkingContextOptions,
next_server::{
ServerChunkingContextOptions, ServerContextType, get_server_chunking_context,
Expand Down Expand Up @@ -160,9 +160,6 @@ pub struct ProjectOptions {
/// The contents of next.config.js, serialized to JSON.
pub next_config: RcStr,

/// The contents of ts/config read by load-jsconfig, serialized to JSON.
pub js_config: RcStr,

/// A map of environment variables to use when compiling code.
pub env: Vec<(RcStr, RcStr)>,

Expand Down Expand Up @@ -212,9 +209,6 @@ pub struct PartialProjectOptions {
/// The contents of next.config.js, serialized to JSON.
pub next_config: Option<RcStr>,

/// The contents of ts/config read by load-jsconfig, serialized to JSON.
pub js_config: Option<RcStr>,

/// A map of environment variables to use when compiling code.
pub env: Option<Vec<(RcStr, RcStr)>>,

Expand Down Expand Up @@ -341,7 +335,6 @@ impl ProjectContainer {
root_path,
project_path,
next_config,
js_config,
env,
define_env,
watch,
Expand All @@ -368,9 +361,6 @@ impl ProjectContainer {
if let Some(next_config) = next_config {
new_options.next_config = next_config;
}
if let Some(js_config) = js_config {
new_options.js_config = js_config;
}
if let Some(env) = env {
new_options.env = env;
}
Expand Down Expand Up @@ -443,7 +433,6 @@ impl ProjectContainer {
let env_map: Vc<EnvMap>;
let next_config;
let define_env;
let js_config;
let root_path;
let project_path;
let watch;
Expand All @@ -467,7 +456,6 @@ impl ProjectContainer {
}
.cell();
next_config = NextConfig::from_string(Vc::cell(options.next_config.clone()));
js_config = JsConfig::from_string(Vc::cell(options.js_config.clone()));
root_path = options.root_path.clone();
project_path = options.project_path.clone();
watch = options.watch;
Expand All @@ -491,7 +479,6 @@ impl ProjectContainer {
project_path,
watch,
next_config: next_config.to_resolved().await?,
js_config: js_config.to_resolved().await?,
dist_dir,
env: ResolvedVc::upcast(env_map.to_resolved().await?),
define_env: define_env.to_resolved().await?,
Expand Down Expand Up @@ -562,9 +549,6 @@ pub struct Project {
/// Next config.
next_config: ResolvedVc<NextConfig>,

/// Js/Tsconfig read by load-jsconfig
js_config: ResolvedVc<JsConfig>,

/// A map of environment variables to use when compiling code.
env: ResolvedVc<Box<dyn ProcessEnv>>,

Expand Down Expand Up @@ -789,11 +773,6 @@ impl Project {
Ok(Vc::cell(*self.mode.await? == NextMode::Development))
}

#[turbo_tasks::function]
pub(super) fn js_config(&self) -> Vc<JsConfig> {
*self.js_config
}

#[turbo_tasks::function]
pub(super) fn encryption_key(&self) -> Vc<RcStr> {
Vc::cell(self.encryption_key.clone())
Expand Down Expand Up @@ -1131,21 +1110,6 @@ impl Project {
// it is always using SWC so we don't check swc here.
emit_event(env!("VERGEN_CARGO_TARGET_TRIPLE"), true);

// Go over jsconfig and report enabled features.
let compiler_options = self.js_config().compiler_options().await?;
let compiler_options = compiler_options.as_object();
let experimental_decorators_enabled = compiler_options
.as_ref()
.and_then(|compiler_options| compiler_options.get("experimentalDecorators"))
.is_some();
let jsx_import_source_enabled = compiler_options
.as_ref()
.and_then(|compiler_options| compiler_options.get("jsxImportSource"))
.is_some();

emit_event("swcExperimentalDecorators", experimental_decorators_enabled);
emit_event("swcImportSource", jsx_import_source_enabled);

// Go over config and report enabled features.
// [TODO]: useSwcLoader is not being reported as it is not directly corresponds (it checks babel config existence)
// need to confirm what we'll do with turbopack.
Expand Down
1 change: 0 additions & 1 deletion crates/next-build-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ fn main() {
dev: true,
encryption_key: rcstr!("deadbeef"),
env: vec![],
js_config: include_str!("../jsConfig.json").into(),
next_config: include_str!("../nextConfig.json").into(),
preview_props: next_api::project::DraftModeOptions {
preview_mode_encryption_key: rcstr!("deadbeef"),
Expand Down
27 changes: 19 additions & 8 deletions crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,19 @@ pub async fn get_client_resolve_options_context(
..Default::default()
};

let tsconfig_path = next_config
.typescript_tsconfig_path()
.await?
.as_ref()
.map(|p| project_path.join(p))
.transpose()?;

Ok(ResolveOptionsContext {
enable_typescript: true,
enable_react: true,
enable_mjs_extension: true,
custom_extensions: next_config.resolve_extension().owned().await?,
tsconfig_path: next_config
.typescript_tsconfig_path()
.await?
.as_ref()
.map(|p| project_path.join(p))
.transpose()?,
tsconfig_path,
rules: vec![(
foreign_code_context_condition(next_config, project_path).await?,
resolve_options_context.clone().resolved_cell(),
Expand Down Expand Up @@ -223,17 +225,26 @@ pub async fn get_client_module_options_context(
*execution_context,
);

let tsconfig = get_typescript_transform_options(project_path.clone())
let tsconfig_path = next_config
.typescript_tsconfig_path()
.await?
.as_ref()
.map(|p| project_path.join(p))
.transpose()?;

let tsconfig = get_typescript_transform_options(project_path.clone(), tsconfig_path.clone())
.to_resolved()
.await?;
let decorators_options = get_decorators_transform_options(project_path.clone());
let decorators_options =
get_decorators_transform_options(project_path.clone(), tsconfig_path.clone());
let enable_mdx_rs = *next_config.mdx_rs().await?;
let jsx_runtime_options = get_jsx_transform_options(
project_path.clone(),
mode,
Some(resolve_options_context),
false,
next_config,
tsconfig_path,
)
.to_resolved()
.await?;
Expand Down
54 changes: 38 additions & 16 deletions crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,19 @@ pub async fn get_server_resolve_options_context(
..Default::default()
};

let tsconfig_path = next_config
.typescript_tsconfig_path()
.await?
.as_ref()
.map(|p| project_path.join(p))
.transpose()?;

Ok(ResolveOptionsContext {
enable_typescript: true,
enable_react: true,
enable_mjs_extension: true,
custom_extensions: next_config.resolve_extension().owned().await?,
tsconfig_path: next_config
.typescript_tsconfig_path()
.await?
.as_ref()
.map(|p| project_path.join(p))
.transpose()?,
tsconfig_path,
rules: vec![(
foreign_code_context_condition,
resolve_options_context.clone().resolved_cell(),
Expand Down Expand Up @@ -520,11 +522,19 @@ pub async fn get_server_module_options_context(
.await?;
let css_versions = environment.css_runtime_versions();

let tsconfig_path = next_config
.typescript_tsconfig_path()
.await?
.as_ref()
.map(|p| project_path.join(p))
.transpose()?;

// ModuleOptionsContext related options
let tsconfig = get_typescript_transform_options(project_path.clone())
let tsconfig = get_typescript_transform_options(project_path.clone(), tsconfig_path.clone())
.to_resolved()
.await?;
let decorators_options = get_decorators_transform_options(project_path.clone());
let decorators_options =
get_decorators_transform_options(project_path.clone(), tsconfig_path.clone());
let enable_mdx_rs = *next_config.mdx_rs().await?;

// Get the jsx transform options for the `client` side.
Expand All @@ -534,14 +544,26 @@ pub async fn get_server_module_options_context(
//
// This enables correct emotion transform and other hydration between server and
// client bundles. ref: https://github.com/vercel/next.js/blob/4bbf9b6c70d2aa4237defe2bebfa790cdb7e334e/packages/next/src/build/webpack-config.ts#L1421-L1426
let jsx_runtime_options =
get_jsx_transform_options(project_path.clone(), mode, None, false, next_config)
.to_resolved()
.await?;
let rsc_jsx_runtime_options =
get_jsx_transform_options(project_path.clone(), mode, None, true, next_config)
.to_resolved()
.await?;
let jsx_runtime_options = get_jsx_transform_options(
project_path.clone(),
mode,
None,
false,
next_config,
tsconfig_path.clone(),
)
.to_resolved()
.await?;
let rsc_jsx_runtime_options = get_jsx_transform_options(
project_path.clone(),
mode,
None,
true,
next_config,
tsconfig_path,
)
.to_resolved()
.await?;

// A set of custom ecma transform rules being applied to server context.
let source_transform_rules: Vec<ModuleRule> = vec![
Expand Down
42 changes: 29 additions & 13 deletions crates/next-core/src/transform_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,41 @@ use crate::{mode::NextMode, next_config::NextConfig};

async fn get_typescript_options(
project_path: FileSystemPath,
tsconfig_path: Option<FileSystemPath>,
) -> Result<Option<Vec<(Vc<FileJsonContent>, ResolvedVc<Box<dyn Source>>)>>> {
let tsconfig = find_context_file(project_path, tsconfig());
Ok(match tsconfig.await.ok().as_deref() {
Some(FindContextFileResult::Found(path, _)) => read_tsconfigs(
path.read(),
ResolvedVc::upcast(FileSource::new(path.clone()).to_resolved().await?),
node_cjs_resolve_options(path.root().owned().await?),
if let Some(tsconfig_path) = tsconfig_path {
let tsconfigs = read_tsconfigs(
tsconfig_path.read(),
ResolvedVc::upcast(FileSource::new(tsconfig_path.clone()).to_resolved().await?),
node_cjs_resolve_options(tsconfig_path.root().owned().await?),
)
.await
.ok(),
Some(FindContextFileResult::NotFound(_)) | None => None,
})
.ok();

Ok(tsconfigs)
} else {
let tsconfig = find_context_file(project_path, tsconfig());
Ok(match tsconfig.await.ok().as_deref() {
Some(FindContextFileResult::Found(path, _)) => read_tsconfigs(
path.read(),
ResolvedVc::upcast(FileSource::new(path.clone()).to_resolved().await?),
node_cjs_resolve_options(path.root().owned().await?),
)
.await
.ok(),
Some(FindContextFileResult::NotFound(_)) | None => None,
})
}
}

/// Build the transform options for specifically for the typescript's runtime
/// outputs
#[turbo_tasks::function]
pub async fn get_typescript_transform_options(
project_path: FileSystemPath,
tsconfig_path: Option<FileSystemPath>,
) -> Result<Vc<TypescriptTransformOptions>> {
let tsconfig = get_typescript_options(project_path).await?;
let tsconfig = get_typescript_options(project_path, tsconfig_path).await?;

let use_define_for_class_fields = if let Some(tsconfig) = tsconfig {
read_from_tsconfigs(&tsconfig, |json, _| {
Expand All @@ -60,12 +74,13 @@ pub async fn get_typescript_transform_options(
}

/// Build the transform options for the decorators.
/// **TODO** Currnently only typescript's legacy decorators are supported
/// **TODO** Currently only typescript's legacy decorators are supported
#[turbo_tasks::function]
pub async fn get_decorators_transform_options(
project_path: FileSystemPath,
tsconfig_path: Option<FileSystemPath>,
) -> Result<Vc<DecoratorsOptions>> {
let tsconfig = get_typescript_options(project_path).await?;
let tsconfig = get_typescript_options(project_path, tsconfig_path).await?;

let experimental_decorators = if let Some(ref tsconfig) = tsconfig {
read_from_tsconfigs(tsconfig, |json, _| {
Expand Down Expand Up @@ -135,8 +150,9 @@ pub async fn get_jsx_transform_options(
resolve_options_context: Option<Vc<ResolveOptionsContext>>,
is_rsc_context: bool,
next_config: Vc<NextConfig>,
tsconfig_path: Option<FileSystemPath>,
) -> Result<Vc<JsxTransformOptions>> {
let tsconfig = get_typescript_options(project_path.clone()).await?;
let tsconfig = get_typescript_options(project_path.clone(), tsconfig_path).await?;

let is_react_development = mode.await?.is_react_development();
let enable_react_refresh = if is_react_development {
Expand Down
Loading
Loading