|
| 1 | +module.exports = { |
| 2 | + onPreBuild: async ({ utils }) => { |
| 3 | + const { run, build } = utils; |
| 4 | + |
| 5 | + console.log("=== Installing build tools (mise, just, uv) ==="); |
| 6 | + |
| 7 | + try { |
| 8 | + // Check if mise is already installed (cached) |
| 9 | + const miseExists = await run.command( |
| 10 | + 'command -v mise || echo "not-found"', |
| 11 | + { |
| 12 | + reject: false, |
| 13 | + }, |
| 14 | + ); |
| 15 | + |
| 16 | + if (miseExists.stdout.includes("not-found")) { |
| 17 | + console.log("Installing mise..."); |
| 18 | + await run.command("curl https://mise.run | sh"); |
| 19 | + |
| 20 | + // Add mise to PATH for subsequent commands |
| 21 | + process.env.PATH = `${process.env.HOME}/.local/bin:${process.env.PATH}`; |
| 22 | + } else { |
| 23 | + console.log("mise already installed (cached)"); |
| 24 | + } |
| 25 | + |
| 26 | + // Trust the mise configuration in this repo |
| 27 | + await run.command("mise trust"); |
| 28 | + |
| 29 | + // Install tools from mise.toml |
| 30 | + console.log("Installing tools from mise.toml..."); |
| 31 | + await run.command("mise install"); |
| 32 | + |
| 33 | + // Install just and uv explicitly (latest versions) |
| 34 | + console.log("Installing just and uv..."); |
| 35 | + await run.command("mise use just@latest"); |
| 36 | + await run.command("mise use uv@latest"); |
| 37 | + |
| 38 | + // Activate mise environment for the build |
| 39 | + // This ensures just/uv are available in PATH |
| 40 | + await run.command("mise activate bash"); |
| 41 | + |
| 42 | + // Update PATH for the rest of the build |
| 43 | + const miseBinDir = `${process.env.HOME}/.local/share/mise/shims`; |
| 44 | + process.env.PATH = `${miseBinDir}:${process.env.PATH}`; |
| 45 | + |
| 46 | + console.log("✓ Build tools installed successfully"); |
| 47 | + } catch (error) { |
| 48 | + // Fail the build if tool installation fails |
| 49 | + build.failBuild("Failed to install build tools", { error }); |
| 50 | + } |
| 51 | + }, |
| 52 | +}; |
0 commit comments