Skip to content

Commit ff457ff

Browse files
Let frozen fail when shard.lock is missing
1 parent 5591a5b commit ff457ff

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

Diff for: spec/integration/install_spec.cr

+3-6
Original file line numberDiff line numberDiff line change
@@ -540,22 +540,19 @@ describe "install" do
540540
dependencies: {web: "*", orm: "*"},
541541
development_dependencies: {mock: "*"},
542542
}
543+
# --production requires a lock file because it implies --frozen
544+
lock = {web: "1.0.0", orm: "0.3.0"}
543545

544-
with_shard(metadata) do
545-
File.exists?(File.join(application_path, "shard.lock")).should be_false
546+
with_shard(metadata, lock) do
546547
run "shards install --production"
547548

548549
# it installed dependencies (recursively)
549550
assert_installed "web"
550551
assert_installed "orm"
551-
assert_installed "pg"
552552

553553
# it didn't install development dependencies
554554
refute_installed "mock"
555555
refute_installed "minitest"
556-
557-
# it didn't generate lock file
558-
File.exists?(File.join(application_path, "shard.lock")).should be_false
559556
end
560557
end
561558
end

Diff for: spec/integration/list_spec.cr

+8-6
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ describe "list" do
2323
dependencies: {web: "*", orm: "*"},
2424
development_dependencies: {mock: "*"},
2525
}
26-
with_shard(metadata) do
26+
# --production requires a lock file because it implies --frozen
27+
lock = {web: "1.0.0", orm: "0.3.0"}
28+
29+
with_shard(metadata, lock) do
2730
run "shards install --production"
2831
stdout = run "shards list --production"
29-
stdout.should contain("web (2.1.0)")
30-
stdout.should contain("orm (0.5.0)")
31-
stdout.should contain("pg (0.2.1)")
32-
stdout.should_not contain("mock (0.1.0)")
33-
stdout.should_not contain("shoulda (0.1.0)")
32+
stdout.should contain("web (1.0.0)")
33+
stdout.should contain("orm (0.3.0)")
34+
stdout.should_not contain("mock")
35+
stdout.should_not contain("shoulda")
3436
end
3537
end
3638

Diff for: src/commands/install.cr

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ module Shards
55
module Commands
66
class Install < Command
77
def run(*, ignore_crystal_version = false)
8+
if Shards.frozen? && !lockfile?
9+
raise Error.new("Missing shard.lock")
10+
end
11+
812
Log.info { "Resolving dependencies" }
913

1014
solver = MolinilloSolver.new(spec, override, ignore_crystal_version: ignore_crystal_version)
@@ -18,7 +22,7 @@ module Shards
1822

1923
packages = handle_resolver_errors { solver.solve }
2024

21-
if lockfile? && Shards.frozen?
25+
if Shards.frozen?
2226
validate(packages)
2327
end
2428

0 commit comments

Comments
 (0)