Skip to content

Commit b9a8d65

Browse files
authoredJul 29, 2023
perf: use magic-string hires boundary for sourcemaps (#13971)
1 parent f8a5ffc commit b9a8d65

File tree

17 files changed

+43
-37
lines changed

17 files changed

+43
-37
lines changed
 

‎packages/plugin-legacy/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@babel/preset-env": "^7.22.9",
4747
"browserslist": "^4.21.9",
4848
"core-js": "^3.31.1",
49-
"magic-string": "^0.30.1",
49+
"magic-string": "^0.30.2",
5050
"regenerator-runtime": "^0.13.11",
5151
"systemjs": "^6.14.1"
5252
},

‎packages/plugin-legacy/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
397397
if (config.build.sourcemap) {
398398
return {
399399
code: ms.toString(),
400-
map: ms.generateMap({ hires: true }),
400+
map: ms.generateMap({ hires: 'boundary' }),
401401
}
402402
}
403403
return {

‎packages/vite/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
"@rollup/plugin-node-resolve": "15.1.0",
8787
"@rollup/plugin-typescript": "^11.1.2",
8888
"@rollup/pluginutils": "^5.0.2",
89-
"@types/pnpapi": "^0.0.2",
9089
"@types/escape-html": "^1.0.2",
90+
"@types/pnpapi": "^0.0.2",
9191
"acorn": "^8.10.0",
9292
"acorn-walk": "^8.2.0",
9393
"cac": "^6.7.14",
@@ -110,7 +110,7 @@
110110
"json-stable-stringify": "^1.0.2",
111111
"launch-editor-middleware": "^2.6.0",
112112
"lightningcss": "^1.21.5",
113-
"magic-string": "^0.30.1",
113+
"magic-string": "^0.30.2",
114114
"micromatch": "^4.0.5",
115115
"mlly": "^1.4.0",
116116
"mrmime": "^1.0.1",
@@ -138,10 +138,10 @@
138138
"peerDependencies": {
139139
"@types/node": ">= 14",
140140
"less": "*",
141+
"lightningcss": "^1.21.0",
141142
"sass": "*",
142143
"stylus": "*",
143144
"sugarss": "*",
144-
"lightningcss": "^1.21.0",
145145
"terser": "^5.4.0"
146146
},
147147
"peerDependenciesMeta": {

‎packages/vite/rollup.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ function shimDepsPlugin(deps: Record<string, ShimOptions>): Plugin {
260260

261261
return {
262262
code: magicString.toString(),
263-
map: magicString.generateMap({ hires: true }),
263+
map: magicString.generateMap({ hires: 'boundary' }),
264264
}
265265
}
266266
}
@@ -308,7 +308,7 @@ const __require = require;
308308

309309
return {
310310
code: s.toString(),
311-
map: s.generateMap({ hires: true }),
311+
map: s.generateMap({ hires: 'boundary' }),
312312
}
313313
},
314314
}

‎packages/vite/src/node/plugins/asset.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ export function assetPlugin(config: ResolvedConfig): Plugin {
189189
if (s) {
190190
return {
191191
code: s.toString(),
192-
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null,
192+
map: config.build.sourcemap
193+
? s.generateMap({ hires: 'boundary' })
194+
: null,
193195
}
194196
} else {
195197
return null

‎packages/vite/src/node/plugins/css.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
697697
// resolve public URL from CSS paths, we need to use absolute paths
698698
return {
699699
code: s.toString(),
700-
map: s.generateMap({ hires: true }),
700+
map: s.generateMap({ hires: 'boundary' }),
701701
}
702702
} else {
703703
return { code: s.toString() }
@@ -2130,7 +2130,7 @@ async function getSource(
21302130
ms.appendLeft(0, sep)
21312131
ms.appendLeft(0, additionalData)
21322132

2133-
const map = ms.generateMap({ hires: true })
2133+
const map = ms.generateMap({ hires: 'boundary' })
21342134
map.file = filename
21352135
map.sources = [filename]
21362136

‎packages/vite/src/node/plugins/importAnalysisBuild.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,9 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
418418
if (s) {
419419
return {
420420
code: s.toString(),
421-
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null,
421+
map: config.build.sourcemap
422+
? s.generateMap({ hires: 'boundary' })
423+
: null,
422424
}
423425
}
424426
},
@@ -436,7 +438,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
436438
}
437439
return {
438440
code: s.toString(),
439-
map: s.generateMap({ hires: true }),
441+
map: s.generateMap({ hires: 'boundary' }),
440442
}
441443
} else {
442444
return code.replace(re, isModern)
@@ -651,7 +653,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
651653
if (config.build.sourcemap && chunk.map) {
652654
const nextMap = s.generateMap({
653655
source: chunk.fileName,
654-
hires: true,
656+
hires: 'boundary',
655657
})
656658
const map = combineSourcemaps(chunk.fileName, [
657659
nextMap as RawSourceMap,

‎packages/vite/src/node/plugins/worker.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
365365
return (
366366
s && {
367367
code: s.toString(),
368-
map: config.build.sourcemap ? s.generateMap({ hires: true }) : null,
368+
map: config.build.sourcemap
369+
? s.generateMap({ hires: 'boundary' })
370+
: null,
369371
}
370372
)
371373
}

‎packages/vite/src/node/server/middlewares/indexHtml.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ const devHtmlHook: IndexHtmlTransformHook = async (
195195
contentNode.sourceCodeLocation!.startOffset,
196196
contentNode.sourceCodeLocation!.endOffset,
197197
)
198-
.generateMap({ hires: true })
198+
.generateMap({ hires: 'boundary' })
199199
map.sources = [filename]
200200
map.file = filename
201201
}

‎packages/vite/src/node/server/pluginContainer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ export async function createPluginContainer(
574574
return createIfNull
575575
? new MagicString(this.originalCode).generateMap({
576576
includeContent: true,
577-
hires: true,
577+
hires: 'boundary',
578578
source: cleanUrl(this.filename),
579579
})
580580
: null

‎packages/vite/src/node/ssr/ssrTransform.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ async function ssrTransformScript(
274274
},
275275
})
276276

277-
let map = s.generateMap({ hires: true })
277+
let map = s.generateMap({ hires: 'boundary' })
278278
if (inMap && inMap.mappings && inMap.sources.length > 0) {
279279
map = combineSourcemaps(url, [
280280
{

‎packages/vite/src/node/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ export function transformStableResult(
11421142
code: s.toString(),
11431143
map:
11441144
config.command === 'build' && config.build.sourcemap
1145-
? s.generateMap({ hires: true, source: id })
1145+
? s.generateMap({ hires: 'boundary', source: id })
11461146
: null,
11471147
}
11481148
}

‎playground/css-sourcemap/__tests__/css-sourcemap.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe.runIf(isServe)('serve', () => {
9292
const map = extractSourcemap(css)
9393
expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
9494
{
95-
"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;",
95+
"mappings": "AAAA,CAAC,QAAQ,CAAC,CAAC;AACX,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC;AACb,CAAC;",
9696
"sources": [
9797
"/root/imported.css",
9898
],

‎playground/css-sourcemap/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"devDependencies": {
1313
"less": "^4.1.3",
14-
"magic-string": "^0.30.1",
14+
"magic-string": "^0.30.2",
1515
"sass": "^1.63.6",
1616
"stylus": "^0.59.0",
1717
"sugarss": "^4.0.1"

‎playground/css-sourcemap/vite.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default defineConfig({
2121
const start = content.indexOf(willBeReplaced)
2222
ms.overwrite(start, start + willBeReplaced.length, 'purple')
2323

24-
const map = ms.generateMap({ hires: true })
24+
const map = ms.generateMap({ hires: 'boundary' })
2525
map.file = filename
2626
map.sources = [filename]
2727

‎playground/js-sourcemap/__tests__/js-sourcemap.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe.runIf(isBuild)('build tests', () => {
5454
const map = findAssetFile(/after-preload-dynamic.*\.js\.map/)
5555
expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(`
5656
{
57-
"mappings": "41BAAAA,EAAA,WAAO,2BAAuB,EAAC,sEAE/B,QAAQ,IAAI,uBAAuB",
57+
"mappings": "k2BAAA,OAAO,2BAAuB,EAAC,sEAE/B,QAAQ,IAAI,uBAAuB",
5858
"sources": [
5959
"../../after-preload-dynamic.js",
6060
],

‎pnpm-lock.yaml

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.