@@ -170,6 +170,16 @@ type SingleProjectOptions = CompileOptions & {
170170export async function bundleSingleProject ( components : BundleComponents , options : SingleProjectOptions ) {
171171 printProgressStep ( components . logger , `Bundling file ${ colors . bold ( options . entrypoint ) } ` , 1 , MAX_STEP )
172172 const editorScene = await isEditorScene ( components , options . workingDirectory )
173+
174+ // Pre-compute composite data so we can inject maxCompositeEntity via esbuild define.
175+ // This must happen before the esbuild context is created because the define values
176+ // are baked into the engine at compile time (the entity counter initializer reads it)
177+ let maxCompositeEntity = 0
178+ if ( ! options . ignoreComposite ) {
179+ const composites = await getAllComposites ( components , options . workingDirectory )
180+ maxCompositeEntity = composites . maxCompositeEntity
181+ }
182+
173183 const sdkPackagePath = ( ( ) => {
174184 try {
175185 // First try to resolve from project's node_modules
@@ -236,7 +246,13 @@ export async function bundleSingleProject(components: BundleComponents, options:
236246 // pick up @dcl /asset-packs installed next to the scene (e.g. at a monorepo root) rather
237247 // than the one the user intentionally installed inside the scene.
238248 '@dcl/asset-packs' : ( ( ) => {
239- const sceneOwnAssetPacks = path . join ( options . workingDirectory , 'node_modules' , '@dcl' , 'asset-packs' , 'package.json' )
249+ const sceneOwnAssetPacks = path . join (
250+ options . workingDirectory ,
251+ 'node_modules' ,
252+ '@dcl' ,
253+ 'asset-packs' ,
254+ 'package.json'
255+ )
240256 if ( fs . existsSync ( sceneOwnAssetPacks ) ) {
241257 return path . dirname ( sceneOwnAssetPacks )
242258 }
@@ -259,7 +275,8 @@ export async function bundleSingleProject(components: BundleComponents, options:
259275 window : 'undefined' ,
260276 DEBUG : options . production ? 'false' : 'true' ,
261277 'globalThis.DEBUG' : options . production ? 'false' : 'true' ,
262- 'process.env.NODE_ENV' : JSON . stringify ( options . production ? 'production' : 'development' )
278+ 'process.env.NODE_ENV' : JSON . stringify ( options . production ? 'production' : 'development' ) ,
279+ DCL_MAX_COMPOSITE_ENTITY : String ( maxCompositeEntity )
263280 } ,
264281 tsconfig : options . tsconfig ,
265282 supported : {
0 commit comments