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
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
2
58
3670
36
+ Addeddel@^3.0.0
+ Addedmake-dir@^1.0.0
+ Addedp-series@^1.0.0
+ Added@sindresorhus/is@0.7.0(transitive)
+ Addedarray-union@1.0.2(transitive)
+ Addedarray-uniq@1.0.3(transitive)
+ Addeddel@3.0.0(transitive)
+ Addedglobby@6.1.0(transitive)
+ Addedis-path-cwd@1.0.0(transitive)
+ Addedis-path-in-cwd@1.0.1(transitive)
+ Addedis-path-inside@1.0.1(transitive)
+ Addedmake-dir@1.3.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedp-map@1.2.0(transitive)
+ Addedp-reduce@1.0.0(transitive)
+ Addedp-series@1.1.0(transitive)
+ Addedpath-is-inside@1.0.2(transitive)
+ Addedpify@3.0.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
- Removedmkdirp@^0.5.0
- Removedpinkie-promise@^1.0.0
- Removedrimraf@^2.2.8
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedpinkie@1.0.0(transitive)
- Removedpinkie-promise@1.0.0(transitive)
Updatedpify@^3.0.0