UNPKG

seia.js

Version:

Lightweight SSR framework for React Server Components

28 lines (27 loc) 929 B
import { match } from 'ts-pattern'; import { trimPrefix } from '../utils.js'; export const detectBoundaries = ({ config: { root } })=>{ const boundaries = new Set(); return { name: 'seia:detect-boundaries', moduleParsed ({ id, ast }) { if (ast?.body.filter((node)=>match(node).with({ type: 'ExpressionStatement', expression: { type: 'Literal', value: 'use client' } }, ()=>true).otherwise(()=>false))?.length) boundaries.add('.' + trimPrefix(id, root)); }, buildEnd () { this.emitFile({ type: 'asset', name: 'boundaries-manifest.json', needsCodeReference: false, source: JSON.stringify([ ...boundaries ]) }); } }; };