import { Plugin , PluginBuild } from 'esbuild' ; import { findUp } from 'find-up' ; import { join } from 'path' ; export function esbuildPreactCompatPlugin ( ) { return { name : 'preact-compat' , setup : function ( build ) : void { build . onResolve ( { filter : /^react(?:-dom)?$/ } , async function ( ) : Promise < { path : string ; } > { const preactCompatPath = await findUp ( join ( 'node_modules' , 'preact' , 'compat' , 'dist' , 'compat.module.js' ) ) ; if ( typeof preactCompatPath === 'undefined' ) { throw new Error ( 'Cannot find `preact`' ) ; } return { path : preactCompatPath } ; } ) ; } } ; }