( projectDir: string, html: string, compSrcPath?: string, )
| 48 | } |
| 49 | |
| 50 | function collectExternalStyles( |
| 51 | projectDir: string, |
| 52 | html: string, |
| 53 | compSrcPath?: string, |
| 54 | ): Array<{ href: string; content: string }> { |
| 55 | const styles: Array<{ href: string; content: string }> = []; |
| 56 | const linkRe = /<link\b[^>]*>/gi; |
| 57 | let match: RegExpExecArray | null; |
| 58 | while ((match = linkRe.exec(html)) !== null) { |
| 59 | const tag = match[0]; |
| 60 | const rel = tag.match(/\brel\s*=\s*["']([^"']+)["']/i)?.[1] ?? ""; |
| 61 | if (!rel.split(/\s+/).some((part) => part.toLowerCase() === "stylesheet")) continue; |
| 62 | const href = tag.match(/\bhref\s*=\s*["']([^"']+)["']/i)?.[1] ?? ""; |
| 63 | if (!isLocalStylesheetHref(href)) continue; |
| 64 | const rootRelative = compSrcPath ? join(dirname(compSrcPath), href) : href; |
| 65 | const stylesheet = resolveExistingLocalAsset(projectDir, rootRelative); |
| 66 | if (!stylesheet) continue; |
| 67 | styles.push({ href, content: readFileSync(stylesheet.resolved, "utf-8") }); |
| 68 | } |
| 69 | return styles; |
| 70 | } |
| 71 | |
| 72 | function collectCssSources(projectDir: string, html: string, compSrcPath?: string): CssSource[] { |
| 73 | const sources: CssSource[] = []; |
no test coverage detected