From 7b9f2357157afa2799af368b01564b1f8b730f7d Mon Sep 17 00:00:00 2001 From: Lorenz Gardner Date: Thu, 18 Dec 2014 18:02:48 -0600 Subject: [PATCH] It actually makes way more sense for __driname to be exectuable dir rather than the cwd. --- README.md | 9 ++------- lib/bundle.js | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ca13477..68eeea3 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Using these two techniques you can change your application code so mdoules are n ### __dirname -Once the module is budnled it is part of the executable. __dirname is therefore the CWD (current working dir) of the executable when run. Thus if you put resources on a realtive path from the cwd of the executable (in most cases the path to the executable) your app will be able to access them. +Once the module is budnled it is part of the executable. __dirname is therefore the executable dir (process.execPath). Thus if you put resources on a realtive path from the the executable your app will be able to access them. If you had a data file at /dev/myNodeApp/stateManager/handler/data/some.csv and a file at /dev/myNodeApp/stateManager/handler/loader.js @@ -80,7 +80,7 @@ and a file at /dev/myNodeApp/stateManager/handler/loader.js ``` you would need to deploy some.csv in a sub dir data/ along side your executable -There are potential use cases for __dirname where the CWD is not the correct substitution, and could result in a silent error (possibly even in a dependciey that you are unaware of). +There are potential use cases for __dirname where the executable path is not the correct substitution, and could result in a silent error (possibly even in a dependciey that you are unaware of). Note: __filename will be 'undefined' @@ -131,8 +131,3 @@ nexe.compile({ }); ```` - - - - - diff --git a/lib/bundle.js b/lib/bundle.js index 4539db8..ba9da5a 100644 --- a/lib/bundle.js +++ b/lib/bundle.js @@ -107,7 +107,7 @@ function bundle (input, complete) { var loader = function (deps) { var darr = []; - var cwd = process.cwd(); + var dir = global.require("path").dirname(process.execPath); for (var key in deps) { darr.push(deps[key]); @@ -121,7 +121,7 @@ var loader = function (deps) { var rdep = deps[dep[2][path]]; var exports = rdep ? rdep.module ? rdep.module.exports : initModule(rdep) : global.require(path); return exports; - }, dep.module, dep.module.exports, cwd); + }, dep.module, dep.module.exports, dir); return dep.module.exports; }