From 6a37218ace6758b39949c3c44a5e3bcb90777cef Mon Sep 17 00:00:00 2001 From: Hristo Deshev Date: Mon, 14 Dec 2015 12:19:17 +0200 Subject: [PATCH] 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. --- file-system/file-system.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/file-system/file-system.ts b/file-system/file-system.ts index f9ebd41b6..f1f27fb60 100644 --- a/file-system/file-system.ts +++ b/file-system/file-system.ts @@ -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(); -} \ No newline at end of file +}