Skip to content

Commit 8cda51e

Browse files
committed
Turbopack: add experimental.turbopackInputSourceMaps and respect serverSourceMaps
1 parent 844ec47 commit 8cda51e

File tree

10 files changed

+69
-63
lines changed

10 files changed

+69
-63
lines changed

crates/next-api/src/project.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use turbopack_core::{
4343
PROJECT_FILESYSTEM_NAME,
4444
changed::content_changed,
4545
chunk::{
46-
ChunkingContext, EvaluatableAssets, SourceMapsType,
46+
ChunkingContext, EvaluatableAssets,
4747
module_id_strategies::{DevModuleIdStrategy, ModuleIdStrategy},
4848
},
4949
compile_time_info::CompileTimeInfo,
@@ -861,11 +861,7 @@ impl Project {
861861
node_build_environment().to_resolved().await?,
862862
next_mode.runtime_type(),
863863
)
864-
.source_maps(if *self.next_config().server_source_maps().await? {
865-
SourceMapsType::Full
866-
} else {
867-
SourceMapsType::None
868-
})
864+
.source_maps(*self.next_config().server_source_maps().await?)
869865
.build(),
870866
);
871867

@@ -1156,8 +1152,8 @@ impl Project {
11561152
environment: self.server_compile_time_info().environment(),
11571153
module_id_strategy: self.module_ids(),
11581154
export_usage: self.export_usage(),
1159-
turbo_minify: self.next_config().turbo_minify(self.next_mode()),
1160-
turbo_source_maps: self.next_config().server_source_maps(),
1155+
minify: self.next_config().turbo_minify(self.next_mode()),
1156+
source_maps: self.next_config().server_source_maps(),
11611157
no_mangling: self.no_mangling(),
11621158
scope_hoisting: self.next_config().turbo_scope_hoisting(self.next_mode()),
11631159
nested_async_chunking: self

crates/next-core/src/next_client/context.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,7 @@ pub async fn get_client_module_options_context(
320320
let enable_postcss_transform = Some(postcss_transform_options.resolved_cell());
321321
let enable_foreign_postcss_transform = Some(postcss_foreign_transform_options.resolved_cell());
322322

323-
let source_maps = if *next_config.client_source_maps(mode).await? {
324-
SourceMapsType::Full
325-
} else {
326-
SourceMapsType::None
327-
};
323+
let source_maps = *next_config.client_source_maps(mode).await?;
328324
let module_options_context = ModuleOptionsContext {
329325
ecmascript: EcmascriptOptionsContext {
330326
enable_typeof_window_inlining: Some(TypeofWindow::Object),
@@ -423,7 +419,7 @@ pub struct ClientChunkingContextOptions {
423419
pub module_id_strategy: Vc<Box<dyn ModuleIdStrategy>>,
424420
pub export_usage: Vc<OptionExportUsageInfo>,
425421
pub minify: Vc<bool>,
426-
pub source_maps: Vc<bool>,
422+
pub source_maps: Vc<SourceMapsType>,
427423
pub no_mangling: Vc<bool>,
428424
pub scope_hoisting: Vc<bool>,
429425
pub nested_async_chunking: Vc<bool>,
@@ -476,11 +472,7 @@ pub async fn get_client_chunking_context(
476472
} else {
477473
MinifyType::NoMinify
478474
})
479-
.source_maps(if *source_maps.await? {
480-
SourceMapsType::Full
481-
} else {
482-
SourceMapsType::None
483-
})
475+
.source_maps(*source_maps.await?)
484476
.asset_base_path(Some(asset_prefix))
485477
.current_chunk_method(CurrentChunkMethod::DocumentCurrentScript)
486478
.export_usage(*export_usage.await?)

crates/next-core/src/next_config.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use turbopack::module_options::{
1717
module_options_context::MdxTransformOptions,
1818
};
1919
use turbopack_core::{
20+
chunk::SourceMapsType,
2021
issue::{Issue, IssueExt, IssueStage, OptionStyledString, StyledString},
2122
resolve::ResolveAliasMap,
2223
};
@@ -884,6 +885,7 @@ pub struct ExperimentalConfig {
884885
turbopack_module_ids: Option<ModuleIds>,
885886
turbopack_persistent_caching: Option<bool>,
886887
turbopack_source_maps: Option<bool>,
888+
turbopack_input_source_maps: Option<bool>,
887889
turbopack_tree_shaking: Option<bool>,
888890
turbopack_scope_hoisting: Option<bool>,
889891
turbopack_client_side_nested_async_chunking: Option<bool>,
@@ -1825,18 +1827,43 @@ impl NextConfig {
18251827
}
18261828

18271829
#[turbo_tasks::function]
1828-
pub async fn client_source_maps(&self, mode: Vc<NextMode>) -> Result<Vc<bool>> {
1829-
let source_maps = self.experimental.turbopack_source_maps;
1830-
Ok(Vc::cell(source_maps.unwrap_or(match &*mode.await? {
1831-
NextMode::Development => true,
1832-
NextMode::Build => self.production_browser_source_maps,
1833-
})))
1830+
pub async fn client_source_maps(&self, mode: Vc<NextMode>) -> Result<Vc<SourceMapsType>> {
1831+
let input_source_maps = self
1832+
.experimental
1833+
.turbopack_input_source_maps
1834+
.unwrap_or(true);
1835+
let source_maps = self
1836+
.experimental
1837+
.turbopack_source_maps
1838+
.unwrap_or(match &*mode.await? {
1839+
NextMode::Development => true,
1840+
NextMode::Build => self.production_browser_source_maps,
1841+
});
1842+
Ok(match (source_maps, input_source_maps) {
1843+
(true, true) => SourceMapsType::Full,
1844+
(true, false) => SourceMapsType::Partial,
1845+
(false, _) => SourceMapsType::None,
1846+
}
1847+
.cell())
18341848
}
18351849

18361850
#[turbo_tasks::function]
1837-
pub fn server_source_maps(&self) -> Result<Vc<bool>> {
1838-
let source_maps = self.experimental.turbopack_source_maps;
1839-
Ok(Vc::cell(source_maps.unwrap_or(true)))
1851+
pub fn server_source_maps(&self) -> Result<Vc<SourceMapsType>> {
1852+
let input_source_maps = self
1853+
.experimental
1854+
.turbopack_input_source_maps
1855+
.unwrap_or(true);
1856+
let source_maps = self
1857+
.experimental
1858+
.turbopack_source_maps
1859+
.or(self.experimental.server_source_maps)
1860+
.unwrap_or(true);
1861+
Ok(match (source_maps, input_source_maps) {
1862+
(true, true) => SourceMapsType::Full,
1863+
(true, false) => SourceMapsType::Partial,
1864+
(false, _) => SourceMapsType::None,
1865+
}
1866+
.cell())
18401867
}
18411868

18421869
#[turbo_tasks::function]

crates/next-core/src/next_edge/context.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub struct EdgeChunkingContextOptions {
205205
pub module_id_strategy: Vc<Box<dyn ModuleIdStrategy>>,
206206
pub export_usage: Vc<OptionExportUsageInfo>,
207207
pub turbo_minify: Vc<bool>,
208-
pub turbo_source_maps: Vc<bool>,
208+
pub turbo_source_maps: Vc<SourceMapsType>,
209209
pub no_mangling: Vc<bool>,
210210
pub scope_hoisting: Vc<bool>,
211211
pub nested_async_chunking: Vc<bool>,
@@ -255,11 +255,7 @@ pub async fn get_edge_chunking_context_with_client_assets(
255255
} else {
256256
MinifyType::NoMinify
257257
})
258-
.source_maps(if *turbo_source_maps.await? {
259-
SourceMapsType::Full
260-
} else {
261-
SourceMapsType::None
262-
})
258+
.source_maps(*turbo_source_maps.await?)
263259
.module_id_strategy(module_id_strategy.to_resolved().await?)
264260
.export_usage(*export_usage.await?)
265261
.nested_async_availability(*nested_async_chunking.await?);
@@ -334,11 +330,7 @@ pub async fn get_edge_chunking_context(
334330
} else {
335331
MinifyType::NoMinify
336332
})
337-
.source_maps(if *turbo_source_maps.await? {
338-
SourceMapsType::Full
339-
} else {
340-
SourceMapsType::None
341-
})
333+
.source_maps(*turbo_source_maps.await?)
342334
.module_id_strategy(module_id_strategy.to_resolved().await?)
343335
.export_usage(*export_usage.await?)
344336
.nested_async_availability(*nested_async_chunking.await?);

crates/next-core/src/next_server/context.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,7 @@ pub async fn get_server_module_options_context(
577577
.flatten()
578578
.collect();
579579

580-
let source_maps = if *next_config.server_source_maps().await? {
581-
SourceMapsType::Full
582-
} else {
583-
SourceMapsType::None
584-
};
580+
let source_maps = *next_config.server_source_maps().await?;
585581
let module_options_context = ModuleOptionsContext {
586582
ecmascript: EcmascriptOptionsContext {
587583
enable_typeof_window_inlining: Some(TypeofWindow::Undefined),
@@ -996,8 +992,8 @@ pub struct ServerChunkingContextOptions {
996992
pub environment: Vc<Environment>,
997993
pub module_id_strategy: Vc<Box<dyn ModuleIdStrategy>>,
998994
pub export_usage: Vc<OptionExportUsageInfo>,
999-
pub turbo_minify: Vc<bool>,
1000-
pub turbo_source_maps: Vc<bool>,
995+
pub minify: Vc<bool>,
996+
pub source_maps: Vc<SourceMapsType>,
1001997
pub no_mangling: Vc<bool>,
1002998
pub scope_hoisting: Vc<bool>,
1003999
pub nested_async_chunking: Vc<bool>,
@@ -1019,8 +1015,8 @@ pub async fn get_server_chunking_context_with_client_assets(
10191015
environment,
10201016
module_id_strategy,
10211017
export_usage,
1022-
turbo_minify,
1023-
turbo_source_maps,
1018+
minify,
1019+
source_maps,
10241020
no_mangling,
10251021
scope_hoisting,
10261022
nested_async_chunking,
@@ -1044,19 +1040,15 @@ pub async fn get_server_chunking_context_with_client_assets(
10441040
next_mode.runtime_type(),
10451041
)
10461042
.asset_prefix(Some(asset_prefix))
1047-
.minify_type(if *turbo_minify.await? {
1043+
.minify_type(if *minify.await? {
10481044
MinifyType::Minify {
10491045
// React needs deterministic function names to work correctly.
10501046
mangle: (!*no_mangling.await?).then_some(MangleType::Deterministic),
10511047
}
10521048
} else {
10531049
MinifyType::NoMinify
10541050
})
1055-
.source_maps(if *turbo_source_maps.await? {
1056-
SourceMapsType::Full
1057-
} else {
1058-
SourceMapsType::None
1059-
})
1051+
.source_maps(*source_maps.await?)
10601052
.module_id_strategy(module_id_strategy.to_resolved().await?)
10611053
.export_usage(*export_usage.await?)
10621054
.file_tracing(next_mode.is_production())
@@ -1105,8 +1097,8 @@ pub async fn get_server_chunking_context(
11051097
environment,
11061098
module_id_strategy,
11071099
export_usage,
1108-
turbo_minify,
1109-
turbo_source_maps,
1100+
minify,
1101+
source_maps,
11101102
no_mangling,
11111103
scope_hoisting,
11121104
nested_async_chunking,
@@ -1131,18 +1123,14 @@ pub async fn get_server_chunking_context(
11311123
.client_roots_override(rcstr!("client"), client_root.clone())
11321124
.asset_root_path_override(rcstr!("client"), client_root.join("static/media")?)
11331125
.asset_prefix_override(rcstr!("client"), asset_prefix)
1134-
.minify_type(if *turbo_minify.await? {
1126+
.minify_type(if *minify.await? {
11351127
MinifyType::Minify {
11361128
mangle: (!*no_mangling.await?).then_some(MangleType::OptimalSize),
11371129
}
11381130
} else {
11391131
MinifyType::NoMinify
11401132
})
1141-
.source_maps(if *turbo_source_maps.await? {
1142-
SourceMapsType::Full
1143-
} else {
1144-
SourceMapsType::None
1145-
})
1133+
.source_maps(*source_maps.await?)
11461134
.module_id_strategy(module_id_strategy.to_resolved().await?)
11471135
.export_usage(*export_usage.await?)
11481136
.file_tracing(next_mode.is_production())

packages/next/src/server/config-schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export const experimentalSchema = {
298298
turbopackFileSystemCacheForDev: z.boolean().optional(),
299299
turbopackFileSystemCacheForBuild: z.boolean().optional(),
300300
turbopackSourceMaps: z.boolean().optional(),
301+
turbopackInputSourceMaps: z.boolean().optional(),
301302
turbopackTreeShaking: z.boolean().optional(),
302303
turbopackRemoveUnusedExports: z.boolean().optional(),
303304
turbopackScopeHoisting: z.boolean().optional(),

packages/next/src/server/config-shared.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,11 @@ export interface ExperimentalConfig {
440440
*/
441441
turbopackSourceMaps?: boolean
442442

443+
/**
444+
* Enable extraction of source maps from input files. Defaults to true.
445+
*/
446+
turbopackInputSourceMaps?: boolean
447+
443448
/**
444449
* Enable tree shaking for the turbopack dev server and build.
445450
*/
@@ -1468,7 +1473,6 @@ export const defaultConfig = Object.freeze({
14681473
appNavFailHandling: false,
14691474
prerenderEarlyExit: true,
14701475
serverMinification: true,
1471-
serverSourceMaps: false,
14721476
linkNoTouchStart: false,
14731477
caseSensitiveRoutes: false,
14741478
clientParamParsingOrigins: undefined,

turbopack/crates/turbopack-browser/src/chunking_context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ impl ChunkingContext for BrowserChunkingContext {
573573
fn reference_chunk_source_maps(&self, _chunk: Vc<Box<dyn OutputAsset>>) -> Vc<bool> {
574574
Vc::cell(match self.source_maps_type {
575575
SourceMapsType::Full => true,
576+
SourceMapsType::Partial => true,
576577
SourceMapsType::None => false,
577578
})
578579
}
@@ -581,6 +582,7 @@ impl ChunkingContext for BrowserChunkingContext {
581582
fn reference_module_source_maps(&self, _module: Vc<Box<dyn Module>>) -> Vc<bool> {
582583
Vc::cell(match self.source_maps_type {
583584
SourceMapsType::Full => true,
585+
SourceMapsType::Partial => true,
584586
SourceMapsType::None => false,
585587
})
586588
}

turbopack/crates/turbopack-core/src/chunk/chunking_context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ pub enum SourceMapsType {
6666
/// Extracts source maps from input files and writes source maps for output files.
6767
#[default]
6868
Full,
69+
/// Ignores existing input source maps, but writes source maps for output files.
70+
Partial,
6971
/// Ignores the existence of source maps and does not write source maps for output files.
7072
None,
7173
}

turbopack/crates/turbopack-nodejs/src/chunking_context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ impl ChunkingContext for NodeJsChunkingContext {
387387
fn reference_chunk_source_maps(&self, _chunk: Vc<Box<dyn OutputAsset>>) -> Vc<bool> {
388388
Vc::cell(match self.source_maps_type {
389389
SourceMapsType::Full => true,
390+
SourceMapsType::Partial => true,
390391
SourceMapsType::None => false,
391392
})
392393
}
@@ -395,6 +396,7 @@ impl ChunkingContext for NodeJsChunkingContext {
395396
fn reference_module_source_maps(&self, _module: Vc<Box<dyn Module>>) -> Vc<bool> {
396397
Vc::cell(match self.source_maps_type {
397398
SourceMapsType::Full => true,
399+
SourceMapsType::Partial => true,
398400
SourceMapsType::None => false,
399401
})
400402
}

0 commit comments

Comments
 (0)