Unverified Commit 5aad9142 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: add experimental.turbopackInputSourceMaps and respect serverSourceMaps (#86340)

<!-- 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

### 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 #

-->
parent fbc9a2b9
...@@ -43,7 +43,7 @@ use turbopack_core::{ ...@@ -43,7 +43,7 @@ use turbopack_core::{
PROJECT_FILESYSTEM_NAME, PROJECT_FILESYSTEM_NAME,
changed::content_changed, changed::content_changed,
chunk::{ chunk::{
ChunkingContext, EvaluatableAssets, SourceMapsType, ChunkingContext, EvaluatableAssets,
module_id_strategies::{DevModuleIdStrategy, ModuleIdStrategy}, module_id_strategies::{DevModuleIdStrategy, ModuleIdStrategy},
}, },
compile_time_info::CompileTimeInfo, compile_time_info::CompileTimeInfo,
...@@ -861,11 +861,7 @@ impl Project { ...@@ -861,11 +861,7 @@ impl Project {
node_build_environment().to_resolved().await?, node_build_environment().to_resolved().await?,
next_mode.runtime_type(), next_mode.runtime_type(),
) )
.source_maps(if *self.next_config().server_source_maps().await? { .source_maps(*self.next_config().server_source_maps().await?)
SourceMapsType::Full
} else {
SourceMapsType::None
})
.build(), .build(),
); );
...@@ -1156,8 +1152,8 @@ impl Project { ...@@ -1156,8 +1152,8 @@ impl Project {
environment: self.server_compile_time_info().environment(), environment: self.server_compile_time_info().environment(),
module_id_strategy: self.module_ids(), module_id_strategy: self.module_ids(),
export_usage: self.export_usage(), export_usage: self.export_usage(),
turbo_minify: self.next_config().turbo_minify(self.next_mode()), minify: self.next_config().turbo_minify(self.next_mode()),
turbo_source_maps: self.next_config().server_source_maps(), source_maps: self.next_config().server_source_maps(),
no_mangling: self.no_mangling(), no_mangling: self.no_mangling(),
scope_hoisting: self.next_config().turbo_scope_hoisting(self.next_mode()), scope_hoisting: self.next_config().turbo_scope_hoisting(self.next_mode()),
nested_async_chunking: self nested_async_chunking: self
......
...@@ -320,11 +320,7 @@ pub async fn get_client_module_options_context( ...@@ -320,11 +320,7 @@ pub async fn get_client_module_options_context(
let enable_postcss_transform = Some(postcss_transform_options.resolved_cell()); let enable_postcss_transform = Some(postcss_transform_options.resolved_cell());
let enable_foreign_postcss_transform = Some(postcss_foreign_transform_options.resolved_cell()); let enable_foreign_postcss_transform = Some(postcss_foreign_transform_options.resolved_cell());
let source_maps = if *next_config.client_source_maps(mode).await? { let source_maps = *next_config.client_source_maps(mode).await?;
SourceMapsType::Full
} else {
SourceMapsType::None
};
let module_options_context = ModuleOptionsContext { let module_options_context = ModuleOptionsContext {
ecmascript: EcmascriptOptionsContext { ecmascript: EcmascriptOptionsContext {
enable_typeof_window_inlining: Some(TypeofWindow::Object), enable_typeof_window_inlining: Some(TypeofWindow::Object),
...@@ -423,7 +419,7 @@ pub struct ClientChunkingContextOptions { ...@@ -423,7 +419,7 @@ pub struct ClientChunkingContextOptions {
pub module_id_strategy: Vc<Box<dyn ModuleIdStrategy>>, pub module_id_strategy: Vc<Box<dyn ModuleIdStrategy>>,
pub export_usage: Vc<OptionExportUsageInfo>, pub export_usage: Vc<OptionExportUsageInfo>,
pub minify: Vc<bool>, pub minify: Vc<bool>,
pub source_maps: Vc<bool>, pub source_maps: Vc<SourceMapsType>,
pub no_mangling: Vc<bool>, pub no_mangling: Vc<bool>,
pub scope_hoisting: Vc<bool>, pub scope_hoisting: Vc<bool>,
pub nested_async_chunking: Vc<bool>, pub nested_async_chunking: Vc<bool>,
...@@ -476,11 +472,7 @@ pub async fn get_client_chunking_context( ...@@ -476,11 +472,7 @@ pub async fn get_client_chunking_context(
} else { } else {
MinifyType::NoMinify MinifyType::NoMinify
}) })
.source_maps(if *source_maps.await? { .source_maps(*source_maps.await?)
SourceMapsType::Full
} else {
SourceMapsType::None
})
.asset_base_path(Some(asset_prefix)) .asset_base_path(Some(asset_prefix))
.current_chunk_method(CurrentChunkMethod::DocumentCurrentScript) .current_chunk_method(CurrentChunkMethod::DocumentCurrentScript)
.export_usage(*export_usage.await?) .export_usage(*export_usage.await?)
......
...@@ -17,6 +17,7 @@ use turbopack::module_options::{ ...@@ -17,6 +17,7 @@ use turbopack::module_options::{
module_options_context::MdxTransformOptions, module_options_context::MdxTransformOptions,
}; };
use turbopack_core::{ use turbopack_core::{
chunk::SourceMapsType,
issue::{Issue, IssueExt, IssueStage, OptionStyledString, StyledString}, issue::{Issue, IssueExt, IssueStage, OptionStyledString, StyledString},
resolve::ResolveAliasMap, resolve::ResolveAliasMap,
}; };
...@@ -884,6 +885,7 @@ pub struct ExperimentalConfig { ...@@ -884,6 +885,7 @@ pub struct ExperimentalConfig {
turbopack_module_ids: Option<ModuleIds>, turbopack_module_ids: Option<ModuleIds>,
turbopack_persistent_caching: Option<bool>, turbopack_persistent_caching: Option<bool>,
turbopack_source_maps: Option<bool>, turbopack_source_maps: Option<bool>,
turbopack_input_source_maps: Option<bool>,
turbopack_tree_shaking: Option<bool>, turbopack_tree_shaking: Option<bool>,
turbopack_scope_hoisting: Option<bool>, turbopack_scope_hoisting: Option<bool>,
turbopack_client_side_nested_async_chunking: Option<bool>, turbopack_client_side_nested_async_chunking: Option<bool>,
...@@ -1825,18 +1827,43 @@ impl NextConfig { ...@@ -1825,18 +1827,43 @@ impl NextConfig {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn client_source_maps(&self, mode: Vc<NextMode>) -> Result<Vc<bool>> { pub async fn client_source_maps(&self, mode: Vc<NextMode>) -> Result<Vc<SourceMapsType>> {
let source_maps = self.experimental.turbopack_source_maps; let input_source_maps = self
Ok(Vc::cell(source_maps.unwrap_or(match &*mode.await? { .experimental
NextMode::Development => true, .turbopack_input_source_maps
NextMode::Build => self.production_browser_source_maps, .unwrap_or(true);
}))) let source_maps = self
.experimental
.turbopack_source_maps
.unwrap_or(match &*mode.await? {
NextMode::Development => true,
NextMode::Build => self.production_browser_source_maps,
});
Ok(match (source_maps, input_source_maps) {
(true, true) => SourceMapsType::Full,
(true, false) => SourceMapsType::Partial,
(false, _) => SourceMapsType::None,
}
.cell())
} }
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn server_source_maps(&self) -> Result<Vc<bool>> { pub fn server_source_maps(&self) -> Result<Vc<SourceMapsType>> {
let source_maps = self.experimental.turbopack_source_maps; let input_source_maps = self
Ok(Vc::cell(source_maps.unwrap_or(true))) .experimental
.turbopack_input_source_maps
.unwrap_or(true);
let source_maps = self
.experimental
.turbopack_source_maps
.or(self.experimental.server_source_maps)
.unwrap_or(true);
Ok(match (source_maps, input_source_maps) {
(true, true) => SourceMapsType::Full,
(true, false) => SourceMapsType::Partial,
(false, _) => SourceMapsType::None,
}
.cell())
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -205,7 +205,7 @@ pub struct EdgeChunkingContextOptions { ...@@ -205,7 +205,7 @@ pub struct EdgeChunkingContextOptions {
pub module_id_strategy: Vc<Box<dyn ModuleIdStrategy>>, pub module_id_strategy: Vc<Box<dyn ModuleIdStrategy>>,
pub export_usage: Vc<OptionExportUsageInfo>, pub export_usage: Vc<OptionExportUsageInfo>,
pub turbo_minify: Vc<bool>, pub turbo_minify: Vc<bool>,
pub turbo_source_maps: Vc<bool>, pub turbo_source_maps: Vc<SourceMapsType>,
pub no_mangling: Vc<bool>, pub no_mangling: Vc<bool>,
pub scope_hoisting: Vc<bool>, pub scope_hoisting: Vc<bool>,
pub nested_async_chunking: Vc<bool>, pub nested_async_chunking: Vc<bool>,
...@@ -255,11 +255,7 @@ pub async fn get_edge_chunking_context_with_client_assets( ...@@ -255,11 +255,7 @@ pub async fn get_edge_chunking_context_with_client_assets(
} else { } else {
MinifyType::NoMinify MinifyType::NoMinify
}) })
.source_maps(if *turbo_source_maps.await? { .source_maps(*turbo_source_maps.await?)
SourceMapsType::Full
} else {
SourceMapsType::None
})
.module_id_strategy(module_id_strategy.to_resolved().await?) .module_id_strategy(module_id_strategy.to_resolved().await?)
.export_usage(*export_usage.await?) .export_usage(*export_usage.await?)
.nested_async_availability(*nested_async_chunking.await?); .nested_async_availability(*nested_async_chunking.await?);
...@@ -334,11 +330,7 @@ pub async fn get_edge_chunking_context( ...@@ -334,11 +330,7 @@ pub async fn get_edge_chunking_context(
} else { } else {
MinifyType::NoMinify MinifyType::NoMinify
}) })
.source_maps(if *turbo_source_maps.await? { .source_maps(*turbo_source_maps.await?)
SourceMapsType::Full
} else {
SourceMapsType::None
})
.module_id_strategy(module_id_strategy.to_resolved().await?) .module_id_strategy(module_id_strategy.to_resolved().await?)
.export_usage(*export_usage.await?) .export_usage(*export_usage.await?)
.nested_async_availability(*nested_async_chunking.await?); .nested_async_availability(*nested_async_chunking.await?);
......
...@@ -577,11 +577,7 @@ pub async fn get_server_module_options_context( ...@@ -577,11 +577,7 @@ pub async fn get_server_module_options_context(
.flatten() .flatten()
.collect(); .collect();
let source_maps = if *next_config.server_source_maps().await? { let source_maps = *next_config.server_source_maps().await?;
SourceMapsType::Full
} else {
SourceMapsType::None
};
let module_options_context = ModuleOptionsContext { let module_options_context = ModuleOptionsContext {
ecmascript: EcmascriptOptionsContext { ecmascript: EcmascriptOptionsContext {
enable_typeof_window_inlining: Some(TypeofWindow::Undefined), enable_typeof_window_inlining: Some(TypeofWindow::Undefined),
...@@ -996,8 +992,8 @@ pub struct ServerChunkingContextOptions { ...@@ -996,8 +992,8 @@ pub struct ServerChunkingContextOptions {
pub environment: Vc<Environment>, pub environment: Vc<Environment>,
pub module_id_strategy: Vc<Box<dyn ModuleIdStrategy>>, pub module_id_strategy: Vc<Box<dyn ModuleIdStrategy>>,
pub export_usage: Vc<OptionExportUsageInfo>, pub export_usage: Vc<OptionExportUsageInfo>,
pub turbo_minify: Vc<bool>, pub minify: Vc<bool>,
pub turbo_source_maps: Vc<bool>, pub source_maps: Vc<SourceMapsType>,
pub no_mangling: Vc<bool>, pub no_mangling: Vc<bool>,
pub scope_hoisting: Vc<bool>, pub scope_hoisting: Vc<bool>,
pub nested_async_chunking: Vc<bool>, pub nested_async_chunking: Vc<bool>,
...@@ -1019,8 +1015,8 @@ pub async fn get_server_chunking_context_with_client_assets( ...@@ -1019,8 +1015,8 @@ pub async fn get_server_chunking_context_with_client_assets(
environment, environment,
module_id_strategy, module_id_strategy,
export_usage, export_usage,
turbo_minify, minify,
turbo_source_maps, source_maps,
no_mangling, no_mangling,
scope_hoisting, scope_hoisting,
nested_async_chunking, nested_async_chunking,
...@@ -1044,7 +1040,7 @@ pub async fn get_server_chunking_context_with_client_assets( ...@@ -1044,7 +1040,7 @@ pub async fn get_server_chunking_context_with_client_assets(
next_mode.runtime_type(), next_mode.runtime_type(),
) )
.asset_prefix(Some(asset_prefix)) .asset_prefix(Some(asset_prefix))
.minify_type(if *turbo_minify.await? { .minify_type(if *minify.await? {
MinifyType::Minify { MinifyType::Minify {
// React needs deterministic function names to work correctly. // React needs deterministic function names to work correctly.
mangle: (!*no_mangling.await?).then_some(MangleType::Deterministic), mangle: (!*no_mangling.await?).then_some(MangleType::Deterministic),
...@@ -1052,11 +1048,7 @@ pub async fn get_server_chunking_context_with_client_assets( ...@@ -1052,11 +1048,7 @@ pub async fn get_server_chunking_context_with_client_assets(
} else { } else {
MinifyType::NoMinify MinifyType::NoMinify
}) })
.source_maps(if *turbo_source_maps.await? { .source_maps(*source_maps.await?)
SourceMapsType::Full
} else {
SourceMapsType::None
})
.module_id_strategy(module_id_strategy.to_resolved().await?) .module_id_strategy(module_id_strategy.to_resolved().await?)
.export_usage(*export_usage.await?) .export_usage(*export_usage.await?)
.file_tracing(next_mode.is_production()) .file_tracing(next_mode.is_production())
...@@ -1105,8 +1097,8 @@ pub async fn get_server_chunking_context( ...@@ -1105,8 +1097,8 @@ pub async fn get_server_chunking_context(
environment, environment,
module_id_strategy, module_id_strategy,
export_usage, export_usage,
turbo_minify, minify,
turbo_source_maps, source_maps,
no_mangling, no_mangling,
scope_hoisting, scope_hoisting,
nested_async_chunking, nested_async_chunking,
...@@ -1131,18 +1123,14 @@ pub async fn get_server_chunking_context( ...@@ -1131,18 +1123,14 @@ pub async fn get_server_chunking_context(
.client_roots_override(rcstr!("client"), client_root.clone()) .client_roots_override(rcstr!("client"), client_root.clone())
.asset_root_path_override(rcstr!("client"), client_root.join("static/media")?) .asset_root_path_override(rcstr!("client"), client_root.join("static/media")?)
.asset_prefix_override(rcstr!("client"), asset_prefix) .asset_prefix_override(rcstr!("client"), asset_prefix)
.minify_type(if *turbo_minify.await? { .minify_type(if *minify.await? {
MinifyType::Minify { MinifyType::Minify {
mangle: (!*no_mangling.await?).then_some(MangleType::OptimalSize), mangle: (!*no_mangling.await?).then_some(MangleType::OptimalSize),
} }
} else { } else {
MinifyType::NoMinify MinifyType::NoMinify
}) })
.source_maps(if *turbo_source_maps.await? { .source_maps(*source_maps.await?)
SourceMapsType::Full
} else {
SourceMapsType::None
})
.module_id_strategy(module_id_strategy.to_resolved().await?) .module_id_strategy(module_id_strategy.to_resolved().await?)
.export_usage(*export_usage.await?) .export_usage(*export_usage.await?)
.file_tracing(next_mode.is_production()) .file_tracing(next_mode.is_production())
......
...@@ -298,6 +298,7 @@ export const experimentalSchema = { ...@@ -298,6 +298,7 @@ export const experimentalSchema = {
turbopackFileSystemCacheForDev: z.boolean().optional(), turbopackFileSystemCacheForDev: z.boolean().optional(),
turbopackFileSystemCacheForBuild: z.boolean().optional(), turbopackFileSystemCacheForBuild: z.boolean().optional(),
turbopackSourceMaps: z.boolean().optional(), turbopackSourceMaps: z.boolean().optional(),
turbopackInputSourceMaps: z.boolean().optional(),
turbopackTreeShaking: z.boolean().optional(), turbopackTreeShaking: z.boolean().optional(),
turbopackRemoveUnusedExports: z.boolean().optional(), turbopackRemoveUnusedExports: z.boolean().optional(),
turbopackScopeHoisting: z.boolean().optional(), turbopackScopeHoisting: z.boolean().optional(),
......
...@@ -440,6 +440,11 @@ export interface ExperimentalConfig { ...@@ -440,6 +440,11 @@ export interface ExperimentalConfig {
*/ */
turbopackSourceMaps?: boolean turbopackSourceMaps?: boolean
/**
* Enable extraction of source maps from input files. Defaults to true.
*/
turbopackInputSourceMaps?: boolean
/** /**
* Enable tree shaking for the turbopack dev server and build. * Enable tree shaking for the turbopack dev server and build.
*/ */
...@@ -1468,7 +1473,6 @@ export const defaultConfig = Object.freeze({ ...@@ -1468,7 +1473,6 @@ export const defaultConfig = Object.freeze({
appNavFailHandling: false, appNavFailHandling: false,
prerenderEarlyExit: true, prerenderEarlyExit: true,
serverMinification: true, serverMinification: true,
serverSourceMaps: false,
linkNoTouchStart: false, linkNoTouchStart: false,
caseSensitiveRoutes: false, caseSensitiveRoutes: false,
clientParamParsingOrigins: undefined, clientParamParsingOrigins: undefined,
......
...@@ -573,6 +573,7 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -573,6 +573,7 @@ impl ChunkingContext for BrowserChunkingContext {
fn reference_chunk_source_maps(&self, _chunk: Vc<Box<dyn OutputAsset>>) -> Vc<bool> { fn reference_chunk_source_maps(&self, _chunk: Vc<Box<dyn OutputAsset>>) -> Vc<bool> {
Vc::cell(match self.source_maps_type { Vc::cell(match self.source_maps_type {
SourceMapsType::Full => true, SourceMapsType::Full => true,
SourceMapsType::Partial => true,
SourceMapsType::None => false, SourceMapsType::None => false,
}) })
} }
...@@ -581,6 +582,7 @@ impl ChunkingContext for BrowserChunkingContext { ...@@ -581,6 +582,7 @@ impl ChunkingContext for BrowserChunkingContext {
fn reference_module_source_maps(&self, _module: Vc<Box<dyn Module>>) -> Vc<bool> { fn reference_module_source_maps(&self, _module: Vc<Box<dyn Module>>) -> Vc<bool> {
Vc::cell(match self.source_maps_type { Vc::cell(match self.source_maps_type {
SourceMapsType::Full => true, SourceMapsType::Full => true,
SourceMapsType::Partial => true,
SourceMapsType::None => false, SourceMapsType::None => false,
}) })
} }
......
...@@ -66,6 +66,8 @@ pub enum SourceMapsType { ...@@ -66,6 +66,8 @@ pub enum SourceMapsType {
/// Extracts source maps from input files and writes source maps for output files. /// Extracts source maps from input files and writes source maps for output files.
#[default] #[default]
Full, Full,
/// Ignores existing input source maps, but writes source maps for output files.
Partial,
/// Ignores the existence of source maps and does not write source maps for output files. /// Ignores the existence of source maps and does not write source maps for output files.
None, None,
} }
......
...@@ -387,6 +387,7 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -387,6 +387,7 @@ impl ChunkingContext for NodeJsChunkingContext {
fn reference_chunk_source_maps(&self, _chunk: Vc<Box<dyn OutputAsset>>) -> Vc<bool> { fn reference_chunk_source_maps(&self, _chunk: Vc<Box<dyn OutputAsset>>) -> Vc<bool> {
Vc::cell(match self.source_maps_type { Vc::cell(match self.source_maps_type {
SourceMapsType::Full => true, SourceMapsType::Full => true,
SourceMapsType::Partial => true,
SourceMapsType::None => false, SourceMapsType::None => false,
}) })
} }
...@@ -395,6 +396,7 @@ impl ChunkingContext for NodeJsChunkingContext { ...@@ -395,6 +396,7 @@ impl ChunkingContext for NodeJsChunkingContext {
fn reference_module_source_maps(&self, _module: Vc<Box<dyn Module>>) -> Vc<bool> { fn reference_module_source_maps(&self, _module: Vc<Box<dyn Module>>) -> Vc<bool> {
Vc::cell(match self.source_maps_type { Vc::cell(match self.source_maps_type {
SourceMapsType::Full => true, SourceMapsType::Full => true,
SourceMapsType::Partial => true,
SourceMapsType::None => false, SourceMapsType::None => false,
}) })
} }
......
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