8000 fix path to node_modules after copying files (#7086) · botnick/arangodb@011d264 · GitHub
[go: up one dir, main page]

Skip to content

Commit 011d264

Browse files
authored
fix path to node_modules after copying files (arangodb#7086)
1 parent 937a7ee commit 011d264

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

arangod/V8Server/V8DealerFeature.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ V8DealerFeature::V8DealerFeature(
115115
}
116116

117117
void V8DealerFeature::collectOptions(std::shared_ptr<ProgramOptions> options) {
118-
119118
options->addSection("javascript", "Configure the Javascript engine");
120119

121120
options->addHiddenOption(
@@ -260,10 +259,28 @@ void V8DealerFeature::prepare() {
260259
void V8DealerFeature::start() {
261260
if (_copyInstallation) {
262261
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+
}
263279
}
264280

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;
267284

268285
_startupLoader.setDirectory(_startupDirectory);
269286
ServerState::instance()->setJavaScriptPath(_startupDirectory);
@@ -282,7 +299,6 @@ void V8DealerFeature::start() {
282299
if (!_appPath.empty()) {
283300
paths.push_back(std::string("application '" + _appPath + "'"));
284301

285-
286302
// create app directory if it does not exist
287303
if (!basics::FileUtils::isDirectory(_appPath)) {
288304
std::string systemErrorStr;
@@ -383,6 +399,7 @@ void V8DealerFeature::copyInstallationFiles() {
383399
// these do not need JavaScript support
384400
return;
385401
}
402+
386403
// get base path from DatabasePathFeature
387404
auto dbPathFeature = application_features::ApplicationServer::getFeature<DatabasePathFeature>();
388405
const std::string copyJSPath = FileUtils::buildFilename(dbPathFeature->directory(), "js");
@@ -393,6 +410,8 @@ void V8DealerFeature::copyInstallationFiles() {
393410
}
394411
TRI_ASSERT(!copyJSPath.empty());
395412

413+
_nodeModulesDirectory = _startupDirectory;
414+
396415
const std::string checksumFile = FileUtils::buildFilename(_startupDirectory, StaticStrings::checksumFileJs);
397416
const std::string copyChecksumFile = FileUtils::buildFilename(copyJSPath, StaticStrings::checksumFileJs);
398417

@@ -450,7 +469,6 @@ void V8DealerFeature::copyInstallationFiles() {
450469
if (normalized.substr(normalized.size() - nodeModulesPath.size(), nodeModulesPath.size()) == nodeModulesPath ||
451470
normalized.substr(normalized.size() - nodeModulesPathVersioned.size(), nodeModulesPathVersioned.size()) == nodeModulesPathVersioned) {
452471
// filter it out!
453-
_nodeModulesDirectory = _startupDirectory;
454472
return true;
455473
}
456474
}
@@ -1398,7 +1416,7 @@ V8Context* V8DealerFeature::buildContext(size_t id) {
13981416
directories.insert(directories.end(), _moduleDirectories.begin(),
13991417
_moduleDirectories.end());
14001418
directories.emplace_back(_startupDirectory);
1401-
if (!_nodeModulesDirectory.empty()) {
1419+
if (!_nodeModulesDirectory.empty() && _nodeModulesDirectory != _startupDirectory) {
14021420
directories.emplace_back(_nodeModulesDirectory);
14031421
}
14041422

arangosh/Shell/V8ShellFeature.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ void V8ShellFeature::copyInstallationFiles() {
241241

242242
LOG_TOPIC(DEBUG, Logger::V8) << "Copying JS installation files from '" << _startupDirectory << "' to '" << _copyDirectory << "'";
243243
int res = TRI_ERROR_NO_ERROR;
244+
245+
_nodeModulesDirectory = _startupDirectory;
244246

245247
if (FileUtils::exists(_copyDirectory)) {
246248
res = TRI_RemoveDirectory(_copyDirectory.c_str());
@@ -270,7 +272,6 @@ void V8ShellFeature::copyInstallationFiles() {
270272
if (normalized.substr(normalized.size() - nodeModulesPath.size(), nodeModulesPath.size()) == nodeModulesPath ||
271273
normalized.substr(normalized.size() - nodeModulesPathVersioned.size(), nodeModulesPathVersioned.size()) == nodeModulesPathVersioned) {
272274
// filter it out!
273-
_nodeModulesDirectory = _startupDirectory;
274275
return true;
275276
}
276277
}

0 commit comments

Comments
 (0)
0