blob: a69bedbb28630f125a6ddcfd5289a6b66b136e24 [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001DEPENDS_prepend = "nodejs-native "
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002RDEPENDS_${PN}_prepend = "nodejs "
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05003S = "${WORKDIR}/npmpkg"
4
5NPM_INSTALLDIR = "${D}${libdir}/node_modules/${PN}"
6
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007# function maps arch names to npm arch names
8def npm_oe_arch_map(target_arch, d):
9 import re
10 if re.match('p(pc|owerpc)(|64)', target_arch): return 'ppc'
11 elif re.match('i.86$', target_arch): return 'ia32'
12 elif re.match('x86_64$', target_arch): return 'x64'
13 elif re.match('arm64$', target_arch): return 'arm'
14 return target_arch
15
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016NPM_ARCH ?= "${@npm_oe_arch_map(d.getVar('TARGET_ARCH'), d)}"
17NPM_INSTALL_DEV = "0"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060018
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050019npm_do_compile() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -060020 # Copy in any additionally fetched modules
21 if [ -d ${WORKDIR}/node_modules ] ; then
22 cp -a ${WORKDIR}/node_modules ${S}/
23 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050024 # changing the home directory to the working directory, the .npmrc will
25 # be created in this directory
26 export HOME=${WORKDIR}
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027 if [ "${NPM_INSTALL_DEV}" = "1" ]; then
28 npm config set dev true
29 else
30 npm config set dev false
31 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050032 npm set cache ${WORKDIR}/npm_cache
33 # clear cache before every build
34 npm cache clear
35 # Install pkg into ${S} without going to the registry
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036 if [ "${NPM_INSTALL_DEV}" = "1" ]; then
37 npm --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --no-registry install
38 else
39 npm --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry install
40 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050041}
42
43npm_do_install() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050044 # changing the home directory to the working directory, the .npmrc will
45 # be created in this directory
46 export HOME=${WORKDIR}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050047 mkdir -p ${NPM_INSTALLDIR}/
Brad Bishop6e60e8b2018-02-01 10:27:11 -050048 npm install --prefix ${D}${prefix} -g --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry
49 if [ -d ${D}${prefix}/etc ] ; then
50 # This will be empty
51 rmdir ${D}${prefix}/etc
52 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050053}
54
55python populate_packages_prepend () {
56 instdir = d.expand('${D}${libdir}/node_modules/${PN}')
57 extrapackages = oe.package.npm_split_package_dirs(instdir)
58 pkgnames = extrapackages.keys()
59 d.prependVar('PACKAGES', '%s ' % ' '.join(pkgnames))
60 for pkgname in pkgnames:
61 pkgrelpath, pdata = extrapackages[pkgname]
62 pkgpath = '${libdir}/node_modules/${PN}/' + pkgrelpath
63 # package names can't have underscores but npm packages sometimes use them
64 oe_pkg_name = pkgname.replace('_', '-')
65 expanded_pkgname = d.expand(oe_pkg_name)
66 d.setVar('FILES_%s' % expanded_pkgname, pkgpath)
67 if pdata:
68 version = pdata.get('version', None)
69 if version:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060070 d.setVar('PKGV_%s' % expanded_pkgname, version)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050071 description = pdata.get('description', None)
72 if description:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060073 d.setVar('SUMMARY_%s' % expanded_pkgname, description.replace(u"\u2018", "'").replace(u"\u2019", "'"))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050074 d.appendVar('RDEPENDS_%s' % d.getVar('PN'), ' %s' % ' '.join(pkgnames).replace('_', '-'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050075}
76
77FILES_${PN} += " \
78 ${libdir}/node_modules/${PN} \
79"
80
81EXPORT_FUNCTIONS do_compile do_install