summaryrefslogtreecommitdiff
path: root/node_modules/fs-extra/lib/ensure
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/fs-extra/lib/ensure')
-rw-r--r--node_modules/fs-extra/lib/ensure/file.js49
-rw-r--r--node_modules/fs-extra/lib/ensure/index.js23
-rw-r--r--node_modules/fs-extra/lib/ensure/link.js61
-rw-r--r--node_modules/fs-extra/lib/ensure/symlink-paths.js99
-rw-r--r--node_modules/fs-extra/lib/ensure/symlink-type.js31
-rw-r--r--node_modules/fs-extra/lib/ensure/symlink.js66
6 files changed, 0 insertions, 329 deletions
diff --git a/node_modules/fs-extra/lib/ensure/file.js b/node_modules/fs-extra/lib/ensure/file.js
deleted file mode 100644
index 67eed30..0000000
--- a/node_modules/fs-extra/lib/ensure/file.js
+++ /dev/null
@@ -1,49 +0,0 @@
-'use strict'
-
-const u = require('universalify').fromCallback
-const path = require('path')
-const fs = require('graceful-fs')
-const mkdir = require('../mkdirs')
-const pathExists = require('../path-exists').pathExists
-
-function createFile (file, callback) {
- function makeFile () {
- fs.writeFile(file, '', err => {
- if (err) return callback(err)
- callback()
- })
- }
-
- fs.stat(file, (err, stats) => { // eslint-disable-line handle-callback-err
- if (!err && stats.isFile()) return callback()
- const dir = path.dirname(file)
- pathExists(dir, (err, dirExists) => {
- if (err) return callback(err)
- if (dirExists) return makeFile()
- mkdir.mkdirs(dir, err => {
- if (err) return callback(err)
- makeFile()
- })
- })
- })
-}
-
-function createFileSync (file) {
- let stats
- try {
- stats = fs.statSync(file)
- } catch (e) {}
- if (stats && stats.isFile()) return
-
- const dir = path.dirname(file)
- if (!fs.existsSync(dir)) {
- mkdir.mkdirsSync(dir)
- }
-
- fs.writeFileSync(file, '')
-}
-
-module.exports = {
- createFile: u(createFile),
- createFileSync
-}
diff --git a/node_modules/fs-extra/lib/ensure/index.js b/node_modules/fs-extra/lib/ensure/index.js
deleted file mode 100644
index c1f67b7..0000000
--- a/node_modules/fs-extra/lib/ensure/index.js
+++ /dev/null
@@ -1,23 +0,0 @@
-'use strict'
-
-const file = require('./file')
-const link = require('./link')
-const symlink = require('./symlink')
-
-module.exports = {
- // file
- createFile: file.createFile,
- createFileSync: file.createFileSync,
- ensureFile: file.createFile,
- ensureFileSync: file.createFileSync,
- // link
- createLink: link.createLink,
- createLinkSync: link.createLinkSync,
- ensureLink: link.createLink,
- ensureLinkSync: link.createLinkSync,
- // symlink
- createSymlink: symlink.createSymlink,
- createSymlinkSync: symlink.createSymlinkSync,
- ensureSymlink: symlink.createSymlink,
- ensureSymlinkSync: symlink.createSymlinkSync
-}
diff --git a/node_modules/fs-extra/lib/ensure/link.js b/node_modules/fs-extra/lib/ensure/link.js
deleted file mode 100644
index 49fe379..0000000
--- a/node_modules/fs-extra/lib/ensure/link.js
+++ /dev/null
@@ -1,61 +0,0 @@
-'use strict'
-
-const u = require('universalify').fromCallback
-const path = require('path')
-const fs = require('graceful-fs')
-const mkdir = require('../mkdirs')
-const pathExists = require('../path-exists').pathExists
-
-function createLink (srcpath, dstpath, callback) {
- function makeLink (srcpath, dstpath) {
- fs.link(srcpath, dstpath, err => {
- if (err) return callback(err)
- callback(null)
- })
- }
-
- pathExists(dstpath, (err, destinationExists) => {
- if (err) return callback(err)
- if (destinationExists) return callback(null)
- fs.lstat(srcpath, (err, stat) => {
- if (err) {
- err.message = err.message.replace('lstat', 'ensureLink')
- return callback(err)
- }
-
- const dir = path.dirname(dstpath)
- pathExists(dir, (err, dirExists) => {
- if (err) return callback(err)
- if (dirExists) return makeLink(srcpath, dstpath)
- mkdir.mkdirs(dir, err => {
- if (err) return callback(err)
- makeLink(srcpath, dstpath)
- })
- })
- })
- })
-}
-
-function createLinkSync (srcpath, dstpath, callback) {
- const destinationExists = fs.existsSync(dstpath)
- if (destinationExists) return undefined
-
- try {
- fs.lstatSync(srcpath)
- } catch (err) {
- err.message = err.message.replace('lstat', 'ensureLink')
- throw err
- }
-
- const dir = path.dirname(dstpath)
- const dirExists = fs.existsSync(dir)
- if (dirExists) return fs.linkSync(srcpath, dstpath)
- mkdir.mkdirsSync(dir)
-
- return fs.linkSync(srcpath, dstpath)
-}
-
-module.exports = {
- createLink: u(createLink),
- createLinkSync
-}
diff --git a/node_modules/fs-extra/lib/ensure/symlink-paths.js b/node_modules/fs-extra/lib/ensure/symlink-paths.js
deleted file mode 100644
index 4a6b78a..0000000
--- a/node_modules/fs-extra/lib/ensure/symlink-paths.js
+++ /dev/null
@@ -1,99 +0,0 @@
-'use strict'
-
-const path = require('path')
-const fs = require('graceful-fs')
-const pathExists = require('../path-exists').pathExists
-
-/**
- * Function that returns two types of paths, one relative to symlink, and one
- * relative to the current working directory. Checks if path is absolute or
- * relative. If the path is relative, this function checks if the path is
- * relative to symlink or relative to current working directory. This is an
- * initiative to find a smarter `srcpath` to supply when building symlinks.
- * This allows you to determine which path to use out of one of three possible
- * types of source paths. The first is an absolute path. This is detected by
- * `path.isAbsolute()`. When an absolute path is provided, it is checked to
- * see if it exists. If it does it's used, if not an error is returned
- * (callback)/ thrown (sync). The other two options for `srcpath` are a
- * relative url. By default Node's `fs.symlink` works by creating a symlink
- * using `dstpath` and expects the `srcpath` to be relative to the newly
- * created symlink. If you provide a `srcpath` that does not exist on the file
- * system it results in a broken symlink. To minimize this, the function
- * checks to see if the 'relative to symlink' source file exists, and if it
- * does it will use it. If it does not, it checks if there's a file that
- * exists that is relative to the current working directory, if does its used.
- * This preserves the expectations of the original fs.symlink spec and adds
- * the ability to pass in `relative to current working direcotry` paths.
- */
-
-function symlinkPaths (srcpath, dstpath, callback) {
- if (path.isAbsolute(srcpath)) {
- return fs.lstat(srcpath, (err, stat) => {
- if (err) {
- err.message = err.message.replace('lstat', 'ensureSymlink')
- return callback(err)
- }
- return callback(null, {
- 'toCwd': srcpath,
- 'toDst': srcpath
- })
- })
- } else {
- const dstdir = path.dirname(dstpath)
- const relativeToDst = path.join(dstdir, srcpath)
- return pathExists(relativeToDst, (err, exists) => {
- if (err) return callback(err)
- if (exists) {
- return callback(null, {
- 'toCwd': relativeToDst,
- 'toDst': srcpath
- })
- } else {
- return fs.lstat(srcpath, (err, stat) => {
- if (err) {
- err.message = err.message.replace('lstat', 'ensureSymlink')
- return callback(err)
- }
- return callback(null, {
- 'toCwd': srcpath,
- 'toDst': path.relative(dstdir, srcpath)
- })
- })
- }
- })
- }
-}
-
-function symlinkPathsSync (srcpath, dstpath) {
- let exists
- if (path.isAbsolute(srcpath)) {
- exists = fs.existsSync(srcpath)
- if (!exists) throw new Error('absolute srcpath does not exist')
- return {
- 'toCwd': srcpath,
- 'toDst': srcpath
- }
- } else {
- const dstdir = path.dirname(dstpath)
- const relativeToDst = path.join(dstdir, srcpath)
- exists = fs.existsSync(relativeToDst)
- if (exists) {
- return {
- 'toCwd': relativeToDst,
- 'toDst': srcpath
- }
- } else {
- exists = fs.existsSync(srcpath)
- if (!exists) throw new Error('relative srcpath does not exist')
- return {
- 'toCwd': srcpath,
- 'toDst': path.relative(dstdir, srcpath)
- }
- }
- }
-}
-
-module.exports = {
- symlinkPaths,
- symlinkPathsSync
-}
diff --git a/node_modules/fs-extra/lib/ensure/symlink-type.js b/node_modules/fs-extra/lib/ensure/symlink-type.js
deleted file mode 100644
index 4f8787c..0000000
--- a/node_modules/fs-extra/lib/ensure/symlink-type.js
+++ /dev/null
@@ -1,31 +0,0 @@
-'use strict'
-
-const fs = require('graceful-fs')
-
-function symlinkType (srcpath, type, callback) {
- callback = (typeof type === 'function') ? type : callback
- type = (typeof type === 'function') ? false : type
- if (type) return callback(null, type)
- fs.lstat(srcpath, (err, stats) => {
- if (err) return callback(null, 'file')
- type = (stats && stats.isDirectory()) ? 'dir' : 'file'
- callback(null, type)
- })
-}
-
-function symlinkTypeSync (srcpath, type) {
- let stats
-
- if (type) return type
- try {
- stats = fs.lstatSync(srcpath)
- } catch (e) {
- return 'file'
- }
- return (stats && stats.isDirectory()) ? 'dir' : 'file'
-}
-
-module.exports = {
- symlinkType,
- symlinkTypeSync
-}
diff --git a/node_modules/fs-extra/lib/ensure/symlink.js b/node_modules/fs-extra/lib/ensure/symlink.js
deleted file mode 100644
index 847c1b9..0000000
--- a/node_modules/fs-extra/lib/ensure/symlink.js
+++ /dev/null
@@ -1,66 +0,0 @@
-'use strict'
-
-const u = require('universalify').fromCallback
-const path = require('path')
-const fs = require('graceful-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 _symlinkType = require('./symlink-type')
-const symlinkType = _symlinkType.symlinkType
-const symlinkTypeSync = _symlinkType.symlinkTypeSync
-
-const pathExists = require('../path-exists').pathExists
-
-function createSymlink (srcpath, dstpath, type, callback) {
- callback = (typeof type === 'function') ? type : callback
- type = (typeof type === 'function') ? false : type
-
- pathExists(dstpath, (err, destinationExists) => {
- if (err) return callback(err)
- if (destinationExists) return callback(null)
- 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)
- })
- })
- })
- })
- })
-}
-
-function createSymlinkSync (srcpath, dstpath, type, callback) {
- callback = (typeof type === 'function') ? type : callback
- type = (typeof type === 'function') ? false : type
-
- const destinationExists = fs.existsSync(dstpath)
- if (destinationExists) return undefined
-
- const relative = symlinkPathsSync(srcpath, dstpath)
- srcpath = relative.toDst
- type = symlinkTypeSync(relative.toCwd, type)
- const dir = path.dirname(dstpath)
- const exists = fs.existsSync(dir)
- if (exists) return fs.symlinkSync(srcpath, dstpath, type)
- mkdirsSync(dir)
- return fs.symlinkSync(srcpath, dstpath, type)
-}
-
-module.exports = {
- createSymlink: u(createSymlink),
- createSymlinkSync
-}