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
e6609447
Commit
e6609447
authored
Aug 11, 2025
by
Tobias Koppers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Turbopack: add `evaluation` info to `EsmExports`
parent
a7107d5b
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
122 additions
and
28 deletions
+122
-28
context.rs
crates/next-core/src/next_client/context.rs
+6
-1
dynamic_module.rs
crates/next-core/src/next_dynamic/dynamic_module.rs
+2
-1
context.rs
crates/next-core/src/next_server/context.rs
+6
-2
server_component_module.rs
...core/src/next_server_component/server_component_module.rs
+2
-1
server_utility_module.rs
...ext-core/src/next_server_utility/server_utility_module.rs
+2
-1
placeable.rs
turbopack/crates/turbopack-ecmascript/src/chunk/placeable.rs
+5
-3
inlined_bytes_module.rs
...k/crates/turbopack-ecmascript/src/inlined_bytes_module.rs
+5
-2
lib.rs
turbopack/crates/turbopack-ecmascript/src/lib.rs
+3
-1
export.rs
.../crates/turbopack-ecmascript/src/references/esm/export.rs
+33
-2
mod.rs
...ack/crates/turbopack-ecmascript/src/references/esm/mod.rs
+1
-1
mod.rs
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
+17
-2
module.rs
...-ecmascript/src/side_effect_optimization/facade/module.rs
+12
-1
module.rs
...-ecmascript/src/side_effect_optimization/locals/module.rs
+1
-0
lib.rs
turbopack/crates/turbopack/src/lib.rs
+11
-8
mod.rs
turbopack/crates/turbopack/src/module_options/mod.rs
+2
-0
module_options_context.rs
...es/turbopack/src/module_options/module_options_context.rs
+14
-2
No files found.
crates/next-core/src/next_client/context.rs
View file @
e6609447
...
@@ -10,6 +10,7 @@ use turbopack::{
...
@@ -10,6 +10,7 @@ use turbopack::{
module_options
::{
module_options
::{
CssOptionsContext
,
EcmascriptOptionsContext
,
JsxTransformOptions
,
ModuleRule
,
CssOptionsContext
,
EcmascriptOptionsContext
,
JsxTransformOptions
,
ModuleRule
,
TypescriptTransformOptions
,
module_options_context
::
ModuleOptionsContext
,
TypescriptTransformOptions
,
module_options_context
::
ModuleOptionsContext
,
package_list_to_glob
,
},
},
resolve_options_context
::
ResolveOptionsContext
,
resolve_options_context
::
ResolveOptionsContext
,
};
};
...
@@ -335,7 +336,11 @@ pub async fn get_client_module_options_context(
...
@@ -335,7 +336,11 @@ pub async fn get_client_module_options_context(
execution_context
:
Some
(
execution_context
),
execution_context
:
Some
(
execution_context
),
tree_shaking_mode
:
tree_shaking_mode_for_user_code
,
tree_shaking_mode
:
tree_shaking_mode_for_user_code
,
enable_postcss_transform
,
enable_postcss_transform
,
side_effect_free_packages
:
next_config
.optimize_package_imports
()
.owned
()
.await
?
,
side_effect_free_packages
:
Some
(
package_list_to_glob
(
next_config
.optimize_package_imports
()
.owned
()
.await
?
)
.to_resolved
()
.await
?
,
),
keep_last_successful_parse
:
next_mode
.is_development
(),
keep_last_successful_parse
:
next_mode
.is_development
(),
..
Default
::
default
()
..
Default
::
default
()
};
};
...
...
crates/next-core/src/next_dynamic/dynamic_module.rs
View file @
e6609447
...
@@ -18,7 +18,7 @@ use turbopack_ecmascript::{
...
@@ -18,7 +18,7 @@ use turbopack_ecmascript::{
EcmascriptChunkItem
,
EcmascriptChunkItemContent
,
EcmascriptChunkPlaceable
,
EcmascriptChunkItem
,
EcmascriptChunkItemContent
,
EcmascriptChunkPlaceable
,
EcmascriptChunkType
,
EcmascriptExports
,
EcmascriptExportsType
,
EcmascriptChunkType
,
EcmascriptExports
,
EcmascriptExportsType
,
},
},
references
::
esm
::{
EsmExport
,
EsmExports
},
references
::
esm
::{
EsmE
valuation
,
EsmE
xport
,
EsmExports
},
runtime_functions
::{
TURBOPACK_EXPORT_NAMESPACE
,
TURBOPACK_IMPORT
},
runtime_functions
::{
TURBOPACK_EXPORT_NAMESPACE
,
TURBOPACK_IMPORT
},
utils
::
StringifyJs
,
utils
::
StringifyJs
,
};
};
...
@@ -118,6 +118,7 @@ impl EcmascriptChunkPlaceable for NextDynamicEntryModule {
...
@@ -118,6 +118,7 @@ impl EcmascriptChunkPlaceable for NextDynamicEntryModule {
EsmExports
{
EsmExports
{
exports
,
exports
,
star_exports
:
vec!
[
module_reference
],
star_exports
:
vec!
[
module_reference
],
evaluation
:
EsmEvaluation
::
DelegatedSideEffects
(
module_reference
),
}
}
.resolved_cell
(),
.resolved_cell
(),
),
),
...
...
crates/next-core/src/next_server/context.rs
View file @
e6609447
...
@@ -9,7 +9,7 @@ use turbopack::{
...
@@ -9,7 +9,7 @@ use turbopack::{
css
::
chunk
::
CssChunkType
,
css
::
chunk
::
CssChunkType
,
module_options
::{
module_options
::{
CssOptionsContext
,
EcmascriptOptionsContext
,
ExternalsTracingOptions
,
JsxTransformOptions
,
CssOptionsContext
,
EcmascriptOptionsContext
,
ExternalsTracingOptions
,
JsxTransformOptions
,
ModuleOptionsContext
,
ModuleRule
,
TypescriptTransformOptions
,
ModuleOptionsContext
,
ModuleRule
,
TypescriptTransformOptions
,
package_list_to_glob
,
},
},
resolve_options_context
::
ResolveOptionsContext
,
resolve_options_context
::
ResolveOptionsContext
,
transition
::
Transition
,
transition
::
Transition
,
...
@@ -589,7 +589,11 @@ pub async fn get_server_module_options_context(
...
@@ -589,7 +589,11 @@ pub async fn get_server_module_options_context(
..
Default
::
default
()
..
Default
::
default
()
},
},
tree_shaking_mode
:
tree_shaking_mode_for_user_code
,
tree_shaking_mode
:
tree_shaking_mode_for_user_code
,
side_effect_free_packages
:
next_config
.optimize_package_imports
()
.owned
()
.await
?
,
side_effect_free_packages
:
Some
(
package_list_to_glob
(
next_config
.optimize_package_imports
()
.owned
()
.await
?
)
.to_resolved
()
.await
?
,
),
enable_externals_tracing
:
if
next_mode
.is_production
()
{
enable_externals_tracing
:
if
next_mode
.is_production
()
{
Some
(
Some
(
ExternalsTracingOptions
{
ExternalsTracingOptions
{
...
...
crates/next-core/src/next_server_component/server_component_module.rs
View file @
e6609447
...
@@ -18,7 +18,7 @@ use turbopack_ecmascript::{
...
@@ -18,7 +18,7 @@ use turbopack_ecmascript::{
EcmascriptChunkItem
,
EcmascriptChunkItemContent
,
EcmascriptChunkPlaceable
,
EcmascriptChunkItem
,
EcmascriptChunkItemContent
,
EcmascriptChunkPlaceable
,
EcmascriptChunkType
,
EcmascriptExports
,
EcmascriptExportsType
,
EcmascriptChunkType
,
EcmascriptExports
,
EcmascriptExportsType
,
},
},
references
::
esm
::{
EsmExport
,
EsmExports
},
references
::
esm
::{
EsmE
valuation
,
EsmE
xport
,
EsmExports
},
runtime_functions
::{
TURBOPACK_EXPORT_NAMESPACE
,
TURBOPACK_IMPORT
},
runtime_functions
::{
TURBOPACK_EXPORT_NAMESPACE
,
TURBOPACK_IMPORT
},
utils
::
StringifyJs
,
utils
::
StringifyJs
,
};
};
...
@@ -111,6 +111,7 @@ impl EcmascriptChunkPlaceable for NextServerComponentModule {
...
@@ -111,6 +111,7 @@ impl EcmascriptChunkPlaceable for NextServerComponentModule {
EsmExports
{
EsmExports
{
exports
,
exports
,
star_exports
:
vec!
[
module_reference
],
star_exports
:
vec!
[
module_reference
],
evaluation
:
EsmEvaluation
::
DelegatedSideEffects
(
module_reference
),
}
}
.resolved_cell
(),
.resolved_cell
(),
),
),
...
...
crates/next-core/src/next_server_utility/server_utility_module.rs
View file @
e6609447
...
@@ -18,7 +18,7 @@ use turbopack_ecmascript::{
...
@@ -18,7 +18,7 @@ use turbopack_ecmascript::{
EcmascriptChunkItem
,
EcmascriptChunkItemContent
,
EcmascriptChunkPlaceable
,
EcmascriptChunkItem
,
EcmascriptChunkItemContent
,
EcmascriptChunkPlaceable
,
EcmascriptChunkType
,
EcmascriptExports
,
EcmascriptExportsType
,
EcmascriptChunkType
,
EcmascriptExports
,
EcmascriptExportsType
,
},
},
references
::
esm
::{
EsmExport
,
EsmExports
},
references
::
esm
::{
EsmE
valuation
,
EsmE
xport
,
EsmExports
},
runtime_functions
::{
TURBOPACK_EXPORT_NAMESPACE
,
TURBOPACK_IMPORT
},
runtime_functions
::{
TURBOPACK_EXPORT_NAMESPACE
,
TURBOPACK_IMPORT
},
utils
::
StringifyJs
,
utils
::
StringifyJs
,
};
};
...
@@ -111,6 +111,7 @@ impl EcmascriptChunkPlaceable for NextServerUtilityModule {
...
@@ -111,6 +111,7 @@ impl EcmascriptChunkPlaceable for NextServerUtilityModule {
EsmExports
{
EsmExports
{
exports
,
exports
,
star_exports
:
vec!
[
module_reference
],
star_exports
:
vec!
[
module_reference
],
evaluation
:
EsmEvaluation
::
DelegatedSideEffects
(
module_reference
),
}
}
.resolved_cell
(),
.resolved_cell
(),
),
),
...
...
turbopack/crates/turbopack-ecmascript/src/chunk/placeable.rs
View file @
e6609447
...
@@ -39,7 +39,7 @@ pub trait EcmascriptChunkPlaceable: ChunkableModule + Module + Asset {
...
@@ -39,7 +39,7 @@ pub trait EcmascriptChunkPlaceable: ChunkableModule + Module + Asset {
)
->
Result
<
Vc
<
bool
>>
{
)
->
Result
<
Vc
<
bool
>>
{
Ok
(
is_marked_as_side_effect_free
(
Ok
(
is_marked_as_side_effect_free
(
self
.ident
()
.path
()
.owned
()
.await
?
,
self
.ident
()
.path
()
.owned
()
.await
?
,
side_effect_free_packages
,
Some
(
side_effect_free_packages
)
,
))
))
}
}
}
}
...
@@ -193,9 +193,11 @@ impl Issue for SideEffectsInPackageJsonIssue {
...
@@ -193,9 +193,11 @@ impl Issue for SideEffectsInPackageJsonIssue {
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
pub
async
fn
is_marked_as_side_effect_free
(
pub
async
fn
is_marked_as_side_effect_free
(
path
:
FileSystemPath
,
path
:
FileSystemPath
,
side_effect_free_packages
:
Vc
<
Glob
>
,
side_effect_free_packages
:
Option
<
Vc
<
Glob
>
>
,
)
->
Result
<
Vc
<
bool
>>
{
)
->
Result
<
Vc
<
bool
>>
{
if
side_effect_free_packages
.await
?
.matches
(
&
path
.path
)
{
if
let
Some
(
side_effect_free_packages
)
=
side_effect_free_packages
&&
side_effect_free_packages
.await
?
.matches
(
&
path
.path
)
{
return
Ok
(
Vc
::
cell
(
true
));
return
Ok
(
Vc
::
cell
(
true
));
}
}
...
...
turbopack/crates/turbopack-ecmascript/src/inlined_bytes_module.rs
View file @
e6609447
...
@@ -16,7 +16,7 @@ use turbopack_core::{
...
@@ -16,7 +16,7 @@ use turbopack_core::{
use
crate
::{
use
crate
::{
chunk
::{
chunk
::{
EcmascriptChunkItem
,
EcmascriptChunkItemContent
,
EcmascriptChunkPlaceable
,
EcmascriptChunkItem
,
EcmascriptChunkItemContent
,
EcmascriptChunkPlaceable
,
EcmascriptChunkType
,
EcmascriptExports
,
EcmascriptChunkType
,
EcmascriptExports
,
EcmascriptExportsType
,
},
},
runtime_functions
::
TURBOPACK_EXPORT_VALUE
,
runtime_functions
::
TURBOPACK_EXPORT_VALUE
,
utils
::
StringifyJs
,
utils
::
StringifyJs
,
...
@@ -72,7 +72,10 @@ impl ChunkableModule for InlinedBytesJsModule {
...
@@ -72,7 +72,10 @@ impl ChunkableModule for InlinedBytesJsModule {
impl
EcmascriptChunkPlaceable
for
InlinedBytesJsModule
{
impl
EcmascriptChunkPlaceable
for
InlinedBytesJsModule
{
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
fn
get_exports
(
&
self
)
->
Vc
<
EcmascriptExports
>
{
fn
get_exports
(
&
self
)
->
Vc
<
EcmascriptExports
>
{
EcmascriptExports
::
Value
.cell
()
EcmascriptExports
{
ty
:
EcmascriptExportsType
::
Value
,
}
.cell
()
}
}
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
...
...
turbopack/crates/turbopack-ecmascript/src/lib.rs
View file @
e6609447
...
@@ -218,6 +218,8 @@ pub struct EcmascriptOptions {
...
@@ -218,6 +218,8 @@ pub struct EcmascriptOptions {
/// If true, it reads a sourceMappingURL comment from the end of the file,
/// If true, it reads a sourceMappingURL comment from the end of the file,
/// reads and generates a source map.
/// reads and generates a source map.
pub
extract_source_map
:
bool
,
pub
extract_source_map
:
bool
,
/// Packages that are considered side effect free.
pub
side_effect_free_packages
:
Option
<
ResolvedVc
<
Glob
>>
,
/// If true, it stores the last successful parse result in state and keeps using it when
/// If true, it stores the last successful parse result in state and keeps using it when
/// parsing fails. This is useful to keep the module graph structure intact when syntax errors
/// parsing fails. This is useful to keep the module graph structure intact when syntax errors
/// are temporarily introduced.
/// are temporarily introduced.
...
@@ -736,7 +738,7 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleAsset {
...
@@ -736,7 +738,7 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleAsset {
// Check package.json first, so that we can skip parsing the module if it's marked that way.
// Check package.json first, so that we can skip parsing the module if it's marked that way.
let
pkg_side_effect_free
=
is_marked_as_side_effect_free
(
let
pkg_side_effect_free
=
is_marked_as_side_effect_free
(
self
.ident
()
.path
()
.owned
()
.await
?
,
self
.ident
()
.path
()
.owned
()
.await
?
,
side_effect_free_packages
,
Some
(
side_effect_free_packages
)
,
);
);
Ok
(
if
*
pkg_side_effect_free
.await
?
{
Ok
(
if
*
pkg_side_effect_free
.await
?
{
pkg_side_effect_free
pkg_side_effect_free
...
...
turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs
View file @
e6609447
...
@@ -14,7 +14,7 @@ use swc_core::{
...
@@ -14,7 +14,7 @@ use swc_core::{
use
turbo_rcstr
::{
RcStr
,
rcstr
};
use
turbo_rcstr
::{
RcStr
,
rcstr
};
use
turbo_tasks
::{
use
turbo_tasks
::{
FxIndexMap
,
NonLocalValue
,
ResolvedVc
,
TryFlatJoinIterExt
,
ValueToString
,
Vc
,
FxIndexMap
,
NonLocalValue
,
ResolvedVc
,
TryFlatJoinIterExt
,
ValueToString
,
Vc
,
trace
::
TraceRawVcs
,
debug
::
ValueDebugFormat
,
trace
::
TraceRawVcs
,
};
};
use
turbo_tasks_fs
::
glob
::
Glob
;
use
turbo_tasks_fs
::
glob
::
Glob
;
use
turbopack_core
::{
use
turbopack_core
::{
...
@@ -435,7 +435,7 @@ pub async fn expand_star_exports(
...
@@ -435,7 +435,7 @@ pub async fn expand_star_exports(
if
let
Entry
::
Vacant
(
entry
)
=
esm_exports
.entry
(
key
.clone
())
{
if
let
Entry
::
Vacant
(
entry
)
=
esm_exports
.entry
(
key
.clone
())
{
entry
.insert
(
match
esm_export
{
entry
.insert
(
match
esm_export
{
EsmExport
::
LocalBinding
(
_
,
liveness
)
=>
EsmExport
::
ImportedBinding
(
EsmExport
::
LocalBinding
(
_
,
liveness
)
=>
EsmExport
::
ImportedBinding
(
ResolvedVc
::
upcast
(
reference
)
,
reference
,
key
.clone
(),
key
.clone
(),
*
liveness
==
Liveness
::
Mutable
,
*
liveness
==
Liveness
::
Mutable
,
),
),
...
@@ -526,11 +526,42 @@ async fn emit_star_exports_issue(source_ident: Vc<AssetIdent>, message: RcStr) -
...
@@ -526,11 +526,42 @@ async fn emit_star_exports_issue(source_ident: Vc<AssetIdent>, message: RcStr) -
Ok
(())
Ok
(())
}
}
#[derive(
Debug,
Default,
Clone,
Copy,
PartialEq,
Eq,
Hash,
ValueDebugFormat,
Serialize,
Deserialize,
TraceRawVcs,
NonLocalValue,
)]
pub
enum
EsmEvaluation
{
/// The module has module evaluation side effects.
#[default]
SideEffects
,
/// The module has no module evaluation side effects when none of the references have side
/// effects.
LocalSideEffectFree
,
/// The module has no module evaluation side effects. It can be ignored when looking for
/// the module evaluation.
SideEffectFree
,
/// The module has no module evaluation side effects other than evaluating the referenced
/// module. In this case the module itself can be skipped in favor of these module that is
/// referenced here.
DelegatedSideEffects
(
ResolvedVc
<
Box
<
dyn
ModuleReference
>>
),
}
#[turbo_tasks
::
value(shared)]
#[turbo_tasks
::
value(shared)]
#[derive(Hash,
Debug)]
#[derive(Hash,
Debug)]
pub
struct
EsmExports
{
pub
struct
EsmExports
{
pub
exports
:
BTreeMap
<
RcStr
,
EsmExport
>
,
pub
exports
:
BTreeMap
<
RcStr
,
EsmExport
>
,
pub
star_exports
:
Vec
<
ResolvedVc
<
Box
<
dyn
ModuleReference
>>>
,
pub
star_exports
:
Vec
<
ResolvedVc
<
Box
<
dyn
ModuleReference
>>>
,
pub
evaluation
:
EsmEvaluation
,
}
}
/// The expanded version of [`EsmExports`], the `exports` field here includes all exports that could
/// The expanded version of [`EsmExports`], the `exports` field here includes all exports that could
...
...
turbopack/crates/turbopack-ecmascript/src/references/esm/mod.rs
View file @
e6609447
...
@@ -11,7 +11,7 @@ pub use self::{
...
@@ -11,7 +11,7 @@ pub use self::{
base
::
EsmAssetReference
,
base
::
EsmAssetReference
,
binding
::
EsmBinding
,
binding
::
EsmBinding
,
dynamic
::
EsmAsyncAssetReference
,
dynamic
::
EsmAsyncAssetReference
,
export
::{
EsmExport
,
EsmExports
,
FoundExportType
,
Liveness
},
export
::{
EsmE
valuation
,
EsmE
xport
,
EsmExports
,
FoundExportType
,
Liveness
},
meta
::{
ImportMetaBinding
,
ImportMetaRef
},
meta
::{
ImportMetaBinding
,
ImportMetaRef
},
module_item
::
EsmModuleItem
,
module_item
::
EsmModuleItem
,
url
::{
UrlAssetReference
,
UrlRewriteBehavior
},
url
::{
UrlAssetReference
,
UrlRewriteBehavior
},
...
...
turbopack/crates/turbopack-ecmascript/src/references/mod.rs
View file @
e6609447
...
@@ -138,9 +138,9 @@ use crate::{
...
@@ -138,9 +138,9 @@ use crate::{
parse_require_context
,
parse_require_context
,
top_level_await
::
has_top_level_await
,
top_level_await
::
has_top_level_await
,
},
},
chunk
::{
EcmascriptExports
,
EcmascriptExportsType
},
chunk
::{
EcmascriptExports
,
EcmascriptExportsType
,
placeable
::
is_marked_as_side_effect_free
},
code_gen
::{
CodeGen
,
CodeGens
,
IntoCodeGenReference
},
code_gen
::{
CodeGen
,
CodeGens
,
IntoCodeGenReference
},
export
::
Liveness
,
export
::
{
EsmEvaluation
,
Liveness
}
,
magic_identifier
,
magic_identifier
,
references
::{
references
::{
async_module
::{
AsyncModule
,
OptionAsyncModule
},
async_module
::{
AsyncModule
,
OptionAsyncModule
},
...
@@ -795,6 +795,17 @@ pub async fn analyse_ecmascript_module_internal(
...
@@ -795,6 +795,17 @@ pub async fn analyse_ecmascript_module_internal(
}
}
}
}
let
marked_as_side_effect_free
=
has_side_effect_free_directive
||
*
is_marked_as_side_effect_free
(
path
.clone
(),
options
.side_effect_free_packages
.map
(|
l
|
*
l
),
)
.await
?
;
let
evaluation
=
if
marked_as_side_effect_free
{
EsmEvaluation
::
SideEffectFree
}
else
{
EsmEvaluation
::
SideEffects
};
let
exports
=
if
!
esm_exports
.is_empty
()
||
!
esm_star_exports
.is_empty
()
{
let
exports
=
if
!
esm_exports
.is_empty
()
||
!
esm_star_exports
.is_empty
()
{
if
specified_type
==
SpecifiedModuleType
::
CommonJs
{
if
specified_type
==
SpecifiedModuleType
::
CommonJs
{
SpecifiedModuleTypeIssue
{
SpecifiedModuleTypeIssue
{
...
@@ -809,6 +820,7 @@ pub async fn analyse_ecmascript_module_internal(
...
@@ -809,6 +820,7 @@ pub async fn analyse_ecmascript_module_internal(
let
esm_exports
=
EsmExports
{
let
esm_exports
=
EsmExports
{
exports
:
esm_exports
,
exports
:
esm_exports
,
star_exports
:
esm_star_exports
,
star_exports
:
esm_star_exports
,
evaluation
,
}
}
.cell
();
.cell
();
...
@@ -829,6 +841,7 @@ pub async fn analyse_ecmascript_module_internal(
...
@@ -829,6 +841,7 @@ pub async fn analyse_ecmascript_module_internal(
EsmExports
{
EsmExports
{
exports
:
Default
::
default
(),
exports
:
Default
::
default
(),
star_exports
:
Default
::
default
(),
star_exports
:
Default
::
default
(),
evaluation
,
}
}
.resolved_cell
(),
.resolved_cell
(),
)
)
...
@@ -840,6 +853,7 @@ pub async fn analyse_ecmascript_module_internal(
...
@@ -840,6 +853,7 @@ pub async fn analyse_ecmascript_module_internal(
EsmExports
{
EsmExports
{
exports
:
Default
::
default
(),
exports
:
Default
::
default
(),
star_exports
:
Default
::
default
(),
star_exports
:
Default
::
default
(),
evaluation
,
}
}
.resolved_cell
(),
.resolved_cell
(),
),
),
...
@@ -854,6 +868,7 @@ pub async fn analyse_ecmascript_module_internal(
...
@@ -854,6 +868,7 @@ pub async fn analyse_ecmascript_module_internal(
EsmExports
{
EsmExports
{
exports
:
Default
::
default
(),
exports
:
Default
::
default
(),
star_exports
:
Default
::
default
(),
star_exports
:
Default
::
default
(),
evaluation
,
}
}
.resolved_cell
(),
.resolved_cell
(),
)
)
...
...
turbopack/crates/turbopack-ecmascript/src/side_effect_optimization/facade/module.rs
View file @
e6609447
...
@@ -22,7 +22,7 @@ use crate::{
...
@@ -22,7 +22,7 @@ use crate::{
EcmascriptModuleContentOptions
,
EcmascriptOptions
,
MergedEcmascriptModule
,
SpecifiedModuleType
,
EcmascriptModuleContentOptions
,
EcmascriptOptions
,
MergedEcmascriptModule
,
SpecifiedModuleType
,
chunk
::{
EcmascriptChunkPlaceable
,
EcmascriptExports
,
EcmascriptExportsType
},
chunk
::{
EcmascriptChunkPlaceable
,
EcmascriptExports
,
EcmascriptExportsType
},
code_gen
::
CodeGens
,
code_gen
::
CodeGens
,
export
::
Liveness
,
export
::
{
EsmEvaluation
,
Liveness
}
,
references
::{
references
::{
async_module
::{
AsyncModule
,
OptionAsyncModule
},
async_module
::{
AsyncModule
,
OptionAsyncModule
},
esm
::{
EsmExport
,
EsmExports
,
base
::
EsmAssetReferences
},
esm
::{
EsmExport
,
EsmExports
,
base
::
EsmAssetReferences
},
...
@@ -238,6 +238,7 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
...
@@ -238,6 +238,7 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
async
fn
get_exports
(
&
self
)
->
Result
<
Vc
<
EcmascriptExports
>>
{
async
fn
get_exports
(
&
self
)
->
Result
<
Vc
<
EcmascriptExports
>>
{
let
mut
exports
=
BTreeMap
::
new
();
let
mut
exports
=
BTreeMap
::
new
();
let
mut
star_exports
=
Vec
::
new
();
let
mut
star_exports
=
Vec
::
new
();
let
mut
evaluation
=
EsmEvaluation
::
SideEffects
;
match
&
self
.part
{
match
&
self
.part
{
ModulePart
::
Facade
=>
{
ModulePart
::
Facade
=>
{
...
@@ -289,6 +290,15 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
...
@@ -289,6 +290,15 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
}
}
}
}
star_exports
.extend
(
esm_exports
.star_exports
.iter
()
.copied
());
star_exports
.extend
(
esm_exports
.star_exports
.iter
()
.copied
());
evaluation
=
EsmEvaluation
::
DelegatedSideEffects
(
ResolvedVc
::
upcast
(
EcmascriptModulePartReference
::
new_part
(
*
self
.module
,
ModulePart
::
locals
(),
ExportUsage
::
evaluation
(),
)
.to_resolved
()
.await
?
,
));
}
}
ModulePart
::
RenamedExport
{
ModulePart
::
RenamedExport
{
original_export
,
original_export
,
...
@@ -331,6 +341,7 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
...
@@ -331,6 +341,7 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
let
exports
=
EsmExports
{
let
exports
=
EsmExports
{
exports
,
exports
,
star_exports
,
star_exports
,
evaluation
,
}
}
.resolved_cell
();
.resolved_cell
();
Ok
(
EcmascriptExports
{
Ok
(
EcmascriptExports
{
...
...
turbopack/crates/turbopack-ecmascript/src/side_effect_optimization/locals/module.rs
View file @
e6609447
...
@@ -159,6 +159,7 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleLocalsModule {
...
@@ -159,6 +159,7 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleLocalsModule {
let
exports
=
EsmExports
{
let
exports
=
EsmExports
{
exports
,
exports
,
star_exports
:
vec!
[],
star_exports
:
vec!
[],
evaluation
:
esm_exports
.evaluation
,
}
}
.resolved_cell
();
.resolved_cell
();
Ok
(
EcmascriptExports
{
Ok
(
EcmascriptExports
{
...
...
turbopack/crates/turbopack/src/lib.rs
View file @
e6609447
...
@@ -899,14 +899,17 @@ impl AssetContext for ModuleAssetContext {
...
@@ -899,14 +899,17 @@ impl AssetContext for ModuleAssetContext {
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
async
fn
side_effect_free_packages
(
&
self
)
->
Result
<
Vc
<
Glob
>>
{
async
fn
side_effect_free_packages
(
&
self
)
->
Result
<
Vc
<
Glob
>>
{
let
pkgs
=
&
self
.module_options_context.await
?
.side_effect_free_packages
;
Ok
(
self
.module_options_context
let
mut
globs
=
String
::
new
();
.await
?
globs
.push_str
(
"**/node_modules/{"
);
.side_effect_free_packages
globs
.push_str
(
&
pkgs
.join
(
","
));
.map_or_else
(
globs
.push_str
(
"}/**"
);
||
{
// If no side effect free packages are configured, return an empty glob.
Ok
(
Glob
::
new
(
globs
.into
(),
GlobOptions
::
default
()))
Glob
::
new
(
rcstr!
(
""
),
GlobOptions
::
default
())
},
|
glob
|
*
glob
,
))
}
}
}
}
...
...
turbopack/crates/turbopack/src/module_options/mod.rs
View file @
e6609447
...
@@ -227,6 +227,7 @@ impl ModuleOptions {
...
@@ -227,6 +227,7 @@ impl ModuleOptions {
execution_context
,
execution_context
,
tree_shaking_mode
,
tree_shaking_mode
,
keep_last_successful_parse
,
keep_last_successful_parse
,
side_effect_free_packages
,
is_tracing
,
is_tracing
,
..
..
}
=
*
module_options_context
.await
?
;
}
=
*
module_options_context
.await
?
;
...
@@ -281,6 +282,7 @@ impl ModuleOptions {
...
@@ -281,6 +282,7 @@ impl ModuleOptions {
ignore_dynamic_requests
,
ignore_dynamic_requests
,
extract_source_map
:
matches!
(
ecmascript_source_maps
,
SourceMapsType
::
Full
),
extract_source_map
:
matches!
(
ecmascript_source_maps
,
SourceMapsType
::
Full
),
keep_last_successful_parse
,
keep_last_successful_parse
,
side_effect_free_packages
,
is_tracing
,
is_tracing
,
enable_typeof_window_inlining
,
enable_typeof_window_inlining
,
..
Default
::
default
()
..
Default
::
default
()
...
...
turbopack/crates/turbopack/src/module_options/module_options_context.rs
View file @
e6609447
...
@@ -4,7 +4,10 @@ use serde::{Deserialize, Serialize};
...
@@ -4,7 +4,10 @@ use serde::{Deserialize, Serialize};
use
turbo_esregex
::
EsRegex
;
use
turbo_esregex
::
EsRegex
;
use
turbo_rcstr
::
RcStr
;
use
turbo_rcstr
::
RcStr
;
use
turbo_tasks
::{
NonLocalValue
,
ResolvedVc
,
ValueDefault
,
Vc
,
trace
::
TraceRawVcs
};
use
turbo_tasks
::{
NonLocalValue
,
ResolvedVc
,
ValueDefault
,
Vc
,
trace
::
TraceRawVcs
};
use
turbo_tasks_fs
::
FileSystemPath
;
use
turbo_tasks_fs
::{
FileSystemPath
,
glob
::{
Glob
,
GlobOptions
},
};
use
turbopack_core
::{
use
turbopack_core
::{
chunk
::
SourceMapsType
,
compile_time_info
::
CompileTimeInfo
,
condition
::
ContextCondition
,
chunk
::
SourceMapsType
,
compile_time_info
::
CompileTimeInfo
,
condition
::
ContextCondition
,
environment
::
Environment
,
resolve
::
options
::
ImportMapping
,
environment
::
Environment
,
resolve
::
options
::
ImportMapping
,
...
@@ -187,7 +190,7 @@ pub struct ModuleOptionsContext {
...
@@ -187,7 +190,7 @@ pub struct ModuleOptionsContext {
pub
environment
:
Option
<
ResolvedVc
<
Environment
>>
,
pub
environment
:
Option
<
ResolvedVc
<
Environment
>>
,
pub
execution_context
:
Option
<
ResolvedVc
<
ExecutionContext
>>
,
pub
execution_context
:
Option
<
ResolvedVc
<
ExecutionContext
>>
,
pub
side_effect_free_packages
:
Vec
<
RcStr
>
,
pub
side_effect_free_packages
:
Option
<
ResolvedVc
<
Glob
>
>
,
pub
tree_shaking_mode
:
Option
<
TreeShakingMode
>
,
pub
tree_shaking_mode
:
Option
<
TreeShakingMode
>
,
/// Generate (non-emitted) output assets for static assets and externals, to facilitate
/// Generate (non-emitted) output assets for static assets and externals, to facilitate
...
@@ -269,3 +272,12 @@ impl ValueDefault for ModuleOptionsContext {
...
@@ -269,3 +272,12 @@ impl ValueDefault for ModuleOptionsContext {
Self
::
cell
(
Default
::
default
())
Self
::
cell
(
Default
::
default
())
}
}
}
}
pub
fn
package_list_to_glob
(
pkgs
:
Vec
<
RcStr
>
)
->
Vc
<
Glob
>
{
let
mut
globs
=
String
::
new
();
globs
.push_str
(
"**/node_modules/{"
);
globs
.push_str
(
&
pkgs
.join
(
","
));
globs
.push_str
(
"}/**"
);
Glob
::
new
(
globs
.into
(),
GlobOptions
::
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