mops icon indicating copy to clipboard operation
mops copied to clipboard

Install a Mops package under a different name?

Open rvanasa opened this issue 10 months ago • 3 comments

For the new Motoko base library, we would like to encourage developers to import new-base under the alias base, which is possible using a GitHub URL but seemingly not yet for other Mops packages.

Would it be feasible to add support for the following pattern (or something equivalent)?

base = "[email protected]"

This would fill the role of the { package = "..." } syntax in cargo.toml and npm: prefix in package.json.

rvanasa avatar Feb 28 '25 20:02 rvanasa

we would like to encourage developers to import new-base under the alias base

What is the reason for this approach? Is this temporary solution?

This is prohibited because the same package must be under the same name, so devs cannot publish a package with dep base = "[email protected]" which would be an alias of base for a completely different package and thus break other dependent code.

What if encourage devs to pin(https://docs.mops.one/dependency-version-pinning#use-case-2) base package to major version and make base package to follow semver?

[dependencies]
base = "0.14.1"
"base@1" = "1.1.0"

Here old code will work with old base, and new code can import new base like this import Nat "mo:base@1/Nat"

with

base = "[email protected]"

other packages expecting old base will fail

ZenVoich avatar Mar 01 '25 09:03 ZenVoich

"base@1" = "1.1.0"

This could be a good pattern for us to encourage for the base library.

base = "[email protected]"

I see what you're saying for the base library. In general, this feature might be useful when having an unmaintained package that you'd want to replace with a newer package which has the same interface.

Perhaps the best alternative is that we could support importing multiple versions of a package in the compiler as you suggested a while ago in https://github.com/dfinity/motoko/issues/3971. Would this feature still be useful for Mops?

rvanasa avatar Mar 02 '25 17:03 rvanasa

In general, this feature might be useful when having an unmaintained package that you'd want to replace with a newer package which has the same interface.

If you want to replace that package in your project, you can just use newer package and replace imports in your code to a new package name.

Perhaps the best alternative is that we could support importing multiple versions of a package in the compiler as you suggested a while ago in dfinity/motoko#3971. Would this feature still be useful for Mops?

This could be useful to eliminate major version pinning, so Mops could always resolve latest minor/patch version for each major version of a package.

For example package A:

base = "0.14.0"

package B:

base = "0.15.0"

a project:

b = "1.0.0"
a = "1.0.0"
base = "1.1.0"

here Mops could resolve base 0.15.0 for A and B, and base 1.1.0 for root project.

Currently dev have to pin base to name base@1 or [email protected] to avoid conflicts:

b = "1.0.0"
a = "1.0.0"
"base@1" = "1.1.0"

ZenVoich avatar Mar 03 '25 08:03 ZenVoich