Unverified Commit f7b7f3c1 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: add NEXT_TURBOPACK_WRITE_ROUTES_HASHES_MANIFEST to write hashes into manifest (#86257)

### What?

Add an env var to write route hashes into a diagnostics file.
parent 2d01e08e
...@@ -4269,6 +4269,7 @@ dependencies = [ ...@@ -4269,6 +4269,7 @@ dependencies = [
"turbo-tasks-backend", "turbo-tasks-backend",
"turbo-tasks-env", "turbo-tasks-env",
"turbo-tasks-fs", "turbo-tasks-fs",
"turbo-tasks-hash",
"turbo-tasks-malloc", "turbo-tasks-malloc",
"turbo-unix-path", "turbo-unix-path",
"turbopack", "turbopack",
......
...@@ -21,6 +21,7 @@ use next_api::{ ...@@ -21,6 +21,7 @@ use next_api::{
ProjectOptions, WatchOptions, ProjectOptions, WatchOptions,
}, },
route::Endpoint, route::Endpoint,
routes_hashes_manifest::routes_hashes_manifest_asset_if_enabled,
}; };
use next_core::tracing_presets::{ use next_core::tracing_presets::{
TRACING_NEXT_OVERVIEW_TARGETS, TRACING_NEXT_TARGETS, TRACING_NEXT_TURBO_TASKS_TARGETS, TRACING_NEXT_OVERVIEW_TARGETS, TRACING_NEXT_TARGETS, TRACING_NEXT_TURBO_TASKS_TARGETS,
...@@ -175,6 +176,9 @@ pub struct NapiProjectOptions { ...@@ -175,6 +176,9 @@ pub struct NapiProjectOptions {
/// debugging/profiling purposes. /// debugging/profiling purposes.
pub no_mangling: bool, pub no_mangling: bool,
/// Whether to write the route hashes manifest.
pub write_routes_hashes_manifest: bool,
/// The version of Node.js that is available/currently running. /// The version of Node.js that is available/currently running.
pub current_node_js_version: RcStr, pub current_node_js_version: RcStr,
} }
...@@ -220,6 +224,9 @@ pub struct NapiPartialProjectOptions { ...@@ -220,6 +224,9 @@ pub struct NapiPartialProjectOptions {
/// The browserslist query to use for targeting browsers. /// The browserslist query to use for targeting browsers.
pub browserslist_query: Option<RcStr>, pub browserslist_query: Option<RcStr>,
/// Whether to write the route hashes manifest.
pub write_routes_hashes_manifest: Option<bool>,
/// When the code is minified, this opts out of the default mangling of /// When the code is minified, this opts out of the default mangling of
/// local names for variables, functions etc., which can be useful for /// local names for variables, functions etc., which can be useful for
/// debugging/profiling purposes. /// debugging/profiling purposes.
...@@ -277,6 +284,7 @@ impl From<NapiProjectOptions> for ProjectOptions { ...@@ -277,6 +284,7 @@ impl From<NapiProjectOptions> for ProjectOptions {
preview_props, preview_props,
browserslist_query, browserslist_query,
no_mangling, no_mangling,
write_routes_hashes_manifest,
current_node_js_version, current_node_js_version,
} = val; } = val;
ProjectOptions { ProjectOptions {
...@@ -292,6 +300,7 @@ impl From<NapiProjectOptions> for ProjectOptions { ...@@ -292,6 +300,7 @@ impl From<NapiProjectOptions> for ProjectOptions {
preview_props: preview_props.into(), preview_props: preview_props.into(),
browserslist_query, browserslist_query,
no_mangling, no_mangling,
write_routes_hashes_manifest,
current_node_js_version, current_node_js_version,
} }
} }
...@@ -312,6 +321,7 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions { ...@@ -312,6 +321,7 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions {
preview_props, preview_props,
browserslist_query, browserslist_query,
no_mangling, no_mangling,
write_routes_hashes_manifest,
} = val; } = val;
PartialProjectOptions { PartialProjectOptions {
root_path, root_path,
...@@ -326,6 +336,7 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions { ...@@ -326,6 +336,7 @@ impl From<NapiPartialProjectOptions> for PartialProjectOptions {
preview_props: preview_props.map(|props| props.into()), preview_props: preview_props.map(|props| props.into()),
browserslist_query, browserslist_query,
no_mangling, no_mangling,
write_routes_hashes_manifest,
} }
} }
} }
...@@ -1057,12 +1068,15 @@ async fn output_assets_operation( ...@@ -1057,12 +1068,15 @@ async fn output_assets_operation(
let nft = next_server_nft_assets(project).await?; let nft = next_server_nft_assets(project).await?;
let routes_hashes_manifest = routes_hashes_manifest_asset_if_enabled(project).await?;
whole_app_module_graphs.as_side_effect().await?; whole_app_module_graphs.as_side_effect().await?;
Ok(Vc::cell( Ok(Vc::cell(
output_assets output_assets
.into_iter() .into_iter()
.chain(nft.iter().copied()) .chain(nft.iter().copied())
.chain(routes_hashes_manifest.iter().copied())
.collect(), .collect(),
)) ))
} }
......
...@@ -28,6 +28,7 @@ swc_core = { workspace = true } ...@@ -28,6 +28,7 @@ swc_core = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
turbo-rcstr = { workspace = true } turbo-rcstr = { workspace = true }
turbo-tasks = { workspace = true } turbo-tasks = { workspace = true }
turbo-tasks-hash = { workspace = true }
turbo-tasks-env = { workspace = true } turbo-tasks-env = { workspace = true }
turbo-tasks-fs = { workspace = true } turbo-tasks-fs = { workspace = true }
turbo-unix-path = { workspace = true } turbo-unix-path = { workspace = true }
......
...@@ -21,6 +21,7 @@ mod pages; ...@@ -21,6 +21,7 @@ mod pages;
pub mod paths; pub mod paths;
pub mod project; pub mod project;
pub mod route; pub mod route;
pub mod routes_hashes_manifest;
mod server_actions; mod server_actions;
mod versioned_content_map; mod versioned_content_map;
mod webpack_stats; mod webpack_stats;
...@@ -1713,7 +1713,11 @@ impl Endpoint for PageEndpoint { ...@@ -1713,7 +1713,11 @@ impl Endpoint for PageEndpoint {
async fn module_graphs(self: Vc<Self>) -> Result<Vc<ModuleGraphs>> { async fn module_graphs(self: Vc<Self>) -> Result<Vc<ModuleGraphs>> {
let client_module_graph = self.client_module_graph().to_resolved().await?; let client_module_graph = self.client_module_graph().to_resolved().await?;
let ssr_module_graph = self.ssr_module_graph().to_resolved().await?; let ssr_module_graph = self.ssr_module_graph().to_resolved().await?;
Ok(Vc::cell(vec![client_module_graph, ssr_module_graph])) Ok(Vc::cell(if client_module_graph != ssr_module_graph {
vec![client_module_graph, ssr_module_graph]
} else {
vec![ssr_module_graph]
}))
} }
} }
......
...@@ -189,6 +189,9 @@ pub struct ProjectOptions { ...@@ -189,6 +189,9 @@ pub struct ProjectOptions {
/// debugging/profiling purposes. /// debugging/profiling purposes.
pub no_mangling: bool, pub no_mangling: bool,
/// Whether to write the route hashes manifest.
pub write_routes_hashes_manifest: bool,
/// The version of Node.js that is available/currently running. /// The version of Node.js that is available/currently running.
pub current_node_js_version: RcStr, pub current_node_js_version: RcStr,
} }
...@@ -237,6 +240,9 @@ pub struct PartialProjectOptions { ...@@ -237,6 +240,9 @@ pub struct PartialProjectOptions {
/// local names for variables, functions etc., which can be useful for /// local names for variables, functions etc., which can be useful for
/// debugging/profiling purposes. /// debugging/profiling purposes.
pub no_mangling: Option<bool>, pub no_mangling: Option<bool>,
/// Whether to write the route hashes manifest.
pub write_routes_hashes_manifest: Option<bool>,
} }
#[derive( #[derive(
...@@ -357,6 +363,7 @@ impl ProjectContainer { ...@@ -357,6 +363,7 @@ impl ProjectContainer {
preview_props, preview_props,
browserslist_query, browserslist_query,
no_mangling, no_mangling,
write_routes_hashes_manifest,
} = options; } = options;
let resolved_self = self.to_resolved().await?; let resolved_self = self.to_resolved().await?;
...@@ -404,6 +411,9 @@ impl ProjectContainer { ...@@ -404,6 +411,9 @@ impl ProjectContainer {
if let Some(no_mangling) = no_mangling { if let Some(no_mangling) = no_mangling {
new_options.no_mangling = no_mangling; new_options.no_mangling = no_mangling;
} }
if let Some(write_routes_hashes_manifest) = write_routes_hashes_manifest {
new_options.write_routes_hashes_manifest = write_routes_hashes_manifest;
}
// TODO: Handle mode switch, should prevent mode being switched. // TODO: Handle mode switch, should prevent mode being switched.
let watch = new_options.watch; let watch = new_options.watch;
...@@ -468,6 +478,7 @@ impl ProjectContainer { ...@@ -468,6 +478,7 @@ impl ProjectContainer {
let preview_props; let preview_props;
let browserslist_query; let browserslist_query;
let no_mangling; let no_mangling;
let write_routes_hashes_manifest;
let current_node_js_version; let current_node_js_version;
{ {
let options = self.options_state.get(); let options = self.options_state.get();
...@@ -491,6 +502,7 @@ impl ProjectContainer { ...@@ -491,6 +502,7 @@ impl ProjectContainer {
preview_props = options.preview_props.clone(); preview_props = options.preview_props.clone();
browserslist_query = options.browserslist_query.clone(); browserslist_query = options.browserslist_query.clone();
no_mangling = options.no_mangling; no_mangling = options.no_mangling;
write_routes_hashes_manifest = options.write_routes_hashes_manifest;
current_node_js_version = options.current_node_js_version.clone(); current_node_js_version = options.current_node_js_version.clone();
} }
...@@ -516,6 +528,7 @@ impl ProjectContainer { ...@@ -516,6 +528,7 @@ impl ProjectContainer {
encryption_key, encryption_key,
preview_props, preview_props,
no_mangling, no_mangling,
write_routes_hashes_manifest,
current_node_js_version, current_node_js_version,
} }
.cell()) .cell())
...@@ -603,6 +616,9 @@ pub struct Project { ...@@ -603,6 +616,9 @@ pub struct Project {
/// debugging/profiling purposes. /// debugging/profiling purposes.
no_mangling: bool, no_mangling: bool,
/// Whether to write the route hashes manifest.
write_routes_hashes_manifest: bool,
current_node_js_version: RcStr, current_node_js_version: RcStr,
} }
...@@ -823,6 +839,11 @@ impl Project { ...@@ -823,6 +839,11 @@ impl Project {
Ok(Vc::cell(self.watch.enable)) Ok(Vc::cell(self.watch.enable))
} }
#[turbo_tasks::function]
pub(super) fn should_write_routes_hashes_manifest(&self) -> Result<Vc<bool>> {
Ok(Vc::cell(self.write_routes_hashes_manifest))
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub(super) async fn per_page_module_graph(&self) -> Result<Vc<bool>> { pub(super) async fn per_page_module_graph(&self) -> Result<Vc<bool>> {
Ok(Vc::cell(*self.mode.await? == NextMode::Development)) Ok(Vc::cell(*self.mode.await? == NextMode::Development))
......
This diff is collapsed.
...@@ -182,6 +182,7 @@ fn main() { ...@@ -182,6 +182,7 @@ fn main() {
Safari versions, last 1 Edge versions" Safari versions, last 1 Edge versions"
.into(), .into(),
no_mangling: false, no_mangling: false,
write_routes_hashes_manifest: false,
current_node_js_version: rcstr!("18.0.0"), current_node_js_version: rcstr!("18.0.0"),
}; };
......
...@@ -16,6 +16,7 @@ use turbopack_core::{ ...@@ -16,6 +16,7 @@ use turbopack_core::{
output::OutputAssetsReference, output::OutputAssetsReference,
reference::{ModuleReference, ModuleReferences}, reference::{ModuleReference, ModuleReferences},
resolve::ModuleResolveResult, resolve::ModuleResolveResult,
source::OptionSource,
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
chunk::{ chunk::{
...@@ -62,6 +63,11 @@ impl Module for HmrEntryModule { ...@@ -62,6 +63,11 @@ impl Module for HmrEntryModule {
hmr_entry_point_base_ident().with_asset(rcstr!("ENTRY"), *self.ident) hmr_entry_point_base_ident().with_asset(rcstr!("ENTRY"), *self.ident)
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
Ok(Vc::cell(vec![ResolvedVc::upcast( Ok(Vc::cell(vec![ResolvedVc::upcast(
......
use anyhow::{Result, bail}; use anyhow::Result;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, ValueToString, Vc}; use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::FileContent;
use turbopack::css::chunk::CssChunkPlaceable; use turbopack::css::chunk::CssChunkPlaceable;
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
...@@ -9,6 +10,7 @@ use turbopack_core::{ ...@@ -9,6 +10,7 @@ use turbopack_core::{
module::Module, module::Module,
reference::{ModuleReference, ModuleReferences}, reference::{ModuleReference, ModuleReferences},
resolve::ModuleResolveResult, resolve::ModuleResolveResult,
source::OptionSource,
}; };
/// A [`CssClientReferenceModule`] is a marker module used to indicate which /// A [`CssClientReferenceModule`] is a marker module used to indicate which
...@@ -40,6 +42,11 @@ impl Module for CssClientReferenceModule { ...@@ -40,6 +42,11 @@ impl Module for CssClientReferenceModule {
.with_modifier(rcstr!("css client reference")) .with_modifier(rcstr!("css client reference"))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> { async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
let CssClientReferenceModule { client_module, .. } = &*self.await?; let CssClientReferenceModule { client_module, .. } = &*self.await?;
...@@ -55,9 +62,14 @@ impl Module for CssClientReferenceModule { ...@@ -55,9 +62,14 @@ impl Module for CssClientReferenceModule {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl Asset for CssClientReferenceModule { impl Asset for CssClientReferenceModule {
#[turbo_tasks::function] #[turbo_tasks::function]
fn content(&self) -> Result<Vc<AssetContent>> { fn content(&self) -> Vc<AssetContent> {
// The client reference asset only serves as a marker asset. AssetContent::File(
bail!("CssClientReferenceModule has no content") FileContent::Content(
"// This is a marker module for Next.js client CSS references.".into(),
)
.resolved_cell(),
)
.cell()
} }
} }
......
...@@ -4,7 +4,7 @@ use anyhow::{Context, Result, bail}; ...@@ -4,7 +4,7 @@ use anyhow::{Context, Result, bail};
use indoc::writedoc; use indoc::writedoc;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{IntoTraitRef, ResolvedVc, ValueToString, Vc}; use turbo_tasks::{IntoTraitRef, ResolvedVc, ValueToString, Vc};
use turbo_tasks_fs::File; use turbo_tasks_fs::{File, FileContent};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ chunk::{
...@@ -20,6 +20,7 @@ use turbopack_core::{ ...@@ -20,6 +20,7 @@ use turbopack_core::{
reference::{ModuleReference, ModuleReferences}, reference::{ModuleReference, ModuleReferences},
reference_type::ReferenceType, reference_type::ReferenceType,
resolve::ModuleResolveResult, resolve::ModuleResolveResult,
source::OptionSource,
virtual_source::VirtualSource, virtual_source::VirtualSource,
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
...@@ -197,6 +198,11 @@ impl Module for EcmascriptClientReferenceModule { ...@@ -197,6 +198,11 @@ impl Module for EcmascriptClientReferenceModule {
.with_layer(self.server_asset_context.into_trait_ref().await?.layer())) .with_layer(self.server_asset_context.into_trait_ref().await?.layer()))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> { async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
let EcmascriptClientReferenceModule { let EcmascriptClientReferenceModule {
...@@ -240,8 +246,12 @@ impl Module for EcmascriptClientReferenceModule { ...@@ -240,8 +246,12 @@ impl Module for EcmascriptClientReferenceModule {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl Asset for EcmascriptClientReferenceModule { impl Asset for EcmascriptClientReferenceModule {
#[turbo_tasks::function] #[turbo_tasks::function]
fn content(&self) -> Result<Vc<AssetContent>> { fn content(&self) -> Vc<AssetContent> {
bail!("client reference module asset has no content") AssetContent::File(
FileContent::Content("// This is a proxy module for Next.js client references.".into())
.resolved_cell(),
)
.cell()
} }
} }
......
use std::collections::BTreeMap; use std::collections::BTreeMap;
use anyhow::{Result, bail}; use anyhow::Result;
use indoc::formatdoc; use indoc::formatdoc;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, Vc}; use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::FileContent;
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt}, chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt},
...@@ -13,6 +14,7 @@ use turbopack_core::{ ...@@ -13,6 +14,7 @@ use turbopack_core::{
output::OutputAssetsReference, output::OutputAssetsReference,
reference::{ModuleReferences, SingleChunkableModuleReference}, reference::{ModuleReferences, SingleChunkableModuleReference},
resolve::ExportUsage, resolve::ExportUsage,
source::OptionSource,
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
chunk::{ chunk::{
...@@ -52,6 +54,11 @@ impl Module for NextDynamicEntryModule { ...@@ -52,6 +54,11 @@ impl Module for NextDynamicEntryModule {
.with_modifier(rcstr!("next/dynamic entry")) .with_modifier(rcstr!("next/dynamic entry"))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
Ok(Vc::cell(vec![ResolvedVc::upcast( Ok(Vc::cell(vec![ResolvedVc::upcast(
...@@ -69,8 +76,12 @@ impl Module for NextDynamicEntryModule { ...@@ -69,8 +76,12 @@ impl Module for NextDynamicEntryModule {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl Asset for NextDynamicEntryModule { impl Asset for NextDynamicEntryModule {
#[turbo_tasks::function] #[turbo_tasks::function]
fn content(&self) -> Result<Vc<AssetContent>> { fn content(&self) -> Vc<AssetContent> {
bail!("Next.js Server Component module has no content") AssetContent::File(
FileContent::Content("// This is a marker module for Next.js dynamic.".into())
.resolved_cell(),
)
.cell()
} }
} }
......
use std::collections::BTreeMap; use std::collections::BTreeMap;
use anyhow::{Result, bail}; use anyhow::Result;
use indoc::formatdoc; use indoc::formatdoc;
use turbo_rcstr::rcstr; use turbo_rcstr::rcstr;
use turbo_tasks::{ResolvedVc, Vc}; use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::{FileContent, FileSystemPath};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt}, chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt},
...@@ -13,6 +13,7 @@ use turbopack_core::{ ...@@ -13,6 +13,7 @@ use turbopack_core::{
module_graph::ModuleGraph, module_graph::ModuleGraph,
output::OutputAssetsReference, output::OutputAssetsReference,
reference::ModuleReferences, reference::ModuleReferences,
source::OptionSource,
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
chunk::{ chunk::{
...@@ -53,6 +54,11 @@ impl Module for NextServerComponentModule { ...@@ -53,6 +54,11 @@ impl Module for NextServerComponentModule {
.with_modifier(rcstr!("Next.js Server Component")) .with_modifier(rcstr!("Next.js Server Component"))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
Ok(Vc::cell(vec![ResolvedVc::upcast( Ok(Vc::cell(vec![ResolvedVc::upcast(
...@@ -66,8 +72,14 @@ impl Module for NextServerComponentModule { ...@@ -66,8 +72,14 @@ impl Module for NextServerComponentModule {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl Asset for NextServerComponentModule { impl Asset for NextServerComponentModule {
#[turbo_tasks::function] #[turbo_tasks::function]
fn content(&self) -> Result<Vc<AssetContent>> { fn content(&self) -> Vc<AssetContent> {
bail!("Next.js Server Component module has no content") AssetContent::File(
FileContent::Content(
"// This is a marker module for Next.js server components.".into(),
)
.resolved_cell(),
)
.cell()
} }
} }
......
use std::collections::BTreeMap; use std::collections::BTreeMap;
use anyhow::{Result, bail}; use anyhow::Result;
use indoc::formatdoc; use indoc::formatdoc;
use turbo_rcstr::rcstr; use turbo_rcstr::rcstr;
use turbo_tasks::{ResolvedVc, Vc}; use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::{FileContent, FileSystemPath};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt}, chunk::{ChunkItem, ChunkType, ChunkableModule, ChunkingContext, ModuleChunkItemIdExt},
...@@ -13,6 +13,7 @@ use turbopack_core::{ ...@@ -13,6 +13,7 @@ use turbopack_core::{
module_graph::ModuleGraph, module_graph::ModuleGraph,
output::OutputAssetsReference, output::OutputAssetsReference,
reference::ModuleReferences, reference::ModuleReferences,
source::OptionSource,
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
chunk::{ chunk::{
...@@ -53,6 +54,11 @@ impl Module for NextServerUtilityModule { ...@@ -53,6 +54,11 @@ impl Module for NextServerUtilityModule {
.with_modifier(rcstr!("Next.js server utility")) .with_modifier(rcstr!("Next.js server utility"))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
Ok(Vc::cell(vec![ResolvedVc::upcast( Ok(Vc::cell(vec![ResolvedVc::upcast(
...@@ -66,8 +72,12 @@ impl Module for NextServerUtilityModule { ...@@ -66,8 +72,12 @@ impl Module for NextServerUtilityModule {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl Asset for NextServerUtilityModule { impl Asset for NextServerUtilityModule {
#[turbo_tasks::function] #[turbo_tasks::function]
fn content(&self) -> Result<Vc<AssetContent>> { fn content(&self) -> Vc<AssetContent> {
bail!("Next.js server utility module has no content") AssetContent::File(
FileContent::Content("// This is a marker module for Next.js server utilities.".into())
.resolved_cell(),
)
.cell()
} }
} }
......
...@@ -22,7 +22,7 @@ use turbopack_core::{ ...@@ -22,7 +22,7 @@ use turbopack_core::{
module_graph::ModuleGraph, module_graph::ModuleGraph,
output::OutputAssetsReference, output::OutputAssetsReference,
resolve::ModulePart, resolve::ModulePart,
source::Source, source::{OptionSource, Source},
source_map::GenerateSourceMap, source_map::GenerateSourceMap,
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
...@@ -93,6 +93,11 @@ impl Module for RawEcmascriptModule { ...@@ -93,6 +93,11 @@ impl Module for RawEcmascriptModule {
self.source.ident().with_modifier(rcstr!("raw")) self.source.ident().with_modifier(rcstr!("raw"))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource> {
Vc::cell(Some(self.source))
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn is_marked_as_side_effect_free( fn is_marked_as_side_effect_free(
self: Vc<Self>, self: Vc<Self>,
......
...@@ -155,6 +155,8 @@ export interface NapiProjectOptions { ...@@ -155,6 +155,8 @@ export interface NapiProjectOptions {
* debugging/profiling purposes. * debugging/profiling purposes.
*/ */
noMangling: boolean noMangling: boolean
/** Whether to write the route hashes manifest. */
writeRoutesHashesManifest: boolean
/** The version of Node.js that is available/currently running. */ /** The version of Node.js that is available/currently running. */
currentNodeJsVersion: RcStr currentNodeJsVersion: RcStr
} }
...@@ -193,6 +195,8 @@ export interface NapiPartialProjectOptions { ...@@ -193,6 +195,8 @@ export interface NapiPartialProjectOptions {
previewProps?: NapiDraftModeOptions previewProps?: NapiDraftModeOptions
/** The browserslist query to use for targeting browsers. */ /** The browserslist query to use for targeting browsers. */
browserslistQuery?: RcStr browserslistQuery?: RcStr
/** Whether to write the route hashes manifest. */
writeRoutesHashesManifest?: boolean
/** /**
* When the code is minified, this opts out of the default mangling of * When the code is minified, this opts out of the default mangling of
* local names for variables, functions etc., which can be useful for * local names for variables, functions etc., which can be useful for
......
...@@ -75,6 +75,7 @@ export async function turbopackAnalyze( ...@@ -75,6 +75,7 @@ export async function turbopackAnalyze(
}, },
browserslistQuery: supportedBrowsers.join(', '), browserslistQuery: supportedBrowsers.join(', '),
noMangling, noMangling,
writeRoutesHashesManifest: false,
currentNodeJsVersion, currentNodeJsVersion,
}, },
{ {
......
...@@ -79,6 +79,8 @@ export async function turbopackBuild(): Promise<{ ...@@ -79,6 +79,8 @@ export async function turbopackBuild(): Promise<{
previewProps, previewProps,
browserslistQuery: supportedBrowsers.join(', '), browserslistQuery: supportedBrowsers.join(', '),
noMangling, noMangling,
writeRoutesHashesManifest:
!!process.env.NEXT_TURBOPACK_WRITE_ROUTES_HASHES_MANIFEST,
currentNodeJsVersion, currentNodeJsVersion,
}, },
{ {
......
...@@ -274,6 +274,7 @@ export async function createHotReloaderTurbopack( ...@@ -274,6 +274,7 @@ export async function createHotReloaderTurbopack(
previewProps: opts.fsChecker.prerenderManifest.preview, previewProps: opts.fsChecker.prerenderManifest.preview,
browserslistQuery: supportedBrowsers.join(', '), browserslistQuery: supportedBrowsers.join(', '),
noMangling: false, noMangling: false,
writeRoutesHashesManifest: false,
currentNodeJsVersion, currentNodeJsVersion,
}, },
{ {
......
...@@ -229,6 +229,7 @@ async function main() { ...@@ -229,6 +229,7 @@ async function main() {
}, },
browserslistQuery: 'last 2 versions', browserslistQuery: 'last 2 versions',
noMangling: false, noMangling: false,
writeRoutesHashesManifest: false,
currentNodeJsVersion: '18.0.0', currentNodeJsVersion: '18.0.0',
}); });
...@@ -386,6 +387,7 @@ describe('next.rs api', () => { ...@@ -386,6 +387,7 @@ describe('next.rs api', () => {
}, },
browserslistQuery: 'last 2 versions', browserslistQuery: 'last 2 versions',
noMangling: false, noMangling: false,
writeRoutesHashesManifest: false,
currentNodeJsVersion: '18.0.0', currentNodeJsVersion: '18.0.0',
}) })
projectUpdateSubscription = filterMapAsyncIterator( projectUpdateSubscription = filterMapAsyncIterator(
......
...@@ -1847,7 +1847,7 @@ impl FileContent { ...@@ -1847,7 +1847,7 @@ impl FileContent {
} }
bitflags! { bitflags! {
#[derive(Default, Serialize, Deserialize, TraceRawVcs, NonLocalValue)] #[derive(Default, Serialize, Deserialize, TraceRawVcs, NonLocalValue, DeterministicHash)]
pub struct LinkType: u8 { pub struct LinkType: u8 {
const DIRECTORY = 0b00000001; const DIRECTORY = 0b00000001;
const ABSOLUTE = 0b00000010; const ABSOLUTE = 0b00000010;
......
...@@ -4,6 +4,7 @@ use turbo_tasks::{ResolvedVc, Vc}; ...@@ -4,6 +4,7 @@ use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::{ use turbo_tasks_fs::{
FileContent, FileJsonContent, FileLinesContent, FileSystemPath, LinkContent, LinkType, FileContent, FileJsonContent, FileLinesContent, FileSystemPath, LinkContent, LinkType,
}; };
use turbo_tasks_hash::Xxh3Hash64Hasher;
use crate::version::{VersionedAssetContent, VersionedContent}; use crate::version::{VersionedAssetContent, VersionedContent};
...@@ -110,4 +111,18 @@ impl AssetContent { ...@@ -110,4 +111,18 @@ impl AssetContent {
} }
Ok(()) Ok(())
} }
#[turbo_tasks::function]
pub async fn hash(&self) -> Result<Vc<u64>> {
match self {
AssetContent::File(content) => Ok(content.hash()),
AssetContent::Redirect { target, link_type } => {
use turbo_tasks_hash::DeterministicHash;
let mut hasher = Xxh3Hash64Hasher::new();
target.deterministic_hash(&mut hasher);
link_type.deterministic_hash(&mut hasher);
Ok(Vc::cell(hasher.finish()))
}
}
}
} }
...@@ -2,7 +2,7 @@ use turbo_rcstr::RcStr; ...@@ -2,7 +2,7 @@ use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, TaskInput, ValueToString, Vc}; use turbo_tasks::{ResolvedVc, TaskInput, ValueToString, Vc};
use turbo_tasks_fs::glob::Glob; use turbo_tasks_fs::glob::Glob;
use crate::{asset::Asset, ident::AssetIdent, reference::ModuleReferences}; use crate::{asset::Asset, ident::AssetIdent, reference::ModuleReferences, source::OptionSource};
#[derive(Clone, Copy, Debug, TaskInput, Hash)] #[derive(Clone, Copy, Debug, TaskInput, Hash)]
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
...@@ -27,6 +27,10 @@ pub trait Module: Asset { ...@@ -27,6 +27,10 @@ pub trait Module: Asset {
self.ident().to_string() self.ident().to_string()
} }
/// The source of the [Module].
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource>;
/// Other [Module]s or [OutputAsset]s referenced from this [Module]. /// Other [Module]s or [OutputAsset]s referenced from this [Module].
// TODO refactor to avoid returning [OutputAsset]s here // TODO refactor to avoid returning [OutputAsset]s here
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -859,11 +859,15 @@ impl ModuleGraphRef { ...@@ -859,11 +859,15 @@ impl ModuleGraphRef {
}) })
}) })
else { else {
bail!("Couldn't find entry module in module graph"); bail!("Couldn't find entry module {entry:?} in module graph");
}; };
Ok(idx) Ok(idx)
} }
pub fn entries(&self) -> impl Iterator<Item = ChunkGroupEntry> + '_ {
self.graphs.iter().flat_map(|g| g.entries.iter().cloned())
}
fn get_node(&self, entry: GraphNodeIndex) -> Result<&SingleModuleGraphNode> { fn get_node(&self, entry: GraphNodeIndex) -> Result<&SingleModuleGraphNode> {
let graph = &self.graphs[entry.graph_idx()]; let graph = &self.graphs[entry.graph_idx()];
graph graph
...@@ -1850,6 +1854,11 @@ pub mod tests { ...@@ -1850,6 +1854,11 @@ pub mod tests {
AssetIdent::from_path(self.path.clone()) AssetIdent::from_path(self.path.clone())
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<crate::source::OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
let repo = self.repo.await?; let repo = self.repo.await?;
......
...@@ -14,7 +14,7 @@ use crate::{ ...@@ -14,7 +14,7 @@ use crate::{
raw_module::RawModule, raw_module::RawModule,
reference::{ModuleReferences, TracedModuleReference}, reference::{ModuleReferences, TracedModuleReference},
resolve::pattern::{Pattern, PatternMatch, read_matches}, resolve::pattern::{Pattern, PatternMatch, read_matches},
source::Source, source::{OptionSource, Source},
}; };
/// A module corresponding to `.node` files. /// A module corresponding to `.node` files.
...@@ -38,6 +38,11 @@ impl Module for NodeAddonModule { ...@@ -38,6 +38,11 @@ impl Module for NodeAddonModule {
self.source.ident().with_modifier(rcstr!("node addon")) self.source.ident().with_modifier(rcstr!("node addon"))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource> {
Vc::cell(Some(self.source))
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
static SHARP_BINARY_REGEX: LazyLock<Regex> = static SHARP_BINARY_REGEX: LazyLock<Regex> =
......
...@@ -4,7 +4,7 @@ use crate::{ ...@@ -4,7 +4,7 @@ use crate::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
ident::AssetIdent, ident::AssetIdent,
module::Module, module::Module,
source::Source, source::{OptionSource, Source},
}; };
/// A module where source code doesn't need to be parsed but can be usd as is. /// A module where source code doesn't need to be parsed but can be usd as is.
...@@ -20,6 +20,11 @@ impl Module for RawModule { ...@@ -20,6 +20,11 @@ impl Module for RawModule {
fn ident(&self) -> Vc<AssetIdent> { fn ident(&self) -> Vc<AssetIdent> {
self.source.ident() self.source.ident()
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource> {
Vc::cell(Some(self.source))
}
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
......
...@@ -14,7 +14,7 @@ use turbopack_core::{ ...@@ -14,7 +14,7 @@ use turbopack_core::{
reference::{ModuleReference, ModuleReferences}, reference::{ModuleReference, ModuleReferences},
reference_type::ImportContext, reference_type::ImportContext,
resolve::origin::ResolveOrigin, resolve::origin::ResolveOrigin,
source::Source, source::{OptionSource, Source},
source_map::GenerateSourceMap, source_map::GenerateSourceMap,
}; };
...@@ -137,6 +137,11 @@ impl Module for CssModuleAsset { ...@@ -137,6 +137,11 @@ impl Module for CssModuleAsset {
Ok(ident) Ok(ident)
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource> {
Vc::cell(Some(self.source))
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> { async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
let result = self.parse_css().await?; let result = self.parse_css().await?;
......
use std::{fmt::Write, sync::Arc}; use std::{fmt::Write, sync::Arc};
use anyhow::{Context, Result, bail}; use anyhow::{Context, Result};
use indoc::formatdoc; use indoc::formatdoc;
use lightningcss::css_modules::CssModuleReference; use lightningcss::css_modules::CssModuleReference;
use swc_core::common::{BytePos, FileName, LineCol, SourceMap}; use swc_core::common::{BytePos, FileName, LineCol, SourceMap};
...@@ -22,7 +22,7 @@ use turbopack_core::{ ...@@ -22,7 +22,7 @@ use turbopack_core::{
reference::{ModuleReference, ModuleReferences}, reference::{ModuleReference, ModuleReferences},
reference_type::{CssReferenceSubType, ReferenceType}, reference_type::{CssReferenceSubType, ReferenceType},
resolve::{origin::ResolveOrigin, parse::Request}, resolve::{origin::ResolveOrigin, parse::Request},
source::Source, source::{OptionSource, Source},
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
chunk::{ chunk::{
...@@ -72,6 +72,11 @@ impl Module for ModuleCssAsset { ...@@ -72,6 +72,11 @@ impl Module for ModuleCssAsset {
.with_layer(self.asset_context.into_trait_ref().await?.layer())) .with_layer(self.asset_context.into_trait_ref().await?.layer()))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource> {
Vc::cell(Some(self.source))
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> { async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
// The inner reference must come last so it is loaded as the last in the // The inner reference must come last so it is loaded as the last in the
...@@ -111,8 +116,8 @@ impl Module for ModuleCssAsset { ...@@ -111,8 +116,8 @@ impl Module for ModuleCssAsset {
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl Asset for ModuleCssAsset { impl Asset for ModuleCssAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
fn content(&self) -> Result<Vc<AssetContent>> { fn content(&self) -> Vc<AssetContent> {
bail!("CSS module asset has no contents") self.source.content()
} }
} }
......
...@@ -50,6 +50,11 @@ impl Module for AsyncLoaderModule { ...@@ -50,6 +50,11 @@ impl Module for AsyncLoaderModule {
Self::asset_ident_for(*self.inner) Self::asset_ident_for(*self.inner)
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> { async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
Ok(Vc::cell(vec![ResolvedVc::upcast( Ok(Vc::cell(vec![ResolvedVc::upcast(
......
...@@ -45,6 +45,11 @@ impl Module for InlinedBytesJsModule { ...@@ -45,6 +45,11 @@ impl Module for InlinedBytesJsModule {
.with_modifier(rcstr!("static bytes in ecmascript")) .with_modifier(rcstr!("static bytes in ecmascript"))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(Some(self.source))
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn is_marked_as_side_effect_free( fn is_marked_as_side_effect_free(
self: Vc<Self>, self: Vc<Self>,
......
...@@ -737,6 +737,11 @@ impl Module for EcmascriptModuleAsset { ...@@ -737,6 +737,11 @@ impl Module for EcmascriptModuleAsset {
Ok(AssetIdent::new(ident)) Ok(AssetIdent::new(ident))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(Some(self.source))
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> { fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
Ok(self.analyze().references()) Ok(self.analyze().references())
......
...@@ -125,6 +125,11 @@ impl Module for ManifestAsyncModule { ...@@ -125,6 +125,11 @@ impl Module for ManifestAsyncModule {
.with_modifier(manifest_chunk_reference_description()) .with_modifier(manifest_chunk_reference_description())
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> { async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
let assets = self.chunk_group().expand_all_assets().await?; let assets = self.chunk_group().expand_all_assets().await?;
......
...@@ -77,6 +77,11 @@ impl Module for MergedEcmascriptModule { ...@@ -77,6 +77,11 @@ impl Module for MergedEcmascriptModule {
self.entry_points.first().unwrap().ident() self.entry_points.first().unwrap().ident()
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> { async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
panic!("references() should not be called"); panic!("references() should not be called");
......
...@@ -225,6 +225,11 @@ impl Module for CachedExternalModule { ...@@ -225,6 +225,11 @@ impl Module for CachedExternalModule {
.with_modifier(self.external_type.to_string().into())) .with_modifier(self.external_type.to_string().into()))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
Ok(match &self.analyze_mode { Ok(match &self.analyze_mode {
...@@ -455,6 +460,11 @@ impl Module for ModuleWithoutSelfAsync { ...@@ -455,6 +460,11 @@ impl Module for ModuleWithoutSelfAsync {
self.module.ident() self.module.ident()
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn references(&self) -> Vc<ModuleReferences> { fn references(&self) -> Vc<ModuleReferences> {
self.module.references() self.module.references()
......
...@@ -409,6 +409,11 @@ impl Module for RequireContextAsset { ...@@ -409,6 +409,11 @@ impl Module for RequireContextAsset {
.with_modifier(modifier(&self.dir, self.include_subdirs)) .with_modifier(modifier(&self.dir, self.include_subdirs))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(Some(self.source))
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
let map = &*self.map.await?; let map = &*self.map.await?;
......
...@@ -152,6 +152,11 @@ impl Module for EcmascriptModuleFacadeModule { ...@@ -152,6 +152,11 @@ impl Module for EcmascriptModuleFacadeModule {
self.module.ident().with_part(self.part.clone()) self.module.ident().with_part(self.part.clone())
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> { async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
let (part_references, esm_references) = self.await?.specific_references().await?; let (part_references, esm_references) = self.await?.specific_references().await?;
......
...@@ -50,6 +50,11 @@ impl Module for EcmascriptModuleLocalsModule { ...@@ -50,6 +50,11 @@ impl Module for EcmascriptModuleLocalsModule {
self.module.ident().with_part(ModulePart::locals()) self.module.ident().with_part(ModulePart::locals())
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn references(&self) -> Result<Vc<ModuleReferences>> { fn references(&self) -> Result<Vc<ModuleReferences>> {
let result = self.module.analyze(); let result = self.module.analyze();
......
...@@ -310,6 +310,11 @@ impl Module for EcmascriptModulePartAsset { ...@@ -310,6 +310,11 @@ impl Module for EcmascriptModulePartAsset {
self.full_module.ident().with_part(self.part.clone()) self.full_module.ident().with_part(self.part.clone())
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn is_self_async(self: Vc<Self>) -> Vc<bool> { fn is_self_async(self: Vc<Self>) -> Vc<bool> {
self.is_async_module() self.is_async_module()
......
use anyhow::Result; use anyhow::Result;
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc}; use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
use turbo_tasks_fs::glob::Glob; use turbo_tasks_fs::{FileContent, glob::Glob};
use turbopack_core::{ use turbopack_core::{
asset::{Asset, AssetContent}, asset::{Asset, AssetContent},
chunk::{ChunkableModule, ChunkingContext, EvaluatableAsset}, chunk::{ChunkableModule, ChunkingContext, EvaluatableAsset},
...@@ -73,6 +73,11 @@ impl Module for SideEffectsModule { ...@@ -73,6 +73,11 @@ impl Module for SideEffectsModule {
Ok(AssetIdent::new(ident)) Ok(AssetIdent::new(ident))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
let mut references = vec![]; let mut references = vec![];
...@@ -118,7 +123,14 @@ impl Module for SideEffectsModule { ...@@ -118,7 +123,14 @@ impl Module for SideEffectsModule {
impl Asset for SideEffectsModule { impl Asset for SideEffectsModule {
#[turbo_tasks::function] #[turbo_tasks::function]
fn content(&self) -> Vc<AssetContent> { fn content(&self) -> Vc<AssetContent> {
unreachable!("SideEffectsModule has no content") AssetContent::File(
FileContent::Content(
"// This is a proxy module for reexportings a module with additional side effects."
.into(),
)
.resolved_cell(),
)
.cell()
} }
} }
......
...@@ -48,6 +48,11 @@ impl Module for TsConfigModuleAsset { ...@@ -48,6 +48,11 @@ impl Module for TsConfigModuleAsset {
self.source.ident() self.source.ident()
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(Some(self.source))
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
let mut references = Vec::new(); let mut references = Vec::new();
......
...@@ -55,6 +55,11 @@ impl Module for WebpackModuleAsset { ...@@ -55,6 +55,11 @@ impl Module for WebpackModuleAsset {
self.source.ident().with_modifier(rcstr!("webpack")) self.source.ident().with_modifier(rcstr!("webpack"))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(Some(self.source))
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn references(&self) -> Vc<ModuleReferences> { fn references(&self) -> Vc<ModuleReferences> {
module_references(*self.source, *self.runtime, *self.transforms) module_references(*self.source, *self.runtime, *self.transforms)
......
...@@ -44,6 +44,11 @@ impl Module for WorkerLoaderModule { ...@@ -44,6 +44,11 @@ impl Module for WorkerLoaderModule {
Self::asset_ident_for(*self.inner) Self::asset_ident_for(*self.inner)
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(None)
}
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> { async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
Ok(Vc::cell(vec![ResolvedVc::upcast( Ok(Vc::cell(vec![ResolvedVc::upcast(
......
...@@ -53,6 +53,11 @@ impl Module for JsonModuleAsset { ...@@ -53,6 +53,11 @@ impl Module for JsonModuleAsset {
self.source.ident().with_modifier(rcstr!("json")) self.source.ident().with_modifier(rcstr!("json"))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(Some(self.source))
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn is_marked_as_side_effect_free( fn is_marked_as_side_effect_free(
self: Vc<Self>, self: Vc<Self>,
......
...@@ -47,6 +47,11 @@ impl Module for StaticUrlCssModule { ...@@ -47,6 +47,11 @@ impl Module for StaticUrlCssModule {
ident ident
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(Some(self.source))
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn is_marked_as_side_effect_free( fn is_marked_as_side_effect_free(
self: Vc<Self>, self: Vc<Self>,
......
...@@ -59,6 +59,11 @@ impl Module for StaticUrlJsModule { ...@@ -59,6 +59,11 @@ impl Module for StaticUrlJsModule {
ident ident
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<turbopack_core::source::OptionSource> {
Vc::cell(Some(self.source))
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn is_marked_as_side_effect_free( fn is_marked_as_side_effect_free(
self: Vc<Self>, self: Vc<Self>,
......
...@@ -16,7 +16,7 @@ use turbopack_core::{ ...@@ -16,7 +16,7 @@ use turbopack_core::{
reference::{ModuleReferences, SingleChunkableModuleReference}, reference::{ModuleReferences, SingleChunkableModuleReference},
reference_type::ReferenceType, reference_type::ReferenceType,
resolve::{ExportUsage, origin::ResolveOrigin, parse::Request}, resolve::{ExportUsage, origin::ResolveOrigin, parse::Request},
source::Source, source::{OptionSource, Source},
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
chunk::{ chunk::{
...@@ -130,6 +130,11 @@ impl Module for WebAssemblyModuleAsset { ...@@ -130,6 +130,11 @@ impl Module for WebAssemblyModuleAsset {
.with_layer(self.asset_context.into_trait_ref().await?.layer())) .with_layer(self.asset_context.into_trait_ref().await?.layer()))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource> {
Vc::cell(Some(ResolvedVc::upcast(self.source)))
}
#[turbo_tasks::function] #[turbo_tasks::function]
fn references(self: Vc<Self>) -> Vc<ModuleReferences> { fn references(self: Vc<Self>) -> Vc<ModuleReferences> {
self.loader().references() self.loader().references()
......
...@@ -9,7 +9,7 @@ use turbopack_core::{ ...@@ -9,7 +9,7 @@ use turbopack_core::{
module::Module, module::Module,
module_graph::ModuleGraph, module_graph::ModuleGraph,
output::{OutputAsset, OutputAssetsReference, OutputAssetsWithReferenced}, output::{OutputAsset, OutputAssetsReference, OutputAssetsWithReferenced},
source::Source, source::{OptionSource, Source},
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
chunk::{ chunk::{
...@@ -59,6 +59,11 @@ impl Module for RawWebAssemblyModuleAsset { ...@@ -59,6 +59,11 @@ impl Module for RawWebAssemblyModuleAsset {
.with_modifier(rcstr!("wasm raw")) .with_modifier(rcstr!("wasm raw"))
.with_layer(self.asset_context.into_trait_ref().await?.layer())) .with_layer(self.asset_context.into_trait_ref().await?.layer()))
} }
#[turbo_tasks::function]
fn source(&self) -> Vc<OptionSource> {
Vc::cell(Some(ResolvedVc::upcast(self.source)))
}
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
......
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