(
html,
{ path: htmlPath, filename, server, originalUrl },
)
| 202 | return processedUrl |
| 203 | } |
| 204 | const devHtmlHook: IndexHtmlTransformHook = async ( |
| 205 | html, |
| 206 | { path: htmlPath, filename, server, originalUrl }, |
| 207 | ) => { |
| 208 | const { config, watcher } = server! |
| 209 | const base = config.base || '/' |
| 210 | const decodedBase = config.decodedBase || '/' |
| 211 | |
| 212 | let proxyModulePath: string |
| 213 | let proxyModuleUrl: string |
| 214 | |
| 215 | const trailingSlash = htmlPath.endsWith('/') |
| 216 | if (!trailingSlash && fs.existsSync(filename)) { |
| 217 | // If htmlPath is a /@fs/ URL (e.g. vitest-browser always uses this form |
| 218 | // for testerHtmlPath), normalise to an absolute FS path so proxyCacheUrl |
| 219 | // is always root-relative. |
| 220 | proxyModulePath = htmlPath.startsWith(FS_PREFIX) ? filename : htmlPath |
| 221 | proxyModuleUrl = htmlPath |
| 222 | } else { |
| 223 | // There are users of vite.transformIndexHtml calling it with url '/' |
| 224 | // for SSR integrations #7993, filename is root for this case |
| 225 | // A user may also use a valid name for a virtual html file |
| 226 | // Mark the path as virtual in both cases so sourcemaps aren't processed |
| 227 | // and ids are properly handled |
| 228 | const validPath = `${htmlPath}${trailingSlash ? 'index.html' : ''}` |
| 229 | proxyModulePath = `\0${validPath}` |
| 230 | proxyModuleUrl = wrapId(proxyModulePath) |
| 231 | } |
| 232 | proxyModuleUrl = joinUrlSegments(decodedBase, proxyModuleUrl) |
| 233 | |
| 234 | const s = new MagicString(html) |
| 235 | let inlineModuleIndex = -1 |
| 236 | // The key to the proxyHtml cache is decoded, as it will be compared |
| 237 | // against decoded URLs by the HTML plugins. |
| 238 | const proxyCacheUrl = decodeURI( |
| 239 | cleanUrl(proxyModulePath).replace(normalizePath(config.root), ''), |
| 240 | ) |
| 241 | const styleUrl: AssetNode[] = [] |
| 242 | const inlineStyles: InlineStyleAttribute[] = [] |
| 243 | const inlineModulePaths: string[] = [] |
| 244 | |
| 245 | const addInlineModule = ( |
| 246 | node: DefaultTreeAdapterMap['element'], |
| 247 | ext: 'js', |
| 248 | ) => { |
| 249 | inlineModuleIndex++ |
| 250 | |
| 251 | const contentNode = node.childNodes[0] as DefaultTreeAdapterMap['textNode'] |
| 252 | |
| 253 | const code = contentNode.value |
| 254 | |
| 255 | let map: SourceMapInput | undefined |
| 256 | if (proxyModulePath[0] !== '\0') { |
| 257 | map = new MagicString(html) |
| 258 | .snip( |
| 259 | contentNode.sourceCodeLocation!.startOffset, |
| 260 | contentNode.sourceCodeLocation!.endOffset, |
| 261 | ) |
nothing calls this directly
no test coverage detected