Skip to content

Commit d2f6f0a

Browse files
feat: check asset packs by absolute path (#1324)
* feat: check asset packs by absolute path * fix: check asset packs without require.resolve --------- Co-authored-by: Nicolas Echezarreta <nicoecheza@gmail.com>
1 parent d3d891b commit d2f6f0a

File tree

1 file changed

+18
-13
lines changed
  • packages/@dcl/sdk-commands/src/logic

1 file changed

+18
-13
lines changed

packages/@dcl/sdk-commands/src/logic/bundle.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import child_process from 'child_process'
66
import esbuild from 'esbuild'
77
import { future } from 'fp-future'
88
import { globSync } from 'glob'
9+
import fs from 'fs'
910
import path from 'path'
1011
import { pathToFileURL } from 'url'
1112
import 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

Comments
 (0)