Skip to content

Commit

Permalink
Merge pull request #2 from dropbox/define-proxy
Browse files Browse the repository at this point in the history
Add ability to control npm proxy environment with --define
  • Loading branch information
samertm committed Sep 14, 2017
2 parents 0c1f49e + 11e44b5 commit 4fe6494
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion node/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,20 @@ def _npm_library_impl(ctx):
if ctx.attr.npm_installer_extra_args:
command_args.extend(ctx.attr.npm_installer_extra_args)

env = {}
if 'HTTP_PROXY' in ctx.var:
env['HTTP_PROXY'] = ctx.var['HTTP_PROXY']
if 'HTTPS_PROXY' in ctx.var:
env['HTTPS_PROXY'] = ctx.var['HTTPS_PROXY']

ctx.action(
inputs = [shrinkwrap],
outputs = node_modules_srcs_dict.values(),
executable = ctx.executable.npm_installer,
arguments = command_args,
progress_message = 'installing node modules from {}'.format(shrinkwrap.path),
mnemonic = 'InstallNPMModules'
mnemonic = 'InstallNPMModules',
env = env,
)

all_node_modules = _new_all_node_modules()
Expand Down
5 changes: 5 additions & 0 deletions node/tools/npm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def run_npm(cmd, env=None, cwd=None):
if env:
full_env = dict(full_env.items() + env.items())

if 'HTTP_PROXY' in os.environ:
full_env['HTTP_PROXY'] = os.environ['HTTP_PROXY']
if 'HTTPS_PROXY' in os.environ:
full_env['HTTPS_PROXY'] = os.environ['HTTPS_PROXY']

try:
ret = subprocess.check_output(
full_cmd, env=full_env, cwd=cwd, stderr=subprocess.STDOUT
Expand Down

0 comments on commit 4fe6494

Please sign in to comment.