From 790a69b6bf826c1abcbf57faca920c4c3eb05fc8 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Mon, 10 Jul 2023 13:06:18 -0700 Subject: [PATCH 01/16] turbopack-cli: modularize code to support turbopack build This work prepares for `turbopack build` by extracting code common between dev and build, such as asset context. This also makes the cli accept a variadic list of entries rather than an unnamed directory parameter. The project directory is now available under `--dir` or `-d`. Test Plan: `cargo run -p turbopack-cli dev` with a `src/index.js` present and `cargo run -p turbopack-cli dev src/entry.js` with `src/entry.js` present. --- Cargo.lock | 21 +- Cargo.toml | 2 +- crates/node-file-trace/src/lib.rs | 6 +- crates/turbo-tasks-macros/src/value_macro.rs | 1 + crates/turbo-tasks-memory/src/lib.rs | 4 +- .../turbo-tasks-memory/src/memory_backend.rs | 6 + crates/turbopack-cli-utils/src/issue.rs | 5 +- crates/turbopack-cli/Cargo.toml | 1 + crates/turbopack-cli/src/arguments.rs | 9 +- crates/turbopack-cli/src/contexts.rs | 201 ++++++++++++ crates/turbopack-cli/src/dev/mod.rs | 64 ++-- .../turbopack-cli/src/dev/web_entry_source.rs | 302 ++++-------------- crates/turbopack-cli/src/lib.rs | 3 + crates/turbopack-cli/src/main.rs | 1 + crates/turbopack-cli/src/util.rs | 69 ++++ crates/turbopack-core/src/issue/mod.rs | 46 ++- crates/turbopack-core/src/reference/mod.rs | 37 ++- crates/turbopack-dev-server/src/http.rs | 27 +- crates/turbopack-dev-server/src/lib.rs | 40 +-- 19 files changed, 506 insertions(+), 339 deletions(-) create mode 100644 crates/turbopack-cli/src/contexts.rs create mode 100644 crates/turbopack-cli/src/util.rs diff --git a/Cargo.lock b/Cargo.lock index 289620518d51f..170963dde9990 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -669,9 +669,9 @@ dependencies = [ [[package]] name = "binding_macros" -version = "0.53.12" +version = "0.53.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624f5dbcd82b932d9f9f959fec4ce89a1fd67a6e4e141bad66f01673704045cb" +checksum = "3ecbec28ed0caaee2843dd557762ded79b2ffddd72edcdda3d681f1f70499ffc" dependencies = [ "anyhow", "console_error_panic_hook", @@ -6737,9 +6737,9 @@ dependencies = [ [[package]] name = "swc" -version = "0.264.12" +version = "0.264.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176cdf854d438bd39aee0dec1f84c053cb7978402b11133f60fbb77453ed020d" +checksum = "2f77c84d7bb17937099e7548ebe35ebf2f35f6d5071adb24ceb78b4dddcbaed3" dependencies = [ "ahash 0.8.3", "anyhow", @@ -6816,9 +6816,9 @@ dependencies = [ [[package]] name = "swc_bundler" -version = "0.217.10" +version = "0.217.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d196673157f333f730602745b208feeee82da239b6defc5b962e68291bd570b" +checksum = "c126fe44ef25de31c73db1874a0feeece8941bafbdfb3778e4af9367c3ac2c2b" dependencies = [ "ahash 0.8.3", "anyhow", @@ -6922,9 +6922,9 @@ dependencies = [ [[package]] name = "swc_core" -version = "0.79.13" +version = "0.79.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fad8d1f1abb42719a841f76915e7d2d573e2f9f0462e26dedca847e9ad7b1e4" +checksum = "0ac072ebc8e6bdaae0a0f93fa2ba2dc922a24ffbe9f58bd27f28109627e5cb3e" dependencies = [ "binding_macros", "swc", @@ -7209,9 +7209,9 @@ dependencies = [ [[package]] name = "swc_ecma_minifier" -version = "0.184.10" +version = "0.184.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87d541b5632bb93d71ea47518075c357afacb86adfe782922f1060f9a995fd29" +checksum = "aecc16ea061975c71b5397a6a26281598bc5a95e30b5e77093c54f74fbbfcace" dependencies = [ "ahash 0.8.3", "arrayvec 0.7.2", @@ -9113,6 +9113,7 @@ dependencies = [ "turbo-tasks-memory", "turbopack", "turbopack-bench", + "turbopack-build", "turbopack-cli-utils", "turbopack-core", "turbopack-dev", diff --git a/Cargo.toml b/Cargo.toml index 24e54a997dac8..9911d4d98f8b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,7 +79,7 @@ mdxjs = { version = "0.1.14" } modularize_imports = { version = "0.32.0" } styled_components = { version = "0.59.0" } styled_jsx = { version = "0.36.0" } -swc_core = { version = "0.79.13" } +swc_core = { version = "0.79.14" } swc_emotion = { version = "0.35.0" } swc_relay = { version = "0.7.0" } testing = { version = "0.33.20" } diff --git a/crates/node-file-trace/src/lib.rs b/crates/node-file-trace/src/lib.rs index f9b32db5ddbf8..060b6d2cf4baa 100644 --- a/crates/node-file-trace/src/lib.rs +++ b/crates/node-file-trace/src/lib.rs @@ -501,7 +501,11 @@ async fn run>( let console_ui = ConsoleUiVc::new(log_options); console_ui .as_issue_reporter() - .report_issues(TransientInstance::new(issues), source) + .report_issues( + TransientInstance::new(issues), + source, + IssueSeverity::Error.cell(), + ) .await?; if has_return_value { diff --git a/crates/turbo-tasks-macros/src/value_macro.rs b/crates/turbo-tasks-macros/src/value_macro.rs index 30bc664010808..2d0518201235a 100644 --- a/crates/turbo-tasks-macros/src/value_macro.rs +++ b/crates/turbo-tasks-macros/src/value_macro.rs @@ -608,6 +608,7 @@ pub fn value(args: TokenStream, input: TokenStream) -> TokenStream { Ok(Self { node: self.node.resolve_strongly_consistent().await? }) } + /// Downcasts the passed Trait Vc into this concrete Vc. pub async fn resolve_from(super_trait_vc: impl std::convert::Into) -> Result, turbo_tasks::ResolveTypeError> { let raw_vc: turbo_tasks::RawVc = super_trait_vc.into(); let raw_vc = raw_vc.resolve_value(*#value_type_id_ident).await?; diff --git a/crates/turbo-tasks-memory/src/lib.rs b/crates/turbo-tasks-memory/src/lib.rs index 72080c065b3a1..e4de44442c7ec 100644 --- a/crates/turbo-tasks-memory/src/lib.rs +++ b/crates/turbo-tasks-memory/src/lib.rs @@ -13,7 +13,7 @@ mod count_hash_set; mod gc; mod map_guard; mod memory_backend; -mod memory_backend_with_pg; +// mod memory_backend_with_pg; mod output; mod priority_pair; pub mod scope; @@ -22,4 +22,4 @@ mod task; pub mod viz; pub use memory_backend::MemoryBackend; -pub use memory_backend_with_pg::MemoryBackendWithPersistedGraph; +// pub use memory_backend_with_pg::MemoryBackendWithPersistedGraph; diff --git a/crates/turbo-tasks-memory/src/memory_backend.rs b/crates/turbo-tasks-memory/src/memory_backend.rs index e0be9f90ed217..87a6077ec1c36 100644 --- a/crates/turbo-tasks-memory/src/memory_backend.rs +++ b/crates/turbo-tasks-memory/src/memory_backend.rs @@ -664,6 +664,12 @@ impl Backend for MemoryBackend { let task_type = Arc::new(task_type); // slow pass with key lock let id = turbo_tasks.get_fresh_task_id(); + // eprintln!( + // "Created {} ({}) with parent {}", + // task_name, + // *unsafe { id.get_unchecked() }, + // parent_task + // ); let task = Task::new_persistent( // Safety: That task will hold the value, but we are still in // control of the task diff --git a/crates/turbopack-cli-utils/src/issue.rs b/crates/turbopack-cli-utils/src/issue.rs index 97d2101ed7489..f5d1d5f798c0f 100644 --- a/crates/turbopack-cli-utils/src/issue.rs +++ b/crates/turbopack-cli-utils/src/issue.rs @@ -16,7 +16,7 @@ use turbo_tasks::{ }; use turbo_tasks_fs::{source_context::get_source_context, FileLinesContent}; use turbopack_core::issue::{ - CapturedIssues, IssueReporter, IssueReporterVc, IssueSeverity, PlainIssue, + CapturedIssues, IssueReporter, IssueReporterVc, IssueSeverity, IssueSeverityVc, PlainIssue, PlainIssueProcessingPathItem, PlainIssueProcessingPathItemReadRef, PlainIssueSource, }; @@ -353,6 +353,7 @@ impl IssueReporter for ConsoleUi { &self, issues: TransientInstance>, source: TransientValue, + min_fatal_severity: IssueSeverityVc, ) -> Result { let issues = &*issues; let LogOptions { @@ -389,7 +390,7 @@ impl IssueReporter for ConsoleUi { } let severity = plain_issue.severity; - if severity == IssueSeverity::Fatal { + if severity <= *min_fatal_severity.await? { has_fatal = true; } diff --git a/crates/turbopack-cli/Cargo.toml b/crates/turbopack-cli/Cargo.toml index 1ac25fa4ed7d8..bae0410b2d5b9 100644 --- a/crates/turbopack-cli/Cargo.toml +++ b/crates/turbopack-cli/Cargo.toml @@ -57,6 +57,7 @@ turbo-tasks-fs = { workspace = true } turbo-tasks-malloc = { workspace = true, default-features = false } turbo-tasks-memory = { workspace = true } turbopack = { workspace = true } +turbopack-build = { workspace = true } turbopack-cli-utils = { workspace = true } turbopack-core = { workspace = true } turbopack-dev = { workspace = true } diff --git a/crates/turbopack-cli/src/arguments.rs b/crates/turbopack-cli/src/arguments.rs index c9a4e7ab73d50..cb1277b49026d 100644 --- a/crates/turbopack-cli/src/arguments.rs +++ b/crates/turbopack-cli/src/arguments.rs @@ -21,11 +21,16 @@ impl Arguments { } } -#[derive(Debug, Args)] +#[derive(Debug, Args, Clone)] pub struct CommonArguments { + /// The entrypoints of the project. Resolved relative to the project's + /// directory (`--dir`). + #[clap(value_parser)] + pub entries: Option>, + /// The directory of the application. /// If no directory is provided, the current directory will be used. - #[clap(value_parser)] + #[clap(short, long, value_parser)] pub dir: Option, /// The root directory of the project. Nothing outside of this directory can diff --git a/crates/turbopack-cli/src/contexts.rs b/crates/turbopack-cli/src/contexts.rs new file mode 100644 index 0000000000000..6c5bc1fee5046 --- /dev/null +++ b/crates/turbopack-cli/src/contexts.rs @@ -0,0 +1,201 @@ +use std::{collections::HashMap, fmt}; + +use anyhow::Result; +use turbo_tasks::Value; +use turbo_tasks_fs::{FileSystem, FileSystemPathVc}; +use turbopack::{ + condition::ContextCondition, + ecmascript::TransformPluginVc, + module_options::{ + CustomEcmascriptTransformPlugins, CustomEcmascriptTransformPluginsVc, JsxTransformOptions, + ModuleOptionsContext, ModuleOptionsContextVc, + }, + resolve_options_context::{ResolveOptionsContext, ResolveOptionsContextVc}, + transition::TransitionsByNameVc, + ModuleAssetContextVc, +}; +use turbopack_core::{ + compile_time_defines, + compile_time_info::{CompileTimeDefinesVc, CompileTimeInfo, CompileTimeInfoVc}, + context::AssetContextVc, + environment::{BrowserEnvironment, Environment, EnvironmentVc, ExecutionEnvironment}, + resolve::options::{ImportMap, ImportMapVc, ImportMapping}, +}; +use turbopack_dev::react_refresh::assert_can_resolve_react_refresh; +use turbopack_ecmascript_plugins::transform::{ + emotion::{EmotionTransformConfig, EmotionTransformer}, + styled_components::{StyledComponentsTransformConfig, StyledComponentsTransformer}, + styled_jsx::StyledJsxTransformer, +}; +use turbopack_node::execution_context::ExecutionContextVc; + +#[turbo_tasks::value(shared)] +pub enum NodeEnv { + Development, + Production, +} + +impl fmt::Display for NodeEnv { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + NodeEnv::Development => f.write_str("development"), + NodeEnv::Production => f.write_str("production"), + } + } +} + +async fn foreign_code_context_condition() -> Result { + Ok(ContextCondition::InDirectory("node_modules".to_string())) +} + +#[turbo_tasks::function] +pub async fn get_client_import_map(project_path: FileSystemPathVc) -> Result { + let mut import_map = ImportMap::empty(); + + import_map.insert_singleton_alias("@swc/helpers", project_path); + import_map.insert_singleton_alias("styled-jsx", project_path); + import_map.insert_singleton_alias("react", project_path); + import_map.insert_singleton_alias("react-dom", project_path); + + import_map.insert_wildcard_alias( + "@vercel/turbopack-ecmascript-runtime/", + ImportMapping::PrimaryAlternative( + "./*".to_string(), + Some(turbopack_ecmascript_runtime::embed_fs().root()), + ) + .cell(), + ); + + Ok(import_map.cell()) +} + +#[turbo_tasks::function] +pub async fn get_client_resolve_options_context( + project_path: FileSystemPathVc, + node_env: NodeEnvVc, +) -> Result { + let next_client_import_map = get_client_import_map(project_path); + let module_options_context = ResolveOptionsContext { + enable_node_modules: Some(project_path.root().resolve().await?), + custom_conditions: vec![node_env.await?.to_string()], + import_map: Some(next_client_import_map), + browser: true, + module: true, + ..Default::default() + }; + Ok(ResolveOptionsContext { + enable_typescript: true, + enable_react: true, + rules: vec![( + foreign_code_context_condition().await?, + module_options_context.clone().cell(), + )], + ..module_options_context + } + .cell()) +} + +#[turbo_tasks::function] +async fn get_client_module_options_context( + project_path: FileSystemPathVc, + execution_context: ExecutionContextVc, + env: EnvironmentVc, + node_env: NodeEnvVc, +) -> Result { + let module_options_context = ModuleOptionsContext { + preset_env_versions: Some(env), + execution_context: Some(execution_context), + ..Default::default() + }; + + let resolve_options_context = get_client_resolve_options_context(project_path, node_env); + + let enable_react_refresh = + assert_can_resolve_react_refresh(project_path, resolve_options_context) + .await? + .is_found(); + + let enable_jsx = Some( + JsxTransformOptions { + react_refresh: enable_react_refresh, + ..Default::default() + } + .cell(), + ); + + let custom_ecma_transform_plugins = Some(CustomEcmascriptTransformPluginsVc::cell( + CustomEcmascriptTransformPlugins { + source_transforms: vec![ + TransformPluginVc::cell(Box::new( + EmotionTransformer::new(&EmotionTransformConfig::default()) + .expect("Should be able to create emotion transformer"), + )), + TransformPluginVc::cell(Box::new(StyledComponentsTransformer::new( + &StyledComponentsTransformConfig::default(), + ))), + TransformPluginVc::cell(Box::new(StyledJsxTransformer::new())), + ], + output_transforms: vec![], + }, + )); + + let module_options_context = ModuleOptionsContext { + enable_jsx, + enable_postcss_transform: Some(Default::default()), + enable_typescript_transform: Some(Default::default()), + rules: vec![( + foreign_code_context_condition().await?, + module_options_context.clone().cell(), + )], + custom_ecma_transform_plugins, + ..module_options_context + } + .cell(); + + Ok(module_options_context) +} + +#[turbo_tasks::function] +pub fn get_client_asset_context( + project_path: FileSystemPathVc, + execution_context: ExecutionContextVc, + compile_time_info: CompileTimeInfoVc, + node_env: NodeEnvVc, +) -> AssetContextVc { + let resolve_options_context = get_client_resolve_options_context(project_path, node_env); + let module_options_context = get_client_module_options_context( + project_path, + execution_context, + compile_time_info.environment(), + node_env, + ); + + let context: AssetContextVc = ModuleAssetContextVc::new( + TransitionsByNameVc::cell(HashMap::new()), + compile_time_info, + module_options_context, + resolve_options_context, + ) + .into(); + + context +} + +fn client_defines(node_env: &NodeEnv) -> CompileTimeDefinesVc { + compile_time_defines!( + process.turbopack = true, + process.env.NODE_ENV = node_env.to_string() + ) + .cell() +} + +#[turbo_tasks::function] +pub async fn get_client_compile_time_info( + env: EnvironmentVc, + node_env: NodeEnvVc, + browserslist_query: &str, +) -> Result { + Ok(CompileTimeInfo::builder(env) + .defines(client_defines(&*node_env.await?)) + .cell()) +} diff --git a/crates/turbopack-cli/src/dev/mod.rs b/crates/turbopack-cli/src/dev/mod.rs index d86e94a13d8b9..a9e5d283fe9b2 100644 --- a/crates/turbopack-cli/src/dev/mod.rs +++ b/crates/turbopack-cli/src/dev/mod.rs @@ -10,14 +10,13 @@ use std::{ }; use anyhow::{Context, Result}; -use dunce::canonicalize; use owo_colors::OwoColorize; use turbo_tasks::{ primitives::StringVc, util::{FormatBytes, FormatDuration}, StatsType, TransientInstance, TurboTasks, TurboTasksBackendApi, UpdateInfo, Value, }; -use turbo_tasks_fs::{DiskFileSystemVc, FileSystem, FileSystemVc}; +use turbo_tasks_fs::FileSystem; use turbo_tasks_malloc::TurboMalloc; use turbo_tasks_memory::MemoryBackend; use turbopack::evaluate_context::node_build_environment; @@ -42,17 +41,17 @@ use turbopack_env::dotenv::load_env; use turbopack_node::execution_context::ExecutionContextVc; use self::web_entry_source::create_web_entry_source; -use crate::arguments::DevArguments; +use crate::{ + arguments::DevArguments, + contexts::NodeEnv, + util::{ + normalize_dirs, normalize_entries, output_fs, project_fs, EntryRequest, NormalizedDirs, + }, +}; pub(crate) mod turbo_tasks_viz; pub(crate) mod web_entry_source; -#[derive(Clone)] -pub enum EntryRequest { - Relative(String), - Module(String, String), -} - pub struct TurbopackDevServerBuilder { turbo_tasks: Arc>, project_dir: String, @@ -230,20 +229,6 @@ impl TurbopackDevServerBuilder { } } -#[turbo_tasks::function] -async fn project_fs(project_dir: &str) -> Result { - let disk_fs = DiskFileSystemVc::new("project".to_string(), project_dir.to_string()); - disk_fs.await?.start_watching()?; - Ok(disk_fs.into()) -} - -#[turbo_tasks::function] -async fn output_fs(project_dir: &str) -> Result { - let disk_fs = DiskFileSystemVc::new("output".to_string(), project_dir.to_string()); - disk_fs.await?.start_watching()?; - Ok(disk_fs.into()) -} - #[allow(clippy::too_many_arguments)] #[turbo_tasks::function] async fn source( @@ -296,6 +281,7 @@ async fn source( server_root, env, eager_compile, + NodeEnv::Development.cell(), &browserslist_query, ); let viz = turbo_tasks_viz::TurboTasksSource { @@ -340,26 +326,10 @@ pub async fn start_server(args: &DevArguments) -> Result<()> { console_subscriber::init(); register(); - let dir = args - .common - .dir - .as_ref() - .map(canonicalize) - .unwrap_or_else(current_dir) - .context("project directory can't be found")? - .to_str() - .context("project directory contains invalid characters")? - .to_string(); - - let root_dir = if let Some(root) = args.common.root.as_ref() { - canonicalize(root) - .context("root directory can't be found")? - .to_str() - .context("root directory contains invalid characters")? - .to_string() - } else { - dir.clone() - }; + let NormalizedDirs { + project_dir, + root_dir, + } = normalize_dirs(&args.common.dir, &args.common.root)?; let tt = TurboTasks::new(MemoryBackend::new( args.common @@ -375,9 +345,7 @@ pub async fn start_server(args: &DevArguments) -> Result<()> { let tt_clone = tt.clone(); - #[allow(unused_mut)] - let mut server = TurbopackDevServerBuilder::new(tt, dir, root_dir) - .entry_request(EntryRequest::Relative("src/index".into())) + let mut server = TurbopackDevServerBuilder::new(tt, project_dir, root_dir) .eager_compile(args.eager_compile) .hostname(args.hostname) .port(args.port) @@ -389,6 +357,10 @@ pub async fn start_server(args: &DevArguments) -> Result<()> { .map_or_else(|| IssueSeverity::Warning, |l| l.0), ); + for entry in normalize_entries(&args.common.entries) { + server = server.entry_request(EntryRequest::Relative(entry)) + } + #[cfg(feature = "serializable")] { server = server.allow_retry(args.allow_retry); diff --git a/crates/turbopack-cli/src/dev/web_entry_source.rs b/crates/turbopack-cli/src/dev/web_entry_source.rs index 5330aa60553dd..435e809649bd5 100644 --- a/crates/turbopack-cli/src/dev/web_entry_source.rs +++ b/crates/turbopack-cli/src/dev/web_entry_source.rs @@ -1,33 +1,14 @@ -use std::collections::HashMap; - use anyhow::{anyhow, Result}; use turbo_tasks::{TryJoinIterExt, Value}; use turbo_tasks_env::ProcessEnvVc; -use turbo_tasks_fs::{FileSystem, FileSystemPathVc}; -use turbopack::{ - condition::ContextCondition, - ecmascript::{EcmascriptModuleAssetVc, TransformPluginVc}, - module_options::{ - CustomEcmascriptTransformPlugins, CustomEcmascriptTransformPluginsVc, JsxTransformOptions, - ModuleOptionsContext, ModuleOptionsContextVc, - }, - resolve_options_context::{ResolveOptionsContext, ResolveOptionsContextVc}, - transition::TransitionsByNameVc, - ModuleAssetContextVc, -}; +use turbo_tasks_fs::FileSystemPathVc; +use turbopack::ecmascript::EcmascriptModuleAssetVc; use turbopack_cli_utils::runtime_entry::{RuntimeEntriesVc, RuntimeEntry}; use turbopack_core::{ chunk::{ChunkableAssetVc, ChunkingContextVc}, - compile_time_defines, - compile_time_info::{CompileTimeDefinesVc, CompileTimeInfo, CompileTimeInfoVc}, - context::AssetContextVc, environment::{BrowserEnvironment, EnvironmentVc, ExecutionEnvironment}, reference_type::{EntryReferenceSubType, ReferenceType}, - resolve::{ - options::{ImportMap, ImportMapVc, ImportMapping}, - origin::PlainResolveOriginVc, - parse::RequestVc, - }, + resolve::{origin::PlainResolveOriginVc, parse::RequestVc}, source_asset::SourceAssetVc, }; use turbopack_dev::{react_refresh::assert_can_resolve_react_refresh, DevChunkingContextVc}; @@ -35,216 +16,15 @@ use turbopack_dev_server::{ html::DevHtmlAssetVc, source::{asset_graph::AssetGraphContentSourceVc, ContentSourceVc}, }; -use turbopack_ecmascript_plugins::transform::{ - emotion::{EmotionTransformConfig, EmotionTransformer}, - styled_components::{StyledComponentsTransformConfig, StyledComponentsTransformer}, - styled_jsx::StyledJsxTransformer, -}; use turbopack_node::execution_context::ExecutionContextVc; -use crate::embed_js::embed_file_path; - -async fn foreign_code_context_condition() -> Result { - Ok(ContextCondition::InDirectory("node_modules".to_string())) -} - -#[turbo_tasks::function] -pub async fn get_client_import_map(project_path: FileSystemPathVc) -> Result { - let mut import_map = ImportMap::empty(); - - import_map.insert_singleton_alias("@swc/helpers", project_path); - import_map.insert_singleton_alias("styled-jsx", project_path); - import_map.insert_singleton_alias("react", project_path); - import_map.insert_singleton_alias("react-dom", project_path); - - import_map.insert_wildcard_alias( - "@vercel/turbopack-ecmascript-runtime/", - ImportMapping::PrimaryAlternative( - "./*".to_string(), - Some(turbopack_ecmascript_runtime::embed_fs().root()), - ) - .cell(), - ); - - Ok(import_map.cell()) -} - -#[turbo_tasks::function] -async fn get_client_resolve_options_context( - project_path: FileSystemPathVc, -) -> Result { - let next_client_import_map = get_client_import_map(project_path); - let module_options_context = ResolveOptionsContext { - enable_node_modules: Some(project_path.root().resolve().await?), - custom_conditions: vec!["development".to_string()], - import_map: Some(next_client_import_map), - browser: true, - module: true, - ..Default::default() - }; - Ok(ResolveOptionsContext { - enable_typescript: true, - enable_react: true, - rules: vec![( - foreign_code_context_condition().await?, - module_options_context.clone().cell(), - )], - ..module_options_context - } - .cell()) -} - -#[turbo_tasks::function] -async fn get_client_module_options_context( - project_path: FileSystemPathVc, - execution_context: ExecutionContextVc, - env: EnvironmentVc, -) -> Result { - let module_options_context = ModuleOptionsContext { - preset_env_versions: Some(env), - execution_context: Some(execution_context), - ..Default::default() - }; - - let resolve_options_context = get_client_resolve_options_context(project_path); - - let enable_react_refresh = - assert_can_resolve_react_refresh(project_path, resolve_options_context) - .await? - .is_found(); - - let enable_jsx = Some( - JsxTransformOptions { - react_refresh: enable_react_refresh, - ..Default::default() - } - .cell(), - ); - - let custom_ecma_transform_plugins = Some(CustomEcmascriptTransformPluginsVc::cell( - CustomEcmascriptTransformPlugins { - source_transforms: vec![ - TransformPluginVc::cell(Box::new( - EmotionTransformer::new(&EmotionTransformConfig::default()) - .expect("Should be able to create emotion transformer"), - )), - TransformPluginVc::cell(Box::new(StyledComponentsTransformer::new( - &StyledComponentsTransformConfig::default(), - ))), - TransformPluginVc::cell(Box::new(StyledJsxTransformer::new())), - ], - output_transforms: vec![], - }, - )); - - let module_options_context = ModuleOptionsContext { - enable_jsx, - enable_postcss_transform: Some(Default::default()), - enable_typescript_transform: Some(Default::default()), - rules: vec![( - foreign_code_context_condition().await?, - module_options_context.clone().cell(), - )], - custom_ecma_transform_plugins, - ..module_options_context - } - .cell(); - - Ok(module_options_context) -} - -#[turbo_tasks::function] -fn get_client_asset_context( - project_path: FileSystemPathVc, - execution_context: ExecutionContextVc, - compile_time_info: CompileTimeInfoVc, -) -> AssetContextVc { - let resolve_options_context = get_client_resolve_options_context(project_path); - let module_options_context = get_client_module_options_context( - project_path, - execution_context, - compile_time_info.environment(), - ); - - let context: AssetContextVc = ModuleAssetContextVc::new( - TransitionsByNameVc::cell(HashMap::new()), - compile_time_info, - module_options_context, - resolve_options_context, - ) - .into(); - - context -} - -pub fn client_defines() -> CompileTimeDefinesVc { - compile_time_defines!( - process.turbopack = true, - process.env.NODE_ENV = "development", - ) - .cell() -} - -#[turbo_tasks::function] -pub fn get_client_compile_time_info(browserslist_query: &str) -> CompileTimeInfoVc { - CompileTimeInfo::builder(EnvironmentVc::new(Value::new( - ExecutionEnvironment::Browser( - BrowserEnvironment { - dom: true, - web_worker: false, - service_worker: false, - browserslist_query: browserslist_query.to_owned(), - } - .into(), - ), - ))) - .defines(client_defines()) - .cell() -} - -#[turbo_tasks::function] -pub fn get_client_chunking_context( - project_path: FileSystemPathVc, - server_root: FileSystemPathVc, - environment: EnvironmentVc, -) -> ChunkingContextVc { - DevChunkingContextVc::builder( - project_path, - server_root, - server_root.join("/_chunks"), - server_root.join("/_assets"), - environment, - ) - .hot_module_replacement() - .build() -} - -#[turbo_tasks::function] -pub async fn get_client_runtime_entries( - project_path: FileSystemPathVc, -) -> Result { - let resolve_options_context = get_client_resolve_options_context(project_path); - - let mut runtime_entries = Vec::new(); - - let enable_react_refresh = - assert_can_resolve_react_refresh(project_path, resolve_options_context) - .await? - .as_request(); - // It's important that React Refresh come before the regular bootstrap file, - // because the bootstrap contains JSX which requires Refresh's global - // functions to be available. - if let Some(request) = enable_react_refresh { - runtime_entries.push(RuntimeEntry::Request(request, project_path.join("_")).cell()) - }; - - runtime_entries.push( - RuntimeEntry::Source(SourceAssetVc::new(embed_file_path("entry/bootstrap.ts")).into()) - .cell(), - ); - - Ok(RuntimeEntriesVc::cell(runtime_entries)) -} +use crate::{ + contexts::{ + get_client_asset_context, get_client_compile_time_info, get_client_resolve_options_context, + NodeEnvVc, + }, + embed_js::embed_file_path, +}; #[turbo_tasks::function] pub async fn create_web_entry_source( @@ -254,13 +34,24 @@ pub async fn create_web_entry_source( server_root: FileSystemPathVc, _env: ProcessEnvVc, eager_compile: bool, + node_env: NodeEnvVc, browserslist_query: &str, ) -> Result { - let compile_time_info = get_client_compile_time_info(browserslist_query); - let context = get_client_asset_context(project_path, execution_context, compile_time_info); + let env = EnvironmentVc::new(Value::new(ExecutionEnvironment::Browser( + BrowserEnvironment { + dom: true, + web_worker: false, + service_worker: false, + browserslist_query: browserslist_query.to_owned(), + } + .into(), + ))); + let compile_time_info = get_client_compile_time_info(env, node_env, browserslist_query); + let context = + get_client_asset_context(project_path, execution_context, compile_time_info, node_env); let chunking_context = get_client_chunking_context(project_path, server_root, compile_time_info.environment()); - let entries = get_client_runtime_entries(project_path); + let entries = get_client_runtime_entries(project_path, node_env); let runtime_entries = entries.resolve_entries(context); @@ -314,3 +105,48 @@ pub async fn create_web_entry_source( .into(); Ok(graph) } + +#[turbo_tasks::function] +pub fn get_client_chunking_context( + project_path: FileSystemPathVc, + server_root: FileSystemPathVc, + environment: EnvironmentVc, +) -> ChunkingContextVc { + DevChunkingContextVc::builder( + project_path, + server_root, + server_root.join("/_chunks"), + server_root.join("/_assets"), + environment, + ) + .hot_module_replacement() + .build() +} + +#[turbo_tasks::function] +pub async fn get_client_runtime_entries( + project_path: FileSystemPathVc, + node_env: NodeEnvVc, +) -> Result { + let resolve_options_context = get_client_resolve_options_context(project_path, node_env); + + let mut runtime_entries = Vec::new(); + + let enable_react_refresh = + assert_can_resolve_react_refresh(project_path, resolve_options_context) + .await? + .as_request(); + // It's important that React Refresh come before the regular bootstrap file, + // because the bootstrap contains JSX which requires Refresh's global + // functions to be available. + if let Some(request) = enable_react_refresh { + runtime_entries.push(RuntimeEntry::Request(request, project_path.join("_")).cell()) + }; + + runtime_entries.push( + RuntimeEntry::Source(SourceAssetVc::new(embed_file_path("entry/bootstrap.ts")).into()) + .cell(), + ); + + Ok(RuntimeEntriesVc::cell(runtime_entries)) +} diff --git a/crates/turbopack-cli/src/lib.rs b/crates/turbopack-cli/src/lib.rs index 93e5a63c3a38f..1743cca88ce44 100644 --- a/crates/turbopack-cli/src/lib.rs +++ b/crates/turbopack-cli/src/lib.rs @@ -2,11 +2,14 @@ #![feature(min_specialization)] pub mod arguments; +pub(crate) mod contexts; pub mod dev; pub(crate) mod embed_js; +pub(crate) mod util; pub fn register() { turbopack::register(); + turbopack_build::register(); turbopack_dev::register(); turbopack_ecmascript_plugins::register(); include!(concat!(env!("OUT_DIR"), "/register.rs")); diff --git a/crates/turbopack-cli/src/main.rs b/crates/turbopack-cli/src/main.rs index cd070ee35445f..c03767c683de6 100644 --- a/crates/turbopack-cli/src/main.rs +++ b/crates/turbopack-cli/src/main.rs @@ -81,6 +81,7 @@ async fn main_inner(args: Arguments) -> Result<()> { register(); match args { + Arguments::Build(args) => turbopack_cli::build::build(&args).await, Arguments::Dev(args) => turbopack_cli::dev::start_server(&args).await, } } diff --git a/crates/turbopack-cli/src/util.rs b/crates/turbopack-cli/src/util.rs new file mode 100644 index 0000000000000..4622e02369ff8 --- /dev/null +++ b/crates/turbopack-cli/src/util.rs @@ -0,0 +1,69 @@ +use std::{env::current_dir, path::PathBuf}; + +use anyhow::{Context, Result}; +use dunce::canonicalize; +use turbo_tasks_fs::{DiskFileSystemVc, FileSystemVc}; + +#[turbo_tasks::value(transparent)] +pub struct EntryRequests(Vec); + +#[turbo_tasks::value(shared)] +#[derive(Clone)] +pub enum EntryRequest { + Relative(String), + Module(String, String), +} + +pub struct NormalizedDirs { + pub project_dir: String, + pub root_dir: String, +} + +pub fn normalize_dirs( + project_dir: &Option, + root_dir: &Option, +) -> Result { + let project_dir = project_dir + .as_ref() + .map(canonicalize) + .unwrap_or_else(current_dir) + .context("project directory can't be found")? + .to_str() + .context("project directory contains invalid characters")? + .to_string(); + + let root_dir = match root_dir.as_ref() { + Some(root) => canonicalize(root) + .context("root directory can't be found")? + .to_str() + .context("root directory contains invalid characters")? + .to_string(), + None => project_dir.clone(), + }; + + Ok(NormalizedDirs { + project_dir, + root_dir, + }) +} + +pub fn normalize_entries(entries: &Option>) -> Vec { + entries + .as_ref() + .cloned() + .unwrap_or_else(|| vec!["src/index".to_owned()]) +} + +#[turbo_tasks::function] +pub async fn project_fs(project_dir: &str) -> Result { + let disk_fs = DiskFileSystemVc::new("project".to_string(), project_dir.to_string()); + disk_fs.await?.start_watching()?; + Ok(disk_fs.into()) +} + +#[turbo_tasks::function] +pub async fn output_fs(project_dir: &str) -> Result { + let disk_fs = DiskFileSystemVc::new("output".to_string(), project_dir.to_string()); + disk_fs.await?.start_watching()?; + Ok(disk_fs.into()) +} diff --git a/crates/turbopack-core/src/issue/mod.rs b/crates/turbopack-core/src/issue/mod.rs index 4eff9783370f7..0d254cea5b379 100644 --- a/crates/turbopack-core/src/issue/mod.rs +++ b/crates/turbopack-core/src/issue/mod.rs @@ -9,7 +9,7 @@ use std::{ sync::Arc, }; -use anyhow::Result; +use anyhow::{anyhow, Result}; use async_trait::async_trait; use auto_hash_map::AutoSet; use turbo_tasks::{ @@ -667,10 +667,22 @@ pub struct PlainIssueProcessingPathItem { #[turbo_tasks::value_trait] pub trait IssueReporter { + /// Reports issues to the user (e.g. to stdio). Returns whether fatal + /// (program-ending) issues were present. + /// + /// # Arguments: + /// + /// * `issues` - A [ReadRef] of [CapturedIssues]. Typically obtained with + /// `IssueVc::peek_issues_with_path(source)`. + /// * `source` - The root [RawVc] from which issues are traced. Can be used + /// by implementers to determine which issues are new. + /// * `min_fatal_severity` - The minimum [IssueSeverityVc] + /// The minimum issue severity level considered to fatally end the program. fn report_issues( &self, issues: TransientInstance>, source: TransientValue, + min_fatal_severity: IssueSeverityVc, ) -> BoolVc; } @@ -703,3 +715,35 @@ where IssueVc::attach_description(description, self).await } } + +pub async fn handle_issues + CollectiblesSource + Copy>( + source: T, + issue_reporter: IssueReporterVc, + path: &Option, + operation: &Option, +) -> Result<()> { + let issues = IssueVc::peek_issues_with_path(source) + .await? + .strongly_consistent() + .await?; + + let has_fatal = issue_reporter.report_issues( + TransientInstance::new(issues.clone()), + TransientValue::new(source.into()), + IssueSeverity::Fatal.into(), + ); + + if *has_fatal.await? { + let mut message = "Fatal issue(s) occurred".to_owned(); + if let Some(path) = path.as_ref() { + message += &format!(" in {path}"); + }; + if let Some(operation) = operation.as_ref() { + message += &format!(" ({operation})"); + }; + + Err(anyhow!(message)) + } else { + Ok(()) + } +} diff --git a/crates/turbopack-core/src/reference/mod.rs b/crates/turbopack-core/src/reference/mod.rs index e2819840ffefe..c34a28741af5d 100644 --- a/crates/turbopack-core/src/reference/mod.rs +++ b/crates/turbopack-core/src/reference/mod.rs @@ -1,7 +1,11 @@ use std::collections::{HashSet, VecDeque}; use anyhow::Result; -use turbo_tasks::{primitives::StringVc, TryJoinIterExt, ValueToString, ValueToStringVc}; +use turbo_tasks::{ + graph::{AdjacencyMap, GraphTraversal}, + primitives::StringVc, + TryJoinIterExt, ValueToString, ValueToStringVc, +}; use crate::{ asset::{Asset, AssetVc, AssetsVc}, @@ -170,3 +174,34 @@ pub async fn all_assets(asset: AssetVc) -> Result { } Ok(AssetsVc::cell(assets.into_iter().collect())) } + +/// Walks the asset graph from a single asset and collect all referenced assets. +#[turbo_tasks::function] +pub async fn all_assets_from_entry(entry: AssetVc) -> Result { + Ok(AssetsVc::cell( + AdjacencyMap::new() + .skip_duplicates() + .visit([entry], get_referenced_assets) + .await + .completed()? + .into_inner() + .into_reverse_topological() + .collect(), + )) +} + +/// Computes the list of all chunk children of a given chunk. +async fn get_referenced_assets(asset: AssetVc) -> Result + Send> { + Ok(asset + .references() + .await? + .iter() + .map(|reference| async move { + let primary_assets = reference.resolve_reference().primary_assets().await?; + Ok(primary_assets.clone_value()) + }) + .try_join() + .await? + .into_iter() + .flatten()) +} diff --git a/crates/turbopack-dev-server/src/http.rs b/crates/turbopack-dev-server/src/http.rs index 195d0dcb2fed7..ee28b29f5d1cc 100644 --- a/crates/turbopack-dev-server/src/http.rs +++ b/crates/turbopack-dev-server/src/http.rs @@ -14,15 +14,16 @@ use tokio_util::io::{ReaderStream, StreamReader}; use turbo_tasks::{util::SharedError, CollectiblesSource, TransientInstance}; use turbo_tasks_bytes::Bytes; use turbo_tasks_fs::{FileContent, FileContentReadRef}; -use turbopack_core::{asset::AssetContent, issue::IssueReporterVc, version::VersionedContent}; - -use crate::{ - handle_issues, - source::{ - request::SourceRequest, - resolve::{resolve_source_request, ResolveSourceRequestResult}, - Body, ContentSourceSideEffectVc, ContentSourceVc, HeaderListReadRef, ProxyResultReadRef, - }, +use turbopack_core::{ + asset::AssetContent, + issue::{handle_issues, IssueReporterVc}, + version::VersionedContent, +}; + +use crate::source::{ + request::SourceRequest, + resolve::{resolve_source_request, ResolveSourceRequestResult}, + Body, ContentSourceSideEffectVc, ContentSourceVc, HeaderListReadRef, ProxyResultReadRef, }; #[turbo_tasks::value(serialization = "none")] @@ -76,7 +77,13 @@ pub async fn process_request_with_content_source( let original_path = request.uri().path().to_string(); let request = http_request_to_source_request(request).await?; let result = get_from_source(source, TransientInstance::new(request)); - handle_issues(result, &original_path, "get_from_source", issue_reporter).await?; + handle_issues( + result, + issue_reporter, + &Some(original_path.clone()), + &Some("get_from_source".to_owned()), + ) + .await?; let side_effects: AutoSet = result.peek_collectibles().strongly_consistent().await?; match &*result.strongly_consistent().await? { diff --git a/crates/turbopack-dev-server/src/lib.rs b/crates/turbopack-dev-server/src/lib.rs index 19bf8396e71ca..e9fd128f97e7e 100644 --- a/crates/turbopack-dev-server/src/lib.rs +++ b/crates/turbopack-dev-server/src/lib.rs @@ -20,7 +20,7 @@ use std::{ time::{Duration, Instant}, }; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result}; use hyper::{ server::{conn::AddrIncoming, Builder}, service::{make_service_fn, service_fn}, @@ -30,13 +30,10 @@ use parking_lot::Mutex; use socket2::{Domain, Protocol, Socket, Type}; use tokio::task::JoinHandle; use tracing::{event, info_span, Instrument, Level, Span}; -use turbo_tasks::{ - run_once_with_reason, trace::TraceRawVcs, util::FormatDuration, CollectiblesSource, RawVc, - TransientInstance, TransientValue, TurboTasksApi, -}; +use turbo_tasks::{run_once_with_reason, trace::TraceRawVcs, util::FormatDuration, TurboTasksApi}; use turbopack_core::{ error::PrettyPrintError, - issue::{IssueReporter, IssueReporterVc, IssueVc}, + issue::{handle_issues, IssueReporterVc}, }; use self::{source::ContentSourceVc, update::UpdateServer}; @@ -75,29 +72,6 @@ pub struct DevServer { pub future: Pin> + Send + 'static>>, } -async fn handle_issues + CollectiblesSource + Copy>( - source: T, - path: &str, - operation: &str, - issue_reporter: IssueReporterVc, -) -> Result<()> { - let issues = IssueVc::peek_issues_with_path(source) - .await? - .strongly_consistent() - .await?; - - let has_fatal = issue_reporter.report_issues( - TransientInstance::new(issues.clone()), - TransientValue::new(source.into()), - ); - - if *has_fatal.await? { - Err(anyhow!("Fatal issue(s) occurred in {path} ({operation})")) - } else { - Ok(()) - } -} - impl DevServer { pub fn listen(addr: SocketAddr) -> Result { // This is annoying. The hyper::Server doesn't allow us to know which port was @@ -232,7 +206,13 @@ impl DevServerBuilder { let uri = request.uri(); let path = uri.path().to_string(); let source = source_provider.get_source(); - handle_issues(source, &path, "get source", issue_reporter).await?; + handle_issues( + source, + issue_reporter, + &Some(path.clone()), + &Some("get source".to_owned()), + ) + .await?; let resolved_source = source.resolve_strongly_consistent().await?; let (response, side_effects) = http::process_request_with_content_source( From 2916a5835fbdfba65f54a9df8292b16d62195057 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Mon, 10 Jul 2023 13:09:14 -0700 Subject: [PATCH 02/16] fixup! turbopack-cli: modularize code to support turbopack build --- Cargo.lock | 232 +++++++++--------- Cargo.toml | 17 +- crates/turbo-tasks-memory/src/lib.rs | 4 +- .../turbo-tasks-memory/src/memory_backend.rs | 6 - 4 files changed, 120 insertions(+), 139 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 170963dde9990..5bf73de7c7f24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -669,9 +669,9 @@ dependencies = [ [[package]] name = "binding_macros" -version = "0.53.13" +version = "0.52.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ecbec28ed0caaee2843dd557762ded79b2ffddd72edcdda3d681f1f70499ffc" +checksum = "85aae362d045d63431d5680622a5c1744489e817a2da12b15e26ddd197c6d4d4" dependencies = [ "anyhow", "console_error_panic_hook", @@ -2157,13 +2157,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] -name = "dotenvs" -version = "0.1.0" +name = "dotenvy" +version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88e3201db19ec4199af513d38c49fcbc5f8ca31d268f942e97324a826c9e9fdb" -dependencies = [ - "nom", -] +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" [[package]] name = "dunce" @@ -3740,9 +3737,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.146" +version = "0.2.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" [[package]] name = "libfuzzer-sys" @@ -3959,9 +3956,9 @@ dependencies = [ [[package]] name = "mdxjs" -version = "0.1.14" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "334329b79f2a86b4e432a4f9911df72e4b7dff1164dfa3027bc7f91d60391d8f" +checksum = "97cab3971e0b25e8e1f7898690cced729d15bece11d71829aebbd9ac4764bc79" dependencies = [ "markdown", "serde", @@ -4201,9 +4198,9 @@ dependencies = [ [[package]] name = "modularize_imports" -version = "0.32.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6d9867fb9717dc6d8204d975056b09c16d675f0eced9eda5840d763316e42f4" +checksum = "499e4759b0a0e78bab1f8eff9b0dc81b93a29300a25c726c3c6051d3124e1012" dependencies = [ "convert_case 0.5.0", "handlebars", @@ -6678,9 +6675,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "styled_components" -version = "0.59.0" +version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c6f0c1fc98644e7e7c16a3c61e94e6cdd6f038ed279b38caeea150764830b48" +checksum = "fed1abe141a7d56439312e490775bab3f9418eddaf80fc3dc63bcec1ff7f3652" dependencies = [ "Inflector", "once_cell", @@ -6692,9 +6689,9 @@ dependencies = [ [[package]] name = "styled_jsx" -version = "0.36.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25417b1f81006c0c08874efccd84b23fc46d6fa0ebb91ff1081908b58851da11" +checksum = "8410f093ece751434a8a088dc705afb9d9e31294b7b0948ef32985af0ef8e38b" dependencies = [ "easy-error", "swc_core", @@ -6737,9 +6734,9 @@ dependencies = [ [[package]] name = "swc" -version = "0.264.13" +version = "0.263.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f77c84d7bb17937099e7548ebe35ebf2f35f6d5071adb24ceb78b4dddcbaed3" +checksum = "200d3e769a2241971da1773e56dce9844fa5a1db829e0f29c1fe0149ecb5acd2" dependencies = [ "ahash 0.8.3", "anyhow", @@ -6800,9 +6797,9 @@ dependencies = [ [[package]] name = "swc_atoms" -version = "0.5.7" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b1370fa1d31e18a999928aaf18f166616b16c5cb7033ced7d50d06858c5fd90" +checksum = "93d0307dc4bfd107d49c7528350c372758cfca94fb503629b9a056e6a1572860" dependencies = [ "bytecheck", "once_cell", @@ -6816,9 +6813,9 @@ dependencies = [ [[package]] name = "swc_bundler" -version = "0.217.11" +version = "0.216.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c126fe44ef25de31c73db1874a0feeece8941bafbdfb3778e4af9367c3ac2c2b" +checksum = "3790ae7674ba531e202f8a66ad1e77209bfa37626880baf878623549bc89988b" dependencies = [ "ahash 0.8.3", "anyhow", @@ -6863,9 +6860,9 @@ dependencies = [ [[package]] name = "swc_common" -version = "0.31.17" +version = "0.31.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1362dec11e2270048e686f0c7d4a9087fcf1ec9d27147c2c226929a806a86f6" +checksum = "c6414bd4e553f5638961d39b07075ffd37a3d63176829592f4a5900260d94ca1" dependencies = [ "ahash 0.8.3", "anyhow", @@ -6922,9 +6919,9 @@ dependencies = [ [[package]] name = "swc_core" -version = "0.79.14" +version = "0.78.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ac072ebc8e6bdaae0a0f93fa2ba2dc922a24ffbe9f58bd27f28109627e5cb3e" +checksum = "b1c8eff9a6e54701c8ca355e74cb63cf10c1f6909ed371812e57cd9b77b49dfc" dependencies = [ "binding_macros", "swc", @@ -6967,9 +6964,9 @@ dependencies = [ [[package]] name = "swc_css_ast" -version = "0.137.17" +version = "0.137.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2849f35c43fb71d93bc5b714fc68bd1f1397260ac30464def1d4b2ca5ba009d" +checksum = "831e96c2b01bb4ce74ee645ed408ae1193f796dc223e3f031a39e0888458109a" dependencies = [ "is-macro", "serde", @@ -6980,9 +6977,9 @@ dependencies = [ [[package]] name = "swc_css_codegen" -version = "0.147.20" +version = "0.147.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5382a1daf95fbada1557c071dd128b318a89b4691be6ef2ef72e9bec25464a6c" +checksum = "3bf63fb602ed28ad13eb257310768883353256e26a35c54ac797708041fab74a" dependencies = [ "auto_impl", "bitflags 2.3.3", @@ -7010,9 +7007,9 @@ dependencies = [ [[package]] name = "swc_css_compat" -version = "0.23.20" +version = "0.23.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b726d00ffb8087868cf0838d77d9b0ee464bb66620f454fbe99b004b80664785" +checksum = "d6e76b3c13f35567f56fb942e236caba34f8fef80793dc78b48e855331aabc34" dependencies = [ "bitflags 2.3.3", "once_cell", @@ -7027,9 +7024,9 @@ dependencies = [ [[package]] name = "swc_css_modules" -version = "0.25.22" +version = "0.25.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1794ac13a81298794c4976561850dfd29a3569fcb06247694bec0ae2e664e7de" +checksum = "a76b35fa8a326f115aaa22ef0c936318656d0f74fbd63320b2a6bbf26b4073c6" dependencies = [ "rustc-hash", "serde", @@ -7043,9 +7040,9 @@ dependencies = [ [[package]] name = "swc_css_parser" -version = "0.146.20" +version = "0.146.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb6aca886d7b3af087d237435eaca5f20978e82e2a4896508b07ff1b0daec80" +checksum = "96d6771dd85849f88ee2d3b3d3a0a68f96da08655e28e592bcc1f475abbbf499" dependencies = [ "lexical", "serde", @@ -7056,9 +7053,9 @@ dependencies = [ [[package]] name = "swc_css_prefixer" -version = "0.149.22" +version = "0.149.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e67ddded029f69740b2658845156cf70926c8eabb9ad8d653b140cfe6a4aae" +checksum = "336c74df93a96c1c6cea34de4808edaa47e07a88fccaeecb83ec9d3fa74794bb" dependencies = [ "once_cell", "preset_env_base", @@ -7073,9 +7070,9 @@ dependencies = [ [[package]] name = "swc_css_utils" -version = "0.134.17" +version = "0.134.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "893da84df13388c147b47d9f0b059daf9472560431908c304055527158b996e3" +checksum = "4cb7228a02c5bcafaeb20f617a57c407e01e923c12a9450dc8f5dd04b36286bd" dependencies = [ "once_cell", "serde", @@ -7088,9 +7085,9 @@ dependencies = [ [[package]] name = "swc_css_visit" -version = "0.136.17" +version = "0.136.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "012a1a07cf04141aef2cfb325f61677c52827ca69670878b20b10694d6e79377" +checksum = "22cafb39c7c10822e2c9ff308534dfbaf371226600f87a8f4e85b405b15d8a25" dependencies = [ "serde", "swc_atoms", @@ -7101,9 +7098,9 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.107.1" +version = "0.106.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0388ff4b0a5b08277c20d88ae630ff3a0c7c8cdd0d5bc843854fa802740fcf2" +checksum = "ebf4d6804b1da4146c4c0359d129e3dd43568d321f69d7953d9abbca4ded76ba" dependencies = [ "bitflags 2.3.3", "bytecheck", @@ -7120,9 +7117,9 @@ dependencies = [ [[package]] name = "swc_ecma_codegen" -version = "0.142.2" +version = "0.141.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f07839021e70d0970cd3565b3968e168db557f7c1cf190fa66e93f87670531" +checksum = "d3845e22d8593a617b973b5f65f3567170b41eb964a70a267b1ec4995dfe5013" dependencies = [ "memchr", "num-bigint", @@ -7152,9 +7149,9 @@ dependencies = [ [[package]] name = "swc_ecma_ext_transforms" -version = "0.106.2" +version = "0.105.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a7cfadf376146453fe38e68aa3717cb29dd1fe2207557be66104bf363a7348" +checksum = "0c3ae43df15bac02f1cded6754041da244a21688fd39cf876984f78b8856c76c" dependencies = [ "phf", "swc_atoms", @@ -7166,9 +7163,9 @@ dependencies = [ [[package]] name = "swc_ecma_lints" -version = "0.85.2" +version = "0.84.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b900cff7482189e87ae053ccc35cebafc2549b50571ec1e1fcc4c6e963e848ee" +checksum = "300cc5f51b8a3cc81758fdc34192552a97dff46716f9e1d7d6bf73ee922f3431" dependencies = [ "ahash 0.8.3", "auto_impl", @@ -7187,9 +7184,9 @@ dependencies = [ [[package]] name = "swc_ecma_loader" -version = "0.43.19" +version = "0.43.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8471c19803c2645652fb0c58defde954962a9f760d3a9cbfc5d56f2a9e81c1a5" +checksum = "8d40f8d1626b33ba85ee17f43268b3bb6382278b9d3a3c1faa52c57e71769a60" dependencies = [ "ahash 0.8.3", "anyhow", @@ -7209,9 +7206,9 @@ dependencies = [ [[package]] name = "swc_ecma_minifier" -version = "0.184.11" +version = "0.183.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aecc16ea061975c71b5397a6a26281598bc5a95e30b5e77093c54f74fbbfcace" +checksum = "43aeb22753ff453bfdabdd8ba19cdf1ada40bf3ce651153cc0863374322f66ef" dependencies = [ "ahash 0.8.3", "arrayvec 0.7.2", @@ -7245,9 +7242,9 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "0.137.2" +version = "0.136.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae92607eb63b82b716129c5497f11a6ebc083a27fb87ece66b2d79954b01ea1c" +checksum = "45d40421c607d7a48334f78a9b24a5cbde1f36250f9986746ec082208d68b39f" dependencies = [ "either", "lexical", @@ -7265,9 +7262,9 @@ dependencies = [ [[package]] name = "swc_ecma_preset_env" -version = "0.198.8" +version = "0.197.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "007e47b9cdfda13273aed07f48bd26753bd18d3a34e8dfce106c427f9431cf19" +checksum = "e8c4d926e3772345fd2abe5058915f21250e145f9c312462a98ad5201e687f7a" dependencies = [ "ahash 0.8.3", "anyhow", @@ -7290,9 +7287,9 @@ dependencies = [ [[package]] name = "swc_ecma_quote_macros" -version = "0.48.2" +version = "0.47.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891104ddecaa64a0c59ae9b39d01a6dbe1a7b8bdfe97556a57b76a835f5c3852" +checksum = "f583b2bd7fb8d3def4313912008111044bbd16cd9a10ee9c009d69eaa8e558ba" dependencies = [ "anyhow", "pmutil", @@ -7308,9 +7305,9 @@ dependencies = [ [[package]] name = "swc_ecma_testing" -version = "0.20.14" +version = "0.20.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "489ad595d4d75fa270d0ca8589a97f338cc7a00ddb327d748269c7fe0403391e" +checksum = "b90ea04390a92f949fbf2d3c411bc7ab82c0981dea04cc18fe6ae1a4e471f121" dependencies = [ "anyhow", "hex", @@ -7321,9 +7318,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms" -version = "0.221.7" +version = "0.220.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f951972ade23dcd5d81a7c0ed7b54f065e1d01f93774881a9ff91479c5aa2f8c" +checksum = "9cfb7ec24e83d284b33b30e2b343262078fdb8382b5340858426b12b6aab8d21" dependencies = [ "swc_atoms", "swc_common", @@ -7341,9 +7338,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.130.2" +version = "0.129.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "780de0309bd17e76563a6e3416824f9e808079b24c80ac9a1de8094dd96f0512" +checksum = "ef3d6800cc1500dfb6983cefac6c6dbf0ea8b2af8dcb1d2e25cae01226479744" dependencies = [ "better_scoped_tls", "bitflags 2.3.3", @@ -7365,9 +7362,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_classes" -version = "0.119.2" +version = "0.118.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84eb1ab0d711131b05c1b430968c4ba059156d0d31fe2e0d6a0395b12addddc9" +checksum = "cd5380415af454bcc6dc9de726064186adc65e6be20eb9c9eb49b0b6d518e361" dependencies = [ "swc_atoms", "swc_common", @@ -7379,9 +7376,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_compat" -version = "0.156.6" +version = "0.155.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3efe68482ff6f461d43adef55f492bb15f66a8f1fe42794b7332ef6a429a630" +checksum = "900373ed4e2ce81d58152b781f5fe37e0b5ba1989805e8a60d97981c4d189a22" dependencies = [ "ahash 0.8.3", "arrayvec 0.7.2", @@ -7419,9 +7416,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_module" -version = "0.173.6" +version = "0.172.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c6a9bc72e0e47b80f5c767a5ea5d454c885d6e37ec041013c9838933cde2878" +checksum = "c3c98365d03820a51eacba68cd703460f1c36b09ed81cd99cb93d1088f92dc35" dependencies = [ "Inflector", "ahash 0.8.3", @@ -7447,9 +7444,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_optimization" -version = "0.190.7" +version = "0.189.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e749cd7eb3cbe02201123da7ecdb0fef91ceba7ac27e795828425e37e1d560f" +checksum = "89756d0ace7efd6acd7223e19e19d789765f95112f247436b7ab42ac9cfae68b" dependencies = [ "ahash 0.8.3", "dashmap", @@ -7473,9 +7470,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_proposal" -version = "0.164.6" +version = "0.163.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b6ecf57711fa307af891776d3398521bfac518c9d304ab91257b7cdb052eeb" +checksum = "6492a52ff1a98f36a12155f865db58bbfcae5fca77e76545cccd5ebcc77bd780" dependencies = [ "either", "rustc-hash", @@ -7493,9 +7490,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_react" -version = "0.176.6" +version = "0.175.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "506abc97a5ace7313d62cf2c884a7ff5f9c8e6cc02faebeabc522820f83db038" +checksum = "67bc38b58cb66cbfd1ad9440073289a3d827b8b1fd2831126f1a3bfae99ec430" dependencies = [ "ahash 0.8.3", "base64 0.13.1", @@ -7519,9 +7516,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_testing" -version = "0.133.2" +version = "0.132.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31fa20bd9ddcad28e21cfc30dcf2abd881ecffafe9b9333e71f46028474796a7" +checksum = "857ed24bc19b38c311c6e479685d00d32052babc8a25db4cef26f0aa28c2b5d8" dependencies = [ "ansi_term", "anyhow", @@ -7545,9 +7542,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_typescript" -version = "0.180.6" +version = "0.179.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330e6572237c2b5edfdc72169cddb23b83abb970d6580bd1c59a3edf16242745" +checksum = "4e235c8b8fdac92de7255b40912077680106ff89de5d8595415d516f389fb9d0" dependencies = [ "serde", "swc_atoms", @@ -7561,9 +7558,9 @@ dependencies = [ [[package]] name = "swc_ecma_usage_analyzer" -version = "0.16.3" +version = "0.15.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b04e9b497be4134b2f4aac798f1379f0ba67d0e0a43293b761e3a7a99fa95ed6" +checksum = "711413fa43abee9fc5c2ca9b626676685c37d95b27f4ae532834e582379b7e85" dependencies = [ "ahash 0.8.3", "indexmap", @@ -7579,9 +7576,9 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.120.2" +version = "0.119.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c9203b881a2bd07de18db0d5cb8df5dfada81efafc4be4cd74674215258033" +checksum = "452c66399edeb88a97bfdc3bbf11e45db85fdf883bfd4fc8bdd93abb92152b9b" dependencies = [ "indexmap", "num_cpus", @@ -7598,9 +7595,9 @@ dependencies = [ [[package]] name = "swc_ecma_visit" -version = "0.93.1" +version = "0.92.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffd98eaa16ea4d829f5636682dd61af01f81689a9f0ed5166b32c25b52f270b5" +checksum = "0f61da6cac0ec3b7e62d367cfbd9e38e078a4601271891ad94f0dac5ff69f839" dependencies = [ "num-bigint", "swc_atoms", @@ -7612,9 +7609,9 @@ dependencies = [ [[package]] name = "swc_emotion" -version = "0.35.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0ab51e2b0d4267a96059213c4985737d1ae70dca8396664fd177012452d39d3" +checksum = "349a12bfaf34e2e5a44fb802d749dab0abdd7fb8fd4492235f68d4ed51cfd7e8" dependencies = [ "base64 0.13.1", "byteorder", @@ -7642,9 +7639,9 @@ dependencies = [ [[package]] name = "swc_error_reporters" -version = "0.15.17" +version = "0.15.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7d96ecd63299674716990592f326c483632aa52dceec85229ee22728499942e" +checksum = "108322b719696e8c368c39dc6d8748494ea2aa870e7d80ea5956078aa6b4dd4d" dependencies = [ "anyhow", "miette 4.7.1", @@ -7655,9 +7652,9 @@ dependencies = [ [[package]] name = "swc_fast_graph" -version = "0.19.17" +version = "0.19.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416ee48930bc32634f2f0139e2fe7107dbc0c990d61c99cb581edd199e0fcb88" +checksum = "b19b76468219b923c34efdeff812fa951fe1a1ecaba78118b013d034a1669ff5" dependencies = [ "indexmap", "petgraph", @@ -7667,9 +7664,9 @@ dependencies = [ [[package]] name = "swc_graph_analyzer" -version = "0.20.20" +version = "0.20.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d11018acd5f325876666d4eba2b036ad08e421f50b129a00d3c6dfe1aa9f67fa" +checksum = "ef31e002bc3980147948c2140fcac4f557daef5dacb7d145cda254cad7aa269b" dependencies = [ "ahash 0.8.3", "auto_impl", @@ -7702,9 +7699,9 @@ dependencies = [ [[package]] name = "swc_node_comments" -version = "0.18.17" +version = "0.18.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "996dba81c8646dd79a0a885bcf6030828e20e6cfa7b2d6257bc23c128993b67c" +checksum = "61839f8a936b5c95ce644d539914bb944b094eee9bd156c3dc41fe8e7eaa84ea" dependencies = [ "ahash 0.8.3", "dashmap", @@ -7728,9 +7725,9 @@ dependencies = [ [[package]] name = "swc_plugin_proxy" -version = "0.36.1" +version = "0.35.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f43a74678e15a200724919644724492b698fa8b51156bbe70831b659068382" +checksum = "c37badc5ab20a495dff7a095b662657397f0c0658fea0576ecaa49fdb747cce1" dependencies = [ "better_scoped_tls", "rkyv", @@ -7742,9 +7739,9 @@ dependencies = [ [[package]] name = "swc_plugin_runner" -version = "0.98.3" +version = "0.97.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d74d941fc1c4c27e704516b9a9ebb620680fabd3db65a5e215cd81dd44f14718" +checksum = "03768d1eb0d37d6b44da689f1ab5126885844ac154ade03b14c8b6b06eeeacc1" dependencies = [ "anyhow", "enumset", @@ -7766,9 +7763,9 @@ dependencies = [ [[package]] name = "swc_relay" -version = "0.7.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc70926fbbd0865af837c88edfcd84af24386ce647a2b56c0c6e471e42ba3a4b" +checksum = "b372065bf36e8047d6d8d84aabc59966539507fd13a9da03f6e54af88a072134" dependencies = [ "once_cell", "regex", @@ -7781,9 +7778,9 @@ dependencies = [ [[package]] name = "swc_timer" -version = "0.19.20" +version = "0.19.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6e1334b8d2edbdd12de67b3f065d940f0afdf47bd84d34f5ada92280669b4f8" +checksum = "9889bf48909289e13e0f343eb8d1238e674e9380a4dd6c6346f62b83cb30236f" dependencies = [ "tracing", ] @@ -8052,9 +8049,9 @@ dependencies = [ [[package]] name = "testing" -version = "0.33.20" +version = "0.33.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f171e44c58e6e710675665cbe48b8996118f2751ca057d448bc02351ee8e0b0" +checksum = "359d2548f4919624af6cd1001e0a3ac9f081f8312e47fdca7650c11c9935981b" dependencies = [ "ansi_term", "cargo_metadata", @@ -8781,7 +8778,7 @@ name = "turbo-tasks-env" version = "0.1.0" dependencies = [ "anyhow", - "dotenvs", + "dotenvy", "indexmap", "serde", "turbo-tasks", @@ -8840,7 +8837,6 @@ dependencies = [ "turbo-tasks-build", "turbo-tasks-hash", "turbo-tasks-memory", - "turbo-tasks-testing", ] [[package]] @@ -8928,7 +8924,6 @@ version = "0.1.0" dependencies = [ "anyhow", "auto-hash-map", - "futures", "lazy_static", "tokio", "turbo-tasks", @@ -9113,7 +9108,6 @@ dependencies = [ "turbo-tasks-memory", "turbopack", "turbopack-bench", - "turbopack-build", "turbopack-cli-utils", "turbopack-core", "turbopack-dev", @@ -9486,7 +9480,6 @@ version = "0.1.0" dependencies = [ "anyhow", "once_cell", - "serde", "similar", "turbo-tasks", "turbo-tasks-build", @@ -9501,7 +9494,6 @@ version = "0.1.0" dependencies = [ "anyhow", "dunce", - "futures", "once_cell", "serde", "serde_json", @@ -9509,7 +9501,6 @@ dependencies = [ "tokio", "turbo-tasks", "turbo-tasks-build", - "turbo-tasks-bytes", "turbo-tasks-env", "turbo-tasks-fs", "turbo-tasks-memory", @@ -9520,7 +9511,6 @@ dependencies = [ "turbopack-ecmascript-plugins", "turbopack-ecmascript-runtime", "turbopack-env", - "turbopack-node", "turbopack-test-utils", ] @@ -9562,9 +9552,7 @@ dependencies = [ "camino", "chrono", "dunce", - "hex", "lazy_static", - "libc", "os_str_bytes", "path-clean 1.0.1", "petgraph", @@ -9753,8 +9741,8 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 1.0.0", - "rand 0.8.5", + "cfg-if 0.1.10", + "rand 0.4.6", "static_assertions", ] diff --git a/Cargo.toml b/Cargo.toml index 9911d4d98f8b9..c00c964f06bb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,14 +75,14 @@ lto = "off" [workspace.dependencies] # Keep consistent with preset_env_base through swc_core browserslist-rs = { version = "0.12.2" } -mdxjs = { version = "0.1.14" } -modularize_imports = { version = "0.32.0" } -styled_components = { version = "0.59.0" } -styled_jsx = { version = "0.36.0" } -swc_core = { version = "0.79.14" } -swc_emotion = { version = "0.35.0" } -swc_relay = { version = "0.7.0" } -testing = { version = "0.33.20" } +mdxjs = { version = "0.1.13" } +modularize_imports = { version = "0.31.0" } +styled_components = { version = "0.58.0" } +styled_jsx = { version = "0.35.0" } +swc_core = { version = "0.78.24" } +swc_emotion = { version = "0.34.0" } +swc_relay = { version = "0.6.0" } +testing = { version = "0.33.14" } auto-hash-map = { path = "crates/turbo-tasks-auto-hash-map" } node-file-trace = { path = "crates/node-file-trace", default-features = false } @@ -177,7 +177,6 @@ dialoguer = "0.10.3" dunce = "1.0.3" futures = "0.3.26" futures-retry = "0.6.0" -hex = "0.4.3" httpmock = { version = "0.6.7", default-features = false } image = { version = "0.24.6", default-features = false } indexmap = "1.9.2" diff --git a/crates/turbo-tasks-memory/src/lib.rs b/crates/turbo-tasks-memory/src/lib.rs index e4de44442c7ec..72080c065b3a1 100644 --- a/crates/turbo-tasks-memory/src/lib.rs +++ b/crates/turbo-tasks-memory/src/lib.rs @@ -13,7 +13,7 @@ mod count_hash_set; mod gc; mod map_guard; mod memory_backend; -// mod memory_backend_with_pg; +mod memory_backend_with_pg; mod output; mod priority_pair; pub mod scope; @@ -22,4 +22,4 @@ mod task; pub mod viz; pub use memory_backend::MemoryBackend; -// pub use memory_backend_with_pg::MemoryBackendWithPersistedGraph; +pub use memory_backend_with_pg::MemoryBackendWithPersistedGraph; diff --git a/crates/turbo-tasks-memory/src/memory_backend.rs b/crates/turbo-tasks-memory/src/memory_backend.rs index 87a6077ec1c36..e0be9f90ed217 100644 --- a/crates/turbo-tasks-memory/src/memory_backend.rs +++ b/crates/turbo-tasks-memory/src/memory_backend.rs @@ -664,12 +664,6 @@ impl Backend for MemoryBackend { let task_type = Arc::new(task_type); // slow pass with key lock let id = turbo_tasks.get_fresh_task_id(); - // eprintln!( - // "Created {} ({}) with parent {}", - // task_name, - // *unsafe { id.get_unchecked() }, - // parent_task - // ); let task = Task::new_persistent( // Safety: That task will hold the value, but we are still in // control of the task From 14871406d867004343238e8a82f31835eaded913 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Mon, 10 Jul 2023 13:09:55 -0700 Subject: [PATCH 03/16] fixup! fixup! turbopack-cli: modularize code to support turbopack build --- Cargo.lock | 247 +++++++++++++++++++++++++++++------------------------ Cargo.toml | 19 +++-- 2 files changed, 144 insertions(+), 122 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5bf73de7c7f24..397175218422f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -669,9 +669,9 @@ dependencies = [ [[package]] name = "binding_macros" -version = "0.52.26" +version = "0.53.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85aae362d045d63431d5680622a5c1744489e817a2da12b15e26ddd197c6d4d4" +checksum = "624f5dbcd82b932d9f9f959fec4ce89a1fd67a6e4e141bad66f01673704045cb" dependencies = [ "anyhow", "console_error_panic_hook", @@ -2157,10 +2157,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" [[package]] -name = "dotenvy" -version = "0.15.7" +name = "dotenvs" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +checksum = "88e3201db19ec4199af513d38c49fcbc5f8ca31d268f942e97324a826c9e9fdb" +dependencies = [ + "nom", +] [[package]] name = "dunce" @@ -3012,6 +3015,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + [[package]] name = "hostname" version = "0.3.1" @@ -3737,9 +3749,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.144" +version = "0.2.146" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" +checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" [[package]] name = "libfuzzer-sys" @@ -3956,9 +3968,9 @@ dependencies = [ [[package]] name = "mdxjs" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97cab3971e0b25e8e1f7898690cced729d15bece11d71829aebbd9ac4764bc79" +checksum = "334329b79f2a86b4e432a4f9911df72e4b7dff1164dfa3027bc7f91d60391d8f" dependencies = [ "markdown", "serde", @@ -4198,9 +4210,9 @@ dependencies = [ [[package]] name = "modularize_imports" -version = "0.31.0" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "499e4759b0a0e78bab1f8eff9b0dc81b93a29300a25c726c3c6051d3124e1012" +checksum = "c6d9867fb9717dc6d8204d975056b09c16d675f0eced9eda5840d763316e42f4" dependencies = [ "convert_case 0.5.0", "handlebars", @@ -5253,9 +5265,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.59" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" dependencies = [ "unicode-ident", ] @@ -6675,9 +6687,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "styled_components" -version = "0.58.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed1abe141a7d56439312e490775bab3f9418eddaf80fc3dc63bcec1ff7f3652" +checksum = "8c6f0c1fc98644e7e7c16a3c61e94e6cdd6f038ed279b38caeea150764830b48" dependencies = [ "Inflector", "once_cell", @@ -6689,9 +6701,9 @@ dependencies = [ [[package]] name = "styled_jsx" -version = "0.35.0" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8410f093ece751434a8a088dc705afb9d9e31294b7b0948ef32985af0ef8e38b" +checksum = "25417b1f81006c0c08874efccd84b23fc46d6fa0ebb91ff1081908b58851da11" dependencies = [ "easy-error", "swc_core", @@ -6734,9 +6746,9 @@ dependencies = [ [[package]] name = "swc" -version = "0.263.26" +version = "0.264.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "200d3e769a2241971da1773e56dce9844fa5a1db829e0f29c1fe0149ecb5acd2" +checksum = "176cdf854d438bd39aee0dec1f84c053cb7978402b11133f60fbb77453ed020d" dependencies = [ "ahash 0.8.3", "anyhow", @@ -6797,9 +6809,9 @@ dependencies = [ [[package]] name = "swc_atoms" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93d0307dc4bfd107d49c7528350c372758cfca94fb503629b9a056e6a1572860" +checksum = "3b1370fa1d31e18a999928aaf18f166616b16c5cb7033ced7d50d06858c5fd90" dependencies = [ "bytecheck", "once_cell", @@ -6813,9 +6825,9 @@ dependencies = [ [[package]] name = "swc_bundler" -version = "0.216.23" +version = "0.217.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3790ae7674ba531e202f8a66ad1e77209bfa37626880baf878623549bc89988b" +checksum = "0d196673157f333f730602745b208feeee82da239b6defc5b962e68291bd570b" dependencies = [ "ahash 0.8.3", "anyhow", @@ -6860,9 +6872,9 @@ dependencies = [ [[package]] name = "swc_common" -version = "0.31.16" +version = "0.31.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6414bd4e553f5638961d39b07075ffd37a3d63176829592f4a5900260d94ca1" +checksum = "e1362dec11e2270048e686f0c7d4a9087fcf1ec9d27147c2c226929a806a86f6" dependencies = [ "ahash 0.8.3", "anyhow", @@ -6919,9 +6931,9 @@ dependencies = [ [[package]] name = "swc_core" -version = "0.78.26" +version = "0.79.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c8eff9a6e54701c8ca355e74cb63cf10c1f6909ed371812e57cd9b77b49dfc" +checksum = "3fad8d1f1abb42719a841f76915e7d2d573e2f9f0462e26dedca847e9ad7b1e4" dependencies = [ "binding_macros", "swc", @@ -6964,9 +6976,9 @@ dependencies = [ [[package]] name = "swc_css_ast" -version = "0.137.16" +version = "0.137.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "831e96c2b01bb4ce74ee645ed408ae1193f796dc223e3f031a39e0888458109a" +checksum = "a2849f35c43fb71d93bc5b714fc68bd1f1397260ac30464def1d4b2ca5ba009d" dependencies = [ "is-macro", "serde", @@ -6977,9 +6989,9 @@ dependencies = [ [[package]] name = "swc_css_codegen" -version = "0.147.19" +version = "0.147.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bf63fb602ed28ad13eb257310768883353256e26a35c54ac797708041fab74a" +checksum = "5382a1daf95fbada1557c071dd128b318a89b4691be6ef2ef72e9bec25464a6c" dependencies = [ "auto_impl", "bitflags 2.3.3", @@ -7007,9 +7019,9 @@ dependencies = [ [[package]] name = "swc_css_compat" -version = "0.23.19" +version = "0.23.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6e76b3c13f35567f56fb942e236caba34f8fef80793dc78b48e855331aabc34" +checksum = "b726d00ffb8087868cf0838d77d9b0ee464bb66620f454fbe99b004b80664785" dependencies = [ "bitflags 2.3.3", "once_cell", @@ -7024,9 +7036,9 @@ dependencies = [ [[package]] name = "swc_css_modules" -version = "0.25.20" +version = "0.25.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a76b35fa8a326f115aaa22ef0c936318656d0f74fbd63320b2a6bbf26b4073c6" +checksum = "1794ac13a81298794c4976561850dfd29a3569fcb06247694bec0ae2e664e7de" dependencies = [ "rustc-hash", "serde", @@ -7040,9 +7052,9 @@ dependencies = [ [[package]] name = "swc_css_parser" -version = "0.146.19" +version = "0.146.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d6771dd85849f88ee2d3b3d3a0a68f96da08655e28e592bcc1f475abbbf499" +checksum = "5bb6aca886d7b3af087d237435eaca5f20978e82e2a4896508b07ff1b0daec80" dependencies = [ "lexical", "serde", @@ -7053,9 +7065,9 @@ dependencies = [ [[package]] name = "swc_css_prefixer" -version = "0.149.21" +version = "0.149.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "336c74df93a96c1c6cea34de4808edaa47e07a88fccaeecb83ec9d3fa74794bb" +checksum = "56e67ddded029f69740b2658845156cf70926c8eabb9ad8d653b140cfe6a4aae" dependencies = [ "once_cell", "preset_env_base", @@ -7070,9 +7082,9 @@ dependencies = [ [[package]] name = "swc_css_utils" -version = "0.134.16" +version = "0.134.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cb7228a02c5bcafaeb20f617a57c407e01e923c12a9450dc8f5dd04b36286bd" +checksum = "893da84df13388c147b47d9f0b059daf9472560431908c304055527158b996e3" dependencies = [ "once_cell", "serde", @@ -7085,9 +7097,9 @@ dependencies = [ [[package]] name = "swc_css_visit" -version = "0.136.16" +version = "0.136.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cafb39c7c10822e2c9ff308534dfbaf371226600f87a8f4e85b405b15d8a25" +checksum = "012a1a07cf04141aef2cfb325f61677c52827ca69670878b20b10694d6e79377" dependencies = [ "serde", "swc_atoms", @@ -7098,9 +7110,9 @@ dependencies = [ [[package]] name = "swc_ecma_ast" -version = "0.106.6" +version = "0.107.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebf4d6804b1da4146c4c0359d129e3dd43568d321f69d7953d9abbca4ded76ba" +checksum = "e0388ff4b0a5b08277c20d88ae630ff3a0c7c8cdd0d5bc843854fa802740fcf2" dependencies = [ "bitflags 2.3.3", "bytecheck", @@ -7117,9 +7129,9 @@ dependencies = [ [[package]] name = "swc_ecma_codegen" -version = "0.141.11" +version = "0.142.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3845e22d8593a617b973b5f65f3567170b41eb964a70a267b1ec4995dfe5013" +checksum = "62f07839021e70d0970cd3565b3968e168db557f7c1cf190fa66e93f87670531" dependencies = [ "memchr", "num-bigint", @@ -7149,9 +7161,9 @@ dependencies = [ [[package]] name = "swc_ecma_ext_transforms" -version = "0.105.10" +version = "0.106.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c3ae43df15bac02f1cded6754041da244a21688fd39cf876984f78b8856c76c" +checksum = "09a7cfadf376146453fe38e68aa3717cb29dd1fe2207557be66104bf363a7348" dependencies = [ "phf", "swc_atoms", @@ -7163,9 +7175,9 @@ dependencies = [ [[package]] name = "swc_ecma_lints" -version = "0.84.14" +version = "0.85.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "300cc5f51b8a3cc81758fdc34192552a97dff46716f9e1d7d6bf73ee922f3431" +checksum = "b900cff7482189e87ae053ccc35cebafc2549b50571ec1e1fcc4c6e963e848ee" dependencies = [ "ahash 0.8.3", "auto_impl", @@ -7184,9 +7196,9 @@ dependencies = [ [[package]] name = "swc_ecma_loader" -version = "0.43.18" +version = "0.43.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d40f8d1626b33ba85ee17f43268b3bb6382278b9d3a3c1faa52c57e71769a60" +checksum = "8471c19803c2645652fb0c58defde954962a9f760d3a9cbfc5d56f2a9e81c1a5" dependencies = [ "ahash 0.8.3", "anyhow", @@ -7206,9 +7218,9 @@ dependencies = [ [[package]] name = "swc_ecma_minifier" -version = "0.183.23" +version = "0.184.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43aeb22753ff453bfdabdd8ba19cdf1ada40bf3ce651153cc0863374322f66ef" +checksum = "87d541b5632bb93d71ea47518075c357afacb86adfe782922f1060f9a995fd29" dependencies = [ "ahash 0.8.3", "arrayvec 0.7.2", @@ -7242,9 +7254,9 @@ dependencies = [ [[package]] name = "swc_ecma_parser" -version = "0.136.8" +version = "0.137.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45d40421c607d7a48334f78a9b24a5cbde1f36250f9986746ec082208d68b39f" +checksum = "ae92607eb63b82b716129c5497f11a6ebc083a27fb87ece66b2d79954b01ea1c" dependencies = [ "either", "lexical", @@ -7262,9 +7274,9 @@ dependencies = [ [[package]] name = "swc_ecma_preset_env" -version = "0.197.20" +version = "0.198.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c4d926e3772345fd2abe5058915f21250e145f9c312462a98ad5201e687f7a" +checksum = "007e47b9cdfda13273aed07f48bd26753bd18d3a34e8dfce106c427f9431cf19" dependencies = [ "ahash 0.8.3", "anyhow", @@ -7287,9 +7299,9 @@ dependencies = [ [[package]] name = "swc_ecma_quote_macros" -version = "0.47.8" +version = "0.48.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f583b2bd7fb8d3def4313912008111044bbd16cd9a10ee9c009d69eaa8e558ba" +checksum = "891104ddecaa64a0c59ae9b39d01a6dbe1a7b8bdfe97556a57b76a835f5c3852" dependencies = [ "anyhow", "pmutil", @@ -7305,9 +7317,9 @@ dependencies = [ [[package]] name = "swc_ecma_testing" -version = "0.20.13" +version = "0.20.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b90ea04390a92f949fbf2d3c411bc7ab82c0981dea04cc18fe6ae1a4e471f121" +checksum = "489ad595d4d75fa270d0ca8589a97f338cc7a00ddb327d748269c7fe0403391e" dependencies = [ "anyhow", "hex", @@ -7318,9 +7330,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms" -version = "0.220.19" +version = "0.221.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cfb7ec24e83d284b33b30e2b343262078fdb8382b5340858426b12b6aab8d21" +checksum = "f951972ade23dcd5d81a7c0ed7b54f065e1d01f93774881a9ff91479c5aa2f8c" dependencies = [ "swc_atoms", "swc_common", @@ -7338,9 +7350,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_base" -version = "0.129.14" +version = "0.130.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef3d6800cc1500dfb6983cefac6c6dbf0ea8b2af8dcb1d2e25cae01226479744" +checksum = "780de0309bd17e76563a6e3416824f9e808079b24c80ac9a1de8094dd96f0512" dependencies = [ "better_scoped_tls", "bitflags 2.3.3", @@ -7362,9 +7374,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_classes" -version = "0.118.14" +version = "0.119.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd5380415af454bcc6dc9de726064186adc65e6be20eb9c9eb49b0b6d518e361" +checksum = "84eb1ab0d711131b05c1b430968c4ba059156d0d31fe2e0d6a0395b12addddc9" dependencies = [ "swc_atoms", "swc_common", @@ -7376,9 +7388,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_compat" -version = "0.155.17" +version = "0.156.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900373ed4e2ce81d58152b781f5fe37e0b5ba1989805e8a60d97981c4d189a22" +checksum = "d3efe68482ff6f461d43adef55f492bb15f66a8f1fe42794b7332ef6a429a630" dependencies = [ "ahash 0.8.3", "arrayvec 0.7.2", @@ -7416,9 +7428,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_module" -version = "0.172.18" +version = "0.173.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c98365d03820a51eacba68cd703460f1c36b09ed81cd99cb93d1088f92dc35" +checksum = "6c6a9bc72e0e47b80f5c767a5ea5d454c885d6e37ec041013c9838933cde2878" dependencies = [ "Inflector", "ahash 0.8.3", @@ -7444,9 +7456,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_optimization" -version = "0.189.19" +version = "0.190.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89756d0ace7efd6acd7223e19e19d789765f95112f247436b7ab42ac9cfae68b" +checksum = "2e749cd7eb3cbe02201123da7ecdb0fef91ceba7ac27e795828425e37e1d560f" dependencies = [ "ahash 0.8.3", "dashmap", @@ -7470,9 +7482,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_proposal" -version = "0.163.17" +version = "0.164.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6492a52ff1a98f36a12155f865db58bbfcae5fca77e76545cccd5ebcc77bd780" +checksum = "47b6ecf57711fa307af891776d3398521bfac518c9d304ab91257b7cdb052eeb" dependencies = [ "either", "rustc-hash", @@ -7490,9 +7502,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_react" -version = "0.175.18" +version = "0.176.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67bc38b58cb66cbfd1ad9440073289a3d827b8b1fd2831126f1a3bfae99ec430" +checksum = "506abc97a5ace7313d62cf2c884a7ff5f9c8e6cc02faebeabc522820f83db038" dependencies = [ "ahash 0.8.3", "base64 0.13.1", @@ -7516,9 +7528,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_testing" -version = "0.132.14" +version = "0.133.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "857ed24bc19b38c311c6e479685d00d32052babc8a25db4cef26f0aa28c2b5d8" +checksum = "31fa20bd9ddcad28e21cfc30dcf2abd881ecffafe9b9333e71f46028474796a7" dependencies = [ "ansi_term", "anyhow", @@ -7542,9 +7554,9 @@ dependencies = [ [[package]] name = "swc_ecma_transforms_typescript" -version = "0.179.19" +version = "0.180.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e235c8b8fdac92de7255b40912077680106ff89de5d8595415d516f389fb9d0" +checksum = "330e6572237c2b5edfdc72169cddb23b83abb970d6580bd1c59a3edf16242745" dependencies = [ "serde", "swc_atoms", @@ -7558,9 +7570,9 @@ dependencies = [ [[package]] name = "swc_ecma_usage_analyzer" -version = "0.15.13" +version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711413fa43abee9fc5c2ca9b626676685c37d95b27f4ae532834e582379b7e85" +checksum = "b04e9b497be4134b2f4aac798f1379f0ba67d0e0a43293b761e3a7a99fa95ed6" dependencies = [ "ahash 0.8.3", "indexmap", @@ -7576,9 +7588,9 @@ dependencies = [ [[package]] name = "swc_ecma_utils" -version = "0.119.10" +version = "0.120.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "452c66399edeb88a97bfdc3bbf11e45db85fdf883bfd4fc8bdd93abb92152b9b" +checksum = "48c9203b881a2bd07de18db0d5cb8df5dfada81efafc4be4cd74674215258033" dependencies = [ "indexmap", "num_cpus", @@ -7595,9 +7607,9 @@ dependencies = [ [[package]] name = "swc_ecma_visit" -version = "0.92.5" +version = "0.93.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f61da6cac0ec3b7e62d367cfbd9e38e078a4601271891ad94f0dac5ff69f839" +checksum = "ffd98eaa16ea4d829f5636682dd61af01f81689a9f0ed5166b32c25b52f270b5" dependencies = [ "num-bigint", "swc_atoms", @@ -7609,9 +7621,9 @@ dependencies = [ [[package]] name = "swc_emotion" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349a12bfaf34e2e5a44fb802d749dab0abdd7fb8fd4492235f68d4ed51cfd7e8" +checksum = "e0ab51e2b0d4267a96059213c4985737d1ae70dca8396664fd177012452d39d3" dependencies = [ "base64 0.13.1", "byteorder", @@ -7639,9 +7651,9 @@ dependencies = [ [[package]] name = "swc_error_reporters" -version = "0.15.16" +version = "0.15.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "108322b719696e8c368c39dc6d8748494ea2aa870e7d80ea5956078aa6b4dd4d" +checksum = "a7d96ecd63299674716990592f326c483632aa52dceec85229ee22728499942e" dependencies = [ "anyhow", "miette 4.7.1", @@ -7652,9 +7664,9 @@ dependencies = [ [[package]] name = "swc_fast_graph" -version = "0.19.16" +version = "0.19.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b19b76468219b923c34efdeff812fa951fe1a1ecaba78118b013d034a1669ff5" +checksum = "416ee48930bc32634f2f0139e2fe7107dbc0c990d61c99cb581edd199e0fcb88" dependencies = [ "indexmap", "petgraph", @@ -7664,9 +7676,9 @@ dependencies = [ [[package]] name = "swc_graph_analyzer" -version = "0.20.19" +version = "0.20.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef31e002bc3980147948c2140fcac4f557daef5dacb7d145cda254cad7aa269b" +checksum = "d11018acd5f325876666d4eba2b036ad08e421f50b129a00d3c6dfe1aa9f67fa" dependencies = [ "ahash 0.8.3", "auto_impl", @@ -7699,9 +7711,9 @@ dependencies = [ [[package]] name = "swc_node_comments" -version = "0.18.16" +version = "0.18.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61839f8a936b5c95ce644d539914bb944b094eee9bd156c3dc41fe8e7eaa84ea" +checksum = "996dba81c8646dd79a0a885bcf6030828e20e6cfa7b2d6257bc23c128993b67c" dependencies = [ "ahash 0.8.3", "dashmap", @@ -7725,9 +7737,9 @@ dependencies = [ [[package]] name = "swc_plugin_proxy" -version = "0.35.5" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c37badc5ab20a495dff7a095b662657397f0c0658fea0576ecaa49fdb747cce1" +checksum = "62f43a74678e15a200724919644724492b698fa8b51156bbe70831b659068382" dependencies = [ "better_scoped_tls", "rkyv", @@ -7739,9 +7751,9 @@ dependencies = [ [[package]] name = "swc_plugin_runner" -version = "0.97.9" +version = "0.98.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03768d1eb0d37d6b44da689f1ab5126885844ac154ade03b14c8b6b06eeeacc1" +checksum = "d74d941fc1c4c27e704516b9a9ebb620680fabd3db65a5e215cd81dd44f14718" dependencies = [ "anyhow", "enumset", @@ -7763,9 +7775,9 @@ dependencies = [ [[package]] name = "swc_relay" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b372065bf36e8047d6d8d84aabc59966539507fd13a9da03f6e54af88a072134" +checksum = "fc70926fbbd0865af837c88edfcd84af24386ce647a2b56c0c6e471e42ba3a4b" dependencies = [ "once_cell", "regex", @@ -7778,9 +7790,9 @@ dependencies = [ [[package]] name = "swc_timer" -version = "0.19.19" +version = "0.19.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9889bf48909289e13e0f343eb8d1238e674e9380a4dd6c6346f62b83cb30236f" +checksum = "e6e1334b8d2edbdd12de67b3f065d940f0afdf47bd84d34f5ada92280669b4f8" dependencies = [ "tracing", ] @@ -8049,9 +8061,9 @@ dependencies = [ [[package]] name = "testing" -version = "0.33.19" +version = "0.33.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "359d2548f4919624af6cd1001e0a3ac9f081f8312e47fdca7650c11c9935981b" +checksum = "7f171e44c58e6e710675665cbe48b8996118f2751ca057d448bc02351ee8e0b0" dependencies = [ "ansi_term", "cargo_metadata", @@ -8778,7 +8790,7 @@ name = "turbo-tasks-env" version = "0.1.0" dependencies = [ "anyhow", - "dotenvy", + "dotenvs", "indexmap", "serde", "turbo-tasks", @@ -8837,6 +8849,7 @@ dependencies = [ "turbo-tasks-build", "turbo-tasks-hash", "turbo-tasks-memory", + "turbo-tasks-testing", ] [[package]] @@ -8924,6 +8937,7 @@ version = "0.1.0" dependencies = [ "anyhow", "auto-hash-map", + "futures", "lazy_static", "tokio", "turbo-tasks", @@ -9480,6 +9494,7 @@ version = "0.1.0" dependencies = [ "anyhow", "once_cell", + "serde", "similar", "turbo-tasks", "turbo-tasks-build", @@ -9494,6 +9509,7 @@ version = "0.1.0" dependencies = [ "anyhow", "dunce", + "futures", "once_cell", "serde", "serde_json", @@ -9501,6 +9517,7 @@ dependencies = [ "tokio", "turbo-tasks", "turbo-tasks-build", + "turbo-tasks-bytes", "turbo-tasks-env", "turbo-tasks-fs", "turbo-tasks-memory", @@ -9511,6 +9528,7 @@ dependencies = [ "turbopack-ecmascript-plugins", "turbopack-ecmascript-runtime", "turbopack-env", + "turbopack-node", "turbopack-test-utils", ] @@ -9552,13 +9570,16 @@ dependencies = [ "camino", "chrono", "dunce", + "hex", + "hmac", "lazy_static", + "libc", "os_str_bytes", "path-clean 1.0.1", "petgraph", - "ring", "serde", "serde_json", + "sha2", "tar", "tempfile", "test-case", @@ -9741,8 +9762,8 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 0.1.10", - "rand 0.4.6", + "cfg-if 1.0.0", + "rand 0.8.5", "static_assertions", ] diff --git a/Cargo.toml b/Cargo.toml index c00c964f06bb2..4ab45d135c59d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,14 +75,14 @@ lto = "off" [workspace.dependencies] # Keep consistent with preset_env_base through swc_core browserslist-rs = { version = "0.12.2" } -mdxjs = { version = "0.1.13" } -modularize_imports = { version = "0.31.0" } -styled_components = { version = "0.58.0" } -styled_jsx = { version = "0.35.0" } -swc_core = { version = "0.78.24" } -swc_emotion = { version = "0.34.0" } -swc_relay = { version = "0.6.0" } -testing = { version = "0.33.14" } +mdxjs = { version = "0.1.14" } +modularize_imports = { version = "0.32.0" } +styled_components = { version = "0.59.0" } +styled_jsx = { version = "0.36.0" } +swc_core = { version = "0.79.13" } +swc_emotion = { version = "0.35.0" } +swc_relay = { version = "0.7.0" } +testing = { version = "0.33.20" } auto-hash-map = { path = "crates/turbo-tasks-auto-hash-map" } node-file-trace = { path = "crates/node-file-trace", default-features = false } @@ -133,7 +133,7 @@ turborepo-cache = { path = "crates/turborepo-cache" } turborepo-env = { path = "crates/turborepo-env" } turborepo-ffi = { path = "crates/turborepo-ffi" } turborepo-fs = { path = "crates/turborepo-fs" } -turborepo-lib = { path = "crates/turborepo-lib" } +turborepo-lib = { path = "crates/turborepo-lib", default-features = false } turborepo-lockfiles = { path = "crates/turborepo-lockfiles" } turborepo-scm = { path = "crates/turborepo-scm" } wax = { path = "crates/turborepo-wax" } @@ -177,6 +177,7 @@ dialoguer = "0.10.3" dunce = "1.0.3" futures = "0.3.26" futures-retry = "0.6.0" +hex = "0.4.3" httpmock = { version = "0.6.7", default-features = false } image = { version = "0.24.6", default-features = false } indexmap = "1.9.2" From c50c3c8044e1d85d348a58dc44f361014202b444 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Mon, 10 Jul 2023 13:21:27 -0700 Subject: [PATCH 04/16] turbopack-cli: implement `turbopack build` Depends on #5487 This implements a basic version of `turbopack build`, only targeting browser targets. In the future, we could accept a cli or configuration option to target Node. Test Plan: `cargo run -p turbopack-cli build` with a `src/index.js` present and `cargo run -p turbopack-cli build src/entry.js` with `src/entry.js` present. --- crates/turbopack-cli/src/arguments.rs | 9 + crates/turbopack-cli/src/build/mod.rs | 311 ++++++++++++++++++++++++++ crates/turbopack-cli/src/lib.rs | 1 + 3 files changed, 321 insertions(+) create mode 100644 crates/turbopack-cli/src/build/mod.rs diff --git a/crates/turbopack-cli/src/arguments.rs b/crates/turbopack-cli/src/arguments.rs index cb1277b49026d..d1767eb50ec4e 100644 --- a/crates/turbopack-cli/src/arguments.rs +++ b/crates/turbopack-cli/src/arguments.rs @@ -9,6 +9,7 @@ use turbopack_cli_utils::issue::IssueSeverityCliOption; #[derive(Debug, Parser)] #[clap(author, version, about, long_about = None)] pub enum Arguments { + Build(BuildArguments), Dev(DevArguments), } @@ -16,6 +17,7 @@ impl Arguments { /// The directory of the application. see [CommonArguments]::dir pub fn dir(&self) -> Option<&Path> { match self { + Arguments::Build(args) => args.common.dir.as_deref(), Arguments::Dev(args) => args.common.dir.as_deref(), } } @@ -95,3 +97,10 @@ pub struct DevArguments { #[clap(long)] pub allow_retry: bool, } + +#[derive(Debug, Args)] +#[clap(author, version, about, long_about = None)] +pub struct BuildArguments { + #[clap(flatten)] + pub common: CommonArguments, +} diff --git a/crates/turbopack-cli/src/build/mod.rs b/crates/turbopack-cli/src/build/mod.rs new file mode 100644 index 0000000000000..5ef485a8f827d --- /dev/null +++ b/crates/turbopack-cli/src/build/mod.rs @@ -0,0 +1,311 @@ +use std::{ + env::current_dir, + path::{PathBuf, MAIN_SEPARATOR}, + sync::Arc, +}; + +use anyhow::{bail, Result}; +use turbo_tasks::{ + primitives::StringVc, NothingVc, TransientInstance, TryJoinIterExt, TurboTasks, Value, +}; +use turbo_tasks_fs::FileSystem; +use turbo_tasks_memory::MemoryBackend; +use turbopack::ecmascript::EcmascriptModuleAssetVc; +use turbopack_build::BuildChunkingContextVc; +use turbopack_cli_utils::issue::{ConsoleUiVc, LogOptions}; +use turbopack_core::{ + asset::{Asset, AssetsVc}, + chunk::{ + ChunkableAsset, ChunkableAssetVc, ChunkingContext, ChunkingContextVc, EvaluatableAssetsVc, + }, + context::AssetContext, + environment::{BrowserEnvironment, EnvironmentVc, ExecutionEnvironment}, + issue::{handle_issues, IssueReporterVc, IssueSeverity}, + reference::all_assets_from_entry, + reference_type::{EntryReferenceSubType, ReferenceType}, + resolve::{origin::PlainResolveOriginVc, parse::RequestVc, pattern::QueryMapVc}, +}; +use turbopack_env::dotenv::load_env; +use turbopack_node::execution_context::ExecutionContextVc; + +use crate::{ + arguments::BuildArguments, + contexts::{get_client_asset_context, get_client_compile_time_info, NodeEnv}, + util::{ + normalize_dirs, normalize_entries, output_fs, project_fs, EntryRequest, EntryRequestVc, + EntryRequestsVc, NormalizedDirs, + }, +}; + +pub fn register() { + turbopack::register(); + include!(concat!(env!("OUT_DIR"), "/register.rs")); +} + +pub struct TurbopackBuildBuilder { + turbo_tasks: Arc>, + project_dir: String, + root_dir: String, + entry_requests: Vec, + browserslist_query: String, + log_level: IssueSeverity, + show_all: bool, + log_detail: bool, +} + +impl TurbopackBuildBuilder { + pub fn new( + turbo_tasks: Arc>, + project_dir: String, + root_dir: String, + ) -> Self { + TurbopackBuildBuilder { + turbo_tasks, + project_dir, + root_dir, + entry_requests: vec![], + browserslist_query: "chrome 64, edge 79, firefox 67, opera 51, safari 12".to_owned(), + log_level: IssueSeverity::Warning, + show_all: false, + log_detail: false, + } + } + + pub fn entry_request(mut self, entry_asset_path: EntryRequest) -> Self { + self.entry_requests.push(entry_asset_path); + self + } + + pub fn browserslist_query(mut self, browserslist_query: String) -> Self { + self.browserslist_query = browserslist_query; + self + } + + pub fn log_level(mut self, log_level: IssueSeverity) -> Self { + self.log_level = log_level; + self + } + + pub fn show_all(mut self, show_all: bool) -> Self { + self.show_all = show_all; + self + } + + pub fn log_detail(mut self, log_detail: bool) -> Self { + self.log_detail = log_detail; + self + } + + pub async fn build(self) -> Result<()> { + let task = self.turbo_tasks.spawn_once_task(async move { + let build_result = build_internal( + StringVc::cell(self.project_dir.clone()), + StringVc::cell(self.root_dir), + EntryRequestsVc::cell( + self.entry_requests + .iter() + .cloned() + .map(EntryRequestVc::cell) + .collect(), + ), + StringVc::cell(self.browserslist_query), + ); + + let issue_reporter: IssueReporterVc = + ConsoleUiVc::new(TransientInstance::new(LogOptions { + project_dir: PathBuf::from(self.project_dir), + current_dir: current_dir().unwrap(), + show_all: self.show_all, + log_detail: self.log_detail, + log_level: self.log_level, + })) + .into(); + + handle_issues(build_result, issue_reporter, &None, &None).await?; + + Ok(NothingVc::new().into()) + }); + + self.turbo_tasks.wait_task_completion(task, true).await?; + + Ok(()) + } +} + +#[turbo_tasks::function] +async fn build_internal( + project_dir: StringVc, + root_dir: StringVc, + entry_requests: EntryRequestsVc, + browserslist_query: StringVc, +) -> Result { + let project_dir = &*project_dir.await?; + let root_dir = &*root_dir.await?; + let browserslist_query = &*browserslist_query.await?; + + let env = EnvironmentVc::new(Value::new(ExecutionEnvironment::Browser( + BrowserEnvironment { + dom: true, + web_worker: false, + service_worker: false, + browserslist_query: browserslist_query.to_owned(), + } + .into(), + ))); + let output_fs = output_fs(project_dir); + let project_fs = project_fs(root_dir); + let project_relative = project_dir.strip_prefix(root_dir).unwrap(); + let project_relative = project_relative + .strip_prefix(MAIN_SEPARATOR) + .unwrap_or(project_relative) + .replace(MAIN_SEPARATOR, "/"); + let project_path = project_fs.root().join(&project_relative); + let build_output_root = output_fs.root().join("dist"); + + let chunking_context: ChunkingContextVc = BuildChunkingContextVc::builder( + project_path, + build_output_root, + build_output_root, + build_output_root, + env, + ) + .build() + .into(); + + let node_env = NodeEnv::Production.cell(); + // TODO: allow node environment via cli + let env = EnvironmentVc::new(Value::new(ExecutionEnvironment::Browser( + BrowserEnvironment { + dom: true, + web_worker: false, + service_worker: false, + browserslist_query: browserslist_query.to_owned(), + } + .into(), + ))); + let compile_time_info = get_client_compile_time_info(env, node_env, browserslist_query); + let execution_context = + ExecutionContextVc::new(project_path, chunking_context, load_env(project_path)); + let context = + get_client_asset_context(project_path, execution_context, compile_time_info, node_env); + + let entry_requests = (*entry_requests + .await? + .iter() + .cloned() + .map(|r| async move { + Ok(match &*r.await? { + EntryRequest::Relative(p) => { + RequestVc::relative(Value::new(p.clone().into()), false) + } + EntryRequest::Module(m, p) => { + RequestVc::module(m.clone(), Value::new(p.clone().into()), QueryMapVc::none()) + } + }) + }) + .try_join() + .await?) + .to_vec(); + + let origin = PlainResolveOriginVc::new(context, output_fs.root().join("_")).as_resolve_origin(); + + let entries = entry_requests + .into_iter() + .map(|request| async move { + let ty = Value::new(ReferenceType::Entry(EntryReferenceSubType::Undefined)); + Ok(*origin + .resolve_asset(request, origin.resolve_options(ty.clone()), ty) + .primary_assets() + .await? + .first() + .unwrap()) + }) + .try_join() + .await?; + + let modules = entries.into_iter().map(|entry| { + context.process( + entry, + Value::new(ReferenceType::Entry(EntryReferenceSubType::Undefined)), + ) + }); + + let entry_chunk_groups = modules + .map(|entry_module| async move { + Ok( + if let Some(ecmascript) = + EcmascriptModuleAssetVc::resolve_from(entry_module).await? + { + AssetsVc::cell(vec![BuildChunkingContextVc::resolve_from(chunking_context) + .await? + .unwrap() + .generate_entry_chunk( + build_output_root + .join( + entry_module + .ident() + .path() + .file_stem() + .await? + .as_deref() + .unwrap(), + ) + .with_extension("entry.js"), + ecmascript.into(), + EvaluatableAssetsVc::one(ecmascript.into()), + )]) + } else if let Some(chunkable) = ChunkableAssetVc::resolve_from(entry_module).await? + { + chunking_context.chunk_group(chunkable.as_root_chunk(chunking_context)) + } else { + // TODO convert into a serve-able asset + bail!( + "Entry module is not chunkable, so it can't be used to bootstrap the \ + application" + ) + }, + ) + }) + .try_join() + .await?; + + for chunk_group in entry_chunk_groups { + for entry in &*chunk_group.await? { + for asset in &*all_assets_from_entry(entry.to_owned()).await? { + asset.content().write(asset.ident().path()).await?; + } + } + } + + Ok(NothingVc::new()) +} + +pub async fn build(args: &BuildArguments) -> Result<()> { + let NormalizedDirs { + project_dir, + root_dir, + } = normalize_dirs(&args.common.dir, &args.common.root)?; + + let tt = TurboTasks::new(MemoryBackend::new( + args.common + .memory_limit + .map_or(usize::MAX, |l| l * 1024 * 1024), + )); + + let mut builder = TurbopackBuildBuilder::new(tt, project_dir, root_dir) + .log_detail(args.common.log_detail) + .show_all(args.common.show_all) + .log_level( + args.common + .log_level + .map_or_else(|| IssueSeverity::Warning, |l| l.0), + ); + + for entry in normalize_entries(&args.common.entries) { + builder = builder.entry_request(EntryRequest::Relative(entry)); + } + + builder.build().await?; + + Ok(()) +} diff --git a/crates/turbopack-cli/src/lib.rs b/crates/turbopack-cli/src/lib.rs index 1743cca88ce44..c802da4bc1b0f 100644 --- a/crates/turbopack-cli/src/lib.rs +++ b/crates/turbopack-cli/src/lib.rs @@ -2,6 +2,7 @@ #![feature(min_specialization)] pub mod arguments; +pub mod build; pub(crate) mod contexts; pub mod dev; pub(crate) mod embed_js; From 9f1b0f0ae5d30467245f79e34d4e00680fbedeb5 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Mon, 10 Jul 2023 14:29:58 -0700 Subject: [PATCH 05/16] fixup! turbopack-cli: modularize code to support turbopack build --- Cargo.lock | 1 + crates/turbopack-cli/src/contexts.rs | 4 +--- crates/turbopack-cli/src/dev/web_entry_source.rs | 4 ++-- crates/turbopack-cli/src/main.rs | 1 - crates/turbopack-cli/src/util.rs | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 397175218422f..d68153ce38028 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9122,6 +9122,7 @@ dependencies = [ "turbo-tasks-memory", "turbopack", "turbopack-bench", + "turbopack-build", "turbopack-cli-utils", "turbopack-core", "turbopack-dev", diff --git a/crates/turbopack-cli/src/contexts.rs b/crates/turbopack-cli/src/contexts.rs index 6c5bc1fee5046..1ea1f3f4a7524 100644 --- a/crates/turbopack-cli/src/contexts.rs +++ b/crates/turbopack-cli/src/contexts.rs @@ -1,7 +1,6 @@ use std::{collections::HashMap, fmt}; use anyhow::Result; -use turbo_tasks::Value; use turbo_tasks_fs::{FileSystem, FileSystemPathVc}; use turbopack::{ condition::ContextCondition, @@ -18,7 +17,7 @@ use turbopack_core::{ compile_time_defines, compile_time_info::{CompileTimeDefinesVc, CompileTimeInfo, CompileTimeInfoVc}, context::AssetContextVc, - environment::{BrowserEnvironment, Environment, EnvironmentVc, ExecutionEnvironment}, + environment::EnvironmentVc, resolve::options::{ImportMap, ImportMapVc, ImportMapping}, }; use turbopack_dev::react_refresh::assert_can_resolve_react_refresh; @@ -193,7 +192,6 @@ fn client_defines(node_env: &NodeEnv) -> CompileTimeDefinesVc { pub async fn get_client_compile_time_info( env: EnvironmentVc, node_env: NodeEnvVc, - browserslist_query: &str, ) -> Result { Ok(CompileTimeInfo::builder(env) .defines(client_defines(&*node_env.await?)) diff --git a/crates/turbopack-cli/src/dev/web_entry_source.rs b/crates/turbopack-cli/src/dev/web_entry_source.rs index 2fed7e0c9455f..683a494a8d446 100644 --- a/crates/turbopack-cli/src/dev/web_entry_source.rs +++ b/crates/turbopack-cli/src/dev/web_entry_source.rs @@ -5,7 +5,7 @@ use turbo_tasks_fs::FileSystemPathVc; use turbopack::ecmascript::EcmascriptModuleAssetVc; use turbopack_cli_utils::runtime_entry::{RuntimeEntriesVc, RuntimeEntry}; use turbopack_core::{ - chunk::{ChunkableAssetVc, ChunkingContextVc}, + chunk::{ChunkableModuleVc, ChunkingContextVc}, environment::{BrowserEnvironment, EnvironmentVc, ExecutionEnvironment}, reference_type::{EntryReferenceSubType, ReferenceType}, resolve::{origin::PlainResolveOriginVc, parse::RequestVc}, @@ -46,7 +46,7 @@ pub async fn create_web_entry_source( } .into(), ))); - let compile_time_info = get_client_compile_time_info(env, node_env, browserslist_query); + let compile_time_info = get_client_compile_time_info(env, node_env); let context = get_client_asset_context(project_path, execution_context, compile_time_info, node_env); let chunking_context = diff --git a/crates/turbopack-cli/src/main.rs b/crates/turbopack-cli/src/main.rs index c03767c683de6..cd070ee35445f 100644 --- a/crates/turbopack-cli/src/main.rs +++ b/crates/turbopack-cli/src/main.rs @@ -81,7 +81,6 @@ async fn main_inner(args: Arguments) -> Result<()> { register(); match args { - Arguments::Build(args) => turbopack_cli::build::build(&args).await, Arguments::Dev(args) => turbopack_cli::dev::start_server(&args).await, } } diff --git a/crates/turbopack-cli/src/util.rs b/crates/turbopack-cli/src/util.rs index 4622e02369ff8..d6eb9fb91a41c 100644 --- a/crates/turbopack-cli/src/util.rs +++ b/crates/turbopack-cli/src/util.rs @@ -51,7 +51,7 @@ pub fn normalize_entries(entries: &Option>) -> Vec { entries .as_ref() .cloned() - .unwrap_or_else(|| vec!["src/index".to_owned()]) + .unwrap_or_else(|| vec!["src/entry".to_owned()]) } #[turbo_tasks::function] From 7cb359be09ea6cba982c3da94d925a30efb3918e Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Mon, 10 Jul 2023 14:52:04 -0700 Subject: [PATCH 06/16] fixup! Merge remote-tracking branch 'origin/wbinnssmith/modularize-cli' into wbinnssmith/turbopack-cli-build --- crates/turbopack-cli/src/build/mod.rs | 7 ++++--- crates/turbopack-cli/src/main.rs | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/turbopack-cli/src/build/mod.rs b/crates/turbopack-cli/src/build/mod.rs index 5ef485a8f827d..8b94ee67da6b8 100644 --- a/crates/turbopack-cli/src/build/mod.rs +++ b/crates/turbopack-cli/src/build/mod.rs @@ -16,7 +16,7 @@ use turbopack_cli_utils::issue::{ConsoleUiVc, LogOptions}; use turbopack_core::{ asset::{Asset, AssetsVc}, chunk::{ - ChunkableAsset, ChunkableAssetVc, ChunkingContext, ChunkingContextVc, EvaluatableAssetsVc, + ChunkableModule, ChunkableModuleVc, ChunkingContext, ChunkingContextVc, EvaluatableAssetsVc, }, context::AssetContext, environment::{BrowserEnvironment, EnvironmentVc, ExecutionEnvironment}, @@ -183,7 +183,7 @@ async fn build_internal( } .into(), ))); - let compile_time_info = get_client_compile_time_info(env, node_env, browserslist_query); + let compile_time_info = get_client_compile_time_info(env, node_env); let execution_context = ExecutionContextVc::new(project_path, chunking_context, load_env(project_path)); let context = @@ -254,7 +254,8 @@ async fn build_internal( ecmascript.into(), EvaluatableAssetsVc::one(ecmascript.into()), )]) - } else if let Some(chunkable) = ChunkableAssetVc::resolve_from(entry_module).await? + } else if let Some(chunkable) = + ChunkableModuleVc::resolve_from(entry_module).await? { chunking_context.chunk_group(chunkable.as_root_chunk(chunking_context)) } else { diff --git a/crates/turbopack-cli/src/main.rs b/crates/turbopack-cli/src/main.rs index cd070ee35445f..c03767c683de6 100644 --- a/crates/turbopack-cli/src/main.rs +++ b/crates/turbopack-cli/src/main.rs @@ -81,6 +81,7 @@ async fn main_inner(args: Arguments) -> Result<()> { register(); match args { + Arguments::Build(args) => turbopack_cli::build::build(&args).await, Arguments::Dev(args) => turbopack_cli::dev::start_server(&args).await, } } From 5b5a34f5aeea8c5347d9d118b46388eccbf48114 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Mon, 10 Jul 2023 15:18:04 -0700 Subject: [PATCH 07/16] fixup! fixup! Merge remote-tracking branch 'origin/wbinnssmith/modularize-cli' into wbinnssmith/turbopack-cli-build --- crates/turbopack-cli/src/build/mod.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/crates/turbopack-cli/src/build/mod.rs b/crates/turbopack-cli/src/build/mod.rs index 8b94ee67da6b8..55aa2d4ebf947 100644 --- a/crates/turbopack-cli/src/build/mod.rs +++ b/crates/turbopack-cli/src/build/mod.rs @@ -4,7 +4,7 @@ use std::{ sync::Arc, }; -use anyhow::{bail, Result}; +use anyhow::{bail, Context, Result}; use turbo_tasks::{ primitives::StringVc, NothingVc, TransientInstance, TryJoinIterExt, TurboTasks, Value, }; @@ -111,6 +111,9 @@ impl TurbopackBuildBuilder { StringVc::cell(self.browserslist_query), ); + // Await the result to propagate any errors. + build_result.await?; + let issue_reporter: IssueReporterVc = ConsoleUiVc::new(TransientInstance::new(LogOptions { project_dir: PathBuf::from(self.project_dir), @@ -211,14 +214,21 @@ async fn build_internal( let entries = entry_requests .into_iter() - .map(|request| async move { + .map(|request_vc| async move { let ty = Value::new(ReferenceType::Entry(EntryReferenceSubType::Undefined)); + let request = request_vc.await?; Ok(*origin - .resolve_asset(request, origin.resolve_options(ty.clone()), ty) + .resolve_asset(request_vc, origin.resolve_options(ty.clone()), ty) .primary_assets() .await? .first() - .unwrap()) + .with_context(|| { + format!( + "Unable to resolve entry {} from directory {}.", + request.request().unwrap(), + project_dir + ) + })?) }) .try_join() .await?; From 6eadb0cb16dcea592fd11616c677ba8d5933bade Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Mon, 10 Jul 2023 15:29:03 -0700 Subject: [PATCH 08/16] fixup! turbopack-cli: implement `turbopack build` --- crates/turbopack-cli/src/contexts.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/turbopack-cli/src/contexts.rs b/crates/turbopack-cli/src/contexts.rs index 1ea1f3f4a7524..3c3627ee463e3 100644 --- a/crates/turbopack-cli/src/contexts.rs +++ b/crates/turbopack-cli/src/contexts.rs @@ -109,8 +109,8 @@ async fn get_client_module_options_context( let resolve_options_context = get_client_resolve_options_context(project_path, node_env); - let enable_react_refresh = - assert_can_resolve_react_refresh(project_path, resolve_options_context) + let enable_react_refresh = matches!(*node_env.await?, NodeEnv::Development) + && assert_can_resolve_react_refresh(project_path, resolve_options_context) .await? .is_found(); From 690744c143ac87b3d6bc00a4058cbf677b21090d Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Wed, 12 Jul 2023 10:21:07 -0700 Subject: [PATCH 09/16] fixup! turbopack-cli: implement `turbopack build` --- crates/turbo-tasks/src/join_iter_ext.rs | 1 + crates/turbopack-cli/src/build/mod.rs | 23 ++++++++++++++++++----- crates/turbopack-core/src/issue/mod.rs | 3 ++- crates/turbopack-dev-server/src/http.rs | 3 ++- crates/turbopack-dev-server/src/lib.rs | 3 ++- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/crates/turbo-tasks/src/join_iter_ext.rs b/crates/turbo-tasks/src/join_iter_ext.rs index 50bdc4c7fbe42..69489dab55837 100644 --- a/crates/turbo-tasks/src/join_iter_ext.rs +++ b/crates/turbo-tasks/src/join_iter_ext.rs @@ -43,6 +43,7 @@ where pin_project! { /// Future for the [TryJoinIterExt::try_join] method. + #[must_use] pub struct TryJoin where F: Future, diff --git a/crates/turbopack-cli/src/build/mod.rs b/crates/turbopack-cli/src/build/mod.rs index 55aa2d4ebf947..b6e67e6c83ace 100644 --- a/crates/turbopack-cli/src/build/mod.rs +++ b/crates/turbopack-cli/src/build/mod.rs @@ -1,4 +1,5 @@ use std::{ + collections::HashSet, env::current_dir, path::{PathBuf, MAIN_SEPARATOR}, sync::Arc, @@ -14,7 +15,7 @@ use turbopack::ecmascript::EcmascriptModuleAssetVc; use turbopack_build::BuildChunkingContextVc; use turbopack_cli_utils::issue::{ConsoleUiVc, LogOptions}; use turbopack_core::{ - asset::{Asset, AssetsVc}, + asset::{Asset, AssetVc, AssetsVc}, chunk::{ ChunkableModule, ChunkableModuleVc, ChunkingContext, ChunkingContextVc, EvaluatableAssetsVc, }, @@ -124,7 +125,14 @@ impl TurbopackBuildBuilder { })) .into(); - handle_issues(build_result, issue_reporter, &None, &None).await?; + handle_issues( + build_result, + issue_reporter, + IssueSeverity::Error.into(), + &None, + &None, + ) + .await?; Ok(NothingVc::new().into()) }); @@ -280,14 +288,19 @@ async fn build_internal( .try_join() .await?; + let mut chunks: HashSet = HashSet::new(); for chunk_group in entry_chunk_groups { for entry in &*chunk_group.await? { - for asset in &*all_assets_from_entry(entry.to_owned()).await? { - asset.content().write(asset.ident().path()).await?; - } + chunks.extend(&*all_assets_from_entry(entry.to_owned()).await?); } } + chunks + .iter() + .map(|c| c.content().write(c.ident().path())) + .try_join() + .await?; + Ok(NothingVc::new()) } diff --git a/crates/turbopack-core/src/issue/mod.rs b/crates/turbopack-core/src/issue/mod.rs index 0d254cea5b379..ab2783b588cf4 100644 --- a/crates/turbopack-core/src/issue/mod.rs +++ b/crates/turbopack-core/src/issue/mod.rs @@ -719,6 +719,7 @@ where pub async fn handle_issues + CollectiblesSource + Copy>( source: T, issue_reporter: IssueReporterVc, + min_fatal_severity: IssueSeverityVc, path: &Option, operation: &Option, ) -> Result<()> { @@ -730,7 +731,7 @@ pub async fn handle_issues + CollectiblesSource + Copy>( let has_fatal = issue_reporter.report_issues( TransientInstance::new(issues.clone()), TransientValue::new(source.into()), - IssueSeverity::Fatal.into(), + min_fatal_severity, ); if *has_fatal.await? { diff --git a/crates/turbopack-dev-server/src/http.rs b/crates/turbopack-dev-server/src/http.rs index ee28b29f5d1cc..b0f37141af7ea 100644 --- a/crates/turbopack-dev-server/src/http.rs +++ b/crates/turbopack-dev-server/src/http.rs @@ -16,7 +16,7 @@ use turbo_tasks_bytes::Bytes; use turbo_tasks_fs::{FileContent, FileContentReadRef}; use turbopack_core::{ asset::AssetContent, - issue::{handle_issues, IssueReporterVc}, + issue::{handle_issues, IssueReporterVc, IssueSeverity}, version::VersionedContent, }; @@ -80,6 +80,7 @@ pub async fn process_request_with_content_source( handle_issues( result, issue_reporter, + IssueSeverity::Fatal.into(), &Some(original_path.clone()), &Some("get_from_source".to_owned()), ) diff --git a/crates/turbopack-dev-server/src/lib.rs b/crates/turbopack-dev-server/src/lib.rs index e9fd128f97e7e..0f8a0ffa1ef07 100644 --- a/crates/turbopack-dev-server/src/lib.rs +++ b/crates/turbopack-dev-server/src/lib.rs @@ -33,7 +33,7 @@ use tracing::{event, info_span, Instrument, Level, Span}; use turbo_tasks::{run_once_with_reason, trace::TraceRawVcs, util::FormatDuration, TurboTasksApi}; use turbopack_core::{ error::PrettyPrintError, - issue::{handle_issues, IssueReporterVc}, + issue::{handle_issues, IssueReporterVc, IssueSeverity}, }; use self::{source::ContentSourceVc, update::UpdateServer}; @@ -209,6 +209,7 @@ impl DevServerBuilder { handle_issues( source, issue_reporter, + IssueSeverity::Fatal.into(), &Some(path.clone()), &Some("get source".to_owned()), ) From accee1abf4ceadfa47bbbcc1f5eab0232a4f979d Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Wed, 12 Jul 2023 16:17:20 -0700 Subject: [PATCH 10/16] fixup! Merge remote-tracking branch 'origin/main' into wbinnssmith/modularize-cli --- crates/turbopack-cli/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/turbopack-cli/src/lib.rs b/crates/turbopack-cli/src/lib.rs index 1743cca88ce44..276c281291870 100644 --- a/crates/turbopack-cli/src/lib.rs +++ b/crates/turbopack-cli/src/lib.rs @@ -1,6 +1,6 @@ #![feature(future_join)] #![feature(min_specialization)] - +#![allow(clippy::too_many_arguments)] pub mod arguments; pub(crate) mod contexts; pub mod dev; From c05dfbac227068186262dd3a2b24a1aeba450492 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Thu, 13 Jul 2023 10:57:24 -0700 Subject: [PATCH 11/16] fixup! fixup! Merge remote-tracking branch 'origin/main' into wbinnssmith/modularize-cli --- crates/turbopack-cli/src/dev/web_entry_source.rs | 4 ++-- crates/turbopack-cli/src/util.rs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/turbopack-cli/src/dev/web_entry_source.rs b/crates/turbopack-cli/src/dev/web_entry_source.rs index 2118444830eab..6315395e9cb6b 100644 --- a/crates/turbopack-cli/src/dev/web_entry_source.rs +++ b/crates/turbopack-cli/src/dev/web_entry_source.rs @@ -115,8 +115,8 @@ pub fn get_client_chunking_context( DevChunkingContextVc::builder( project_path, server_root, - server_root.join("/_chunks"), - server_root.join("/_assets"), + server_root.join("_chunks"), + server_root.join("_assets"), environment, ) .hot_module_replacement() diff --git a/crates/turbopack-cli/src/util.rs b/crates/turbopack-cli/src/util.rs index d6eb9fb91a41c..9f8926d9f861a 100644 --- a/crates/turbopack-cli/src/util.rs +++ b/crates/turbopack-cli/src/util.rs @@ -15,10 +15,14 @@ pub enum EntryRequest { } pub struct NormalizedDirs { + /// Normalized project directory path as an absolute path pub project_dir: String, + /// Normalized root directory path as an absolute path pub root_dir: String, } +/// Normalizes (canonicalizes and represents as an absolute path in a String) +/// the project and root directories. pub fn normalize_dirs( project_dir: &Option, root_dir: &Option, From de9b98d2cf818a3108bd87ff54c588c1b8667f98 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Tue, 18 Jul 2023 10:25:17 -0700 Subject: [PATCH 12/16] fixup! Merge remote-tracking branch 'origin/main' into wbinnssmith/modularize-cli --- crates/turbopack-dev-server/src/http.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/turbopack-dev-server/src/http.rs b/crates/turbopack-dev-server/src/http.rs index bb0329dccc8f9..9caae484387ac 100644 --- a/crates/turbopack-dev-server/src/http.rs +++ b/crates/turbopack-dev-server/src/http.rs @@ -83,7 +83,7 @@ pub async fn process_request_with_content_source( handle_issues( result, issue_reporter, - IssueSeverity::Error.cell(), + IssueSeverity::Fatal.cell(), Some(&original_path), Some("get_from_source"), ) From 792ed437d706d6eee3e4cb6d2b2bc75749bcdcd4 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Tue, 18 Jul 2023 14:44:44 -0700 Subject: [PATCH 13/16] fixup! Merge remote-tracking branch 'origin/wbinnssmith/modularize-cli' into wbinnssmith/turbopack-cli-build --- crates/turbopack-cli/src/build/mod.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/crates/turbopack-cli/src/build/mod.rs b/crates/turbopack-cli/src/build/mod.rs index 20ed5daca8736..30b524569533d 100644 --- a/crates/turbopack-cli/src/build/mod.rs +++ b/crates/turbopack-cli/src/build/mod.rs @@ -15,7 +15,6 @@ use turbopack_cli_utils::issue::{ConsoleUi, LogOptions}; use turbopack_core::{ asset::Asset, chunk::{ChunkableModule, ChunkingContext, EvaluatableAssets}, - context::AssetContext, environment::{BrowserEnvironment, Environment, ExecutionEnvironment}, issue::{handle_issues, IssueReporter, IssueSeverity}, module::Module, @@ -27,7 +26,6 @@ use turbopack_core::{ parse::Request, pattern::QueryMap, }, - source::asset_to_source, }; use turbopack_env::dotenv::load_env; use turbopack_node::execution_context::ExecutionContext; @@ -229,14 +227,8 @@ async fn build_internal( .try_join() .await?; - let modules = entries.into_iter().map(|entry| { - context.process( - asset_to_source(entry), - Value::new(ReferenceType::Entry(EntryReferenceSubType::Undefined)), - ) - }); - - let entry_chunk_groups = modules + let entry_chunk_groups = entries + .into_iter() .map(|entry_module| async move { Ok( if let Some(ecmascript) = @@ -250,7 +242,7 @@ async fn build_internal( .entry_chunk( build_output_root .join( - entry_module + ecmascript .ident() .path() .file_stem() From cb3b1a4e279cffb7a8c40129e16627e8be430615 Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Tue, 18 Jul 2023 14:50:04 -0700 Subject: [PATCH 14/16] fixup! fixup! Merge remote-tracking branch 'origin/main' into wbinnssmith/modularize-cli --- crates/turbopack-build/src/chunking_context.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/turbopack-build/src/chunking_context.rs b/crates/turbopack-build/src/chunking_context.rs index 6da253d2d63e9..8f52eed331f4a 100644 --- a/crates/turbopack-build/src/chunking_context.rs +++ b/crates/turbopack-build/src/chunking_context.rs @@ -360,8 +360,8 @@ where let chunks = ecmascript_chunks .iter() .copied() - .map(|chunk| Vc::upcast(chunk)) - .chain(css_chunks.iter().copied().map(|chunk| Vc::upcast(chunk))) + .map(Vc::upcast) + .chain(css_chunks.iter().copied().map(Vc::upcast)) .chain(other_chunks) .collect(); From d41b4e0071014d8367df310381d9b6748e33cfbc Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Wed, 19 Jul 2023 10:48:13 -0700 Subject: [PATCH 15/16] fixup! Merge remote-tracking branch 'origin/main' into wbinnssmith/modularize-cli --- crates/turbopack-core/src/reference/mod.rs | 38 ++++++++-------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/crates/turbopack-core/src/reference/mod.rs b/crates/turbopack-core/src/reference/mod.rs index 289fcb7dd625a..fceede101958b 100644 --- a/crates/turbopack-core/src/reference/mod.rs +++ b/crates/turbopack-core/src/reference/mod.rs @@ -10,6 +10,7 @@ use crate::{ asset::Asset, issue::IssueContextExt, module::{convert_asset_to_module, Module, Modules}, + output::{OutputAsset, OutputAssets}, resolve::{PrimaryResolveResult, ResolveResult}, }; pub mod source_map; @@ -185,11 +186,14 @@ pub async fn all_modules(asset: Vc>) -> Result> { /// Walks the asset graph from multiple assets and collect all referenced /// assets. #[turbo_tasks::function] -async fn all_assets_from_entries(entries: Vc) -> Result> { +pub async fn all_assets_from_entries(entries: Vc) -> Result> { Ok(Vc::cell( AdjacencyMap::new() .skip_duplicates() - .visit(entries.await?.iter().copied(), get_referenced_assets) + .visit( + entries.await?.iter().copied().map(Vc::upcast), + get_referenced_assets, + ) .await .completed()? .into_inner() @@ -199,28 +203,14 @@ async fn all_assets_from_entries(entries: Vc) -> Result>, ) -> Result>> + Send> { - Ok( - asset - .references() - .await? - .iter() - .map(|reference| async move { - let primary_assets = reference.resolve_reference().primary_assets().await?; - Ok(primary_assets.clone_value()) - }) - .try_join() - .await? - .into_iter() - .flatten() - .map(|asset| async move { - Ok(Vc::try_resolve_sidecast::>(asset).await?) - }) - .try_join() - .await? - .into_iter() - .flatten(), - ) + Ok(asset + .references() + .await? + .iter() + .copied() + .collect::>() + .into_iter()) } From b7b6f90bd8da2de76381c582427504834c401f3d Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Thu, 20 Jul 2023 15:02:19 -0700 Subject: [PATCH 16/16] fixup! Merge remote-tracking branch 'origin/main' into wbinnssmith/turbopack-cli-build --- crates/turbopack-cli/src/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/turbopack-cli/src/util.rs b/crates/turbopack-cli/src/util.rs index eb07b08434138..bca5920c41a64 100644 --- a/crates/turbopack-cli/src/util.rs +++ b/crates/turbopack-cli/src/util.rs @@ -6,7 +6,7 @@ use turbo_tasks::Vc; use turbo_tasks_fs::{DiskFileSystem, FileSystem}; #[turbo_tasks::value(transparent)] -pub struct EntryRequests(Vec>); +pub struct EntryRequests(pub Vec>); #[turbo_tasks::value(shared)] #[derive(Clone)]