Skip to content

Commit 4fe6494

Browse files
authored
Merge pull request #2 from dropbox/define-proxy
Add ability to control npm proxy environment with --define
2 parents 0c1f49e + 11e44b5 commit 4fe6494

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

node/defs.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,20 @@ def _npm_library_impl(ctx):
143143
if ctx.attr.npm_installer_extra_args:
144144
command_args.extend(ctx.attr.npm_installer_extra_args)
145145

146+
env = {}
147+
if 'HTTP_PROXY' in ctx.var:
148+
env['HTTP_PROXY'] = ctx.var['HTTP_PROXY']
149+
if 'HTTPS_PROXY' in ctx.var:
150+
env['HTTPS_PROXY'] = ctx.var['HTTPS_PROXY']
151+
146152
ctx.action(
147153
inputs = [shrinkwrap],
148154
outputs = node_modules_srcs_dict.values(),
149155
executable = ctx.executable.npm_installer,
150156
arguments = command_args,
151157
progress_message = 'installing node modules from {}'.format(shrinkwrap.path),
152-
mnemonic = 'InstallNPMModules'
158+
mnemonic = 'InstallNPMModules',
159+
env = env,
153160
)
154161

155162
all_node_modules = _new_all_node_modules()

node/tools/npm/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ def run_npm(cmd, env=None, cwd=None):
8383
if env:
8484
full_env = dict(full_env.items() + env.items())
8585

86+
if 'HTTP_PROXY' in os.environ:
87+
full_env['HTTP_PROXY'] = os.environ['HTTP_PROXY']
88+
if 'HTTPS_PROXY' in os.environ:
89+
full_env['HTTPS_PROXY'] = os.environ['HTTPS_PROXY']
90+
8691
try:
8792
ret = subprocess.check_output(
8893
full_cmd, env=full_env, cwd=cwd, stderr=subprocess.STDOUT

0 commit comments

Comments
 (0)