Unverified Commit 6e3ef5b0 authored by Leah's avatar Leah Committed by GitHub

feat: support expanding urls in nexturbo (and fix static files) (#55147)

Closes WEB-1525
parent d61c6ba4
...@@ -69,6 +69,9 @@ pub struct NapiProjectOptions { ...@@ -69,6 +69,9 @@ pub struct NapiProjectOptions {
/// A map of environment variables to use when compiling code. /// A map of environment variables to use when compiling code.
pub env: Vec<NapiEnvVar>, pub env: Vec<NapiEnvVar>,
/// The address of the dev server.
pub server_addr: String,
} }
#[napi(object)] #[napi(object)]
...@@ -90,6 +93,7 @@ impl From<NapiProjectOptions> for ProjectOptions { ...@@ -90,6 +93,7 @@ impl From<NapiProjectOptions> for ProjectOptions {
.into_iter() .into_iter()
.map(|NapiEnvVar { name, value }| (name, value)) .map(|NapiEnvVar { name, value }| (name, value))
.collect(), .collect(),
server_addr: val.server_addr,
} }
} }
} }
......
use std::path::MAIN_SEPARATOR; use std::{net::SocketAddr, path::MAIN_SEPARATOR};
use anyhow::Result; use anyhow::Result;
use indexmap::{map::Entry, IndexMap}; use indexmap::{map::Entry, IndexMap};
...@@ -81,6 +81,9 @@ pub struct ProjectOptions { ...@@ -81,6 +81,9 @@ pub struct ProjectOptions {
/// Whether to watch the filesystem for file changes. /// Whether to watch the filesystem for file changes.
pub watch: bool, pub watch: bool,
/// The address of the dev server.
pub server_addr: String,
} }
#[derive(Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, ValueDebugFormat)] #[derive(Serialize, Deserialize, TraceRawVcs, PartialEq, Eq, ValueDebugFormat)]
...@@ -122,6 +125,7 @@ impl ProjectContainer { ...@@ -122,6 +125,7 @@ impl ProjectContainer {
root_path: options.root_path.clone(), root_path: options.root_path.clone(),
project_path: options.project_path.clone(), project_path: options.project_path.clone(),
watch: options.watch, watch: options.watch,
server_addr: options.server_addr.parse()?,
next_config, next_config,
js_config, js_config,
env: Vc::upcast(env), env: Vc::upcast(env),
...@@ -159,6 +163,10 @@ pub struct Project { ...@@ -159,6 +163,10 @@ pub struct Project {
/// Whether to watch the filesystem for file changes. /// Whether to watch the filesystem for file changes.
watch: bool, watch: bool,
/// The address of the dev server.
#[turbo_tasks(trace_ignore)]
server_addr: SocketAddr,
/// Next config. /// Next config.
next_config: Vc<NextConfig>, next_config: Vc<NextConfig>,
...@@ -222,6 +230,11 @@ impl Project { ...@@ -222,6 +230,11 @@ impl Project {
Ok(Vc::upcast(disk_fs)) Ok(Vc::upcast(disk_fs))
} }
#[turbo_tasks::function]
fn server_addr(&self) -> Vc<ServerAddr> {
ServerAddr::new(self.server_addr).cell()
}
#[turbo_tasks::function] #[turbo_tasks::function]
pub(super) fn node_root(self: Vc<Self>) -> Vc<FileSystemPath> { pub(super) fn node_root(self: Vc<Self>) -> Vc<FileSystemPath> {
self.node_fs().root().join(".next".to_string()) self.node_fs().root().join(".next".to_string())
...@@ -302,18 +315,13 @@ impl Project { ...@@ -302,18 +315,13 @@ impl Project {
Ok(get_server_compile_time_info( Ok(get_server_compile_time_info(
this.mode, this.mode,
self.env(), self.env(),
// TODO(alexkirsz) Fill this out. self.server_addr(),
ServerAddr::empty(),
)) ))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub(super) fn edge_compile_time_info(self: Vc<Self>) -> Vc<CompileTimeInfo> { pub(super) fn edge_compile_time_info(self: Vc<Self>) -> Vc<CompileTimeInfo> {
get_edge_compile_time_info( get_edge_compile_time_info(self.project_path(), self.server_addr())
self.project_path(),
// TODO(alexkirsz) Fill this out.
ServerAddr::empty(),
)
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -604,7 +604,7 @@ pub fn get_server_chunking_context( ...@@ -604,7 +604,7 @@ pub fn get_server_chunking_context(
project_path, project_path,
node_root, node_root,
node_root.join("server/chunks".to_string()), node_root.join("server/chunks".to_string()),
client_root.join("static/media".to_string()), client_root.join("_next/static/media".to_string()),
environment, environment,
) )
.minify_type(MinifyType::NoMinify) .minify_type(MinifyType::NoMinify)
......
...@@ -399,9 +399,14 @@ interface ProjectOptions { ...@@ -399,9 +399,14 @@ interface ProjectOptions {
env: Record<string, string> env: Record<string, string>
/** /**
* Whether to watch he filesystem for file changes. * Whether to watch the filesystem for file changes.
*/ */
watch: boolean watch: boolean
/**
* The address of the dev server.
*/
serverAddr: string
} }
interface TurboEngineOptions { interface TurboEngineOptions {
......
...@@ -124,6 +124,7 @@ export async function initialize(opts: { ...@@ -124,6 +124,7 @@ export async function initialize(opts: {
nextConfig: config, nextConfig: config,
isCustomServer: opts.customServer, isCustomServer: opts.customServer,
turbo: !!process.env.TURBOPACK, turbo: !!process.env.TURBOPACK,
port: opts.port,
}) })
} }
......
...@@ -119,6 +119,7 @@ type SetupOpts = { ...@@ -119,6 +119,7 @@ type SetupOpts = {
ReturnType<typeof import('./filesystem').setupFsCheck> ReturnType<typeof import('./filesystem').setupFsCheck>
> >
nextConfig: NextConfigComplete nextConfig: NextConfigComplete
port: number
} }
async function verifyTypeScript(opts: SetupOpts) { async function verifyTypeScript(opts: SetupOpts) {
...@@ -203,6 +204,7 @@ async function startWatcher(opts: SetupOpts) { ...@@ -203,6 +204,7 @@ async function startWatcher(opts: SetupOpts) {
jsConfig, jsConfig,
watch: true, watch: true,
env: process.env as Record<string, string>, env: process.env as Record<string, string>,
serverAddr: `127.0.0.1:${opts.port}`,
}) })
const iter = project.entrypointsSubscribe() const iter = project.entrypointsSubscribe()
const curEntries: Map<string, Route> = new Map() const curEntries: Map<string, Route> = new Map()
......
...@@ -172,6 +172,7 @@ describe('next.rs api', () => { ...@@ -172,6 +172,7 @@ describe('next.rs api', () => {
? path.resolve(__dirname, '../../..') ? path.resolve(__dirname, '../../..')
: next.testDir, : next.testDir,
watch: true, watch: true,
serverAddr: `127.0.0.1:3000`,
}) })
projectUpdateSubscription = project.updateInfoSubscribe() projectUpdateSubscription = project.updateInfoSubscribe()
}) })
......
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