@@ -48,6 +48,17 @@ async function browserBundle(entry: string): Promise<{ ok: boolean; message: str
4848}
4949
5050describe ( "#287 — browser bundleability" , ( ) => {
51+ test ( "loadMetaModel is reachable in a browser bundle" , async ( ) => {
52+ // load-meta-model.ts imports its metamodel constants from
53+ // @metaobjectsdev /metadata/constants. If that ever becomes the package root,
54+ // the root pulls MetaDataLoader -> library-sources.ts -> node:url and this fails.
55+ const out = await Bun . build ( { entrypoints : [ DIST_ENTRY ] , target : "browser" , throw : false } ) ;
56+ const code = await out . outputs [ 0 ] ?. text ( ) || "" ;
57+ expect ( out . success , out . logs . map ( ( l ) => String ( l ) ) . join ( "\n" ) ) . toBe ( true ) ;
58+ expect ( code ) . toContain ( "loadMetaModel" ) ;
59+ expect ( code ) . not . toContain ( "fileURLToPath" ) ;
60+ } ) ;
61+
5162 test ( "the BUILT runtime-web entry bundles for a browser target" , async ( ) => {
5263 // dist/ is what a published consumer resolves. If it is missing the gate is
5364 // meaningless, so say so rather than skipping quietly.
@@ -86,19 +97,4 @@ describe("#287 — browser bundleability", () => {
8697 const { ok } = await browserBundle ( root ) ;
8798 expect ( ok ) . toBe ( false ) ;
8899 } ) ;
89-
90- test ( "loadMetaModel is reachable and imports from browser-safe paths" , async ( ) => {
91- // load-meta-model.ts imports TYPE_* from @metaobjectsdev/metadata/constants.
92- // If it ever imports them from the package root instead, the root pulls
93- // MetaDataLoader -> library-sources.ts -> node:url and this breaks browser bundles (#287).
94- // Test 1: load Meta Model function is exported from built dist
95- const distModule = await import ( DIST_ENTRY ) ;
96- expect ( distModule . loadMetaModel ) . toBeDefined ( ) ;
97- expect ( typeof distModule . loadMetaModel ) . toBe ( "function" ) ;
98-
99- // Test 2: source file imports constants from the safe subpath, not the root
100- const sourceFile = await Bun . file ( join ( PKG_ROOT , "src" , "load-meta-model.ts" ) ) . text ( ) ;
101- expect ( sourceFile ) . toContain ( 'from "@metaobjectsdev/metadata/constants"' ) ;
102- expect ( sourceFile ) . not . toMatch ( / f r o m [ " ' ] @ m e t a o b j e c t s d e v \/ m e t a d a t a [ " ' ] \s * ; / ) ;
103- } ) ;
104100} ) ;
0 commit comments