Skip to content

Commit

Permalink
resolve entrypoint to allow it to select jsx automatically (vercel/tu…
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra authored Aug 26, 2022
1 parent 3148d3b commit 32d10a0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl NodeJsPoolProcess {
}

fn start(mut cmd: Command) -> Result<Self> {
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();
Expand Down
20 changes: 13 additions & 7 deletions packages/next-swc/crates/next-core/src/web_entry_source.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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::{
Expand All @@ -23,7 +22,7 @@ use turbopack_dev_server::{
#[turbo_tasks::function]
pub async fn create_web_entry_source(
root: FileSystemPathVc,
entry_paths: Vec<FileSystemPathVc>,
entry_requests: Vec<RequestVc>,
dev_server_fs: FileSystemVc,
eager_compile: bool,
) -> Result<ContentSourceVc> {
Expand Down Expand Up @@ -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::<Vec<_>>());
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()))
Expand Down
26 changes: 16 additions & 10 deletions packages/next-swc/crates/next-dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -22,7 +25,7 @@ pub struct NextDevServerBuilder {
turbo_tasks: Option<Arc<TurboTasks<MemoryBackend>>>,
project_dir: Option<String>,
root_dir: Option<String>,
entry_assets: Vec<String>,
entry_requests: Vec<String>,
eager_compile: bool,
hostname: Option<IpAddr>,
port: Option<u16>,
Expand All @@ -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,
Expand All @@ -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
}

Expand Down Expand Up @@ -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;
Expand All @@ -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(),
Expand Down Expand Up @@ -181,7 +184,7 @@ async fn output_fs(project_dir: &str, log_options: LogOptionsVc) -> Result<FileS
async fn source(
root_dir: String,
project_dir: String,
entry_assets: Vec<String>,
entry_requests: Vec<String>,
eager_compile: bool,
turbo_tasks: TransientInstance<TurboTasks<MemoryBackend>>,
log_options: LogOptionsVc,
Expand All @@ -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,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/crates/next-dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/next-dev/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 32d10a0

Please sign in to comment.