Skip to content

Commit

Permalink
Dedupe functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Jan 11, 2025
1 parent ff681cf commit 40c717c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 53 deletions.
24 changes: 2 additions & 22 deletions crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::Result;
use turbo_rcstr::RcStr;
use turbo_tasks::{FxIndexMap, ResolvedVc, Value, Vc};
use turbo_tasks_env::EnvMap;
use turbo_tasks_fs::{FileSystem, FileSystemPath};
use turbo_tasks_fs::FileSystemPath;
use turbopack::{
module_options::{
module_options_context::ModuleOptionsContext, CssOptionsContext, EcmascriptOptionsContext,
Expand All @@ -19,7 +19,6 @@ use turbopack_core::{
CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, DefineableNameSegment,
FreeVarReference, FreeVarReferences,
},
condition::ContextCondition,
environment::{BrowserEnvironment, Environment, ExecutionEnvironment},
free_var_references,
resolve::{parse::Request, pattern::Pattern},
Expand All @@ -31,7 +30,6 @@ use turbopack_node::{

use super::transforms::get_next_client_transforms_rules;
use crate::{
embed_js::next_js_fs,
mode::NextMode,
next_build::get_postcss_package_mapping,
next_client::runtime_entry::{RuntimeEntries, RuntimeEntry},
Expand Down Expand Up @@ -60,7 +58,7 @@ use crate::{
get_decorators_transform_options, get_jsx_transform_options,
get_typescript_transform_options,
},
util::foreign_code_context_condition,
util::{foreign_code_context_condition, internal_assets_conditions},
};

fn defines(define_env: &FxIndexMap<RcStr, RcStr>) -> CompileTimeDefines {
Expand Down Expand Up @@ -212,24 +210,6 @@ pub async fn get_client_resolve_options_context(
.cell())
}

async fn internal_assets_conditions() -> Result<ContextCondition> {
Ok(ContextCondition::any(vec![
ContextCondition::InPath(next_js_fs().root().to_resolved().await?),
ContextCondition::InPath(
turbopack_ecmascript_runtime::embed_fs()
.root()
.to_resolved()
.await?,
),
ContextCondition::InPath(
turbopack_node::embed_js::embed_fs()
.root()
.to_resolved()
.await?,
),
]))
}

#[turbo_tasks::function]
pub async fn get_client_module_options_context(
project_path: ResolvedVc<FileSystemPath>,
Expand Down
33 changes: 3 additions & 30 deletions crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{bail, Result};
use turbo_rcstr::RcStr;
use turbo_tasks::{FxIndexMap, ResolvedVc, Value, Vc};
use turbo_tasks_env::{EnvMap, ProcessEnv};
use turbo_tasks_fs::{FileSystem, FileSystemPath};
use turbo_tasks_fs::FileSystemPath;
use turbopack::{
module_options::{
CssOptionsContext, EcmascriptOptionsContext, JsxTransformOptions, ModuleOptionsContext,
Expand All @@ -19,7 +19,6 @@ use turbopack_core::{
CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, DefineableNameSegment,
FreeVarReferences,
},
condition::ContextCondition,
environment::{
Environment, ExecutionEnvironment, NodeJsEnvironment, NodeJsVersion, RuntimeVersions,
},
Expand All @@ -41,7 +40,6 @@ use super::{
transforms::{get_next_server_internal_transforms_rules, get_next_server_transforms_rules},
};
use crate::{
embed_js::next_js_fs,
mode::NextMode,
next_build::get_postcss_package_mapping,
next_client::RuntimeEntries,
Expand Down Expand Up @@ -71,8 +69,8 @@ use crate::{
get_typescript_transform_options,
},
util::{
foreign_code_context_condition, get_transpiled_packages, load_next_js_templateon,
NextRuntime,
foreign_code_context_condition, get_transpiled_packages, internal_assets_conditions,
load_next_js_templateon, NextRuntime,
},
};

Expand Down Expand Up @@ -396,31 +394,6 @@ pub async fn get_server_compile_time_info(
.await
}

/// Determins if the module is an internal asset (i.e overlay, fallback) coming
/// from the embedded FS, don't apply user defined transforms.
///
/// [TODO] turbopack specific embed fs should be handled by internals of
/// turbopack itself and user config should not try to leak this. However,
/// currently we apply few transform options subject to next.js's configuration
/// even if it's embedded assets.
async fn internal_assets_conditions() -> Result<ContextCondition> {
Ok(ContextCondition::any(vec![
ContextCondition::InPath(next_js_fs().root().to_resolved().await?),
ContextCondition::InPath(
turbopack_ecmascript_runtime::embed_fs()
.root()
.to_resolved()
.await?,
),
ContextCondition::InPath(
turbopack_node::embed_js::embed_fs()
.root()
.to_resolved()
.await?,
),
]))
}

#[turbo_tasks::function]
pub async fn get_server_module_options_context(
project_path: ResolvedVc<FileSystemPath>,
Expand Down
28 changes: 27 additions & 1 deletion crates/next-core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use turbo_tasks::{
};
use turbo_tasks_fs::{
self, json::parse_json_rope_with_source_context, rope::Rope, util::join_path, File,
FileContent, FileSystemPath,
FileContent, FileSystem, FileSystemPath,
};
use turbopack_core::{
asset::AssetContent,
Expand All @@ -32,6 +32,7 @@ use turbopack_ecmascript::{
};

use crate::{
embed_js::next_js_fs,
next_config::{NextConfig, RouteHas},
next_import_map::get_next_package,
next_manifests::MiddlewareMatcher,
Expand Down Expand Up @@ -140,6 +141,31 @@ pub async fn foreign_code_context_condition(
Ok(result)
}

/// Determines if the module is an internal asset (i.e overlay, fallback) coming
/// from the embedded FS, don't apply user defined transforms.
///
/// [TODO] turbopack specific embed fs should be handled by internals of

Check warning on line 147 in crates/next-core/src/util.rs

View workflow job for this annotation

GitHub Actions / rustdoc check / build

unresolved link to `TODO`
/// turbopack itself and user config should not try to leak this. However,
/// currently we apply few transform options subject to next.js's configuration
/// even if it's embedded assets.
pub async fn internal_assets_conditions() -> Result<ContextCondition> {
Ok(ContextCondition::any(vec![
ContextCondition::InPath(next_js_fs().root().to_resolved().await?),
ContextCondition::InPath(
turbopack_ecmascript_runtime::embed_fs()
.root()
.to_resolved()
.await?,
),
ContextCondition::InPath(
turbopack_node::embed_js::embed_fs()
.root()
.to_resolved()
.await?,
),
]))
}

#[derive(
Default,
PartialEq,
Expand Down

0 comments on commit 40c717c

Please sign in to comment.