1'use strict'; 2const common = require('../common'); 3const path = require('path'); 4 5const kNodeShared = Boolean(process.config.variables.node_shared); 6const kShlibSuffix = process.config.variables.shlib_suffix; 7const kExecPath = path.dirname(process.execPath); 8 9// If node executable is linked to shared lib, need to take care about the 10// shared lib path. 11function addLibraryPath(env) { 12 if (!kNodeShared) { 13 return; 14 } 15 16 env = env || process.env; 17 18 env.LD_LIBRARY_PATH = 19 (env.LD_LIBRARY_PATH ? env.LD_LIBRARY_PATH + path.delimiter : '') + 20 kExecPath; 21 // For AIX. 22 env.LIBPATH = 23 (env.LIBPATH ? env.LIBPATH + path.delimiter : '') + 24 kExecPath; 25 // For Mac OSX. 26 env.DYLD_LIBRARY_PATH = 27 (env.DYLD_LIBRARY_PATH ? env.DYLD_LIBRARY_PATH + path.delimiter : '') + 28 kExecPath; 29 // For Windows. 30 env.PATH = (env.PATH ? env.PATH + path.delimiter : '') + kExecPath; 31} 32 33// Get the full path of shared lib. 34function getSharedLibPath() { 35 if (common.isWindows) { 36 return path.join(kExecPath, 'node.dll'); 37 } 38 return path.join(kExecPath, `libnode.${kShlibSuffix}`); 39} 40 41// Get the binary path of stack frames. 42function getBinaryPath() { 43 return kNodeShared ? getSharedLibPath() : process.execPath; 44} 45 46module.exports = { 47 addLibraryPath, 48 getBinaryPath, 49 getSharedLibPath 50}; 51