dpl 1.7.19.travis.946.4 → 1.7.19.travis.947.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/dpl/provider/npm.rb +15 -1
- data/spec/provider/npm_spec.rb +35 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDM4ZjdjYTg1MTliZTk0YmY5YjA5ZGY3MzQyNmU4N2RhNzg1ZTRiZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmMxYWRkMGNlYjA1YjdiOWU5YTQ0ZWE4ZDAwMWU4MjI0M2ZkYTAxYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjhlMDFlNDI3NTI1MDNhMDk2ZDY0OWE1NjcxYTZlM2ZkY2EzMzE2ZjRjZTQw
|
10
|
+
YjA4NTRlYWI1ZjVkZjBhMWY5ZTFlZDNkMTdhM2ViYTk0MTdkNWRmMjIyODY5
|
11
|
+
OTE4MmEzYWZjMGQ0ZDlmYjU4NDA4OWY2OTBlZDNiYmY2ZTQ2NTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWYxMTFmNmMyOTkwNTBhOTRmMTI4YmZlMTFkZmVmMDdjZjhlZjEzMWYxMmE1
|
14
|
+
MTIwZDg1MDQzYmEwNGJiZDQ5MThjY2RhOTk4OTAyZDVlZWIyMWE2MTkxNjNi
|
15
|
+
MjM3OGQwNzE1MDVhYWQ0YmZiMTFhNDFlNzY1OTY2MTQxZDY4MDQ=
|
data/lib/dpl/provider/npm.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module DPL
|
2
4
|
class Provider
|
3
5
|
class NPM < Provider
|
4
6
|
NPMRC_FILE = '~/.npmrc'
|
7
|
+
DEFAULT_NPM_REGISTRY = 'registry.npmjs.org'
|
5
8
|
|
6
9
|
def needs_key?
|
7
10
|
false
|
@@ -12,7 +15,7 @@ module DPL
|
|
12
15
|
|
13
16
|
def setup_auth
|
14
17
|
f = File.open(File.expand_path(NPMRC_FILE), 'w')
|
15
|
-
f.puts("
|
18
|
+
f.puts("//#{package_registry}/:_authToken=${NPM_API_KEY}")
|
16
19
|
end
|
17
20
|
|
18
21
|
def check_auth
|
@@ -26,6 +29,17 @@ module DPL
|
|
26
29
|
context.shell "env NPM_API_KEY=#{option(:api_key)} npm publish"
|
27
30
|
FileUtils.rm(File.expand_path(NPMRC_FILE))
|
28
31
|
end
|
32
|
+
|
33
|
+
def package_registry
|
34
|
+
if File.exists?('package.json')
|
35
|
+
data = JSON.parse(File.read('package.json'))
|
36
|
+
if data['publishConfig'] && data['publishConfig']['registry']
|
37
|
+
return data['publishConfig']['registry']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
DEFAULT_NPM_REGISTRY
|
42
|
+
end
|
29
43
|
end
|
30
44
|
end
|
31
45
|
end
|
data/spec/provider/npm_spec.rb
CHANGED
@@ -24,10 +24,41 @@ describe DPL::Provider::NPM do
|
|
24
24
|
|
25
25
|
describe "#setup_auth" do
|
26
26
|
example do
|
27
|
-
|
28
|
-
expect(File).to receive(:open).with(File.expand_path(DPL::Provider::NPM::NPMRC_FILE), 'w').and_return(f)
|
29
|
-
expect(f).to receive(:puts).with("//registry.npmjs.org/:_authToken=${NPM_API_KEY}")
|
30
|
-
provider.setup_auth
|
27
|
+
test_setup_auth
|
31
28
|
end
|
32
29
|
end
|
30
|
+
|
31
|
+
context 'when package.json exists' do
|
32
|
+
let(:custom_rpm_registry) { 'npm.example.com' }
|
33
|
+
before :each do
|
34
|
+
expect(File).to receive(:exists?).with('package.json').and_return(true)
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'and it defines custom RPM registry' do
|
38
|
+
before { expect(File).to receive(:read).with('package.json').and_return("{\"publishConfig\":{\"registry\":\"#{custom_rpm_registry}\"}}") }
|
39
|
+
|
40
|
+
describe '#setup_auth' do
|
41
|
+
example do
|
42
|
+
test_setup_auth(custom_rpm_registry)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'and it does not define custom RPM registry' do
|
48
|
+
before { expect(File).to receive(:read).with('package.json').and_return("{}") }
|
49
|
+
|
50
|
+
describe '#setup_auth' do
|
51
|
+
example do
|
52
|
+
test_setup_auth
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_setup_auth(registry=DPL::Provider::NPM::DEFAULT_NPM_REGISTRY)
|
60
|
+
f = double(:npmrc)
|
61
|
+
expect(File).to receive(:open).with(File.expand_path(DPL::Provider::NPM::NPMRC_FILE), 'w').and_return(f)
|
62
|
+
expect(f).to receive(:puts).with("//#{registry}/:_authToken=${NPM_API_KEY}")
|
63
|
+
provider.setup_auth
|
33
64
|
end
|