This commit is contained in:
nuno maduro
2026-04-27 10:30:08 +01:00
parent b46f051550
commit 48357c6f30
4 changed files with 311 additions and 0 deletions

View File

@ -51,6 +51,24 @@ final class JsModuleGraph
return JsImportParser::parse($projectRoot);
}
/**
* Strict variant — only runs the Node helper, never falls back to
* the PHP parser. Returns null when Node isn't available or Vite
* won't load.
*
* Used at replay time when we need to *trust a negative result*
* (i.e., "no page imports this file, so it's orphan, safe to
* skip"). The PHP fallback is conservative on positives but can
* miss imports that rely on custom aliases or plugins — negative
* results from it cannot be trusted for orphan pruning.
*
* @return array<string, list<string>>|null
*/
public static function buildStrict(string $projectRoot): ?array
{
return self::tryNodeHelper($projectRoot);
}
/**
* True when the project looks like a Vite + Node project we can
* ask for a module graph. Gate for callers that want to skip the