diff --git a/packages/next-swc/crates/napi/src/next_api/project.rs b/packages/next-swc/crates/napi/src/next_api/project.rs index 3e91939b76b235..ba514d4f8af0d5 100644 --- a/packages/next-swc/crates/napi/src/next_api/project.rs +++ b/packages/next-swc/crates/napi/src/next_api/project.rs @@ -69,6 +69,9 @@ pub struct NapiProjectOptions { /// A map of environment variables to use when compiling code. pub env: Vec, + + /// The address of the dev server. + pub server_addr: String, } #[napi(object)] @@ -90,6 +93,7 @@ impl From for ProjectOptions { .into_iter() .map(|NapiEnvVar { name, value }| (name, value)) .collect(), + server_addr: val.server_addr, } } } diff --git a/packages/next-swc/crates/next-api/src/project.rs b/packages/next-swc/crates/next-api/src/project.rs index f8c95aab78ef5b..9e5a8f3ea576cc 100644 --- a/packages/next-swc/crates/next-api/src/project.rs +++ b/packages/next-swc/crates/next-api/src/project.rs @@ -1,4 +1,4 @@ -use std::path::MAIN_SEPARATOR; +use std::{net::SocketAddr, path::MAIN_SEPARATOR}; use anyhow::Result; use indexmap::{map::Entry, IndexMap}; @@ -81,6 +81,9 @@ pub struct ProjectOptions { /// Whether to watch the filesystem for file changes. pub watch: bool, + + /// The address of the dev server. + pub server_addr: String, } #[derive(Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, ValueDebugFormat)] @@ -122,6 +125,7 @@ impl ProjectContainer { root_path: options.root_path.clone(), project_path: options.project_path.clone(), watch: options.watch, + server_addr: options.server_addr.parse()?, next_config, js_config, env: Vc::upcast(env), @@ -159,6 +163,10 @@ pub struct Project { /// Whether to watch the filesystem for file changes. watch: bool, + /// The address of the dev server. + #[turbo_tasks(trace_ignore)] + server_addr: SocketAddr, + /// Next config. next_config: Vc, @@ -222,6 +230,11 @@ impl Project { Ok(Vc::upcast(disk_fs)) } + #[turbo_tasks::function] + fn server_addr(&self) -> Vc { + ServerAddr::new(self.server_addr).cell() + } + #[turbo_tasks::function] pub(super) fn node_root(self: Vc) -> Vc { self.node_fs().root().join(".next".to_string()) @@ -302,8 +315,7 @@ impl Project { Ok(get_server_compile_time_info( this.mode, self.env(), - // TODO(alexkirsz) Fill this out. - ServerAddr::empty(), + self.server_addr(), )) } @@ -311,8 +323,7 @@ impl Project { pub(super) fn edge_compile_time_info(self: Vc) -> Vc { get_edge_compile_time_info( self.project_path(), - // TODO(alexkirsz) Fill this out. - ServerAddr::empty(), + self.server_addr(), ) } diff --git a/packages/next-swc/crates/next-core/src/next_server/context.rs b/packages/next-swc/crates/next-core/src/next_server/context.rs index 1d242498b36df7..7fffe23be44d20 100644 --- a/packages/next-swc/crates/next-core/src/next_server/context.rs +++ b/packages/next-swc/crates/next-core/src/next_server/context.rs @@ -604,7 +604,7 @@ pub fn get_server_chunking_context( project_path, node_root, node_root.join("server/chunks".to_string()), - client_root.join("static/media".to_string()), + client_root.join("_next/static/media".to_string()), environment, ) .minify_type(MinifyType::NoMinify) diff --git a/packages/next/src/build/swc/index.ts b/packages/next/src/build/swc/index.ts index 28d205c81c234f..80164d4baf03f4 100644 --- a/packages/next/src/build/swc/index.ts +++ b/packages/next/src/build/swc/index.ts @@ -399,9 +399,14 @@ interface ProjectOptions { env: Record /** - * Whether to watch he filesystem for file changes. + * Whether to watch the filesystem for file changes. */ watch: boolean + + /** + * The address of the dev server. + */ + serverAddr: string } interface TurboEngineOptions { diff --git a/packages/next/src/server/lib/router-server.ts b/packages/next/src/server/lib/router-server.ts index 90d23955195c11..c7d77c202a15a6 100644 --- a/packages/next/src/server/lib/router-server.ts +++ b/packages/next/src/server/lib/router-server.ts @@ -119,6 +119,7 @@ export async function initialize(opts: { nextConfig: config, isCustomServer: opts.customServer, turbo: !!process.env.TURBOPACK, + port: opts.port, }) } diff --git a/packages/next/src/server/lib/router-utils/setup-dev.ts b/packages/next/src/server/lib/router-utils/setup-dev.ts index 5af0d92c3a2d80..425506a3d3460d 100644 --- a/packages/next/src/server/lib/router-utils/setup-dev.ts +++ b/packages/next/src/server/lib/router-utils/setup-dev.ts @@ -119,6 +119,7 @@ type SetupOpts = { ReturnType > nextConfig: NextConfigComplete + port: number } async function verifyTypeScript(opts: SetupOpts) { @@ -203,6 +204,7 @@ async function startWatcher(opts: SetupOpts) { jsConfig, watch: true, env: process.env as Record, + serverAddr: `127.0.0.1:${opts.port}`, }) const iter = project.entrypointsSubscribe() const curEntries: Map = new Map()