12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154 |
- module.exports = (function() {
- var __MODS__ = {};
- var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
- var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
- var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
- var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
- __DEFINE__(1677462587430, function(require, module, exports) {
- module.exports = {
- // Export promiseified graceful-fs:
- ...require('./fs'),
- // Export extra methods:
- ...require('./copy'),
- ...require('./empty'),
- ...require('./ensure'),
- ...require('./json'),
- ...require('./mkdirs'),
- ...require('./move'),
- ...require('./output-file'),
- ...require('./path-exists'),
- ...require('./remove')
- }
- }, function(modId) {var map = {"./fs":1677462587431,"./copy":1677462587432,"./ensure":1677462587442,"./json":1677462587446,"./mkdirs":1677462587434,"./move":1677462587451,"./output-file":1677462587449,"./path-exists":1677462587437,"./remove":1677462587453}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587431, function(require, module, exports) {
- // 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',
- 'copyFile',
- 'fchmod',
- 'fchown',
- 'fdatasync',
- 'fstat',
- 'fsync',
- 'ftruncate',
- 'futimes',
- 'lchmod',
- 'lchown',
- 'link',
- 'lstat',
- 'mkdir',
- 'mkdtemp',
- 'open',
- 'opendir',
- 'readdir',
- 'readFile',
- 'readlink',
- 'realpath',
- 'rename',
- 'rm',
- 'rmdir',
- 'stat',
- 'symlink',
- 'truncate',
- 'unlink',
- 'utimes',
- 'writeFile'
- ].filter(key => {
- // Some commands are not available on some systems. Ex:
- // fs.opendir was added in Node.js v12.12.0
- // fs.rm was added in Node.js v14.14.0
- // fs.lchown is not available on at least some Linux
- return typeof fs[key] === 'function'
- })
- // Export cloned fs:
- Object.assign(exports, fs)
- // 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)
- })
- }
- // fs.read(), fs.write(), & fs.writev() need special treatment due to multiple callback args
- exports.read = function (fd, buffer, offset, length, position, callback) {
- if (typeof callback === 'function') {
- return fs.read(fd, buffer, offset, length, position, callback)
- }
- return new Promise((resolve, reject) => {
- fs.read(fd, buffer, offset, length, position, (err, bytesRead, buffer) => {
- if (err) return reject(err)
- resolve({ bytesRead, buffer })
- })
- })
- }
- // Function signature can be
- // fs.write(fd, buffer[, offset[, length[, position]]], callback)
- // OR
- // fs.write(fd, string[, position[, encoding]], callback)
- // We need to handle both cases, so we use ...args
- exports.write = function (fd, buffer, ...args) {
- if (typeof args[args.length - 1] === 'function') {
- return fs.write(fd, buffer, ...args)
- }
- return new Promise((resolve, reject) => {
- fs.write(fd, buffer, ...args, (err, bytesWritten, buffer) => {
- if (err) return reject(err)
- resolve({ bytesWritten, buffer })
- })
- })
- }
- // fs.writev only available in Node v12.9.0+
- if (typeof fs.writev === 'function') {
- // Function signature is
- // s.writev(fd, buffers[, position], callback)
- // We need to handle the optional arg, so we use ...args
- exports.writev = function (fd, buffers, ...args) {
- if (typeof args[args.length - 1] === 'function') {
- return fs.writev(fd, buffers, ...args)
- }
- return new Promise((resolve, reject) => {
- fs.writev(fd, buffers, ...args, (err, bytesWritten, buffers) => {
- if (err) return reject(err)
- resolve({ bytesWritten, buffers })
- })
- })
- }
- }
- // fs.realpath.native sometimes not available if fs is monkey-patched
- if (typeof fs.realpath.native === 'function') {
- exports.realpath.native = u(fs.realpath.native)
- } else {
- process.emitWarning(
- 'fs.realpath.native is not a function. Is fs being monkey-patched?',
- 'Warning', 'fs-extra-WARN0003'
- )
- }
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587432, function(require, module, exports) {
- const u = require('universalify').fromCallback
- module.exports = {
- copy: u(require('./copy')),
- copySync: require('./copy-sync')
- }
- }, function(modId) { var map = {"./copy":1677462587433,"./copy-sync":1677462587440}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587433, function(require, module, exports) {
- const fs = require('graceful-fs')
- const path = require('path')
- const mkdirs = require('../mkdirs').mkdirs
- const pathExists = require('../path-exists').pathExists
- const utimesMillis = require('../util/utimes').utimesMillis
- const stat = require('../util/stat')
- function copy (src, dest, opts, cb) {
- if (typeof opts === 'function' && !cb) {
- cb = opts
- opts = {}
- } else if (typeof opts === 'function') {
- opts = { filter: opts }
- }
- cb = cb || function () {}
- opts = opts || {}
- opts.clobber = 'clobber' in opts ? !!opts.clobber : true // default to true for now
- opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber // overwrite falls back to clobber
- // Warn about using preserveTimestamps on 32-bit node
- if (opts.preserveTimestamps && process.arch === 'ia32') {
- process.emitWarning(
- 'Using the preserveTimestamps option in 32-bit node is not recommended;\n\n' +
- '\tsee https://github.com/jprichardson/node-fs-extra/issues/269',
- 'Warning', 'fs-extra-WARN0001'
- )
- }
- stat.checkPaths(src, dest, 'copy', opts, (err, stats) => {
- if (err) return cb(err)
- const { srcStat, destStat } = stats
- stat.checkParentPaths(src, srcStat, dest, 'copy', err => {
- if (err) return cb(err)
- if (opts.filter) return handleFilter(checkParentDir, destStat, src, dest, opts, cb)
- return checkParentDir(destStat, src, dest, opts, cb)
- })
- })
- }
- function checkParentDir (destStat, src, dest, opts, cb) {
- const destParent = path.dirname(dest)
- pathExists(destParent, (err, dirExists) => {
- if (err) return cb(err)
- if (dirExists) return getStats(destStat, src, dest, opts, cb)
- mkdirs(destParent, err => {
- if (err) return cb(err)
- return getStats(destStat, src, dest, opts, cb)
- })
- })
- }
- function handleFilter (onInclude, destStat, src, dest, opts, cb) {
- Promise.resolve(opts.filter(src, dest)).then(include => {
- if (include) return onInclude(destStat, src, dest, opts, cb)
- return cb()
- }, error => cb(error))
- }
- function startCopy (destStat, src, dest, opts, cb) {
- if (opts.filter) return handleFilter(getStats, destStat, src, dest, opts, cb)
- return getStats(destStat, src, dest, opts, cb)
- }
- function getStats (destStat, src, dest, opts, cb) {
- const stat = opts.dereference ? fs.stat : fs.lstat
- stat(src, (err, srcStat) => {
- if (err) return cb(err)
- if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts, cb)
- else if (srcStat.isFile() ||
- srcStat.isCharacterDevice() ||
- srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts, cb)
- else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts, cb)
- else if (srcStat.isSocket()) return cb(new Error(`Cannot copy a socket file: ${src}`))
- else if (srcStat.isFIFO()) return cb(new Error(`Cannot copy a FIFO pipe: ${src}`))
- return cb(new Error(`Unknown file: ${src}`))
- })
- }
- function onFile (srcStat, destStat, src, dest, opts, cb) {
- if (!destStat) return copyFile(srcStat, src, dest, opts, cb)
- return mayCopyFile(srcStat, src, dest, opts, cb)
- }
- function mayCopyFile (srcStat, src, dest, opts, cb) {
- if (opts.overwrite) {
- fs.unlink(dest, err => {
- if (err) return cb(err)
- return copyFile(srcStat, src, dest, opts, cb)
- })
- } else if (opts.errorOnExist) {
- return cb(new Error(`'${dest}' already exists`))
- } else return cb()
- }
- function copyFile (srcStat, src, dest, opts, cb) {
- fs.copyFile(src, dest, err => {
- if (err) return cb(err)
- if (opts.preserveTimestamps) return handleTimestampsAndMode(srcStat.mode, src, dest, cb)
- return setDestMode(dest, srcStat.mode, cb)
- })
- }
- function handleTimestampsAndMode (srcMode, src, dest, cb) {
- // Make sure the file is writable before setting the timestamp
- // otherwise open fails with EPERM when invoked with 'r+'
- // (through utimes call)
- if (fileIsNotWritable(srcMode)) {
- return makeFileWritable(dest, srcMode, err => {
- if (err) return cb(err)
- return setDestTimestampsAndMode(srcMode, src, dest, cb)
- })
- }
- return setDestTimestampsAndMode(srcMode, src, dest, cb)
- }
- function fileIsNotWritable (srcMode) {
- return (srcMode & 0o200) === 0
- }
- function makeFileWritable (dest, srcMode, cb) {
- return setDestMode(dest, srcMode | 0o200, cb)
- }
- function setDestTimestampsAndMode (srcMode, src, dest, cb) {
- setDestTimestamps(src, dest, err => {
- if (err) return cb(err)
- return setDestMode(dest, srcMode, cb)
- })
- }
- function setDestMode (dest, srcMode, cb) {
- return fs.chmod(dest, srcMode, cb)
- }
- function setDestTimestamps (src, dest, cb) {
- // The initial srcStat.atime cannot be trusted
- // because it is modified by the read(2) system call
- // (See https://nodejs.org/api/fs.html#fs_stat_time_values)
- fs.stat(src, (err, updatedSrcStat) => {
- if (err) return cb(err)
- return utimesMillis(dest, updatedSrcStat.atime, updatedSrcStat.mtime, cb)
- })
- }
- function onDir (srcStat, destStat, src, dest, opts, cb) {
- if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts, cb)
- return copyDir(src, dest, opts, cb)
- }
- function mkDirAndCopy (srcMode, src, dest, opts, cb) {
- fs.mkdir(dest, err => {
- if (err) return cb(err)
- copyDir(src, dest, opts, err => {
- if (err) return cb(err)
- return setDestMode(dest, srcMode, cb)
- })
- })
- }
- function copyDir (src, dest, opts, cb) {
- fs.readdir(src, (err, items) => {
- if (err) return cb(err)
- return copyDirItems(items, src, dest, opts, cb)
- })
- }
- function copyDirItems (items, src, dest, opts, cb) {
- const item = items.pop()
- if (!item) return cb()
- return copyDirItem(items, item, src, dest, opts, cb)
- }
- function copyDirItem (items, item, src, dest, opts, cb) {
- const srcItem = path.join(src, item)
- const destItem = path.join(dest, item)
- stat.checkPaths(srcItem, destItem, 'copy', opts, (err, stats) => {
- if (err) return cb(err)
- const { destStat } = stats
- startCopy(destStat, srcItem, destItem, opts, err => {
- if (err) return cb(err)
- return copyDirItems(items, src, dest, opts, cb)
- })
- })
- }
- function onLink (destStat, src, dest, opts, cb) {
- fs.readlink(src, (err, resolvedSrc) => {
- if (err) return cb(err)
- if (opts.dereference) {
- resolvedSrc = path.resolve(process.cwd(), resolvedSrc)
- }
- if (!destStat) {
- return fs.symlink(resolvedSrc, dest, cb)
- } else {
- fs.readlink(dest, (err, resolvedDest) => {
- if (err) {
- // dest exists and is a regular file or directory,
- // Windows may throw UNKNOWN error. If dest already exists,
- // fs throws error anyway, so no need to guard against it here.
- if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs.symlink(resolvedSrc, dest, cb)
- return cb(err)
- }
- if (opts.dereference) {
- resolvedDest = path.resolve(process.cwd(), resolvedDest)
- }
- if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
- return cb(new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`))
- }
- // do not copy if src is a subdir of dest since unlinking
- // dest in this case would result in removing src contents
- // and therefore a broken symlink would be created.
- if (destStat.isDirectory() && stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
- return cb(new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`))
- }
- return copyLink(resolvedSrc, dest, cb)
- })
- }
- })
- }
- function copyLink (resolvedSrc, dest, cb) {
- fs.unlink(dest, err => {
- if (err) return cb(err)
- return fs.symlink(resolvedSrc, dest, cb)
- })
- }
- module.exports = copy
- }, function(modId) { var map = {"../mkdirs":1677462587434,"../path-exists":1677462587437,"../util/utimes":1677462587438,"../util/stat":1677462587439}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587434, function(require, module, exports) {
- const u = require('universalify').fromPromise
- const { makeDir: _makeDir, makeDirSync } = require('./make-dir')
- const makeDir = u(_makeDir)
- module.exports = {
- mkdirs: makeDir,
- mkdirsSync: makeDirSync,
- // alias
- mkdirp: makeDir,
- mkdirpSync: makeDirSync,
- ensureDir: makeDir,
- ensureDirSync: makeDirSync
- }
- }, function(modId) { var map = {"./make-dir":1677462587435}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587435, function(require, module, exports) {
- const fs = require('../fs')
- const { checkPath } = require('./utils')
- const getMode = options => {
- const defaults = { mode: 0o777 }
- if (typeof options === 'number') return options
- return ({ ...defaults, ...options }).mode
- }
- module.exports.makeDir = async (dir, options) => {
- checkPath(dir)
- return fs.mkdir(dir, {
- mode: getMode(options),
- recursive: true
- })
- }
- module.exports.makeDirSync = (dir, options) => {
- checkPath(dir)
- return fs.mkdirSync(dir, {
- mode: getMode(options),
- recursive: true
- })
- }
- }, function(modId) { var map = {"../fs":1677462587431,"./utils":1677462587436}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587436, function(require, module, exports) {
- // Adapted from https://github.com/sindresorhus/make-dir
- // Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
- // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- const path = require('path')
- // https://github.com/nodejs/node/issues/8987
- // https://github.com/libuv/libuv/pull/1088
- module.exports.checkPath = function checkPath (pth) {
- if (process.platform === 'win32') {
- const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path.parse(pth).root, ''))
- if (pathHasInvalidWinCharacters) {
- const error = new Error(`Path contains invalid characters: ${pth}`)
- error.code = 'EINVAL'
- throw error
- }
- }
- }
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587437, function(require, module, exports) {
- 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
- }
- }, function(modId) { var map = {"../fs":1677462587431}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587438, function(require, module, exports) {
- const fs = require('graceful-fs')
- 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)
- })
- })
- })
- }
- function utimesMillisSync (path, atime, mtime) {
- const fd = fs.openSync(path, 'r+')
- fs.futimesSync(fd, atime, mtime)
- return fs.closeSync(fd)
- }
- module.exports = {
- utimesMillis,
- utimesMillisSync
- }
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587439, function(require, module, exports) {
- const fs = require('../fs')
- const path = require('path')
- const util = require('util')
- function getStats (src, dest, opts) {
- const statFunc = opts.dereference
- ? (file) => fs.stat(file, { bigint: true })
- : (file) => fs.lstat(file, { bigint: true })
- return Promise.all([
- statFunc(src),
- statFunc(dest).catch(err => {
- if (err.code === 'ENOENT') return null
- throw err
- })
- ]).then(([srcStat, destStat]) => ({ srcStat, destStat }))
- }
- function getStatsSync (src, dest, opts) {
- let destStat
- const statFunc = opts.dereference
- ? (file) => fs.statSync(file, { bigint: true })
- : (file) => fs.lstatSync(file, { bigint: true })
- const srcStat = statFunc(src)
- try {
- destStat = statFunc(dest)
- } catch (err) {
- if (err.code === 'ENOENT') return { srcStat, destStat: null }
- throw err
- }
- return { srcStat, destStat }
- }
- function checkPaths (src, dest, funcName, opts, cb) {
- util.callbackify(getStats)(src, dest, opts, (err, stats) => {
- if (err) return cb(err)
- const { srcStat, destStat } = stats
- if (destStat) {
- if (areIdentical(srcStat, destStat)) {
- const srcBaseName = path.basename(src)
- const destBaseName = path.basename(dest)
- if (funcName === 'move' &&
- srcBaseName !== destBaseName &&
- srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
- return cb(null, { srcStat, destStat, isChangingCase: true })
- }
- return cb(new Error('Source and destination must not be the same.'))
- }
- if (srcStat.isDirectory() && !destStat.isDirectory()) {
- return cb(new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`))
- }
- if (!srcStat.isDirectory() && destStat.isDirectory()) {
- return cb(new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`))
- }
- }
- if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
- return cb(new Error(errMsg(src, dest, funcName)))
- }
- return cb(null, { srcStat, destStat })
- })
- }
- function checkPathsSync (src, dest, funcName, opts) {
- const { srcStat, destStat } = getStatsSync(src, dest, opts)
- if (destStat) {
- if (areIdentical(srcStat, destStat)) {
- const srcBaseName = path.basename(src)
- const destBaseName = path.basename(dest)
- if (funcName === 'move' &&
- srcBaseName !== destBaseName &&
- srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
- return { srcStat, destStat, isChangingCase: true }
- }
- throw new Error('Source and destination must not be the same.')
- }
- if (srcStat.isDirectory() && !destStat.isDirectory()) {
- throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`)
- }
- if (!srcStat.isDirectory() && destStat.isDirectory()) {
- throw new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`)
- }
- }
- if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
- throw new Error(errMsg(src, dest, funcName))
- }
- return { srcStat, destStat }
- }
- // recursively check if dest parent is a subdirectory of src.
- // It works for all file types including symlinks since it
- // checks the src and dest inodes. It starts from the deepest
- // parent and stops once it reaches the src parent or the root path.
- function checkParentPaths (src, srcStat, dest, funcName, cb) {
- const srcParent = path.resolve(path.dirname(src))
- const destParent = path.resolve(path.dirname(dest))
- if (destParent === srcParent || destParent === path.parse(destParent).root) return cb()
- fs.stat(destParent, { bigint: true }, (err, destStat) => {
- if (err) {
- if (err.code === 'ENOENT') return cb()
- return cb(err)
- }
- if (areIdentical(srcStat, destStat)) {
- return cb(new Error(errMsg(src, dest, funcName)))
- }
- return checkParentPaths(src, srcStat, destParent, funcName, cb)
- })
- }
- function checkParentPathsSync (src, srcStat, dest, funcName) {
- const srcParent = path.resolve(path.dirname(src))
- const destParent = path.resolve(path.dirname(dest))
- if (destParent === srcParent || destParent === path.parse(destParent).root) return
- let destStat
- try {
- destStat = fs.statSync(destParent, { bigint: true })
- } catch (err) {
- if (err.code === 'ENOENT') return
- throw err
- }
- if (areIdentical(srcStat, destStat)) {
- throw new Error(errMsg(src, dest, funcName))
- }
- return checkParentPathsSync(src, srcStat, destParent, funcName)
- }
- function areIdentical (srcStat, destStat) {
- return destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev
- }
- // return true if dest is a subdir of src, otherwise false.
- // It only checks the path strings.
- function isSrcSubdir (src, dest) {
- const srcArr = path.resolve(src).split(path.sep).filter(i => i)
- const destArr = path.resolve(dest).split(path.sep).filter(i => i)
- return srcArr.reduce((acc, cur, i) => acc && destArr[i] === cur, true)
- }
- function errMsg (src, dest, funcName) {
- return `Cannot ${funcName} '${src}' to a subdirectory of itself, '${dest}'.`
- }
- module.exports = {
- checkPaths,
- checkPathsSync,
- checkParentPaths,
- checkParentPathsSync,
- isSrcSubdir,
- areIdentical
- }
- }, function(modId) { var map = {"../fs":1677462587431}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587440, function(require, module, exports) {
- const fs = require('graceful-fs')
- const path = require('path')
- const mkdirsSync = require('../mkdirs').mkdirsSync
- const utimesMillisSync = require('../util/utimes').utimesMillisSync
- const stat = require('../util/stat')
- function copySync (src, dest, opts) {
- if (typeof opts === 'function') {
- opts = { filter: opts }
- }
- opts = opts || {}
- opts.clobber = 'clobber' in opts ? !!opts.clobber : true // default to true for now
- opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber // overwrite falls back to clobber
- // Warn about using preserveTimestamps on 32-bit node
- if (opts.preserveTimestamps && process.arch === 'ia32') {
- process.emitWarning(
- 'Using the preserveTimestamps option in 32-bit node is not recommended;\n\n' +
- '\tsee https://github.com/jprichardson/node-fs-extra/issues/269',
- 'Warning', 'fs-extra-WARN0002'
- )
- }
- const { srcStat, destStat } = stat.checkPathsSync(src, dest, 'copy', opts)
- stat.checkParentPathsSync(src, srcStat, dest, 'copy')
- return handleFilterAndCopy(destStat, src, dest, opts)
- }
- function handleFilterAndCopy (destStat, src, dest, opts) {
- if (opts.filter && !opts.filter(src, dest)) return
- const destParent = path.dirname(dest)
- if (!fs.existsSync(destParent)) mkdirsSync(destParent)
- return getStats(destStat, src, dest, opts)
- }
- function startCopy (destStat, src, dest, opts) {
- if (opts.filter && !opts.filter(src, dest)) return
- return getStats(destStat, src, dest, opts)
- }
- function getStats (destStat, src, dest, opts) {
- const statSync = opts.dereference ? fs.statSync : fs.lstatSync
- const srcStat = statSync(src)
- if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts)
- else if (srcStat.isFile() ||
- srcStat.isCharacterDevice() ||
- srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts)
- else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts)
- else if (srcStat.isSocket()) throw new Error(`Cannot copy a socket file: ${src}`)
- else if (srcStat.isFIFO()) throw new Error(`Cannot copy a FIFO pipe: ${src}`)
- throw new Error(`Unknown file: ${src}`)
- }
- function onFile (srcStat, destStat, src, dest, opts) {
- if (!destStat) return copyFile(srcStat, src, dest, opts)
- return mayCopyFile(srcStat, src, dest, opts)
- }
- function mayCopyFile (srcStat, src, dest, opts) {
- if (opts.overwrite) {
- fs.unlinkSync(dest)
- return copyFile(srcStat, src, dest, opts)
- } else if (opts.errorOnExist) {
- throw new Error(`'${dest}' already exists`)
- }
- }
- function copyFile (srcStat, src, dest, opts) {
- fs.copyFileSync(src, dest)
- if (opts.preserveTimestamps) handleTimestamps(srcStat.mode, src, dest)
- return setDestMode(dest, srcStat.mode)
- }
- function handleTimestamps (srcMode, src, dest) {
- // Make sure the file is writable before setting the timestamp
- // otherwise open fails with EPERM when invoked with 'r+'
- // (through utimes call)
- if (fileIsNotWritable(srcMode)) makeFileWritable(dest, srcMode)
- return setDestTimestamps(src, dest)
- }
- function fileIsNotWritable (srcMode) {
- return (srcMode & 0o200) === 0
- }
- function makeFileWritable (dest, srcMode) {
- return setDestMode(dest, srcMode | 0o200)
- }
- function setDestMode (dest, srcMode) {
- return fs.chmodSync(dest, srcMode)
- }
- function setDestTimestamps (src, dest) {
- // The initial srcStat.atime cannot be trusted
- // because it is modified by the read(2) system call
- // (See https://nodejs.org/api/fs.html#fs_stat_time_values)
- const updatedSrcStat = fs.statSync(src)
- return utimesMillisSync(dest, updatedSrcStat.atime, updatedSrcStat.mtime)
- }
- function onDir (srcStat, destStat, src, dest, opts) {
- if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts)
- return copyDir(src, dest, opts)
- }
- function mkDirAndCopy (srcMode, src, dest, opts) {
- fs.mkdirSync(dest)
- copyDir(src, dest, opts)
- return setDestMode(dest, srcMode)
- }
- function copyDir (src, dest, opts) {
- fs.readdirSync(src).forEach(item => copyDirItem(item, src, dest, opts))
- }
- function copyDirItem (item, src, dest, opts) {
- const srcItem = path.join(src, item)
- const destItem = path.join(dest, item)
- const { destStat } = stat.checkPathsSync(srcItem, destItem, 'copy', opts)
- return startCopy(destStat, srcItem, destItem, opts)
- }
- function onLink (destStat, src, dest, opts) {
- let resolvedSrc = fs.readlinkSync(src)
- if (opts.dereference) {
- resolvedSrc = path.resolve(process.cwd(), resolvedSrc)
- }
- if (!destStat) {
- return fs.symlinkSync(resolvedSrc, dest)
- } else {
- let resolvedDest
- try {
- resolvedDest = fs.readlinkSync(dest)
- } catch (err) {
- // dest exists and is a regular file or directory,
- // Windows may throw UNKNOWN error. If dest already exists,
- // fs throws error anyway, so no need to guard against it here.
- if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs.symlinkSync(resolvedSrc, dest)
- throw err
- }
- if (opts.dereference) {
- resolvedDest = path.resolve(process.cwd(), resolvedDest)
- }
- if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
- throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`)
- }
- // prevent copy if src is a subdir of dest since unlinking
- // dest in this case would result in removing src contents
- // and therefore a broken symlink would be created.
- if (fs.statSync(dest).isDirectory() && stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
- throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)
- }
- return copyLink(resolvedSrc, dest)
- }
- }
- function copyLink (resolvedSrc, dest) {
- fs.unlinkSync(dest)
- return fs.symlinkSync(resolvedSrc, dest)
- }
- module.exports = copySync
- }, function(modId) { var map = {"../mkdirs":1677462587434,"../util/utimes":1677462587438,"../util/stat":1677462587439}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587442, function(require, module, exports) {
- const { createFile, createFileSync } = require('./file')
- const { createLink, createLinkSync } = require('./link')
- const { createSymlink, createSymlinkSync } = require('./symlink')
- module.exports = {
- // file
- createFile,
- createFileSync,
- ensureFile: createFile,
- ensureFileSync: createFileSync,
- // link
- createLink,
- createLinkSync,
- ensureLink: createLink,
- ensureLinkSync: createLinkSync,
- // symlink
- createSymlink,
- createSymlinkSync,
- ensureSymlink: createSymlink,
- ensureSymlinkSync: createSymlinkSync
- }
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587446, function(require, module, exports) {
- const u = require('universalify').fromPromise
- const jsonFile = require('./jsonfile')
- jsonFile.outputJson = u(require('./output-json'))
- jsonFile.outputJsonSync = require('./output-json-sync')
- // aliases
- jsonFile.outputJSON = jsonFile.outputJson
- jsonFile.outputJSONSync = jsonFile.outputJsonSync
- jsonFile.writeJSON = jsonFile.writeJson
- jsonFile.writeJSONSync = jsonFile.writeJsonSync
- jsonFile.readJSON = jsonFile.readJson
- jsonFile.readJSONSync = jsonFile.readJsonSync
- module.exports = jsonFile
- }, function(modId) { var map = {"./jsonfile":1677462587447,"./output-json":1677462587448,"./output-json-sync":1677462587450}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587447, function(require, module, exports) {
- const jsonFile = require('jsonfile')
- module.exports = {
- // jsonfile exports
- readJson: jsonFile.readFile,
- readJsonSync: jsonFile.readFileSync,
- writeJson: jsonFile.writeFile,
- writeJsonSync: jsonFile.writeFileSync
- }
- }, function(modId) { var map = {"jsonfile":1677462587447}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587448, function(require, module, exports) {
- const { stringify } = require('jsonfile/utils')
- const { outputFile } = require('../output-file')
- async function outputJson (file, data, options = {}) {
- const str = stringify(data, options)
- await outputFile(file, str, options)
- }
- module.exports = outputJson
- }, function(modId) { var map = {"../output-file":1677462587449}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587449, function(require, module, exports) {
- 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, ...args) {
- const dir = path.dirname(file)
- if (fs.existsSync(dir)) {
- return fs.writeFileSync(file, ...args)
- }
- mkdir.mkdirsSync(dir)
- fs.writeFileSync(file, ...args)
- }
- module.exports = {
- outputFile: u(outputFile),
- outputFileSync
- }
- }, function(modId) { var map = {"../mkdirs":1677462587434,"../path-exists":1677462587437}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587450, function(require, module, exports) {
- const { stringify } = require('jsonfile/utils')
- const { outputFileSync } = require('../output-file')
- function outputJsonSync (file, data, options) {
- const str = stringify(data, options)
- outputFileSync(file, str, options)
- }
- module.exports = outputJsonSync
- }, function(modId) { var map = {"../output-file":1677462587449}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587451, function(require, module, exports) {
- const u = require('universalify').fromCallback
- module.exports = {
- move: u(require('./move')),
- moveSync: require('./move-sync')
- }
- }, function(modId) { var map = {"./move":1677462587452,"./move-sync":1677462587455}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587452, function(require, module, exports) {
- const fs = require('graceful-fs')
- const path = require('path')
- const copy = require('../copy').copy
- const remove = require('../remove').remove
- const mkdirp = require('../mkdirs').mkdirp
- const pathExists = require('../path-exists').pathExists
- const stat = require('../util/stat')
- function move (src, dest, opts, cb) {
- if (typeof opts === 'function') {
- cb = opts
- opts = {}
- }
- opts = opts || {}
- const overwrite = opts.overwrite || opts.clobber || false
- stat.checkPaths(src, dest, 'move', opts, (err, stats) => {
- if (err) return cb(err)
- const { srcStat, isChangingCase = false } = stats
- stat.checkParentPaths(src, srcStat, dest, 'move', err => {
- if (err) return cb(err)
- if (isParentRoot(dest)) return doRename(src, dest, overwrite, isChangingCase, cb)
- mkdirp(path.dirname(dest), err => {
- if (err) return cb(err)
- return doRename(src, dest, overwrite, isChangingCase, cb)
- })
- })
- })
- }
- function isParentRoot (dest) {
- const parent = path.dirname(dest)
- const parsedPath = path.parse(parent)
- return parsedPath.root === parent
- }
- function doRename (src, dest, overwrite, isChangingCase, cb) {
- if (isChangingCase) return rename(src, dest, overwrite, cb)
- if (overwrite) {
- return remove(dest, err => {
- if (err) return cb(err)
- return rename(src, dest, overwrite, cb)
- })
- }
- pathExists(dest, (err, destExists) => {
- if (err) return cb(err)
- if (destExists) return cb(new Error('dest already exists.'))
- return rename(src, dest, overwrite, cb)
- })
- }
- function rename (src, dest, overwrite, cb) {
- fs.rename(src, dest, err => {
- if (!err) return cb()
- if (err.code !== 'EXDEV') return cb(err)
- return moveAcrossDevice(src, dest, overwrite, cb)
- })
- }
- function moveAcrossDevice (src, dest, overwrite, cb) {
- const opts = {
- overwrite,
- errorOnExist: true
- }
- copy(src, dest, opts, err => {
- if (err) return cb(err)
- return remove(src, cb)
- })
- }
- module.exports = move
- }, function(modId) { var map = {"../copy":1677462587432,"../remove":1677462587453,"../mkdirs":1677462587434,"../path-exists":1677462587437,"../util/stat":1677462587439}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587453, function(require, module, exports) {
- const fs = require('graceful-fs')
- const u = require('universalify').fromCallback
- const rimraf = require('./rimraf')
- function remove (path, callback) {
- // Node 14.14.0+
- if (fs.rm) return fs.rm(path, { recursive: true, force: true }, callback)
- rimraf(path, callback)
- }
- function removeSync (path) {
- // Node 14.14.0+
- if (fs.rmSync) return fs.rmSync(path, { recursive: true, force: true })
- rimraf.sync(path)
- }
- module.exports = {
- remove: u(remove),
- removeSync
- }
- }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
- __DEFINE__(1677462587455, function(require, module, exports) {
- const fs = require('graceful-fs')
- const path = require('path')
- const copySync = require('../copy').copySync
- const removeSync = require('../remove').removeSync
- const mkdirpSync = require('../mkdirs').mkdirpSync
- const stat = require('../util/stat')
- function moveSync (src, dest, opts) {
- opts = opts || {}
- const overwrite = opts.overwrite || opts.clobber || false
- const { srcStat, isChangingCase = false } = stat.checkPathsSync(src, dest, 'move', opts)
- stat.checkParentPathsSync(src, srcStat, dest, 'move')
- if (!isParentRoot(dest)) mkdirpSync(path.dirname(dest))
- return doRename(src, dest, overwrite, isChangingCase)
- }
- function isParentRoot (dest) {
- const parent = path.dirname(dest)
- const parsedPath = path.parse(parent)
- return parsedPath.root === parent
- }
- function doRename (src, dest, overwrite, isChangingCase) {
- if (isChangingCase) return rename(src, dest, overwrite)
- if (overwrite) {
- removeSync(dest)
- return rename(src, dest, overwrite)
- }
- if (fs.existsSync(dest)) throw new Error('dest already exists.')
- return rename(src, dest, overwrite)
- }
- function rename (src, dest, overwrite) {
- try {
- fs.renameSync(src, dest)
- } catch (err) {
- if (err.code !== 'EXDEV') throw err
- return moveAcrossDevice(src, dest, overwrite)
- }
- }
- function moveAcrossDevice (src, dest, overwrite) {
- const opts = {
- overwrite,
- errorOnExist: true
- }
- copySync(src, dest, opts)
- return removeSync(src)
- }
- module.exports = moveSync
- }, function(modId) { var map = {"../copy":1677462587432,"../remove":1677462587453,"../mkdirs":1677462587434,"../util/stat":1677462587439}; return __REQUIRE__(map[modId], modId); })
- return __REQUIRE__(1677462587430);
- })()
- //miniprogram-npm-outsideDeps=["./empty","universalify","graceful-fs","path","util","./file","./link","./symlink","jsonfile/utils","./rimraf"]
- //# sourceMappingURL=index.js.map
|