index.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. 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; };
  5. 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; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1677462587430, function(require, module, exports) {
  8. module.exports = {
  9. // Export promiseified graceful-fs:
  10. ...require('./fs'),
  11. // Export extra methods:
  12. ...require('./copy'),
  13. ...require('./empty'),
  14. ...require('./ensure'),
  15. ...require('./json'),
  16. ...require('./mkdirs'),
  17. ...require('./move'),
  18. ...require('./output-file'),
  19. ...require('./path-exists'),
  20. ...require('./remove')
  21. }
  22. }, 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); })
  23. __DEFINE__(1677462587431, function(require, module, exports) {
  24. // This is adapted from https://github.com/normalize/mz
  25. // Copyright (c) 2014-2016 Jonathan Ong me@jongleberry.com and Contributors
  26. const u = require('universalify').fromCallback
  27. const fs = require('graceful-fs')
  28. const api = [
  29. 'access',
  30. 'appendFile',
  31. 'chmod',
  32. 'chown',
  33. 'close',
  34. 'copyFile',
  35. 'fchmod',
  36. 'fchown',
  37. 'fdatasync',
  38. 'fstat',
  39. 'fsync',
  40. 'ftruncate',
  41. 'futimes',
  42. 'lchmod',
  43. 'lchown',
  44. 'link',
  45. 'lstat',
  46. 'mkdir',
  47. 'mkdtemp',
  48. 'open',
  49. 'opendir',
  50. 'readdir',
  51. 'readFile',
  52. 'readlink',
  53. 'realpath',
  54. 'rename',
  55. 'rm',
  56. 'rmdir',
  57. 'stat',
  58. 'symlink',
  59. 'truncate',
  60. 'unlink',
  61. 'utimes',
  62. 'writeFile'
  63. ].filter(key => {
  64. // Some commands are not available on some systems. Ex:
  65. // fs.opendir was added in Node.js v12.12.0
  66. // fs.rm was added in Node.js v14.14.0
  67. // fs.lchown is not available on at least some Linux
  68. return typeof fs[key] === 'function'
  69. })
  70. // Export cloned fs:
  71. Object.assign(exports, fs)
  72. // Universalify async methods:
  73. api.forEach(method => {
  74. exports[method] = u(fs[method])
  75. })
  76. // We differ from mz/fs in that we still ship the old, broken, fs.exists()
  77. // since we are a drop-in replacement for the native module
  78. exports.exists = function (filename, callback) {
  79. if (typeof callback === 'function') {
  80. return fs.exists(filename, callback)
  81. }
  82. return new Promise(resolve => {
  83. return fs.exists(filename, resolve)
  84. })
  85. }
  86. // fs.read(), fs.write(), & fs.writev() need special treatment due to multiple callback args
  87. exports.read = function (fd, buffer, offset, length, position, callback) {
  88. if (typeof callback === 'function') {
  89. return fs.read(fd, buffer, offset, length, position, callback)
  90. }
  91. return new Promise((resolve, reject) => {
  92. fs.read(fd, buffer, offset, length, position, (err, bytesRead, buffer) => {
  93. if (err) return reject(err)
  94. resolve({ bytesRead, buffer })
  95. })
  96. })
  97. }
  98. // Function signature can be
  99. // fs.write(fd, buffer[, offset[, length[, position]]], callback)
  100. // OR
  101. // fs.write(fd, string[, position[, encoding]], callback)
  102. // We need to handle both cases, so we use ...args
  103. exports.write = function (fd, buffer, ...args) {
  104. if (typeof args[args.length - 1] === 'function') {
  105. return fs.write(fd, buffer, ...args)
  106. }
  107. return new Promise((resolve, reject) => {
  108. fs.write(fd, buffer, ...args, (err, bytesWritten, buffer) => {
  109. if (err) return reject(err)
  110. resolve({ bytesWritten, buffer })
  111. })
  112. })
  113. }
  114. // fs.writev only available in Node v12.9.0+
  115. if (typeof fs.writev === 'function') {
  116. // Function signature is
  117. // s.writev(fd, buffers[, position], callback)
  118. // We need to handle the optional arg, so we use ...args
  119. exports.writev = function (fd, buffers, ...args) {
  120. if (typeof args[args.length - 1] === 'function') {
  121. return fs.writev(fd, buffers, ...args)
  122. }
  123. return new Promise((resolve, reject) => {
  124. fs.writev(fd, buffers, ...args, (err, bytesWritten, buffers) => {
  125. if (err) return reject(err)
  126. resolve({ bytesWritten, buffers })
  127. })
  128. })
  129. }
  130. }
  131. // fs.realpath.native sometimes not available if fs is monkey-patched
  132. if (typeof fs.realpath.native === 'function') {
  133. exports.realpath.native = u(fs.realpath.native)
  134. } else {
  135. process.emitWarning(
  136. 'fs.realpath.native is not a function. Is fs being monkey-patched?',
  137. 'Warning', 'fs-extra-WARN0003'
  138. )
  139. }
  140. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  141. __DEFINE__(1677462587432, function(require, module, exports) {
  142. const u = require('universalify').fromCallback
  143. module.exports = {
  144. copy: u(require('./copy')),
  145. copySync: require('./copy-sync')
  146. }
  147. }, function(modId) { var map = {"./copy":1677462587433,"./copy-sync":1677462587440}; return __REQUIRE__(map[modId], modId); })
  148. __DEFINE__(1677462587433, function(require, module, exports) {
  149. const fs = require('graceful-fs')
  150. const path = require('path')
  151. const mkdirs = require('../mkdirs').mkdirs
  152. const pathExists = require('../path-exists').pathExists
  153. const utimesMillis = require('../util/utimes').utimesMillis
  154. const stat = require('../util/stat')
  155. function copy (src, dest, opts, cb) {
  156. if (typeof opts === 'function' && !cb) {
  157. cb = opts
  158. opts = {}
  159. } else if (typeof opts === 'function') {
  160. opts = { filter: opts }
  161. }
  162. cb = cb || function () {}
  163. opts = opts || {}
  164. opts.clobber = 'clobber' in opts ? !!opts.clobber : true // default to true for now
  165. opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber // overwrite falls back to clobber
  166. // Warn about using preserveTimestamps on 32-bit node
  167. if (opts.preserveTimestamps && process.arch === 'ia32') {
  168. process.emitWarning(
  169. 'Using the preserveTimestamps option in 32-bit node is not recommended;\n\n' +
  170. '\tsee https://github.com/jprichardson/node-fs-extra/issues/269',
  171. 'Warning', 'fs-extra-WARN0001'
  172. )
  173. }
  174. stat.checkPaths(src, dest, 'copy', opts, (err, stats) => {
  175. if (err) return cb(err)
  176. const { srcStat, destStat } = stats
  177. stat.checkParentPaths(src, srcStat, dest, 'copy', err => {
  178. if (err) return cb(err)
  179. if (opts.filter) return handleFilter(checkParentDir, destStat, src, dest, opts, cb)
  180. return checkParentDir(destStat, src, dest, opts, cb)
  181. })
  182. })
  183. }
  184. function checkParentDir (destStat, src, dest, opts, cb) {
  185. const destParent = path.dirname(dest)
  186. pathExists(destParent, (err, dirExists) => {
  187. if (err) return cb(err)
  188. if (dirExists) return getStats(destStat, src, dest, opts, cb)
  189. mkdirs(destParent, err => {
  190. if (err) return cb(err)
  191. return getStats(destStat, src, dest, opts, cb)
  192. })
  193. })
  194. }
  195. function handleFilter (onInclude, destStat, src, dest, opts, cb) {
  196. Promise.resolve(opts.filter(src, dest)).then(include => {
  197. if (include) return onInclude(destStat, src, dest, opts, cb)
  198. return cb()
  199. }, error => cb(error))
  200. }
  201. function startCopy (destStat, src, dest, opts, cb) {
  202. if (opts.filter) return handleFilter(getStats, destStat, src, dest, opts, cb)
  203. return getStats(destStat, src, dest, opts, cb)
  204. }
  205. function getStats (destStat, src, dest, opts, cb) {
  206. const stat = opts.dereference ? fs.stat : fs.lstat
  207. stat(src, (err, srcStat) => {
  208. if (err) return cb(err)
  209. if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts, cb)
  210. else if (srcStat.isFile() ||
  211. srcStat.isCharacterDevice() ||
  212. srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts, cb)
  213. else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts, cb)
  214. else if (srcStat.isSocket()) return cb(new Error(`Cannot copy a socket file: ${src}`))
  215. else if (srcStat.isFIFO()) return cb(new Error(`Cannot copy a FIFO pipe: ${src}`))
  216. return cb(new Error(`Unknown file: ${src}`))
  217. })
  218. }
  219. function onFile (srcStat, destStat, src, dest, opts, cb) {
  220. if (!destStat) return copyFile(srcStat, src, dest, opts, cb)
  221. return mayCopyFile(srcStat, src, dest, opts, cb)
  222. }
  223. function mayCopyFile (srcStat, src, dest, opts, cb) {
  224. if (opts.overwrite) {
  225. fs.unlink(dest, err => {
  226. if (err) return cb(err)
  227. return copyFile(srcStat, src, dest, opts, cb)
  228. })
  229. } else if (opts.errorOnExist) {
  230. return cb(new Error(`'${dest}' already exists`))
  231. } else return cb()
  232. }
  233. function copyFile (srcStat, src, dest, opts, cb) {
  234. fs.copyFile(src, dest, err => {
  235. if (err) return cb(err)
  236. if (opts.preserveTimestamps) return handleTimestampsAndMode(srcStat.mode, src, dest, cb)
  237. return setDestMode(dest, srcStat.mode, cb)
  238. })
  239. }
  240. function handleTimestampsAndMode (srcMode, src, dest, cb) {
  241. // Make sure the file is writable before setting the timestamp
  242. // otherwise open fails with EPERM when invoked with 'r+'
  243. // (through utimes call)
  244. if (fileIsNotWritable(srcMode)) {
  245. return makeFileWritable(dest, srcMode, err => {
  246. if (err) return cb(err)
  247. return setDestTimestampsAndMode(srcMode, src, dest, cb)
  248. })
  249. }
  250. return setDestTimestampsAndMode(srcMode, src, dest, cb)
  251. }
  252. function fileIsNotWritable (srcMode) {
  253. return (srcMode & 0o200) === 0
  254. }
  255. function makeFileWritable (dest, srcMode, cb) {
  256. return setDestMode(dest, srcMode | 0o200, cb)
  257. }
  258. function setDestTimestampsAndMode (srcMode, src, dest, cb) {
  259. setDestTimestamps(src, dest, err => {
  260. if (err) return cb(err)
  261. return setDestMode(dest, srcMode, cb)
  262. })
  263. }
  264. function setDestMode (dest, srcMode, cb) {
  265. return fs.chmod(dest, srcMode, cb)
  266. }
  267. function setDestTimestamps (src, dest, cb) {
  268. // The initial srcStat.atime cannot be trusted
  269. // because it is modified by the read(2) system call
  270. // (See https://nodejs.org/api/fs.html#fs_stat_time_values)
  271. fs.stat(src, (err, updatedSrcStat) => {
  272. if (err) return cb(err)
  273. return utimesMillis(dest, updatedSrcStat.atime, updatedSrcStat.mtime, cb)
  274. })
  275. }
  276. function onDir (srcStat, destStat, src, dest, opts, cb) {
  277. if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts, cb)
  278. return copyDir(src, dest, opts, cb)
  279. }
  280. function mkDirAndCopy (srcMode, src, dest, opts, cb) {
  281. fs.mkdir(dest, err => {
  282. if (err) return cb(err)
  283. copyDir(src, dest, opts, err => {
  284. if (err) return cb(err)
  285. return setDestMode(dest, srcMode, cb)
  286. })
  287. })
  288. }
  289. function copyDir (src, dest, opts, cb) {
  290. fs.readdir(src, (err, items) => {
  291. if (err) return cb(err)
  292. return copyDirItems(items, src, dest, opts, cb)
  293. })
  294. }
  295. function copyDirItems (items, src, dest, opts, cb) {
  296. const item = items.pop()
  297. if (!item) return cb()
  298. return copyDirItem(items, item, src, dest, opts, cb)
  299. }
  300. function copyDirItem (items, item, src, dest, opts, cb) {
  301. const srcItem = path.join(src, item)
  302. const destItem = path.join(dest, item)
  303. stat.checkPaths(srcItem, destItem, 'copy', opts, (err, stats) => {
  304. if (err) return cb(err)
  305. const { destStat } = stats
  306. startCopy(destStat, srcItem, destItem, opts, err => {
  307. if (err) return cb(err)
  308. return copyDirItems(items, src, dest, opts, cb)
  309. })
  310. })
  311. }
  312. function onLink (destStat, src, dest, opts, cb) {
  313. fs.readlink(src, (err, resolvedSrc) => {
  314. if (err) return cb(err)
  315. if (opts.dereference) {
  316. resolvedSrc = path.resolve(process.cwd(), resolvedSrc)
  317. }
  318. if (!destStat) {
  319. return fs.symlink(resolvedSrc, dest, cb)
  320. } else {
  321. fs.readlink(dest, (err, resolvedDest) => {
  322. if (err) {
  323. // dest exists and is a regular file or directory,
  324. // Windows may throw UNKNOWN error. If dest already exists,
  325. // fs throws error anyway, so no need to guard against it here.
  326. if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs.symlink(resolvedSrc, dest, cb)
  327. return cb(err)
  328. }
  329. if (opts.dereference) {
  330. resolvedDest = path.resolve(process.cwd(), resolvedDest)
  331. }
  332. if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
  333. return cb(new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`))
  334. }
  335. // do not copy if src is a subdir of dest since unlinking
  336. // dest in this case would result in removing src contents
  337. // and therefore a broken symlink would be created.
  338. if (destStat.isDirectory() && stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
  339. return cb(new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`))
  340. }
  341. return copyLink(resolvedSrc, dest, cb)
  342. })
  343. }
  344. })
  345. }
  346. function copyLink (resolvedSrc, dest, cb) {
  347. fs.unlink(dest, err => {
  348. if (err) return cb(err)
  349. return fs.symlink(resolvedSrc, dest, cb)
  350. })
  351. }
  352. module.exports = copy
  353. }, function(modId) { var map = {"../mkdirs":1677462587434,"../path-exists":1677462587437,"../util/utimes":1677462587438,"../util/stat":1677462587439}; return __REQUIRE__(map[modId], modId); })
  354. __DEFINE__(1677462587434, function(require, module, exports) {
  355. const u = require('universalify').fromPromise
  356. const { makeDir: _makeDir, makeDirSync } = require('./make-dir')
  357. const makeDir = u(_makeDir)
  358. module.exports = {
  359. mkdirs: makeDir,
  360. mkdirsSync: makeDirSync,
  361. // alias
  362. mkdirp: makeDir,
  363. mkdirpSync: makeDirSync,
  364. ensureDir: makeDir,
  365. ensureDirSync: makeDirSync
  366. }
  367. }, function(modId) { var map = {"./make-dir":1677462587435}; return __REQUIRE__(map[modId], modId); })
  368. __DEFINE__(1677462587435, function(require, module, exports) {
  369. const fs = require('../fs')
  370. const { checkPath } = require('./utils')
  371. const getMode = options => {
  372. const defaults = { mode: 0o777 }
  373. if (typeof options === 'number') return options
  374. return ({ ...defaults, ...options }).mode
  375. }
  376. module.exports.makeDir = async (dir, options) => {
  377. checkPath(dir)
  378. return fs.mkdir(dir, {
  379. mode: getMode(options),
  380. recursive: true
  381. })
  382. }
  383. module.exports.makeDirSync = (dir, options) => {
  384. checkPath(dir)
  385. return fs.mkdirSync(dir, {
  386. mode: getMode(options),
  387. recursive: true
  388. })
  389. }
  390. }, function(modId) { var map = {"../fs":1677462587431,"./utils":1677462587436}; return __REQUIRE__(map[modId], modId); })
  391. __DEFINE__(1677462587436, function(require, module, exports) {
  392. // Adapted from https://github.com/sindresorhus/make-dir
  393. // Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
  394. // 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:
  395. // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  396. // 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.
  397. const path = require('path')
  398. // https://github.com/nodejs/node/issues/8987
  399. // https://github.com/libuv/libuv/pull/1088
  400. module.exports.checkPath = function checkPath (pth) {
  401. if (process.platform === 'win32') {
  402. const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path.parse(pth).root, ''))
  403. if (pathHasInvalidWinCharacters) {
  404. const error = new Error(`Path contains invalid characters: ${pth}`)
  405. error.code = 'EINVAL'
  406. throw error
  407. }
  408. }
  409. }
  410. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  411. __DEFINE__(1677462587437, function(require, module, exports) {
  412. const u = require('universalify').fromPromise
  413. const fs = require('../fs')
  414. function pathExists (path) {
  415. return fs.access(path).then(() => true).catch(() => false)
  416. }
  417. module.exports = {
  418. pathExists: u(pathExists),
  419. pathExistsSync: fs.existsSync
  420. }
  421. }, function(modId) { var map = {"../fs":1677462587431}; return __REQUIRE__(map[modId], modId); })
  422. __DEFINE__(1677462587438, function(require, module, exports) {
  423. const fs = require('graceful-fs')
  424. function utimesMillis (path, atime, mtime, callback) {
  425. // if (!HAS_MILLIS_RES) return fs.utimes(path, atime, mtime, callback)
  426. fs.open(path, 'r+', (err, fd) => {
  427. if (err) return callback(err)
  428. fs.futimes(fd, atime, mtime, futimesErr => {
  429. fs.close(fd, closeErr => {
  430. if (callback) callback(futimesErr || closeErr)
  431. })
  432. })
  433. })
  434. }
  435. function utimesMillisSync (path, atime, mtime) {
  436. const fd = fs.openSync(path, 'r+')
  437. fs.futimesSync(fd, atime, mtime)
  438. return fs.closeSync(fd)
  439. }
  440. module.exports = {
  441. utimesMillis,
  442. utimesMillisSync
  443. }
  444. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  445. __DEFINE__(1677462587439, function(require, module, exports) {
  446. const fs = require('../fs')
  447. const path = require('path')
  448. const util = require('util')
  449. function getStats (src, dest, opts) {
  450. const statFunc = opts.dereference
  451. ? (file) => fs.stat(file, { bigint: true })
  452. : (file) => fs.lstat(file, { bigint: true })
  453. return Promise.all([
  454. statFunc(src),
  455. statFunc(dest).catch(err => {
  456. if (err.code === 'ENOENT') return null
  457. throw err
  458. })
  459. ]).then(([srcStat, destStat]) => ({ srcStat, destStat }))
  460. }
  461. function getStatsSync (src, dest, opts) {
  462. let destStat
  463. const statFunc = opts.dereference
  464. ? (file) => fs.statSync(file, { bigint: true })
  465. : (file) => fs.lstatSync(file, { bigint: true })
  466. const srcStat = statFunc(src)
  467. try {
  468. destStat = statFunc(dest)
  469. } catch (err) {
  470. if (err.code === 'ENOENT') return { srcStat, destStat: null }
  471. throw err
  472. }
  473. return { srcStat, destStat }
  474. }
  475. function checkPaths (src, dest, funcName, opts, cb) {
  476. util.callbackify(getStats)(src, dest, opts, (err, stats) => {
  477. if (err) return cb(err)
  478. const { srcStat, destStat } = stats
  479. if (destStat) {
  480. if (areIdentical(srcStat, destStat)) {
  481. const srcBaseName = path.basename(src)
  482. const destBaseName = path.basename(dest)
  483. if (funcName === 'move' &&
  484. srcBaseName !== destBaseName &&
  485. srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
  486. return cb(null, { srcStat, destStat, isChangingCase: true })
  487. }
  488. return cb(new Error('Source and destination must not be the same.'))
  489. }
  490. if (srcStat.isDirectory() && !destStat.isDirectory()) {
  491. return cb(new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`))
  492. }
  493. if (!srcStat.isDirectory() && destStat.isDirectory()) {
  494. return cb(new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`))
  495. }
  496. }
  497. if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
  498. return cb(new Error(errMsg(src, dest, funcName)))
  499. }
  500. return cb(null, { srcStat, destStat })
  501. })
  502. }
  503. function checkPathsSync (src, dest, funcName, opts) {
  504. const { srcStat, destStat } = getStatsSync(src, dest, opts)
  505. if (destStat) {
  506. if (areIdentical(srcStat, destStat)) {
  507. const srcBaseName = path.basename(src)
  508. const destBaseName = path.basename(dest)
  509. if (funcName === 'move' &&
  510. srcBaseName !== destBaseName &&
  511. srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
  512. return { srcStat, destStat, isChangingCase: true }
  513. }
  514. throw new Error('Source and destination must not be the same.')
  515. }
  516. if (srcStat.isDirectory() && !destStat.isDirectory()) {
  517. throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`)
  518. }
  519. if (!srcStat.isDirectory() && destStat.isDirectory()) {
  520. throw new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`)
  521. }
  522. }
  523. if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
  524. throw new Error(errMsg(src, dest, funcName))
  525. }
  526. return { srcStat, destStat }
  527. }
  528. // recursively check if dest parent is a subdirectory of src.
  529. // It works for all file types including symlinks since it
  530. // checks the src and dest inodes. It starts from the deepest
  531. // parent and stops once it reaches the src parent or the root path.
  532. function checkParentPaths (src, srcStat, dest, funcName, cb) {
  533. const srcParent = path.resolve(path.dirname(src))
  534. const destParent = path.resolve(path.dirname(dest))
  535. if (destParent === srcParent || destParent === path.parse(destParent).root) return cb()
  536. fs.stat(destParent, { bigint: true }, (err, destStat) => {
  537. if (err) {
  538. if (err.code === 'ENOENT') return cb()
  539. return cb(err)
  540. }
  541. if (areIdentical(srcStat, destStat)) {
  542. return cb(new Error(errMsg(src, dest, funcName)))
  543. }
  544. return checkParentPaths(src, srcStat, destParent, funcName, cb)
  545. })
  546. }
  547. function checkParentPathsSync (src, srcStat, dest, funcName) {
  548. const srcParent = path.resolve(path.dirname(src))
  549. const destParent = path.resolve(path.dirname(dest))
  550. if (destParent === srcParent || destParent === path.parse(destParent).root) return
  551. let destStat
  552. try {
  553. destStat = fs.statSync(destParent, { bigint: true })
  554. } catch (err) {
  555. if (err.code === 'ENOENT') return
  556. throw err
  557. }
  558. if (areIdentical(srcStat, destStat)) {
  559. throw new Error(errMsg(src, dest, funcName))
  560. }
  561. return checkParentPathsSync(src, srcStat, destParent, funcName)
  562. }
  563. function areIdentical (srcStat, destStat) {
  564. return destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev
  565. }
  566. // return true if dest is a subdir of src, otherwise false.
  567. // It only checks the path strings.
  568. function isSrcSubdir (src, dest) {
  569. const srcArr = path.resolve(src).split(path.sep).filter(i => i)
  570. const destArr = path.resolve(dest).split(path.sep).filter(i => i)
  571. return srcArr.reduce((acc, cur, i) => acc && destArr[i] === cur, true)
  572. }
  573. function errMsg (src, dest, funcName) {
  574. return `Cannot ${funcName} '${src}' to a subdirectory of itself, '${dest}'.`
  575. }
  576. module.exports = {
  577. checkPaths,
  578. checkPathsSync,
  579. checkParentPaths,
  580. checkParentPathsSync,
  581. isSrcSubdir,
  582. areIdentical
  583. }
  584. }, function(modId) { var map = {"../fs":1677462587431}; return __REQUIRE__(map[modId], modId); })
  585. __DEFINE__(1677462587440, function(require, module, exports) {
  586. const fs = require('graceful-fs')
  587. const path = require('path')
  588. const mkdirsSync = require('../mkdirs').mkdirsSync
  589. const utimesMillisSync = require('../util/utimes').utimesMillisSync
  590. const stat = require('../util/stat')
  591. function copySync (src, dest, opts) {
  592. if (typeof opts === 'function') {
  593. opts = { filter: opts }
  594. }
  595. opts = opts || {}
  596. opts.clobber = 'clobber' in opts ? !!opts.clobber : true // default to true for now
  597. opts.overwrite = 'overwrite' in opts ? !!opts.overwrite : opts.clobber // overwrite falls back to clobber
  598. // Warn about using preserveTimestamps on 32-bit node
  599. if (opts.preserveTimestamps && process.arch === 'ia32') {
  600. process.emitWarning(
  601. 'Using the preserveTimestamps option in 32-bit node is not recommended;\n\n' +
  602. '\tsee https://github.com/jprichardson/node-fs-extra/issues/269',
  603. 'Warning', 'fs-extra-WARN0002'
  604. )
  605. }
  606. const { srcStat, destStat } = stat.checkPathsSync(src, dest, 'copy', opts)
  607. stat.checkParentPathsSync(src, srcStat, dest, 'copy')
  608. return handleFilterAndCopy(destStat, src, dest, opts)
  609. }
  610. function handleFilterAndCopy (destStat, src, dest, opts) {
  611. if (opts.filter && !opts.filter(src, dest)) return
  612. const destParent = path.dirname(dest)
  613. if (!fs.existsSync(destParent)) mkdirsSync(destParent)
  614. return getStats(destStat, src, dest, opts)
  615. }
  616. function startCopy (destStat, src, dest, opts) {
  617. if (opts.filter && !opts.filter(src, dest)) return
  618. return getStats(destStat, src, dest, opts)
  619. }
  620. function getStats (destStat, src, dest, opts) {
  621. const statSync = opts.dereference ? fs.statSync : fs.lstatSync
  622. const srcStat = statSync(src)
  623. if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts)
  624. else if (srcStat.isFile() ||
  625. srcStat.isCharacterDevice() ||
  626. srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts)
  627. else if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts)
  628. else if (srcStat.isSocket()) throw new Error(`Cannot copy a socket file: ${src}`)
  629. else if (srcStat.isFIFO()) throw new Error(`Cannot copy a FIFO pipe: ${src}`)
  630. throw new Error(`Unknown file: ${src}`)
  631. }
  632. function onFile (srcStat, destStat, src, dest, opts) {
  633. if (!destStat) return copyFile(srcStat, src, dest, opts)
  634. return mayCopyFile(srcStat, src, dest, opts)
  635. }
  636. function mayCopyFile (srcStat, src, dest, opts) {
  637. if (opts.overwrite) {
  638. fs.unlinkSync(dest)
  639. return copyFile(srcStat, src, dest, opts)
  640. } else if (opts.errorOnExist) {
  641. throw new Error(`'${dest}' already exists`)
  642. }
  643. }
  644. function copyFile (srcStat, src, dest, opts) {
  645. fs.copyFileSync(src, dest)
  646. if (opts.preserveTimestamps) handleTimestamps(srcStat.mode, src, dest)
  647. return setDestMode(dest, srcStat.mode)
  648. }
  649. function handleTimestamps (srcMode, src, dest) {
  650. // Make sure the file is writable before setting the timestamp
  651. // otherwise open fails with EPERM when invoked with 'r+'
  652. // (through utimes call)
  653. if (fileIsNotWritable(srcMode)) makeFileWritable(dest, srcMode)
  654. return setDestTimestamps(src, dest)
  655. }
  656. function fileIsNotWritable (srcMode) {
  657. return (srcMode & 0o200) === 0
  658. }
  659. function makeFileWritable (dest, srcMode) {
  660. return setDestMode(dest, srcMode | 0o200)
  661. }
  662. function setDestMode (dest, srcMode) {
  663. return fs.chmodSync(dest, srcMode)
  664. }
  665. function setDestTimestamps (src, dest) {
  666. // The initial srcStat.atime cannot be trusted
  667. // because it is modified by the read(2) system call
  668. // (See https://nodejs.org/api/fs.html#fs_stat_time_values)
  669. const updatedSrcStat = fs.statSync(src)
  670. return utimesMillisSync(dest, updatedSrcStat.atime, updatedSrcStat.mtime)
  671. }
  672. function onDir (srcStat, destStat, src, dest, opts) {
  673. if (!destStat) return mkDirAndCopy(srcStat.mode, src, dest, opts)
  674. return copyDir(src, dest, opts)
  675. }
  676. function mkDirAndCopy (srcMode, src, dest, opts) {
  677. fs.mkdirSync(dest)
  678. copyDir(src, dest, opts)
  679. return setDestMode(dest, srcMode)
  680. }
  681. function copyDir (src, dest, opts) {
  682. fs.readdirSync(src).forEach(item => copyDirItem(item, src, dest, opts))
  683. }
  684. function copyDirItem (item, src, dest, opts) {
  685. const srcItem = path.join(src, item)
  686. const destItem = path.join(dest, item)
  687. const { destStat } = stat.checkPathsSync(srcItem, destItem, 'copy', opts)
  688. return startCopy(destStat, srcItem, destItem, opts)
  689. }
  690. function onLink (destStat, src, dest, opts) {
  691. let resolvedSrc = fs.readlinkSync(src)
  692. if (opts.dereference) {
  693. resolvedSrc = path.resolve(process.cwd(), resolvedSrc)
  694. }
  695. if (!destStat) {
  696. return fs.symlinkSync(resolvedSrc, dest)
  697. } else {
  698. let resolvedDest
  699. try {
  700. resolvedDest = fs.readlinkSync(dest)
  701. } catch (err) {
  702. // dest exists and is a regular file or directory,
  703. // Windows may throw UNKNOWN error. If dest already exists,
  704. // fs throws error anyway, so no need to guard against it here.
  705. if (err.code === 'EINVAL' || err.code === 'UNKNOWN') return fs.symlinkSync(resolvedSrc, dest)
  706. throw err
  707. }
  708. if (opts.dereference) {
  709. resolvedDest = path.resolve(process.cwd(), resolvedDest)
  710. }
  711. if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
  712. throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`)
  713. }
  714. // prevent copy if src is a subdir of dest since unlinking
  715. // dest in this case would result in removing src contents
  716. // and therefore a broken symlink would be created.
  717. if (fs.statSync(dest).isDirectory() && stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
  718. throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`)
  719. }
  720. return copyLink(resolvedSrc, dest)
  721. }
  722. }
  723. function copyLink (resolvedSrc, dest) {
  724. fs.unlinkSync(dest)
  725. return fs.symlinkSync(resolvedSrc, dest)
  726. }
  727. module.exports = copySync
  728. }, function(modId) { var map = {"../mkdirs":1677462587434,"../util/utimes":1677462587438,"../util/stat":1677462587439}; return __REQUIRE__(map[modId], modId); })
  729. __DEFINE__(1677462587442, function(require, module, exports) {
  730. const { createFile, createFileSync } = require('./file')
  731. const { createLink, createLinkSync } = require('./link')
  732. const { createSymlink, createSymlinkSync } = require('./symlink')
  733. module.exports = {
  734. // file
  735. createFile,
  736. createFileSync,
  737. ensureFile: createFile,
  738. ensureFileSync: createFileSync,
  739. // link
  740. createLink,
  741. createLinkSync,
  742. ensureLink: createLink,
  743. ensureLinkSync: createLinkSync,
  744. // symlink
  745. createSymlink,
  746. createSymlinkSync,
  747. ensureSymlink: createSymlink,
  748. ensureSymlinkSync: createSymlinkSync
  749. }
  750. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  751. __DEFINE__(1677462587446, function(require, module, exports) {
  752. const u = require('universalify').fromPromise
  753. const jsonFile = require('./jsonfile')
  754. jsonFile.outputJson = u(require('./output-json'))
  755. jsonFile.outputJsonSync = require('./output-json-sync')
  756. // aliases
  757. jsonFile.outputJSON = jsonFile.outputJson
  758. jsonFile.outputJSONSync = jsonFile.outputJsonSync
  759. jsonFile.writeJSON = jsonFile.writeJson
  760. jsonFile.writeJSONSync = jsonFile.writeJsonSync
  761. jsonFile.readJSON = jsonFile.readJson
  762. jsonFile.readJSONSync = jsonFile.readJsonSync
  763. module.exports = jsonFile
  764. }, function(modId) { var map = {"./jsonfile":1677462587447,"./output-json":1677462587448,"./output-json-sync":1677462587450}; return __REQUIRE__(map[modId], modId); })
  765. __DEFINE__(1677462587447, function(require, module, exports) {
  766. const jsonFile = require('jsonfile')
  767. module.exports = {
  768. // jsonfile exports
  769. readJson: jsonFile.readFile,
  770. readJsonSync: jsonFile.readFileSync,
  771. writeJson: jsonFile.writeFile,
  772. writeJsonSync: jsonFile.writeFileSync
  773. }
  774. }, function(modId) { var map = {"jsonfile":1677462587447}; return __REQUIRE__(map[modId], modId); })
  775. __DEFINE__(1677462587448, function(require, module, exports) {
  776. const { stringify } = require('jsonfile/utils')
  777. const { outputFile } = require('../output-file')
  778. async function outputJson (file, data, options = {}) {
  779. const str = stringify(data, options)
  780. await outputFile(file, str, options)
  781. }
  782. module.exports = outputJson
  783. }, function(modId) { var map = {"../output-file":1677462587449}; return __REQUIRE__(map[modId], modId); })
  784. __DEFINE__(1677462587449, function(require, module, exports) {
  785. const u = require('universalify').fromCallback
  786. const fs = require('graceful-fs')
  787. const path = require('path')
  788. const mkdir = require('../mkdirs')
  789. const pathExists = require('../path-exists').pathExists
  790. function outputFile (file, data, encoding, callback) {
  791. if (typeof encoding === 'function') {
  792. callback = encoding
  793. encoding = 'utf8'
  794. }
  795. const dir = path.dirname(file)
  796. pathExists(dir, (err, itDoes) => {
  797. if (err) return callback(err)
  798. if (itDoes) return fs.writeFile(file, data, encoding, callback)
  799. mkdir.mkdirs(dir, err => {
  800. if (err) return callback(err)
  801. fs.writeFile(file, data, encoding, callback)
  802. })
  803. })
  804. }
  805. function outputFileSync (file, ...args) {
  806. const dir = path.dirname(file)
  807. if (fs.existsSync(dir)) {
  808. return fs.writeFileSync(file, ...args)
  809. }
  810. mkdir.mkdirsSync(dir)
  811. fs.writeFileSync(file, ...args)
  812. }
  813. module.exports = {
  814. outputFile: u(outputFile),
  815. outputFileSync
  816. }
  817. }, function(modId) { var map = {"../mkdirs":1677462587434,"../path-exists":1677462587437}; return __REQUIRE__(map[modId], modId); })
  818. __DEFINE__(1677462587450, function(require, module, exports) {
  819. const { stringify } = require('jsonfile/utils')
  820. const { outputFileSync } = require('../output-file')
  821. function outputJsonSync (file, data, options) {
  822. const str = stringify(data, options)
  823. outputFileSync(file, str, options)
  824. }
  825. module.exports = outputJsonSync
  826. }, function(modId) { var map = {"../output-file":1677462587449}; return __REQUIRE__(map[modId], modId); })
  827. __DEFINE__(1677462587451, function(require, module, exports) {
  828. const u = require('universalify').fromCallback
  829. module.exports = {
  830. move: u(require('./move')),
  831. moveSync: require('./move-sync')
  832. }
  833. }, function(modId) { var map = {"./move":1677462587452,"./move-sync":1677462587455}; return __REQUIRE__(map[modId], modId); })
  834. __DEFINE__(1677462587452, function(require, module, exports) {
  835. const fs = require('graceful-fs')
  836. const path = require('path')
  837. const copy = require('../copy').copy
  838. const remove = require('../remove').remove
  839. const mkdirp = require('../mkdirs').mkdirp
  840. const pathExists = require('../path-exists').pathExists
  841. const stat = require('../util/stat')
  842. function move (src, dest, opts, cb) {
  843. if (typeof opts === 'function') {
  844. cb = opts
  845. opts = {}
  846. }
  847. opts = opts || {}
  848. const overwrite = opts.overwrite || opts.clobber || false
  849. stat.checkPaths(src, dest, 'move', opts, (err, stats) => {
  850. if (err) return cb(err)
  851. const { srcStat, isChangingCase = false } = stats
  852. stat.checkParentPaths(src, srcStat, dest, 'move', err => {
  853. if (err) return cb(err)
  854. if (isParentRoot(dest)) return doRename(src, dest, overwrite, isChangingCase, cb)
  855. mkdirp(path.dirname(dest), err => {
  856. if (err) return cb(err)
  857. return doRename(src, dest, overwrite, isChangingCase, cb)
  858. })
  859. })
  860. })
  861. }
  862. function isParentRoot (dest) {
  863. const parent = path.dirname(dest)
  864. const parsedPath = path.parse(parent)
  865. return parsedPath.root === parent
  866. }
  867. function doRename (src, dest, overwrite, isChangingCase, cb) {
  868. if (isChangingCase) return rename(src, dest, overwrite, cb)
  869. if (overwrite) {
  870. return remove(dest, err => {
  871. if (err) return cb(err)
  872. return rename(src, dest, overwrite, cb)
  873. })
  874. }
  875. pathExists(dest, (err, destExists) => {
  876. if (err) return cb(err)
  877. if (destExists) return cb(new Error('dest already exists.'))
  878. return rename(src, dest, overwrite, cb)
  879. })
  880. }
  881. function rename (src, dest, overwrite, cb) {
  882. fs.rename(src, dest, err => {
  883. if (!err) return cb()
  884. if (err.code !== 'EXDEV') return cb(err)
  885. return moveAcrossDevice(src, dest, overwrite, cb)
  886. })
  887. }
  888. function moveAcrossDevice (src, dest, overwrite, cb) {
  889. const opts = {
  890. overwrite,
  891. errorOnExist: true
  892. }
  893. copy(src, dest, opts, err => {
  894. if (err) return cb(err)
  895. return remove(src, cb)
  896. })
  897. }
  898. module.exports = move
  899. }, function(modId) { var map = {"../copy":1677462587432,"../remove":1677462587453,"../mkdirs":1677462587434,"../path-exists":1677462587437,"../util/stat":1677462587439}; return __REQUIRE__(map[modId], modId); })
  900. __DEFINE__(1677462587453, function(require, module, exports) {
  901. const fs = require('graceful-fs')
  902. const u = require('universalify').fromCallback
  903. const rimraf = require('./rimraf')
  904. function remove (path, callback) {
  905. // Node 14.14.0+
  906. if (fs.rm) return fs.rm(path, { recursive: true, force: true }, callback)
  907. rimraf(path, callback)
  908. }
  909. function removeSync (path) {
  910. // Node 14.14.0+
  911. if (fs.rmSync) return fs.rmSync(path, { recursive: true, force: true })
  912. rimraf.sync(path)
  913. }
  914. module.exports = {
  915. remove: u(remove),
  916. removeSync
  917. }
  918. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  919. __DEFINE__(1677462587455, function(require, module, exports) {
  920. const fs = require('graceful-fs')
  921. const path = require('path')
  922. const copySync = require('../copy').copySync
  923. const removeSync = require('../remove').removeSync
  924. const mkdirpSync = require('../mkdirs').mkdirpSync
  925. const stat = require('../util/stat')
  926. function moveSync (src, dest, opts) {
  927. opts = opts || {}
  928. const overwrite = opts.overwrite || opts.clobber || false
  929. const { srcStat, isChangingCase = false } = stat.checkPathsSync(src, dest, 'move', opts)
  930. stat.checkParentPathsSync(src, srcStat, dest, 'move')
  931. if (!isParentRoot(dest)) mkdirpSync(path.dirname(dest))
  932. return doRename(src, dest, overwrite, isChangingCase)
  933. }
  934. function isParentRoot (dest) {
  935. const parent = path.dirname(dest)
  936. const parsedPath = path.parse(parent)
  937. return parsedPath.root === parent
  938. }
  939. function doRename (src, dest, overwrite, isChangingCase) {
  940. if (isChangingCase) return rename(src, dest, overwrite)
  941. if (overwrite) {
  942. removeSync(dest)
  943. return rename(src, dest, overwrite)
  944. }
  945. if (fs.existsSync(dest)) throw new Error('dest already exists.')
  946. return rename(src, dest, overwrite)
  947. }
  948. function rename (src, dest, overwrite) {
  949. try {
  950. fs.renameSync(src, dest)
  951. } catch (err) {
  952. if (err.code !== 'EXDEV') throw err
  953. return moveAcrossDevice(src, dest, overwrite)
  954. }
  955. }
  956. function moveAcrossDevice (src, dest, overwrite) {
  957. const opts = {
  958. overwrite,
  959. errorOnExist: true
  960. }
  961. copySync(src, dest, opts)
  962. return removeSync(src)
  963. }
  964. module.exports = moveSync
  965. }, function(modId) { var map = {"../copy":1677462587432,"../remove":1677462587453,"../mkdirs":1677462587434,"../util/stat":1677462587439}; return __REQUIRE__(map[modId], modId); })
  966. return __REQUIRE__(1677462587430);
  967. })()
  968. //miniprogram-npm-outsideDeps=["./empty","universalify","graceful-fs","path","util","./file","./link","./symlink","jsonfile/utils","./rimraf"]
  969. //# sourceMappingURL=index.js.map