mirror of
https://github.com/hanzoai/pack.git
synced 2026-09-30 23:43:13 +00:00
feat: use mise node version when installing node alongside bun (#341)
* Use mise to install Node.js instead of apt packages When Bun is installed but Node.js is not required in the final image, the provider now uses mise to install Node.js instead of installing it via apt packages. This provides better version management and consistency with the rest of the mise-based tooling. Key changes: - Install Node.js via mise with default version "latest" - Check for version specifications in NODE_VERSION env var, .nvmrc, and .node-version files - Support mise.toml and .tool-versions configuration files - Remove apt package installation of nodejs in this scenario This ensures Node.js is available for build steps (e.g., node-gyp for native modules) while respecting user-specified versions and providing consistent version management across all tools. * Simplify Node.js version detection for Bun projects When Node.js needs to be installed for Bun projects (for build tools like node-gyp), keep the version detection simple: - Default to "latest" - Let UseMiseVersions handle mise.toml and .tool-versions Added a TODO to implement full version detection logic in the future (NODE_VERSION env var, package.json engines, .nvmrc, .node-version). * Only check mise versions for packages that are installed Instead of unconditionally checking mise versions for both node and bun, only add packages to the UseMiseVersions check if they were actually added to the mise step. This is more efficient and makes the intent clearer. * Track mise packages as they're added instead of re-checking conditions Build a list of mise packages as they're added to miseStep, then use that list for UseMiseVersions. This avoids duplicating the conditional logic and makes it clear which packages we're checking versions for. * test: snapshot update --------- Co-authored-by: Hanzo Dev <[email protected]>
This commit is contained in:
committed by
GitHub
co-authored by
Hanzo Dev
parent
4740a55ac0
commit
2543f736d6
@@ -73,8 +73,8 @@
|
||||
],
|
||||
"commands": [
|
||||
{
|
||||
"cmd": "sh -c 'apt-get update \u0026\u0026 apt-get install -y neofetch nodejs'",
|
||||
"customName": "install apt packages: neofetch nodejs"
|
||||
"cmd": "sh -c 'apt-get update \u0026\u0026 apt-get install -y neofetch'",
|
||||
"customName": "install apt packages: neofetch"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
@@ -99,7 +99,7 @@
|
||||
},
|
||||
{
|
||||
"cmd": "mise install",
|
||||
"customName": "install mise packages: bun, python"
|
||||
"customName": "install mise packages: bun, node, python"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
{
|
||||
"caches": {
|
||||
"apt": {
|
||||
"directory": "/var/cache/apt",
|
||||
"type": "locked"
|
||||
},
|
||||
"apt-lists": {
|
||||
"directory": "/var/lib/apt/lists",
|
||||
"type": "locked"
|
||||
},
|
||||
"bun-install": {
|
||||
"directory": "/root/.bun/install/cache",
|
||||
"type": "shared"
|
||||
@@ -60,24 +52,6 @@
|
||||
}
|
||||
},
|
||||
"steps": [
|
||||
{
|
||||
"caches": [
|
||||
"apt",
|
||||
"apt-lists"
|
||||
],
|
||||
"commands": [
|
||||
{
|
||||
"cmd": "sh -c 'apt-get update \u0026\u0026 apt-get install -y nodejs'",
|
||||
"customName": "install apt packages: nodejs"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"image": "ghcr.io/railwayapp/railpack-builder:latest"
|
||||
}
|
||||
],
|
||||
"name": "packages:apt:build"
|
||||
},
|
||||
{
|
||||
"assets": {
|
||||
"mise.toml": "[mise.toml]"
|
||||
@@ -93,12 +67,12 @@
|
||||
},
|
||||
{
|
||||
"cmd": "mise install",
|
||||
"customName": "install mise packages: bun"
|
||||
"customName": "install mise packages: bun, node"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"step": "packages:apt:build"
|
||||
"image": "ghcr.io/railwayapp/railpack-builder:latest"
|
||||
}
|
||||
],
|
||||
"name": "packages:mise",
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
{
|
||||
"caches": {
|
||||
"apt": {
|
||||
"directory": "/var/cache/apt",
|
||||
"type": "locked"
|
||||
},
|
||||
"apt-lists": {
|
||||
"directory": "/var/lib/apt/lists",
|
||||
"type": "locked"
|
||||
},
|
||||
"bun-install": {
|
||||
"directory": "/root/.bun/install/cache",
|
||||
"type": "shared"
|
||||
@@ -60,24 +52,6 @@
|
||||
}
|
||||
},
|
||||
"steps": [
|
||||
{
|
||||
"caches": [
|
||||
"apt",
|
||||
"apt-lists"
|
||||
],
|
||||
"commands": [
|
||||
{
|
||||
"cmd": "sh -c 'apt-get update \u0026\u0026 apt-get install -y nodejs'",
|
||||
"customName": "install apt packages: nodejs"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"image": "ghcr.io/railwayapp/railpack-builder:latest"
|
||||
}
|
||||
],
|
||||
"name": "packages:apt:build"
|
||||
},
|
||||
{
|
||||
"assets": {
|
||||
"mise.toml": "[mise.toml]"
|
||||
@@ -93,12 +67,12 @@
|
||||
},
|
||||
{
|
||||
"cmd": "mise install",
|
||||
"customName": "install mise packages: bun"
|
||||
"customName": "install mise packages: bun, node"
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
{
|
||||
"step": "packages:apt:build"
|
||||
"image": "ghcr.io/railwayapp/railpack-builder:latest"
|
||||
}
|
||||
],
|
||||
"name": "packages:mise",
|
||||
|
||||
@@ -280,10 +280,12 @@ func (p *NodeProvider) InstallNodeDeps(ctx *generate.GenerateContext, install *g
|
||||
|
||||
func (p *NodeProvider) InstallMisePackages(ctx *generate.GenerateContext, miseStep *generate.MiseStepBuilder) {
|
||||
requiresNode := p.requiresNode(ctx)
|
||||
misePackages := []string{}
|
||||
|
||||
// Node
|
||||
if requiresNode {
|
||||
node := miseStep.Default("node", DEFAULT_NODE_VERSION)
|
||||
misePackages = append(misePackages, "node")
|
||||
|
||||
if envVersion, varName := ctx.Env.GetConfigVariable("NODE_VERSION"); envVersion != "" {
|
||||
miseStep.Version(node, envVersion, varName)
|
||||
@@ -309,6 +311,7 @@ func (p *NodeProvider) InstallMisePackages(ctx *generate.GenerateContext, miseSt
|
||||
// Bun
|
||||
if p.requiresBun(ctx) {
|
||||
bun := miseStep.Default("bun", DEFAULT_BUN_VERSION)
|
||||
misePackages = append(misePackages, "bun")
|
||||
|
||||
if envVersion, varName := ctx.Env.GetConfigVariable("BUN_VERSION"); envVersion != "" {
|
||||
miseStep.Version(bun, envVersion, varName)
|
||||
@@ -322,12 +325,12 @@ func (p *NodeProvider) InstallMisePackages(ctx *generate.GenerateContext, miseSt
|
||||
miseStep.Version(bun, string(bunVersionFile), ".bun-version")
|
||||
}
|
||||
|
||||
// TODO why don't we install this via mise?
|
||||
// If we don't need node in the final image, we still want to include it for the install steps
|
||||
// since many packages need node-gyp to install native modules
|
||||
// in this case, we don't need a specific version, so we'll just pull from apt
|
||||
// TODO: use the same version detection logic as when bun is not in place (NODE_VERSION, package.json engines, .nvmrc, .node-version)
|
||||
if !requiresNode && ctx.Config.Packages["node"] == "" {
|
||||
miseStep.AddSupportingAptPackage("nodejs")
|
||||
miseStep.Default("node", "latest")
|
||||
misePackages = append(misePackages, "node")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,6 +339,11 @@ func (p *NodeProvider) InstallMisePackages(ctx *generate.GenerateContext, miseSt
|
||||
if p.usesCorepack() {
|
||||
miseStep.Variables["MISE_NODE_COREPACK"] = "true"
|
||||
}
|
||||
|
||||
// Check for mise.toml and .tool-versions and use those versions if they exist
|
||||
if len(misePackages) > 0 {
|
||||
miseStep.UseMiseVersions(ctx, misePackages)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *NodeProvider) GetNodeEnvVars(ctx *generate.GenerateContext) map[string]string {
|
||||
|
||||
Reference in New Issue
Block a user