anchor.diff:            cd $BUILD_DIR
             # NPM reads the `HOME` environment variable and fails if it doesn't
             # exist, so set it here.
  -          HOME=$PWD npm install $PATCHED_SRC ${npmFlags} || {
  +          (HOME=$PWD npm install $PATCHED_SRC ${npmFlags}) || {
  +            echo
  +            echo
  +            echo "NPM installation failed!"
  +            echo "The command was:"
  +            echo HOME=$PWD npm install $PATCHED_SRC ${npmFlags}
  +            echo
  +            echo
  +            echo
  +            # Drop the package's package.json file that we picked up before;
  +            # the `npm list` command will read this file and tell us if any
  +            # dependencies are missing or invalid (which is probably the reason
  +            # for failure).
  +            echo "$PACKAGE_JSON" > package.json
  +            echo "The following output might be helpful in understanding why:"
               npm list
               exit 1
             }
  
positive.code: else
  
  let
    inherit (stdenv.lib) fold removePrefix hasPrefix subtractLists isList flip
                         intersectLists isAttrs listToAttrs nameValuePair
                         mapAttrs filterAttrs attrNames elem concatMapStrings
  
negative.code: 
        # Propagate pieces of information about the package so that downstream
        # packages can reflect on them.
        passthru = {
          inherit pkgName namespace version;
          # The basic name is the name without namespace or version.
          basicName = name;
          peerDependencies = _peerDependencies.requiredDeps;
          recursiveDeps = let
            required = attrValues requiredDependencies;
            recursive = attrNames recursiveDependencies;
          in
            flatten (map (dep: remove name dep.recursiveDeps) required) ++
            recursive;
  
          # The `env` attribute is meant to be used with `nix-shell` (although
          # that's not required). It will build the package with its dev
          # dependencies. This means that the package must have dev dependencies
          # defined, or it will error.
          env = buildNodePackage (args // {installDevDependencies = true;});
  
          # An 'override' attribute, which will call `buildNodePackage` with the
          # given arguments overridden.
          override = newArgs: buildNodePackage (args // newArgs);
        };
      } // (removeAttrs args attrsToRemove) // {
        name = "${namePrefix}${name}-${version}";
  
  