UNPKG

@neodx/vfs

Version:

Simple virtual file system - working dir context, lazy changes, different modes, integrations and moreover

28 lines (27 loc) 1.1 kB
var t = require('@neodx/pkg-misc'), e = require('@neodx/std'), r = require('../_internal/operations-DJhEnMA2.cjs'), a = require('../_internal/create-vfs-plugin-Bg0LL_-h.cjs'); exports.prettier = function ({ auto: i = !0 } = {}) { return a.createVfsPlugin('prettier', (a, { context: n, beforeApply: l }) => { let s = n.log.child('prettier'); async function u(i, l) { s.debug('Formatting %s', r.displayPath(n, i)); let u = await t.tryFormatPrettier(i, e.isTypeOfString(l) ? l : l.toString('utf-8')); null !== u ? (await a.write(i, u), s.debug('Formatted %s', r.displayPath(n, i))) : s.debug('Skipped %s', r.displayPath(n, i)); } return ( (a.format = async t => await u(t, await a.read(t, 'utf-8'))), (a.formatAll = async () => { s.debug('Formatting all changed files...'); let t = await r.getVfsActions(n, ['create', 'update']); await e.concurrently(t, async ({ path: t, content: e }) => u(t, e), 5); }), i && l(() => a.formatAll()), a ); }); }; //# sourceMappingURL=prettier.cjs.map