Package: nodejs
Version: 10.4.0~dfsg-2
Severity: important
tags: patch

Hi,

In order to get search path in multiarch path and in /usr/local I use the 
following patch

/usr/local part will allow to satisfy policy 9.1.2 and the other part to get 
node package multiarch like perl or python.

I think this patch could be upstreamed if needed

search order is :
usr/local/lib/$(DEB_HOST_MULTIARCH)/nodejs:/usr/local/share/nodejs:/usr/local/lib/nodejs:/usr/lib/$(DEB_HOST_MULTIARCH)/nodejs:/usr/share/nodejs:/usr/lib/nodejs

note that /usr/lib/nodejs will tested last.

You could check the patch by doing require('os').constants and see 
 ARCH_TRIPLET: 'x86_64-linux-gnu',
  GLOBAL_NODE_PATH:
   
'/usr/local/lib/x86_64-linux-gnu/nodejs:/usr/local/share/nodejs:/usr/local/lib/nodejs:/usr/lib/x86_64-linux-gnu/nodejs:/usr/share/nodejs:/usr/lib/nodejs',

then checking the load path by:
require('module')
and see the array globalPaths:
lobalPaths:
   [ '/home/bastien/.node_modules',
     '/home/bastien/.node_libraries',
     '/usr/local/lib/x86_64-linux-gnu/nodejs',
     '/usr/local/share/nodejs',
     '/usr/local/lib/nodejs',
     '/usr/lib/x86_64-linux-gnu/nodejs',
     '/usr/share/nodejs',
     '/usr/lib/nodejs' ],

I have also added arch triplet because some module will need it.

Bastien

diff --git a/debian/patches/pass-arch-dir-to-constants 
b/debian/patches/pass-arch-dir-to-constants
new file mode 100644
index 00000000..b12f0f4e
--- /dev/null
+++ b/debian/patches/pass-arch-dir-to-constants
@@ -0,0 +1,51 @@
+Index: nodejs/src/node_constants.cc
+===================================================================
+--- nodejs.orig/src/node_constants.cc
++++ nodejs/src/node_constants.cc
+@@ -1309,6 +1309,15 @@ void DefineConstants(v8::Isolate* isolat
+   NODE_DEFINE_CONSTANT(fs_constants, UV_FS_COPYFILE_FICLONE);
+   NODE_DEFINE_CONSTANT(fs_constants, UV_FS_COPYFILE_FICLONE_FORCE);
+ 
++  // Define arch triplet
++#ifdef DEBIAN_ARCH_TRIPLET
++  NODE_DEFINE_STRING_CONSTANT(os_constants, "ARCH_TRIPLET", 
DEBIAN_ARCH_TRIPLET);
++#endif
++
++#ifdef DEBIAN_GLOBAL_NODE_PATH
++  NODE_DEFINE_STRING_CONSTANT(os_constants, "GLOBAL_NODE_PATH", 
DEBIAN_GLOBAL_NODE_PATH);
++#endif
++
+   os_constants->Set(OneByteString(isolate, "dlopen"), dlopen_constants);
+   os_constants->Set(OneByteString(isolate, "errno"), err_constants);
+   os_constants->Set(OneByteString(isolate, "signals"), sig_constants);
+Index: nodejs/lib/internal/modules/cjs/loader.js
+===================================================================
+--- nodejs.orig/lib/internal/modules/cjs/loader.js
++++ nodejs/lib/internal/modules/cjs/loader.js
+@@ -26,6 +26,7 @@ const util = require('util');
+ const vm = require('vm');
+ const assert = require('assert').ok;
+ const fs = require('fs');
++const GLOBAL_NODE_PATH = (require("os").constants).GLOBAL_NODE_PATH;
+ const internalFS = require('internal/fs/utils');
+ const path = require('path');
+ const {
+@@ -768,7 +769,17 @@ Module._initPaths = function() {
+   } else {
+     prefixDir = path.resolve(process.execPath, '..', '..');
+   }
+-  var paths = [path.resolve(prefixDir, 'lib', 'nodejs')];
++  var paths = [];
++  // prefer /usr/local over /usr and arch over all
++
++  if (GLOBAL_NODE_PATH) {
++    paths = GLOBAL_NODE_PATH.split(path.delimiter).filter(function 
pathsFilterCB(path) {
++      return !!path;
++    }).concat(paths);
++  }
++  else {
++    paths.push(path.resolve('/usr','lib','nodejs'));
++  }
+ 
+   if (homeDir) {
+     paths.unshift(path.resolve(homeDir, '.node_libraries'));
diff --git a/debian/patches/series b/debian/patches/series
index cd794b90..b35d3b3e 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -8,3 +8,4 @@ build-doc-using-js-yaml.patch
 test_ci_buildd.patch
 fix_disable_cctest.patch
 benchmark_without_alice.patch
+pass-arch-dir-to-constants
diff --git a/debian/rules b/debian/rules
index a9014f81..c0f3a53b 100755
--- a/debian/rules
+++ b/debian/rules
@@ -188,6 +188,13 @@ CPPFLAGS+=-fPIC
 CFLAGS+=-g
 CPPFLAGS+=-g
 CXXFLAGS+=$(CPPFLAGS)
+
+GLOBAL_NODE_PATH= 
/usr/local/lib/$(DEB_HOST_MULTIARCH)/nodejs:/usr/local/share/nodejs:/usr/local/lib/nodejs
+GLOBAL_NODE_PATH:= 
$(GLOBAL_NODE_PATH):/usr/lib/$(DEB_HOST_MULTIARCH)/nodejs:/usr/share/nodejs:/usr/lib/nodejs
+
+CFLAGS+=-DDEBIAN_ARCH_TRIPLET=\"$(DEB_HOST_MULTIARCH)\" 
-DDEBIAN_GLOBAL_NODE_PATH=\"$(GLOBAL_NODE_PATH)\" 
+CPPFLAGS+=-DDEBIAN_ARCH_TRIPLET=\"$(DEB_HOST_MULTIARCH)\" 
-DDEBIAN_GLOBAL_NODE_PATH=\"$(GLOBAL_NODE_PATH)\"
+CXXFLAGS+=-DDEBIAN_ARCH_TRIPLET=\"$(DEB_HOST_MULTIARCH)\" 
-DDEBIAN_GLOBAL_NODE_PATH=\"$(GLOBAL_NODE_PATH)\"
 export CPPFLAGS
 export CXXFLAGS
 export CFLAGS

Attachment: signature.asc
Description: This is a digitally signed message part.

-- 
Pkg-javascript-devel mailing list
Pkg-javascript-devel@alioth-lists.debian.net
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/pkg-javascript-devel

Reply via email to