Skip to content

Commit

Permalink
Implement Vc<NextMode> (#62099)
Browse files Browse the repository at this point in the history
## What?

Ensures that `NextMode` is passed through based on the project setting
instead of hardcoding it to development in various places in the
Turbopack integration.

<!-- 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-2503
  • Loading branch information
timneutkens committed Feb 15, 2024
1 parent 00633f1 commit 2b177d6
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 727 deletions.
48 changes: 13 additions & 35 deletions packages/next-swc/crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use next_core::{
MetadataItem,
},
get_edge_resolve_options_context,
mode::NextMode,
next_app::{
app_client_references_chunks::get_app_server_reference_modules,
get_app_client_references_chunks, get_app_client_shared_chunks, get_app_page_entry,
Expand Down Expand Up @@ -75,7 +74,6 @@ use crate::{
pub struct AppProject {
project: Vc<Project>,
app_dir: Vc<FileSystemPath>,
mode: NextMode,
}

#[turbo_tasks::value(transparent)]
Expand Down Expand Up @@ -108,13 +106,8 @@ const ECMASCRIPT_CLIENT_TRANSITION_NAME: &str = "next-ecmascript-client-referenc
#[turbo_tasks::value_impl]
impl AppProject {
#[turbo_tasks::function]
pub fn new(project: Vc<Project>, app_dir: Vc<FileSystemPath>, mode: NextMode) -> Vc<Self> {
AppProject {
project,
app_dir,
mode,
}
.cell()
pub fn new(project: Vc<Project>, app_dir: Vc<FileSystemPath>) -> Vc<Self> {
AppProject { project, app_dir }.cell()
}

#[turbo_tasks::function]
Expand All @@ -127,36 +120,29 @@ impl AppProject {
self.app_dir
}

#[turbo_tasks::function]
fn mode(&self) -> Vc<NextMode> {
self.mode.cell()
}

#[turbo_tasks::function]
fn app_entrypoints(&self) -> Vc<AppEntrypoints> {
get_entrypoints(self.app_dir, self.project.next_config().page_extensions())
}

#[turbo_tasks::function]
async fn client_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
let this = self.await?;
Ok(get_client_module_options_context(
self.project().project_path(),
self.project().execution_context(),
self.project().client_compile_time_info().environment(),
Value::new(self.client_ty()),
this.mode,
self.project().next_mode(),
self.project().next_config(),
))
}

#[turbo_tasks::function]
async fn client_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
let this = self.await?;
Ok(get_client_resolve_options_context(
self.project().project_path(),
Value::new(self.client_ty()),
this.mode,
self.project().next_mode(),
self.project().next_config(),
self.project().execution_context(),
))
Expand All @@ -179,35 +165,32 @@ impl AppProject {

#[turbo_tasks::function]
async fn rsc_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
let this = self.await?;
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Value::new(self.rsc_ty()),
this.mode,
self.project().next_mode(),
self.project().next_config(),
))
}

#[turbo_tasks::function]
async fn rsc_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
let this = self.await?;
Ok(get_server_resolve_options_context(
self.project().project_path(),
Value::new(self.rsc_ty()),
this.mode,
self.project().next_mode(),
self.project().next_config(),
self.project().execution_context(),
))
}

#[turbo_tasks::function]
async fn edge_rsc_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
let this = self.await?;
Ok(get_edge_resolve_options_context(
self.project().project_path(),
Value::new(self.rsc_ty()),
this.mode,
self.project().next_mode(),
self.project().next_config(),
self.project().execution_context(),
))
Expand Down Expand Up @@ -283,35 +266,32 @@ impl AppProject {

#[turbo_tasks::function]
async fn ssr_module_options_context(self: Vc<Self>) -> Result<Vc<ModuleOptionsContext>> {
let this = self.await?;
Ok(get_server_module_options_context(
self.project().project_path(),
self.project().execution_context(),
Value::new(self.ssr_ty()),
this.mode,
self.project().next_mode(),
self.project().next_config(),
))
}

#[turbo_tasks::function]
async fn ssr_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
let this = self.await?;
Ok(get_server_resolve_options_context(
self.project().project_path(),
Value::new(self.ssr_ty()),
this.mode,
self.project().next_mode(),
self.project().next_config(),
self.project().execution_context(),
))
}

#[turbo_tasks::function]
async fn edge_ssr_resolve_options_context(self: Vc<Self>) -> Result<Vc<ResolveOptionsContext>> {
let this = self.await?;
Ok(get_edge_resolve_options_context(
self.project().project_path(),
Value::new(self.ssr_ty()),
this.mode,
self.project().next_mode(),
self.project().next_config(),
self.project().execution_context(),
))
Expand Down Expand Up @@ -339,10 +319,9 @@ impl AppProject {

#[turbo_tasks::function]
async fn runtime_entries(self: Vc<Self>) -> Result<Vc<RuntimeEntries>> {
let this = self.await?;
Ok(get_server_runtime_entries(
Value::new(self.rsc_ty()),
this.mode,
self.project().next_mode(),
))
}

Expand All @@ -368,11 +347,10 @@ impl AppProject {

#[turbo_tasks::function]
async fn client_runtime_entries(self: Vc<Self>) -> Result<Vc<EvaluatableAssets>> {
let this = self.await?;
Ok(get_client_runtime_entries(
self.project().project_path(),
Value::new(self.client_ty()),
this.mode,
self.project().next_mode(),
self.project().next_config(),
self.project().execution_context(),
)
Expand Down Expand Up @@ -513,7 +491,7 @@ impl AppEndpoint {
self.app_project.edge_rsc_module_context(),
self.app_project.project().project_path(),
self.page.clone(),
*self.app_project.mode().await?,
*self.app_project.project().next_mode().await?,
metadata,
))
}
Expand Down
5 changes: 2 additions & 3 deletions packages/next-swc/crates/next-api/src/instrumentation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::{bail, Result};
use next_core::{
all_assets_from_entries,
mode::NextMode,
next_edge::entry::wrap_edge_entry,
next_manifests::{InstrumentationDefinition, MiddlewaresManifestV2},
next_server::{get_server_chunking_context, get_server_runtime_entries, ServerContextType},
Expand Down Expand Up @@ -78,7 +77,7 @@ impl InstrumentationEndpoint {

let mut evaluatable_assets = get_server_runtime_entries(
Value::new(ServerContextType::Middleware),
NextMode::Development,
self.project.next_mode(),
)
.resolve_entries(self.context)
.await?
Expand Down Expand Up @@ -136,7 +135,7 @@ impl InstrumentationEndpoint {
module,
get_server_runtime_entries(
Value::new(ServerContextType::Instrumentation),
NextMode::Development,
self.project.next_mode(),
)
.resolve_entries(self.context),
Value::new(AvailabilityInfo::Root),
Expand Down
3 changes: 1 addition & 2 deletions packages/next-swc/crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use anyhow::{bail, Context, Result};
use next_core::{
all_assets_from_entries,
middleware::get_middleware_module,
mode::NextMode,
next_edge::entry::wrap_edge_entry,
next_manifests::{
AssetBinding, EdgeFunctionDefinition, MiddlewareMatcher, MiddlewaresManifestV2,
Expand Down Expand Up @@ -80,7 +79,7 @@ impl MiddlewareEndpoint {

let mut evaluatable_assets = get_server_runtime_entries(
Value::new(ServerContextType::Middleware),
NextMode::Development,
self.project.next_mode(),
)
.resolve_entries(self.context)
.await?
Expand Down

0 comments on commit 2b177d6

Please sign in to comment.