@@ -6,6 +6,7 @@ import child_process from 'child_process'
66import esbuild from 'esbuild'
77import { future } from 'fp-future'
88import { globSync } from 'glob'
9+ import fs from 'fs'
910import path from 'path'
1011import { pathToFileURL } from 'url'
1112import i18next from 'i18next'
@@ -228,22 +229,26 @@ export async function bundleSingleProject(components: BundleComponents, options:
228229 }
229230 }
230231 } ) ( ) ,
231- // Resolve asset-packs from sdk-commands' dependencies (nested in @dcl/inspector)
232+ // Resolve asset-packs from the scene's own node_modules (if the user explicitly installed it),
233+ // otherwise fall back to the version bundled inside @dcl /inspector.
234+ // NOTE: We use a direct path check (fs.existsSync) instead of require.resolve here because
235+ // require.resolve walks UP the directory tree from workingDirectory, which would incorrectly
236+ // pick up @dcl /asset-packs installed next to the scene (e.g. at a monorepo root) rather
237+ // than the one the user intentionally installed inside the scene.
232238 '@dcl/asset-packs' : ( ( ) => {
239+ const sceneOwnAssetPacks = path . join ( options . workingDirectory , 'node_modules' , '@dcl' , 'asset-packs' , 'package.json' )
240+ if ( fs . existsSync ( sceneOwnAssetPacks ) ) {
241+ return path . dirname ( sceneOwnAssetPacks )
242+ }
233243 try {
234- // Try to resolve from project's node_modules first
235- return path . dirname ( require . resolve ( '@dcl/asset-packs/package.json' , { paths : [ options . workingDirectory ] } ) )
244+ // Fallback: resolve from @dcl /inspector's node_modules
245+ const inspectorPath = require . resolve ( '@dcl/inspector/package.json' , { paths : [ __dirname ] } )
246+ return path . dirname (
247+ require . resolve ( '@dcl/asset-packs/package.json' , { paths : [ path . dirname ( inspectorPath ) ] } )
248+ )
236249 } catch {
237- try {
238- // Fallback: resolve from @dcl /inspector's node_modules
239- const inspectorPath = require . resolve ( '@dcl/inspector/package.json' , { paths : [ __dirname ] } )
240- return path . dirname (
241- require . resolve ( '@dcl/asset-packs/package.json' , { paths : [ path . dirname ( inspectorPath ) ] } )
242- )
243- } catch {
244- // Last resort: try resolving from current directory
245- return path . dirname ( require . resolve ( '@dcl/asset-packs/package.json' , { paths : [ __dirname ] } ) )
246- }
250+ // Last resort: try resolving from current directory
251+ return path . dirname ( require . resolve ( '@dcl/asset-packs/package.json' , { paths : [ __dirname ] } ) )
247252 }
248253 } ) ( )
249254 } ,
0 commit comments