Template Upload
This commit is contained in:
41
node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
generated
vendored
Normal file
41
node_modules/fs-extra/lib/copy-sync/copy-file-sync.js
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
|
||||
const BUF_LENGTH = 64 * 1024
|
||||
const _buff = require('../util/buffer')(BUF_LENGTH)
|
||||
|
||||
function copyFileSync (srcFile, destFile, options) {
|
||||
const overwrite = options.overwrite
|
||||
const errorOnExist = options.errorOnExist
|
||||
const preserveTimestamps = options.preserveTimestamps
|
||||
|
||||
if (fs.existsSync(destFile)) {
|
||||
if (overwrite) {
|
||||
fs.unlinkSync(destFile)
|
||||
} else if (errorOnExist) {
|
||||
throw new Error(`${destFile} already exists`)
|
||||
} else return
|
||||
}
|
||||
|
||||
const fdr = fs.openSync(srcFile, 'r')
|
||||
const stat = fs.fstatSync(fdr)
|
||||
const fdw = fs.openSync(destFile, 'w', stat.mode)
|
||||
let bytesRead = 1
|
||||
let pos = 0
|
||||
|
||||
while (bytesRead > 0) {
|
||||
bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
|
||||
fs.writeSync(fdw, _buff, 0, bytesRead)
|
||||
pos += bytesRead
|
||||
}
|
||||
|
||||
if (preserveTimestamps) {
|
||||
fs.futimesSync(fdw, stat.atime, stat.mtime)
|
||||
}
|
||||
|
||||
fs.closeSync(fdr)
|
||||
fs.closeSync(fdw)
|
||||
}
|
||||
|
||||
module.exports = copyFileSync
|
62
node_modules/fs-extra/lib/copy-sync/copy-sync.js
generated
vendored
Normal file
62
node_modules/fs-extra/lib/copy-sync/copy-sync.js
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const path = require('path')
|
||||
const copyFileSync = require('./copy-file-sync')
|
||||
const mkdir = require('../mkdirs')
|
||||
|
||||
function copySync (src, dest, options) {
|
||||
if (typeof options === 'function' || options instanceof RegExp) {
|
||||
options = {filter: options}
|
||||
}
|
||||
|
||||
options = options || {}
|
||||
options.recursive = !!options.recursive
|
||||
|
||||
// default to true for now
|
||||
options.clobber = 'clobber' in options ? !!options.clobber : true
|
||||
// overwrite falls back to clobber
|
||||
options.overwrite = 'overwrite' in options ? !!options.overwrite : options.clobber
|
||||
options.dereference = 'dereference' in options ? !!options.dereference : false
|
||||
options.preserveTimestamps = 'preserveTimestamps' in options ? !!options.preserveTimestamps : false
|
||||
|
||||
options.filter = options.filter || function () { return true }
|
||||
|
||||
// Warn about using preserveTimestamps on 32-bit node:
|
||||
if (options.preserveTimestamps && process.arch === 'ia32') {
|
||||
console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n
|
||||
see https://github.com/jprichardson/node-fs-extra/issues/269`)
|
||||
}
|
||||
|
||||
const stats = (options.recursive && !options.dereference) ? fs.lstatSync(src) : fs.statSync(src)
|
||||
const destFolder = path.dirname(dest)
|
||||
const destFolderExists = fs.existsSync(destFolder)
|
||||
let performCopy = false
|
||||
|
||||
if (options.filter instanceof RegExp) {
|
||||
console.warn('Warning: fs-extra: Passing a RegExp filter is deprecated, use a function')
|
||||
performCopy = options.filter.test(src)
|
||||
} else if (typeof options.filter === 'function') performCopy = options.filter(src, dest)
|
||||
|
||||
if (stats.isFile() && performCopy) {
|
||||
if (!destFolderExists) mkdir.mkdirsSync(destFolder)
|
||||
copyFileSync(src, dest, {
|
||||
overwrite: options.overwrite,
|
||||
errorOnExist: options.errorOnExist,
|
||||
preserveTimestamps: options.preserveTimestamps
|
||||
})
|
||||
} else if (stats.isDirectory() && performCopy) {
|
||||
if (!fs.existsSync(dest)) mkdir.mkdirsSync(dest)
|
||||
const contents = fs.readdirSync(src)
|
||||
contents.forEach(content => {
|
||||
const opts = options
|
||||
opts.recursive = true
|
||||
copySync(path.join(src, content), path.join(dest, content), opts)
|
||||
})
|
||||
} else if (options.recursive && stats.isSymbolicLink() && performCopy) {
|
||||
const srcPath = fs.readlinkSync(src)
|
||||
fs.symlinkSync(srcPath, dest)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = copySync
|
3
node_modules/fs-extra/lib/copy-sync/index.js
generated
vendored
Normal file
3
node_modules/fs-extra/lib/copy-sync/index.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
copySync: require('./copy-sync')
|
||||
}
|
54
node_modules/fs-extra/lib/copy/copy.js
generated
vendored
Normal file
54
node_modules/fs-extra/lib/copy/copy.js
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const path = require('path')
|
||||
const ncp = require('./ncp')
|
||||
const mkdir = require('../mkdirs')
|
||||
const pathExists = require('../path-exists').pathExists
|
||||
|
||||
function copy (src, dest, options, callback) {
|
||||
if (typeof options === 'function' && !callback) {
|
||||
callback = options
|
||||
options = {}
|
||||
} else if (typeof options === 'function' || options instanceof RegExp) {
|
||||
options = {filter: options}
|
||||
}
|
||||
callback = callback || function () {}
|
||||
options = options || {}
|
||||
|
||||
// Warn about using preserveTimestamps on 32-bit node:
|
||||
if (options.preserveTimestamps && process.arch === 'ia32') {
|
||||
console.warn(`fs-extra: Using the preserveTimestamps option in 32-bit node is not recommended;\n
|
||||
see https://github.com/jprichardson/node-fs-extra/issues/269`)
|
||||
}
|
||||
|
||||
// don't allow src and dest to be the same
|
||||
const basePath = process.cwd()
|
||||
const currentPath = path.resolve(basePath, src)
|
||||
const targetPath = path.resolve(basePath, dest)
|
||||
if (currentPath === targetPath) return callback(new Error('Source and destination must not be the same.'))
|
||||
|
||||
fs.lstat(src, (err, stats) => {
|
||||
if (err) return callback(err)
|
||||
|
||||
let dir = null
|
||||
if (stats.isDirectory()) {
|
||||
const parts = dest.split(path.sep)
|
||||
parts.pop()
|
||||
dir = parts.join(path.sep)
|
||||
} else {
|
||||
dir = path.dirname(dest)
|
||||
}
|
||||
|
||||
pathExists(dir, (err, dirExists) => {
|
||||
if (err) return callback(err)
|
||||
if (dirExists) return ncp(src, dest, options, callback)
|
||||
mkdir.mkdirs(dir, err => {
|
||||
if (err) return callback(err)
|
||||
ncp(src, dest, options, callback)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = copy
|
4
node_modules/fs-extra/lib/copy/index.js
generated
vendored
Normal file
4
node_modules/fs-extra/lib/copy/index.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
const u = require('universalify').fromCallback
|
||||
module.exports = {
|
||||
copy: u(require('./copy'))
|
||||
}
|
234
node_modules/fs-extra/lib/copy/ncp.js
generated
vendored
Normal file
234
node_modules/fs-extra/lib/copy/ncp.js
generated
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
// imported from ncp (this is temporary, will rewrite)
|
||||
|
||||
var fs = require('graceful-fs')
|
||||
var path = require('path')
|
||||
var utimes = require('../util/utimes')
|
||||
|
||||
function ncp (source, dest, options, callback) {
|
||||
if (!callback) {
|
||||
callback = options
|
||||
options = {}
|
||||
}
|
||||
|
||||
var basePath = process.cwd()
|
||||
var currentPath = path.resolve(basePath, source)
|
||||
var targetPath = path.resolve(basePath, dest)
|
||||
|
||||
var filter = options.filter
|
||||
var transform = options.transform
|
||||
var overwrite = options.overwrite
|
||||
// If overwrite is undefined, use clobber, otherwise default to true:
|
||||
if (overwrite === undefined) overwrite = options.clobber
|
||||
if (overwrite === undefined) overwrite = true
|
||||
var errorOnExist = options.errorOnExist
|
||||
var dereference = options.dereference
|
||||
var preserveTimestamps = options.preserveTimestamps === true
|
||||
|
||||
var started = 0
|
||||
var finished = 0
|
||||
var running = 0
|
||||
|
||||
var errored = false
|
||||
|
||||
startCopy(currentPath)
|
||||
|
||||
function startCopy (source) {
|
||||
started++
|
||||
if (filter) {
|
||||
if (filter instanceof RegExp) {
|
||||
console.warn('Warning: fs-extra: Passing a RegExp filter is deprecated, use a function')
|
||||
if (!filter.test(source)) {
|
||||
return doneOne(true)
|
||||
}
|
||||
} else if (typeof filter === 'function') {
|
||||
if (!filter(source, dest)) {
|
||||
return doneOne(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
return getStats(source)
|
||||
}
|
||||
|
||||
function getStats (source) {
|
||||
var stat = dereference ? fs.stat : fs.lstat
|
||||
running++
|
||||
stat(source, function (err, stats) {
|
||||
if (err) return onError(err)
|
||||
|
||||
// We need to get the mode from the stats object and preserve it.
|
||||
var item = {
|
||||
name: source,
|
||||
mode: stats.mode,
|
||||
mtime: stats.mtime, // modified time
|
||||
atime: stats.atime, // access time
|
||||
stats: stats // temporary
|
||||
}
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
return onDir(item)
|
||||
} else if (stats.isFile() || stats.isCharacterDevice() || stats.isBlockDevice()) {
|
||||
return onFile(item)
|
||||
} else if (stats.isSymbolicLink()) {
|
||||
// Symlinks don't really need to know about the mode.
|
||||
return onLink(source)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function onFile (file) {
|
||||
var target = file.name.replace(currentPath, targetPath.replace('$', '$$$$')) // escapes '$' with '$$'
|
||||
isWritable(target, function (writable) {
|
||||
if (writable) {
|
||||
copyFile(file, target)
|
||||
} else {
|
||||
if (overwrite) {
|
||||
rmFile(target, function () {
|
||||
copyFile(file, target)
|
||||
})
|
||||
} else if (errorOnExist) {
|
||||
onError(new Error(target + ' already exists'))
|
||||
} else {
|
||||
doneOne()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function copyFile (file, target) {
|
||||
var readStream = fs.createReadStream(file.name)
|
||||
var writeStream = fs.createWriteStream(target, { mode: file.mode })
|
||||
|
||||
readStream.on('error', onError)
|
||||
writeStream.on('error', onError)
|
||||
|
||||
if (transform) {
|
||||
transform(readStream, writeStream, file)
|
||||
} else {
|
||||
writeStream.on('open', function () {
|
||||
readStream.pipe(writeStream)
|
||||
})
|
||||
}
|
||||
|
||||
writeStream.once('close', function () {
|
||||
fs.chmod(target, file.mode, function (err) {
|
||||
if (err) return onError(err)
|
||||
if (preserveTimestamps) {
|
||||
utimes.utimesMillis(target, file.atime, file.mtime, function (err) {
|
||||
if (err) return onError(err)
|
||||
return doneOne()
|
||||
})
|
||||
} else {
|
||||
doneOne()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function rmFile (file, done) {
|
||||
fs.unlink(file, function (err) {
|
||||
if (err) return onError(err)
|
||||
return done()
|
||||
})
|
||||
}
|
||||
|
||||
function onDir (dir) {
|
||||
var target = dir.name.replace(currentPath, targetPath.replace('$', '$$$$')) // escapes '$' with '$$'
|
||||
isWritable(target, function (writable) {
|
||||
if (writable) {
|
||||
return mkDir(dir, target)
|
||||
}
|
||||
copyDir(dir.name)
|
||||
})
|
||||
}
|
||||
|
||||
function mkDir (dir, target) {
|
||||
fs.mkdir(target, dir.mode, function (err) {
|
||||
if (err) return onError(err)
|
||||
// despite setting mode in fs.mkdir, doesn't seem to work
|
||||
// so we set it here.
|
||||
fs.chmod(target, dir.mode, function (err) {
|
||||
if (err) return onError(err)
|
||||
copyDir(dir.name)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function copyDir (dir) {
|
||||
fs.readdir(dir, function (err, items) {
|
||||
if (err) return onError(err)
|
||||
items.forEach(function (item) {
|
||||
startCopy(path.join(dir, item))
|
||||
})
|
||||
return doneOne()
|
||||
})
|
||||
}
|
||||
|
||||
function onLink (link) {
|
||||
var target = link.replace(currentPath, targetPath)
|
||||
fs.readlink(link, function (err, resolvedPath) {
|
||||
if (err) return onError(err)
|
||||
checkLink(resolvedPath, target)
|
||||
})
|
||||
}
|
||||
|
||||
function checkLink (resolvedPath, target) {
|
||||
if (dereference) {
|
||||
resolvedPath = path.resolve(basePath, resolvedPath)
|
||||
}
|
||||
isWritable(target, function (writable) {
|
||||
if (writable) {
|
||||
return makeLink(resolvedPath, target)
|
||||
}
|
||||
fs.readlink(target, function (err, targetDest) {
|
||||
if (err) return onError(err)
|
||||
|
||||
if (dereference) {
|
||||
targetDest = path.resolve(basePath, targetDest)
|
||||
}
|
||||
if (targetDest === resolvedPath) {
|
||||
return doneOne()
|
||||
}
|
||||
return rmFile(target, function () {
|
||||
makeLink(resolvedPath, target)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function makeLink (linkPath, target) {
|
||||
fs.symlink(linkPath, target, function (err) {
|
||||
if (err) return onError(err)
|
||||
return doneOne()
|
||||
})
|
||||
}
|
||||
|
||||
function isWritable (path, done) {
|
||||
fs.lstat(path, function (err) {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') return done(true)
|
||||
return done(false)
|
||||
}
|
||||
return done(false)
|
||||
})
|
||||
}
|
||||
|
||||
function onError (err) {
|
||||
// ensure callback is defined & called only once:
|
||||
if (!errored && callback !== undefined) {
|
||||
errored = true
|
||||
return callback(err)
|
||||
}
|
||||
}
|
||||
|
||||
function doneOne (skipped) {
|
||||
if (!skipped) running--
|
||||
finished++
|
||||
if ((started === finished) && (running === 0)) {
|
||||
if (callback !== undefined) {
|
||||
return callback(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ncp
|
48
node_modules/fs-extra/lib/empty/index.js
generated
vendored
Normal file
48
node_modules/fs-extra/lib/empty/index.js
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
'use strict'
|
||||
|
||||
const u = require('universalify').fromCallback
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const mkdir = require('../mkdirs')
|
||||
const remove = require('../remove')
|
||||
|
||||
const emptyDir = u(function emptyDir (dir, callback) {
|
||||
callback = callback || function () {}
|
||||
fs.readdir(dir, (err, items) => {
|
||||
if (err) return mkdir.mkdirs(dir, callback)
|
||||
|
||||
items = items.map(item => path.join(dir, item))
|
||||
|
||||
deleteItem()
|
||||
|
||||
function deleteItem () {
|
||||
const item = items.pop()
|
||||
if (!item) return callback()
|
||||
remove.remove(item, err => {
|
||||
if (err) return callback(err)
|
||||
deleteItem()
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
function emptyDirSync (dir) {
|
||||
let items
|
||||
try {
|
||||
items = fs.readdirSync(dir)
|
||||
} catch (err) {
|
||||
return mkdir.mkdirsSync(dir)
|
||||
}
|
||||
|
||||
items.forEach(item => {
|
||||
item = path.join(dir, item)
|
||||
remove.removeSync(item)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
emptyDirSync,
|
||||
emptydirSync: emptyDirSync,
|
||||
emptyDir,
|
||||
emptydir: emptyDir
|
||||
}
|
46
node_modules/fs-extra/lib/ensure/file.js
generated
vendored
Normal file
46
node_modules/fs-extra/lib/ensure/file.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
'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()
|
||||
})
|
||||
}
|
||||
|
||||
pathExists(file, (err, fileExists) => {
|
||||
if (err) return callback(err)
|
||||
if (fileExists) 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) {
|
||||
if (fs.existsSync(file)) return
|
||||
|
||||
const dir = path.dirname(file)
|
||||
if (!fs.existsSync(dir)) {
|
||||
mkdir.mkdirsSync(dir)
|
||||
}
|
||||
|
||||
fs.writeFileSync(file, '')
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
createFile: u(createFile),
|
||||
createFileSync
|
||||
}
|
23
node_modules/fs-extra/lib/ensure/index.js
generated
vendored
Normal file
23
node_modules/fs-extra/lib/ensure/index.js
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
'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
|
||||
}
|
61
node_modules/fs-extra/lib/ensure/link.js
generated
vendored
Normal file
61
node_modules/fs-extra/lib/ensure/link.js
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
'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
|
||||
}
|
99
node_modules/fs-extra/lib/ensure/symlink-paths.js
generated
vendored
Normal file
99
node_modules/fs-extra/lib/ensure/symlink-paths.js
generated
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
'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
|
||||
}
|
31
node_modules/fs-extra/lib/ensure/symlink-type.js
generated
vendored
Normal file
31
node_modules/fs-extra/lib/ensure/symlink-type.js
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
'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
|
||||
}
|
66
node_modules/fs-extra/lib/ensure/symlink.js
generated
vendored
Normal file
66
node_modules/fs-extra/lib/ensure/symlink.js
generated
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
'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
|
||||
}
|
61
node_modules/fs-extra/lib/fs/index.js
generated
vendored
Normal file
61
node_modules/fs-extra/lib/fs/index.js
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
// This is adapted from https://github.com/normalize/mz
|
||||
// Copyright (c) 2014-2016 Jonathan Ong me@jongleberry.com and Contributors
|
||||
const u = require('universalify').fromCallback
|
||||
const fs = require('graceful-fs')
|
||||
|
||||
const api = [
|
||||
'access',
|
||||
'appendFile',
|
||||
'chmod',
|
||||
'chown',
|
||||
'close',
|
||||
'fchmod',
|
||||
'fchown',
|
||||
'fdatasync',
|
||||
'fstat',
|
||||
'fsync',
|
||||
'ftruncate',
|
||||
'futimes',
|
||||
'lchown',
|
||||
'link',
|
||||
'lstat',
|
||||
'mkdir',
|
||||
'open',
|
||||
'read',
|
||||
'readFile',
|
||||
'readdir',
|
||||
'readlink',
|
||||
'realpath',
|
||||
'rename',
|
||||
'rmdir',
|
||||
'stat',
|
||||
'symlink',
|
||||
'truncate',
|
||||
'unlink',
|
||||
'utimes',
|
||||
'write',
|
||||
'writeFile'
|
||||
]
|
||||
// fs.mkdtemp() was added in Node.js v5.10.0, so check if it exists
|
||||
typeof fs.mkdtemp === 'function' && api.push('mkdtemp')
|
||||
|
||||
// Export all keys:
|
||||
Object.keys(fs).forEach(key => {
|
||||
exports[key] = fs[key]
|
||||
})
|
||||
|
||||
// Universalify async methods:
|
||||
api.forEach(method => {
|
||||
exports[method] = u(fs[method])
|
||||
})
|
||||
|
||||
// We differ from mz/fs in that we still ship the old, broken, fs.exists()
|
||||
// since we are a drop-in replacement for the native module
|
||||
exports.exists = function (filename, callback) {
|
||||
if (typeof callback === 'function') {
|
||||
return fs.exists(filename, callback)
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
return fs.exists(filename, resolve)
|
||||
})
|
||||
}
|
22
node_modules/fs-extra/lib/index.js
generated
vendored
Normal file
22
node_modules/fs-extra/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
'use strict'
|
||||
|
||||
const assign = require('./util/assign')
|
||||
|
||||
const fs = {}
|
||||
|
||||
// Export graceful-fs:
|
||||
assign(fs, require('./fs'))
|
||||
// Export extra methods:
|
||||
assign(fs, require('./copy'))
|
||||
assign(fs, require('./copy-sync'))
|
||||
assign(fs, require('./mkdirs'))
|
||||
assign(fs, require('./remove'))
|
||||
assign(fs, require('./json'))
|
||||
assign(fs, require('./move'))
|
||||
assign(fs, require('./move-sync'))
|
||||
assign(fs, require('./empty'))
|
||||
assign(fs, require('./ensure'))
|
||||
assign(fs, require('./output'))
|
||||
assign(fs, require('./path-exists'))
|
||||
|
||||
module.exports = fs
|
16
node_modules/fs-extra/lib/json/index.js
generated
vendored
Normal file
16
node_modules/fs-extra/lib/json/index.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
'use strict'
|
||||
|
||||
const u = require('universalify').fromCallback
|
||||
const jsonFile = require('./jsonfile')
|
||||
|
||||
jsonFile.outputJsonSync = require('./output-json-sync')
|
||||
jsonFile.outputJson = u(require('./output-json'))
|
||||
// aliases
|
||||
jsonFile.outputJSONSync = jsonFile.outputJSONSync
|
||||
jsonFile.outputJSON = jsonFile.outputJson
|
||||
jsonFile.writeJSON = jsonFile.writeJson
|
||||
jsonFile.writeJSONSync = jsonFile.writeJsonSync
|
||||
jsonFile.readJSON = jsonFile.readJson
|
||||
jsonFile.readJSONSync = jsonFile.readJsonSync
|
||||
|
||||
module.exports = jsonFile
|
12
node_modules/fs-extra/lib/json/jsonfile.js
generated
vendored
Normal file
12
node_modules/fs-extra/lib/json/jsonfile.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
const u = require('universalify').fromCallback
|
||||
const jsonFile = require('jsonfile')
|
||||
|
||||
module.exports = {
|
||||
// jsonfile exports
|
||||
readJson: u(jsonFile.readFile),
|
||||
readJsonSync: jsonFile.readFileSync,
|
||||
writeJson: u(jsonFile.writeFile),
|
||||
writeJsonSync: jsonFile.writeFileSync
|
||||
}
|
18
node_modules/fs-extra/lib/json/output-json-sync.js
generated
vendored
Normal file
18
node_modules/fs-extra/lib/json/output-json-sync.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const path = require('path')
|
||||
const mkdir = require('../mkdirs')
|
||||
const jsonFile = require('./jsonfile')
|
||||
|
||||
function outputJsonSync (file, data, options) {
|
||||
const dir = path.dirname(file)
|
||||
|
||||
if (!fs.existsSync(dir)) {
|
||||
mkdir.mkdirsSync(dir)
|
||||
}
|
||||
|
||||
jsonFile.writeJsonSync(file, data, options)
|
||||
}
|
||||
|
||||
module.exports = outputJsonSync
|
27
node_modules/fs-extra/lib/json/output-json.js
generated
vendored
Normal file
27
node_modules/fs-extra/lib/json/output-json.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
'use strict'
|
||||
|
||||
const path = require('path')
|
||||
const mkdir = require('../mkdirs')
|
||||
const pathExists = require('../path-exists').pathExists
|
||||
const jsonFile = require('./jsonfile')
|
||||
|
||||
function outputJson (file, data, options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options
|
||||
options = {}
|
||||
}
|
||||
|
||||
const dir = path.dirname(file)
|
||||
|
||||
pathExists(dir, (err, itDoes) => {
|
||||
if (err) return callback(err)
|
||||
if (itDoes) return jsonFile.writeJson(file, data, options, callback)
|
||||
|
||||
mkdir.mkdirs(dir, err => {
|
||||
if (err) return callback(err)
|
||||
jsonFile.writeJson(file, data, options, callback)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = outputJson
|
14
node_modules/fs-extra/lib/mkdirs/index.js
generated
vendored
Normal file
14
node_modules/fs-extra/lib/mkdirs/index.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
'use strict'
|
||||
const u = require('universalify').fromCallback
|
||||
const mkdirs = u(require('./mkdirs'))
|
||||
const mkdirsSync = require('./mkdirs-sync')
|
||||
|
||||
module.exports = {
|
||||
mkdirs: mkdirs,
|
||||
mkdirsSync: mkdirsSync,
|
||||
// alias
|
||||
mkdirp: mkdirs,
|
||||
mkdirpSync: mkdirsSync,
|
||||
ensureDir: mkdirs,
|
||||
ensureDirSync: mkdirsSync
|
||||
}
|
59
node_modules/fs-extra/lib/mkdirs/mkdirs-sync.js
generated
vendored
Normal file
59
node_modules/fs-extra/lib/mkdirs/mkdirs-sync.js
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const path = require('path')
|
||||
const invalidWin32Path = require('./win32').invalidWin32Path
|
||||
|
||||
const o777 = parseInt('0777', 8)
|
||||
|
||||
function mkdirsSync (p, opts, made) {
|
||||
if (!opts || typeof opts !== 'object') {
|
||||
opts = { mode: opts }
|
||||
}
|
||||
|
||||
let mode = opts.mode
|
||||
const xfs = opts.fs || fs
|
||||
|
||||
if (process.platform === 'win32' && invalidWin32Path(p)) {
|
||||
const errInval = new Error(p + ' contains invalid WIN32 path characters.')
|
||||
errInval.code = 'EINVAL'
|
||||
throw errInval
|
||||
}
|
||||
|
||||
if (mode === undefined) {
|
||||
mode = o777 & (~process.umask())
|
||||
}
|
||||
if (!made) made = null
|
||||
|
||||
p = path.resolve(p)
|
||||
|
||||
try {
|
||||
xfs.mkdirSync(p, mode)
|
||||
made = made || p
|
||||
} catch (err0) {
|
||||
switch (err0.code) {
|
||||
case 'ENOENT':
|
||||
if (path.dirname(p) === p) throw err0
|
||||
made = mkdirsSync(path.dirname(p), opts, made)
|
||||
mkdirsSync(p, opts, made)
|
||||
break
|
||||
|
||||
// In the case of any other error, just see if there's a dir
|
||||
// there already. If so, then hooray! If not, then something
|
||||
// is borked.
|
||||
default:
|
||||
let stat
|
||||
try {
|
||||
stat = xfs.statSync(p)
|
||||
} catch (err1) {
|
||||
throw err0
|
||||
}
|
||||
if (!stat.isDirectory()) throw err0
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return made
|
||||
}
|
||||
|
||||
module.exports = mkdirsSync
|
63
node_modules/fs-extra/lib/mkdirs/mkdirs.js
generated
vendored
Normal file
63
node_modules/fs-extra/lib/mkdirs/mkdirs.js
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const path = require('path')
|
||||
const invalidWin32Path = require('./win32').invalidWin32Path
|
||||
|
||||
const o777 = parseInt('0777', 8)
|
||||
|
||||
function mkdirs (p, opts, callback, made) {
|
||||
if (typeof opts === 'function') {
|
||||
callback = opts
|
||||
opts = {}
|
||||
} else if (!opts || typeof opts !== 'object') {
|
||||
opts = { mode: opts }
|
||||
}
|
||||
|
||||
if (process.platform === 'win32' && invalidWin32Path(p)) {
|
||||
const errInval = new Error(p + ' contains invalid WIN32 path characters.')
|
||||
errInval.code = 'EINVAL'
|
||||
return callback(errInval)
|
||||
}
|
||||
|
||||
let mode = opts.mode
|
||||
const xfs = opts.fs || fs
|
||||
|
||||
if (mode === undefined) {
|
||||
mode = o777 & (~process.umask())
|
||||
}
|
||||
if (!made) made = null
|
||||
|
||||
callback = callback || function () {}
|
||||
p = path.resolve(p)
|
||||
|
||||
xfs.mkdir(p, mode, er => {
|
||||
if (!er) {
|
||||
made = made || p
|
||||
return callback(null, made)
|
||||
}
|
||||
switch (er.code) {
|
||||
case 'ENOENT':
|
||||
if (path.dirname(p) === p) return callback(er)
|
||||
mkdirs(path.dirname(p), opts, (er, made) => {
|
||||
if (er) callback(er, made)
|
||||
else mkdirs(p, opts, callback, made)
|
||||
})
|
||||
break
|
||||
|
||||
// In the case of any other error, just see if there's a dir
|
||||
// there already. If so, then hooray! If not, then something
|
||||
// is borked.
|
||||
default:
|
||||
xfs.stat(p, (er2, stat) => {
|
||||
// if the stat fails, then that's super weird.
|
||||
// let the original error be the failure reason.
|
||||
if (er2 || !stat.isDirectory()) callback(er, made)
|
||||
else callback(null, made)
|
||||
})
|
||||
break
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = mkdirs
|
25
node_modules/fs-extra/lib/mkdirs/win32.js
generated
vendored
Normal file
25
node_modules/fs-extra/lib/mkdirs/win32.js
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
'use strict'
|
||||
|
||||
const path = require('path')
|
||||
|
||||
// get drive on windows
|
||||
function getRootPath (p) {
|
||||
p = path.normalize(path.resolve(p)).split(path.sep)
|
||||
if (p.length > 0) return p[0]
|
||||
return null
|
||||
}
|
||||
|
||||
// http://stackoverflow.com/a/62888/10333 contains more accurate
|
||||
// TODO: expand to include the rest
|
||||
const INVALID_PATH_CHARS = /[<>:"|?*]/
|
||||
|
||||
function invalidWin32Path (p) {
|
||||
const rp = getRootPath(p)
|
||||
p = p.replace(rp, '')
|
||||
return INVALID_PATH_CHARS.test(p)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getRootPath,
|
||||
invalidWin32Path
|
||||
}
|
118
node_modules/fs-extra/lib/move-sync/index.js
generated
vendored
Normal file
118
node_modules/fs-extra/lib/move-sync/index.js
generated
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const path = require('path')
|
||||
const copySync = require('../copy-sync').copySync
|
||||
const removeSync = require('../remove').removeSync
|
||||
const mkdirpSync = require('../mkdirs').mkdirsSync
|
||||
const buffer = require('../util/buffer')
|
||||
|
||||
function moveSync (src, dest, options) {
|
||||
options = options || {}
|
||||
const overwrite = options.overwrite || options.clobber || false
|
||||
|
||||
src = path.resolve(src)
|
||||
dest = path.resolve(dest)
|
||||
|
||||
if (src === dest) return fs.accessSync(src)
|
||||
|
||||
if (isSrcSubdir(src, dest)) throw new Error(`Cannot move '${src}' into itself '${dest}'.`)
|
||||
|
||||
mkdirpSync(path.dirname(dest))
|
||||
tryRenameSync()
|
||||
|
||||
function tryRenameSync () {
|
||||
if (overwrite) {
|
||||
try {
|
||||
return fs.renameSync(src, dest)
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOTEMPTY' || err.code === 'EEXIST' || err.code === 'EPERM') {
|
||||
removeSync(dest)
|
||||
options.overwrite = false // just overwriteed it, no need to do it again
|
||||
return moveSync(src, dest, options)
|
||||
}
|
||||
|
||||
if (err.code !== 'EXDEV') throw err
|
||||
return moveSyncAcrossDevice(src, dest, overwrite)
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
fs.linkSync(src, dest)
|
||||
return fs.unlinkSync(src)
|
||||
} catch (err) {
|
||||
if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM' || err.code === 'ENOTSUP') {
|
||||
return moveSyncAcrossDevice(src, dest, overwrite)
|
||||
}
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function moveSyncAcrossDevice (src, dest, overwrite) {
|
||||
const stat = fs.statSync(src)
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
return moveDirSyncAcrossDevice(src, dest, overwrite)
|
||||
} else {
|
||||
return moveFileSyncAcrossDevice(src, dest, overwrite)
|
||||
}
|
||||
}
|
||||
|
||||
function moveFileSyncAcrossDevice (src, dest, overwrite) {
|
||||
const BUF_LENGTH = 64 * 1024
|
||||
const _buff = buffer(BUF_LENGTH)
|
||||
|
||||
const flags = overwrite ? 'w' : 'wx'
|
||||
|
||||
const fdr = fs.openSync(src, 'r')
|
||||
const stat = fs.fstatSync(fdr)
|
||||
const fdw = fs.openSync(dest, flags, stat.mode)
|
||||
let bytesRead = 1
|
||||
let pos = 0
|
||||
|
||||
while (bytesRead > 0) {
|
||||
bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
|
||||
fs.writeSync(fdw, _buff, 0, bytesRead)
|
||||
pos += bytesRead
|
||||
}
|
||||
|
||||
fs.closeSync(fdr)
|
||||
fs.closeSync(fdw)
|
||||
return fs.unlinkSync(src)
|
||||
}
|
||||
|
||||
function moveDirSyncAcrossDevice (src, dest, overwrite) {
|
||||
const options = {
|
||||
overwrite: false
|
||||
}
|
||||
|
||||
if (overwrite) {
|
||||
removeSync(dest)
|
||||
tryCopySync()
|
||||
} else {
|
||||
tryCopySync()
|
||||
}
|
||||
|
||||
function tryCopySync () {
|
||||
copySync(src, dest, options)
|
||||
return removeSync(src)
|
||||
}
|
||||
}
|
||||
|
||||
// return true if dest is a subdir of src, otherwise false.
|
||||
// extract dest base dir and check if that is the same as src basename
|
||||
function isSrcSubdir (src, dest) {
|
||||
try {
|
||||
return fs.statSync(src).isDirectory() &&
|
||||
src !== dest &&
|
||||
dest.indexOf(src) > -1 &&
|
||||
dest.split(path.dirname(src) + path.sep)[1].split(path.sep)[0] === path.basename(src)
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
moveSync
|
||||
}
|
162
node_modules/fs-extra/lib/move/index.js
generated
vendored
Normal file
162
node_modules/fs-extra/lib/move/index.js
generated
vendored
Normal file
@ -0,0 +1,162 @@
|
||||
'use strict'
|
||||
|
||||
// most of this code was written by Andrew Kelley
|
||||
// licensed under the BSD license: see
|
||||
// https://github.com/andrewrk/node-mv/blob/master/package.json
|
||||
|
||||
// this needs a cleanup
|
||||
|
||||
const u = require('universalify').fromCallback
|
||||
const fs = require('graceful-fs')
|
||||
const ncp = require('../copy/ncp')
|
||||
const path = require('path')
|
||||
const remove = require('../remove').remove
|
||||
const mkdirp = require('../mkdirs').mkdirs
|
||||
|
||||
function move (source, dest, options, callback) {
|
||||
if (typeof options === 'function') {
|
||||
callback = options
|
||||
options = {}
|
||||
}
|
||||
|
||||
const shouldMkdirp = ('mkdirp' in options) ? options.mkdirp : true
|
||||
const overwrite = options.overwrite || options.clobber || false
|
||||
|
||||
if (shouldMkdirp) {
|
||||
mkdirs()
|
||||
} else {
|
||||
doRename()
|
||||
}
|
||||
|
||||
function mkdirs () {
|
||||
mkdirp(path.dirname(dest), err => {
|
||||
if (err) return callback(err)
|
||||
doRename()
|
||||
})
|
||||
}
|
||||
|
||||
function doRename () {
|
||||
if (path.resolve(source) === path.resolve(dest)) {
|
||||
fs.access(source, callback)
|
||||
} else if (overwrite) {
|
||||
fs.rename(source, dest, err => {
|
||||
if (!err) return callback()
|
||||
|
||||
if (err.code === 'ENOTEMPTY' || err.code === 'EEXIST') {
|
||||
remove(dest, err => {
|
||||
if (err) return callback(err)
|
||||
options.overwrite = false // just overwriteed it, no need to do it again
|
||||
move(source, dest, options, callback)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// weird Windows shit
|
||||
if (err.code === 'EPERM') {
|
||||
setTimeout(() => {
|
||||
remove(dest, err => {
|
||||
if (err) return callback(err)
|
||||
options.overwrite = false
|
||||
move(source, dest, options, callback)
|
||||
})
|
||||
}, 200)
|
||||
return
|
||||
}
|
||||
|
||||
if (err.code !== 'EXDEV') return callback(err)
|
||||
moveAcrossDevice(source, dest, overwrite, callback)
|
||||
})
|
||||
} else {
|
||||
fs.link(source, dest, err => {
|
||||
if (err) {
|
||||
if (err.code === 'EXDEV' || err.code === 'EISDIR' || err.code === 'EPERM' || err.code === 'ENOTSUP') {
|
||||
moveAcrossDevice(source, dest, overwrite, callback)
|
||||
return
|
||||
}
|
||||
callback(err)
|
||||
return
|
||||
}
|
||||
fs.unlink(source, callback)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function moveAcrossDevice (source, dest, overwrite, callback) {
|
||||
fs.stat(source, (err, stat) => {
|
||||
if (err) {
|
||||
callback(err)
|
||||
return
|
||||
}
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
moveDirAcrossDevice(source, dest, overwrite, callback)
|
||||
} else {
|
||||
moveFileAcrossDevice(source, dest, overwrite, callback)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function moveFileAcrossDevice (source, dest, overwrite, callback) {
|
||||
const flags = overwrite ? 'w' : 'wx'
|
||||
const ins = fs.createReadStream(source)
|
||||
const outs = fs.createWriteStream(dest, { flags })
|
||||
|
||||
ins.on('error', err => {
|
||||
ins.destroy()
|
||||
outs.destroy()
|
||||
outs.removeListener('close', onClose)
|
||||
|
||||
// may want to create a directory but `out` line above
|
||||
// creates an empty file for us: See #108
|
||||
// don't care about error here
|
||||
fs.unlink(dest, () => {
|
||||
// note: `err` here is from the input stream errror
|
||||
if (err.code === 'EISDIR' || err.code === 'EPERM') {
|
||||
moveDirAcrossDevice(source, dest, overwrite, callback)
|
||||
} else {
|
||||
callback(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
outs.on('error', err => {
|
||||
ins.destroy()
|
||||
outs.destroy()
|
||||
outs.removeListener('close', onClose)
|
||||
callback(err)
|
||||
})
|
||||
|
||||
outs.once('close', onClose)
|
||||
ins.pipe(outs)
|
||||
|
||||
function onClose () {
|
||||
fs.unlink(source, callback)
|
||||
}
|
||||
}
|
||||
|
||||
function moveDirAcrossDevice (source, dest, overwrite, callback) {
|
||||
const options = {
|
||||
overwrite: false
|
||||
}
|
||||
|
||||
if (overwrite) {
|
||||
remove(dest, err => {
|
||||
if (err) return callback(err)
|
||||
startNcp()
|
||||
})
|
||||
} else {
|
||||
startNcp()
|
||||
}
|
||||
|
||||
function startNcp () {
|
||||
ncp(source, dest, options, err => {
|
||||
if (err) return callback(err)
|
||||
remove(source, callback)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
move: u(move)
|
||||
}
|
40
node_modules/fs-extra/lib/output/index.js
generated
vendored
Normal file
40
node_modules/fs-extra/lib/output/index.js
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
'use strict'
|
||||
|
||||
const u = require('universalify').fromCallback
|
||||
const fs = require('graceful-fs')
|
||||
const path = require('path')
|
||||
const mkdir = require('../mkdirs')
|
||||
const pathExists = require('../path-exists').pathExists
|
||||
|
||||
function outputFile (file, data, encoding, callback) {
|
||||
if (typeof encoding === 'function') {
|
||||
callback = encoding
|
||||
encoding = 'utf8'
|
||||
}
|
||||
|
||||
const dir = path.dirname(file)
|
||||
pathExists(dir, (err, itDoes) => {
|
||||
if (err) return callback(err)
|
||||
if (itDoes) return fs.writeFile(file, data, encoding, callback)
|
||||
|
||||
mkdir.mkdirs(dir, err => {
|
||||
if (err) return callback(err)
|
||||
|
||||
fs.writeFile(file, data, encoding, callback)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function outputFileSync (file, data, encoding) {
|
||||
const dir = path.dirname(file)
|
||||
if (fs.existsSync(dir)) {
|
||||
return fs.writeFileSync.apply(fs, arguments)
|
||||
}
|
||||
mkdir.mkdirsSync(dir)
|
||||
fs.writeFileSync.apply(fs, arguments)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
outputFile: u(outputFile),
|
||||
outputFileSync
|
||||
}
|
12
node_modules/fs-extra/lib/path-exists/index.js
generated
vendored
Normal file
12
node_modules/fs-extra/lib/path-exists/index.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict'
|
||||
const u = require('universalify').fromPromise
|
||||
const fs = require('../fs')
|
||||
|
||||
function pathExists (path) {
|
||||
return fs.access(path).then(() => true).catch(() => false)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
pathExists: u(pathExists),
|
||||
pathExistsSync: fs.existsSync
|
||||
}
|
9
node_modules/fs-extra/lib/remove/index.js
generated
vendored
Normal file
9
node_modules/fs-extra/lib/remove/index.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict'
|
||||
|
||||
const u = require('universalify').fromCallback
|
||||
const rimraf = require('./rimraf')
|
||||
|
||||
module.exports = {
|
||||
remove: u(rimraf),
|
||||
removeSync: rimraf.sync
|
||||
}
|
296
node_modules/fs-extra/lib/remove/rimraf.js
generated
vendored
Normal file
296
node_modules/fs-extra/lib/remove/rimraf.js
generated
vendored
Normal file
@ -0,0 +1,296 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const path = require('path')
|
||||
const assert = require('assert')
|
||||
|
||||
const isWindows = (process.platform === 'win32')
|
||||
|
||||
function defaults (options) {
|
||||
const methods = [
|
||||
'unlink',
|
||||
'chmod',
|
||||
'stat',
|
||||
'lstat',
|
||||
'rmdir',
|
||||
'readdir'
|
||||
]
|
||||
methods.forEach(m => {
|
||||
options[m] = options[m] || fs[m]
|
||||
m = m + 'Sync'
|
||||
options[m] = options[m] || fs[m]
|
||||
})
|
||||
|
||||
options.maxBusyTries = options.maxBusyTries || 3
|
||||
}
|
||||
|
||||
function rimraf (p, options, cb) {
|
||||
let busyTries = 0
|
||||
|
||||
if (typeof options === 'function') {
|
||||
cb = options
|
||||
options = {}
|
||||
}
|
||||
|
||||
assert(p, 'rimraf: missing path')
|
||||
assert.equal(typeof p, 'string', 'rimraf: path should be a string')
|
||||
assert.equal(typeof cb, 'function', 'rimraf: callback function required')
|
||||
assert(options, 'rimraf: invalid options argument provided')
|
||||
assert.equal(typeof options, 'object', 'rimraf: options should be object')
|
||||
|
||||
defaults(options)
|
||||
|
||||
rimraf_(p, options, function CB (er) {
|
||||
if (er) {
|
||||
if (isWindows && (er.code === 'EBUSY' || er.code === 'ENOTEMPTY' || er.code === 'EPERM') &&
|
||||
busyTries < options.maxBusyTries) {
|
||||
busyTries++
|
||||
let time = busyTries * 100
|
||||
// try again, with the same exact callback as this one.
|
||||
return setTimeout(() => rimraf_(p, options, CB), time)
|
||||
}
|
||||
|
||||
// already gone
|
||||
if (er.code === 'ENOENT') er = null
|
||||
}
|
||||
|
||||
cb(er)
|
||||
})
|
||||
}
|
||||
|
||||
// Two possible strategies.
|
||||
// 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR
|
||||
// 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR
|
||||
//
|
||||
// Both result in an extra syscall when you guess wrong. However, there
|
||||
// are likely far more normal files in the world than directories. This
|
||||
// is based on the assumption that a the average number of files per
|
||||
// directory is >= 1.
|
||||
//
|
||||
// If anyone ever complains about this, then I guess the strategy could
|
||||
// be made configurable somehow. But until then, YAGNI.
|
||||
function rimraf_ (p, options, cb) {
|
||||
assert(p)
|
||||
assert(options)
|
||||
assert(typeof cb === 'function')
|
||||
|
||||
// sunos lets the root user unlink directories, which is... weird.
|
||||
// so we have to lstat here and make sure it's not a dir.
|
||||
options.lstat(p, (er, st) => {
|
||||
if (er && er.code === 'ENOENT') {
|
||||
return cb(null)
|
||||
}
|
||||
|
||||
// Windows can EPERM on stat. Life is suffering.
|
||||
if (er && er.code === 'EPERM' && isWindows) {
|
||||
return fixWinEPERM(p, options, er, cb)
|
||||
}
|
||||
|
||||
if (st && st.isDirectory()) {
|
||||
return rmdir(p, options, er, cb)
|
||||
}
|
||||
|
||||
options.unlink(p, er => {
|
||||
if (er) {
|
||||
if (er.code === 'ENOENT') {
|
||||
return cb(null)
|
||||
}
|
||||
if (er.code === 'EPERM') {
|
||||
return (isWindows)
|
||||
? fixWinEPERM(p, options, er, cb)
|
||||
: rmdir(p, options, er, cb)
|
||||
}
|
||||
if (er.code === 'EISDIR') {
|
||||
return rmdir(p, options, er, cb)
|
||||
}
|
||||
}
|
||||
return cb(er)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function fixWinEPERM (p, options, er, cb) {
|
||||
assert(p)
|
||||
assert(options)
|
||||
assert(typeof cb === 'function')
|
||||
if (er) {
|
||||
assert(er instanceof Error)
|
||||
}
|
||||
|
||||
options.chmod(p, 666, er2 => {
|
||||
if (er2) {
|
||||
cb(er2.code === 'ENOENT' ? null : er)
|
||||
} else {
|
||||
options.stat(p, (er3, stats) => {
|
||||
if (er3) {
|
||||
cb(er3.code === 'ENOENT' ? null : er)
|
||||
} else if (stats.isDirectory()) {
|
||||
rmdir(p, options, er, cb)
|
||||
} else {
|
||||
options.unlink(p, cb)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function fixWinEPERMSync (p, options, er) {
|
||||
let stats
|
||||
|
||||
assert(p)
|
||||
assert(options)
|
||||
if (er) {
|
||||
assert(er instanceof Error)
|
||||
}
|
||||
|
||||
try {
|
||||
options.chmodSync(p, 666)
|
||||
} catch (er2) {
|
||||
if (er2.code === 'ENOENT') {
|
||||
return
|
||||
} else {
|
||||
throw er
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
stats = options.statSync(p)
|
||||
} catch (er3) {
|
||||
if (er3.code === 'ENOENT') {
|
||||
return
|
||||
} else {
|
||||
throw er
|
||||
}
|
||||
}
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
rmdirSync(p, options, er)
|
||||
} else {
|
||||
options.unlinkSync(p)
|
||||
}
|
||||
}
|
||||
|
||||
function rmdir (p, options, originalEr, cb) {
|
||||
assert(p)
|
||||
assert(options)
|
||||
if (originalEr) {
|
||||
assert(originalEr instanceof Error)
|
||||
}
|
||||
assert(typeof cb === 'function')
|
||||
|
||||
// try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
|
||||
// if we guessed wrong, and it's not a directory, then
|
||||
// raise the original error.
|
||||
options.rmdir(p, er => {
|
||||
if (er && (er.code === 'ENOTEMPTY' || er.code === 'EEXIST' || er.code === 'EPERM')) {
|
||||
rmkids(p, options, cb)
|
||||
} else if (er && er.code === 'ENOTDIR') {
|
||||
cb(originalEr)
|
||||
} else {
|
||||
cb(er)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function rmkids (p, options, cb) {
|
||||
assert(p)
|
||||
assert(options)
|
||||
assert(typeof cb === 'function')
|
||||
|
||||
options.readdir(p, (er, files) => {
|
||||
if (er) return cb(er)
|
||||
|
||||
let n = files.length
|
||||
let errState
|
||||
|
||||
if (n === 0) return options.rmdir(p, cb)
|
||||
|
||||
files.forEach(f => {
|
||||
rimraf(path.join(p, f), options, er => {
|
||||
if (errState) {
|
||||
return
|
||||
}
|
||||
if (er) return cb(errState = er)
|
||||
if (--n === 0) {
|
||||
options.rmdir(p, cb)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// this looks simpler, and is strictly *faster*, but will
|
||||
// tie up the JavaScript thread and fail on excessively
|
||||
// deep directory trees.
|
||||
function rimrafSync (p, options) {
|
||||
let st
|
||||
|
||||
options = options || {}
|
||||
defaults(options)
|
||||
|
||||
assert(p, 'rimraf: missing path')
|
||||
assert.equal(typeof p, 'string', 'rimraf: path should be a string')
|
||||
assert(options, 'rimraf: missing options')
|
||||
assert.equal(typeof options, 'object', 'rimraf: options should be object')
|
||||
|
||||
try {
|
||||
st = options.lstatSync(p)
|
||||
} catch (er) {
|
||||
if (er.code === 'ENOENT') {
|
||||
return
|
||||
}
|
||||
|
||||
// Windows can EPERM on stat. Life is suffering.
|
||||
if (er.code === 'EPERM' && isWindows) {
|
||||
fixWinEPERMSync(p, options, er)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// sunos lets the root user unlink directories, which is... weird.
|
||||
if (st && st.isDirectory()) {
|
||||
rmdirSync(p, options, null)
|
||||
} else {
|
||||
options.unlinkSync(p)
|
||||
}
|
||||
} catch (er) {
|
||||
if (er.code === 'ENOENT') {
|
||||
return
|
||||
} else if (er.code === 'EPERM') {
|
||||
return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er)
|
||||
} else if (er.code !== 'EISDIR') {
|
||||
throw er
|
||||
}
|
||||
rmdirSync(p, options, er)
|
||||
}
|
||||
}
|
||||
|
||||
function rmdirSync (p, options, originalEr) {
|
||||
assert(p)
|
||||
assert(options)
|
||||
if (originalEr) {
|
||||
assert(originalEr instanceof Error)
|
||||
}
|
||||
|
||||
try {
|
||||
options.rmdirSync(p)
|
||||
} catch (er) {
|
||||
if (er.code === 'ENOTDIR') {
|
||||
throw originalEr
|
||||
} else if (er.code === 'ENOTEMPTY' || er.code === 'EEXIST' || er.code === 'EPERM') {
|
||||
rmkidsSync(p, options)
|
||||
} else if (er.code !== 'ENOENT') {
|
||||
throw er
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function rmkidsSync (p, options) {
|
||||
assert(p)
|
||||
assert(options)
|
||||
options.readdirSync(p).forEach(f => rimrafSync(path.join(p, f), options))
|
||||
options.rmdirSync(p, options)
|
||||
}
|
||||
|
||||
module.exports = rimraf
|
||||
rimraf.sync = rimrafSync
|
16
node_modules/fs-extra/lib/util/assign.js
generated
vendored
Normal file
16
node_modules/fs-extra/lib/util/assign.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
'use strict'
|
||||
|
||||
// simple mutable assign
|
||||
function assign () {
|
||||
const args = [].slice.call(arguments).filter(i => i)
|
||||
const dest = args.shift()
|
||||
args.forEach(src => {
|
||||
Object.keys(src).forEach(key => {
|
||||
dest[key] = src[key]
|
||||
})
|
||||
})
|
||||
|
||||
return dest
|
||||
}
|
||||
|
||||
module.exports = assign
|
11
node_modules/fs-extra/lib/util/buffer.js
generated
vendored
Normal file
11
node_modules/fs-extra/lib/util/buffer.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/* eslint-disable node/no-deprecated-api */
|
||||
module.exports = function (size) {
|
||||
if (typeof Buffer.allocUnsafe === 'function') {
|
||||
try {
|
||||
return Buffer.allocUnsafe(size)
|
||||
} catch (e) {
|
||||
return new Buffer(size)
|
||||
}
|
||||
}
|
||||
return new Buffer(size)
|
||||
}
|
72
node_modules/fs-extra/lib/util/utimes.js
generated
vendored
Normal file
72
node_modules/fs-extra/lib/util/utimes.js
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('graceful-fs')
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
|
||||
// HFS, ext{2,3}, FAT do not, Node.js v0.10 does not
|
||||
function hasMillisResSync () {
|
||||
let tmpfile = path.join('millis-test-sync' + Date.now().toString() + Math.random().toString().slice(2))
|
||||
tmpfile = path.join(os.tmpdir(), tmpfile)
|
||||
|
||||
// 550 millis past UNIX epoch
|
||||
const d = new Date(1435410243862)
|
||||
fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141')
|
||||
const fd = fs.openSync(tmpfile, 'r+')
|
||||
fs.futimesSync(fd, d, d)
|
||||
fs.closeSync(fd)
|
||||
return fs.statSync(tmpfile).mtime > 1435410243000
|
||||
}
|
||||
|
||||
function hasMillisRes (callback) {
|
||||
let tmpfile = path.join('millis-test' + Date.now().toString() + Math.random().toString().slice(2))
|
||||
tmpfile = path.join(os.tmpdir(), tmpfile)
|
||||
|
||||
// 550 millis past UNIX epoch
|
||||
const d = new Date(1435410243862)
|
||||
fs.writeFile(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141', err => {
|
||||
if (err) return callback(err)
|
||||
fs.open(tmpfile, 'r+', (err, fd) => {
|
||||
if (err) return callback(err)
|
||||
fs.futimes(fd, d, d, err => {
|
||||
if (err) return callback(err)
|
||||
fs.close(fd, err => {
|
||||
if (err) return callback(err)
|
||||
fs.stat(tmpfile, (err, stats) => {
|
||||
if (err) return callback(err)
|
||||
callback(null, stats.mtime > 1435410243000)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function timeRemoveMillis (timestamp) {
|
||||
if (typeof timestamp === 'number') {
|
||||
return Math.floor(timestamp / 1000) * 1000
|
||||
} else if (timestamp instanceof Date) {
|
||||
return new Date(Math.floor(timestamp.getTime() / 1000) * 1000)
|
||||
} else {
|
||||
throw new Error('fs-extra: timeRemoveMillis() unknown parameter type')
|
||||
}
|
||||
}
|
||||
|
||||
function utimesMillis (path, atime, mtime, callback) {
|
||||
// if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
|
||||
fs.open(path, 'r+', (err, fd) => {
|
||||
if (err) return callback(err)
|
||||
fs.futimes(fd, atime, mtime, futimesErr => {
|
||||
fs.close(fd, closeErr => {
|
||||
if (callback) callback(futimesErr || closeErr)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
hasMillisRes,
|
||||
hasMillisResSync,
|
||||
timeRemoveMillis,
|
||||
utimesMillis
|
||||
}
|
Reference in New Issue
Block a user