File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,20 +14,18 @@ import { execSync } from 'node:child_process'
1414const outdir = 'dist'
1515
1616async function postBuild ( ) {
17- // Step 1: Patch globalThis.Bun destructuring from third-party deps
18- const files = await readdir ( outdir , { recursive : true } )
17+ // Step 1: Patch globalThis.Bun destructuring in the single bundled file
18+ const cliPath = join ( outdir , 'cli.js' )
1919 const BUN_DESTRUCTURE = / v a r \{ ( [ ^ } ] + ) \} = g l o b a l T h i s \. B u n ; ? / g
2020 const BUN_DESTRUCTURE_SAFE =
2121 'var {$1} = typeof globalThis.Bun !== "undefined" ? globalThis.Bun : {};'
2222
2323 let bunPatched = 0
24- for ( const file of files ) {
25- const filePath = join ( outdir , file )
26- if ( typeof file !== 'string' || ! file . endsWith ( '.js' ) ) continue
27- const content = await readFile ( filePath , 'utf-8' )
24+ {
25+ const content = await readFile ( cliPath , 'utf-8' )
2826 if ( BUN_DESTRUCTURE . test ( content ) ) {
2927 await writeFile (
30- filePath ,
28+ cliPath ,
3129 content . replace ( BUN_DESTRUCTURE , BUN_DESTRUCTURE_SAFE ) ,
3230 )
3331 bunPatched ++
Original file line number Diff line number Diff line change @@ -110,12 +110,15 @@ export async function connectDoubaoStream(
110110 let doubaoAsr : typeof import ( 'doubaoime-asr' )
111111 try {
112112 doubaoAsr = await import ( 'doubaoime-asr' )
113- } catch {
114- logError ( new Error ( '[doubao-asr] Failed to import doubaoime-asr package' ) )
115- callbacks . onError (
116- 'doubaoime -asr package is not installed. Install it with: bun add doubaoime-asr' ,
117- { fatal : true } ,
113+ } catch ( err ) {
114+ logError (
115+ new Error (
116+ `[doubao -asr] Failed to import doubaoime-asr package: ${ String ( err ) } ` ,
117+ ) ,
118118 )
119+ callbacks . onError ( `doubaoime-asr package import failed: ${ String ( err ) } ` , {
120+ fatal : true ,
121+ } )
119122 return null
120123 }
121124
Original file line number Diff line number Diff line change @@ -70,6 +70,11 @@ export default defineConfig({
7070 ssr : {
7171 target : 'node' ,
7272 noExternal : true ,
73+ // Packages with runtime require.resolve() or WASM binaries can't be
74+ // inlined into the bundle — they must be resolved from node_modules
75+ // at runtime. doubaoime-asr uses opus-encdec which does
76+ // require.resolve('opus-encdec/dist/libopus-encoder.wasm.js').
77+ external : [ 'doubaoime-asr' , 'opus-encdec' ] ,
7378 } ,
7479
7580 build : {
@@ -88,9 +93,9 @@ export default defineConfig({
8893
8994 output : {
9095 format : 'es' ,
91- dir : 'dist' ,
96+ // Single-file build: no code splitting, all dynamic imports inlined
97+ codeSplitting : false ,
9298 entryFileNames : 'cli.js' ,
93- chunkFileNames : 'chunks/[name]-[hash].js' ,
9499 } ,
95100
96101 plugins : [
You can’t perform that action at this time.
0 commit comments