Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lnfs

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lnfs - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

94

index.js

@@ -5,98 +5,40 @@ 'use strict';

var mkdirp = require('mkdirp');
var pify = require('pify');
var Promise = require('pinkie-promise');
var rimraf = require('rimraf');
function link(src, dest, type, cb) {
rimraf(dest, function (err) {
if (err) {
cb(err);
return;
}
mkdirp(path.dirname(dest), function (err) {
if (err) {
cb(err);
return;
}
fs.symlink(src, dest, type, cb);
});
function link(src, dest, type) {
return Promise.all([
pify(rimraf, Promise)(dest),
pify(mkdirp, Promise)(path.dirname(dest))
]).then(function () {
return pify(fs.symlink, Promise)(src, dest, type);
});
}
module.exports = function (src, dest, type, cb) {
module.exports = function (src, dest, type) {
if (typeof src !== 'string' || typeof dest !== 'string') {
throw new Error('Source file and target required');
return Promise.reject(new TypeError('Expected a string'));
}
if (typeof type === 'function' && !cb) {
cb = type;
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) {
cb(err);
return;
}
return pify(fs.lstat, Promise)(dest).then(function (stats) {
if (!stats.isSymbolicLink()) {
return link(src, dest, type, cb);
return link(src, dest, type);
}
fs.realpath(dest, function (err, res) {
if (err) {
cb(err);
return;
return pify(fs.realpath, Promise)(dest).then(function (res) {
if (res !== src) {
return link(src, dest, type);
}
if (res === src) {
cb();
return;
}
link(src, dest, type, cb);
});
});
};
module.exports.sync = function (src, dest, type) {
if (typeof src !== 'string' || typeof dest !== 'string') {
throw new Error('Source file and target required');
}
src = path.resolve(src);
dest = path.resolve(dest);
try {
var stats = fs.lstatSync(dest);
var realpath = fs.realpathSync(dest);
if (!stats.isSymbolicLink()) {
rimraf.sync(dest);
fs.symlinkSync(src, dest, type);
return;
}
if (realpath === src) {
return;
}
rimraf.sync(dest);
fs.symlinkSync(src, dest, type);
} catch (err) {
}).catch(function (err) {
if (err.code === 'ENOENT') {
mkdirp.sync(path.dirname(dest));
fs.symlinkSync(src, dest, type);
return;
return link(src, dest, type);
}
throw err;
}
});
};

16

package.json
{
"name": "lnfs",
"version": "2.0.0",
"version": "3.0.0",
"description": "Safely force create symlinks",

@@ -16,3 +16,3 @@ "license": "MIT",

"scripts": {
"test": "node test.js"
"test": "xo && ava"
},

@@ -31,7 +31,17 @@ "files": [

"mkdirp": "^0.5.0",
"pify": "^2.2.0",
"pinkie-promise": "^1.0.0",
"rimraf": "^2.2.8"
},
"devDependencies": {
"ava": "^0.0.4"
"ava": "*",
"pify": "^2.2.0",
"pinkie-promise": "^1.0.0",
"xo": "*"
},
"xo": {
"ignore": [
"test.js"
]
}
}

@@ -18,9 +18,7 @@ # lnfs [![Build Status](http://img.shields.io/travis/kevva/lnfs.svg?style=flat)](https://travis-ci.org/kevva/lnfs)

```js
var symlink = require('lnfs');
const symlink = require('lnfs');
symlink('foo.txt', 'bar.txt', function (err) {
symlink('foo.txt', 'bar.txt').then(() => {
console.log('Symlink successfully created!');
});
symlink.sync('foo.txt', 'bar.txt');
```

@@ -31,4 +29,6 @@

### lnfs(src, dest, type, callback)
### lnfs(src, dest, type)
Returns a promise that resolves nothing.
#### src

@@ -55,11 +55,5 @@

#### callback(err)
Type: `function`
Returns nothing but a possible exception.
## License
MIT © [Kevin Mårtensson](https://github.com/kevva)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc