# JavaScript/TypeScript runtime — Node.js and Bun.
{
  config,
  lib,
  pkgs,
  ...
}:
with lib; let
  cfg = config.coding.languages.javascript;
  npmGlobalPrefix = "${config.home.homeDirectory}/.npm-global";
in {
  options.coding.languages.javascript.enable = mkEnableOption "JavaScript runtime (Node.js + Bun)";

  config = mkIf cfg.enable {
    home.packages = with pkgs; [
      nodejs
      bun
    ];

    home.file.".npmrc".text = ''
      prefix=${npmGlobalPrefix}
    '';
    home.sessionVariables.NPM_CONFIG_PREFIX = npmGlobalPrefix;
  };
}
