# \.test-favicon.mjs · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/blob/refs%2Fheads%2Fcodething%2F0cbde587/.test-favicon.mjs)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

Requested revision: refs/heads/codething/0cbde587

Commit: e6fd90df22c6d28bda7a918dd379e9ecfdc81883

Blob: 5c9d741806e2cb2546e9efcac29dbbea1e1d909f

Size: 2179 bytes

[Immutable source](https://git.cafe/pingdotgg/t3code/blob/e6fd90df22c6d28bda7a918dd379e9ecfdc81883/.test-favicon.mjs?format=markdown)

```
import path from "path";
import fs from "fs";

const FAVICON_CANDIDATES = [
  "favicon.svg", "favicon.ico", "favicon.png",
  "public/favicon.svg", "public/favicon.ico", "public/favicon.png",
  "app/favicon.ico", "app/favicon.png", "app/icon.svg", "app/icon.png", "app/icon.ico",
  "src/favicon.ico", "src/favicon.svg", "src/app/favicon.ico", "src/app/icon.svg", "src/app/icon.png",
];

const ICON_SOURCE_FILES = [
  "index.html", "public/index.html",
  "app/routes/__root.tsx", "src/routes/__root.tsx",
  "app/root.tsx", "src/root.tsx", "src/index.html",
];

const LINK_ICON_HTML_RE = /<link[^>]*rel=["'](?:icon|shortcut icon)["'][^>]*href=["']([^"'?]+)/i;
const LINK_ICON_OBJ_RE = /rel:\s*["'](?:icon|shortcut icon)["'][^}]*href:\s*["']([^"'?]+)/i;

function test(projectCwd) {
  console.log("--- Testing:", projectCwd, "---");

  for (const c of FAVICON_CANDIDATES) {
    const full = path.join(projectCwd, c);
    if (fs.existsSync(full) && fs.statSync(full).isFile()) {
      console.log("  Phase 1 FOUND:", c);
      return;
    }
  }
  console.log("  Phase 1: no match");

  for (const sf of ICON_SOURCE_FILES) {
    const full = path.join(projectCwd, sf);
    if (!fs.existsSync(full)) continue;
    const content = fs.readFileSync(full, "utf8");
    const href = content.match(LINK_ICON_HTML_RE)?.[1] || content.match(LINK_ICON_OBJ_RE)?.[1];
    if (href) {
      const clean = href.replace(/^\//, "");
      const tryPaths = [path.join(projectCwd, "public", clean), path.join(projectCwd, clean)];
      for (const p of tryPaths) {
        if (fs.existsSync(p)) {
          console.log("  Phase 2 FOUND:", sf, "->", href, "->", p);
          return;
        }
      }
      console.log("  Phase 2 href found but file missing:", href);
    }
  }
  console.log("  Phase 2: no match");
}

function getTestPaths() {
  const cliPaths = process.argv.slice(2).map((p) => p.trim()).filter(Boolean);
  if (cliPaths.length > 0) return cliPaths;

  const envPaths = process.env.TEST_PATHS?.split(path.delimiter).map((p) => p.trim()).filter(Boolean);
  if (envPaths?.length) return envPaths;

  return [process.cwd()];
}

for (const p of getTestPaths()) {
  test(path.resolve(p));
}

```
