Skip to content

Commit 1f0c50b

Browse files
committed
Fix: manager no longer install path dependencies
PathResolver returns the installed spec from the local path (where the source code is installed) because it links the `src` folder and thus can't access `shard.yml` from its libs folder. Yet PathResolver always returned something for the installed spec, and thus the install and update commands thought it was already installed, which was wrong.
1 parent 2c01e17 commit 1f0c50b

File tree

5 files changed

+35
-27
lines changed

5 files changed

+35
-27
lines changed

src/package.cr

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ module Shards
3232
end
3333

3434
def installed?(loose = false)
35-
if loose
36-
matching_versions.includes?(resolver.spec(:installed).version)
35+
if spec = resolver.installed_spec
36+
if loose
37+
matching_versions.includes?(spec.version)
38+
else
39+
version == spec.version
40+
end
3741
else
38-
version == resolver.spec(:installed).version
42+
false
3943
end
4044
end
4145

src/resolvers/path.cr

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require "./resolver"
2-
require "../core_ext/file"
2+
#require "../core_ext/file"
33

44
module Shards
55
class PathResolver < Resolver
@@ -13,13 +13,17 @@ module Shards
1313
end
1414
end
1515

16-
def spec(version = nil)
17-
if version == :installed
18-
path = File.join(local_path, SPEC_FILENAME)
19-
return Spec.from_file(path) if File.exists?(path)
20-
end
16+
def installed_spec
17+
return unless installed?
18+
19+
path = File.join(local_path, SPEC_FILENAME)
20+
return Spec.from_file(path) if File.exists?(path)
21+
22+
Spec.from_yaml("name: #{dependency.name}\n")
23+
end
2124

22-
super
25+
def installed?
26+
File.symlink?(install_path)
2327
end
2428

2529
def available_versions

src/resolvers/resolver.cr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ module Shards
1313
end
1414

1515
def spec(version = nil)
16-
if version == :installed
17-
path = File.join(install_path, SPEC_FILENAME)
18-
if File.exists?(path)
19-
Spec.from_file(path)
20-
else
21-
Spec.from_yaml("name: #{dependency.name}\n")
22-
end
23-
else
24-
Spec.from_yaml(read_spec(version))
25-
end
16+
Spec.from_yaml(read_spec(version))
17+
end
18+
19+
def installed_spec
20+
return unless installed?
21+
22+
path = File.join(install_path, SPEC_FILENAME)
23+
return Spec.from_file(path) if File.exists?(path)
24+
25+
Spec.from_yaml("name: #{dependency.name}\n")
2626
end
2727

28-
def installed?(version)
29-
spec(:installed).version == version
28+
def installed?
29+
File.exists?(install_path)
3030
end
3131

3232
abstract def read_spec(version = nil)

test/git_resolver_test.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ module Shards
4040
library.install("0.1.2")
4141
assert File.exists?(install_path("library", "library.cr"))
4242
assert File.exists?(install_path("library", "shard.yml"))
43-
assert_equal "0.1.2", library.spec(:installed).version
43+
assert_equal "0.1.2", library.installed_spec.not_nil!.version
4444
#assert File.exists?(install_path("library", "LICENSE"))
4545

4646
library.install
47-
assert_equal "0.2.0", library.spec(:installed).version
47+
assert_equal "0.2.0", library.installed_spec.not_nil!.version
4848

4949
legacy.install
5050
assert File.exists?(install_path("legacy", "legacy.cr"))
@@ -53,7 +53,7 @@ module Shards
5353
legacy.install("1.0.0")
5454
assert File.exists?(install_path("legacy", "legacy.cr"))
5555
assert File.exists?(install_path("legacy", "shard.yml"))
56-
assert_equal "1.0.0", legacy.spec(:installed).version
56+
assert_equal "1.0.0", legacy.installed_spec.not_nil!.version
5757

5858
empty.install # HEAD
5959
assert File.exists?(install_path("empty", "empty.cr"))

test/path_resolver_test.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ module Shards
2222
library.install
2323
assert File.exists?(install_path("library", "library.cr"))
2424
refute File.exists?(install_path("library", "shard.yml"))
25-
assert_equal "1.2.3", library.spec(:installed).version
25+
assert_equal "1.2.3", library.installed_spec.not_nil!.version
2626
end
2727

2828
resolver("legacy").tap do |legacy|
2929
legacy.install
3030
assert File.exists?(install_path("legacy", "legacy.cr"))
3131
refute File.exists?(install_path("legacy", "shard.yml"))
32-
assert_empty legacy.spec(:installed).version
32+
assert_empty legacy.installed_spec.not_nil!.version
3333
end
3434
end
3535

0 commit comments

Comments
 (0)