jdx / mise

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

[feat] Parse package.json to get `engines.node` version #2284

Closed g4rcez closed 2 weeks ago

g4rcez commented 3 weeks ago

Context

Some NodeJS/Javascript projects have the attribute engines in package.json. That enforces the version of NodeJS in the project. Ref: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#engines

Can mise parse the package.json files to grab the version from engines.node?

Possible solutions

Accept a hook before setting the version of NodeJS.

[node]
preload = "~/.bin/node-pre-hook"

File: ~/.bin/node-pre-hook

#!/bin/bash
jq 'engines.node' package.json

With this solution, we can enable custom hooks to accept any custom methods to accept configuration

Motivation

I was using volta and all my projects use volta.node at package.json. This motivates me to configure volta projects to work with mise

I'm trying to do this just using zsh prehooks and I will share at this issue if I can get it.

g4rcez commented 2 weeks ago

I suggested implementing prehooks to parse the version from an output of the script, but for specific node stuff, I did PR #2288.

jdx commented 2 weeks ago

I feel strongly this is not a good idea. That field denotes compatibility, it should not be used to determine the ultimate version of node.

There is a thread for nvm that discusses this topic in-depth: https://github.com/nvm-sh/nvm/issues/651

I've had this debate with many people over the years and my mind is made up so I won't be discussing it further.