Skip to content

Commit

Permalink
make lockfile correctly grab all dependencies (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
magnalite authored Jun 1, 2023
1 parent c7e3ff3 commit 2b5d94e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
36 changes: 26 additions & 10 deletions src/lockfile.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::BTreeMap;
use std::path::Path;
use std::{
fs::read_to_string,
Expand All @@ -8,6 +9,7 @@ use fs_err::File;
use semver::Version;
use serde::{Deserialize, Serialize};

use crate::package_id;
use crate::{
manifest::Manifest, package_id::PackageId, package_name::PackageName, resolution::Resolve,
};
Expand All @@ -22,6 +24,24 @@ pub struct Lockfile {
pub packages: Vec<LockPackage>,
}

fn grab_dependencies(
package_id: &PackageId,
dependencies: &BTreeMap<
package_id::PackageId,
BTreeMap<std::string::String, package_id::PackageId>,
>,
) -> Vec<(String, PackageId)> {
dependencies
.get(package_id)
.map(|dependencies| {
dependencies
.iter()
.map(|(key, value)| (key.clone(), value.clone()))
.collect()
})
.unwrap_or_else(Vec::new)
}

impl Lockfile {
pub fn from_manifest(manifest: &Manifest) -> Self {
Self {
Expand All @@ -34,16 +54,12 @@ impl Lockfile {
let mut packages = Vec::new();

for package_id in &resolve.activated {
let dependencies = resolve
.shared_dependencies
.get(package_id)
.map(|dependencies| {
dependencies
.iter()
.map(|(key, value)| (key.clone(), value.clone()))
.collect()
})
.unwrap_or_else(Vec::new);
let dependencies = [
grab_dependencies(&package_id, &resolve.shared_dependencies),
grab_dependencies(&package_id, &resolve.server_dependencies),
grab_dependencies(&package_id, &resolve.dev_dependencies),
]
.concat();

packages.push(LockPackage::Registry(RegistryLockPackage {
name: package_id.name().clone(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: tests/integration/install.rs
expression: result

---
DevPackages:
Transitive.lua: "return require(script.Parent._Index[\"biff_transitive-dependency@0.1.0\"][\"transitive-dependency\"])\n"
Expand All @@ -24,6 +23,6 @@ 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\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/minimal\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/one-dependency\"\nversion = \"0.1.0\"\ndependencies = []\n\n[[package]]\nname = \"biff/transitive-dependency\"\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/dev-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"Minimal\", \"biff/minimal@0.1.0\"], [\"One\", \"biff/one-dependency@0.1.0\"], [\"Transitive\", \"biff/transitive-dependency@0.1.0\"]]\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/minimal@0.1.0\"]]\n\n[[package]]\nname = \"biff/transitive-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"OneDependency\", \"biff/one-dependency@0.1.0\"]]\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[server-dependencies]\nMinimal = \"biff/minimal@0.1.0\"\nOne = \"biff/one-dependency@0.1.0\"\n\n[dev-dependencies]\nTransitive = \"biff/transitive-dependency@0.1.0\"\n"

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

---
ServerPackages:
Minimal.lua: "return require(script.Parent._Index[\"biff_minimal@0.1.0\"][\"minimal\"])\n"
Expand All @@ -12,6 +11,6 @@ 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 = []\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 = [[\"Minimal\", \"biff/minimal@0.1.0\"]]\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/minimal@0.1.0\"\n"

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

---
ServerPackages:
Minimal.lua: "return require(script.Parent._Index[\"biff_minimal@0.1.0\"][\"minimal\"])\n"
Expand All @@ -12,6 +11,6 @@ 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 = []\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 = [[\"Minimal\", \"biff/minimal@0.1.0\"]]\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/minimal@0.1.0\""

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

---
ServerPackages:
OneDependency.lua: "return require(script.Parent._Index[\"biff_one-dependency@0.1.0\"][\"one-dependency\"])\n"
Expand All @@ -16,6 +15,6 @@ 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 = []\n\n[[package]]\nname = \"biff/transitive-dependency\"\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[[package]]\nname = \"biff/one-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"Minimal\", \"biff/minimal@0.1.0\"]]\n\n[[package]]\nname = \"biff/transitive-dependency\"\nversion = \"0.1.0\"\ndependencies = [[\"OneDependency\", \"biff/one-dependency@0.1.0\"]]\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/one-dependency@0.1.0\"\n"

0 comments on commit 2b5d94e

Please sign in to comment.