Skip to content

Commit 707756f

Browse files
committed
add ./ to relative paths to make it easier to understand
1 parent bb85aa2 commit 707756f

File tree

3 files changed

+49
-50
lines changed

3 files changed

+49
-50
lines changed

crates/napi/src/next_api/project.rs

+30-37
Original file line numberDiff line numberDiff line change
@@ -1124,44 +1124,37 @@ pub async fn project_trace_source(
11241124

11251125
let project_root_uri =
11261126
uri_from_file(project.container.project().project_root_path(), None).await? + "/";
1127-
let (file, original_file, is_internal) = if let Some(source_file) =
1128-
original_file.strip_prefix(&project_root_uri)
1129-
{
1130-
// Client code uses file://
1131-
(
1132-
get_relative_path_to(&current_directory_file_url, &original_file)
1133-
// TODO(sokra) remove this to include a ./ here to make it a relative path
1134-
.trim_start_matches("./")
1135-
.to_string(),
1136-
Some(source_file.to_string()),
1137-
false,
1138-
)
1139-
} else if let Some(source_file) =
1140-
original_file.strip_prefix(&*SOURCE_MAP_PREFIX_PROJECT)
1141-
{
1142-
// Server code uses turbopack://[project]
1143-
// TODO should this also be file://?
1144-
(
1145-
get_relative_path_to(
1146-
&current_directory_file_url,
1147-
&format!("{}{}", project_root_uri, source_file),
1127+
let (file, original_file, is_internal) =
1128+
if let Some(source_file) = original_file.strip_prefix(&project_root_uri) {
1129+
// Client code uses file://
1130+
(
1131+
get_relative_path_to(&current_directory_file_url, &original_file),
1132+
Some(source_file.to_string()),
1133+
false,
11481134
)
1149-
// TODO(sokra) remove this to include a ./ here to make it a relative path
1150-
.trim_start_matches("./")
1151-
.to_string(),
1152-
Some(source_file.to_string()),
1153-
false,
1154-
)
1155-
} else if let Some(source_file) = original_file.strip_prefix(SOURCE_MAP_PREFIX) {
1156-
// All other code like turbopack://[turbopack] is internal code
1157-
(source_file.to_string(), None, true)
1158-
} else {
1159-
bail!(
1160-
"Original file ({}) outside project ({})",
1161-
original_file,
1162-
project_root_uri
1163-
)
1164-
};
1135+
} else if let Some(source_file) =
1136+
original_file.strip_prefix(&*SOURCE_MAP_PREFIX_PROJECT)
1137+
{
1138+
// Server code uses turbopack://[project]
1139+
// TODO should this also be file://?
1140+
(
1141+
get_relative_path_to(
1142+
&current_directory_file_url,
1143+
&format!("{}{}", project_root_uri, source_file),
1144+
),
1145+
Some(source_file.to_string()),
1146+
false,
1147+
)
1148+
} else if let Some(source_file) = original_file.strip_prefix(SOURCE_MAP_PREFIX) {
1149+
// All other code like turbopack://[turbopack] is internal code
1150+
(source_file.to_string(), None, true)
1151+
} else {
1152+
bail!(
1153+
"Original file ({}) outside project ({})",
1154+
original_file,
1155+
project_root_uri
1156+
)
1157+
};
11651158

11661159
Ok(Some(StackFrame {
11671160
file,

packages/next/src/client/components/react-dev-overlay/server/middleware-turbopack.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type { Project, TurbopackStackFrame } from '../../../../build/swc/types'
1919
import { getSourceMapFromFile } from '../internal/helpers/get-source-map-from-file'
2020
import { findSourceMap, type SourceMapPayload } from 'node:module'
2121
import { pathToFileURL } from 'node:url'
22+
import { isAbsolute } from 'node:path'
2223

2324
function shouldIgnorePath(modulePath: string): boolean {
2425
return (
@@ -255,8 +256,13 @@ async function nativeTraceSource(
255256

256257
function relativeToCwd(file: string): string {
257258
const relPath = path.relative(process.cwd(), url.fileURLToPath(file))
258-
// TODO(sokra) include a ./ here to make it a relative path
259-
return relPath
259+
if (isAbsolute(relPath)) {
260+
return relPath
261+
}
262+
if (relPath.startsWith('../')) {
263+
return relPath
264+
}
265+
return './' + relPath
260266
}
261267

262268
export async function createOriginalStackFrame(

test/e2e/app-dir/non-root-project-monorepo/non-root-project-monorepo.test.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('non-root-project-monorepo', () => {
6666
if (isTurbopack) {
6767
// TODO the function name should be hidden
6868
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
69-
"app/source-maps-rsc/page.tsx (9:28) @ innerArrowFunction
69+
"./app/source-maps-rsc/page.tsx (9:28) @ innerArrowFunction
7070
7171
7 | }
7272
8 |
@@ -82,9 +82,9 @@ describe('non-root-project-monorepo', () => {
8282
"<unknown>
8383
[project]/apps/web/app/separate-file.ts [app-rsc] (ecmascript) (rsc://React/Server/file://<full-path>/apps/web/.next/server/chunks/ssr/apps_web_8d1c0a._.js (7:7)
8484
innerFunction
85-
app/source-maps-rsc/page.tsx (6:3)
85+
./app/source-maps-rsc/page.tsx (6:3)
8686
Page
87-
app/source-maps-rsc/page.tsx (2:3)"
87+
./app/source-maps-rsc/page.tsx (2:3)"
8888
`)
8989
} else {
9090
// TODO the function name is incorrect
@@ -120,7 +120,7 @@ describe('non-root-project-monorepo', () => {
120120
if (isTurbopack) {
121121
// TODO the function name should be hidden
122122
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
123-
"app/separate-file.ts (1:7) @ [project]/apps/web/app/separate-file.ts [app-client] (ecmascript)
123+
"./app/separate-file.ts (1:7) @ [project]/apps/web/app/separate-file.ts [app-client] (ecmascript)
124124
125125
> 1 | throw new Error('Expected error')
126126
| ^
@@ -129,11 +129,11 @@ describe('non-root-project-monorepo', () => {
129129
expect(normalizeStackTrace(await getRedboxCallStack(browser)))
130130
.toMatchInlineSnapshot(`
131131
"innerArrowFunction
132-
app/source-maps-ssr/page.tsx (11:28)
132+
./app/source-maps-ssr/page.tsx (11:28)
133133
innerFunction
134-
app/source-maps-ssr/page.tsx (8:3)
134+
./app/source-maps-ssr/page.tsx (8:3)
135135
Page
136-
app/source-maps-ssr/page.tsx (4:3)"
136+
./app/source-maps-ssr/page.tsx (4:3)"
137137
`)
138138
} else {
139139
// TODO the function name should be hidden
@@ -173,7 +173,7 @@ describe('non-root-project-monorepo', () => {
173173
if (isTurbopack) {
174174
// TODO the function name should be hidden
175175
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
176-
"app/separate-file.ts (1:7) @ [project]/apps/web/app/separate-file.ts [app-client] (ecmascript)
176+
"./app/separate-file.ts (1:7) @ [project]/apps/web/app/separate-file.ts [app-client] (ecmascript)
177177
178178
> 1 | throw new Error('Expected error')
179179
| ^
@@ -182,11 +182,11 @@ describe('non-root-project-monorepo', () => {
182182
expect(normalizeStackTrace(await getRedboxCallStack(browser)))
183183
.toMatchInlineSnapshot(`
184184
"innerArrowFunction
185-
app/source-maps-client/page.tsx (16:28)
185+
./app/source-maps-client/page.tsx (16:28)
186186
innerFunction
187-
app/source-maps-client/page.tsx (13:3)
187+
./app/source-maps-client/page.tsx (13:3)
188188
effectCallback
189-
app/source-maps-client/page.tsx (7:5)"
189+
./app/source-maps-client/page.tsx (7:5)"
190190
`)
191191
} else {
192192
// TODO the function name should be hidden

0 commit comments

Comments
 (0)