elm_install 0.3.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.reek +4 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +4 -0
  5. data/Gemfile.lock +30 -25
  6. data/Rakefile +2 -2
  7. data/Readme.md +85 -23
  8. data/bin/elm-install +5 -2
  9. data/elm_install.gemspec +2 -0
  10. data/lib/elm_install.rb +18 -1
  11. data/lib/elm_install/base.rb +3 -46
  12. data/lib/elm_install/dependency.rb +37 -0
  13. data/lib/elm_install/directory_source.rb +66 -0
  14. data/lib/elm_install/ext.rb +23 -0
  15. data/lib/elm_install/git_source.rb +173 -0
  16. data/lib/elm_install/identifier.rb +133 -0
  17. data/lib/elm_install/installer.rb +38 -96
  18. data/lib/elm_install/populator.rb +54 -75
  19. data/lib/elm_install/repository.rb +82 -0
  20. data/lib/elm_install/resolver.rb +48 -118
  21. data/lib/elm_install/source.rb +18 -0
  22. data/lib/elm_install/types.rb +43 -0
  23. data/lib/elm_install/utils.rb +14 -20
  24. data/lib/elm_install/version.rb +1 -1
  25. data/package.json +1 -1
  26. data/packaging/Gemfile +1 -1
  27. data/packaging/Gemfile.lock +8 -4
  28. data/scripts/install.js +4 -4
  29. data/scripts/run.js +4 -4
  30. data/spec/directory_source_spec.rb +37 -0
  31. data/spec/{eml_install_spec.rb → elm_install_spec.rb} +6 -3
  32. data/spec/git_source_spec.rb +115 -0
  33. data/spec/identifer_spec.rb +53 -0
  34. data/spec/installer_spec.rb +57 -26
  35. data/spec/repository_spec.rb +44 -0
  36. data/spec/resolver_spec.rb +0 -73
  37. data/spec/spec_helper.rb +3 -1
  38. data/spec/utils_spec.rb +10 -15
  39. metadata +43 -17
  40. data/docs/How it works.md +0 -54
  41. data/lib/elm_install/cache.rb +0 -52
  42. data/lib/elm_install/elm_package.rb +0 -119
  43. data/lib/elm_install/git_resolver.rb +0 -129
  44. data/lib/elm_install/graph_builder.rb +0 -73
  45. data/spec/elm_package_spec.rb +0 -73
  46. data/spec/fixtures/cache.json +0 -8
  47. data/spec/fixtures/elm-package.json +0 -12
  48. data/spec/fixtures/invalid-elm-package.json +0 -6
  49. data/spec/fixtures/mismatched-elm-package.json +0 -9
  50. data/spec/fixtures/ref-cache.json +0 -4
  51. data/spec/git_resolver_spec.rb +0 -103
  52. data/spec/graph_builder_spec.rb +0 -36
  53. data/spec/populator_spec.rb +0 -44
@@ -0,0 +1,44 @@
1
+ describe ElmInstall::Repository do
2
+ subject { described_class.new '', '.' }
3
+
4
+ describe '#clone' do
5
+ it 'clones the repository' do
6
+ expect(FileUtils)
7
+ .to receive(:mkdir_p)
8
+
9
+ expect(Git)
10
+ .to receive(:clone)
11
+ .with('', '.')
12
+ .and_return(Git::Base.new)
13
+
14
+ subject.clone
15
+ end
16
+ end
17
+
18
+ describe '#checkout' do
19
+ it 'checks out the given reference' do
20
+ expect_any_instance_of(Git::Base)
21
+ .to receive(:reset_hard)
22
+ .twice
23
+
24
+ expect_any_instance_of(Git::Base)
25
+ .to receive(:checkout).with('')
26
+
27
+ subject.checkout('')
28
+ end
29
+ end
30
+
31
+ describe '#versions' do
32
+ it 'returns the versions of the repository' do
33
+ expect_any_instance_of(Git::Base)
34
+ .to receive(:reset_hard)
35
+
36
+ expect_any_instance_of(Git::Base)
37
+ .to receive(:tags)
38
+ .and_return [double(name: 'test'), double(name: '1.0.0')]
39
+
40
+ expect(subject.versions)
41
+ .to eq([Semverse::Version.new('1.0.0')])
42
+ end
43
+ end
44
+ end
@@ -1,75 +1,2 @@
1
- require 'spec_helper'
2
-
3
1
  describe ElmInstall::Resolver do
4
- subject { described_class.new cache, git_resolver }
5
-
6
- let(:git_resolver) { ElmInstall::GitResolver.new directory: CACHE_DIRECTORY }
7
- let(:cache) { ElmInstall::Cache.new directory: CACHE_DIRECTORY }
8
-
9
- let(:directory) { File.join CACHE_DIRECTORY, 'github.com/test/repo' }
10
- let(:core_directory) { File.join CACHE_DIRECTORY, 'github.com/base/core' }
11
-
12
- let(:package_json) do
13
- { dependencies: { 'base/core' => '1.0.0 <= v < 2.0.0' } }.to_json
14
- end
15
-
16
- before do
17
- FileUtils.mkdir_p directory
18
- File.binwrite File.join(directory, 'elm-package.json'), package_json
19
- Git.init directory
20
- end
21
-
22
- let(:url) { 'git@github.com:test/repo' }
23
-
24
- let(:core_repo) do
25
- repo = Git.init core_directory
26
- File.binwrite File.join(core_directory, 'elm-package.json'), '{}'
27
- repo
28
- end
29
-
30
- it 'should resolve packages' do
31
- expect(Git)
32
- .to receive(:clone) { core_repo }
33
-
34
- expect(Git)
35
- .to receive(:ls_remote)
36
- .and_return(tags: { name: '1.0.0' })
37
-
38
- expect(ElmInstall::Logger)
39
- .to receive(:arrow)
40
- .with "Package: #{'https://github.com/base/core'.bold} not found in \
41
- cache, cloning...".gsub(/\s+/, ' ')
42
-
43
- allow_any_instance_of(Git::Remote)
44
- .to receive(:url)
45
- .and_return url
46
-
47
- allow_any_instance_of(Git::Base)
48
- .to receive(:tags)
49
- .and_return [double(name: '1.0.0')]
50
-
51
- allow_any_instance_of(Git::Base)
52
- .to receive(:checkout)
53
-
54
- subject
55
- .instance_variable_get('@git_resolver')
56
- .instance_variable_get('@check_cache')[directory] = {}
57
-
58
- subject.instance_variable_get('@git_resolver').cache[directory] = {}
59
-
60
- subject.add_constraints(
61
- url => 'development',
62
- 'git@github.com:base/core' => '1.0.0 <= v < 2.0.0'
63
- )
64
- end
65
-
66
- describe '#elm_dependencies' do
67
- it 'should return empty hash on error' do
68
- expect(ElmInstall::ElmPackage)
69
- .to receive(:read)
70
- .and_raise 'test'
71
-
72
- expect(subject.elm_dependencies('test')).to eq({})
73
- end
74
- end
75
2
  end
@@ -1,9 +1,11 @@
1
1
  require 'simplecov'
2
2
 
3
- CACHE_DIRECTORY = 'spec/fixtures/cache'.freeze
3
+ CACHE_DIRECTORY = 'spec/cache'.freeze
4
4
 
5
5
  RSpec.configure do |config|
6
6
  config.before do
7
+ allow(Process).to receive(:exit)
8
+ allow(ElmInstall::Logger).to receive(:puts)
7
9
  FileUtils.mkdir_p CACHE_DIRECTORY
8
10
  end
9
11
 
@@ -1,34 +1,29 @@
1
- require 'spec_helper'
2
-
3
1
  describe ElmInstall::Utils do
4
2
  subject { described_class }
5
3
 
6
4
  let(:package_variations) do
7
5
  [
8
- 'git@github.com:test/repo',
9
6
  'https://github.com/test/repo',
10
- 'git://github.com/test/repo'
7
+ 'git://github.com/test/repo',
8
+ 'git@github.com:test/repo'
11
9
  ]
12
10
  end
13
11
 
14
- describe '.package_version_path' do
15
- it 'should return the path for a package in elm-stuff' do
16
- package_variations.each do |package|
17
- expect(subject.package_version_path(package, '1.0.0'))
18
- .to eq(['test/repo', 'elm-stuff/packages/test/repo/1.0.0'])
19
- end
20
- end
21
- end
22
-
23
12
  describe '.transform_constraint' do
24
13
  it 'should convert basic constraint' do
25
14
  expect(subject.transform_constraint('0.1.0 <= v < 1.0.0'))
26
- .to eq(['< 1.0.0', '>= 0.1.0'])
15
+ .to eq(
16
+ [Solve::Constraint.new('< 1.0.0'),
17
+ Solve::Constraint.new('>= 0.1.0')]
18
+ )
27
19
  end
28
20
 
29
21
  it 'should convert advanced constraint' do
30
22
  expect(subject.transform_constraint('0.1.0 < v <= 1.0.0'))
31
- .to eq(['<= 1.0.0', '> 0.1.0'])
23
+ .to eq(
24
+ [Solve::Constraint.new('<= 1.0.0'),
25
+ Solve::Constraint.new('> 0.1.0')]
26
+ )
32
27
  end
33
28
  end
34
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elm_install
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusztáv Szikszai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-16 00:00:00.000000000 Z
11
+ date: 2017-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -120,6 +120,34 @@ dependencies:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
122
  version: 0.1.1
123
+ - !ruby/object:Gem::Dependency
124
+ name: contracts
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: 0.16.0
130
+ type: :runtime
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: 0.16.0
137
+ - !ruby/object:Gem::Dependency
138
+ name: adts
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: 0.1.2
144
+ type: :runtime
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: 0.1.2
123
151
  description:
124
152
  email: gusztav.szikszai@digitalnatives.hu
125
153
  executables:
@@ -140,18 +168,21 @@ files:
140
168
  - Rakefile
141
169
  - Readme.md
142
170
  - bin/elm-install
143
- - docs/How it works.md
144
171
  - elm_install.gemspec
145
172
  - lib/elm_install.rb
146
173
  - lib/elm_install/base.rb
147
- - lib/elm_install/cache.rb
148
- - lib/elm_install/elm_package.rb
149
- - lib/elm_install/git_resolver.rb
150
- - lib/elm_install/graph_builder.rb
174
+ - lib/elm_install/dependency.rb
175
+ - lib/elm_install/directory_source.rb
176
+ - lib/elm_install/ext.rb
177
+ - lib/elm_install/git_source.rb
178
+ - lib/elm_install/identifier.rb
151
179
  - lib/elm_install/installer.rb
152
180
  - lib/elm_install/logger.rb
153
181
  - lib/elm_install/populator.rb
182
+ - lib/elm_install/repository.rb
154
183
  - lib/elm_install/resolver.rb
184
+ - lib/elm_install/source.rb
185
+ - lib/elm_install/types.rb
155
186
  - lib/elm_install/utils.rb
156
187
  - lib/elm_install/version.rb
157
188
  - package.json
@@ -164,17 +195,12 @@ files:
164
195
  - packaging/wrapper.sh
165
196
  - scripts/install.js
166
197
  - scripts/run.js
167
- - spec/elm_package_spec.rb
168
- - spec/eml_install_spec.rb
169
- - spec/fixtures/cache.json
170
- - spec/fixtures/elm-package.json
171
- - spec/fixtures/invalid-elm-package.json
172
- - spec/fixtures/mismatched-elm-package.json
173
- - spec/fixtures/ref-cache.json
174
- - spec/git_resolver_spec.rb
175
- - spec/graph_builder_spec.rb
198
+ - spec/directory_source_spec.rb
199
+ - spec/elm_install_spec.rb
200
+ - spec/git_source_spec.rb
201
+ - spec/identifer_spec.rb
176
202
  - spec/installer_spec.rb
177
- - spec/populator_spec.rb
203
+ - spec/repository_spec.rb
178
204
  - spec/resolver_spec.rb
179
205
  - spec/spec_helper.rb
180
206
  - spec/utils_spec.rb
@@ -1,54 +0,0 @@
1
- Program flow
2
- ------------
3
-
4
- 1. Try to load the cache of dependencies from `~/.elm-install/cache.json` and
5
- load the cache of references from `~/.elm-install/ref-cache.json`. If no
6
- cache files found initialize empty caches.
7
-
8
- 2. Read `dependencies` and `dependency-sources` from `elm-package.json` and
9
- transform them from:
10
-
11
- ```
12
- {
13
- "dependencies": {
14
- "elm-lang/core": "5.0.0 <= 6.0.0",
15
- "gdotdesign/elm-ui": "1.0.0 <= 2.0.0"
16
- },
17
- "dependency-sources": {
18
- "gdotdesign/elm-ui": {
19
- "url": "git@bitbucket.com:gdotdesign/elm-ui",
20
- "ref": "development"
21
- }
22
- }
23
- }
24
- ```
25
-
26
- to:
27
-
28
- ```
29
- {
30
- "https://github.com/elm-lang/core": "5.0.0 <= 6.0.0",
31
- "git@bitbucket.com:gdotdesign/elm-ui": "development"
32
- }
33
- ```
34
-
35
- 3. Add dependencies to the cache, skipping if the package is already added:
36
-
37
- 1. If a package is not added, it is cloned from it's remote repository into
38
- the cache directory.
39
-
40
- 2. Tags are extracted and iterated over, checking out the tag, reading and
41
- transforming it's the `elm-package.json` and adding it's dependecies (2.)
42
-
43
- 4. Try to solve dependencies from the caches.
44
-
45
- 5. (If no solution found) Go through the packages from the cache and update
46
- their references and if it changed update the repository (fetching new
47
- content)
48
-
49
- 6. (If no solution found) Solve dependencies from the updated cache.
50
-
51
- 7. Save cache.
52
-
53
- 8. (If solution found) Populate `elm-stuff` and write
54
- `elm-stuff/exact-dependecies.json`.
@@ -1,52 +0,0 @@
1
- require_relative './base'
2
-
3
- module ElmInstall
4
- # This class is responsible for maintaining a cache
5
- # of all the repositories their versions and their dependencies.
6
- #
7
- # By default the clones of the repositories live in the users
8
- # home directory (~/.elm-install), this can be changed with
9
- # the `directory` option.
10
- class Cache < Base
11
- # Initializes a cache with the given options.
12
- #
13
- # @param options [Hash] The options
14
- def initialize(options)
15
- @file = 'cache.json'
16
- super options
17
- end
18
-
19
- # Adds a new dependency to the cache for a given package & version
20
- # combination.
21
- #
22
- # @param package [String] The url of the package
23
- # @param version [String] The semver version (1.0.0 or 1.0.0+master)
24
- # @param constraint [Array] The constraint ["pacakge", "<= 1.0.0"]
25
- #
26
- # @return [Array] The dependencies of the package & version combination
27
- def dependency(package, version, constraint)
28
- ensure_package version
29
- @cache[package][version] << constraint
30
- end
31
-
32
- # Ensures that a package & version combination exists in the cache.
33
- #
34
- # @param package [String] The url of the package
35
- # @param version [String] The semver version (1.0.0 or 1.0.0+master)
36
- #
37
- # @return [Array] The dependencies of the package & version combination
38
- def ensure_version(package, version)
39
- ensure_package package
40
- @cache[package][version] ||= []
41
- end
42
-
43
- # Ensures that a package exists in the cache.
44
- #
45
- # @param package [String] The url of the package
46
- #
47
- # @return [Hash] The dependency hash of the package
48
- def ensure_package(package)
49
- @cache[package] ||= {}
50
- end
51
- end
52
- end
@@ -1,119 +0,0 @@
1
- module ElmInstall
2
- # This is a class for reading the `elm-package`.json file and
3
- # transform it's `dependecies` field to a unified format.
4
- module ElmPackage
5
- # Returns the dependencies for the given `elm-package`.
6
- #
7
- # @param path [String] The path for the file
8
- #
9
- # @return [Hash] The hash of dependenceis (url => version or ref)
10
- def self.dependencies(path, options = { silent: true })
11
- json = read path, options
12
- transform_dependencies(
13
- json['dependencies'].to_h,
14
- json['dependency-sources'].to_h
15
- )
16
- end
17
-
18
- # Reads the given file as JSON.
19
- #
20
- # :reek:DuplicateMethodCall
21
- #
22
- # @param path [String] The path
23
- #
24
- # @return [Hash] The json
25
- def self.read(path, options = { silent: true })
26
- JSON.parse(File.read(path))
27
- rescue JSON::ParserError
28
- exit "Invalid JSON in file: #{path.bold}.", options
29
- rescue Errno::ENOENT
30
- exit "Could not find file: #{path.bold}.", options
31
- end
32
-
33
- # Exits the current process with the given message.
34
- #
35
- # @param message [String] The message
36
- # @param options [Hash] The options
37
- #
38
- # @return [void]
39
- def self.exit(message, options)
40
- return {} if options[:silent]
41
- Logger.arrow message
42
- Process.exit
43
- end
44
-
45
- # Transform dependencies from (package name => version) to
46
- # (url => version or ref) format using the `depdendency-sources` field.
47
- #
48
- # @param raw_dependencies [Hash] The raw dependencies
49
- # @param sources [Hash] The sources for the dependencies
50
- #
51
- # @return [Hash] The dependencies
52
- def self.transform_dependencies(raw_dependencies, sources)
53
- raw_dependencies.each_with_object({}) do |(package, constraint), memo|
54
- value = sources.fetch(package, package)
55
-
56
- transform_dependency package, value, constraint, memo
57
- end
58
- end
59
-
60
- # Transforms a dependecy.
61
- #
62
- # :reek:LongParameterList
63
- # :reek:DuplicateMethodCall
64
- #
65
- # @param package [String] The package
66
- # @param value [String] The version
67
- # @param constraint [String] The constarint
68
- # @param memo [Hash] The hash to save the dependency to
69
- #
70
- # @return [Hash] The memo object
71
- def self.transform_dependency(package, value, constraint, memo)
72
- if value.is_a?(Hash)
73
- check_path package, value['url']
74
- memo[value['url']] = value['ref']
75
- else
76
- url = transform_package(value)
77
- check_path package, url
78
- memo[url] = constraint
79
- end
80
- end
81
-
82
- # Checks if the given url matches the given package.
83
- #
84
- # :reek:DuplicateMethodCall
85
- #
86
- # @param package [String] The package
87
- # @param url [String] The url
88
- #
89
- # @return [void]
90
- def self.check_path(package, url)
91
- uri = GitCloneUrl.parse(url)
92
- path = uri.path.sub(%r{^/}, '')
93
-
94
- return if path == package
95
-
96
- puts "
97
- The source of package #{package.bold} is set to #{url.bold} which would
98
- be install to #{"elm-stuff/#{path}".bold}. This would cause a conflict
99
- when trying to compile anything.
100
-
101
- The name of a package must match the source url's path.
102
-
103
- #{package.bold} <=> #{path.bold}
104
- "
105
- Process.exit
106
- end
107
-
108
- # Transforms a package to it's url for if needed.
109
- #
110
- # @param key [String] The package
111
- #
112
- # @return [String] The url
113
- def self.transform_package(key)
114
- GitCloneUrl.parse(key).to_s.gsub(/\.git$/, '')
115
- rescue
116
- "https://github.com/#{key}"
117
- end
118
- end
119
- end