Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use relative path for sources field #14247

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/vite/src/node/server/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
OutgoingHttpHeaders,
ServerResponse,
} from 'node:http'
import path from 'node:path'
import getEtag from 'etag'
import type { SourceMap } from 'rollup'
import MagicString from 'magic-string'
Expand Down Expand Up @@ -69,7 +70,11 @@ export function send(
content = getCodeWithSourcemap(
type,
content.toString(),
ms.generateMap({ source: urlWithoutTimestamp, hires: 'boundary' }),
ms.generateMap({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but a question: Since #13514, if the JS code has no sourcemap (map is falsy), we're still creating a fallback sourcemap here.

If there's no sourcemap, shouldn't we don't need to do anything?

Copy link
Member Author

@sapphi-red sapphi-red Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, to make dev tools happy, we'll always have to generate a sourcemap (#13514 (comment)).
Just in case, we are skipping sourcemap generation for { "mappings": "" } because it indicates generating a sourcemap is meaningless.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, thats feels like unnecessary overhead if the user never debugs a file, but good to know that it's needed for cases like this.

source: path.basename(urlWithoutTimestamp),
hires: 'boundary',
includeContent: true,
}),
)
}
}
Expand Down
6 changes: 5 additions & 1 deletion playground/js-sourcemap/__tests__/js-sourcemap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ if (!isBuild) {
{
"mappings": "AAAA,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;",
"sources": [
"/foo.js",
"foo.js",
],
"sourcesContent": [
"export const foo = 'foo'
",
],
"version": 3,
}
Expand Down