Skip to content

Commit

Permalink
Merge branch 'canary' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
delbaoliveira authored Nov 6, 2024
2 parents 688b5dd + f3533cb commit 92502f7
Show file tree
Hide file tree
Showing 185 changed files with 3,495 additions and 1,846 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ jobs:
stepName: 'devlow-bench-${{ matrix.mode }}-${{ matrix.selector }}'
secrets: inherit

test-devlow:
name: test devlow package
needs: ['optimize-ci', 'changes']
if: ${{ needs.optimize-ci.outputs.skip == 'false' && needs.changes.outputs.docs-only == 'false' }}
strategy:
fail-fast: false
uses: ./.github/workflows/build_reusable.yml
with:
stepName: 'test-devlow'
afterBuild: pnpm install && pnpm run --filter=devlow-bench test
secrets: inherit

test-turbopack-dev:
name: test turbopack dev
needs: ['optimize-ci', 'changes', 'build-next', 'build-native']
Expand Down
45 changes: 34 additions & 11 deletions crates/napi/src/next_api/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,10 @@ pub fn project_hmr_identifiers_subscribe(
)
}

struct NapiUpdateInfoOpts {
include_reasons: bool,
}

enum UpdateMessage {
Start,
End(UpdateInfo),
Expand All @@ -904,16 +908,16 @@ struct NapiUpdateMessage {
pub value: Option<NapiUpdateInfo>,
}

impl From<UpdateMessage> for NapiUpdateMessage {
fn from(update_message: UpdateMessage) -> Self {
impl NapiUpdateMessage {
fn from_update_message(update_message: UpdateMessage, opts: NapiUpdateInfoOpts) -> Self {
match update_message {
UpdateMessage::Start => NapiUpdateMessage {
update_type: "start".to_string(),
value: None,
},
UpdateMessage::End(info) => NapiUpdateMessage {
update_type: "end".to_string(),
value: Some(info.into()),
value: Some(NapiUpdateInfo::from_update_info(info, opts)),
},
}
}
Expand All @@ -923,13 +927,27 @@ impl From<UpdateMessage> for NapiUpdateMessage {
struct NapiUpdateInfo {
pub duration: u32,
pub tasks: u32,
/// A human-readable list of invalidation reasons (typically changed file paths) if known. Will
/// be `None` if [`NapiUpdateInfoOpts::include_reasons`] is `false` or if no reason was
/// specified (not every invalidation includes a reason).
pub reasons: Option<String>,
}

impl From<UpdateInfo> for NapiUpdateInfo {
fn from(update_info: UpdateInfo) -> Self {
impl NapiUpdateInfo {
fn from_update_info(update_info: UpdateInfo, opts: NapiUpdateInfoOpts) -> Self {
Self {
duration: update_info.duration.as_millis() as u32,
tasks: update_info.tasks as u32,
// u32::MAX in milliseconds is 49.71 days
duration: update_info
.duration
.as_millis()
.try_into()
.expect("update duration in milliseconds should not exceed u32::MAX"),
tasks: update_info
.tasks
.try_into()
.expect("number of tasks should not exceed u32::MAX"),
reasons: (opts.include_reasons && !update_info.reasons.is_empty())
.then(|| update_info.reasons.to_string()),
}
}
}
Expand All @@ -949,12 +967,17 @@ impl From<UpdateInfo> for NapiUpdateInfo {
pub fn project_update_info_subscribe(
#[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External<ProjectInstance>,
aggregation_ms: u32,
include_reasons: bool,
func: JsFunction,
) -> napi::Result<()> {
let func: ThreadsafeFunction<UpdateMessage> = func.create_threadsafe_function(0, |ctx| {
let message = ctx.value;
Ok(vec![NapiUpdateMessage::from(message)])
})?;
let func: ThreadsafeFunction<UpdateMessage> =
func.create_threadsafe_function(0, move |ctx| {
let message = ctx.value;
Ok(vec![NapiUpdateMessage::from_update_message(
message,
NapiUpdateInfoOpts { include_reasons },
)])
})?;
let turbo_tasks = project.turbo_tasks.clone();
tokio::spawn(async move {
loop {
Expand Down
10 changes: 6 additions & 4 deletions crates/napi/src/next_api/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
collections::HashMap, future::Future, ops::Deref, path::PathBuf, sync::Arc, time::Duration,
collections::HashMap, env, future::Future, ops::Deref, path::PathBuf, sync::Arc, time::Duration,
};

use anyhow::{anyhow, Context, Result};
Expand Down Expand Up @@ -133,9 +133,11 @@ pub fn create_turbo_tasks(
)?),
))
} else {
NextTurboTasks::Memory(TurboTasks::new(turbo_tasks_memory::MemoryBackend::new(
memory_limit,
)))
let mut backend = turbo_tasks_memory::MemoryBackend::new(memory_limit);
if env::var_os("NEXT_TURBOPACK_PRINT_TASK_INVALIDATION").is_some() {
backend.print_task_invalidation(true);
}
NextTurboTasks::Memory(TurboTasks::new(backend))
})
}

Expand Down
2 changes: 1 addition & 1 deletion crates/napi/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn log_internal_error_and_inform(err_info: &str) {
.unwrap_or_else(|_| panic!("Failed to open {}", PANIC_LOG.to_string_lossy()));

writeln!(log_file, "{}\n{}", LOG_DIVIDER, err_info).unwrap();
eprintln!("{}: An unexpected Turbopack error occurred. Please report the content of {} to https://github.com/vercel/next.js/issues/new", "FATAL".red().bold(), PANIC_LOG.to_string_lossy());
eprintln!("{}: An unexpected Turbopack error occurred. Please report the content of {}, along with a description of what you were doing when the error occurred, to https://github.com/vercel/next.js/issues/new", "FATAL".red().bold(), PANIC_LOG.to_string_lossy());
}

#[napi]
Expand Down
6 changes: 5 additions & 1 deletion crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,11 @@ pub async fn get_client_module_options_context(
next_client_rules.extend(additional_rules);

let postcss_transform_options = PostCssTransformOptions {
postcss_package: Some(get_postcss_package_mapping(project_path)),
postcss_package: Some(
get_postcss_package_mapping(project_path)
.to_resolved()
.await?,
),
config_location: PostCssConfigLocation::ProjectPathOrLocalPath,
..Default::default()
};
Expand Down
12 changes: 8 additions & 4 deletions crates/next-core/src/next_client/transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use crate::{
next_client::context::ClientContextType,
next_config::NextConfig,
next_shared::transforms::{
get_next_dynamic_transform_rule, get_next_font_transform_rule, get_next_image_rule,
get_next_lint_transform_rule, get_next_modularize_imports_rule,
get_next_pages_transforms_rule, get_server_actions_transform_rule,
next_amp_attributes::get_next_amp_attr_rule,
debug_fn_name::get_debug_fn_name_rule, get_next_dynamic_transform_rule,
get_next_font_transform_rule, get_next_image_rule, get_next_lint_transform_rule,
get_next_modularize_imports_rule, get_next_pages_transforms_rule,
get_server_actions_transform_rule, next_amp_attributes::get_next_amp_attr_rule,
next_cjs_optimizer::get_next_cjs_optimizer_rule,
next_disallow_re_export_all_in_page::get_next_disallow_export_all_in_page_rule,
next_page_config::get_next_page_config_rule,
Expand Down Expand Up @@ -43,6 +43,10 @@ pub async fn get_next_client_transforms_rules(

rules.push(get_next_font_transform_rule(enable_mdx_rs));

if mode.await?.is_development() {
rules.push(get_debug_fn_name_rule(enable_mdx_rs));
}

let mut is_app_dir = false;

match context_ty {
Expand Down
6 changes: 3 additions & 3 deletions crates/next-core/src/next_edge/unsupported.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use indoc::formatdoc;
use turbo_tasks::Vc;
use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::{File, FileSystemPath};
use turbopack_core::{
asset::AssetContent,
Expand Down Expand Up @@ -62,9 +62,9 @@ impl ImportMappingReplacement for NextEdgeUnsupportedModuleReplacer {
"#
};
let content = AssetContent::file(File::from(code).into());
let source = VirtualSource::new(root_path, content);
let source = VirtualSource::new(root_path, content).to_resolved().await?;
return Ok(ImportMapResult::Result(
ResolveResult::source(Vc::upcast(source)).resolved_cell(),
ResolveResult::source(ResolvedVc::upcast(source)).resolved_cell(),
)
.cell());
};
Expand Down
24 changes: 13 additions & 11 deletions crates/next-core/src/next_font/google/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ impl NextFontGoogleReplacer {
.into(),
)
.cell()),
);
Ok(
ImportMapResult::Result(ResolveResult::source(Vc::upcast(js_asset)).resolved_cell())
.cell(),
).to_resolved().await?;
Ok(ImportMapResult::Result(
ResolveResult::source(ResolvedVc::upcast(js_asset)).resolved_cell(),
)
.cell())
}
}

Expand Down Expand Up @@ -267,7 +267,7 @@ impl NextFontGoogleCssModuleReplacer {
.await?;

Ok(ImportMapResult::Result(
ResolveResult::source(*ResolvedVc::upcast(css_asset)).resolved_cell(),
ResolveResult::source(ResolvedVc::upcast(css_asset)).resolved_cell(),
)
.cell())
}
Expand Down Expand Up @@ -386,12 +386,14 @@ impl ImportMappingReplacement for NextFontGoogleFontFileReplacer {
let font_source = VirtualSource::new(
font_virtual_path,
AssetContent::file(FileContent::Content(font.await?.0.as_slice().into()).cell()),
);
)
.to_resolved()
.await?;

Ok(
ImportMapResult::Result(ResolveResult::source(Vc::upcast(font_source)).resolved_cell())
.cell(),
Ok(ImportMapResult::Result(
ResolveResult::source(ResolvedVc::upcast(font_source)).resolved_cell(),
)
.cell())
}
}

Expand Down Expand Up @@ -690,10 +692,10 @@ async fn get_mock_stylesheet(
let val = evaluate(
mocked_response_asset,
root,
env,
*env,
AssetIdent::from_path(loader_path),
asset_context,
chunking_context,
*chunking_context,
None,
vec![],
Completion::immutable(),
Expand Down
22 changes: 14 additions & 8 deletions crates/next-core/src/next_font/local/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{bail, Context, Result};
use indoc::formatdoc;
use serde::{Deserialize, Serialize};
use turbo_tasks::{RcStr, Value, Vc};
use turbo_tasks::{RcStr, ResolvedVc, Value, Vc};
use turbo_tasks_fs::{
glob::Glob, json::parse_json_with_source_context, FileContent, FileSystemPath,
};
Expand Down Expand Up @@ -174,10 +174,12 @@ impl BeforeResolvePlugin for NextFontLocalResolvePlugin {
.into(),
),
AssetContent::file(FileContent::Content(file_content.into()).into()),
);
)
.to_resolved()
.await?;

Ok(ResolveResultOption::some(
ResolveResult::source(Vc::upcast(js_asset)).into(),
ResolveResult::source(ResolvedVc::upcast(js_asset)).cell(),
))
}
"@vercel/turbopack-next/internal/font/local/cssmodule.module.css" => {
Expand All @@ -202,11 +204,13 @@ impl BeforeResolvePlugin for NextFontLocalResolvePlugin {

let css_asset = VirtualSource::new(
css_virtual_path,
AssetContent::file(FileContent::Content(stylesheet.into()).into()),
);
AssetContent::file(FileContent::Content(stylesheet.into()).cell()),
)
.to_resolved()
.await?;

Ok(ResolveResultOption::some(
ResolveResult::source(Vc::upcast(css_asset)).into(),
ResolveResult::source(ResolvedVc::upcast(css_asset)).cell(),
))
}
"@vercel/turbopack-next/internal/font/local/font" => {
Expand All @@ -233,10 +237,12 @@ impl BeforeResolvePlugin for NextFontLocalResolvePlugin {
let font_file = lookup_path.join(path.clone()).read();

let font_source =
VirtualSource::new(font_virtual_path, AssetContent::file(font_file));
VirtualSource::new(font_virtual_path, AssetContent::file(font_file))
.to_resolved()
.await?;

Ok(ResolveResultOption::some(
ResolveResult::source(Vc::upcast(font_source)).into(),
ResolveResult::source(ResolvedVc::upcast(font_source)).cell(),
))
}
_ => Ok(ResolveResultOption::none()),
Expand Down
27 changes: 20 additions & 7 deletions crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,11 @@ pub async fn get_server_module_options_context(
let foreign_code_context_condition =
foreign_code_context_condition(next_config, project_path).await?;
let postcss_transform_options = PostCssTransformOptions {
postcss_package: Some(get_postcss_package_mapping(project_path)),
postcss_package: Some(
get_postcss_package_mapping(project_path)
.to_resolved()
.await?,
),
config_location: PostCssConfigLocation::ProjectPathOrLocalPath,
..Default::default()
};
Expand Down Expand Up @@ -945,7 +949,7 @@ pub async fn get_server_chunking_context_with_client_assets(
// TODO(alexkirsz) This should return a trait that can be implemented by the
// different server chunking contexts. OR the build chunking context should
// support both production and development modes.
Ok(NodeJsChunkingContext::builder(
let mut builder = NodeJsChunkingContext::builder(
project_path,
node_root,
client_root,
Expand All @@ -956,8 +960,12 @@ pub async fn get_server_chunking_context_with_client_assets(
)
.asset_prefix(asset_prefix)
.minify_type(next_mode.minify_type())
.module_id_strategy(module_id_strategy)
.build())
.module_id_strategy(module_id_strategy);

if next_mode.is_development() {
builder = builder.use_file_source_map_uris();
}
Ok(builder.build())
}

#[turbo_tasks::function]
Expand All @@ -972,7 +980,7 @@ pub async fn get_server_chunking_context(
// TODO(alexkirsz) This should return a trait that can be implemented by the
// different server chunking contexts. OR the build chunking context should
// support both production and development modes.
Ok(NodeJsChunkingContext::builder(
let mut builder = NodeJsChunkingContext::builder(
project_path,
node_root,
node_root,
Expand All @@ -982,6 +990,11 @@ pub async fn get_server_chunking_context(
next_mode.runtime_type(),
)
.minify_type(next_mode.minify_type())
.module_id_strategy(module_id_strategy)
.build())
.module_id_strategy(module_id_strategy);

if next_mode.is_development() {
builder = builder.use_file_source_map_uris()
}

Ok(builder.build())
}
12 changes: 9 additions & 3 deletions crates/next-core/src/next_shared/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use anyhow::Result;
use lazy_static::lazy_static;
use turbo_tasks::{RcStr, Value, Vc};
use turbo_tasks::{RcStr, ResolvedVc, Value, Vc};
use turbo_tasks_fs::{glob::Glob, FileSystemPath};
use turbopack_core::{
diagnostics::DiagnosticExt,
Expand Down Expand Up @@ -319,7 +319,10 @@ impl AfterResolvePlugin for NextNodeSharedRuntimeResolvePlugin {
.join(format!("{base}/{resource_request}").into());

Ok(Vc::cell(Some(
ResolveResult::source(Vc::upcast(FileSource::new(new_path))).into(),
ResolveResult::source(ResolvedVc::upcast(
FileSource::new(new_path).to_resolved().await?,
))
.cell(),
)))
}
}
Expand Down Expand Up @@ -418,7 +421,10 @@ impl AfterResolvePlugin for NextSharedRuntimeResolvePlugin {
let modified_path = raw_fs_path.path.replace("next/dist/esm/", "next/dist/");
let new_path = fs_path.root().join(modified_path.into());
Ok(Vc::cell(Some(
ResolveResult::source(Vc::upcast(FileSource::new(new_path))).into(),
ResolveResult::source(ResolvedVc::upcast(
FileSource::new(new_path).to_resolved().await?,
))
.cell(),
)))
}
}
Loading

0 comments on commit 92502f7

Please sign in to comment.