UNPKG

histoire

Version:

A fast story book powered by Vite

28 lines (27 loc) • 1.55 kB
import micromatch from 'micromatch'; import { relative, resolve } from 'pathe'; import { isPathWithinRoot } from '../runtime/content/files.js'; import { getProjectCacheDir, getProjectTempDir } from './temp-paths.js'; /** Shares source admission and directory pruning across both filesystem watchers. */ export function createStoryIgnore(ctx) { const temporary = getProjectTempDir(ctx.root); // Persistent optimizer caches (see vite/optimizer-cache.ts) are as large. const cache = getProjectCacheDir(ctx.root); const patterns = ctx.config.storyIgnored.map(pattern => resolve(ctx.root, pattern)); return (file) => { const absolute = resolve(ctx.root, file); // Old and concurrent runs can contain gigabytes of optimizer output. // Prune the directory itself; generated stories register through addStory. return isPathWithinRoot(temporary, absolute) || isPathWithinRoot(cache, absolute) || patterns.some(pattern => micromatch.isMatch(absolute, pattern)); }; } /** Prunes only kind/run/vite cache ancestry, retaining generated plugin sources. */ export function createOptimizerCacheIgnore(ctx) { const temporary = getProjectTempDir(ctx.root); return (file) => { const absolute = resolve(ctx.root, file); // Exact segments also handle roots containing glob characters, and never // confuse plugins/vite with the optimizer directory beside plugins. return isPathWithinRoot(temporary, absolute) && relative(temporary, absolute).split('/')[2] === 'vite'; }; }