Skip to content

Commit

Permalink
fix: Better support for webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
inxilpro committed Mar 25, 2019
1 parent 59352ec commit 1202623
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -90,6 +90,9 @@ you want. `app-root-path` is aware of this edge-case and will strip the `/bin` a

## Change Log

### 2.2.1
- Better handling of webpack

### 2.2.0
- Added support for Yarn Plug'n'Play
- Adjusted browser-shim to address webpack warnings
Expand Down
18 changes: 13 additions & 5 deletions lib/resolve.js
Expand Up @@ -18,6 +18,11 @@ var npmGlobalModuleDir = path.resolve(npmGlobalPrefix, 'lib', 'node_modules');
// Save OS-specific path separator
var sep = path.sep;

// If we're in webpack, force it to use the original require() method
var requireFunction = ("function" === typeof __webpack_require__ || "function" === typeof __non_webpack_require__)
? __non_webpack_require__
: require;

// Resolver
module.exports = function resolve(dirname) {
// Check for environmental variable
Expand All @@ -27,15 +32,18 @@ module.exports = function resolve(dirname) {

// Defer to Yarn Plug'n'Play if enabled
if (process.versions.pnp) {
var pnp = require('pnpapi');
return pnp.getPackageInformation(pnp.topLevel).packageLocation;
try {
var pnp = requireFunction('pnpapi');
return pnp.getPackageInformation(pnp.topLevel).packageLocation;
} catch (e) {}
}

// Defer to main process in electron renderer
if ('undefined' !== typeof window && window.process && 'renderer' === window.process.type) {
var electron = 'electron';
var remote = require(electron).remote;
return remote.require('app-root-path').path;
try {
var remote = requireFunction('electron').remote;
return remote.require('app-root-path').path;
} catch (e) {}
}

// Defer to AWS Lambda when executing there
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "app-root-path",
"version": "2.2.0",
"version": "2.2.1",
"description": "Determine an app's root path from anywhere inside the app",
"main": "index.js",
"browser": "browser-shim.js",
Expand Down

0 comments on commit 1202623

Please sign in to comment.