Comparing version 1.0.0 to 1.1.0
63
index.js
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var mkdirp = require('mkdirp'); | ||
var path = require('path'); | ||
var rm = require('rimraf'); | ||
var rimraf = require('rimraf'); | ||
/** | ||
* Create symlink | ||
* | ||
* @param {String} src | ||
* @param {String} dest | ||
* @param {String} type | ||
* @param {Function} cb | ||
* @api private | ||
*/ | ||
function link(src, dest, type, cb) { | ||
rm(dest, function (err) { | ||
rimraf(dest, function (err) { | ||
if (err) { | ||
@@ -36,27 +25,21 @@ cb(err); | ||
/** | ||
* Async | ||
* | ||
* @param {String} src | ||
* @param {String} dest | ||
* @param {String} type | ||
* @param {Function} cb | ||
* @api public | ||
*/ | ||
module.exports = function (src, dest, type, cb) { | ||
src = path.resolve(src); | ||
dest = path.resolve(dest); | ||
if (typeof src !== 'string' || typeof dest !== 'string') { | ||
throw new Error('Source file and target required'); | ||
} | ||
if (typeof type === 'function' && !cb) { | ||
cb = type; | ||
type = 'file'; | ||
type = null; | ||
} | ||
src = path.resolve(src); | ||
dest = path.resolve(dest); | ||
fs.lstat(dest, function (err, stats) { | ||
if (err && err.code === 'ENOENT') { | ||
return link(src, dest, type, cb); | ||
} | ||
if (err) { | ||
if (err.code === 'ENOENT') { | ||
return link(src, dest, type, cb); | ||
} | ||
cb(err); | ||
@@ -86,15 +69,9 @@ return; | ||
/** | ||
* Sync | ||
* | ||
* @param {String} src | ||
* @param {String} dest | ||
* @param {String} type | ||
* @api public | ||
*/ | ||
module.exports.sync = function (src, dest, type) { | ||
if (typeof src !== 'string' || typeof dest !== 'string') { | ||
throw new Error('Source file and target required'); | ||
} | ||
module.exports.sync = function (src, dest, type) { | ||
src = path.resolve(src); | ||
dest = path.resolve(dest); | ||
type = type || 'file'; | ||
@@ -106,3 +83,3 @@ try { | ||
if (!stats.isSymbolicLink()) { | ||
rm.sync(dest); | ||
rimraf.sync(dest); | ||
fs.symlinkSync(src, dest, type); | ||
@@ -116,3 +93,3 @@ return; | ||
rm.sync(dest); | ||
rimraf.sync(dest); | ||
fs.symlinkSync(src, dest, type); | ||
@@ -119,0 +96,0 @@ } catch (err) { |
{ | ||
"name": "lnfs", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Safely force create symlinks", | ||
@@ -15,2 +15,3 @@ "license": "MIT", | ||
}, | ||
"bin": "cli.js", | ||
"scripts": { | ||
@@ -20,2 +21,3 @@ "test": "node test.js" | ||
"files": [ | ||
"cli.js", | ||
"index.js" | ||
@@ -25,2 +27,3 @@ ], | ||
"dependencies": { | ||
"meow": "^3.3.0", | ||
"mkdirp": "^0.5.0", | ||
@@ -27,0 +30,0 @@ "rimraf": "^2.2.8" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4994
5
107
78
3
+ Addedmeow@^3.3.0
+ Addedarray-find-index@1.0.2(transitive)
+ Addedcamelcase@2.1.1(transitive)
+ Addedcamelcase-keys@2.1.0(transitive)
+ Addedcurrently-unhandled@0.4.1(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedfind-up@1.1.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-stdin@4.0.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedindent-string@2.1.0(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedis-utf8@0.2.1(transitive)
+ Addedload-json-file@1.1.0(transitive)
+ Addedloud-rejection@1.6.0(transitive)
+ Addedmap-obj@1.0.1(transitive)
+ Addedmeow@3.7.0(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedparse-json@2.2.0(transitive)
+ Addedpath-exists@2.1.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@1.1.0(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedread-pkg@1.1.0(transitive)
+ Addedread-pkg-up@1.0.1(transitive)
+ Addedredent@1.0.0(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstrip-bom@2.0.0(transitive)
+ Addedstrip-indent@1.0.1(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtrim-newlines@1.0.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)