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

perf: use magic-string hires boundary for sourcemaps #13971

Merged
merged 1 commit into from
Jul 29, 2023
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
2 changes: 1 addition & 1 deletion packages/plugin-legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@babel/preset-env": "^7.22.9",
"browserslist": "^4.21.9",
"core-js": "^3.31.1",
"magic-string": "^0.30.1",
"magic-string": "^0.30.2",
"regenerator-runtime": "^0.13.11",
"systemjs": "^6.14.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
if (config.build.sourcemap) {
return {
code: ms.toString(),
map: ms.generateMap({ hires: true }),
map: ms.generateMap({ hires: 'boundary' }),
}
}
return {
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
"@rollup/plugin-node-resolve": "15.1.0",
"@rollup/plugin-typescript": "^11.1.2",
"@rollup/pluginutils": "^5.0.2",
"@types/pnpapi": "^0.0.2",
"@types/escape-html": "^1.0.2",
"@types/pnpapi": "^0.0.2",
"acorn": "^8.10.0",
"acorn-walk": "^8.2.0",
"cac": "^6.7.14",
Expand All @@ -110,7 +110,7 @@
"json-stable-stringify": "^1.0.2",
"launch-editor-middleware": "^2.6.0",
"lightningcss": "^1.21.5",
"magic-string": "^0.30.1",
"magic-string": "^0.30.2",
"micromatch": "^4.0.5",
"mlly": "^1.4.0",
"mrmime": "^1.0.1",
Expand Down Expand Up @@ -138,10 +138,10 @@
"peerDependencies": {
"@types/node": ">= 14",
"less": "*",
"lightningcss": "^1.21.0",
"sass": "*",
"stylus": "*",
"sugarss": "*",
"lightningcss": "^1.21.0",
"terser": "^5.4.0"
},
"peerDependenciesMeta": {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function shimDepsPlugin(deps: Record<string, ShimOptions>): Plugin {

return {
code: magicString.toString(),
map: magicString.generateMap({ hires: true }),
map: magicString.generateMap({ hires: 'boundary' }),
}
}
}
Expand Down Expand Up @@ -308,7 +308,7 @@ const __require = require;

return {
code: s.toString(),
map: s.generateMap({ hires: true }),
map: s.generateMap({ hires: 'boundary' }),
}
},
}
Expand Down
4 changes: 3 additions & 1 deletion packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
if (s) {
return {
code: s.toString(),
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null,
map: config.build.sourcemap
? s.generateMap({ hires: 'boundary' })
: null,
}
} else {
return null
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
// resolve public URL from CSS paths, we need to use absolute paths
return {
code: s.toString(),
map: s.generateMap({ hires: true }),
map: s.generateMap({ hires: 'boundary' }),
}
} else {
return { code: s.toString() }
Expand Down Expand Up @@ -2130,7 +2130,7 @@ async function getSource(
ms.appendLeft(0, sep)
ms.appendLeft(0, additionalData)

const map = ms.generateMap({ hires: true })
const map = ms.generateMap({ hires: 'boundary' })
map.file = filename
map.sources = [filename]

Expand Down
8 changes: 5 additions & 3 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,9 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
if (s) {
return {
code: s.toString(),
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null,
map: config.build.sourcemap
? s.generateMap({ hires: 'boundary' })
: null,
}
}
},
Expand All @@ -436,7 +438,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
}
return {
code: s.toString(),
map: s.generateMap({ hires: true }),
map: s.generateMap({ hires: 'boundary' }),
}
} else {
return code.replace(re, isModern)
Expand Down Expand Up @@ -651,7 +653,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
if (config.build.sourcemap && chunk.map) {
const nextMap = s.generateMap({
source: chunk.fileName,
hires: true,
hires: 'boundary',
})
const map = combineSourcemaps(chunk.fileName, [
nextMap as RawSourceMap,
Expand Down
4 changes: 3 additions & 1 deletion packages/vite/src/node/plugins/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
return (
s && {
code: s.toString(),
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null,
map: config.build.sourcemap
? s.generateMap({ hires: 'boundary' })
: null,
}
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/middlewares/indexHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const devHtmlHook: IndexHtmlTransformHook = async (
contentNode.sourceCodeLocation!.startOffset,
contentNode.sourceCodeLocation!.endOffset,
)
.generateMap({ hires: true })
.generateMap({ hires: 'boundary' })
map.sources = [filename]
map.file = filename
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ export async function createPluginContainer(
return createIfNull
? new MagicString(this.originalCode).generateMap({
includeContent: true,
hires: true,
hires: 'boundary',
source: cleanUrl(this.filename),
})
: null
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ async function ssrTransformScript(
},
})

let map = s.generateMap({ hires: true })
let map = s.generateMap({ hires: 'boundary' })
if (inMap && inMap.mappings && inMap.sources.length > 0) {
map = combineSourcemaps(url, [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ export function transformStableResult(
code: s.toString(),
map:
config.command === 'build' && config.build.sourcemap
? s.generateMap({ hires: true, source: id })
? s.generateMap({ hires: 'boundary', source: id })
: null,
}
}
Expand Down
2 changes: 1 addition & 1 deletion playground/css-sourcemap/__tests__/css-sourcemap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe.runIf(isServe)('serve', () => {
const map = extractSourcemap(css)
expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
{
"mappings": "AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACX,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACb,CAAC;",
"mappings": "AAAA,CAAC,QAAQ,CAAC,CAAC;AACX,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC;AACb,CAAC;",
"sources": [
"/root/imported.css",
],
Expand Down
2 changes: 1 addition & 1 deletion playground/css-sourcemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"devDependencies": {
"less": "^4.1.3",
"magic-string": "^0.30.1",
"magic-string": "^0.30.2",
"sass": "^1.63.6",
"stylus": "^0.59.0",
"sugarss": "^4.0.1"
Expand Down
2 changes: 1 addition & 1 deletion playground/css-sourcemap/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default defineConfig({
const start = content.indexOf(willBeReplaced)
ms.overwrite(start, start + willBeReplaced.length, 'purple')

const map = ms.generateMap({ hires: true })
const map = ms.generateMap({ hires: 'boundary' })
map.file = filename
map.sources = [filename]

Expand Down
2 changes: 1 addition & 1 deletion playground/js-sourcemap/__tests__/js-sourcemap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe.runIf(isBuild)('build tests', () => {
const map = findAssetFile(/after-preload-dynamic.*\.js\.map/)
expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(`
{
"mappings": "41BAAAA,EAAA,WAAO,2BAAuB,EAAC,sEAE/B,QAAQ,IAAI,uBAAuB",
"mappings": "k2BAAA,OAAO,2BAAuB,EAAC,sEAE/B,QAAQ,IAAI,uBAAuB",
"sources": [
"../../after-preload-dynamic.js",
],
Expand Down
30 changes: 15 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.