mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
851 B
33 lines
851 B
|
|
module.exports = link
|
|
link.ifExists = linkIfExists
|
|
|
|
var fs = require("graceful-fs")
|
|
, chain = require("slide").chain
|
|
, mkdir = require("mkdirp")
|
|
, rm = require("./gently-rm.js")
|
|
, path = require("path")
|
|
, relativize = require("./relativize.js")
|
|
, npm = require("../npm.js")
|
|
|
|
function linkIfExists (from, to, gently, cb) {
|
|
fs.stat(from, function (er) {
|
|
if (er) return cb()
|
|
link(from, to, gently, cb)
|
|
})
|
|
}
|
|
|
|
function link (from, to, gently, cb) {
|
|
if (typeof cb !== "function") cb = gently, gently = null
|
|
if (npm.config.get("force")) gently = false
|
|
|
|
// junction symlinks on windows must be absolute
|
|
var rel = process.platform === "win32" ? from : relativize(from, to)
|
|
|
|
chain
|
|
( [ [fs, "stat", from]
|
|
, [rm, to, gently]
|
|
, [mkdir, path.dirname(to)]
|
|
, [fs, "symlink", rel, to, "junction"] ]
|
|
, cb)
|
|
}
|
|
|