jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
9.92k stars 285 forks source link

postinstall is not run for mise exec #2877

Open hverlin opened 4 days ago

hverlin commented 4 days ago

Describe the bug

To Reproduce

[tools]
node = { version = "23", postinstall = 'corepack enable' }

Here is the current behavior

> mise x node -c 'pnpm -v'
mise node@23.1.0 ✓ installed 
zsh:1: command not found: pnpm

> pnpm
zsh: command not found: pnpm

> mise install
mise all runtimes are installed

Expected behavior Using mise x node -c 'pnpm -v' I would expect:

i.e. same behavior as:

mise install
mise x -c 'pnpm -v'
9.12.2

mise version

mise -v
2024.10.13 macos-arm64 (ee83488 2024-10-28)
jdx commented 4 days ago

We can fix this, but since node is in your config there isn't any need to also specify it on the command line. If you didn't include it then it would work.

hverlin commented 4 days ago

I have noticed that it's not always working as it should if I don't specify the tool. Let's say I only update mise.toml file and try to run mise -x.

Here is what happens:

[tools]
node = "23"
> mise x -c 'node -v'
mise WARN  missing: node@23.1.0
zsh:1: command not found: node

However, if I just type node it works (given that my shell had mise activated)

> node
mise node@23.1.0 ✓ installed 
Welcome to Node.js v23.1.0.
Type ".help" for more information.
> 
jdx commented 4 days ago

Oh right, I forgot that is by design. It doesn't auto install if no other versions are installed

hverlin commented 4 days ago

For additional context, this is how I was thinking of using this. In GitLab CI, I was thinking I could just do:

build:
  stage: build
  image: some-image-with-mise
  script: |
    mise x -c 'pnpm i'

without mise install

hverlin commented 4 days ago

It doesn't auto install if no other versions are installed

Ah, makes sense! Do you think it could be added to the warning message?

jdx commented 3 days ago

Do you think it could be added to the warning message?

I think it's too much noise, the fix should be obvious I would think—running mise i

hverlin commented 3 days ago

Maybe then, would it be possible to have a flag for mise exec and mise run to always run the install?

mise run --install ...
mise exec --install ...

(since in the code it anyway checks for it, and there is a force install option in the code)

This would fit nicely with https://mise.jdx.dev/tips-and-tricks.html#shebang

Another thing which surprised me is that postinstall does not require one to trust the file, whereas env variables do?

(Happy to contribute to fix this issue, btw)

hverlin commented 3 days ago

There is this setting also: https://mise.jdx.dev/configuration/settings.html#not_found_auto_install I think it would need to clarify that it will auto-install only if:

jdx commented 3 days ago

it only autoinstalls if at least 1 version is already installed

mise run --install ...

I don't think it's worth adding a flag for. I would just run mise i && mise x. shebang trick is a good point but I still don't think it's worth the noise.