(env)
| 306 | } |
| 307 | |
| 308 | function withRustToolchainOnPath(env) { |
| 309 | const next = { ...env }; |
| 310 | const currentPath = typeof next.PATH === "string" ? next.PATH : ""; |
| 311 | |
| 312 | // When npm is configured to run scripts via Git Bash on Windows, PATH may not |
| 313 | // include the Rust toolchain even if it exists on disk. The napi CLI shells |
| 314 | // out to `cargo`, so ensure it's discoverable. |
| 315 | const cargoHome = |
| 316 | typeof next.CARGO_HOME === "string" && next.CARGO_HOME.length > 0 |
| 317 | ? next.CARGO_HOME |
| 318 | : typeof next.USERPROFILE === "string" && next.USERPROFILE.length > 0 |
| 319 | ? join(next.USERPROFILE, ".cargo") |
| 320 | : null; |
| 321 | |
| 322 | if (cargoHome) { |
| 323 | const cargoBin = join(cargoHome, "bin"); |
| 324 | const cargoExe = |
| 325 | process.platform === "win32" ? join(cargoBin, "cargo.exe") : join(cargoBin, "cargo"); |
| 326 | if (existsSync(cargoExe) && !currentPath.toLowerCase().includes(cargoBin.toLowerCase())) { |
| 327 | next.PATH = `${cargoBin}${delimiter}${currentPath}`; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | // Ensure `napi` can find cargo even if it shells out through cmd.exe with a |
| 332 | // different PATH resolution behavior. |
| 333 | if (typeof next.CARGO !== "string" || next.CARGO.length === 0) { |
| 334 | const cargoExe = getCargoExePath(next); |
| 335 | if (cargoExe) next.CARGO = cargoExe; |
| 336 | } |
| 337 | |
| 338 | return next; |
| 339 | } |
| 340 | |
| 341 | function buildWithCargoDirectly(env, host) { |
| 342 | const cargoExe = getCargoExePath(env) ?? "cargo"; |
no test coverage detected