mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
Fix sourcemap warning in server islands plugin (#12877)
This commit is contained in:
parent
78bcad952e
commit
73a078835e
2 changed files with 22 additions and 1 deletions
5
.changeset/big-mugs-approve.md
Normal file
5
.changeset/big-mugs-approve.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes sourcemap warning generated by the `astro:server-islands` Vite plugin
|
|
@ -1,3 +1,4 @@
|
||||||
|
import MagicString from 'magic-string';
|
||||||
import type { ConfigEnv, ViteDevServer, Plugin as VitePlugin } from 'vite';
|
import type { ConfigEnv, ViteDevServer, Plugin as VitePlugin } from 'vite';
|
||||||
import type { AstroPluginOptions } from '../../types/astro.js';
|
import type { AstroPluginOptions } from '../../types/astro.js';
|
||||||
import type { AstroPluginMetadata } from '../../vite-plugin-astro/index.js';
|
import type { AstroPluginMetadata } from '../../vite-plugin-astro/index.js';
|
||||||
|
@ -82,6 +83,15 @@ export function vitePluginServerIslands({ settings, logger }: AstroPluginOptions
|
||||||
},
|
},
|
||||||
renderChunk(code) {
|
renderChunk(code) {
|
||||||
if (code.includes(serverIslandPlaceholder)) {
|
if (code.includes(serverIslandPlaceholder)) {
|
||||||
|
// If there's no reference, we can fast-path to an empty map replacement
|
||||||
|
// without sourcemaps as it doesn't shift rows
|
||||||
|
if (referenceIdMap.size === 0) {
|
||||||
|
return {
|
||||||
|
code: code.replace(serverIslandPlaceholder, 'new Map();'),
|
||||||
|
map: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let mapSource = 'new Map([';
|
let mapSource = 'new Map([';
|
||||||
for (let [resolvedPath, referenceId] of referenceIdMap) {
|
for (let [resolvedPath, referenceId] of referenceIdMap) {
|
||||||
const fileName = this.getFileName(referenceId);
|
const fileName = this.getFileName(referenceId);
|
||||||
|
@ -90,7 +100,13 @@ export function vitePluginServerIslands({ settings, logger }: AstroPluginOptions
|
||||||
}
|
}
|
||||||
mapSource += '\n]);';
|
mapSource += '\n]);';
|
||||||
referenceIdMap.clear();
|
referenceIdMap.clear();
|
||||||
return code.replace(serverIslandPlaceholder, mapSource);
|
|
||||||
|
const ms = new MagicString(code);
|
||||||
|
ms.replace(serverIslandPlaceholder, mapSource);
|
||||||
|
return {
|
||||||
|
code: ms.toString(),
|
||||||
|
map: ms.generateMap({ hires: 'boundary' }),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue