Unverified Commit 8ef121df authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Implement new runtime_type for Turbopack (#63212)

## What?

Implementation of https://github.com/vercel/turbo/pull/7711

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->


Closes NEXT-2791

---------
Co-authored-by: 's avatarTobias Koppers <tobias.koppers@googlemail.com>
parent 500bc1fe
This diff is collapsed.
...@@ -37,11 +37,11 @@ swc_core = { version = "0.90.17", features = [ ...@@ -37,11 +37,11 @@ swc_core = { version = "0.90.17", features = [
testing = { version = "0.35.20" } testing = { version = "0.35.20" }
# Turbo crates # Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240313.3" } turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240313.5" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros.. # [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240313.3" } turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240313.5" }
# [TODO]: need to refactor embed_directory! macro usage in next-core # [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240313.3" } turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240313.5" }
# General Deps # General Deps
......
...@@ -493,8 +493,9 @@ impl Project { ...@@ -493,8 +493,9 @@ impl Project {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub(super) fn execution_context(self: Vc<Self>) -> Vc<ExecutionContext> { pub(super) async fn execution_context(self: Vc<Self>) -> Result<Vc<ExecutionContext>> {
let node_root = self.node_root(); let node_root = self.node_root();
let next_mode = self.next_mode().await?;
let node_execution_chunking_context = Vc::upcast( let node_execution_chunking_context = Vc::upcast(
BrowserChunkingContext::builder( BrowserChunkingContext::builder(
...@@ -504,15 +505,16 @@ impl Project { ...@@ -504,15 +505,16 @@ impl Project {
node_root.join("chunks".to_string()), node_root.join("chunks".to_string()),
node_root.join("assets".to_string()), node_root.join("assets".to_string()),
node_build_environment(), node_build_environment(),
next_mode.runtime_type(),
) )
.build(), .build(),
); );
ExecutionContext::new( Ok(ExecutionContext::new(
self.project_path(), self.project_path(),
node_execution_chunking_context, node_execution_chunking_context,
self.env(), self.env(),
) ))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -584,6 +586,7 @@ impl Project { ...@@ -584,6 +586,7 @@ impl Project {
) )
} else { } else {
get_edge_chunking_context( get_edge_chunking_context(
self.next_mode(),
self.project_path(), self.project_path(),
self.node_root(), self.node_root(),
self.edge_compile_time_info().environment(), self.edge_compile_time_info().environment(),
......
use turbo_tasks::TaskInput; use turbo_tasks::TaskInput;
use turbopack_binding::turbopack::{core::chunk::MinifyType, ecmascript_runtime::RuntimeType};
/// The mode in which Next.js is running. /// The mode in which Next.js is running.
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
...@@ -41,10 +42,17 @@ impl NextMode { ...@@ -41,10 +42,17 @@ impl NextMode {
} }
} }
pub fn should_minify(&self) -> bool { pub fn minify_type(&self) -> MinifyType {
match self { match self {
NextMode::Development => false, NextMode::Development => MinifyType::NoMinify,
NextMode::Build => true, NextMode::Build => MinifyType::Minify,
}
}
pub fn runtime_type(&self) -> RuntimeType {
match self {
NextMode::Development => RuntimeType::Development,
NextMode::Build => RuntimeType::Production,
} }
} }
} }
...@@ -9,7 +9,6 @@ use turbopack_binding::{ ...@@ -9,7 +9,6 @@ use turbopack_binding::{
turbopack::{ turbopack::{
browser::{react_refresh::assert_can_resolve_react_refresh, BrowserChunkingContext}, browser::{react_refresh::assert_can_resolve_react_refresh, BrowserChunkingContext},
core::{ core::{
chunk::MinifyType,
compile_time_info::{ compile_time_info::{
CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, FreeVarReference, CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, FreeVarReference,
FreeVarReferences, FreeVarReferences,
...@@ -346,13 +345,10 @@ pub async fn get_client_chunking_context( ...@@ -346,13 +345,10 @@ pub async fn get_client_chunking_context(
client_root.join("static/chunks".to_string()), client_root.join("static/chunks".to_string()),
get_client_assets_path(client_root), get_client_assets_path(client_root),
environment, environment,
next_mode.runtime_type(),
) )
.chunk_base_path(asset_prefix) .chunk_base_path(asset_prefix)
.minify_type(if next_mode.should_minify() { .minify_type(next_mode.minify_type())
MinifyType::Minify
} else {
MinifyType::NoMinify
})
.asset_base_path(asset_prefix); .asset_base_path(asset_prefix);
if next_mode.is_development() { if next_mode.is_development() {
......
...@@ -6,7 +6,6 @@ use turbopack_binding::{ ...@@ -6,7 +6,6 @@ use turbopack_binding::{
turbopack::{ turbopack::{
browser::BrowserChunkingContext, browser::BrowserChunkingContext,
core::{ core::{
chunk::MinifyType,
compile_time_info::{ compile_time_info::{
CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, FreeVarReference, CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, FreeVarReference,
FreeVarReferences, FreeVarReferences,
...@@ -158,6 +157,7 @@ pub async fn get_edge_chunking_context_with_client_assets( ...@@ -158,6 +157,7 @@ pub async fn get_edge_chunking_context_with_client_assets(
environment: Vc<Environment>, environment: Vc<Environment>,
) -> Result<Vc<Box<dyn EcmascriptChunkingContext>>> { ) -> Result<Vc<Box<dyn EcmascriptChunkingContext>>> {
let output_root = node_root.join("server/edge".to_string()); let output_root = node_root.join("server/edge".to_string());
let next_mode = mode.await?;
Ok(Vc::upcast( Ok(Vc::upcast(
BrowserChunkingContext::builder( BrowserChunkingContext::builder(
project_path, project_path,
...@@ -166,26 +166,25 @@ pub async fn get_edge_chunking_context_with_client_assets( ...@@ -166,26 +166,25 @@ pub async fn get_edge_chunking_context_with_client_assets(
output_root.join("chunks".to_string()), output_root.join("chunks".to_string()),
client_root.join("static/media".to_string()), client_root.join("static/media".to_string()),
environment, environment,
next_mode.runtime_type(),
) )
.asset_base_path(asset_prefix) .asset_base_path(asset_prefix)
.reference_chunk_source_maps(should_debug("edge")) .reference_chunk_source_maps(should_debug("edge"))
.minify_type(if mode.await?.should_minify() { .minify_type(next_mode.minify_type())
MinifyType::Minify
} else {
MinifyType::NoMinify
})
.build(), .build(),
)) ))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn get_edge_chunking_context( pub async fn get_edge_chunking_context(
mode: Vc<NextMode>,
project_path: Vc<FileSystemPath>, project_path: Vc<FileSystemPath>,
node_root: Vc<FileSystemPath>, node_root: Vc<FileSystemPath>,
environment: Vc<Environment>, environment: Vc<Environment>,
) -> Vc<Box<dyn EcmascriptChunkingContext>> { ) -> Result<Vc<Box<dyn EcmascriptChunkingContext>>> {
let output_root = node_root.join("server/edge".to_string()); let output_root = node_root.join("server/edge".to_string());
Vc::upcast( let next_mode = mode.await?;
Ok(Vc::upcast(
BrowserChunkingContext::builder( BrowserChunkingContext::builder(
project_path, project_path,
output_root, output_root,
...@@ -193,6 +192,7 @@ pub fn get_edge_chunking_context( ...@@ -193,6 +192,7 @@ pub fn get_edge_chunking_context(
output_root.join("chunks".to_string()), output_root.join("chunks".to_string()),
output_root.join("assets".to_string()), output_root.join("assets".to_string()),
environment, environment,
next_mode.runtime_type(),
) )
// Since one can't read files in edge directly, any asset need to be fetched // Since one can't read files in edge directly, any asset need to be fetched
// instead. This special blob url is handled by the custom fetch // instead. This special blob url is handled by the custom fetch
...@@ -201,5 +201,5 @@ pub fn get_edge_chunking_context( ...@@ -201,5 +201,5 @@ pub fn get_edge_chunking_context(
.asset_base_path(Vc::cell(Some("blob:server/edge/".to_string()))) .asset_base_path(Vc::cell(Some("blob:server/edge/".to_string())))
.reference_chunk_source_maps(should_debug("edge")) .reference_chunk_source_maps(should_debug("edge"))
.build(), .build(),
) ))
} }
...@@ -9,7 +9,6 @@ use turbopack_binding::{ ...@@ -9,7 +9,6 @@ use turbopack_binding::{
}, },
turbopack::{ turbopack::{
core::{ core::{
chunk::MinifyType,
compile_time_info::{ compile_time_info::{
CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, FreeVarReferences, CompileTimeDefineValue, CompileTimeDefines, CompileTimeInfo, FreeVarReferences,
}, },
...@@ -720,6 +719,7 @@ pub async fn get_server_chunking_context( ...@@ -720,6 +719,7 @@ pub async fn get_server_chunking_context(
asset_prefix: Vc<Option<String>>, asset_prefix: Vc<Option<String>>,
environment: Vc<Environment>, environment: Vc<Environment>,
) -> Result<Vc<NodeJsChunkingContext>> { ) -> Result<Vc<NodeJsChunkingContext>> {
let next_mode = mode.await?;
// TODO(alexkirsz) This should return a trait that can be implemented by the // TODO(alexkirsz) This should return a trait that can be implemented by the
// different server chunking contexts. OR the build chunking context should // different server chunking contexts. OR the build chunking context should
// support both production and development modes. // support both production and development modes.
...@@ -730,12 +730,9 @@ pub async fn get_server_chunking_context( ...@@ -730,12 +730,9 @@ pub async fn get_server_chunking_context(
node_root.join("server/chunks".to_string()), node_root.join("server/chunks".to_string()),
client_root.join("static/media".to_string()), client_root.join("static/media".to_string()),
environment, environment,
next_mode.runtime_type(),
) )
.asset_prefix(asset_prefix) .asset_prefix(asset_prefix)
.minify_type(if mode.await?.should_minify() { .minify_type(next_mode.minify_type())
MinifyType::Minify
} else {
MinifyType::NoMinify
})
.build()) .build())
} }
...@@ -192,7 +192,7 @@ ...@@ -192,7 +192,7 @@
"@types/ws": "8.2.0", "@types/ws": "8.2.0",
"@vercel/ncc": "0.34.0", "@vercel/ncc": "0.34.0",
"@vercel/nft": "0.26.4", "@vercel/nft": "0.26.4",
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240313.3", "@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240313.5",
"acorn": "8.5.0", "acorn": "8.5.0",
"amphtml-validator": "1.0.35", "amphtml-validator": "1.0.35",
"anser": "1.4.9", "anser": "1.4.9",
......
...@@ -1071,8 +1071,8 @@ importers: ...@@ -1071,8 +1071,8 @@ importers:
specifier: 0.26.4 specifier: 0.26.4
version: 0.26.4 version: 0.26.4
'@vercel/turbopack-ecmascript-runtime': '@vercel/turbopack-ecmascript-runtime':
specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240313.3 specifier: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240313.5
version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240313.3' version: '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240313.5'
acorn: acorn:
specifier: 8.5.0 specifier: 8.5.0
version: 8.5.0 version: 8.5.0
...@@ -25494,8 +25494,8 @@ packages: ...@@ -25494,8 +25494,8 @@ packages:
/zwitch@2.0.4: /zwitch@2.0.4:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==} resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
'@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240313.3': '@gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240313.5':
resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240313.3} resolution: {tarball: https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240313.5}
name: '@vercel/turbopack-ecmascript-runtime' name: '@vercel/turbopack-ecmascript-runtime'
version: 0.0.0 version: 0.0.0
dependencies: dependencies:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment