It actually makes way more sense for __driname to be exectuable dir rather

than the cwd.
This commit is contained in:
Lorenz Gardner
2014-12-18 18:02:48 -06:00
parent e7b28d0aa5
commit 7b9f235715
2 changed files with 4 additions and 9 deletions
+2 -7
View File
@@ -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({
});
````
+2 -2
View File
@@ -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;
}