<commit_before>
// link the supplied folder to .npm/{name}/{version}/package

var npm = require("../npm")
  , chain = require("./utils/chain")
  , log = require("./utils/log")
  , fs = require("fs")
  , readJson = require("./utils/read-json")
  , rm = require("./utils/rm-rf")
  , mkdir = require("./utils/mkdir-p")
  , path = require("path")
  , crypto
  , readInstalled = require("./utils/read-installed")
  , semver = require("./utils/semver")

try {
  crypto = process.binding("crypto") && require("crypto")
} catch (ex) {}

module.exports = link

function link (args, cb) {
  if (!crypto) return cb(new Error(
    "You must compile node with ssl support to use the link feature"))
  var folder = args.shift() || "."
  // folder's root MUST contain a package.json
  // read that for package info, then link it in, clobbering if necessary.
  if (folder.charAt(0) !== "/") folder = path.join(process.cwd(), folder)
  var jsonFile = path.join(folder, "package.json")
  log(folder, "link")
  chain
    ( function (cb) { fs.stat(folder, function (er, stats) {
        if (er) return cb(er)
        if (!stats.isDirectory()) return cb(new Error(
          "npm link requires a directory"))
        cb()
      })}
    , [log, "reading "+jsonFile, "link"]
    , [readAndLink, jsonFile, folder]
    , cb
    )
}

function readAndLink (jsonFile, folder, cb) {
  readJson
    ( jsonFile
    , "-1-LINK-"+(
        crypto.createHash("sha1").update(folder).digest("hex").substr(0,8)
      )
    , doLink(folder, cb)
    )
}
function doLink (folder, cb) { return function (er, data) {
  if (er) return cb(er)
  log(data.name+" "+data.version, "link")
  var pkgDir = path.join(npm.dir, data.name, data.version, "package")
    , deps = data.dependencies || {}
    , depNames = Array.isArray(deps) ? deps : Object.keys(deps)
  if (Array.isArray(deps)) {
    var o = {}
    deps.forEach(function (d) { o[d] = "*" })
    deps = o
  }

  // skip any that are installed
  readInstalled(depNames, function (er, inst) {
    if (er) return log.er(cb, "Couldn't read installed packages")(er)
    for (var d in inst) if (deps[d]) {
      var satis = semver.maxSatisfying(Object.keys(inst[d]), deps[d])
      if (satis) delete deps[d]
    }
    var depsNeeded = Object.keys(deps).map(function (d) {
      return d+"@"+deps[d]
    })
    log(depsNeeded, "link install deps")
    chain
      ( depsNeeded.length
        ? [ npm.commands, "install", depsNeeded.slice(0) ]
        : function (cb) { cb() }
      , [ require("./utils/link"), folder, pkgDir ]
      , [ npm.commands, "build", [data] ]
      , function (er) {
          if (!er) return cb()
          // error, rollback
          log(er, "error linking, rollback")
          var rb = depsNeeded.concat([data.name+"@"+data.version])
          npm.commands.rm(rb, function (er_) {
            if (er_) log(er_, "error rolling back")
            cb(er)
          })
        }
      )
  })
}}
<commit_msg>always install devDependencies when doing a link install<commit_after>
// link the supplied folder to .npm/{name}/{version}/package

var npm = require("../npm")
  , chain = require("./utils/chain")
  , log = require("./utils/log")
  , fs = require("fs")
  , readJson = require("./utils/read-json")
  , rm = require("./utils/rm-rf")
  , mkdir = require("./utils/mkdir-p")
  , path = require("path")
  , crypto
  , readInstalled = require("./utils/read-installed")
  , semver = require("./utils/semver")

try {
  crypto = process.binding("crypto") && require("crypto")
} catch (ex) {}

module.exports = link

function link (args, cb) {
  if (!crypto) return cb(new Error(
    "You must compile node with ssl support to use the link feature"))
  var folder = args.shift() || "."
  // folder's root MUST contain a package.json
  // read that for package info, then link it in, clobbering if necessary.
  if (folder.charAt(0) !== "/") folder = path.join(process.cwd(), folder)
  var jsonFile = path.join(folder, "package.json")
  log(folder, "link")
  chain
    ( function (cb) { fs.stat(folder, function (er, stats) {
        if (er) return cb(er)
        if (!stats.isDirectory()) return cb(new Error(
          "npm link requires a directory"))
        cb()
      })}
    , [log, "reading "+jsonFile, "link"]
    , [readAndLink, jsonFile, folder]
    , cb
    )
}

function readAndLink (jsonFile, folder, cb) {
  readJson
    ( jsonFile
    , "-1-LINK-"+(
        crypto.createHash("sha1").update(folder).digest("hex").substr(0,8)
      )
    , doLink(folder, cb)
    )
}
function depObjectify (deps) {
  if (!Array.isArray(deps)) return deps
  var o = {}
  deps.forEach(function (d) { o[d] = "*" })
  return o
}
function getDeps (data) {
  var deps = data.dependencies || {}
    , devDeps = data.devDependencies || {}
  deps = depObjectify(deps)
  devDeps = depObjectify(devDeps)
  Object.keys(devDeps).forEach(function (d) { deps[d] = devDeps[d] })
  return deps
}
function doLink (folder, cb) { return function (er, data) {
  if (er) return cb(er)
  log(data.name+" "+data.version, "link")
  var pkgDir = path.join(npm.dir, data.name, data.version, "package")
    , deps = getDeps(data)
    , depNames = Object.keys(deps)

  // skip any that are installed
  readInstalled(depNames, function (er, inst) {
    if (er) return log.er(cb, "Couldn't read installed packages")(er)
    for (var d in inst) if (deps[d]) {
      var satis = semver.maxSatisfying(Object.keys(inst[d]), deps[d])
      if (satis) delete deps[d]
    }
    var depsNeeded = Object.keys(deps).map(function (d) {
      return d+"@"+deps[d]
    })
    log(depsNeeded, "link install deps")
    chain
      ( depsNeeded.length
        ? [ npm.commands, "install", depsNeeded.slice(0) ]
        : function (cb) { cb() }
      , [ require("./utils/link"), folder, pkgDir ]
      , [ npm.commands, "build", [data] ]
      , function (er) {
          if (!er) return cb()
          // error, rollback
          log(er, "error linking, rollback")
          var rb = depsNeeded.concat([data.name+"@"+data.version])
          npm.commands.rm(rb, function (er_) {
            if (er_) log(er_, "error rolling back")
            cb(er)
          })
        }
      )
  })
}}

{'fraction_non_alphanumeric': 0.17088197146562906, 'fraction_numerical': 0.0019455252918287938, 'mean_word_length': 2.734261501210654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2036105', 'n_tokens_mistral': 2148, 'n_tokens_neox': 2102, 'n_words': 524}