npm.bbclass: introduce NPM_PXORY

Submitted by Ming Liu on Jan. 9, 2019, 5:24 p.m. | Patch ID: 157661

Details

Message ID 1547054675-32745-1-git-send-email-liu.ming50@gmail.com
State New
Headers show

Commit Message

Ming Liu Jan. 9, 2019, 5:24 p.m.
From: Ming Liu <liu.ming50@gmail.com>

This is needed to support building npm packages under environment with
proxy setting.

Signed-off-by: Ming Liu <liu.ming50@gmail.com>
---
 meta/classes/npm.bbclass | 10 ++++++++++
 1 file changed, 10 insertions(+)

Patch hide | download patch | download mbox

diff --git a/meta/classes/npm.bbclass b/meta/classes/npm.bbclass
index 6dbae6b..0f37f30 100644
--- a/meta/classes/npm.bbclass
+++ b/meta/classes/npm.bbclass
@@ -24,6 +24,9 @@  def npm_oe_arch_map(target_arch, d):
 NPM_ARCH ?= "${@npm_oe_arch_map(d.getVar('TARGET_ARCH'), d)}"
 NPM_INSTALL_DEV ?= "0"
 
+# Format: http://proxyhost:proxyport
+NPM_PROXY ?= ""
+
 npm_do_compile() {
 	# Copy in any additionally fetched modules
 	if [ -d ${WORKDIR}/node_modules ] ; then
@@ -32,6 +35,13 @@  npm_do_compile() {
 	# changing the home directory to the working directory, the .npmrc will
 	# be created in this directory
 	export HOME=${WORKDIR}
+	if [ -n "${NPM_PROXY}" ]; then
+		npm config set proxy ${NPM_PROXY}
+		npm config set https-proxy ${NPM_PROXY}
+	else
+		npm config set proxy null
+		npm config set https-proxy null
+	fi
 	if [  "${NPM_INSTALL_DEV}" = "1" ]; then
 		npm config set dev true
 	else

Comments

Alexander Kanavin Jan. 9, 2019, 5:27 p.m.
On Wed, 9 Jan 2019 at 18:24, <liu.ming50@gmail.com> wrote:

> +       if [ -n "${NPM_PROXY}" ]; then
> +               npm config set proxy ${NPM_PROXY}
> +               npm config set https-proxy ${NPM_PROXY}
> +       else
> +               npm config set proxy null
> +               npm config set https-proxy null
> +       fi

Isn't it better to set those from http[s]_proxy environment variables
which are standard?

Alex
Ross Burton Jan. 9, 2019, 5:32 p.m.
On Wed, 9 Jan 2019 at 17:28, Alexander Kanavin <alex.kanavin@gmail.com> wrote:
> > +       if [ -n "${NPM_PROXY}" ]; then
> > +               npm config set proxy ${NPM_PROXY}
> > +               npm config set https-proxy ${NPM_PROXY}
> > +       else
> > +               npm config set proxy null
> > +               npm config set https-proxy null
> > +       fi
>
> Isn't it better to set those from http[s]_proxy environment variables
> which are standard?

Please, unless there's a very good reason lets use the proxy variables
that we already export to various other bits of the system.

If npm will respect http_proxy in the environment, then just use
bb.utils.export_proxies.

Ross