Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle shared dependencies being required by server dependencies #80

Merged
merged 12 commits into from
Jun 1, 2023
59 changes: 42 additions & 17 deletions src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ pub fn resolve(
// our constraints.
for package_id in &matching_activated {
if dependency_request.package_req.matches_id(package_id) {
resolve.activate(
dependency_request.request_source.clone(),
dependency_request.package_alias.clone(),
dependency_request.request_realm,
package_id.clone(),
);

let metadata = resolve
.metadata
.get_mut(package_id)
Expand All @@ -144,14 +137,22 @@ pub fn resolve(
// with a shared/server origin requires it. This way server/shared dependencies
// which only originate from dev dependencies get put into the dev folder even
// if they usually belong to another realm.
metadata.origin_realm =
match (metadata.origin_realm, dependency_request.origin_realm) {
(_, Realm::Shared) => Realm::Shared,
(Realm::Shared, _) => Realm::Shared,
(_, Realm::Server) => Realm::Server,
(Realm::Server, _) => Realm::Server,
(Realm::Dev, Realm::Dev) => Realm::Dev,
};
let realm_match = match (metadata.origin_realm, dependency_request.origin_realm) {
(_, Realm::Shared) => Realm::Shared,
(Realm::Shared, _) => Realm::Shared,
(_, Realm::Server) => Realm::Server,
(Realm::Server, _) => Realm::Server,
(Realm::Dev, Realm::Dev) => Realm::Dev,
};

metadata.origin_realm = realm_match;

resolve.activate(
dependency_request.request_source.clone(),
dependency_request.package_alias.clone(),
realm_match,
package_id.clone(),
);

continue 'outer;
}
Expand Down Expand Up @@ -228,7 +229,7 @@ pub fn resolve(
resolve.activate(
dependency_request.request_source.clone(),
dependency_request.package_alias.to_owned(),
dependency_request.request_realm,
dependency_request.origin_realm,
candidate_id.clone(),
);

Expand Down Expand Up @@ -383,9 +384,33 @@ mod tests {
fn server_to_shared() -> anyhow::Result<()> {
let registry = InMemoryRegistry::new();
registry.publish(PackageBuilder::new("biff/shared@1.0.0"));
registry.publish(
PackageBuilder::new("biff/server@1.0.0")
.with_realm(Realm::Server)
.with_dep("Shared", "biff/shared@1.0.0"),
);

let root =
PackageBuilder::new("biff/root@1.0.0").with_server_dep("Shared", "biff/shared@1.0.0");
PackageBuilder::new("biff/root@1.0.0").with_server_dep("Server", "biff/server@1.0.0");

test_project(registry, root)
}

/// but... if that shared dependency is required by another shared dependency,
/// (while not being also server-only) it's not server-only anymore.
#[test]
fn server_to_shared_and_shared_to_shared() -> anyhow::Result<()> {
let registry = InMemoryRegistry::new();
registry.publish(PackageBuilder::new("biff/shared@1.0.0"));
registry.publish(
PackageBuilder::new("biff/server@1.0.0")
.with_realm(Realm::Server)
.with_dep("Shared", "biff/shared@1.0.0"),
);

let root = PackageBuilder::new("biff/root@1.0.0")
.with_server_dep("Server", "biff/server@1.0.0")
.with_dep("Shared", "biff/shared@1.0.0");

test_project(registry, root)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@ expression: resolve
---
activated:
- biff/root@1.0.0
- biff/server@1.0.0
- biff/shared@1.0.0
metadata:
biff/root@1.0.0:
realm: shared
origin_realm: shared
source_registry: DefaultRegistry
biff/server@1.0.0:
realm: server
origin_realm: server
source_registry: DefaultRegistry
biff/shared@1.0.0:
realm: shared
origin_realm: server
source_registry: DefaultRegistry
shared_dependencies: {}
server_dependencies:
biff/root@1.0.0:
Server: biff/server@1.0.0
biff/server@1.0.0:
Shared: biff/shared@1.0.0
dev_dependencies: {}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
source: src/resolution.rs
expression: resolve

---
activated:
- biff/root@1.0.0
- biff/server@1.0.0
- biff/shared@1.0.0
metadata:
biff/root@1.0.0:
realm: shared
origin_realm: shared
source_registry: DefaultRegistry
biff/server@1.0.0:
realm: server
origin_realm: server
source_registry: DefaultRegistry
biff/shared@1.0.0:
realm: shared
origin_realm: shared
source_registry: DefaultRegistry
shared_dependencies:
biff/root@1.0.0:
Shared: biff/shared@1.0.0
biff/server@1.0.0:
Shared: biff/shared@1.0.0
server_dependencies:
biff/root@1.0.0:
Server: biff/server@1.0.0
dev_dependencies: {}

6 changes: 6 additions & 0 deletions test-projects/cross-realm-dependency/default.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "cross-realm-dependency",
"tree": {
"$path": "src"
}
}
6 changes: 6 additions & 0 deletions test-projects/cross-realm-dependency/src/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local sdos = require(script.Parent.sdos)

return function()
print("howdy")
sdos()
end
12 changes: 12 additions & 0 deletions test-projects/cross-realm-dependency/wally.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "biff/cross-realm-dependency"
version = "0.1.0"
license = "MIT"
realm = "shared"
registry = "test-registries/primary-registry"

[place]
shared-packages = "game.ReplicatedStorage.Packages"

[server-dependencies]
sdos = "biff/server-depends-on-shared@0.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "cross-realm-explicit-dependency",
"tree": {
"$path": "src"
}
}
7 changes: 7 additions & 0 deletions test-projects/cross-realm-explicit-dependency/src/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
local Minimal = require(script.Parent.Minimal)
local sdos = require(script.Parent.sdos)

return function()
print(Minimal)
sdos()
end
15 changes: 15 additions & 0 deletions test-projects/cross-realm-explicit-dependency/wally.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "biff/cross-realm-explicit-dependency"
version = "0.1.0"
license = "MIT"
realm = "shared"
registry = "test-registries/primary-registry"

[place]
shared-packages = "game.ReplicatedStorage.Packages"

[dependencies]
Minimal = "biff/minimal-shared@0.1.0"

[server-dependencies]
sdos = "biff/server-depends-on-shared@0.1.0"
6 changes: 6 additions & 0 deletions test-projects/minimal-shared/default.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "minimal-shared",
"tree": {
"$path": "src"
}
}
1 change: 1 addition & 0 deletions test-projects/minimal-shared/src/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return "hey"
6 changes: 6 additions & 0 deletions test-projects/minimal-shared/wally.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "biff/minimal-shared"
version = "0.1.0"
license = "MIT"
realm = "shared"
registry = "test-registries/primary-registry"
6 changes: 6 additions & 0 deletions test-projects/server-depends-on-shared/default.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "server-depends-on-shared",
"tree": {
"$path": "src"
}
}
5 changes: 5 additions & 0 deletions test-projects/server-depends-on-shared/src/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
local Minimal = require(script.Parent.Minimal)

return function()
print(Minimal)
end
9 changes: 9 additions & 0 deletions test-projects/server-depends-on-shared/wally.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "biff/server-depends-on-shared"
version = "0.1.0"
license = "MIT"
realm = "server"
registry = "test-registries/primary-registry"

[dependencies]
Minimal = "biff/minimal-shared@0.1.0"
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions test-registries/primary-registry/index/biff/minimal-shared
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"package":{"name":"biff/minimal-shared","version":"0.1.0","registry":"https://github.com/UpliftGames/wally-test-index","realm":"shared","description":null,"license":"MIT","authors":[],"include":[],"exclude":[]},"place":{"shared-packages":null,"server-packages":null},"dependencies":{},"server-dependencies":{},"dev-dependencies":{}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"package":{"name":"biff/server-depends-on-shared","version":"0.1.0","registry":"https://github.com/UpliftGames/wally-test-index","realm":"server","description":null,"license":"MIT","authors":[],"include":[],"exclude":[]},"place":{"shared-packages":null,"server-packages":null},"dependencies":{"Minimal":"biff/minimal-shared@>=0.1.0, <0.2.0"},"server-dependencies":{},"dev-dependencies":{}}
10 changes: 10 additions & 0 deletions tests/integration/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ fn dev_dependency() {
run_test("dev-dependency");
}

#[test]
fn cross_realm_dependency() {
run_test("cross-realm-dependency");
}

#[test]
fn cross_realm_explicit_dependency() {
run_test("cross-realm-explicit-dependency");
}

fn run_test(name: &str) -> TempProject {
let source_project =
Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/test-projects",)).join(name);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
source: tests/integration/install.rs
expression: result

---
ServerPackages:
_Index:
biff_minimal-shared@0.1.0:
minimal-shared:
default.project.json: "{\n \"name\": \"minimal-shared\",\n \"tree\": {\n \"$path\": \"src\"\n }\n}"
src:
init.lua: "return \"hey\""
wally.toml: "[package]\nname = \"biff/minimal-shared\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nrealm = \"shared\"\nregistry = \"test-registries/primary-registry\"\n"
biff_server-depends-on-shared@0.1.0:
Minimal.lua: "return require(script.Parent.Parent[\"biff_minimal-shared@0.1.0\"][\"minimal-shared\"])\n"
server-depends-on-shared:
default.project.json: "{\n \"name\": \"server-depends-on-shared\",\n \"tree\": {\n \"$path\": \"src\"\n }\n}"
src:
init.lua: "local Minimal = require(script.Parent.Minimal)\n\nreturn function()\n\tprint(Minimal)\nend"
wally.toml: "[package]\nname = \"biff/server-depends-on-shared\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nrealm = \"server\"\nregistry = \"test-registries/primary-registry\"\n\n[dependencies]\nMinimal = \"biff/minimal-shared@0.1.0\"\n"
sdos.lua: "return require(script.Parent._Index[\"biff_server-depends-on-shared@0.1.0\"][\"server-depends-on-shared\"])\n"
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/server-depends-on-shared@0.1.0\"]]\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/minimal-shared@0.1.0\"]]\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/server-depends-on-shared@0.1.0\"\n"

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

---
Packages:
Minimal.lua: "return require(script.Parent._Index[\"biff_minimal-shared@0.1.0\"][\"minimal-shared\"])\n"
_Index:
biff_minimal-shared@0.1.0:
minimal-shared:
default.project.json: "{\n \"name\": \"minimal-shared\",\n \"tree\": {\n \"$path\": \"src\"\n }\n}"
src:
init.lua: "return \"hey\""
wally.toml: "[package]\nname = \"biff/minimal-shared\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nrealm = \"shared\"\nregistry = \"test-registries/primary-registry\"\n"
ServerPackages:
_Index:
biff_server-depends-on-shared@0.1.0:
Minimal.lua: "return require(game.ReplicatedStorage.Packages._Index[\"biff_minimal-shared@0.1.0\"][\"minimal-shared\"])\n"
server-depends-on-shared:
default.project.json: "{\n \"name\": \"server-depends-on-shared\",\n \"tree\": {\n \"$path\": \"src\"\n }\n}"
src:
init.lua: "local Minimal = require(script.Parent.Minimal)\n\nreturn function()\n\tprint(Minimal)\nend"
wally.toml: "[package]\nname = \"biff/server-depends-on-shared\"\nversion = \"0.1.0\"\nlicense = \"MIT\"\nrealm = \"server\"\nregistry = \"test-registries/primary-registry\"\n\n[dependencies]\nMinimal = \"biff/minimal-shared@0.1.0\"\n"
sdos.lua: "return require(script.Parent._Index[\"biff_server-depends-on-shared@0.1.0\"][\"server-depends-on-shared\"])\n"
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/minimal-shared@0.1.0\"], [\"sdos\", \"biff/server-depends-on-shared@0.1.0\"]]\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/minimal-shared@0.1.0\"]]\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/minimal-shared@0.1.0\"\n\n[server-dependencies]\nsdos = \"biff/server-depends-on-shared@0.1.0\"\n"