<commit_before>{ stdenv, fetchurl, openssl, python2, zlib, libuv, v8, utillinux, http-parser
, pkgconfig, runCommand, which, libtool, fetchpatch
, callPackage
, darwin ? null
, enableNpm ? true
}:

with stdenv.lib;

let

  inherit (darwin.apple_sdk.frameworks) CoreServices ApplicationServices;

  sharedLibDeps = { inherit openssl zlib libuv; } // (optionalAttrs (!stdenv.isDarwin) { inherit http-parser; });

  sharedConfigureFlags = concatMap (name: [
    "--shared-${name}"
    "--shared-${name}-libpath=${getLib sharedLibDeps.${name}}/lib"
    /** Closure notes: we explicitly avoid specifying --shared-*-includes,
     *  as that would put the paths into bin/nodejs.
     *  Including pkgconfig in build inputs would also have the same effect!
     */
  ]) (builtins.attrNames sharedLibDeps);

  extraConfigFlags = optionals (!enableNpm) [ "--without-npm" ];
in

  rec {

    buildInputs = optionals stdenv.isDarwin [ CoreServices ApplicationServices ]
    ++ [ python2 which zlib libuv openssl ]
    ++ optionals stdenv.isLinux [ utillinux http-parser ]
    ++ optionals stdenv.isDarwin [ pkgconfig libtool ];

    configureFlags = sharedConfigureFlags ++ [ "--without-dtrace" ] ++ extraConfigFlags;

    dontDisableStatic = true;

    enableParallelBuilding = true;

    passthru.interpreterName = "nodejs";


    setupHook = ./setup-hook.sh;

    patches = optionals stdenv.isDarwin [ ./no-xcode.patch ];

    preBuild = optionalString stdenv.isDarwin ''
      sed -i -e "s|tr1/type_traits|type_traits|g" \
      -e "s|std::tr1|std|" src/util.h
    '';

    prePatch = ''
      patchShebangs .
      sed -i 's/raise.*No Xcode or CLT version detected.*/version = "7.0.0"/' tools/gyp/pylib/gyp/xcode_emulation.py
    '';

    postInstall = ''
      paxmark m $out/bin/node
      PATH=$out/bin:$PATH patchShebangs $out
    '';

    meta = {
      description = "Event-driven I/O framework for the V8 JavaScript engine";
      homepage = http://nodejs.org;
      license = licenses.mit;
      maintainers = with maintainers; [ <NAME> cko ];
      platforms = platforms.linux ++ platforms.darwin;
    };

    passthru.python = python2; # to ensure nodeEnv uses the same version
}<commit_msg>nodejs: add bash completions for npm<commit_after>{ stdenv, fetchurl, openssl, python2, zlib, libuv, v8, utillinux, http-parser
, pkgconfig, runCommand, which, libtool, fetchpatch
, callPackage
, darwin ? null
, enableNpm ? true
}:

with stdenv.lib;

let

  inherit (darwin.apple_sdk.frameworks) CoreServices ApplicationServices;

  sharedLibDeps = { inherit openssl zlib libuv; } // (optionalAttrs (!stdenv.isDarwin) { inherit http-parser; });

  sharedConfigureFlags = concatMap (name: [
    "--shared-${name}"
    "--shared-${name}-libpath=${getLib sharedLibDeps.${name}}/lib"
    /** Closure notes: we explicitly avoid specifying --shared-*-includes,
     *  as that would put the paths into bin/nodejs.
     *  Including pkgconfig in build inputs would also have the same effect!
     */
  ]) (builtins.attrNames sharedLibDeps);

  extraConfigFlags = optionals (!enableNpm) [ "--without-npm" ];
in

  rec {

    buildInputs = optionals stdenv.isDarwin [ CoreServices ApplicationServices ]
    ++ [ python2 which zlib libuv openssl ]
    ++ optionals stdenv.isLinux [ utillinux http-parser ]
    ++ optionals stdenv.isDarwin [ pkgconfig libtool ];

    configureFlags = sharedConfigureFlags ++ [ "--without-dtrace" ] ++ extraConfigFlags;

    dontDisableStatic = true;

    enableParallelBuilding = true;

    passthru.interpreterName = "nodejs";


    setupHook = ./setup-hook.sh;

    patches = optionals stdenv.isDarwin [ ./no-xcode.patch ];

    preBuild = optionalString stdenv.isDarwin ''
      sed -i -e "s|tr1/type_traits|type_traits|g" \
      -e "s|std::tr1|std|" src/util.h
    '';

    prePatch = ''
      patchShebangs .
      sed -i 's/raise.*No Xcode or CLT version detected.*/version = "7.0.0"/' tools/gyp/pylib/gyp/xcode_emulation.py
    '';

    postInstall = ''
      paxmark m $out/bin/node
      PATH=$out/bin:$PATH patchShebangs $out

      ${optionalString enableNpm '' 
        mkdir -p $out/share/bash-completion/completions/
        $out/bin/npm completion > $out/share/bash-completion/completions/npm
      ''}
    '';

    meta = {
      description = "Event-driven I/O framework for the V8 JavaScript engine";
      homepage = http://nodejs.org;
      license = licenses.mit;
      maintainers = with maintainers; [ <NAME> ];
      platforms = platforms.linux ++ platforms.darwin;
    };

    passthru.python = python2; # to ensure nodeEnv uses the same version
}
{'fraction_non_alphanumeric': 0.12611631452842517, 'fraction_numerical': 0.004356349379220213, 'mean_word_length': 3.1332133213321334, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2873812', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1476, 'n_words': 352}