Skip to content

Commit

Permalink
Pretty-print wally.lock (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
LouieK22 authored Jan 2, 2025
1 parent e625a04 commit 2c928d9
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## Unreleased Changes
* Added --locked flag for the install subcommand ([#119])
* Improved lockfile formatting for better text diffs ([#214])

[#119]: https://github.com/UpliftGames/wally/pull/119
[#214]: https://github.com/UpliftGames/wally/pull/214

## 0.3.2 (2023-06-05)
* Added private field to package manifest ([#9])([#76])
Expand Down
47 changes: 45 additions & 2 deletions src/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,55 @@ impl Lockfile {

pub fn save(&self, project_path: &Path) -> anyhow::Result<()> {
let lockfile_path = project_path.join(LOCKFILE_NAME);
let serialized = toml::to_string(self)?;

let mut file = BufWriter::new(File::create(lockfile_path)?);
writeln!(file, "# This file is automatically @generated by Wally.")?;
writeln!(file, "# It is not intended for manual editing.")?;
write!(file, "{}", serialized)?;
writeln!(file, "registry = \"{}\"", self.registry)?;
writeln!(file, "")?;

for lock_package in self.packages.iter() {
writeln!(file, "[[package]]")?;

match lock_package {
LockPackage::Registry(registry_lock_package) => {
writeln!(file, "name = \"{}\"", registry_lock_package.name)?;
writeln!(file, "version = \"{}\"", registry_lock_package.version)?;

if let Some(checksum) = &registry_lock_package.checksum {
writeln!(file, "checksum = \"{}\"", checksum)?;
}

if registry_lock_package.dependencies.len() == 0 {
writeln!(file, "dependencies = []")?;
} else {
writeln!(file, "dependencies = [")?;
for dependency in registry_lock_package.dependencies.iter() {
writeln!(file, "\t[\"{}\", \"{}\"],", dependency.0, dependency.1)?;
}
writeln!(file, "]")?;
}
}
LockPackage::Git(git_lock_package) => {
writeln!(file, "name = \"{}\"", git_lock_package.name)?;
writeln!(file, "rev = \"{}\"", git_lock_package.rev)?;
writeln!(file, "commit = \"{}\"", git_lock_package.commit)?;

if git_lock_package.dependencies.len() == 0 {
writeln!(file, "dependencies = []")?;
} else {
writeln!(file, "dependencies = [")?;
for dependency in git_lock_package.dependencies.iter() {
writeln!(file, "\t\"{}\",", dependency)?;
}
writeln!(file, "]")?;
}
}
}

writeln!(file, "")?;
}

file.flush()?;

Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: tests/integration/install.rs
expression: result

snapshot_kind: text
---
ServerPackages:
_Index:
Expand All @@ -22,6 +22,5 @@ ServerPackages:
default.project.json: "{\n\t\"name\": \"cross-realm-dependency\",\n\t\"tree\": {\n\t\t\"$path\": \"src\"\n\t}\n}"
src:
init.lua: "local sdos = require(script.Parent.sdos)\n\nreturn function()\n\tprint(\"howdy\")\n\tsdos()\nend\n"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/cross-realm-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"sdos\", \"biff/[email protected]\"]]\n\n[[package]]\nname = \"biff/minimal-shared\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/server-depends-on-shared\"\nversion = \"0.1.0\"\ndependencies = [[\"Minimal\", \"biff/[email protected]\"]]\n"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/cross-realm-dependency\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"sdos\", \"biff/[email protected]\"],\n]\n\n[[package]]\nname = \"biff/minimal-shared\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/server-depends-on-shared\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"Minimal\", \"biff/[email protected]\"],\n]\n\n"
wally.toml: "[package]\nname = \"biff/cross-realm-dependency\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nrealm = \"shared\"\nregistry = \"test-registries/primary-registry\"\n\n[place]\nshared-packages = \"game.ReplicatedStorage.Packages\"\n\n[server-dependencies]\nsdos = \"biff/[email protected]\"\n"

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: tests/integration/install.rs
expression: result

snapshot_kind: text
---
Packages:
Minimal.lua: "return require(script.Parent._Index[\"[email protected]\"][\"minimal-shared\"])\n"
Expand All @@ -25,6 +25,5 @@ ServerPackages:
default.project.json: "{\n\t\"name\": \"cross-realm-explicit-dependency\",\n\t\"tree\": {\n\t\t\"$path\": \"src\"\n\t}\n}"
src:
init.lua: "local Minimal = require(script.Parent.Minimal)\nlocal sdos = require(script.Parent.sdos)\n\nreturn function()\n\tprint(Minimal)\n\tsdos()\nend"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/cross-realm-explicit-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"Minimal\", \"biff/[email protected]\"], [\"sdos\", \"biff/[email protected]\"]]\n\n[[package]]\nname = \"biff/minimal-shared\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/server-depends-on-shared\"\nversion = \"0.1.0\"\ndependencies = [[\"Minimal\", \"biff/[email protected]\"]]\n"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/cross-realm-explicit-dependency\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"Minimal\", \"biff/[email protected]\"],\n\t[\"sdos\", \"biff/[email protected]\"],\n]\n\n[[package]]\nname = \"biff/minimal-shared\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/server-depends-on-shared\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"Minimal\", \"biff/[email protected]\"],\n]\n\n"
wally.toml: "[package]\nname = \"biff/cross-realm-explicit-dependency\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nrealm = \"shared\"\nregistry = \"test-registries/primary-registry\"\n\n[place]\nshared-packages = \"game.ReplicatedStorage.Packages\"\n\n[dependencies]\nMinimal = \"biff/[email protected]\"\n\n[server-dependencies]\nsdos = \"biff/[email protected]\"\n"

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: tests/integration/install.rs
expression: result
snapshot_kind: text
---
DevPackages:
Transitive.lua: "return require(script.Parent._Index[\"[email protected]\"][\"transitive-dependency\"])\n"
Expand All @@ -19,6 +20,5 @@ DevPackages:
default.project.json: "{\n\t\"name\": \"dev-dependency\",\n\t\"tree\": {\n\t\t\"$path\": \"src\"\n\t}\n}"
src:
init.lua: "local Minimal = require(script.Parent.Minimal)\n\nreturn function()\n\tprint(Minimal)\nend"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/dev-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"Transitive\", \"biff/[email protected]\"]]\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/one-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"Minimal\", \"biff/[email protected]\"]]\n\n[[package]]\nname = \"biff/transitive-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"OneDependency\", \"biff/[email protected]\"]]\n"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/dev-dependency\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"Transitive\", \"biff/[email protected]\"],\n]\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/one-dependency\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"Minimal\", \"biff/[email protected]\"],\n]\n\n[[package]]\nname = \"biff/transitive-dependency\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"OneDependency\", \"biff/[email protected]\"],\n]\n\n"
wally.toml: "[package]\nname = \"biff/dev-dependency\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nrealm = \"server\"\nregistry = \"test-registries/primary-registry\"\n\n[place]\nserver-packages = \"game.ServerScriptStorage.Packages\"\n\n[dev-dependencies]\nTransitive = \"biff/[email protected]\"\n"

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: tests/integration/install.rs
expression: result
snapshot_kind: text
---
DevPackages:
Minimal.lua: "return require(game.ServerScriptStorage.Packages._Index[\"[email protected]\"][\"minimal\"])\n"
Expand All @@ -21,6 +22,5 @@ ServerPackages:
default.project.json: "{\n\t\"name\": \"dev-dependency\",\n\t\"tree\": {\n\t\t\"$path\": \"src\"\n\t}\n}"
src:
init.lua: "local Minimal = require(script.Parent.Minimal)\n\nreturn function()\n\tprint(Minimal)\nend"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/dev-dependency-also-required-as-non-dev\"\nversion = \"0.1.0\"\ndependencies = [[\"Transitive\", \"biff/[email protected]\"], [\"Minimal\", \"biff/[email protected]\"]]\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/one-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"Minimal\", \"biff/[email protected]\"]]\n\n[[package]]\nname = \"biff/transitive-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"OneDependency\", \"biff/[email protected]\"]]\n"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/dev-dependency-also-required-as-non-dev\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"Transitive\", \"biff/[email protected]\"],\n\t[\"Minimal\", \"biff/[email protected]\"],\n]\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/one-dependency\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"Minimal\", \"biff/[email protected]\"],\n]\n\n[[package]]\nname = \"biff/transitive-dependency\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"OneDependency\", \"biff/[email protected]\"],\n]\n\n"
wally.toml: "[package]\nname = \"biff/dev-dependency-also-required-as-non-dev\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nrealm = \"server\"\nregistry = \"test-registries/primary-registry\"\n\n[place]\nserver-packages = \"game.ServerScriptStorage.Packages\"\n\n[server-dependencies]\nTransitive = \"biff/[email protected]\"\n\n[dev-dependencies]\nMinimal = \"biff/[email protected]\"\n"

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
---
source: tests/integration/install.rs
expression: result
snapshot_kind: text
---
default.project.json: "{\n \"name\": \"minimal\",\n \"tree\": {\n \"$path\": \"src\"\n }\n}"
src:
init.luau: "return \"hey\"\n"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n\n"
wally.toml: "[package]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nrealm = \"server\"\nregistry = \"test-registries/primary-registry\"\nrepository = \"https://github.com/UpliftGames/player-module.git\"\nhomepage = \"https://github.com/UpliftGames/player-module\"\n"
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
---
source: tests/integration/install.rs
expression: result

snapshot_kind: text
---
default.project.json: "{\n\t\"name\": \"minimal\",\n\t\"tree\": {\n\t\t\"$path\": \"src\"\n\t}\n}"
src:
init.lua: "return \"hey\""
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n\n"
wally.toml: "[package]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nrealm = \"server\"\nregistry = \"test-registries/primary-registry\"\n"

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: tests/integration/install.rs
expression: result
snapshot_kind: text
---
ServerPackages:
Minimal.lua: "return require(script.Parent._Index[\"[email protected]\"][\"minimal\"])\n"
Expand All @@ -11,6 +12,5 @@ ServerPackages:
default.project.json: "{\n\t\"name\": \"one-dependency\",\n\t\"tree\": {\n\t\t\"$path\": \"src\"\n\t}\n}"
src:
init.lua: "local Minimal = require(script.Parent.Minimal)\n\nreturn function()\n\tprint(Minimal)\nend"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/one-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"Minimal\", \"biff/[email protected]\"]]\n"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/one-dependency\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"Minimal\", \"biff/[email protected]\"],\n]\n\n"
wally.toml: "[package]\nname = \"biff/one-dependency\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nrealm = \"server\"\nregistry = \"test-registries/primary-registry\"\n\n[server-dependencies]\nMinimal = \"biff/[email protected]\"\n"

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: tests/integration/install.rs
expression: result
snapshot_kind: text
---
ServerPackages:
Minimal.lua: "return require(script.Parent._Index[\"[email protected]\"][\"minimal\"])\n"
Expand All @@ -11,6 +12,5 @@ ServerPackages:
default.project.json: "{\n\t\"name\": \"private-with-public-dependency\",\n\t\"tree\": {\n\t\t\"$path\": \"src\"\n\t}\n}"
src:
init.lua: "return \"I'm private\""
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"private/private-with-public-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"Minimal\", \"biff/[email protected]\"]]\n"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"private/private-with-public-dependency\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"Minimal\", \"biff/[email protected]\"],\n]\n\n"
wally.toml: "[package]\nname = \"private/private-with-public-dependency\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nrealm = \"server\"\nregistry = \"test-registries/tertiary-registry\"\n\n[server-dependencies]\nMinimal = \"biff/[email protected]\""

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: tests/integration/install.rs
expression: result
snapshot_kind: text
---
ServerPackages:
OneDependency.lua: "return require(script.Parent._Index[\"[email protected]\"][\"one-dependency\"])\n"
Expand All @@ -15,6 +16,5 @@ ServerPackages:
default.project.json: "{\n\t\"name\": \"transitive-dependency\",\n\t\"tree\": {\n\t\t\"$path\": \"src\"\n\t}\n}"
src:
init.lua: "local OneDependency = require(script.Parent.OneDependency)\n\nreturn function()\n\treturn OneDependency()\nend"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/one-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"Minimal\", \"biff/[email protected]\"]]\n\n[[package]]\nname = \"biff/transitive-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"OneDependency\", \"biff/[email protected]\"]]\n"
wally.lock: "# This file is automatically @generated by Wally.\n# It is not intended for manual editing.\nregistry = \"test\"\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/one-dependency\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"Minimal\", \"biff/[email protected]\"],\n]\n\n[[package]]\nname = \"biff/transitive-dependency\"\nversion = \"0.1.0\"\ndependencies = [\n\t[\"OneDependency\", \"biff/[email protected]\"],\n]\n\n"
wally.toml: "[package]\nname = \"biff/transitive-dependency\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nrealm = \"server\"\nregistry = \"test-registries/primary-registry\"\n\n[server-dependencies]\nOneDependency = \"biff/[email protected]\"\n"

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: tests/integration/update.rs
expression: lockfile
snapshot_kind: text
---
# This file is automatically @generated by Wally.
# It is not intended for manual editing.
Expand All @@ -9,12 +10,16 @@ registry = "test"
[[package]]
name = "diamond-graph/direct-dependency-a"
version = "0.1.1"
dependencies = [["Indirect", "diamond-graph/[email protected]"]]
dependencies = [
["Indirect", "diamond-graph/[email protected]"],
]

[[package]]
name = "diamond-graph/direct-dependency-b"
version = "0.1.0"
dependencies = [["Indirect", "diamond-graph/[email protected]"]]
dependencies = [
["Indirect", "diamond-graph/[email protected]"],
]

[[package]]
name = "diamond-graph/indirect-dependency-a"
Expand All @@ -29,5 +34,7 @@ dependencies = []
[[package]]
name = "diamond-graph/root"
version = "0.1.0"
dependencies = [["A", "diamond-graph/[email protected]"], ["B", "diamond-graph/[email protected]"]]

dependencies = [
["A", "diamond-graph/[email protected]"],
["B", "diamond-graph/[email protected]"],
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: tests/integration/update.rs
expression: lockfile_content
snapshot_kind: text
---
# This file is automatically @generated by Wally.
# It is not intended for manual editing.
Expand All @@ -9,12 +10,16 @@ registry = "test"
[[package]]
name = "diamond-graph/direct-dependency-a"
version = "0.1.1"
dependencies = [["Indirect", "diamond-graph/[email protected]"]]
dependencies = [
["Indirect", "diamond-graph/[email protected]"],
]

[[package]]
name = "diamond-graph/direct-dependency-b"
version = "0.1.0"
dependencies = [["Indirect", "diamond-graph/[email protected]"]]
dependencies = [
["Indirect", "diamond-graph/[email protected]"],
]

[[package]]
name = "diamond-graph/indirect-dependency-a"
Expand All @@ -29,5 +34,7 @@ dependencies = []
[[package]]
name = "diamond-graph/root"
version = "0.1.0"
dependencies = [["A", "diamond-graph/[email protected]"], ["B", "diamond-graph/[email protected]"]]

dependencies = [
["A", "diamond-graph/[email protected]"],
["B", "diamond-graph/[email protected]"],
]
Loading

0 comments on commit 2c928d9

Please sign in to comment.