From 43be1e8a37330b9109aee47897830e14644dc0b4 Mon Sep 17 00:00:00 2001 From: Enrico Giordani Date: Tue, 20 Feb 2018 14:55:42 +0100 Subject: [PATCH] plugin: set NODE_PATH for 'nodejs.startWithScript' --- .../com/janeasystems/cdvnodejsmobile/NodeJS.java | 3 +-- src/ios/CDVNodeJS.mm | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/android/java/com/janeasystems/cdvnodejsmobile/NodeJS.java b/src/android/java/com/janeasystems/cdvnodejsmobile/NodeJS.java index 45f43c6..ff554e7 100644 --- a/src/android/java/com/janeasystems/cdvnodejsmobile/NodeJS.java +++ b/src/android/java/com/janeasystems/cdvnodejsmobile/NodeJS.java @@ -69,7 +69,7 @@ public void pluginInitialize() { NodeJS.filesDir = activity.getBaseContext().getFilesDir().getAbsolutePath(); NodeJS.nodeAppRootAbsolutePath = filesDir + "/" + NodeJS.PROJECT_ROOT; - NodeJS.nodePath = filesDir + "/" + NodeJS.BUILTIN_MODULES; + NodeJS.nodePath = NodeJS.nodeAppRootAbsolutePath + ":" + filesDir + "/" + NodeJS.BUILTIN_MODULES; NodeJS.trashDir = filesDir + "/" + NodeJS.TRASH_DIR; NodeJS.nativeAssetsPath = BUILTIN_NATIVE_ASSETS_PREFIX + getCurrentABIName(); @@ -201,7 +201,6 @@ private boolean startEngineWithScript(final String scriptBody, final JSONObject final boolean redirectOutputToLogcat = getOptionRedirectOutputToLogcat(startOptions); final String scriptBodyToRun = new String(scriptBody); - Log.v(LOGTAG, "Script absolute path: " + scriptBody); new Thread(new Runnable() { @Override public void run() { diff --git a/src/ios/CDVNodeJS.mm b/src/ios/CDVNodeJS.mm index 3f13871..c29ff49 100644 --- a/src/ios/CDVNodeJS.mm +++ b/src/ios/CDVNodeJS.mm @@ -42,14 +42,14 @@ - (void) pluginInitialize { NSString* const NODE_PATH = @"NODE_PATH"; NSString* const BUILTIN_MODULES = @"/www/nodejs-mobile-cordova-assets/builtin_modules"; - NSString* const NODE_MODULES = @"/www/nodejs-project/node_modules"; + NSString* const NODE_ROOT = @"/www/nodejs-project/"; // The 'onAppTerminate', 'onReset' and 'onMemoryWarning' events are already // registered in the super class while 'onPause' and 'onResume' are not. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onPause) name:UIApplicationDidEnterBackgroundNotification object:nil]; - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResume) name:UIApplicationWillEnterForegroundNotification object:nil]; @@ -59,8 +59,8 @@ - (void) pluginInitialize { NSString* nodePath = [[NSProcessInfo processInfo] environment][NODE_PATH]; NSString* appPath = [[NSBundle mainBundle] bundlePath]; NSString* builtinModulesPath = [appPath stringByAppendingString:BUILTIN_MODULES]; - NSString* nodeModulesPath = [appPath stringByAppendingString:NODE_MODULES]; - + NSString* nodeRootPath = [appPath stringByAppendingString:NODE_ROOT]; + if (nodePath == NULL) { nodePath = builtinModulesPath; } else { @@ -68,8 +68,8 @@ - (void) pluginInitialize { nodePath = [nodePath stringByAppendingString:builtinModulesPath]; } nodePath = [nodePath stringByAppendingString:@":"]; - nodePath = [nodePath stringByAppendingString:nodeModulesPath]; - + nodePath = [nodePath stringByAppendingString:nodeRootPath]; + setenv([NODE_PATH UTF8String], (const char*)[nodePath UTF8String], 1); activeInstance = self;