pkgxdev / pkgx

the last thing you’ll install
https://pkgx.sh
Apache License 2.0
8.81k stars 1.36k forks source link

Pkgx downloaded the wrong version of Go into the right folder #983

Closed fredrikaverpil closed 4 months ago

fredrikaverpil commented 4 months ago

I've defined a project to use go 1.21 via pkgx.yaml, but pkgx still uses go 1.22.

❯ pkgx --version
pkgx 1.1.6

❯ go version
^^ type `x` to run that

❯ cat myproj/pkgx.yaml
dependencies:
  - go@1.21

❯ cd myproj
env +go.dev~1.21 +git-scm.org

❯ go version
go version go1.22.1 darwin/arm64

❯ which go
/Users/fredrik/.pkgx/go.dev/v1.21.8/bin/go

I ran rm -rf /Users/fredrik/.pkgx/go.dev and re-downloaded it all, but it ended up doing the same thing. I also tried adding a patch version in pkgx.yaml:

❯ cat myproj/pkgx.yaml
dependencies:
  - go@1.21.5

❯ cd myproj
 ✓  ~/.pkgx/go.dev/v1.21.5
env +go.dev@1.21.5 +git-scm.org

❯ go version
go version go1.22.1 darwin/arm64

❯ which go
/Users/fredrik/.pkgx/go.dev/v1.21.5/bin/go

My starship prompt also shows the 1.22 version no matter what:

myproj on  master [$] via  v1.22.1

Furthermore;

❯ ll ~/.pkgx/go.dev
Permissions Size User    Group Date Modified Name
lrwxr-xr-x     - fredrik staff  7 Mar 17:01  v* -> v1.22.1
lrwxr-xr-x     - fredrik staff  7 Mar 17:01  v1 -> v1.22.1
lrwxr-xr-x     - fredrik staff  7 Mar 16:57  v1.21 -> v1.21.8
drwxr-xr-x     - fredrik staff  7 Mar 17:08  v1.21.5
drwxr-xr-x     - fredrik staff  7 Mar 16:57  v1.21.8
lrwxr-xr-x     - fredrik staff  7 M

What could be wrong?

dosubot[bot] commented 4 months ago

Hey @fredrikaverpil! 😄 Great to cross paths with you again here in the digital wilderness! 🌐👾 I'm diving into your issue now and will be back with you in a jiffy with some insights. Stay tuned! 🚀

fredrikaverpil commented 4 months ago

To add to this confusion;

❯ /Users/fredrik/.pkgx/go.dev/v1.21.5/bin/go version
go version go1.22.1 darwin/arm64

❯ cd ..
env -go.dev@1.21.5 -git-scm.org

❯ /Users/fredrik/.pkgx/go.dev/v1.21.5/bin/go version
go version go1.21.5 darwin/arm64

I'm just super confused at this point.

dosubot[bot] commented 4 months ago

Based on the information you've provided, it seems like there might be an issue with how pkgx is handling the version constraints for Go. The parse_deps function in pkgx processes the dependencies specified in the pkgx.yaml file and has a specific behavior for handling version constraints. If the version constraint ends with @latest, it is replaced with *, which means any version (the latest available version). However, this might not be the direct cause if you're specifying a version other than @latest.

The real issue could be related to how the parse_deps function or the validatePackageRequirement function from pkgx/hooks/usePantry.ts validates and processes the specified version constraints. If the version constraint specified in the pkgx.yaml file doesn't match the expected format or if there's an issue in how these functions interpret the version constraint, pkgx might end up fetching an incorrect version.

To resolve this issue, ensure that the version constraint specified in the pkgx.yaml file strictly follows the expected format. If you're specifying a version directly and still facing issues, it might be worth investigating the validatePackageRequirement function or how the parse_deps function processes the version constraints.

If the problem persists, it might be a bug in the version handling logic of pkgx. In that case, providing a detailed description of the issue, including the specific version constraint that's causing problems, to the pkgx maintainers could help in identifying and resolving the issue.

You can find more information about this in the src/utils/devenv.ts file in the pkgx repository.

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.
michaelessiet commented 4 months ago

Hey @fredrikaverpil , I'm unable to reproduce this error. Please try removing the entire .pkgx/ directory and try again

fredrikaverpil commented 4 months ago

Hey @michaelessiet, I just did this;

brew uninstall pkgx
rm -rf ~/.pkgx
rm -rf "${XDG_CACHE_HOME:-$HOME/Library/Caches}/pkgx"
rm -rf "${XDG_DATA_HOME:-$HOME/Library/Application Support}"/pkgx

The problem still persists and it's driving me nuts at this point;

❯ brew install pkgx
...

❯ pkgx go@1.21 version
 ✓  ~/.pkgx/curl.se/ca-certs/v2023.12.12
 ✓  ~/.pkgx/openssl.org/v1.1.1w
 ✓  ~/.pkgx/go.dev/v1.21.8
go version go1.21.8 darwin/arm64           <--- 👍

❯ ll ~/.pkgx/go.dev
Permissions Size User    Group Date Modified Name
lrwxr-xr-x@    - fredrik staff  7 Mar 17:35  v* -> v1.21.8
lrwxr-xr-x@    - fredrik staff  7 Mar 17:35  v1 -> v1.21.8
lrwxr-xr-x@    - fredrik staff  7 Mar 17:35  v1.21 -> v1.21.8
drwxr-xr-x@    - fredrik staff  7 Mar 17:35  v1.21.8

❯ cd myproj
❯ pkgx go@1.21 version
go version go1.22.1 darwin/arm64           <--- 🤯
fredrikaverpil commented 4 months ago

I just added this go file:

package main

import (
        "fmt"
        "runtime"
)

func main() {
        fmt.Println("Go version:", runtime.Version())
}

Then I run it a few different ways:

❯ ~/.pkgx/go.dev/v1.21.8/bin/go run book-service/main.go
Go version: go1.21.8            <--- 👍

❯ cd myproj
❯ ~/.pkgx/go.dev/v1.21.8/bin/go run main.go
Go version: go1.22.1            <--- 🤯

And here, I did not have dev enabled!!! What the heck?!!!

fredrikaverpil commented 4 months ago

Problem solved, in the project's go.mod I apparently had toolchain go1.22.1 which causes go itself to download a new version (which I already had cached) and use that.

If setting the toolchain to a non-existing version, like toolchain go1.26.1, I get this:

❯ /Users/fredrik/.pkgx/go.dev/v1.21.8/bin/go version
go: downloading go1.26.1 (darwin/arm64)
go: download go1.26.1 for darwin/arm64: toolchain not available

This was such a mindfuck. Sorry for the noise.

jhheider commented 4 months ago

in general, i like how good modern languages (specifically go and rust) are at managing themselves. but, once in a while, there's a very subtle foot-gun in the mix. this was a good find.

mxcl commented 4 months ago

I get why they do this, but really they should leave such stuff to tools like us. They are the wrong layer to do this sort of thing and by doing it they are adding complexity for everyone as well as burden for themselves to maintain.