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

[feature] Add support for multiple version of moon in the same machine #1048

Closed
prabirshrestha opened this issue Sep 12, 2023 · 10 comments
Closed
Labels
enhancement New feature or request

Comments

@prabirshrestha
Copy link

I find it ironic that moon support side by side for tons of toolchains but not for moon itself.

moon setup
Error:   × Invalid moon version, unable to proceed. Found 1.13.4, expected =1.12.0.

I'm fan of reproducible builds and lockfiles that locks the version such that even after a decade someone can come and build by project. I set versionConstraint: '=1.12.0'.

This is a pain when working on multiple projects or even same project when different branches having different version. It would be great if versionConstraint is set auto download the correct moon binaries and set it as long as we have at least one moon binary.

@prabirshrestha prabirshrestha added the enhancement New feature or request label Sep 12, 2023
@prabirshrestha
Copy link
Author

Same with proto. Since moon is dependant on proto would be good if it could auto download proto. Is there an equivalent of versionConstraint for proto?

@milesj
Copy link
Collaborator

milesj commented Sep 12, 2023

@prabirshrestha I don't want to build this into moon directly. However, if using proto, you can use the moon plugin: https://moonrepo.dev/docs/install#proto

As for moon depending on proto, moon uses proto's Rust crates directly (https://crates.io/crates/proto_core), and it doesn't use the proto binary. moon will always be fixed to whatever version of the Rust crates it's currently using.

@milesj milesj closed this as completed Sep 12, 2023
@prabirshrestha
Copy link
Author

I highly suggest reconsidering this as it makes it painful to work with moon when using multiple version.

Even when I add .prototools with the following text.

moon = "1.14.0"

[plugins]
moon = "source:https://raw.githubusercontent.com/moonrepo/moon/master/proto-plugin.toml"

It will download and install the tools when using proto use but how do I update the current environment to use moon version from the .prototools file?

@milesj
Copy link
Collaborator

milesj commented Oct 10, 2023

@prabirshrestha It does it automatically at runtime. That's the main feature of proto: https://moonrepo.dev/docs/proto/detection

@prabirshrestha
Copy link
Author

Hmm.. This isn't working for me.

$ cat .prototools
moon = "1.14.0"

[plugins]
moon = "source:https://raw.githubusercontent.com/moonrepo/moon/master/proto-plugin.toml"
$ proto bin moon
/home/prabir/.proto/tools/moon/1.14.0/moon
$ proto run moon -- -V
moon 1.15.0

proto bin points to v1.14 but when I run it points to v1.15. I did install moon globally before I tried proto so not sure if that is the reason but it should still respect the .prototools file.

@milesj
Copy link
Collaborator

milesj commented Oct 10, 2023

Can you paste --log trace output for both bin/run commands.

@prabirshrestha
Copy link
Author

Uninstalling moon and proto globally and removing it from paths and installing proto only and adding it to path seems to have fixed it after restart. Probably some lingering path.

@prabirshrestha
Copy link
Author

Ran into this issue on my mac now that I solved it for linux. Every time I need to update moon it seems to cause issue. Removing proto and moon and restarting didn't solve so stuck here now.

This time I do have a trace.
/Users/prabirshrestha/code/objstor$ proto run moon --log trace -- -V
[DEBUG 2023-10-11 20:24:18] proto  Running proto v0.19.3
[TRACE 20:24:18] starbase::app  Running startup phase with 1 systems
[TRACE 20:24:18] starbase::app  Running analyze phase with 1 systems
[TRACE 20:24:18] starbase::app  Running execute phase with 2 systems
[DEBUG 20:24:18] proto_core::tool_loader:run  Traversing upwards to find a configured plugin  tool="moon"
[DEBUG 20:24:18] proto_core::tools_config:run  Loading .prototools  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:24:18] starbase_utils::fs:run  Opening file  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:24:18] starbase_utils::fs_lock:run  Locking file  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:24:18] starbase_utils::fs_lock:run  Unlocking file  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:24:18] warpgate::loader:run  Creating plugin loader  cache_dir="/Users/prabirshrestha/.proto/plugins"
[TRACE 20:24:18] warpgate::loader:run  Loading plugin moon  plugin="moon" locator="source:https://raw.githubusercontent.com/moonrepo/moon/master/proto-plugin.toml"
[TRACE 20:24:18] warpgate::loader:run  Plugin already downloaded and cached  plugin="moon" path="/Users/prabirshrestha/.proto/plugins/moon-2dda8ed333df7c1b2093634d70a878355b036745c18c868856720588fb649e21.toml"
[DEBUG 20:24:18] proto_core::tool_loader:run  Loading TOML plugin  source="/Users/prabirshrestha/.proto/plugins/moon-2dda8ed333df7c1b2093634d70a878355b036745c18c868856720588fb649e21.toml"
[TRACE 20:24:18] warpgate::loader:run  Loading plugin moon  plugin="moon" locator="source:https://github.com/moonrepo/schema-plugin/releases/latest/download/schema_plugin.wasm"
[TRACE 20:24:18] starbase_utils::fs:run  Reading file metadata  file="/Users/prabirshrestha/.proto/plugins/moon-latest-b3b347506cd8178aefd5cbdaea7f51c143e2f2e612587f5482498fb938ce741a.wasm"
[TRACE 20:24:18] warpgate::loader:run  Plugin already downloaded and cached  plugin="moon" path="/Users/prabirshrestha/.proto/plugins/moon-latest-b3b347506cd8178aefd5cbdaea7f51c143e2f2e612587f5482498fb938ce741a.wasm"
[TRACE 20:24:18] starbase_utils::fs:run  Reading file  file="/Users/prabirshrestha/.proto/plugins/moon-2dda8ed333df7c1b2093634d70a878355b036745c18c868856720588fb649e21.toml"
[TRACE 20:24:18] starbase_utils::toml:run  Parsing TOML  file="/Users/prabirshrestha/.proto/plugins/moon-2dda8ed333df7c1b2093634d70a878355b036745c18c868856720588fb649e21.toml"
[TRACE 20:24:18] proto_core::tool_loader:run  Storing schema settings  schema={"install":{"download-url":"https://github.com/moonrepo/moon/releases/download/v{version}/{download_file}","unpack":false},"name":"moon","platform":{"linux":{"download-file":"moon-{arch}-unknown-linux-{libc}"},"macos":{"download-file":"moon-{arch}-apple-darwin"},"windows":{"download-file":"moon-{arch}-pc-windows-msvc.exe"}},"resolve":{"git-url":"https://github.com/moonrepo/moon"},"type":"cli"}
[TRACE 20:24:18] proto_core::tool_loader:run  Storing tool identifier  id="moon"
[TRACE 20:24:18] proto_core::tool_loader:run  Storing user configuration  config={"auto_clean":false,"auto_install":false,"node_intercept_globals":true}
[TRACE 20:24:18] proto_core::tool_loader:run  Storing proto environment  env={"arch":"x64","os":"macos","home_dir":{"path":"/home/","virtual_prefix":"/home","real_prefix":"/Users/prabirshrestha"},"proto_dir":{"path":"/home/.proto","virtual_prefix":"/home","real_prefix":"/Users/prabirshrestha"}}
[DEBUG 20:24:18] proto_core::tool:run  Creating tool moon and instantiating plugin
[DEBUG 20:24:18] proto_core::tool_manifest:run:load  Loading manifest.json  file="/Users/prabirshrestha/.proto/tools/moon/manifest.json"
[TRACE 20:24:18] starbase_utils::fs:run:load  Opening file  file="/Users/prabirshrestha/.proto/tools/moon/manifest.json"
[TRACE 20:24:18] starbase_utils::fs_lock:run:load  Locking file  file="/Users/prabirshrestha/.proto/tools/moon/manifest.json"
[TRACE 20:24:18] starbase_utils::fs_lock:run:load  Unlocking file  file="/Users/prabirshrestha/.proto/tools/moon/manifest.json"
[DEBUG 20:24:20] proto_core::tool:run  Created tool moon and its WASM runtime
[TRACE 20:24:20] warpgate::plugin:run  Calling plugin function register_tool  plugin="moon" input={"id":"moon"}
[TRACE 20:24:20] warpgate::plugin:run  Called plugin function register_tool  plugin="moon" output={"env_vars":[],"inventory":{"disable_progress_bars":false},"name":"moon","plugin_version":"0.3.3","type_of":"CLI"}
[TRACE 20:24:20] proto_core::version_detector:run  Attempting to find local version from config files  tool="moon"
[TRACE 20:24:20] proto_core::version_detector:run  Checking directory  tool="moon" dir="/Users/prabirshrestha/code/objstor"
[DEBUG 20:24:20] proto_core::tools_config:run  Loading .prototools  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:24:20] starbase_utils::fs:run  Opening file  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:24:20] starbase_utils::fs_lock:run  Locking file  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:24:20] starbase_utils::fs_lock:run  Unlocking file  file="/Users/prabirshrestha/code/objstor/.prototools"
[DEBUG 20:24:20] proto_core::version_detector:run  Detected version from .prototools file  tool="moon" version=Version(Version { major: 1, minor: 15, patch: 1 }) file="/Users/prabirshrestha/code/objstor/.prototools"
[DEBUG 20:24:20] proto_core::tool:run  Resolving a semantic version or alias  tool="moon" initial_version="1.15.1"
[DEBUG 20:24:20] proto_core::tool:run  Loading available versions  tool="moon"
[TRACE 20:24:20] starbase_utils::fs:run  Reading file metadata  file="/Users/prabirshrestha/.proto/tools/moon/remote-versions.json"
[DEBUG 20:24:20] proto_core::tool:run  Loading from local cache  tool="moon" cache="/Users/prabirshrestha/.proto/tools/moon/remote-versions.json"
[TRACE 20:24:20] starbase_utils::fs:run  Opening file  file="/Users/prabirshrestha/.proto/tools/moon/remote-versions.json"
[TRACE 20:24:20] starbase_utils::fs_lock:run  Locking file  file="/Users/prabirshrestha/.proto/tools/moon/remote-versions.json"
/Users/prabirshrestha/code/objstor$ proto run moon --log trace -- -V
[DEBUG 2023-10-11 20:25:25] proto  Running proto v0.19.3
[TRACE 20:25:25] starbase::app  Running startup phase with 1 systems
[TRACE 20:25:25] starbase::app  Running analyze phase with 1 systems
[TRACE 20:25:25] starbase::app  Running execute phase with 2 systems
[DEBUG 20:25:25] proto_core::tool_loader:run  Traversing upwards to find a configured plugin  tool="moon"
[DEBUG 20:25:25] proto_core::tools_config:run  Loading .prototools  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:25:25] starbase_utils::fs:run  Opening file  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:25:25] starbase_utils::fs_lock:run  Locking file  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:25:25] starbase_utils::fs_lock:run  Unlocking file  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:25:26] warpgate::loader:run  Creating plugin loader  cache_dir="/Users/prabirshrestha/.proto/plugins"
[TRACE 20:25:26] warpgate::loader:run  Loading plugin moon  plugin="moon" locator="source:https://raw.githubusercontent.com/moonrepo/moon/master/proto-plugin.toml"
[TRACE 20:25:26] warpgate::loader:run  Plugin already downloaded and cached  plugin="moon" path="/Users/prabirshrestha/.proto/plugins/moon-2dda8ed333df7c1b2093634d70a878355b036745c18c868856720588fb649e21.toml"
[DEBUG 20:25:26] proto_core::tool_loader:run  Loading TOML plugin  source="/Users/prabirshrestha/.proto/plugins/moon-2dda8ed333df7c1b2093634d70a878355b036745c18c868856720588fb649e21.toml"
[TRACE 20:25:26] warpgate::loader:run  Loading plugin moon  plugin="moon" locator="source:https://github.com/moonrepo/schema-plugin/releases/latest/download/schema_plugin.wasm"
[TRACE 20:25:26] starbase_utils::fs:run  Reading file metadata  file="/Users/prabirshrestha/.proto/plugins/moon-latest-b3b347506cd8178aefd5cbdaea7f51c143e2f2e612587f5482498fb938ce741a.wasm"
[TRACE 20:25:26] warpgate::loader:run  Plugin already downloaded and cached  plugin="moon" path="/Users/prabirshrestha/.proto/plugins/moon-latest-b3b347506cd8178aefd5cbdaea7f51c143e2f2e612587f5482498fb938ce741a.wasm"
[TRACE 20:25:26] starbase_utils::fs:run  Reading file  file="/Users/prabirshrestha/.proto/plugins/moon-2dda8ed333df7c1b2093634d70a878355b036745c18c868856720588fb649e21.toml"
[TRACE 20:25:26] starbase_utils::toml:run  Parsing TOML  file="/Users/prabirshrestha/.proto/plugins/moon-2dda8ed333df7c1b2093634d70a878355b036745c18c868856720588fb649e21.toml"
[TRACE 20:25:26] proto_core::tool_loader:run  Storing schema settings  schema={"install":{"download-url":"https://github.com/moonrepo/moon/releases/download/v{version}/{download_file}","unpack":false},"name":"moon","platform":{"linux":{"download-file":"moon-{arch}-unknown-linux-{libc}"},"macos":{"download-file":"moon-{arch}-apple-darwin"},"windows":{"download-file":"moon-{arch}-pc-windows-msvc.exe"}},"resolve":{"git-url":"https://github.com/moonrepo/moon"},"type":"cli"}
[TRACE 20:25:26] proto_core::tool_loader:run  Storing tool identifier  id="moon"
[TRACE 20:25:26] proto_core::tool_loader:run  Storing user configuration  config={"auto_clean":false,"auto_install":false,"node_intercept_globals":true}
[TRACE 20:25:26] proto_core::tool_loader:run  Storing proto environment  env={"arch":"x64","os":"macos","home_dir":{"path":"/home/","virtual_prefix":"/home","real_prefix":"/Users/prabirshrestha"},"proto_dir":{"path":"/home/.proto","virtual_prefix":"/home","real_prefix":"/Users/prabirshrestha"}}
[DEBUG 20:25:26] proto_core::tool:run  Creating tool moon and instantiating plugin
[DEBUG 20:25:26] proto_core::tool_manifest:run:load  Loading manifest.json  file="/Users/prabirshrestha/.proto/tools/moon/manifest.json"
[TRACE 20:25:26] starbase_utils::fs:run:load  Opening file  file="/Users/prabirshrestha/.proto/tools/moon/manifest.json"
[TRACE 20:25:26] starbase_utils::fs_lock:run:load  Locking file  file="/Users/prabirshrestha/.proto/tools/moon/manifest.json"
[TRACE 20:25:26] starbase_utils::fs_lock:run:load  Unlocking file  file="/Users/prabirshrestha/.proto/tools/moon/manifest.json"
[DEBUG 20:25:27] proto_core::tool:run  Created tool moon and its WASM runtime
[TRACE 20:25:27] warpgate::plugin:run  Calling plugin function register_tool  plugin="moon" input={"id":"moon"}
[TRACE 20:25:27] warpgate::plugin:run  Called plugin function register_tool  plugin="moon" output={"env_vars":[],"inventory":{"disable_progress_bars":false},"name":"moon","plugin_version":"0.3.3","type_of":"CLI"}
[TRACE 20:25:27] proto_core::version_detector:run  Attempting to find local version from config files  tool="moon"
[TRACE 20:25:27] proto_core::version_detector:run  Checking directory  tool="moon" dir="/Users/prabirshrestha/code/objstor"
[DEBUG 20:25:27] proto_core::tools_config:run  Loading .prototools  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:25:27] starbase_utils::fs:run  Opening file  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:25:27] starbase_utils::fs_lock:run  Locking file  file="/Users/prabirshrestha/code/objstor/.prototools"
[TRACE 20:25:27] starbase_utils::fs_lock:run  Unlocking file  file="/Users/prabirshrestha/code/objstor/.prototools"
[DEBUG 20:25:27] proto_core::version_detector:run  Detected version from .prototools file  tool="moon" version=Version(Version { major: 1, minor: 15, patch: 1 }) file="/Users/prabirshrestha/code/objstor/.prototools"
[DEBUG 20:25:27] proto_core::tool:run  Resolving a semantic version or alias  tool="moon" initial_version="1.15.1"
[DEBUG 20:25:27] proto_core::tool:run  Loading available versions  tool="moon"
[TRACE 20:25:27] starbase_utils::fs:run  Reading file metadata  file="/Users/prabirshrestha/.proto/tools/moon/remote-versions.json"
[DEBUG 20:25:27] proto_core::tool:run  Loading from local cache  tool="moon" cache="/Users/prabirshrestha/.proto/tools/moon/remote-versions.json"
[TRACE 20:25:27] starbase_utils::fs:run  Opening file  file="/Users/prabirshrestha/.proto/tools/moon/remote-versions.json"
[TRACE 20:25:27] starbase_utils::fs_lock:run  Locking file  file="/Users/prabirshrestha/.proto/tools/moon/remote-versions.json"
[TRACE 20:25:27] starbase_utils::fs_lock:run  Unlocking file  file="/Users/prabirshrestha/.proto/tools/moon/remote-versions.json"
[DEBUG 20:25:27] proto_core::tool:run  Resolved to 1.15.1  tool="moon" version="1.15.1"
[DEBUG 20:25:27] proto_core::tool:run  Checking if tool is installed  tool="moon" install_dir="/Users/prabirshrestha/.proto/tools/moon/1.15.1"
[DEBUG 20:25:27] proto_core::tool:run  Tool has already been installed, locating binaries and shims  tool="moon" install_dir="/Users/prabirshrestha/.proto/tools/moon/1.15.1"
[DEBUG 20:25:27] proto_core::tool:run  Locating binaries for tool  tool="moon"
[TRACE 20:25:27] warpgate::plugin:run  Calling plugin function locate_bins  plugin="moon" input={"context":{"env_vars":{},"tool_dir":{"path":"/home/.proto/tools/moon/1.15.1","virtual_prefix":"/home","real_prefix":"/Users/prabirshrestha"},"version":"1.15.1"}}
[TRACE 20:25:27] warpgate::plugin:run  Called plugin function locate_bins  plugin="moon" output={"bin_path":"moon","fallback_last_globals_dir":true,"globals_lookup_dirs":[]}
[DEBUG 20:25:27] proto_core::tool:run  Found a potential binary  tool="moon" bin_path="/Users/prabirshrestha/.proto/tools/moon/1.15.1/moon"
[TRACE 20:25:27] warpgate::plugin:run  Calling plugin function create_shims  plugin="moon" input={"context":{"env_vars":{},"tool_dir":{"path":"/home/.proto/tools/moon/1.15.1","virtual_prefix":"/home","real_prefix":"/Users/prabirshrestha"},"version":"1.15.1"}}
[TRACE 20:25:27] warpgate::plugin:run  Called plugin function create_shims  plugin="moon" output={"no_primary_global":false,"global_shims":{},"local_shims":{}}
[DEBUG 20:25:27] proto::commands::run:run  Running moon  bin="/Users/prabirshrestha/.proto/tools/moon/1.15.1/moon" args=["-V"]
moon 1.14.0
[TRACE 20:25:27] starbase::app  Running shutdown phase with 1 systems
[DEBUG 20:25:27] proto_core::tool_manifest:save  Saving manifest  file="/Users/prabirshrestha/.proto/tools/moon/manifest.json"
[TRACE 20:25:27] starbase_utils::fs_lock:save  Locking file exclusively  file="/Users/prabirshrestha/.proto/tools/moon/manifest.json"
[TRACE 20:25:27] starbase_utils::fs_lock:save  Writing file  file="/Users/prabirshrestha/.proto/tools/moon/manifest.json"
[TRACE 20:25:27] starbase_utils::fs_lock:save  Unlocking file exclusively  file="/Users/prabirshrestha/.proto/tools/moon/manifest.json"

Interesting part seems to this where it does locate moon 1.15.1 but seems to print 1.14.0 instead.

[DEBUG 20:25:27] proto::commands::run:run  Running moon  bin="/Users/prabirshrestha/.proto/tools/moon/1.15.1/moon" args=["-V"]
moon 1.14.0
But if I got to the 1.15.1 directory it does print it correctly.
/Users/prabirshrestha/code/objstor$cat .prototools
moon = "1.15.1"

[plugins]
moon = "source:https://raw.githubusercontent.com/moonrepo/moon/master/proto-plugin.toml"
/Users/prabirshrestha/code/objstor$ moon --version
moon 1.14.0
/Users/prabirshrestha/code/objstor$ proto run moon -- --version
moon 1.14.0
/Users/prabirshrestha/code/objstor$ which moon
/Users/prabirshrestha/.proto/bin/moon
/Users/prabirshrestha/code/objstor$ cat /Users/prabirshrestha/.proto/bin/moon
#!/usr/bin/env bash
set -e
[ -n "$PROTO_DEBUG" ] && set -x



exec proto run moon --  "$@"

/Users/prabirshrestha/code/objstor$ cd /Users/prabirshrestha/.proto/tools/moon/1.15.1
/Users/prabirshrestha/.proto/tools/moon/1.15.1$ ./moon --version
moon 1.15.1

@prabirshrestha
Copy link
Author

I found the issue and here is the repro steps. This seems primarily an issue when you have pacakge.json in root with has "@moonrepo/cli": "^1.14.0"

  1. I have a repro with moon globally and in package.json installed with v1.14 in machine A.
  2. I clone the repro in machine B.
  3. Build works fine in machine A and B.
  4. Update moon in machine B with moon 1.15.1 globally and in package.json.
  5. Go to machine A pull the latest. Install moon 1.15.1 globally. (Do not run npm install)
  6. Build in machine A fails.

Reason for this is I forget to do npm install in machine A after the latest pull, so even though I only have latest moon 1.15.1 installed, it pickups moon 1.14 from my old npm_modules folder.

This was when I was trying to make it easy to use moon. For now I'm removing moon cli from the package.json so it always picks up whatever .protoools file has. Might be --log trace should have logs on this. In this case since the moon binary is getting loaded from node_modules/.bin/moon when running pnpm build and by passes proto.

{
   "scripts": {
    "dev": "moon run dev",
    "build": "moon run build"
   },
  "devDependencies": {
    "@moonrepo/cli": "^1.15.1"
  }
}

@milesj
Copy link
Collaborator

milesj commented Oct 12, 2023

Yeah this is by design. The @moonrepo/cli dep always takes highest precedence since that's what the "repo is locked to".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants