summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2018-10-22 23:43:32 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-10-25 14:53:44 +0100
commite9270af4296ce2af292059617a717e42fc17425c (patch)
tree21efdf44ac3fec4ff49bc3f84e63312e300d4579 /meta
parent1c03ada82de69a7f04ebb191fa560c02a2d29ea7 (diff)
downloadpoky-e9270af4296ce2af292059617a717e42fc17425c.tar.gz
npm: change install directory to upstream default
The node binary searches for packages in a number of locations, the last of which is $PREFIX/lib/node (here: /usr/lib/node) from the list of GLOBAL_FOLDERS [1]. So change the installation directory for all packages depending on npm.bbclass to that location. This removes the need to define the NODE_PATH variable to the non-standard /usr/lib/node_modules value. While the Tips for Package Managers [2] discusses installing packages to /usr/lib/node_modules/<name>/<version>, this has several drawbacks: * it does not work for the REPL as mentioned in the documentation * it also does not work for any code _not_ installed as a global package under /usr/lib/node_modules (e.g. /usr/share/foo.js will not find any packages below /usr/lib) * using the non-default location and then having to set NODE_PATH barely saves any time: there are only two file-system lookups (to the legacy $HOME/.node_modules and $HOME/.node_libraries) directories before the library would be found And the suggestion was made in the context of deduping the node_modules tree by installing all packages in a flat hierarchy and using symlinks to the correct version of each dependency. This is not what OpenEmbedded does, so none of those benefits (deduping, cleaner packages) are being had by shifting the installation directory to /usr/lib/node_modules. The choice of a "proper" installation path is not helped by npm installing to /usr/lib/node_modules if asked to install globally. Still, using the location expected by nodejs (/usr/lib/node) seems the right choice. [1]: https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders [2]: https://nodejs.org/api/modules.html#modules_addenda_package_manager_tips (From OE-Core rev: c73bc49038effd64f2c2542c1f4da8b6a4168477) Signed-off-by: Olaf Mandel <o.mandel@menlosystems.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/classes/npm.bbclass11
1 files changed, 6 insertions, 5 deletions
diff --git a/meta/classes/npm.bbclass b/meta/classes/npm.bbclass
index d5ff0c6d57..30febcffb2 100644
--- a/meta/classes/npm.bbclass
+++ b/meta/classes/npm.bbclass
@@ -10,7 +10,7 @@ def node_pkgname(d):
10 10
11NPMPN ?= "${@node_pkgname(d)}" 11NPMPN ?= "${@node_pkgname(d)}"
12 12
13NPM_INSTALLDIR = "${D}${libdir}/node/${NPMPN}" 13NPM_INSTALLDIR = "${libdir}/node/${NPMPN}"
14 14
15# function maps arch names to npm arch names 15# function maps arch names to npm arch names
16def npm_oe_arch_map(target_arch, d): 16def npm_oe_arch_map(target_arch, d):
@@ -52,9 +52,10 @@ npm_do_install() {
52 # changing the home directory to the working directory, the .npmrc will 52 # changing the home directory to the working directory, the .npmrc will
53 # be created in this directory 53 # be created in this directory
54 export HOME=${WORKDIR} 54 export HOME=${WORKDIR}
55 mkdir -p ${NPM_INSTALLDIR}/ 55 mkdir -p ${D}${libdir}/node_modules
56 npm pack . 56 npm pack .
57 npm install --prefix ${D}${prefix} -g --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry ${NPMPN}-${PV}.tgz 57 npm install --prefix ${D}${prefix} -g --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry ${NPMPN}-${PV}.tgz
58 mv ${D}${libdir}/node_modules ${D}${libdir}/node
58 if [ -d ${D}${prefix}/etc ] ; then 59 if [ -d ${D}${prefix}/etc ] ; then
59 # This will be empty 60 # This will be empty
60 rmdir ${D}${prefix}/etc 61 rmdir ${D}${prefix}/etc
@@ -62,13 +63,13 @@ npm_do_install() {
62} 63}
63 64
64python populate_packages_prepend () { 65python populate_packages_prepend () {
65 instdir = d.expand('${D}${libdir}/node_modules/${NPMPN}') 66 instdir = d.expand('${D}${NPM_INSTALLDIR}')
66 extrapackages = oe.package.npm_split_package_dirs(instdir) 67 extrapackages = oe.package.npm_split_package_dirs(instdir)
67 pkgnames = extrapackages.keys() 68 pkgnames = extrapackages.keys()
68 d.prependVar('PACKAGES', '%s ' % ' '.join(pkgnames)) 69 d.prependVar('PACKAGES', '%s ' % ' '.join(pkgnames))
69 for pkgname in pkgnames: 70 for pkgname in pkgnames:
70 pkgrelpath, pdata = extrapackages[pkgname] 71 pkgrelpath, pdata = extrapackages[pkgname]
71 pkgpath = '${libdir}/node_modules/${NPMPN}/' + pkgrelpath 72 pkgpath = '${NPM_INSTALLDIR}/' + pkgrelpath
72 # package names can't have underscores but npm packages sometimes use them 73 # package names can't have underscores but npm packages sometimes use them
73 oe_pkg_name = pkgname.replace('_', '-') 74 oe_pkg_name = pkgname.replace('_', '-')
74 expanded_pkgname = d.expand(oe_pkg_name) 75 expanded_pkgname = d.expand(oe_pkg_name)
@@ -84,7 +85,7 @@ python populate_packages_prepend () {
84} 85}
85 86
86FILES_${PN} += " \ 87FILES_${PN} += " \
87 ${libdir}/node_modules/${NPMPN} \ 88 ${NPM_INSTALLDIR} \
88" 89"
89 90
90EXPORT_FUNCTIONS do_compile do_install 91EXPORT_FUNCTIONS do_compile do_install