( html: string, hooks: IndexHtmlTransformHook[], pluginContext: MinimalPluginContextWithoutEnvironment, ctx: IndexHtmlTransformContext, )
| 1441 | } |
| 1442 | |
| 1443 | export async function applyHtmlTransforms( |
| 1444 | html: string, |
| 1445 | hooks: IndexHtmlTransformHook[], |
| 1446 | pluginContext: MinimalPluginContextWithoutEnvironment, |
| 1447 | ctx: IndexHtmlTransformContext, |
| 1448 | ): Promise<string> { |
| 1449 | for (const hook of hooks) { |
| 1450 | const res = await hook.call(pluginContext, html, ctx) |
| 1451 | if (!res) { |
| 1452 | continue |
| 1453 | } |
| 1454 | if (typeof res === 'string') { |
| 1455 | html = res |
| 1456 | } else { |
| 1457 | let tags: HtmlTagDescriptor[] |
| 1458 | if (Array.isArray(res)) { |
| 1459 | tags = res |
| 1460 | } else { |
| 1461 | html = res.html || html |
| 1462 | tags = res.tags |
| 1463 | } |
| 1464 | |
| 1465 | let headTags: HtmlTagDescriptor[] | undefined |
| 1466 | let headPrependTags: HtmlTagDescriptor[] | undefined |
| 1467 | let bodyTags: HtmlTagDescriptor[] | undefined |
| 1468 | let bodyPrependTags: HtmlTagDescriptor[] | undefined |
| 1469 | |
| 1470 | for (const tag of tags) { |
| 1471 | switch (tag.injectTo) { |
| 1472 | case 'body': |
| 1473 | ;(bodyTags ??= []).push(tag) |
| 1474 | break |
| 1475 | case 'body-prepend': |
| 1476 | ;(bodyPrependTags ??= []).push(tag) |
| 1477 | break |
| 1478 | case 'head': |
| 1479 | ;(headTags ??= []).push(tag) |
| 1480 | break |
| 1481 | default: |
| 1482 | ;(headPrependTags ??= []).push(tag) |
| 1483 | } |
| 1484 | } |
| 1485 | headTagInsertCheck([...(headTags || []), ...(headPrependTags || [])], ctx) |
| 1486 | if (headPrependTags) html = injectToHead(html, headPrependTags, true) |
| 1487 | if (headTags) html = injectToHead(html, headTags) |
| 1488 | if (bodyPrependTags) html = injectToBody(html, bodyPrependTags, true) |
| 1489 | if (bodyTags) html = injectToBody(html, bodyTags) |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | return html |
| 1494 | } |
| 1495 | |
| 1496 | const entirelyImportRE = |
| 1497 | /^(?:import\s*(?:"[^"\n]*[^\\\n]"|'[^'\n]*[^\\\n]');*|\/\*[\s\S]*?\*\/|\/\/.*[$\n])*$/ |
no test coverage detected