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 3.0.0 to 3.0.1

67

index.js
'use strict';
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var pify = require('pify');
var Promise = require('pinkie-promise');
var rimraf = require('rimraf');
const fs = require('fs');
const path = require('path');
const del = require('del');
const makeDir = require('make-dir');
const pify = require('pify');
const pSeries = require('p-series');
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);
});
}
const fsP = pify(fs);
module.exports = function (src, dest, type) {
if (typeof src !== 'string' || typeof dest !== 'string') {
return Promise.reject(new TypeError('Expected a string'));
const link = (src, dest, type) => pSeries([
() => del(dest, {force: true}),
() => makeDir(path.dirname(dest)),
() => fsP.symlink(src, dest, type)
]);
module.exports = (src, dest, type) => {
if (typeof src !== 'string') {
return Promise.reject(new TypeError(`Expected a \`string\`, got \`${typeof src}\``));
}
src = path.resolve(src);
dest = path.resolve(dest);
if (typeof dest !== 'string') {
return Promise.reject(new TypeError(`Expected a \`string\`, got \`${typeof dest}\``));
}
return pify(fs.lstat, Promise)(dest).then(function (stats) {
if (!stats.isSymbolicLink()) {
return link(src, dest, type);
}
const resolvedSrc = path.resolve(src);
const resolvedDest = path.resolve(dest);
return pify(fs.realpath, Promise)(dest).then(function (res) {
if (res !== src) {
return link(src, dest, type);
return fsP.lstat(resolvedDest)
.then(stats => {
if (!stats.isSymbolicLink()) {
return link(resolvedSrc, resolvedDest, type);
}
return fsP.realpath(resolvedDest).then(res => res !== resolvedSrc && link(resolvedSrc, resolvedDest, type));
})
.catch(err => {
if (err.code === 'ENOENT') {
return link(resolvedSrc, dest, type);
}
throw err;
});
}).catch(function (err) {
if (err.code === 'ENOENT') {
return link(src, dest, type);
}
throw err;
});
};
{
"name": "lnfs",
"version": "3.0.0",
"description": "Safely force create symlinks",
"license": "MIT",
"repository": "kevva/lnfs",
"author": {
"name": "Kevin Mårtensson",
"email": "kevinmartensson@gmail.com",
"url": "https://github.com/kevva"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"linux",
"lnfs",
"osx",
"symlink",
"windows"
],
"dependencies": {
"mkdirp": "^0.5.0",
"pify": "^2.2.0",
"pinkie-promise": "^1.0.0",
"rimraf": "^2.2.8"
},
"devDependencies": {
"ava": "*",
"pify": "^2.2.0",
"pinkie-promise": "^1.0.0",
"xo": "*"
},
"xo": {
"ignore": [
"test.js"
]
}
"name": "lnfs",
"version": "3.0.1",
"description": "Safely force create symlinks",
"license": "MIT",
"repository": "kevva/lnfs",
"author": {
"name": "Kevin Mårtensson",
"email": "kevinmartensson@gmail.com",
"url": "https://github.com/kevva"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"linux",
"lnfs",
"osx",
"symlink",
"windows"
],
"dependencies": {
"del": "^3.0.0",
"make-dir": "^1.0.0",
"p-series": "^1.0.0",
"pify": "^3.0.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
}
}

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

*See [lnfs-cli](https://github.com/kevva/lnfs-cli) for the command-line version.*
## Install
```
$ npm install --save lnfs
$ npm install lnfs
```

@@ -19,5 +17,5 @@

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

@@ -30,9 +28,8 @@ });

### lnfs(src, dest, type)
### lnfs(src, dest, [type])
Returns a promise that resolves nothing.
Returns a `Promise` with the path to the symlink.
#### src
*Required*
Type: `string`

@@ -44,3 +41,2 @@

*Required*
Type: `string`

@@ -52,3 +48,3 @@

Type: `string`
Type: `string`<br>
Default: `file`

@@ -59,4 +55,9 @@

## Related
* [lnfs-cli](https://github.com/kevva/lnfs-cli) - CLI for this module
## License
MIT © [Kevin Mårtensson](https://github.com/kevva)

Sorry, the diff of this file is not supported yet

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