@@ -6,6 +6,12 @@ import { normalizeObjectHook } from '../utils/filter'
66import { toArray } from '../utils/general'
77import { createBuildContext , createPluginContext , guessLoader } from './utils'
88
9+ // Coerce plugin.name to satisfy Bun's namespace validator:
10+ // https://github.com/oven-sh/bun/blob/12d77d1ac561771e9fa1d0822e954273248e7f9a/src/js/builtins/BundlerPlugin.ts#L215-L217
11+ function toBunNamespace ( name : string ) : string {
12+ return name . replace ( / [ ^ $ a - z A - Z 0 - 9 _ - ] / g, '-' )
13+ }
14+
915export function getBunPlugin < UserOptions = Record < string , never > > (
1016 factory : UnpluginFactory < UserOptions > ,
1117) : UnpluginInstance < UserOptions > [ 'bun' ] {
@@ -102,7 +108,7 @@ export function getBunPlugin<UserOptions = Record<string, never>>(
102108 if ( ! isAbsolute ( result ) ) {
103109 return {
104110 path : result ,
105- namespace : plugin . name ,
111+ namespace : toBunNamespace ( plugin . name ) ,
106112 }
107113 }
108114 return { path : result }
@@ -112,7 +118,7 @@ export function getBunPlugin<UserOptions = Record<string, never>>(
112118 return {
113119 path : result . id ,
114120 external : result . external ,
115- namespace : plugin . name ,
121+ namespace : toBunNamespace ( plugin . name ) ,
116122 }
117123 }
118124 return {
@@ -217,7 +223,7 @@ export function getBunPlugin<UserOptions = Record<string, never>>(
217223 }
218224
219225 for ( const pluginName of virtualModulePlugins ) {
220- build . onLoad ( { filter : / .* / , namespace : pluginName } , async ( args ) => {
226+ build . onLoad ( { filter : / .* / , namespace : toBunNamespace ( pluginName ) } , async ( args ) => {
221227 return processLoadTransform ( args . path , pluginName , args . loader )
222228 } )
223229 }
0 commit comments