Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] add support for esbuild #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/resolve.js
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