diff --git a/packages/next-swc/crates/next-core/src/server_render/nodejs_pool.rs b/packages/next-swc/crates/next-core/src/server_render/nodejs_pool.rs index 1b1f673ae0a3c..ba26f44a9a233 100644 --- a/packages/next-swc/crates/next-core/src/server_render/nodejs_pool.rs +++ b/packages/next-swc/crates/next-core/src/server_render/nodejs_pool.rs @@ -45,7 +45,7 @@ impl NodeJsPoolProcess { } fn start(mut cmd: Command) -> Result { - let mut child = cmd.spawn().with_context(|| format!("spawning node pool"))?; + let mut child = cmd.spawn().context("spawning node pool")?; let stdin = child.stdin.take().unwrap(); let mut stdout = BufReader::new(child.stdout.take().unwrap()); let mut bootstrap_log = Vec::new(); diff --git a/packages/next-swc/crates/next-core/src/web_entry_source.rs b/packages/next-swc/crates/next-core/src/web_entry_source.rs index 086b28eab36fe..b98f47ac7af0e 100644 --- a/packages/next-swc/crates/next-core/src/web_entry_source.rs +++ b/packages/next-swc/crates/next-core/src/web_entry_source.rs @@ -1,8 +1,7 @@ -use std::collections::HashMap; +use std::{collections::HashMap, future::IntoFuture}; use anyhow::{anyhow, Result}; -use futures::future::try_join_all; -use turbo_tasks::Value; +use turbo_tasks::{util::try_join_all, Value}; use turbo_tasks_fs::{FileSystemPathVc, FileSystemVc}; use turbopack::{ecmascript::EcmascriptModuleAssetVc, ModuleAssetContextVc}; use turbopack_core::{ @@ -12,7 +11,7 @@ use turbopack_core::{ }, context::AssetContextVc, environment::{BrowserEnvironment, EnvironmentIntention, EnvironmentVc, ExecutionEnvironment}, - source_asset::SourceAssetVc, + resolve::parse::RequestVc, transition::TransitionsByNameVc, }; use turbopack_dev_server::{ @@ -23,7 +22,7 @@ use turbopack_dev_server::{ #[turbo_tasks::function] pub async fn create_web_entry_source( root: FileSystemPathVc, - entry_paths: Vec, + entry_requests: Vec, dev_server_fs: FileSystemVc, eager_compile: bool, ) -> Result { @@ -52,9 +51,16 @@ pub async fn create_web_entry_source( } .into(); - let modules = entry_paths + let modules = try_join_all(entry_requests.into_iter().map(|r| { + context + .resolve_asset(context.context_path(), r, context.resolve_options()) + .primary_assets() + .into_future() + })) + .await?; + let modules = modules .into_iter() - .map(|p| context.process(SourceAssetVc::new(p).into())); + .flat_map(|assets| assets.iter().copied().collect::>()); let chunks = try_join_all(modules.map(|module| async move { if let Some(ecmascript) = EcmascriptModuleAssetVc::resolve_from(module).await? { Ok(ecmascript.as_evaluated_chunk(chunking_context.into())) diff --git a/packages/next-swc/crates/next-dev/src/lib.rs b/packages/next-swc/crates/next-dev/src/lib.rs index b34d464577b71..98a692fdc9dc7 100644 --- a/packages/next-swc/crates/next-dev/src/lib.rs +++ b/packages/next-swc/crates/next-dev/src/lib.rs @@ -5,11 +5,14 @@ use std::{net::IpAddr, path::MAIN_SEPARATOR, sync::Arc}; use anyhow::{anyhow, Context, Result}; use next_core::{create_server_rendered_source, create_web_entry_source}; -use turbo_tasks::{CollectiblesSource, TransientInstance, TurboTasks}; +use turbo_tasks::{CollectiblesSource, TransientInstance, TurboTasks, Value}; use turbo_tasks_fs::{DiskFileSystemVc, FileSystemPathVc, FileSystemVc}; use turbo_tasks_memory::MemoryBackend; use turbopack_cli_utils::issue::{group_and_display_issues, LogOptions, LogOptionsVc}; -use turbopack_core::issue::{IssueSeverity, IssueVc}; +use turbopack_core::{ + issue::{IssueSeverity, IssueVc}, + resolve::parse::RequestVc, +}; use turbopack_dev_server::{ fs::DevServerFileSystemVc, source::{combined::CombinedContentSource, router::RouterContentSource, ContentSourceVc}, @@ -22,7 +25,7 @@ pub struct NextDevServerBuilder { turbo_tasks: Option>>, project_dir: Option, root_dir: Option, - entry_assets: Vec, + entry_requests: Vec, eager_compile: bool, hostname: Option, port: Option, @@ -43,7 +46,7 @@ impl NextDevServerBuilder { turbo_tasks: None, project_dir: None, root_dir: None, - entry_assets: vec![], + entry_requests: vec![], eager_compile: false, hostname: None, port: None, @@ -68,8 +71,8 @@ impl NextDevServerBuilder { self } - pub fn entry_asset(mut self, entry_asset_path: String) -> NextDevServerBuilder { - self.entry_assets.push(entry_asset_path); + pub fn entry_request(mut self, entry_asset_path: String) -> NextDevServerBuilder { + self.entry_requests.push(entry_asset_path); self } @@ -108,7 +111,7 @@ impl NextDevServerBuilder { let project_dir = self.project_dir.context("project_dir must be set")?; let root_dir = self.root_dir.context("root_dir must be set")?; - let entry_assets = self.entry_assets; + let entry_requests = self.entry_requests; let eager_compile = self.eager_compile; let show_all = self.show_all; let log_detail = self.log_detail; @@ -126,7 +129,7 @@ impl NextDevServerBuilder { source( root_dir.clone(), project_dir.clone(), - entry_assets.clone(), + entry_requests.clone(), eager_compile, turbo_tasks.clone().into(), log_options.clone().cell(), @@ -181,7 +184,7 @@ async fn output_fs(project_dir: &str, log_options: LogOptionsVc) -> Result, + entry_requests: Vec, eager_compile: bool, turbo_tasks: TransientInstance>, log_options: LogOptionsVc, @@ -197,7 +200,10 @@ async fn source( let dev_server_fs = DevServerFileSystemVc::new().as_file_system(); let web_source = create_web_entry_source( project_path, - entry_assets.iter().map(|a| project_path.join(a)).collect(), + entry_requests + .iter() + .map(|a| RequestVc::relative(Value::new(a.to_string().into()), false)) + .collect(), dev_server_fs, eager_compile, ); diff --git a/packages/next-swc/crates/next-dev/src/main.rs b/packages/next-swc/crates/next-dev/src/main.rs index 3b65cc1aa1c54..40021ddf1da8b 100644 --- a/packages/next-swc/crates/next-dev/src/main.rs +++ b/packages/next-swc/crates/next-dev/src/main.rs @@ -96,7 +96,7 @@ async fn main() -> Result<()> { .turbo_tasks(tt) .project_dir(dir) .root_dir(root_dir) - .entry_asset("src/index.js".into()) + .entry_request("src/index".into()) .eager_compile(args.eager_compile) .hostname(args.hostname) .port(args.port) diff --git a/packages/next-swc/crates/next-dev/tests/integration.rs b/packages/next-swc/crates/next-dev/tests/integration.rs index e942af3150156..3bf97fe47d9b9 100644 --- a/packages/next-swc/crates/next-dev/tests/integration.rs +++ b/packages/next-swc/crates/next-dev/tests/integration.rs @@ -122,8 +122,8 @@ async fn run_test(resource: &str) -> JestRunResult { .turbo_tasks(TurboTasks::new(MemoryBackend::new())) .root_dir("tests".into()) .project_dir("tests".into()) - .entry_asset("harness.js".into()) - .entry_asset( + .entry_request("harness.js".into()) + .entry_request( sys_to_unix(test_entry.strip_prefix("tests").unwrap().to_str().unwrap()).to_string(), ) .eager_compile(false)