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 {
/// A map of environment variables to use when compiling code.
pub env: Vec<NapiEnvVar>,
/// The address of the dev server.
pub server_addr: String,
}
#[napi(object)]
......@@ -90,6 +93,7 @@ impl From<NapiProjectOptions> for ProjectOptions {
.into_iter()
.map(|NapiEnvVar { name, value }| (name, value))
.collect(),
server_addr: val.server_addr,
}
}
}
......
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<NextConfig>,
......@@ -222,6 +230,11 @@ impl Project {
Ok(Vc::upcast(disk_fs))
}
#[turbo_tasks::function]
fn server_addr(&self) -> Vc<ServerAddr> {
ServerAddr::new(self.server_addr).cell()
}
#[turbo_tasks::function]
pub(super) fn node_root(self: Vc<Self>) -> Vc<FileSystemPath> {
self.node_fs().root().join(".next".to_string())
......@@ -302,18 +315,13 @@ impl Project {
Ok(get_server_compile_time_info(
this.mode,
self.env(),
// TODO(alexkirsz) Fill this out.
ServerAddr::empty(),
self.server_addr(),
))
}
#[turbo_tasks::function]
pub(super) fn edge_compile_time_info(self: Vc<Self>) -> Vc<CompileTimeInfo> {
get_edge_compile_time_info(
self.project_path(),
// TODO(alexkirsz) Fill this out.
ServerAddr::empty(),
)
get_edge_compile_time_info(self.project_path(), self.server_addr())
}
#[turbo_tasks::function]
......
......@@ -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)
......
......@@ -399,9 +399,14 @@ interface ProjectOptions {
env: Record<string, string>
/**
* 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 {
......
......@@ -124,6 +124,7 @@ export async function initialize(opts: {
nextConfig: config,
isCustomServer: opts.customServer,
turbo: !!process.env.TURBOPACK,
port: opts.port,
})
}
......
......@@ -119,6 +119,7 @@ type SetupOpts = {
ReturnType<typeof import('./filesystem').setupFsCheck>
>
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<string, string>,
serverAddr: `127.0.0.1:${opts.port}`,
})
const iter = project.entrypointsSubscribe()
const curEntries: Map<string, Route> = new Map()
......
......@@ -172,6 +172,7 @@ describe('next.rs api', () => {
? path.resolve(__dirname, '../../..')
: next.testDir,
watch: true,
serverAddr: `127.0.0.1:3000`,
})
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