import type * as d from '../../declarations' ; import { isString , normalizeFsPath } from '@utils' ; import type { Plugin } from 'rollup' ; import { isOutputTargetHydrate } from '../output-targets/output-utils' ; import { isAbsolute } from 'path' ; export const serverPlugin = ( config , platform ) : Plugin => { const isHydrateBundle = platform === 'hydrate' ; const serverVarid = `@removed-server-code` ; const isServerOnlyModule = ( id ) => { if ( isString ( id ) ) { id = normalizeFsPath ( id ) ; return id . includes ( '.server/' ) || id . endsWith ( '.server' ) ; } return false ; } ; const externals = isHydrateBundle ? config . outputTargets . filter ( isOutputTargetHydrate ) . flatMap ( ( o ) => o . external ) : [ ] ; return { name : 'serverPlugin' , resolveId ( id , importer ) { if ( id === serverVarid ) { return id ; } if ( isHydrateBundle ) { if ( externals . includes ( id ) ) { return { id , external : true , } ; } if ( isServerOnlyModule ( importer ) && ! id . startsWith ( '.' ) && ! isAbsolute ( id ) ) { return { id , external : true , } ; } } else { if ( isServerOnlyModule ( id ) ) { return serverVarid ; } } return null ; } , load ( id ) { if ( id === serverVarid ) { return { code : 'export default {};' , syntheticNamedExports : true , } ; } return null ; } , } ; } ;