1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
Description: Multiarch search path, arch triplet, DFHS path for modules
Author: "Bastien ROUCARIÈS" <roucaries.bastien@gmail.com>
Last-Update: 2018-09-30
Forwarded: https://github.com/nodejs/node/issues/22745
Reviewed-By: Xavier Guimard <yadd@debian.org>
Last-Update: 2020-03-04
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -1723,6 +1723,7 @@
Module._initPaths = function() {
const homeDir = isWindows ? process.env.USERPROFILE : safeGetenv('HOME');
const nodePath = isWindows ? process.env.NODE_PATH : safeGetenv('NODE_PATH');
+ const relativePaths = process.config?.variables?.node_relative_path;
// process.execPath is $PREFIX/bin/node except on Windows where it is
// $PREFIX\node.exe where $PREFIX is the root of the Node.js installation.
@@ -1730,7 +1731,18 @@
path.resolve(process.execPath, '..') :
path.resolve(process.execPath, '..', '..');
- const paths = [path.resolve(prefixDir, 'lib', 'node')];
+ const postDirs = [];
+ if (relativePaths) {
+ relativePaths.split(path.delimiter).map(path => {
+ if (path) postDirs.push(path);
+ });
+ } else {
+ postDirs.push(path.join('lib', 'node'));
+ }
+
+ const paths = postDirs.map(postDir => {
+ return path.resolve(prefixDir, postDir);
+ });
if (homeDir) {
ArrayPrototypeUnshift(paths, path.resolve(homeDir, '.node_libraries'));
--- a/configure.py
+++ b/configure.py
@@ -96,6 +96,12 @@
default=None,
help='Build node with code coverage enabled')
+parser.add_argument('--arch-triplet',
+ action='store',
+ dest='arch_triplet',
+ default=None,
+ help='arch triplet used by distro')
+
parser.add_argument('--debug',
action='store_true',
dest='debug',
@@ -155,6 +161,13 @@
default=None,
help='add gdb support')
+parser.add_argument('--node-relative-path',
+ action='store',
+ dest='node_relative_path',
+ default=None,
+ help='Node path(s) used by require, resolved relative to prefix dir.')
+
+
parser.add_argument('--no-ifaddrs',
action='store_true',
dest='no_ifaddrs',
@@ -1562,6 +1575,17 @@
version = getnapibuildversion.get_napi_version()
output['variables']['napi_build_version'] = version
+def configure_debian(output):
+ if options.arch_triplet:
+ output['variables']['arch_triplet'] = options.arch_triplet
+ else:
+ output['variables']['arch_triplet'] = 'unknown-unknown-unknown'
+
+ if options.node_relative_path:
+ output['variables']['node_relative_path'] = options.node_relative_path
+ else:
+ output['variables']['node_relative_path']= ''
+
def configure_library(lib, output, pkgname=None):
shared_lib = 'shared_' + lib
output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
@@ -2145,6 +2169,7 @@
configure_node(output)
configure_node_lib_files(output)
configure_napi(output)
+configure_debian(output)
configure_library('zlib', output)
configure_library('http_parser', output)
configure_library('libuv', output)
--- a/test/parallel/test-module-loading-globalpaths.js
+++ b/test/parallel/test-module-loading-globalpaths.js
@@ -71,12 +71,12 @@
env.HOME = env.USERPROFILE = bothHomeDir;
runTest('$HOME/.node_modules', env);
- // Test module in $PREFIX/lib/node.
- // Write module into $PREFIX/lib/node.
- const expectedString = '$PREFIX/lib/node';
- const prefixLibPath = path.join(prefixPath, 'lib');
+ // Test module in $PREFIX/share/node.
+ // Write module into $PREFIX/share/node.
+ const expectedString = '$PREFIX/share/nodejs';
+ const prefixLibPath = path.join(prefixPath, 'share');
fs.mkdirSync(prefixLibPath);
- const prefixLibNodePath = path.join(prefixLibPath, 'node');
+ const prefixLibNodePath = path.join(prefixLibPath, 'nodejs');
fs.mkdirSync(prefixLibNodePath);
const pkgPath = path.join(prefixLibNodePath, `${pkgName}.js`);
fs.writeFileSync(pkgPath, `exports.string = '${expectedString}';`);
|