Skip to content

Commit

Permalink
plugin: set NODE_PATH for 'nodejs.startWithScript'
Browse files Browse the repository at this point in the history
  • Loading branch information
enricogior authored Feb 20, 2018
1 parent c159d1b commit 43be1e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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() {
Expand Down
12 changes: 6 additions & 6 deletions src/ios/CDVNodeJS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -59,17 +59,17 @@ - (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 {
nodePath = [nodePath stringByAppendingString:@":"];
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;
Expand Down

0 comments on commit 43be1e8

Please sign in to comment.