diff --git a/lib/resolve.js b/lib/resolve.js index 3dd2091..a94ef76 100644 --- a/lib/resolve.js +++ b/lib/resolve.js @@ -34,11 +34,14 @@ const isInstalledWithPNPM = function(resolved) { return false; } -const getFirstPartFromNodeModules = function(resolved) { +const getFirstPart = function (resolved) { const nodeModulesDir = sep + 'node_modules'; + const esbuildDir = sep + '.esbuild'; - if (-1 !== resolved.indexOf(nodeModulesDir)) { - const parts = resolved.split(nodeModulesDir); + const dirRegEx = new RegExp(`${nodeModulesDir}|${esbuildDir}`); + + if (-1 !== resolved.indexOf(nodeModulesDir) || -1 !== resolved.indexOf(esbuildDir)) { + const parts = resolved.split(dirRegEx); if (parts.length) { return parts[0]; } @@ -82,7 +85,7 @@ module.exports = function resolve(dirname) { // Check if the globalPaths contain some folders with '.pnpm' in the path // If yes this means it is most likely installed with pnpm if (isInstalledWithPNPM(resolved)) { - appRootPath = getFirstPartFromNodeModules(resolved); + appRootPath = getFirstPart(resolved); if (appRootPath) { return appRootPath; @@ -102,7 +105,7 @@ module.exports = function resolve(dirname) { // If the app-root-path library isn't loaded globally, // and node_modules exists in the path, just split __dirname if (!alternateMethod) { - appRootPath = getFirstPartFromNodeModules(resolved); + appRootPath = getFirstPart(resolved); } // If the above didn't work, or this module is loaded globally, then