MCPcopy
hub / github.com/tailwindlabs/tailwindcss / fetchStyles

Function fetchStyles

integrations/utils.ts:680–723  ·  view source on GitHub ↗
(base: string, path = '/')

Source from the content-addressed store, hash-verified

678}
679
680export async function fetchStyles(base: string, path = '/'): Promise<string> {
681 while (base.endsWith('/')) {
682 base = base.slice(0, -1)
683 }
684
685 let index = await fetch(`${base}${path}`)
686 let html = await index.text()
687
688 let linkRegex = /<link rel="stylesheet" href="([a-zA-Z0-9/_.?=%-]+)"/gi
689 let styleRegex = /<style\b[^>]*>([\s\S]*?)<\/style>/gi
690
691 let stylesheets: string[] = []
692
693 let paths: string[] = []
694 for (let match of html.matchAll(linkRegex)) {
695 let path: string = match[1]
696 if (path.startsWith('./')) {
697 path = path.slice(1)
698 }
699 paths.push(path)
700 }
701 stylesheets.push(
702 ...(await Promise.all(
703 paths.map(async (path) => {
704 let css = await fetch(`${base}${path}`, {
705 headers: {
706 Accept: 'text/css',
707 },
708 })
709 return await css.text()
710 }),
711 )),
712 )
713
714 for (let match of html.matchAll(styleRegex)) {
715 stylesheets.push(match[1])
716 }
717
718 return stylesheets.reduce((acc, css) => {
719 if (acc.length > 0) acc += '\n'
720 acc += css
721 return acc
722 }, '')
723}
724
725export async function getRandomPort() {
726 return new Promise<number>((resolve, reject) => {

Callers 13

next.test.tsFile · 0.90
index.test.tsFile · 0.90
qwik.test.tsFile · 0.90
resolvers.test.tsFile · 0.90
solidstart.test.tsFile · 0.90
multi-root.test.tsFile · 0.90
nuxt.test.tsFile · 0.90
config.test.tsFile · 0.90
astro.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected