@neodx/vfs
Version:
Simple virtual file system - working dir context, lazy changes, different modes, integrations and moreover
29 lines (28 loc) • 1.08 kB
JavaScript
import { tryFormatPrettier as t } from '@neodx/pkg-misc';
import { concurrently as a, isTypeOfString as r } from '@neodx/std';
import { g as e, j as i } from '../_internal/operations-D4d9Xk5B.mjs';
import { c as n } from '../_internal/create-vfs-plugin-CTZbwgZU.mjs';
function o({ auto: o = !0 } = {}) {
return n('prettier', (n, { context: l, beforeApply: m }) => {
let s = l.log.child('prettier');
async function p(a, e) {
s.debug('Formatting %s', i(l, a));
let o = await t(a, r(e) ? e : e.toString('utf-8'));
null !== o
? (await n.write(a, o), s.debug('Formatted %s', i(l, a)))
: s.debug('Skipped %s', i(l, a));
}
return (
(n.format = async t => await p(t, await n.read(t, 'utf-8'))),
(n.formatAll = async () => {
s.debug('Formatting all changed files...');
let t = await e(l, ['create', 'update']);
await a(t, async ({ path: t, content: a }) => p(t, a), 5);
}),
o && m(() => n.formatAll()),
n
);
});
}
export { o as prettier };
//# sourceMappingURL=prettier.mjs.map