Skip to content

Commit 75c8ea4

Browse files
Add --frozen and --without_development flags
1 parent ff457ff commit 75c8ea4

File tree

5 files changed

+193
-125
lines changed

5 files changed

+193
-125
lines changed

docs/shards.adoc

+7-7
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Exit status:
5858
*init*::
5959
Initializes a default _shard.yml_ in the current folder.
6060

61-
*install*::
61+
*install* [--frozen] [--without-development] [--production]::
6262
Resolves and installs dependencies into the _lib_ folder. If not already
6363
present, generates a _shard.lock_ file from resolved dependencies, locking
6464
version numbers or Git commits.
@@ -67,6 +67,12 @@ Reads and enforces locked versions and commits if a _shard.lock_ file is
6767
present. The *install* command may fail if a locked version doesn't match
6868
a requirement, but may succeed if a new dependency was added, as long as it
6969
doesn't generate a conflict, thus generating a new _shard.lock_ file.
70+
+
71+
--
72+
--frozen:: Strictly installs locked versions from _shard.lock_. Fails if _shard.lock_ is missing.
73+
--without-development:: Does not install development dependencies.
74+
--production:: same as _--frozen_ and _--without-development_
75+
--
7076

7177
*list* [--tree]::
7278
Lists the installed dependencies and their versions.
@@ -121,12 +127,6 @@ after a command.
121127
--ignore-crystal-version::
122128
Do not enforce crystal version restrictions on shards.
123129

124-
--production::
125-
Runs in release mode. Development dependencies won’t
126-
be installed and only locked dependencies will be installed. Commands
127-
will fail if dependencies in _shard.yml_ and _shard.lock_ are out of
128-
sync (used by *install*, *update*, *check* and *list* commands).
129-
130130
-q, --quiet::
131131
Decreases the log verbosity, printing only warnings and errors.
132132

man/shards.1

+18-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
.\" Title: shards
33
.\" Author: [see the "AUTHOR(S)" section]
44
.\" Generator: Asciidoctor 2.0.12
5-
.\" Date: 2021-01-30
5+
.\" Date: 2021-02-02
66
.\" Manual: Shards Manual
77
.\" Source: shards 0.13.0
88
.\" Language: English
99
.\"
10-
.TH "SHARDS" "1" "2021-01-30" "shards 0.13.0" "Shards Manual"
10+
.TH "SHARDS" "1" "2021-02-02" "shards 0.13.0" "Shards Manual"
1111
.ie \n(.g .ds Aq \(aq
1212
.el .ds Aq '
1313
.ss \n[.ss] 0
@@ -92,7 +92,7 @@ Dependencies are not satisfied.
9292
Initializes a default \fIshard.yml\fP in the current folder.
9393
.RE
9494
.sp
95-
\fBinstall\fP
95+
\fBinstall\fP [\-\-frozen] [\-\-without\-development] [\-\-production]
9696
.RS 4
9797
Resolves and installs dependencies into the \fIlib\fP folder. If not already
9898
present, generates a \fIshard.lock\fP file from resolved dependencies, locking
@@ -102,6 +102,21 @@ Reads and enforces locked versions and commits if a \fIshard.lock\fP file is
102102
present. The \fBinstall\fP command may fail if a locked version doesn\(cqt match
103103
a requirement, but may succeed if a new dependency was added, as long as it
104104
doesn\(cqt generate a conflict, thus generating a new \fIshard.lock\fP file.
105+
.sp
106+
\-\-frozen
107+
.RS 4
108+
Strictly installs locked versions from \fIshard.lock\fP. Fails if \fIshard.lock\fP is missing.
109+
.RE
110+
.sp
111+
\-\-without\-development
112+
.RS 4
113+
Does not install development dependencies.
114+
.RE
115+
.sp
116+
\-\-production
117+
.RS 4
118+
same as \fI\-\-frozen\fP and \fI\-\-without\-development\fP
119+
.RE
105120
.RE
106121
.sp
107122
\fBlist\fP [\-\-tree]
@@ -178,14 +193,6 @@ Don\(cqt update remote repositories, use the local cache only.
178193
Do not enforce crystal version restrictions on shards.
179194
.RE
180195
.sp
181-
\-\-production
182-
.RS 4
183-
Runs in release mode. Development dependencies won’t
184-
be installed and only locked dependencies will be installed. Commands
185-
will fail if dependencies in \fIshard.yml\fP and \fIshard.lock\fP are out of
186-
sync (used by \fBinstall\fP, \fBupdate\fP, \fBcheck\fP and \fBlist\fP commands).
187-
.RE
188-
.sp
189196
\-q, \-\-quiet
190197
.RS 4
191198
Decreases the log verbosity, printing only warnings and errors.

spec/integration/install_spec.cr

+143-105
Original file line numberDiff line numberDiff line change
@@ -398,143 +398,181 @@ describe "install" do
398398
end
399399
end
400400

401-
describe "with --production" do
402-
it "fails if shard.lock and shard.yml has different sources" do
403-
# The sources will not match, so the .lock is not valid regarding the specs
404-
metadata = {dependencies: {awesome: {git: git_url(:forked_awesome)}}}
405-
lock = {awesome: "0.1.0", d: "0.1.0"}
401+
["frozen", "production"].each do |flag|
402+
describe "with --#{flag}" do
403+
it "fails if shard.lock and shard.yml has different sources" do
404+
# The sources will not match, so the .lock is not valid regarding the specs
405+
metadata = {dependencies: {awesome: {git: git_url(:forked_awesome)}}}
406+
lock = {awesome: "0.1.0", d: "0.1.0"}
407+
408+
with_shard(metadata, lock) do
409+
assert_locked "awesome", "0.1.0", source: {git: git_url(:awesome)}
410+
411+
ex = expect_raises(FailedCommand) { run "shards install --#{flag} --no-color" }
412+
ex.stdout.should contain("Outdated shard.lock (awesome source changed)")
413+
ex.stderr.should be_empty
414+
end
415+
end
406416

407-
with_shard(metadata, lock) do
408-
assert_locked "awesome", "0.1.0", source: {git: git_url(:awesome)}
417+
it "fails if shard.lock is missing" do
418+
metadata = {dependencies: {web: "*"}}
409419

410-
ex = expect_raises(FailedCommand) { run "shards install --production --no-color" }
411-
ex.stdout.should contain("Outdated shard.lock (awesome source changed)")
412-
ex.stderr.should be_empty
420+
with_shard(metadata) do
421+
ex = expect_raises(FailedCommand) { run "shards install --#{flag} --no-color" }
422+
ex.stdout.should contain("Missing shard.lock")
423+
ex.stderr.should be_empty
424+
end
413425
end
414-
end
415426

416-
it "fails if shard.lock and shard.yml has different sources with incompatible versions." do
417-
# User should use update command in this scenario
418-
# forked_awesome does not have a 0.3.0
419-
# awesome has 0.3.0
420-
metadata = {dependencies: {awesome: {git: git_url(:forked_awesome)}}}
421-
lock = {awesome: "0.3.0"}
427+
it "fails if shard.lock and shard.yml has different sources with incompatible versions." do
428+
# User should use update command in this scenario
429+
# forked_awesome does not have a 0.3.0
430+
# awesome has 0.3.0
431+
metadata = {dependencies: {awesome: {git: git_url(:forked_awesome)}}}
432+
lock = {awesome: "0.3.0"}
422433

423-
with_shard(metadata, lock) do
424-
assert_locked "awesome", "0.3.0", source: {git: git_url(:awesome)}
434+
with_shard(metadata, lock) do
435+
assert_locked "awesome", "0.3.0", source: {git: git_url(:awesome)}
425436

426-
ex = expect_raises(FailedCommand) { run "shards install --production --no-color" }
427-
ex.stdout.should contain("Maybe a commit, branch or file doesn't exist?")
428-
ex.stderr.should be_empty
437+
ex = expect_raises(FailedCommand) { run "shards install --#{flag} --no-color" }
438+
ex.stdout.should contain("Maybe a commit, branch or file doesn't exist?")
439+
ex.stderr.should be_empty
440+
end
429441
end
430-
end
431442

432-
it "fails to install when dependency requirement changed" do
433-
metadata = {dependencies: {web: "2.0.0"}}
434-
lock = {web: "1.0.0"}
443+
it "fails to install when dependency requirement changed" do
444+
metadata = {dependencies: {web: "2.0.0"}}
445+
lock = {web: "1.0.0"}
446+
447+
with_shard(metadata, lock) do
448+
ex = expect_raises(FailedCommand) { run "shards install --no-color --#{flag}" }
449+
ex.stdout.should contain("Outdated shard.lock")
450+
ex.stderr.should be_empty
451+
refute_installed "web"
452+
end
453+
end
454+
455+
it "fails to install when dependency requirement (commit) changed" do
456+
metadata = {dependencies: {inprogress: {git: git_url(:inprogress), commit: git_commits(:inprogress)[1]}}}
457+
lock = {inprogress: "0.1.0+git.commit.#{git_commits(:inprogress).first}"}
458+
459+
with_shard(metadata, lock) do
460+
ex = expect_raises(FailedCommand) { run "shards install --no-color --#{flag}" }
461+
ex.stdout.should contain("Outdated shard.lock")
462+
refute_installed "inprogress"
463+
end
464+
end
435465

436-
with_shard(metadata, lock) do
437-
ex = expect_raises(FailedCommand) { run "shards install --no-color --production" }
438-
ex.stdout.should contain("Outdated shard.lock")
439-
ex.stderr.should be_empty
440-
refute_installed "web"
466+
it "doesn't install new dependencies" do
467+
metadata = {
468+
dependencies: {
469+
web: "~> 1.0.0",
470+
orm: "*",
471+
},
472+
}
473+
lock = {web: "1.0.0"}
474+
475+
with_shard(metadata, lock) do
476+
ex = expect_raises(FailedCommand) { run "shards install --#{flag} --no-color" }
477+
ex.stdout.should contain("Outdated shard.lock")
478+
ex.stderr.should be_empty
479+
end
441480
end
442-
end
443481

444-
it "fails to install when dependency requirement (commit) changed" do
445-
metadata = {dependencies: {inprogress: {git: git_url(:inprogress), commit: git_commits(:inprogress)[1]}}}
446-
lock = {inprogress: "0.1.0+git.commit.#{git_commits(:inprogress).first}"}
482+
it "install" do
483+
metadata = {dependencies: {web: "*"}}
484+
lock = {web: "1.0.0"}
447485

448-
with_shard(metadata, lock) do
449-
ex = expect_raises(FailedCommand) { run "shards install --no-color --production" }
450-
ex.stdout.should contain("Outdated shard.lock")
451-
refute_installed "inprogress"
486+
with_shard(metadata, lock) do
487+
run "shards install --#{flag}"
488+
assert_installed "web", "1.0.0"
489+
end
452490
end
453-
end
454491

455-
it "doesn't install new dependencies" do
456-
metadata = {
457-
dependencies: {
458-
web: "~> 1.0.0",
459-
orm: "*",
460-
},
461-
}
462-
lock = {web: "1.0.0"}
492+
it "install with locked commit" do
493+
metadata = {dependencies: {web: "*"}}
494+
web_version = "2.1.0+git.commit.#{git_commits(:web).first}"
495+
lock = {web: web_version}
463496

464-
with_shard(metadata, lock) do
465-
ex = expect_raises(FailedCommand) { run "shards install --production --no-color" }
466-
ex.stdout.should contain("Outdated shard.lock")
467-
ex.stderr.should be_empty
497+
with_shard(metadata, lock) do
498+
run "shards install --#{flag}"
499+
assert_installed "web", "2.1.0", git: git_commits(:web).first
500+
end
468501
end
469-
end
470502

471-
it "install" do
472-
metadata = {dependencies: {web: "*"}}
473-
lock = {web: "1.0.0"}
503+
it "install with locked commit by a previous shards version" do
504+
metadata = {dependencies: {web: "*"}}
474505

475-
with_shard(metadata, lock) do
476-
run "shards install --production"
477-
assert_installed "web", "1.0.0"
506+
with_shard(metadata) do
507+
File.write "shard.lock", {version: "1.0", shards: {web: {git: git_url(:web), commit: git_commits(:web).first}}}
508+
run "shards install --#{flag}"
509+
assert_installed "web", "2.1.0", git: git_commits(:web).first
510+
end
478511
end
479-
end
480512

481-
it "install with locked commit" do
482-
metadata = {dependencies: {web: "*"}}
483-
web_version = "2.1.0+git.commit.#{git_commits(:web).first}"
484-
lock = {web: web_version}
513+
it "fails if lock is not up to date with override in main dependency" do
514+
metadata = {dependencies: {
515+
awesome: "*",
516+
}}
517+
lock = {awesome: "0.1.0", d: "0.1.0"}
518+
override = {dependencies: {
519+
awesome: {git: git_url(:forked_awesome), branch: "feature/super"},
520+
}}
521+
expected_commit = git_commits(:forked_awesome).first
522+
523+
with_shard(metadata, lock, override) do
524+
ex = expect_raises(FailedCommand) { run "shards install --no-color --#{flag}" }
525+
ex.stdout.should contain("Outdated shard.lock")
526+
ex.stderr.should be_empty
527+
refute_installed "awesome"
528+
end
529+
end
485530

486-
with_shard(metadata, lock) do
487-
run "shards install --production"
488-
assert_installed "web", "2.1.0", git: git_commits(:web).first
531+
it "fails if lock is not up to date with override in nested dependency" do
532+
metadata = {dependencies: {
533+
intermediate: "*",
534+
}}
535+
lock = {intermediate: "0.1.0", awesome: "0.1.0", d: "0.1.0"}
536+
override = {dependencies: {
537+
awesome: {git: git_url(:forked_awesome), branch: "feature/super"},
538+
}}
539+
expected_commit = git_commits(:forked_awesome).first
540+
541+
with_shard(metadata, lock, override) do
542+
ex = expect_raises(FailedCommand) { run "shards install --no-color --#{flag}" }
543+
ex.stdout.should contain("Outdated shard.lock")
544+
ex.stderr.should be_empty
545+
refute_installed "awesome"
546+
end
489547
end
490548
end
549+
end
491550

492-
it "install with locked commit by a previous shards version" do
493-
metadata = {dependencies: {web: "*"}}
551+
describe "with --without-development" do
552+
it "doesn't install development dependencies" do
553+
metadata = {
554+
dependencies: {web: "*", orm: "*"},
555+
development_dependencies: {mock: "*"},
556+
}
494557

495558
with_shard(metadata) do
496-
File.write "shard.lock", {version: "1.0", shards: {web: {git: git_url(:web), commit: git_commits(:web).first}}}
497-
run "shards install --production"
498-
assert_installed "web", "2.1.0", git: git_commits(:web).first
499-
end
500-
end
559+
File.exists?(File.join(application_path, "shard.lock")).should be_false
560+
run "shards install --without-development"
501561

502-
it "fails if lock is not up to date with override in main dependency" do
503-
metadata = {dependencies: {
504-
awesome: "*",
505-
}}
506-
lock = {awesome: "0.1.0", d: "0.1.0"}
507-
override = {dependencies: {
508-
awesome: {git: git_url(:forked_awesome), branch: "feature/super"},
509-
}}
510-
expected_commit = git_commits(:forked_awesome).first
511-
512-
with_shard(metadata, lock, override) do
513-
ex = expect_raises(FailedCommand) { run "shards install --no-color --production" }
514-
ex.stdout.should contain("Outdated shard.lock")
515-
ex.stderr.should be_empty
516-
refute_installed "awesome"
517-
end
518-
end
562+
# it installed dependencies (recursively)
563+
assert_installed "web"
564+
assert_installed "orm"
519565

520-
it "fails if lock is not up to date with override in nested dependency" do
521-
metadata = {dependencies: {
522-
intermediate: "*",
523-
}}
524-
lock = {intermediate: "0.1.0", awesome: "0.1.0", d: "0.1.0"}
525-
override = {dependencies: {
526-
awesome: {git: git_url(:forked_awesome), branch: "feature/super"},
527-
}}
528-
expected_commit = git_commits(:forked_awesome).first
566+
# it didn't install development dependencies
567+
refute_installed "mock"
568+
refute_installed "minitest"
529569

530-
with_shard(metadata, lock, override) do
531-
ex = expect_raises(FailedCommand) { run "shards install --no-color --production" }
532-
ex.stdout.should contain("Outdated shard.lock")
533-
ex.stderr.should be_empty
534-
refute_installed "awesome"
570+
File.exists?(File.join(application_path, "shard.lock")).should be_true
535571
end
536572
end
573+
end
537574

575+
describe "with --production" do
538576
it "doesn't install development dependencies" do
539577
metadata = {
540578
dependencies: {web: "*", orm: "*"},

0 commit comments

Comments
 (0)