-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from tmatilai/npm
Add support for npm proxy
- Loading branch information
Showing
8 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require_relative 'base' | ||
|
||
module VagrantPlugins | ||
module ProxyConf | ||
class Action | ||
# Action for configuring npm on the guest | ||
class ConfigureNpmProxy < Base | ||
def config_name | ||
'npm_proxy' | ||
end | ||
|
||
private | ||
|
||
# @return [Vagrant::Plugin::V2::Config] the configuration | ||
def config | ||
# Use global proxy config | ||
@config ||= finalize_config(@machine.config.proxy) | ||
end | ||
|
||
def configure_machine | ||
set_or_delete_proxy('proxy', config.http) | ||
set_or_delete_proxy('https-proxy', config.https) | ||
end | ||
|
||
def set_or_delete_proxy(key, value) | ||
if value | ||
command = "npm config set #{key} #{escape(config.http)}" | ||
else | ||
command = "npm config delete #{key}" | ||
end | ||
@machine.communicate.sudo(command) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module VagrantPlugins | ||
module ProxyConf | ||
module Cap | ||
module Linux | ||
# Capability for npm proxy configuration | ||
module NpmProxyConf | ||
# @return [Boolean] if npm is installed | ||
def self.npm_proxy_conf(machine) | ||
machine.communicate.test('which npm') | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
spec/unit/vagrant-proxyconf/action/configure_npm_proxy_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'spec_helper' | ||
require 'vagrant-proxyconf/action/configure_npm_proxy' | ||
|
||
describe VagrantPlugins::ProxyConf::Action::ConfigureNpmProxy do | ||
|
||
describe '#config_name' do | ||
subject { described_class.new(double, double).config_name } | ||
it { should eq 'npm_proxy' } | ||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
spec/unit/vagrant-proxyconf/cap/linux/npm_proxy_conf_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'spec_helper' | ||
require 'vagrant-proxyconf/cap/linux/npm_proxy_conf' | ||
|
||
describe VagrantPlugins::ProxyConf::Cap::Linux::NpmProxyConf do | ||
|
||
describe '.npm_proxy_conf' do | ||
let(:machine) { double } | ||
let(:communicator) { double } | ||
|
||
before do | ||
machine.stub(:communicate => communicator) | ||
end | ||
|
||
it "returns true when npm is installed" do | ||
expect(communicator).to receive(:test).with('which npm').and_return(true) | ||
expect(described_class.npm_proxy_conf(machine)).to be_true | ||
end | ||
|
||
it "returns false when npm is not installed" do | ||
expect(communicator).to receive(:test).with('which npm').and_return(false) | ||
expect(described_class.npm_proxy_conf(machine)).to be_false | ||
end | ||
end | ||
|
||
end |