Make knownFolders.currentApp default to __dirname.

In cases where we can't find a `tns_modules` subfolder (webpack, etc),
assume the current dir is the app dir.
This commit is contained in:
Hristo Deshev
2015-12-14 12:19:17 +02:00
parent fa264d9374
commit 6a37218ace

View File

@@ -442,10 +442,17 @@ export module knownFolders {
export var currentApp = function (): Folder {
if (!_app) {
var currentDir = __dirname;
var path = currentDir.substring(0, currentDir.indexOf("/tns_modules"));
const currentDir = __dirname;
const tnsModulesIndex = currentDir.indexOf("/tns_modules");
// Module not hosted in ~/tns_modules when bundled. Use current dir.
let appPath = currentDir;
if (tnsModulesIndex !== -1) {
// Strip part after tns_modules to obtain app root
appPath = currentDir.substring(0, tnsModulesIndex);
}
_app = new Folder();
_app[pathProperty] = path;
_app[pathProperty] = appPath;
_app[isKnownProperty] = true;
}
@@ -465,4 +472,4 @@ export module path {
}
export var separator = getFileAccess().getPathSeparator();
}
}