summaryrefslogtreecommitdiff
path: root/node_modules/fs-extra/lib/ensure/symlink.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/fs-extra/lib/ensure/symlink.js')
-rw-r--r--node_modules/fs-extra/lib/ensure/symlink.js73
1 files changed, 29 insertions, 44 deletions
diff --git a/node_modules/fs-extra/lib/ensure/symlink.js b/node_modules/fs-extra/lib/ensure/symlink.js
index 2b93052f..a3d5f578 100644
--- a/node_modules/fs-extra/lib/ensure/symlink.js
+++ b/node_modules/fs-extra/lib/ensure/symlink.js
@@ -1,65 +1,50 @@
'use strict'
-const u = require('universalify').fromCallback
+const u = require('universalify').fromPromise
const path = require('path')
const fs = require('../fs')
-const _mkdirs = require('../mkdirs')
-const mkdirs = _mkdirs.mkdirs
-const mkdirsSync = _mkdirs.mkdirsSync
-const _symlinkPaths = require('./symlink-paths')
-const symlinkPaths = _symlinkPaths.symlinkPaths
-const symlinkPathsSync = _symlinkPaths.symlinkPathsSync
+const { mkdirs, mkdirsSync } = require('../mkdirs')
-const _symlinkType = require('./symlink-type')
-const symlinkType = _symlinkType.symlinkType
-const symlinkTypeSync = _symlinkType.symlinkTypeSync
+const { symlinkPaths, symlinkPathsSync } = require('./symlink-paths')
+const { symlinkType, symlinkTypeSync } = require('./symlink-type')
-const pathExists = require('../path-exists').pathExists
+const { pathExists } = require('../path-exists')
const { areIdentical } = require('../util/stat')
-function createSymlink (srcpath, dstpath, type, callback) {
- callback = (typeof type === 'function') ? type : callback
- type = (typeof type === 'function') ? false : type
+async function createSymlink (srcpath, dstpath, type) {
+ let stats
+ try {
+ stats = await fs.lstat(dstpath)
+ } catch { }
- fs.lstat(dstpath, (err, stats) => {
- if (!err && stats.isSymbolicLink()) {
- Promise.all([
- fs.stat(srcpath),
- fs.stat(dstpath)
- ]).then(([srcStat, dstStat]) => {
- if (areIdentical(srcStat, dstStat)) return callback(null)
- _createSymlink(srcpath, dstpath, type, callback)
- })
- } else _createSymlink(srcpath, dstpath, type, callback)
- })
-}
+ if (stats && stats.isSymbolicLink()) {
+ const [srcStat, dstStat] = await Promise.all([
+ fs.stat(srcpath),
+ fs.stat(dstpath)
+ ])
+
+ if (areIdentical(srcStat, dstStat)) return
+ }
+
+ const relative = await symlinkPaths(srcpath, dstpath)
+ srcpath = relative.toDst
+ const toType = await symlinkType(relative.toCwd, type)
+ const dir = path.dirname(dstpath)
+
+ if (!(await pathExists(dir))) {
+ await mkdirs(dir)
+ }
-function _createSymlink (srcpath, dstpath, type, callback) {
- symlinkPaths(srcpath, dstpath, (err, relative) => {
- if (err) return callback(err)
- srcpath = relative.toDst
- symlinkType(relative.toCwd, type, (err, type) => {
- if (err) return callback(err)
- const dir = path.dirname(dstpath)
- pathExists(dir, (err, dirExists) => {
- if (err) return callback(err)
- if (dirExists) return fs.symlink(srcpath, dstpath, type, callback)
- mkdirs(dir, err => {
- if (err) return callback(err)
- fs.symlink(srcpath, dstpath, type, callback)
- })
- })
- })
- })
+ return fs.symlink(srcpath, dstpath, toType)
}
function createSymlinkSync (srcpath, dstpath, type) {
let stats
try {
stats = fs.lstatSync(dstpath)
- } catch {}
+ } catch { }
if (stats && stats.isSymbolicLink()) {
const srcStat = fs.statSync(srcpath)
const dstStat = fs.statSync(dstpath)