mirror of
https://github.com/vitejs/vite.git
synced 2024-11-21 22:59:10 +00:00
Co-authored-by: Ari Perkkiö <ari.perkkio@gmail.com>
This commit is contained in:
parent
0474550c9f
commit
262a8796d4
@ -0,0 +1,11 @@
|
||||
// nested-directory/nested-file.js
|
||||
var nested_file_default =
|
||||
'Nested file will trigger edge case that used to break sourcemaps'
|
||||
|
||||
// entrypoint.js
|
||||
function entrypoint() {
|
||||
console.log(nested_file_default)
|
||||
throw new Error('Hello world')
|
||||
}
|
||||
export { entrypoint }
|
||||
//# sourceMappingURL=dist.js.map
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"version": 3,
|
||||
"sources": ["nested-directory/nested-file.js", "entrypoint.js"],
|
||||
"sourcesContent": ["export default 'Nested file will trigger edge case that used to break sourcemaps'\n", "/*\n * You can rebuild this with:\n * - rm -f ./dist.js ./dist.js.map\n * - npx esbuild --bundle entrypoint.js --outfile=dist.js --sourcemap --format=esm\n */\n\nimport nested from './nested-directory/nested-file'\n\nexport function entrypoint() {\n console.log(nested)\n throw new Error('Hello world')\n}\n"],
|
||||
"mappings": ";AAAA,IAAO,sBAAQ;;;ACQR,SAAS,aAAa;AAC3B,UAAQ,IAAI,mBAAM;AAClB,QAAM,IAAI,MAAM,aAAa;AAC/B;",
|
||||
"names": []
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* You can rebuild this with:
|
||||
* - rm -f ./dist.js ./dist.js.map
|
||||
* - npx esbuild --bundle entrypoint.js --outfile=dist.js --sourcemap --format=esm
|
||||
*/
|
||||
|
||||
import nested from './nested-directory/nested-file'
|
||||
|
||||
export function entrypoint() {
|
||||
console.log(nested)
|
||||
throw new Error('Hello world')
|
||||
}
|
@ -0,0 +1 @@
|
||||
export default 'Nested file will trigger edge case that used to break sourcemaps'
|
@ -441,6 +441,31 @@ test('sourcemap with multiple sources', async () => {
|
||||
}
|
||||
})
|
||||
|
||||
test('sourcemap with multiple sources and nested paths', async () => {
|
||||
const code = readFixture('dist.js')
|
||||
const map = readFixture('dist.js.map')
|
||||
|
||||
const result = await ssrTransform(code, JSON.parse(map), '', code)
|
||||
assert(result?.map)
|
||||
|
||||
const { sources } = result.map as SourceMap
|
||||
expect(sources).toMatchInlineSnapshot(`
|
||||
[
|
||||
"nested-directory/nested-file.js",
|
||||
"entrypoint.js",
|
||||
]
|
||||
`)
|
||||
|
||||
function readFixture(filename: string) {
|
||||
const url = new URL(
|
||||
`./fixtures/multi-source-sourcemaps/${filename}`,
|
||||
import.meta.url,
|
||||
)
|
||||
|
||||
return readFileSync(fileURLToPath(url), 'utf8')
|
||||
}
|
||||
})
|
||||
|
||||
test('overwrite bindings', async () => {
|
||||
expect(
|
||||
await ssrTransformSimpleCode(
|
||||
|
@ -346,6 +346,10 @@ async function ssrTransformScript(
|
||||
})
|
||||
|
||||
let map = s.generateMap({ hires: 'boundary' })
|
||||
map.sources = [path.basename(url)]
|
||||
// needs to use originalCode instead of code
|
||||
// because code might be already transformed even if map is null
|
||||
map.sourcesContent = [originalCode]
|
||||
if (
|
||||
inMap &&
|
||||
inMap.mappings &&
|
||||
@ -353,18 +357,9 @@ async function ssrTransformScript(
|
||||
inMap.sources.length > 0
|
||||
) {
|
||||
map = combineSourcemaps(url, [
|
||||
{
|
||||
...map,
|
||||
sources: inMap.sources,
|
||||
sourcesContent: inMap.sourcesContent,
|
||||
} as RawSourceMap,
|
||||
map as RawSourceMap,
|
||||
inMap as RawSourceMap,
|
||||
]) as SourceMap
|
||||
} else {
|
||||
map.sources = [path.basename(url)]
|
||||
// needs to use originalCode instead of code
|
||||
// because code might be already transformed even if map is null
|
||||
map.sourcesContent = [originalCode]
|
||||
}
|
||||
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user