11import type { Plugin } from 'esbuild'
2- import { mkdtempSync , rmSync } from 'node:fs'
2+ import { mkdtempSync , readdirSync , readFileSync , rmSync } from 'node:fs'
33import { join } from 'node:path'
44import { fileURLToPath , pathToFileURL } from 'node:url'
55import { build } from 'esbuild'
@@ -12,6 +12,7 @@ const entries = [
1212 'packages/hub/dist/node/initiate.mjs' ,
1313 'packages/next/dist/hub.mjs' ,
1414]
15+ const nextServerChunks = join ( root , 'examples/hub-next/src/client/.next/server/chunks' )
1516const temporaryDirectories : string [ ] = [ ]
1617
1718afterEach ( ( ) => {
@@ -98,4 +99,14 @@ describe('optional MCP peers in consumer bundles', () => {
9899 await hub . close ( )
99100 }
100101 } )
102+
103+ it ( 'preserves the runtime importer in Next production bundles' , ( ) => {
104+ const runtimeImportChunks = readdirSync ( nextServerChunks )
105+ . filter ( file => file . endsWith ( '.js' ) )
106+ . map ( file => readFileSync ( join ( nextServerChunks , file ) , 'utf8' ) )
107+ . filter ( source => source . includes ( 'packages/devframe/src/node/import-runtime-module.ts' ) )
108+
109+ expect ( runtimeImportChunks ) . not . toHaveLength ( 0 )
110+ expect ( runtimeImportChunks . join ( '\n' ) ) . not . toContain ( 'Cannot find module as expression is too dynamic' )
111+ } )
101112} )
0 commit comments