@@ -115,7 +115,6 @@ V8DealerFeature::V8DealerFeature(
115
115
}
116
116
117
117
void V8DealerFeature::collectOptions (std::shared_ptr<ProgramOptions> options) {
118
-
119
118
options->addSection (" javascript" , " Configure the Javascript engine" );
120
119
121
120
options->addHiddenOption (
@@ -260,10 +259,28 @@ void V8DealerFeature::prepare() {
260
259
void V8DealerFeature::start () {
261
260
if (_copyInstallation) {
262
261
copyInstallationFiles (); // will exit process if it fails
262
+ } else {
263
+ // don't copy JS files on startup
264
+ // now check if we have a js directory inside the database directory, and if it looks good
265
+ auto dbPathFeature = application_features::ApplicationServer::getFeature<DatabasePathFeature>(DatabasePathFeature::name ());
266
+ const std::string dbJSPath = FileUtils::buildFilename (dbPathFeature->directory (), " js" );
267
+ const std::string checksumFile = FileUtils::buildFilename (dbJSPath, StaticStrings::checksumFileJs);
268
+ const std::string serverPath = FileUtils::buildFilename (dbJSPath, " server" );
269
+ const std::string commonPath = FileUtils::buildFilename (dbJSPath, " common" );
270
+ if (FileUtils::isDirectory (dbJSPath) &&
271
+ FileUtils::exists (checksumFile) &&
272
+ FileUtils::isDirectory (serverPath) &&
273
+ FileUtils::isDirectory (commonPath)) {
274
+ // only load node modules from original startup path
275
+ _nodeModulesDirectory = _startupDirectory;
276
+ // js directory inside database directory looks good. now use it!
277
+ _startupDirectory = dbJSPath;
278
+ }
263
279
}
264
280
265
- LOG_TOPIC (DEBUG, Logger::V8) << " effective startup-directory is '" << _startupDirectory <<
266
- " ', effective module-directories are " << _moduleDirectories;
281
+ LOG_TOPIC (DEBUG, Logger::V8) << " effective startup-directory: " << _startupDirectory <<
282
+ " , effective module-directories: " << _moduleDirectories <<
283
+ " , node-modules-directory: " << _nodeModulesDirectory;
267
284
268
285
_startupLoader.setDirectory (_startupDirectory);
269
286
ServerState::instance ()->setJavaScriptPath (_startupDirectory);
@@ -282,7 +299,6 @@ void V8DealerFeature::start() {
282
299
if (!_appPath.empty ()) {
283
300
paths.push_back (std::string (" application '" + _appPath + " '" ));
284
301
285
-
286
302
// create app directory if it does not exist
287
303
if (!basics::FileUtils::isDirectory (_appPath)) {
288
304
std::string systemErrorStr;
@@ -383,6 +399,7 @@ void V8DealerFeature::copyInstallationFiles() {
383
399
// these do not need JavaScript support
384
400
return ;
385
401
}
402
+
386
403
// get base path from DatabasePathFeature
387
404
auto dbPathFeature = application_features::ApplicationServer::getFeature<DatabasePathFeature>();
388
405
const std::string copyJSPath = FileUtils::buildFilename (dbPathFeature->directory (), " js" );
@@ -393,6 +410,8 @@ void V8DealerFeature::copyInstallationFiles() {
393
410
}
394
411
TRI_ASSERT (!copyJSPath.empty ());
395
412
413
+ _nodeModulesDirectory = _startupDirectory;
414
+
396
415
const std::string checksumFile = FileUtils::buildFilename (_startupDirectory, StaticStrings::checksumFileJs);
397
416
const std::string copyChecksumFile = FileUtils::buildFilename (copyJSPath, StaticStrings::checksumFileJs);
398
417
@@ -450,7 +469,6 @@ void V8DealerFeature::copyInstallationFiles() {
450
469
if (normalized.substr (normalized.size () - nodeModulesPath.size (), nodeModulesPath.size ()) == nodeModulesPath ||
451
470
normalized.substr (normalized.size () - nodeModulesPathVersioned.size (), nodeModulesPathVersioned.size ()) == nodeModulesPathVersioned) {
452
471
// filter it out!
453
- _nodeModulesDirectory = _startupDirectory;
454
472
return true ;
455
473
}
456
474
}
@@ -1398,7 +1416,7 @@ V8Context* V8DealerFeature::buildContext(size_t id) {
1398
1416
directories.insert (directories.end (), _moduleDirectories.begin (),
1399
1417
_moduleDirectories.end ());
1400
1418
directories.emplace_back (_startupDirectory);
1401
- if (!_nodeModulesDirectory.empty ()) {
1419
+ if (!_nodeModulesDirectory.empty () && _nodeModulesDirectory != _startupDirectory ) {
1402
1420
directories.emplace_back (_nodeModulesDirectory);
1403
1421
}
1404
1422
0 commit comments