UNPKG

histoire

Version:

A fast story book powered by Vite

32 lines (31 loc) • 1.41 kB
import { readFileSnapshot } from '@histoire/dev-proxy/config'; import path from 'pathe'; export { readFileSnapshot } from '@histoire/dev-proxy/config'; /** Dependencies recorded per resolved config object; the config owns their lifetime. */ const recorded = new WeakMap(); /** * Snapshots the local modules among loader-reported dependencies. Installed packages are left to * the package manager: they change through installs, which already need a restart. * @param files Absolute module paths reported by the loader. */ export async function snapshotLocalModules(files) { const local = [...new Set([...files].map(file => path.resolve(file)))] .filter(file => !file.split('/').includes('node_modules')); return new Map(await Promise.all(local.map(async (file) => [file, await readFileSnapshot(file)]))); } /** * Attaches loader dependencies to the config they produced. * @param config Resolved config. * @param dependencies Local module snapshots. */ export function recordConfigDependencies(config, dependencies) { recorded.set(config, dependencies); } /** * Local modules the given resolved config was loaded from, `undefined` for configs that did not * come from {@link recordConfigDependencies} (test doubles, hand-built contexts). * @param config Resolved config. */ export function getConfigDependencies(config) { return config ? recorded.get(config) : undefined; }