import * as babel from '@babel/core' ; import path from 'path' ; import { ReboostPlugin } from 'reboost' ; declare namespace ReactRefreshPlugin { export interface Options { excludeNodeModules ? : boolean ; } } function ReactRefreshPlugin ( { excludeNodeModules = true } = { } ) { const transformOptions = { ast : false , configFile : false , babelrc : false , envName : 'development' , comments : false , compact : true , plugins : [ require . resolve ( 'react-refresh/babel' ) ] , sourceMaps : true } ; const Runtime = '__React_Refresh_Runtime__' ; const runtimeFilePath = path . join ( __dirname , '../runtime/index.js' ) ; const preCode = `
    import * as ${ Runtime } from ${ JSON . stringify ( runtimeFilePath ) };

    const __prevRefreshReg = self.$RefreshReg$;
    const __prevRefreshSig = self.$RefreshSig$;

    self.$RefreshReg$ = (type, id) => {
      const fullId = import.meta.hot.id + ' ' + id;
      ${ Runtime }.register(type, fullId);
    }
    self.$RefreshSig$ = ${ Runtime }.createSignatureFunction;\n
  ` ; const postCode = `;
    self.$RefreshReg$ = __prevRefreshReg;
    self.$RefreshSig$ = __prevRefreshSig;

    import.meta.hot.accept((updatedModule) => {
      // Check if all exports are React components
      if (${ Runtime }.isReactRefreshBoundary(updatedModule)) {
        ${ Runtime }.performReactRefresh();
      } else {
        import.meta.hot.invalidate();
      }
    });
  ` ; const offsetMapping = ';' . repeat ( preCode . match ( /\n/g ) . length ) ; return { name : 'react-refresh-plugin' , getCacheKey : ( ) => 1 , async transformJSContent ( { code } , filePath ) { if ( excludeNodeModules && /node_modules/ . test ( filePath ) ) return ; try { const babelResult = await babel . transformAsync ( code , transformOptions ) ; const resultCode = preCode + babelResult . code + postCode ; if ( babelResult . map ) { babelResult . map . sources = [ filePath ] ; babelResult . map . mappings = offsetMapping + babelResult . map . mappings ; } return { code : resultCode , map : babelResult . map } ; } catch ( e ) { console . log ( e ) ; } return null ; } } ; } export = ReactRefreshPlugin ;