summaryrefslogtreecommitdiffstats
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-23 11:33:42 +0100
commitc73bc49038effd64f2c2542c1f4da8b6a4168477 (patch)
tree91fa6e8dadc1be078635a2f79373aa8c1e4023aa
parent5fface331c46b809c10b4f3d65904534d6933896 (diff)
downloadopenembedded-core-contrib-c73bc49038effd64f2c2542c1f4da8b6a4168477.tar.gz
openembedded-core-contrib-c73bc49038effd64f2c2542c1f4da8b6a4168477.tar.bz2
openembedded-core-contrib-c73bc49038effd64f2c2542c1f4da8b6a4168477.zip
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 Signed-off-by: Olaf Mandel <o.mandel@menlosystems.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-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):
NPMPN ?= "${@node_pkgname(d)}"
-NPM_INSTALLDIR = "${D}${libdir}/node/${NPMPN}"
+NPM_INSTALLDIR = "${libdir}/node/${NPMPN}"
# function maps arch names to npm arch names
def npm_oe_arch_map(target_arch, d):
@@ -52,9 +52,10 @@ npm_do_install() {
# changing the home directory to the working directory, the .npmrc will
# be created in this directory
export HOME=${WORKDIR}
- mkdir -p ${NPM_INSTALLDIR}/
+ mkdir -p ${D}${libdir}/node_modules
npm pack .
npm install --prefix ${D}${prefix} -g --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry ${NPMPN}-${PV}.tgz
+ mv ${D}${libdir}/node_modules ${D}${libdir}/node
if [ -d ${D}${prefix}/etc ] ; then
# This will be empty
rmdir ${D}${prefix}/etc
@@ -62,13 +63,13 @@ npm_do_install() {
}
python populate_packages_prepend () {
- instdir = d.expand('${D}${libdir}/node_modules/${NPMPN}')
+ instdir = d.expand('${D}${NPM_INSTALLDIR}')
extrapackages = oe.package.npm_split_package_dirs(instdir)
pkgnames = extrapackages.keys()
d.prependVar('PACKAGES', '%s ' % ' '.join(pkgnames))
for pkgname in pkgnames:
pkgrelpath, pdata = extrapackages[pkgname]
- pkgpath = '${libdir}/node_modules/${NPMPN}/' + pkgrelpath
+ pkgpath = '${NPM_INSTALLDIR}/' + pkgrelpath
# package names can't have underscores but npm packages sometimes use them
oe_pkg_name = pkgname.replace('_', '-')
expanded_pkgname = d.expand(oe_pkg_name)
@@ -84,7 +85,7 @@ python populate_packages_prepend () {
}
FILES_${PN} += " \
- ${libdir}/node_modules/${NPMPN} \
+ ${NPM_INSTALLDIR} \
"
EXPORT_FUNCTIONS do_compile do_install