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