Skip to content

Commit

Permalink
Merge branch 'vercel:canary' into canary
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan authored Oct 24, 2024
2 parents 0d5e982 + 0dce6bb commit 032ea1f
Show file tree
Hide file tree
Showing 510 changed files with 3,614 additions and 2,030 deletions.
2 changes: 1 addition & 1 deletion .github/actions/next-integration-stat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ const createCommentPostAsync =
console.log('Created a new comment', result.data.html_url)
}

// An action report failed next.js integration test with --turbo
// An action report failed next.js integration test with --turbopack
async function run() {
const {
token,
Expand Down
2 changes: 1 addition & 1 deletion bench/heavy-npm-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev-turbopack": "next dev --turbo",
"dev-turbopack": "next dev --turbopack",
"dev-webpack": "next dev",
"build-turbopack": "TURBOPACK=1 TURBOPACK_BUILD=1 next build",
"build-webpack": "next build",
Expand Down
2 changes: 1 addition & 1 deletion crates/napi/src/turbopack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::next_api::project::NapiDefineEnv;
#[napi(object, object_to_js = false)]
#[derive(Debug)]
pub struct NextBuildContext {
// Added by Next.js for next build --turbo specifically.
// Added by Next.js for next build --turbopack specifically.
/// The root directory of the workspace.
pub root: Option<String>,

Expand Down
14 changes: 7 additions & 7 deletions crates/next-api/src/dynamic_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tracing::{Instrument, Level};
use turbo_tasks::{
graph::{GraphTraversal, NonDeterministic, VisitControlFlow, VisitedNodes},
trace::TraceRawVcs,
FxIndexMap, RcStr, ReadRef, TryJoinIterExt, Value, ValueToString, Vc,
FxIndexMap, RcStr, ReadRef, ResolvedVc, TryJoinIterExt, Value, ValueToString, Vc,
};
use turbopack_core::{
chunk::{
Expand Down Expand Up @@ -162,7 +162,7 @@ pub(crate) async fn collect_next_dynamic_imports(
.iter()
.map(|module| async move {
Ok(NextDynamicVisitEntry::Module(
module.resolve().await?,
module.to_resolved().await?,
module.ident().to_string().await?,
))
})
Expand Down Expand Up @@ -209,8 +209,8 @@ pub(crate) async fn collect_next_dynamic_imports(

#[derive(Debug, PartialEq, Eq, Hash, Clone, TraceRawVcs, Serialize, Deserialize)]
enum NextDynamicVisitEntry {
Module(Vc<Box<dyn Module>>, ReadRef<RcStr>),
DynamicImportsMap(Vc<DynamicImportsMap>),
Module(ResolvedVc<Box<dyn Module>>, ReadRef<RcStr>),
DynamicImportsMap(ResolvedVc<DynamicImportsMap>),
}

#[turbo_tasks::value(transparent)]
Expand All @@ -227,7 +227,7 @@ async fn get_next_dynamic_edges(
.iter()
.map(|&referenced_module| async move {
Ok(NextDynamicVisitEntry::Module(
referenced_module,
referenced_module.to_resolved().await?,
referenced_module.ident().to_string().await?,
))
})
Expand All @@ -236,7 +236,7 @@ async fn get_next_dynamic_edges(
if let Some(dynamic_imports_map) = *dynamic_imports_map.await? {
edges.reserve_exact(1);
edges.push(NextDynamicVisitEntry::DynamicImportsMap(
dynamic_imports_map,
dynamic_imports_map.to_resolved().await?,
));
}
Ok(Vc::cell(edges))
Expand Down Expand Up @@ -264,7 +264,7 @@ impl turbo_tasks::graph::Visit<NextDynamicVisitEntry> for NextDynamicVisit {
};
let client_asset_context = self.client_asset_context;
async move {
Ok(get_next_dynamic_edges(client_asset_context, module)
Ok(get_next_dynamic_edges(client_asset_context, *module)
.await?
.into_iter()
.cloned())
Expand Down
36 changes: 18 additions & 18 deletions crates/next-api/src/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::{collections::BTreeMap, io::Write, iter::once};
use anyhow::{bail, Context, Result};
use indexmap::map::Entry;
use next_core::{
next_manifests::{ActionLayer, ActionManifestWorkerEntry, ServerReferenceManifest},
next_manifests::{
ActionLayer, ActionManifestModuleId, ActionManifestWorkerEntry, ServerReferenceManifest,
},
util::NextRuntime,
};
use swc_core::{
Expand All @@ -22,7 +24,7 @@ use turbo_tasks::{
use turbo_tasks_fs::{self, rope::RopeBuilder, File, FileSystemPath};
use turbopack_core::{
asset::AssetContent,
chunk::{ChunkItemExt, ChunkableModule, ChunkingContext, EvaluatableAsset},
chunk::{ChunkItem, ChunkItemExt, ChunkableModule, ChunkingContext, EvaluatableAsset},
context::AssetContext,
file_source::FileSource,
module::{Module, Modules},
Expand Down Expand Up @@ -69,11 +71,8 @@ pub(crate) async fn create_server_actions_manifest(
.await?
.context("loader module must be evaluatable")?;

let loader_id = loader
.as_chunk_item(Vc::upcast(chunking_context))
.id()
.to_string();
let manifest = build_manifest(node_root, page_name, runtime, actions, loader_id).await?;
let chunk_item = loader.as_chunk_item(Vc::upcast(chunking_context));
let manifest = build_manifest(node_root, page_name, runtime, actions, chunk_item).await?;
Ok(ServerActionsManifest {
loader: evaluable,
manifest,
Expand All @@ -96,11 +95,11 @@ async fn build_server_actions_loader(
) -> Result<Vc<Box<dyn EcmascriptChunkPlaceable>>> {
let actions = actions.await?;

// Every module which exports an action (that is accessible starting from our
// app page entry point) will be present. We generate a single loader file
// which lazily imports the respective module's chunk_item id and invokes
// the exported action function.
let mut contents = RopeBuilder::from("__turbopack_export_value__({\n");
// Every module which exports an action (that is accessible starting from
// our app page entry point) will be present. We generate a single loader
// file which re-exports the respective module's action function using the
// hashed ID as export name.
let mut contents = RopeBuilder::from("");
let mut import_map = FxIndexMap::default();
for (hash_id, (_layer, name, module)) in actions.iter() {
let index = import_map.len();
Expand All @@ -109,11 +108,9 @@ async fn build_server_actions_loader(
.or_insert_with(|| format!("ACTIONS_MODULE{index}").into());
writeln!(
contents,
" '{hash_id}': (...args) => Promise.resolve(require('{module_name}')).then(mod => \
(0, mod['{name}'])(...args)),",
"export {{{name} as '{hash_id}'}} from '{module_name}'"
)?;
}
write!(contents, "}});")?;

let output_path =
project_path.join(format!(".next-internal/server/app{page_name}/actions.js").into());
Expand Down Expand Up @@ -143,7 +140,7 @@ async fn build_manifest(
page_name: RcStr,
runtime: NextRuntime,
actions: Vc<AllActions>,
loader_id: Vc<RcStr>,
chunk_item: Vc<Box<dyn ChunkItem>>,
) -> Result<Vc<Box<dyn OutputAsset>>> {
let manifest_path_prefix = &page_name;
let manifest_path = node_root
Expand All @@ -155,7 +152,7 @@ async fn build_manifest(
let key = format!("app{page_name}");

let actions_value = actions.await?;
let loader_id_value = loader_id.await?;
let loader_id = chunk_item.id().to_string().await?;
let mapping = match runtime {
NextRuntime::Edge => &mut manifest.edge,
NextRuntime::NodeJs => &mut manifest.node,
Expand All @@ -165,7 +162,10 @@ async fn build_manifest(
let entry = mapping.entry(hash_id.as_str()).or_default();
entry.workers.insert(
&key,
ActionManifestWorkerEntry::String(loader_id_value.as_str()),
ActionManifestWorkerEntry {
module_id: ActionManifestModuleId::String(loader_id.as_str()),
is_async: *chunk_item.is_self_async().await?,
},
);
entry.layer.insert(&key, *layer);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/next-core/src/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use turbopack_ecmascript_runtime::RuntimeType;
#[turbo_tasks::value(shared)]
#[derive(Debug, Copy, Clone, TaskInput, Ord, PartialOrd, Hash)]
pub enum NextMode {
/// `next dev --turbo`
/// `next dev --turbopack`
Development,
/// `next build`
Build,
Expand Down
8 changes: 4 additions & 4 deletions crates/next-core/src/next_app/include_modules_module.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use turbo_tasks::{RcStr, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks::{RcStr, ResolvedVc, TryJoinIterExt, ValueToString, Vc};
use turbo_tasks_fs::glob::Glob;
use turbopack_core::{
asset::{Asset, AssetContent},
Expand All @@ -19,13 +19,13 @@ use turbopack_ecmascript::chunk::{
#[turbo_tasks::value]
pub struct IncludeModulesModule {
ident: Vc<AssetIdent>,
modules: Vec<Vc<Box<dyn Module>>>,
modules: Vec<ResolvedVc<Box<dyn Module>>>,
}

#[turbo_tasks::value_impl]
impl IncludeModulesModule {
#[turbo_tasks::function]
pub fn new(ident: Vc<AssetIdent>, modules: Vec<Vc<Box<dyn Module>>>) -> Vc<Self> {
pub fn new(ident: Vc<AssetIdent>, modules: Vec<ResolvedVc<Box<dyn Module>>>) -> Vc<Self> {
Self { ident, modules }.cell()
}
}
Expand All @@ -50,7 +50,7 @@ impl Module for IncludeModulesModule {
.iter()
.map(|&module| async move {
Ok(Vc::upcast(
IncludedModuleReference::new(module).resolve().await?,
IncludedModuleReference::new(*module).resolve().await?,
))
})
.try_join()
Expand Down
4 changes: 2 additions & 2 deletions crates/next-core/src/next_app/metadata/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async fn static_route_source(
if ({is_twitter} || {is_open_graph}) {{
const fileSizeInMB = buffer.byteLength / 1024 / 1024
if (fileSizeInMB > {file_size_limit}) {{
throw new Error('File size for {img_name} image "{path}" exceeds {file_size_limit}MB. ' +
throw new Error('File size for {img_name} image {path} exceeds {file_size_limit}MB. ' +
`(Current: ${{fileSizeInMB.toFixed(2)}}MB)\n` +
'Read more: https://nextjs.org/docs/app/api-reference/file-conventions/metadata/opengraph-image#image-files-jpg-png-gif'
)
Expand All @@ -193,7 +193,7 @@ async fn static_route_source(
is_open_graph = is_open_graph,
file_size_limit = file_size_limit,
img_name = img_name,
path = path.to_string().await?,
path = StringifyJs(&path.to_string().await?),
};

let file = File::from(code);
Expand Down
20 changes: 12 additions & 8 deletions crates/next-core/src/next_client/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::iter::once;

use anyhow::Result;
use turbo_tasks::{FxIndexMap, RcStr, Value, Vc};
use turbo_tasks::{FxIndexMap, RcStr, ResolvedVc, Value, Vc};
use turbo_tasks_env::EnvMap;
use turbo_tasks_fs::{FileSystem, FileSystemPath};
use turbopack::{
Expand Down Expand Up @@ -193,16 +193,16 @@ fn internal_assets_conditions() -> ContextCondition {
#[turbo_tasks::function]
pub async fn get_client_module_options_context(
project_path: Vc<FileSystemPath>,
execution_context: Vc<ExecutionContext>,
env: Vc<Environment>,
execution_context: ResolvedVc<ExecutionContext>,
env: ResolvedVc<Environment>,
ty: Value<ClientContextType>,
mode: Vc<NextMode>,
next_config: Vc<NextConfig>,
) -> Result<Vc<ModuleOptionsContext>> {
let next_mode = mode.await?;

let resolve_options_context =
get_client_resolve_options_context(project_path, ty, mode, next_config, execution_context);
get_client_resolve_options_context(project_path, ty, mode, next_config, *execution_context);

let tsconfig = get_typescript_transform_options(project_path);
let decorators_options = get_decorators_transform_options(project_path);
Expand Down Expand Up @@ -312,7 +312,7 @@ pub async fn get_client_module_options_context(
ecmascript: EcmascriptOptionsContext {
enable_jsx: Some(jsx_runtime_options),
enable_typescript_transform: Some(tsconfig),
enable_decorators: Some(decorators_options),
enable_decorators: Some(decorators_options.to_resolved().await?),
..module_options_context.ecmascript.clone()
},
enable_webpack_loaders,
Expand Down Expand Up @@ -408,8 +408,10 @@ pub async fn get_client_runtime_entries(
// 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_root.join("_".into())).cell())
runtime_entries.push(
RuntimeEntry::Request(request.to_resolved().await?, project_root.join("_".into()))
.cell(),
)
};
}

Expand All @@ -418,7 +420,9 @@ pub async fn get_client_runtime_entries(
RuntimeEntry::Request(
Request::parse(Value::new(Pattern::Constant(
"next/dist/client/app-next-turbopack.js".into(),
))),
)))
.to_resolved()
.await?,
project_root.join("_".into()),
)
.cell(),
Expand Down
8 changes: 4 additions & 4 deletions crates/next-core/src/next_client/runtime_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use turbopack_ecmascript::resolve::cjs_resolve;

#[turbo_tasks::value(shared)]
pub enum RuntimeEntry {
Request(Vc<Request>, Vc<FileSystemPath>),
Evaluatable(Vc<Box<dyn EvaluatableAsset>>),
Request(ResolvedVc<Request>, Vc<FileSystemPath>),
Evaluatable(ResolvedVc<Box<dyn EvaluatableAsset>>),
Source(ResolvedVc<Box<dyn Source>>),
}

Expand All @@ -25,7 +25,7 @@ impl RuntimeEntry {
asset_context: Vc<Box<dyn AssetContext>>,
) -> Result<Vc<EvaluatableAssets>> {
let (request, path) = match *self.await? {
RuntimeEntry::Evaluatable(e) => return Ok(EvaluatableAssets::one(e)),
RuntimeEntry::Evaluatable(e) => return Ok(EvaluatableAssets::one(*e)),
RuntimeEntry::Source(source) => {
return Ok(EvaluatableAssets::one(source.to_evaluatable(asset_context)));
}
Expand All @@ -34,7 +34,7 @@ impl RuntimeEntry {

let modules = cjs_resolve(
Vc::upcast(PlainResolveOrigin::new(asset_context, path)),
request,
*request,
None,
false,
)
Expand Down
16 changes: 12 additions & 4 deletions crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashSet;
use anyhow::{bail, Context, Result};
use serde::{Deserialize, Deserializer, Serialize};
use serde_json::Value as JsonValue;
use turbo_tasks::{trace::TraceRawVcs, FxIndexMap, RcStr, TaskInput, Vc};
use turbo_tasks::{trace::TraceRawVcs, FxIndexMap, RcStr, ResolvedVc, TaskInput, Vc};
use turbo_tasks_env::EnvMap;
use turbo_tasks_fs::FileSystemPath;
use turbopack::module_options::{
Expand Down Expand Up @@ -481,7 +481,7 @@ pub enum ReactCompilerOptionsOrBoolean {
}

#[turbo_tasks::value(transparent)]
pub struct OptionalReactCompilerOptions(Option<Vc<ReactCompilerOptions>>);
pub struct OptionalReactCompilerOptions(Option<ResolvedVc<ReactCompilerOptions>>);

#[turbo_tasks::value(eq = "manual")]
#[derive(Clone, Debug, Default, PartialEq)]
Expand Down Expand Up @@ -561,6 +561,7 @@ pub struct ExperimentalConfig {
/// directory.
ppr: Option<ExperimentalPartialPrerendering>,
taint: Option<bool>,
react_owner_stack: Option<bool>,
#[serde(rename = "dynamicIO")]
dynamic_io: Option<bool>,
proxy_timeout: Option<f64>,
Expand Down Expand Up @@ -1080,11 +1081,11 @@ impl NextConfig {
compilation_mode: None,
panic_threshold: None,
}
.cell(),
.resolved_cell(),
))
}
Some(ReactCompilerOptionsOrBoolean::Option(options)) => OptionalReactCompilerOptions(
Some(ReactCompilerOptions { ..options.clone() }.cell()),
Some(ReactCompilerOptions { ..options.clone() }.resolved_cell()),
),
_ => OptionalReactCompilerOptions(None),
};
Expand Down Expand Up @@ -1148,6 +1149,13 @@ impl NextConfig {
Vc::cell(self.experimental.taint.unwrap_or(false))
}

#[turbo_tasks::function]
pub async fn enable_react_owner_stack(self: Vc<Self>) -> Result<Vc<bool>> {
Ok(Vc::cell(
self.await?.experimental.react_owner_stack.unwrap_or(false),
))
}

#[turbo_tasks::function]
pub fn use_swc_css(&self) -> Vc<bool> {
Vc::cell(
Expand Down
4 changes: 2 additions & 2 deletions crates/next-core/src/next_edge/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use turbo_tasks::{FxIndexMap, RcStr, Value, Vc};
use turbo_tasks::{FxIndexMap, RcStr, ResolvedVc, Value, Vc};
use turbo_tasks_env::EnvMap;
use turbo_tasks_fs::FileSystemPath;
use turbopack::resolve_options_context::ResolveOptionsContext;
Expand Down Expand Up @@ -60,7 +60,7 @@ async fn next_edge_defines(define_env: Vc<EnvMap>) -> Result<Vc<CompileTimeDefin
/// See [here](https://github.com/vercel/next.js/blob/160bb99b06e9c049f88e25806fd995f07f4cc7e1/packages/next/src/build/webpack-config.ts#L1715-L1718) how webpack configures it.
#[turbo_tasks::function]
async fn next_edge_free_vars(
project_path: Vc<FileSystemPath>,
project_path: ResolvedVc<FileSystemPath>,
define_env: Vc<EnvMap>,
) -> Result<Vc<FreeVarReferences>> {
Ok(free_var_references!(
Expand Down
Loading

0 comments on commit 032ea1f

Please sign in to comment.