app-root-path
Advanced tools
Comparing version
@@ -110,4 +110,11 @@ 'use strict'; | ||
// resort to require.main.filename (See http://nodejs.org/api/modules.html) | ||
if (alternateMethod || null == appRootPath) { | ||
appRootPath = path.dirname(requireFunction.main.filename); | ||
if ((alternateMethod || null == appRootPath)) { | ||
if (requireFunction.main) { | ||
appRootPath = path.dirname(requireFunction.main.filename); | ||
} else { | ||
// This is the case when app-root-path is bundle'd to a commonjs2 format and is being called from an esm file. | ||
// In those cases require.main is undefined (See https://nodejs.org/api/modules.html#accessing-the-main-module) | ||
// At that point we can only get the root from looking at the callee | ||
appRootPath = path.dirname(process.argv[1]); | ||
} | ||
} | ||
@@ -114,0 +121,0 @@ |
{ | ||
"name": "app-root-path", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Determine an app's root path from anywhere inside the app", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -93,2 +93,6 @@ # App Root Path Module | ||
### 3.1.0 | ||
- Added TypeScript types | ||
- Added fallback for when `require.main` is missing (ESM imports) | ||
### 3.0.0 | ||
@@ -95,0 +99,0 @@ - Improved Yarn Plug'n'Play support |
154
10.79%160
2.56%14962
-26.29%