Skip to content

Commit

Permalink
Turbopack: use file:// uris for server resources in development
Browse files Browse the repository at this point in the history
  • Loading branch information
wbinnssmith committed Oct 28, 2024
1 parent 9ccdf4b commit e5da935
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 63 deletions.
2 changes: 2 additions & 0 deletions crates/next-core/src/next_server/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ pub async fn get_server_chunking_context_with_client_assets(
)
.asset_prefix(asset_prefix)
.minify_type(next_mode.minify_type())
.use_file_source_map_uris()
.module_id_strategy(module_id_strategy)
.build())
}
Expand Down Expand Up @@ -956,5 +957,6 @@ pub async fn get_server_chunking_context(
)
.minify_type(next_mode.minify_type())
.module_id_strategy(module_id_strategy)
.use_file_source_map_uris()
.build())
}
97 changes: 35 additions & 62 deletions test/e2e/app-dir/server-source-maps/server-source-maps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,19 @@ describe('app-dir - server source maps', () => {
if (isNextDev) {
await retry(() => {
expect(normalizeCliOutput(next.cliOutput)).toContain(
isTurbopack
? '\nError: Boom' +
'\n at logError (turbopack://[project]/app/rsc-error-log/page.js:2:16)' +
'\n at Page (turbopack://[project]/app/rsc-error-log/page.js:7:2)' +
'\n 1 | function logError() {' +
"\n> 2 | const error = new Error('Boom')" +
'\n | ^' +
'\n 3 | console.error(error)' +
'\n 4 | }' +
'\n 5 |' +
'\n'
: '\nError: Boom' +
'\n at logError (app/rsc-error-log/page.js:2:16)' +
// FIXME: Method name should be "Page"
'\n at logError (app/rsc-error-log/page.js:7:2)' +
'\n 1 | function logError() {' +
"\n> 2 | const error = new Error('Boom')" +
'\n | ^' +
'\n 3 | console.error(error)' +
'\n 4 | }' +
'\n 5 |' +
'\n'
'\nError: Boom' +
'\n at logError (app/rsc-error-log/page.js:2:16)' +
(isTurbopack
? '\n at Page (app/rsc-error-log/page.js:7:2)'
: // FIXME: Method name should be "Page"
'\n at logError (app/rsc-error-log/page.js:7:2)') +
'\n 1 | function logError() {' +
"\n> 2 | const error = new Error('Boom')" +
'\n | ^' +
'\n 3 | console.error(error)' +
'\n 4 | }' +
'\n 5 |' +
'\n'
)
})
} else {
Expand All @@ -66,46 +57,28 @@ describe('app-dir - server source maps', () => {
if (isNextDev) {
await retry(() => {
expect(normalizeCliOutput(next.cliOutput)).toContain(
isTurbopack
? '\nError: Boom' +
'\n at logError (turbopack://[project]/app/rsc-error-log-cause/page.js:2:16)' +
'\n at Page (turbopack://[project]/app/rsc-error-log-cause/page.js:8:2)' +
'\n 1 | function logError(cause) {' +
"\n> 2 | const error = new Error('Boom', { cause })" +
'\n | ^' +
'\n 3 | console.error(error)' +
'\n 4 | }' +
'\n 5 | {' +
'\n [cause]: Error: Boom' +
'\n at Page (turbopack://[project]/app/rsc-error-log-cause/page.js:7:16)' +
'\n 5 |' +
'\n 6 | export default function Page() {' +
"\n > 7 | const error = new Error('Boom')" +
'\n | ^' +
'\n 8 | logError(error)' +
'\n 9 | return null' +
'\n 10 | }' +
'\n'
: '\nError: Boom' +
'\n at logError (app/rsc-error-log-cause/page.js:2:16)' +
// FIXME: Method name should be "Page"
'\n at logError (app/rsc-error-log-cause/page.js:8:2)' +
'\n 1 | function logError(cause) {' +
"\n> 2 | const error = new Error('Boom', { cause })" +
'\n | ^' +
'\n 3 | console.error(error)' +
'\n 4 | }' +
'\n 5 | {' +
'\n [cause]: Error: Boom' +
'\n at Page (app/rsc-error-log-cause/page.js:7:16)' +
'\n 5 |' +
'\n 6 | export default function Page() {' +
"\n > 7 | const error = new Error('Boom')" +
'\n | ^' +
'\n 8 | logError(error)' +
'\n 9 | return null' +
'\n 10 | }' +
'\n'
'\nError: Boom' +
'\n at logError (app/rsc-error-log-cause/page.js:2:16)' +
(isTurbopack
? '\n at Page (app/rsc-error-log-cause/page.js:8:2)'
: // FIXME: Method name should be "Page"
'\n at logError (app/rsc-error-log/page.js:7:2)') +
'\n 1 | function logError(cause) {' +
"\n> 2 | const error = new Error('Boom', { cause })" +
'\n | ^' +
'\n 3 | console.error(error)' +
'\n 4 | }' +
'\n 5 | {' +
'\n [cause]: Error: Boom' +
'\n at Page (app/rsc-error-log-cause/page.js:7:16)' +
'\n 5 |' +
'\n 6 | export default function Page() {' +
"\n > 7 | const error = new Error('Boom')" +
'\n | ^' +
'\n 8 | logError(error)' +
'\n 9 | return null' +
'\n 10 | }' +
'\n'
)
})
} else {
Expand Down
10 changes: 9 additions & 1 deletion turbopack/crates/turbopack-nodejs/src/chunking_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ impl NodeJsChunkingContextBuilder {
self
}

pub fn use_file_source_map_uris(mut self) -> Self {
self.chunking_context.should_use_file_source_map_uris = true;
self
}

pub fn module_id_strategy(mut self, module_id_strategy: Vc<Box<dyn ModuleIdStrategy>>) -> Self {
self.chunking_context.module_id_strategy = module_id_strategy;
self
Expand Down Expand Up @@ -92,6 +97,8 @@ pub struct NodeJsChunkingContext {
manifest_chunks: bool,
/// The strategy to use for generating module ids
module_id_strategy: Vc<Box<dyn ModuleIdStrategy>>,
/// Whether to use file:// uris for source map sources
should_use_file_source_map_uris: bool,
}

impl NodeJsChunkingContext {
Expand All @@ -117,6 +124,7 @@ impl NodeJsChunkingContext {
runtime_type,
minify_type: MinifyType::NoMinify,
manifest_chunks: false,
should_use_file_source_map_uris: false,
module_id_strategy: Vc::upcast(DevModuleIdStrategy::new()),
},
}
Expand Down Expand Up @@ -233,7 +241,7 @@ impl ChunkingContext for NodeJsChunkingContext {

#[turbo_tasks::function]
fn should_use_file_source_map_uris(&self) -> Vc<bool> {
Vc::cell(false)
Vc::cell(self.should_use_file_source_map_uris)
}

#[turbo_tasks::function]
Expand Down

0 comments on commit e5da935

Please sign in to comment.