Files
renovate[bot]GitHubrenovate[bot] <29139614+renovate[bot]@users.noreply.github.com>Hanashulaodaandrew翠
db373bb871 feat: update rolldown-related dependencies and use client-side HMR in bundled-dev (#22961)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Hana <[email protected]>
Co-authored-by: shulaoda <[email protected]>
Co-authored-by: andrew <[email protected]>
Co-authored-by: 翠 <[email protected]>
2026-07-22 13:29:03 +09:00

407 lines
18 KiB
TypeScript

import { URL, fileURLToPath } from 'node:url'
import { promisify } from 'node:util'
import { execFile } from 'node:child_process'
import { existsSync } from 'node:fs'
import { TraceMap, originalPositionFor } from '@jridgewell/trace-mapping'
import { describe, expect, test } from 'vitest'
import { mapFileCommentRegex } from 'convert-source-map'
import { commentSourceMap } from '../foo-with-sourcemap-plugin'
import {
extractSourcemap,
findAssetFile,
formatSourcemapForSnapshot,
isBuild,
listAssets,
page,
readFile,
serverLogs,
} from '~utils'
const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g
function escapeRegex(str: string): string {
return str.replace(escapeRegexRE, '\\$&')
}
async function getDepJs(entry: string, depIdFragment: string) {
const res = await page.request.get(new URL(entry, page.url()).href)
const js = await res.text()
const depUrlMatch = js.match(
new RegExp(`from\\s+"([^"]*${depIdFragment}[^"]*)"`),
)
expect(depUrlMatch).toBeTruthy()
const depUrl = depUrlMatch![1]
expect(depUrl).toContain('/deps/')
const depRes = await page.request.get(new URL(depUrl, page.url()).href)
return depRes.text()
}
function expectConsoleLogArgumentMapsToOriginalX(
depJs: string,
generatedName: string,
) {
const map = extractSourcemap(depJs)
const depLines = depJs.split('\n')
const consoleLogCallRE = new RegExp(
`console[\\w$]*\\.\\s*log[\\w$]*\\(${escapeRegex(generatedName)}\\)`,
)
const generatedLine =
depLines.findIndex((line) => consoleLogCallRE.test(line)) + 1
expect(generatedLine).toBeGreaterThan(0)
const generatedColumn = depLines[generatedLine - 1].indexOf(generatedName)
expect(generatedColumn).toBeGreaterThanOrEqual(0)
const position = originalPositionFor(new TraceMap(map), {
line: generatedLine,
column: generatedColumn,
})
expect(depJs).toMatch(
/^\/\/# sourceMappingURL=data:application\/json;base64,/m,
)
expect(position).toMatchObject({
line: 6,
column: 16,
name: 'x',
})
}
if (!isBuild) {
test('js', async () => {
const res = await page.request.get(new URL('./foo.js', page.url()).href)
const js = await res.text()
const map = extractSourcemap(js)
expect(formatSourcemapForSnapshot(map, js)).toMatchInlineSnapshot(`
SourceMap {
content: {
"mappings": "AAAA,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG;",
"sources": [
"foo.js",
],
"sourcesContent": [
"export const foo = 'foo'
",
],
"version": 3,
},
visualization: "https://evanw.github.io/source-map-visualization/#MjUAZXhwb3J0IGNvbnN0IGZvbyA9ICdmb28nCjE1MQB7InZlcnNpb24iOjMsInNvdXJjZXMiOlsiZm9vLmpzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBjb25zdCBmb28gPSAnZm9vJ1xuIl0sIm1hcHBpbmdzIjoiQUFBQSxNQUFNLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQyxHQUFHOyJ9"
}
`)
})
test('plugin return sourcemap with `sources: [""]`', async () => {
const res = await page.request.get(new URL('./zoo.js', page.url()).href)
const js = await res.text()
expect(js).toContain('// add comment')
const map = extractSourcemap(js)
expect(formatSourcemapForSnapshot(map, js)).toMatchInlineSnapshot(`
SourceMap {
content: {
"mappings": "AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;",
"sources": [
"zoo.js",
],
"sourcesContent": [
"export const zoo = 'zoo'
",
],
"version": 3,
},
visualization: "https://evanw.github.io/source-map-visualization/#NDAAZXhwb3J0IGNvbnN0IHpvbyA9ICd6b28nCi8vIGFkZCBjb21tZW50CjIxNgB7InZlcnNpb24iOjMsInNvdXJjZXMiOlsiem9vLmpzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBjb25zdCB6b28gPSAnem9vJ1xuIl0sIm1hcHBpbmdzIjoiQUFBQSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7In0="
}
`)
})
test('js with inline sourcemap injected by a plugin', async () => {
const res = await page.request.get(
new URL('./foo-with-sourcemap.js', page.url()).href,
)
const js = await res.text()
expect(js).toContain(commentSourceMap)
const sourcemapComments = js.match(mapFileCommentRegex).length
expect(sourcemapComments).toBe(1)
const map = extractSourcemap(js)
expect(formatSourcemapForSnapshot(map, js)).toMatchInlineSnapshot(`
SourceMap {
content: {
"mappings": "AAAA,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG",
"sources": [
"",
],
"version": 3,
},
visualization: "https://evanw.github.io/source-map-visualization/#NzMAZXhwb3J0IGNvbnN0IGZvbyA9ICdmb28nCi8vIGRlZmF1bHQgYm91bmRhcnkgc291cmNlbWFwIHdpdGggbWFnaWMtc3RyaW5nCjk2AHsidmVyc2lvbiI6Mywic291cmNlcyI6WyIiXSwibWFwcGluZ3MiOiJBQUFBLE1BQU0sQ0FBQyxLQUFLLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDLEdBQUcifQ=="
}
`)
})
test('ts', async () => {
const res = await page.request.get(new URL('./bar.ts', page.url()).href)
const js = await res.text()
const map = extractSourcemap(js)
expect(formatSourcemapForSnapshot(map, js)).toMatchInlineSnapshot(`
SourceMap {
content: {
"mappings": "AAAA,OAAO,MAAM,MAAM",
"sources": [
"bar.ts",
],
"sourcesContent": [
"export const bar = 'bar'
",
],
"version": 3,
},
visualization: "https://evanw.github.io/source-map-visualization/#MjYAZXhwb3J0IGNvbnN0IGJhciA9ICJiYXIiOwoxMTUAeyJtYXBwaW5ncyI6IkFBQUEsT0FBTyxNQUFNLE1BQU0iLCJzb3VyY2VzIjpbImJhci50cyJdLCJ2ZXJzaW9uIjozLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgY29uc3QgYmFyID0gJ2JhcidcbiJdfQ=="
}
`)
})
test('multiline import', async () => {
const res = await page.request.get(
new URL('./with-multiline-import.ts', page.url()).href,
)
const js = await res.text()
const map = extractSourcemap(js)
expect(formatSourcemapForSnapshot(map, js)).toMatchInlineSnapshot(`
SourceMap {
content: {
"mappings": ";AACA,SACE,WACK;AAEP,QAAQ,IAAI,yBAAyB,GAAG",
"sources": [
"with-multiline-import.ts",
],
"sourcesContent": [
"// prettier-ignore
import {
foo
} from '@vitejs/test-importee-pkg'
console.log('with-multiline-import', foo)
",
],
"version": 3,
},
visualization: "https://evanw.github.io/source-map-visualization/#MjQ3AGNvbnN0IGZvbyA9IF9fdml0ZV9fY2pzSW1wb3J0MF9fdml0ZWpzX3Rlc3RJbXBvcnRlZVBrZ1siZm9vIl07Ly8gcHJldHRpZXItaWdub3JlCmltcG9ydCBfX3ZpdGVfX2Nqc0ltcG9ydDBfX3ZpdGVqc190ZXN0SW1wb3J0ZWVQa2cgZnJvbSAiL25vZGVfbW9kdWxlcy8udml0ZS9kZXBzL0B2aXRlanNfdGVzdC1pbXBvcnRlZS1wa2cuanM/dj0wMDAwMDAwMCI7CmNvbnNvbGUubG9nKCJ3aXRoLW11bHRpbGluZS1pbXBvcnQiLCBmb28pOwoyNDgAeyJtYXBwaW5ncyI6IjtBQUNBLFNBQ0UsV0FDSztBQUVQLFFBQVEsSUFBSSx5QkFBeUIsR0FBRyIsInNvdXJjZXMiOlsid2l0aC1tdWx0aWxpbmUtaW1wb3J0LnRzIl0sInZlcnNpb24iOjMsInNvdXJjZXNDb250ZW50IjpbIi8vIHByZXR0aWVyLWlnbm9yZVxuaW1wb3J0IHtcbiAgZm9vXG59IGZyb20gJ0B2aXRlanMvdGVzdC1pbXBvcnRlZS1wa2cnXG5cbmNvbnNvbGUubG9nKCd3aXRoLW11bHRpbGluZS1pbXBvcnQnLCBmb28pXG4iXX0="
}
`)
})
test('should not output missing source file warning', () => {
serverLogs.forEach((log) => {
expect(log).not.toMatch(/Sourcemap for .+ points to missing source files/)
})
})
test('should not leak file contents via sourcemap path traversal in node_modules', async () => {
const res = await page.request.get(
new URL('./malicious-import.js', page.url()).href,
)
const js = await res.text()
// Find the rewritten import URL for the malicious dep
const depUrlMatch = js.match(/from\s+"([^"]*malicious-sourcemap[^"]*)"/)
expect(depUrlMatch).toBeTruthy()
const depUrl = depUrlMatch![1]
const depRes = await page.request.get(new URL(depUrl, page.url()).href)
const depJs = await depRes.text()
const map = extractSourcemap(depJs)
expect(map.sourcesContent).toBeDefined()
expect(map.sourcesContent).not.toContainEqual(
expect.stringContaining('defineConfig'),
)
})
test('should not leak file contents via sourcemap path traversal in optimized deps', async () => {
const res = await page.request.get(
new URL('./optimized-malicious-import.js', page.url()).href,
)
const js = await res.text()
// Find the rewritten import URL for the optimized malicious dep
const depUrlMatch = js.match(/from\s+"([^"]*optimized-malicious[^"]*)"/)
expect(depUrlMatch).toBeTruthy()
const depUrl = depUrlMatch![1]
// Ensure the dep was actually optimized (served from .vite/deps)
expect(depUrl).toContain('.vite/deps')
const depRes = await page.request.get(new URL(depUrl, page.url()).href)
const depJs = await depRes.text()
expect(depJs).toMatch(
/^\/\/# sourceMappingURL=data:application\/json;base64,/m,
)
const map = extractSourcemap(depJs)
expect(map.sourcesContent).toBeDefined()
expect(map.sourcesContent).not.toContainEqual(
expect.stringContaining('defineConfig'),
)
})
test('babel-transformed downleveled optimized dep maps to the correct original name', async () => {
const depJs = await getDepJs(
'./optimized-class-field-import-babel.js',
'test-dep-class-field-sourcemap-babel',
)
expect(depJs).toContain('x = () => 1')
expect(depJs).toContain('constructor(_x)')
expect(depJs).toContain('console.log(_x)')
expectConsoleLogArgumentMapsToOriginalX(depJs, '_x')
})
test('oxc-transformed downleveled optimized dep maps to the correct original name', async () => {
const depJs = await getDepJs(
'./optimized-class-field-import-oxc.js',
'test-dep-class-field-sourcemap-oxc',
)
expect(depJs).toContain('x$$$ = () => 1')
expect(depJs).toContain('constructor$$$(_x$$$)')
expect(depJs).toContain('console$$$.log$$$(_x$$$)')
expectConsoleLogArgumentMapsToOriginalX(depJs, '_x$$$')
})
}
describe.runIf(isBuild)('build tests', () => {
test('should not output sourcemap warning (#4939)', () => {
serverLogs.forEach((log) => {
expect(log).not.toMatch('Sourcemap is likely to be incorrect')
})
})
test('sourcemap is correct when preload information is injected', async () => {
const js = findAssetFile(/after-preload-dynamic-[-\w]{8}\.js$/)
const map = findAssetFile(/after-preload-dynamic-[-\w]{8}\.js\.map/)
expect(formatSourcemapForSnapshot(JSON.parse(map), js))
.toMatchInlineSnapshot(`
SourceMap {
content: {
"debugId": "00000000-0000-0000-0000-000000000000",
"ignoreList": [],
"mappings": ";6pCAAA,aAAO,qDAEP,QAAQ,IAAI,uBAAuB",
"sources": [
"../../after-preload-dynamic.js",
],
"sourcesContent": [
"import('./dynamic/dynamic-foo')
console.log('after preload dynamic')
",
],
"version": 3,
},
visualization: "https://evanw.github.io/source-map-visualization/#MTU1MgBjb25zdCBfX3ZpdGVfX21hcERlcHM9KGksbT1fX3ZpdGVfX21hcERlcHMsZD0obS5mfHwobS5mPVsiYXNzZXRzL2R5bmFtaWMtZm9vLUJ3aFpUa3RCLmpzIiwiYXNzZXRzL2R5bmFtaWMtZm9vLURzcUtSckV5LmNzcyJdKSkpPT5pLm1hcChpPT5kW2ldKTsKdmFyIGU9ZnVuY3Rpb24oZSl7cmV0dXJuYC9gK2V9LHQ9e30sbj1mdW5jdGlvbihuLHIsaSl7bGV0IGE9UHJvbWlzZS5yZXNvbHZlKCk7aWYociYmci5sZW5ndGg+MCl7bGV0IG49ZG9jdW1lbnQuZ2V0RWxlbWV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L=after-preload-dynamic-[-\w]{8}\.js\.map\n?$/,
)
})
test('sourcemap file field is consistent (#20853)', async () => {
const assets = listAssets()
const mapAssets = assets.filter((asset) => asset.endsWith('.js.map'))
for (const mapAsset of mapAssets) {
const mapContent = readFile(`dist/assets/${mapAsset}`)
const mapObj = JSON.parse(mapContent)
if (mapObj.file) {
expect(
mapObj.file,
`Sourcemap file field for ${mapAsset} should be just the filename`,
).toMatch(/^[^/]+\.js$/)
}
}
})
test('__vite__mapDeps injected after banner', async () => {
const js = findAssetFile(/after-preload-dynamic-hashbang-[-\w]{8}\.js$/)
expect(js.split('\n').slice(0, 2)).toEqual([
'#!/usr/bin/env node',
expect.stringContaining('const __vite__mapDeps=(i'),
])
})
test('no unused __vite__mapDeps', async () => {
const js = findAssetFile(/after-preload-dynamic-no-dep-[-\w]{8}\.js$/)
expect(js).not.toMatch(/__vite__mapDeps/)
})
test('sourcemap is correct when using object as "define" value', async () => {
const js = findAssetFile(/with-define-object.*\.js$/)
const map = findAssetFile(/with-define-object.*\.js\.map/)
expect(formatSourcemapForSnapshot(JSON.parse(map), js))
.toMatchInlineSnapshot(`
SourceMap {
content: {
"debugId": "00000000-0000-0000-0000-000000000000",
"mappings": "AAEA,SAAS,GAAO,CACd,EAAU,CACZ,CAEA,SAAS,GAAY,CAEnB,QAAQ,MAAM,qBAAA,CAAA,MAAA,MAAA,CAAwC,CACxD,CAEA,EAAK",
"sources": [
"../../with-define-object.ts",
],
"sourcesContent": [
"// test complicated stack since broken sourcemap
// might still look correct with a simple case
function main() {
mainInner()
}
function mainInner() {
// @ts-expect-error "define"
console.trace('with-define-object', __testDefineObject)
}
main()
",
],
"version": 3,
},
visualization: "https://evanw.github.io/source-map-visualization/#MTkwAGZ1bmN0aW9uIGUoKXt0KCl9ZnVuY3Rpb24gdCgpe2NvbnNvbGUudHJhY2UoYHdpdGgtZGVmaW5lLW9iamVjdGAse2hlbGxvOmB0ZXN0YH0pfWUoKTsKLy8jIGRlYnVnSWQ9NjRlNzI1NTUtMTk0Zi00MTRkLTk1MzUtOWVmYjI1ZTQyZmI2Ci8vIyBzb3VyY2VNYXBwaW5nVVJMPXdpdGgtZGVmaW5lLW9iamVjdC1CazV5VlZHVS5qcy5tYXA1MTAAeyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3dpdGgtZGVmaW5lLW9iamVjdC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyIvLyB0ZXN0IGNvbXBsaWNhdGVkIHN0YWNrIHNpbmNlIGJyb2tlbiBzb3VyY2VtYXBcbi8vIG1pZ2h0IHN0aWxsIGxvb2sgY29ycmVjdCB3aXRoIGEgc2ltcGxlIGNhc2VcbmZ1bmN0aW9uIG1haW4oKSB7XG4gIG1haW5Jbm5lcigpXG59XG5cbmZ1bmN0aW9uIG1haW5Jbm5lcigpIHtcbiAgLy8gQHRzLWV4cGVjdC1lcnJvciBcImRlZmluZVwiXG4gIGNvbnNvbGUudHJhY2UoJ3dpdGgtZGVmaW5lLW9iamVjdCcsIF9fdGVzdERlZmluZU9iamVjdClcbn1cblxubWFpbigpXG4iXSwibWFwcGluZ3MiOiJBQUVBLFNBQVMsR0FBTyxDQUNkLEVBQVUsQ0FDWixDQUVBLFNBQVMsR0FBWSxDQUVuQixRQUFRLE1BQU0scUJBQUEsQ0FBQSxNQUFBLE1BQUEsQ0FBd0MsQ0FDeEQsQ0FFQSxFQUFLIiwiZGVidWdJZCI6IjAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMCJ9"
}
`)
})
test('correct sourcemap during ssr dev when using object as "define" value', async () => {
const execFileAsync = promisify(execFile)
await execFileAsync('node', ['test-ssr-dev.js'], {
cwd: fileURLToPath(new URL('..', import.meta.url)),
})
})
test('source and sourcemap contain matching debug IDs', () => {
function getDebugIdFromString(input: string): string | undefined {
const match = input.match(/\/\/# debugId=([a-fA-F0-9-]+)/)
return match ? match[1] : undefined
}
const assets = listAssets().map((asset) => `dist/assets/${asset}`)
const jsAssets = assets.filter((asset) => asset.endsWith('.js'))
for (const jsAsset of jsAssets) {
const jsContent = readFile(jsAsset)
const hasSourcemap = existsSync(`${jsAsset}.map`)
if (!hasSourcemap) continue
const sourceDebugId = getDebugIdFromString(jsContent)
expect(
sourceDebugId,
`Asset '${jsAsset}' did not contain a debug ID`,
).toBeDefined()
const mapFile = jsAsset + '.map'
const mapContent = readFile(mapFile)
const mapObj = JSON.parse(mapContent)
const mapDebugId = mapObj.debugId
expect(
sourceDebugId,
'Debug ID in source didnt match debug ID in sourcemap',
).toEqual(mapDebugId)
}
})
})