Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down