mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-12 06:06:37 +03:00
A ground-up hardening of live mode, driven by a production session in a nested-app monorepo that hit six distinct failure classes. Full design rationale in docs/LIVE-REWRITE-PLAN.md; every Codex-reported failure now has a mechanical fix and a regression test. Roots: live/roots.mjs resolves appRoot/repoRoot/contextRoot once at boot (keyed on dev-server configs, not monorepo brand markers), persists a manifest, and every live CLI re-anchors onto it at startup, so a helper run from the wrong directory can no longer fork session state. Context files are discovered upward to the git root. Render truth: variant_mounted / variant_mount_failed events give the journal per-variant mount state; failures reach the agent's poll queue, raise a persistent error card with Retry (no more localStorage wipe), and an attach probe names root/dev-server mismatches explicitly. The browser rehydrates from the server when localStorage is gone. Svelte: the scaffolder now parses with the app's own svelte 5 compiler. Control flow survives (an each collection crosses the contract as one structured prop), keyed each blocks hydrate synthetic keys, and anything a detached preview cannot support falls back to source-preview instead of shipping a wrong scaffold. Preview modules live in per-publish revision directories, defeating stale transform caches. Accept: CSS is reconciled, not appended. Matching selectors are replaced, params bake from params.json kinds, the compiler's unused-selector pass prunes superseded rules (pre-existing dead rules protected), a selector- loss postcondition refuses any write that would drop hand-written rules, and live-complete refuses to finish while live plumbing remains in source. Also: framework registry (live/frameworks/) with a crash-safe injection journal, session-store snapshot caching with read-only reads, protocol enum consolidation, steer Send button, honest DESIGN-panel empty states. Testing: new unit suites (roots, AST scaffolder, accept CSS, accept pipeline, framework conformance); e2e now fails on preview-tree 404s, proves computed-style mount for every variant, drives the Tune panel through baked params, and injects failures (broken mounts, republish, storage loss). New runtime fixtures: monorepo-nested-vite (repo root != app root) and vite8-sveltekit-stateful (each blocks + state). Nightly full-matrix cron. An independent adversarial review pass preceded this commit; its blocker and major findings are fixed and regression-tested. This work was produced with AI assistance (Claude Code). Co-Authored-By: Claude Code <noreply@anthropic.com>
74 lines
2.1 KiB
JavaScript
74 lines
2.1 KiB
JavaScript
/**
|
|
* Small read-only probes the framework entries share.
|
|
*
|
|
* Every helper here is cheap and failure-tolerant: detection runs on every
|
|
* inject, against project trees that may be half-installed, so a missing or
|
|
* malformed file means "not this framework", never a throw.
|
|
*/
|
|
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
/** Merged dependency names from package.json, or an empty object. */
|
|
export function readPackageDeps(cwd) {
|
|
const file = path.join(cwd, 'package.json');
|
|
try {
|
|
const pkg = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
return {
|
|
...(pkg.dependencies || {}),
|
|
...(pkg.devDependencies || {}),
|
|
...(pkg.peerDependencies || {}),
|
|
};
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
export function hasAnyDependency(cwd, names) {
|
|
const deps = readPackageDeps(cwd);
|
|
return names.some((name) => Boolean(deps[name]));
|
|
}
|
|
|
|
/** First top-level file name matching `re`, or null. */
|
|
export function findConfigFile(cwd, re) {
|
|
try {
|
|
return fs.readdirSync(cwd, { withFileTypes: true })
|
|
.find((entry) => entry.isFile() && re.test(entry.name))
|
|
?.name ?? null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function fileExists(cwd, rel) {
|
|
try {
|
|
return fs.existsSync(path.join(cwd, rel));
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function firstExistingFile(cwd, candidates) {
|
|
for (const rel of candidates) {
|
|
if (fileExists(cwd, rel)) return rel;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Literal (non-glob) entries of `config.files` that exist on disk. Several
|
|
* detectors read the configured injection target as a signal, which is how the
|
|
* bare fixtures — a tree of `.astro` files with no astro.config — still resolve
|
|
* to the framework that authored them.
|
|
*/
|
|
export function literalConfigFiles(cwd, config) {
|
|
const files = Array.isArray(config?.files) ? config.files : [];
|
|
const out = [];
|
|
for (const rel of files) {
|
|
if (typeof rel !== 'string' || rel.includes('*') || rel.includes('?')) continue;
|
|
const normalized = rel.split(path.sep).join('/');
|
|
if (fileExists(cwd, normalized)) out.push(normalized);
|
|
}
|
|
return out;
|
|
}
|