Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
521cdaef
Unverified
Commit
521cdaef
authored
Jan 13, 2025
by
Benjamin Woodruff
Committed by
GitHub
Jan 13, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(turbopack-core): Use ResolvedVc in ContextCondition (#74711)
parent
5a935b03
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
44 deletions
+46
-44
context.rs
crates/next-core/src/next_client/context.rs
+3
-13
context.rs
crates/next-core/src/next_server/context.rs
+8
-25
util.rs
crates/next-core/src/util.rs
+31
-2
condition.rs
turbopack/crates/turbopack-core/src/condition.rs
+3
-3
resolve_options_context.rs
...k/crates/turbopack-resolve/src/resolve_options_context.rs
+1
-1
No files found.
crates/next-core/src/next_client/context.rs
View file @
521cdaef
...
@@ -4,7 +4,7 @@ use anyhow::Result;
...
@@ -4,7 +4,7 @@ use anyhow::Result;
use
turbo_rcstr
::
RcStr
;
use
turbo_rcstr
::
RcStr
;
use
turbo_tasks
::{
FxIndexMap
,
ResolvedVc
,
Value
,
Vc
};
use
turbo_tasks
::{
FxIndexMap
,
ResolvedVc
,
Value
,
Vc
};
use
turbo_tasks_env
::
EnvMap
;
use
turbo_tasks_env
::
EnvMap
;
use
turbo_tasks_fs
::
{
FileSystem
,
FileSystemPath
}
;
use
turbo_tasks_fs
::
FileSystemPath
;
use
turbopack
::{
use
turbopack
::{
module_options
::{
module_options
::{
module_options_context
::
ModuleOptionsContext
,
CssOptionsContext
,
EcmascriptOptionsContext
,
module_options_context
::
ModuleOptionsContext
,
CssOptionsContext
,
EcmascriptOptionsContext
,
...
@@ -19,7 +19,6 @@ use turbopack_core::{
...
@@ -19,7 +19,6 @@ use turbopack_core::{
CompileTimeDefineValue
,
CompileTimeDefines
,
CompileTimeInfo
,
DefineableNameSegment
,
CompileTimeDefineValue
,
CompileTimeDefines
,
CompileTimeInfo
,
DefineableNameSegment
,
FreeVarReference
,
FreeVarReferences
,
FreeVarReference
,
FreeVarReferences
,
},
},
condition
::
ContextCondition
,
environment
::{
BrowserEnvironment
,
Environment
,
ExecutionEnvironment
},
environment
::{
BrowserEnvironment
,
Environment
,
ExecutionEnvironment
},
free_var_references
,
free_var_references
,
resolve
::{
parse
::
Request
,
pattern
::
Pattern
},
resolve
::{
parse
::
Request
,
pattern
::
Pattern
},
...
@@ -31,7 +30,6 @@ use turbopack_node::{
...
@@ -31,7 +30,6 @@ use turbopack_node::{
use
super
::
transforms
::
get_next_client_transforms_rules
;
use
super
::
transforms
::
get_next_client_transforms_rules
;
use
crate
::{
use
crate
::{
embed_js
::
next_js_fs
,
mode
::
NextMode
,
mode
::
NextMode
,
next_build
::
get_postcss_package_mapping
,
next_build
::
get_postcss_package_mapping
,
next_client
::
runtime_entry
::{
RuntimeEntries
,
RuntimeEntry
},
next_client
::
runtime_entry
::{
RuntimeEntries
,
RuntimeEntry
},
...
@@ -60,7 +58,7 @@ use crate::{
...
@@ -60,7 +58,7 @@ use crate::{
get_decorators_transform_options
,
get_jsx_transform_options
,
get_decorators_transform_options
,
get_jsx_transform_options
,
get_typescript_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
{
fn
defines
(
define_env
:
&
FxIndexMap
<
RcStr
,
RcStr
>
)
->
CompileTimeDefines
{
...
@@ -212,14 +210,6 @@ pub async fn get_client_resolve_options_context(
...
@@ -212,14 +210,6 @@ pub async fn get_client_resolve_options_context(
.cell
())
.cell
())
}
}
fn
internal_assets_conditions
()
->
ContextCondition
{
ContextCondition
::
any
(
vec!
[
ContextCondition
::
InPath
(
next_js_fs
()
.root
()),
ContextCondition
::
InPath
(
turbopack_ecmascript_runtime
::
embed_fs
()
.root
()),
ContextCondition
::
InPath
(
turbopack_node
::
embed_js
::
embed_fs
()
.root
()),
])
}
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
pub
async
fn
get_client_module_options_context
(
pub
async
fn
get_client_module_options_context
(
project_path
:
ResolvedVc
<
FileSystemPath
>
,
project_path
:
ResolvedVc
<
FileSystemPath
>
,
...
@@ -387,7 +377,7 @@ pub async fn get_client_module_options_context(
...
@@ -387,7 +377,7 @@ pub async fn get_client_module_options_context(
foreign_codes_options_context
.resolved_cell
(),
foreign_codes_options_context
.resolved_cell
(),
),
),
(
(
internal_assets_conditions
(),
internal_assets_conditions
()
.await
?
,
internal_context
.resolved_cell
(),
internal_context
.resolved_cell
(),
),
),
],
],
...
...
crates/next-core/src/next_server/context.rs
View file @
521cdaef
...
@@ -4,7 +4,7 @@ use anyhow::{bail, Result};
...
@@ -4,7 +4,7 @@ use anyhow::{bail, Result};
use
turbo_rcstr
::
RcStr
;
use
turbo_rcstr
::
RcStr
;
use
turbo_tasks
::{
FxIndexMap
,
ResolvedVc
,
Value
,
Vc
};
use
turbo_tasks
::{
FxIndexMap
,
ResolvedVc
,
Value
,
Vc
};
use
turbo_tasks_env
::{
EnvMap
,
ProcessEnv
};
use
turbo_tasks_env
::{
EnvMap
,
ProcessEnv
};
use
turbo_tasks_fs
::
{
FileSystem
,
FileSystemPath
}
;
use
turbo_tasks_fs
::
FileSystemPath
;
use
turbopack
::{
use
turbopack
::{
module_options
::{
module_options
::{
CssOptionsContext
,
EcmascriptOptionsContext
,
JsxTransformOptions
,
ModuleOptionsContext
,
CssOptionsContext
,
EcmascriptOptionsContext
,
JsxTransformOptions
,
ModuleOptionsContext
,
...
@@ -19,7 +19,6 @@ use turbopack_core::{
...
@@ -19,7 +19,6 @@ use turbopack_core::{
CompileTimeDefineValue
,
CompileTimeDefines
,
CompileTimeInfo
,
DefineableNameSegment
,
CompileTimeDefineValue
,
CompileTimeDefines
,
CompileTimeInfo
,
DefineableNameSegment
,
FreeVarReferences
,
FreeVarReferences
,
},
},
condition
::
ContextCondition
,
environment
::{
environment
::{
Environment
,
ExecutionEnvironment
,
NodeJsEnvironment
,
NodeJsVersion
,
RuntimeVersions
,
Environment
,
ExecutionEnvironment
,
NodeJsEnvironment
,
NodeJsVersion
,
RuntimeVersions
,
},
},
...
@@ -41,7 +40,6 @@ use super::{
...
@@ -41,7 +40,6 @@ use super::{
transforms
::{
get_next_server_internal_transforms_rules
,
get_next_server_transforms_rules
},
transforms
::{
get_next_server_internal_transforms_rules
,
get_next_server_transforms_rules
},
};
};
use
crate
::{
use
crate
::{
embed_js
::
next_js_fs
,
mode
::
NextMode
,
mode
::
NextMode
,
next_build
::
get_postcss_package_mapping
,
next_build
::
get_postcss_package_mapping
,
next_client
::
RuntimeEntries
,
next_client
::
RuntimeEntries
,
...
@@ -71,8 +69,8 @@ use crate::{
...
@@ -71,8 +69,8 @@ use crate::{
get_typescript_transform_options
,
get_typescript_transform_options
,
},
},
util
::{
util
::{
foreign_code_context_condition
,
get_transpiled_packages
,
load_next_js_templateon
,
foreign_code_context_condition
,
get_transpiled_packages
,
internal_assets_conditions
,
NextRuntime
,
load_next_js_templateon
,
NextRuntime
,
},
},
};
};
...
@@ -396,21 +394,6 @@ pub async fn get_server_compile_time_info(
...
@@ -396,21 +394,6 @@ pub async fn get_server_compile_time_info(
.await
.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.
fn
internal_assets_conditions
()
->
ContextCondition
{
ContextCondition
::
any
(
vec!
[
ContextCondition
::
InPath
(
next_js_fs
()
.root
()),
ContextCondition
::
InPath
(
turbopack_ecmascript_runtime
::
embed_fs
()
.root
()),
ContextCondition
::
InPath
(
turbopack_node
::
embed_js
::
embed_fs
()
.root
()),
])
}
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
pub
async
fn
get_server_module_options_context
(
pub
async
fn
get_server_module_options_context
(
project_path
:
ResolvedVc
<
FileSystemPath
>
,
project_path
:
ResolvedVc
<
FileSystemPath
>
,
...
@@ -648,7 +631,7 @@ pub async fn get_server_module_options_context(
...
@@ -648,7 +631,7 @@ pub async fn get_server_module_options_context(
foreign_code_module_options_context
.resolved_cell
(),
foreign_code_module_options_context
.resolved_cell
(),
),
),
(
(
internal_assets_conditions
(),
internal_assets_conditions
()
.await
?
,
internal_module_options_context
.resolved_cell
(),
internal_module_options_context
.resolved_cell
(),
),
),
],
],
...
@@ -713,7 +696,7 @@ pub async fn get_server_module_options_context(
...
@@ -713,7 +696,7 @@ pub async fn get_server_module_options_context(
foreign_code_module_options_context
.resolved_cell
(),
foreign_code_module_options_context
.resolved_cell
(),
),
),
(
(
internal_assets_conditions
(),
internal_assets_conditions
()
.await
?
,
internal_module_options_context
.resolved_cell
(),
internal_module_options_context
.resolved_cell
(),
),
),
],
],
...
@@ -789,7 +772,7 @@ pub async fn get_server_module_options_context(
...
@@ -789,7 +772,7 @@ pub async fn get_server_module_options_context(
foreign_code_module_options_context
.resolved_cell
(),
foreign_code_module_options_context
.resolved_cell
(),
),
),
(
(
internal_assets_conditions
(),
internal_assets_conditions
()
.await
?
,
internal_module_options_context
.resolved_cell
(),
internal_module_options_context
.resolved_cell
(),
),
),
],
],
...
@@ -864,7 +847,7 @@ pub async fn get_server_module_options_context(
...
@@ -864,7 +847,7 @@ pub async fn get_server_module_options_context(
foreign_code_module_options_context
.resolved_cell
(),
foreign_code_module_options_context
.resolved_cell
(),
),
),
(
(
internal_assets_conditions
(),
internal_assets_conditions
()
.await
?
,
internal_module_options_context
.resolved_cell
(),
internal_module_options_context
.resolved_cell
(),
),
),
],
],
...
@@ -961,7 +944,7 @@ pub async fn get_server_module_options_context(
...
@@ -961,7 +944,7 @@ pub async fn get_server_module_options_context(
foreign_code_module_options_context
.resolved_cell
(),
foreign_code_module_options_context
.resolved_cell
(),
),
),
(
(
internal_assets_conditions
(),
internal_assets_conditions
()
.await
?
,
internal_module_options_context
.resolved_cell
(),
internal_module_options_context
.resolved_cell
(),
),
),
],
],
...
...
crates/next-core/src/util.rs
View file @
521cdaef
...
@@ -13,7 +13,7 @@ use turbo_tasks::{
...
@@ -13,7 +13,7 @@ use turbo_tasks::{
};
};
use
turbo_tasks_fs
::{
use
turbo_tasks_fs
::{
self
,
json
::
parse_json_rope_with_source_context
,
rope
::
Rope
,
util
::
join_path
,
File
,
self
,
json
::
parse_json_rope_with_source_context
,
rope
::
Rope
,
util
::
join_path
,
File
,
FileContent
,
FileSystemPath
,
FileContent
,
FileSystem
,
FileSystem
Path
,
};
};
use
turbopack_core
::{
use
turbopack_core
::{
asset
::
AssetContent
,
asset
::
AssetContent
,
...
@@ -32,6 +32,7 @@ use turbopack_ecmascript::{
...
@@ -32,6 +32,7 @@ use turbopack_ecmascript::{
};
};
use
crate
::{
use
crate
::{
embed_js
::
next_js_fs
,
next_config
::{
NextConfig
,
RouteHas
},
next_config
::{
NextConfig
,
RouteHas
},
next_import_map
::
get_next_package
,
next_import_map
::
get_next_package
,
next_manifests
::
MiddlewareMatcher
,
next_manifests
::
MiddlewareMatcher
,
...
@@ -121,7 +122,10 @@ pub async fn foreign_code_context_condition(
...
@@ -121,7 +122,10 @@ pub async fn foreign_code_context_condition(
// of the `node_modules` specific resolve options (the template files are
// of the `node_modules` specific resolve options (the template files are
// technically node module files).
// technically node module files).
let
not_next_template_dir
=
ContextCondition
::
not
(
ContextCondition
::
InPath
(
let
not_next_template_dir
=
ContextCondition
::
not
(
ContextCondition
::
InPath
(
get_next_package
(
*
project_path
)
.join
(
NEXT_TEMPLATE_PATH
.into
()),
get_next_package
(
*
project_path
)
.join
(
NEXT_TEMPLATE_PATH
.into
())
.to_resolved
()
.await
?
,
));
));
let
result
=
ContextCondition
::
all
(
vec!
[
let
result
=
ContextCondition
::
all
(
vec!
[
...
@@ -137,6 +141,31 @@ pub async fn foreign_code_context_condition(
...
@@ -137,6 +141,31 @@ pub async fn foreign_code_context_condition(
Ok
(
result
)
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
/// 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(
#[derive(
Default,
Default,
PartialEq,
PartialEq,
...
...
turbopack/crates/turbopack-core/src/condition.rs
View file @
521cdaef
use
anyhow
::
Result
;
use
anyhow
::
Result
;
use
futures
::{
stream
,
StreamExt
};
use
futures
::{
stream
,
StreamExt
};
use
serde
::{
Deserialize
,
Serialize
};
use
serde
::{
Deserialize
,
Serialize
};
use
turbo_tasks
::{
trace
::
TraceRawVcs
,
Vc
};
use
turbo_tasks
::{
trace
::
TraceRawVcs
,
NonLocalValue
,
Resolved
Vc
};
use
turbo_tasks_fs
::
FileSystemPath
;
use
turbo_tasks_fs
::
FileSystemPath
;
#[derive(Debug,
Clone,
Serialize,
Deserialize,
TraceRawVcs,
PartialEq,
Eq)]
#[derive(Debug,
Clone,
Serialize,
Deserialize,
TraceRawVcs,
PartialEq,
Eq
,
NonLocalValue
)]
pub
enum
ContextCondition
{
pub
enum
ContextCondition
{
All
(
Vec
<
ContextCondition
>
),
All
(
Vec
<
ContextCondition
>
),
Any
(
Vec
<
ContextCondition
>
),
Any
(
Vec
<
ContextCondition
>
),
Not
(
Box
<
ContextCondition
>
),
Not
(
Box
<
ContextCondition
>
),
InDirectory
(
String
),
InDirectory
(
String
),
InPath
(
Vc
<
FileSystemPath
>
),
InPath
(
Resolved
Vc
<
FileSystemPath
>
),
}
}
impl
ContextCondition
{
impl
ContextCondition
{
...
...
turbopack/crates/turbopack-resolve/src/resolve_options_context.rs
View file @
521cdaef
...
@@ -11,7 +11,7 @@ use turbopack_core::{
...
@@ -11,7 +11,7 @@ use turbopack_core::{
},
},
};
};
#[turbo_tasks
::
value(shared
,
local
)]
#[turbo_tasks
::
value(shared)]
#[derive(Default,
Clone)]
#[derive(Default,
Clone)]
pub
struct
ResolveOptionsContext
{
pub
struct
ResolveOptionsContext
{
#[serde(default)]
#[serde(default)]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment