@lxf2513/node-mv
Advanced tools
| import { existsSync, statSync, renameSync } from 'node:fs'; | ||
| import { mkdirpSync } from 'makedirp'; | ||
| import { cpr } from 'node-cpr'; | ||
| import { rmrfSync } from 'node-rmrf'; | ||
| import { sep, resolve } from 'node:path'; | ||
| const name = "nodemv"; | ||
| const errorLog = (str) => { | ||
| console.log("\x1B[31m%s\x1B[0m", str); | ||
| }; | ||
| function isPathExist(path) { | ||
| try { | ||
| return existsSync(path); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
| function isFile(path) { | ||
| try { | ||
| const stat = statSync(resolve(path)); | ||
| return stat.isFile(); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
| function isDirectory(path) { | ||
| try { | ||
| const stat = statSync(resolve(path)); | ||
| return stat.isDirectory(); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
| function isExistedInDest(source, dest) { | ||
| if (isDirectory(dest) && isPathExist(`${dest}${sep}${source}`)) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| function errorMsg(source, dest, mkdirp) { | ||
| if (typeof source === "string" || source.length === 1) { | ||
| const sourcePath = typeof source === "string" ? source : source[0]; | ||
| if (!isPathExist(sourcePath)) { | ||
| errorLog( | ||
| `${name}: cannot stat '${sourcePath}': No such file or directory` | ||
| ); | ||
| return false; | ||
| } else if (isDirectory(sourcePath) && !isDirectory(dest) && isFile(dest)) { | ||
| errorLog( | ||
| `${name}: cannot overwrite non-directory '${dest}' with directory '${sourcePath}'` | ||
| ); | ||
| return false; | ||
| } else if (isDirectory(sourcePath) && isDirectory(dest) && sourcePath === dest) { | ||
| errorLog( | ||
| `${name}: cannot move '${sourcePath}' to a subdirectory of itself, '${dest}/${sourcePath}'` | ||
| ); | ||
| return false; | ||
| } else if (!isPathExist(sourcePath) && !mkdirp) { | ||
| errorLog( | ||
| `${name}: cannot move '${sourcePath}' to '${dest}': No such file or directory` | ||
| ); | ||
| return false; | ||
| } | ||
| return true; | ||
| } else { | ||
| if (!isDirectory(dest) && !mkdirp) { | ||
| errorLog(`${name}: target '${dest}' is not a directory`); | ||
| return false; | ||
| } else { | ||
| source.forEach((s) => { | ||
| errorMsg(s, dest); | ||
| }); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| function moveFile(source, dest) { | ||
| try { | ||
| renameSync(source, dest); | ||
| } catch (error) { | ||
| const err = error; | ||
| if (err?.code === "EPERM" || err?.code === "EISDIR" || err?.code === "EXDEV") { | ||
| cpr(source, dest); | ||
| rmrfSync(source); | ||
| } | ||
| } | ||
| } | ||
| function mv(source, dest, options) { | ||
| const { clobber = true, mkdirp } = options; | ||
| const exist = isPathExist(dest); | ||
| const isStr = typeof source === "string"; | ||
| const isArray = Array.isArray(source); | ||
| if (isArray && source.length > 1 && !exist && mkdirp || isStr && !exist) { | ||
| mkdirpSync(dest); | ||
| } | ||
| if (!errorMsg(source, dest)) { | ||
| return; | ||
| } | ||
| if (!exist || clobber || !clobber && (isStr && !isExistedInDest(source, dest) || isArray && source.length === 1 && !isExistedInDest(source[0], dest))) { | ||
| if (isStr) { | ||
| moveFile(source, dest); | ||
| } else { | ||
| source.forEach((s) => { | ||
| moveFile(s, dest); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| export { errorLog as e, mv as m, name as n }; |
| 'use strict'; | ||
| const node_fs = require('node:fs'); | ||
| const makedirp = require('makedirp'); | ||
| const nodeCpr = require('node-cpr'); | ||
| const nodeRmrf = require('node-rmrf'); | ||
| const node_path = require('node:path'); | ||
| const name = "nodemv"; | ||
| const errorLog = (str) => { | ||
| console.log("\x1B[31m%s\x1B[0m", str); | ||
| }; | ||
| function isPathExist(path) { | ||
| try { | ||
| return node_fs.existsSync(path); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
| function isFile(path) { | ||
| try { | ||
| const stat = node_fs.statSync(node_path.resolve(path)); | ||
| return stat.isFile(); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
| function isDirectory(path) { | ||
| try { | ||
| const stat = node_fs.statSync(node_path.resolve(path)); | ||
| return stat.isDirectory(); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
| function isExistedInDest(source, dest) { | ||
| if (isDirectory(dest) && isPathExist(`${dest}${node_path.sep}${source}`)) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| function errorMsg(source, dest, mkdirp) { | ||
| if (typeof source === "string" || source.length === 1) { | ||
| const sourcePath = typeof source === "string" ? source : source[0]; | ||
| if (!isPathExist(sourcePath)) { | ||
| errorLog( | ||
| `${name}: cannot stat '${sourcePath}': No such file or directory` | ||
| ); | ||
| return false; | ||
| } else if (isDirectory(sourcePath) && !isDirectory(dest) && isFile(dest)) { | ||
| errorLog( | ||
| `${name}: cannot overwrite non-directory '${dest}' with directory '${sourcePath}'` | ||
| ); | ||
| return false; | ||
| } else if (isDirectory(sourcePath) && isDirectory(dest) && sourcePath === dest) { | ||
| errorLog( | ||
| `${name}: cannot move '${sourcePath}' to a subdirectory of itself, '${dest}/${sourcePath}'` | ||
| ); | ||
| return false; | ||
| } else if (!isPathExist(sourcePath) && !mkdirp) { | ||
| errorLog( | ||
| `${name}: cannot move '${sourcePath}' to '${dest}': No such file or directory` | ||
| ); | ||
| return false; | ||
| } | ||
| return true; | ||
| } else { | ||
| if (!isDirectory(dest) && !mkdirp) { | ||
| errorLog(`${name}: target '${dest}' is not a directory`); | ||
| return false; | ||
| } else { | ||
| source.forEach((s) => { | ||
| errorMsg(s, dest); | ||
| }); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| function moveFile(source, dest) { | ||
| try { | ||
| node_fs.renameSync(source, dest); | ||
| } catch (error) { | ||
| const err = error; | ||
| if (err?.code === "EPERM" || err?.code === "EISDIR" || err?.code === "EXDEV") { | ||
| nodeCpr.cpr(source, dest); | ||
| nodeRmrf.rmrfSync(source); | ||
| } | ||
| } | ||
| } | ||
| function mv(source, dest, options) { | ||
| const { clobber = true, mkdirp } = options; | ||
| const exist = isPathExist(dest); | ||
| const isStr = typeof source === "string"; | ||
| const isArray = Array.isArray(source); | ||
| if (isArray && source.length > 1 && !exist && mkdirp || isStr && !exist) { | ||
| makedirp.mkdirpSync(dest); | ||
| } | ||
| if (!errorMsg(source, dest)) { | ||
| return; | ||
| } | ||
| if (!exist || clobber || !clobber && (isStr && !isExistedInDest(source, dest) || isArray && source.length === 1 && !isExistedInDest(source[0], dest))) { | ||
| if (isStr) { | ||
| moveFile(source, dest); | ||
| } else { | ||
| source.forEach((s) => { | ||
| moveFile(s, dest); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| exports.errorLog = errorLog; | ||
| exports.mv = mv; | ||
| exports.name = name; |
+2
-95
| #!/usr/bin/env node | ||
| 'use strict'; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| const readline = require('readline'); | ||
| const index = require('./shared/node-mv.c33fac70.cjs'); | ||
| const index = require('./shared/node-mv.5714bdb0.cjs'); | ||
| require('node:fs'); | ||
@@ -14,90 +12,4 @@ require('makedirp'); | ||
| const name = "@lxf2513/node-mv"; | ||
| const version$1 = "1.0.4"; | ||
| const description = "The 'mv' command implementation for nodejs.It will create all the necessary directories and destination file which not exist."; | ||
| const type = "module"; | ||
| const bin = { | ||
| nodemv: "./dist/bin.mjs" | ||
| }; | ||
| const main$1 = "./dist/index.cjs"; | ||
| const module$1 = "./dist/index.mjs"; | ||
| const types = "./dist/index.d.cts"; | ||
| const exports$1 = { | ||
| ".": { | ||
| "import": { | ||
| types: "./dist/index.d.mts", | ||
| "default": "./dist/index.mjs" | ||
| }, | ||
| require: { | ||
| types: "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| } | ||
| } | ||
| }; | ||
| const files = [ | ||
| "dist" | ||
| ]; | ||
| const scripts = { | ||
| "type-check": "tsc --strict --noEmit", | ||
| format: "prettier --write src/", | ||
| build: "unbuild", | ||
| release: "npm publish" | ||
| }; | ||
| const repository = { | ||
| type: "git", | ||
| url: "git+git@github.com:luoxiangfan/node-mv.git" | ||
| }; | ||
| const keywords = [ | ||
| "mv", | ||
| "move", | ||
| "node mv", | ||
| "rename", | ||
| "file", | ||
| "folder", | ||
| "recursive" | ||
| ]; | ||
| const author = "lxf <infiniment@163.com>"; | ||
| const license = "MIT"; | ||
| const bugs = { | ||
| url: "https://github.com/luoxiangfan/node-mv/issues" | ||
| }; | ||
| const homepage = "https://github.com/luoxiangfan/node-mv#readme"; | ||
| const devDependencies = { | ||
| "@types/node": "^22.10.0", | ||
| prettier: "^3.4.1", | ||
| typescript: "^5.7.2", | ||
| unbuild: "^2.0.0" | ||
| }; | ||
| const dependencies = { | ||
| makedirp: "^1.1.1", | ||
| "node-cpr": "^1.2.2", | ||
| "node-rmrf": "^1.0.4" | ||
| }; | ||
| const publishConfig = { | ||
| access: "public" | ||
| }; | ||
| const packageConfig = { | ||
| name: name, | ||
| version: version$1, | ||
| description: description, | ||
| type: type, | ||
| bin: bin, | ||
| main: main$1, | ||
| module: module$1, | ||
| types: types, | ||
| exports: exports$1, | ||
| files: files, | ||
| scripts: scripts, | ||
| repository: repository, | ||
| keywords: keywords, | ||
| author: author, | ||
| license: license, | ||
| bugs: bugs, | ||
| homepage: homepage, | ||
| devDependencies: devDependencies, | ||
| dependencies: dependencies, | ||
| publishConfig: publishConfig | ||
| }; | ||
| const version = "1.1.0"; | ||
| const { version } = packageConfig; | ||
| const helpInfo = () => { | ||
@@ -177,4 +89,2 @@ index.errorLog(`Try '${index.name} --help' for more information.`); | ||
| }; | ||
| main.help = help; | ||
| main.version = version; | ||
| const args = process.argv.slice(2); | ||
@@ -188,4 +98,1 @@ main(...args).then( | ||
| ); | ||
| exports.default = main; | ||
| exports.help = help; |
+1
-7
@@ -1,8 +0,2 @@ | ||
| declare const help: string; | ||
| declare const main: { | ||
| (...args: string[]): Promise<1 | 0>; | ||
| help: string; | ||
| version: string; | ||
| }; | ||
| export { main as default, help }; | ||
| export { } |
+1
-7
@@ -1,8 +0,2 @@ | ||
| declare const help: string; | ||
| declare const main: { | ||
| (...args: string[]): Promise<1 | 0>; | ||
| help: string; | ||
| version: string; | ||
| }; | ||
| export { main as default, help }; | ||
| export { } |
+1
-7
@@ -1,8 +0,2 @@ | ||
| declare const help: string; | ||
| declare const main: { | ||
| (...args: string[]): Promise<1 | 0>; | ||
| help: string; | ||
| version: string; | ||
| }; | ||
| export { main as default, help }; | ||
| export { } |
+8
-98
| #!/usr/bin/env node | ||
| import { createInterface } from 'readline'; | ||
| import { e as errorLog, n as name$1, m as mv } from './shared/node-mv.2a305ff8.mjs'; | ||
| import { e as errorLog, n as name, m as mv } from './shared/node-mv.52ddd0ae.mjs'; | ||
| import 'node:fs'; | ||
@@ -10,96 +10,10 @@ import 'makedirp'; | ||
| const name = "@lxf2513/node-mv"; | ||
| const version$1 = "1.0.4"; | ||
| const description = "The 'mv' command implementation for nodejs.It will create all the necessary directories and destination file which not exist."; | ||
| const type = "module"; | ||
| const bin = { | ||
| nodemv: "./dist/bin.mjs" | ||
| }; | ||
| const main$1 = "./dist/index.cjs"; | ||
| const module = "./dist/index.mjs"; | ||
| const types = "./dist/index.d.cts"; | ||
| const exports = { | ||
| ".": { | ||
| "import": { | ||
| types: "./dist/index.d.mts", | ||
| "default": "./dist/index.mjs" | ||
| }, | ||
| require: { | ||
| types: "./dist/index.d.cts", | ||
| "default": "./dist/index.cjs" | ||
| } | ||
| } | ||
| }; | ||
| const files = [ | ||
| "dist" | ||
| ]; | ||
| const scripts = { | ||
| "type-check": "tsc --strict --noEmit", | ||
| format: "prettier --write src/", | ||
| build: "unbuild", | ||
| release: "npm publish" | ||
| }; | ||
| const repository = { | ||
| type: "git", | ||
| url: "git+git@github.com:luoxiangfan/node-mv.git" | ||
| }; | ||
| const keywords = [ | ||
| "mv", | ||
| "move", | ||
| "node mv", | ||
| "rename", | ||
| "file", | ||
| "folder", | ||
| "recursive" | ||
| ]; | ||
| const author = "lxf <infiniment@163.com>"; | ||
| const license = "MIT"; | ||
| const bugs = { | ||
| url: "https://github.com/luoxiangfan/node-mv/issues" | ||
| }; | ||
| const homepage = "https://github.com/luoxiangfan/node-mv#readme"; | ||
| const devDependencies = { | ||
| "@types/node": "^22.10.0", | ||
| prettier: "^3.4.1", | ||
| typescript: "^5.7.2", | ||
| unbuild: "^2.0.0" | ||
| }; | ||
| const dependencies = { | ||
| makedirp: "^1.1.1", | ||
| "node-cpr": "^1.2.2", | ||
| "node-rmrf": "^1.0.4" | ||
| }; | ||
| const publishConfig = { | ||
| access: "public" | ||
| }; | ||
| const packageConfig = { | ||
| name: name, | ||
| version: version$1, | ||
| description: description, | ||
| type: type, | ||
| bin: bin, | ||
| main: main$1, | ||
| module: module, | ||
| types: types, | ||
| exports: exports, | ||
| files: files, | ||
| scripts: scripts, | ||
| repository: repository, | ||
| keywords: keywords, | ||
| author: author, | ||
| license: license, | ||
| bugs: bugs, | ||
| homepage: homepage, | ||
| devDependencies: devDependencies, | ||
| dependencies: dependencies, | ||
| publishConfig: publishConfig | ||
| }; | ||
| const version = "1.1.0"; | ||
| const { version } = packageConfig; | ||
| const helpInfo = () => { | ||
| errorLog(`Try '${name$1} --help' for more information.`); | ||
| errorLog(`Try '${name} --help' for more information.`); | ||
| }; | ||
| const help = `${name$1} ${version} | ||
| const help = `${name} ${version} | ||
| Usage: ${name$1} [OPTION]... SOURCE... DIRECTORY | ||
| Usage: ${name} [OPTION]... SOURCE... DIRECTORY | ||
| Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY. | ||
@@ -129,3 +43,3 @@ | ||
| if (!_args.length || _args.length === 1 && idx > -1) { | ||
| errorLog(`${name$1}: missing file operand`); | ||
| errorLog(`${name}: missing file operand`); | ||
| helpInfo(); | ||
@@ -153,3 +67,3 @@ return 1; | ||
| } else if (arg === "-v" || arg === "--version") { | ||
| console.log(`${name$1} ${version}`); | ||
| console.log(`${name} ${version}`); | ||
| return 0; | ||
@@ -162,3 +76,3 @@ } else if (arg === "-n" || arg === "--no-clobber") { | ||
| } else { | ||
| errorLog(`${name$1}: unknown option: ${arg}`); | ||
| errorLog(`${name}: unknown option: ${arg}`); | ||
| helpInfo(); | ||
@@ -176,4 +90,2 @@ return 1; | ||
| }; | ||
| main.help = help; | ||
| main.version = version; | ||
| const args = process.argv.slice(2); | ||
@@ -187,3 +99,1 @@ main(...args).then( | ||
| ); | ||
| export { main as default, help }; |
+1
-1
@@ -7,3 +7,3 @@ 'use strict'; | ||
| require('node-rmrf'); | ||
| const index = require('./shared/node-mv.c33fac70.cjs'); | ||
| const index = require('./shared/node-mv.5714bdb0.cjs'); | ||
| require('node:path'); | ||
@@ -10,0 +10,0 @@ |
+1
-1
@@ -5,3 +5,3 @@ import 'node:fs'; | ||
| import 'node-rmrf'; | ||
| export { m as mv } from './shared/node-mv.2a305ff8.mjs'; | ||
| export { m as mv } from './shared/node-mv.52ddd0ae.mjs'; | ||
| import 'node:path'; |
+4
-4
| { | ||
| "name": "@lxf2513/node-mv", | ||
| "version": "1.0.4", | ||
| "version": "1.1.0", | ||
| "description": "The 'mv' command implementation for nodejs.It will create all the necessary directories and destination file which not exist.", | ||
@@ -59,5 +59,5 @@ "type": "module", | ||
| "dependencies": { | ||
| "makedirp": "^1.1.1", | ||
| "node-cpr": "^1.2.2", | ||
| "node-rmrf": "^1.0.4" | ||
| "makedirp": "^1.1.2", | ||
| "node-cpr": "^1.2.4", | ||
| "node-rmrf": "^1.0.7" | ||
| }, | ||
@@ -64,0 +64,0 @@ "publishConfig": { |
| import fs from 'node:fs'; | ||
| import { mkdirpSync } from 'makedirp'; | ||
| import { cpr } from 'node-cpr'; | ||
| import { rmrfSync } from 'node-rmrf'; | ||
| import path from 'node:path'; | ||
| const name = "nodemv"; | ||
| const errorLog = (str) => { | ||
| console.log("\x1B[31m%s\x1B[0m", str); | ||
| }; | ||
| function isPathExist(filePath) { | ||
| try { | ||
| return fs.existsSync(filePath); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function isFile(filePath) { | ||
| try { | ||
| const stat = fs.statSync(path.resolve(filePath)); | ||
| return stat.isFile(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function isDirectory(filePath) { | ||
| try { | ||
| const stat = fs.statSync(path.resolve(filePath)); | ||
| return stat.isDirectory(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| const isArray = Array.isArray; | ||
| function isExistedInDest(source, dest) { | ||
| if (isDirectory(dest) && isPathExist(`${dest}/${source}`)) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| function errorMsg(source, dest, mkdirp) { | ||
| if (typeof source === "string" || source.length === 1) { | ||
| const sourcePath = typeof source === "string" ? source : source[0]; | ||
| if (!isPathExist(sourcePath)) { | ||
| errorLog( | ||
| `${name}: cannot stat '${sourcePath}': No such file or directory` | ||
| ); | ||
| return false; | ||
| } else if (isDirectory(sourcePath) && !isDirectory(dest) && isFile(dest)) { | ||
| errorLog( | ||
| `${name}: cannot overwrite non-directory '${dest}' with directory '${sourcePath}'` | ||
| ); | ||
| return false; | ||
| } else if (isDirectory(sourcePath) && isDirectory(dest) && sourcePath === dest) { | ||
| errorLog( | ||
| `${name}: cannot move '${sourcePath}' to a subdirectory of itself, '${dest}/${sourcePath}'` | ||
| ); | ||
| return false; | ||
| } else if (!isPathExist(sourcePath) && !mkdirp) { | ||
| errorLog( | ||
| `${name}: cannot move '${sourcePath}' to '${dest}': No such file or directory` | ||
| ); | ||
| return false; | ||
| } | ||
| return true; | ||
| } else { | ||
| if (!isDirectory(dest) && !mkdirp) { | ||
| errorLog(`${name}: target '${dest}' is not a directory`); | ||
| return false; | ||
| } else { | ||
| source.forEach((s) => { | ||
| errorMsg(s, dest); | ||
| }); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| function moveFile(source, dest) { | ||
| try { | ||
| fs.renameSync(source, dest); | ||
| } catch (error) { | ||
| const err = error; | ||
| if (err?.code === "EPERM" || err?.code === "EISDIR" || err?.code === "EXDEV") { | ||
| cpr(source, dest); | ||
| rmrfSync(source); | ||
| } | ||
| } | ||
| } | ||
| function mv(source, dest, options) { | ||
| const { clobber = true, mkdirp } = options; | ||
| const destExist = isPathExist(dest); | ||
| const isSourceString = typeof source === "string"; | ||
| const isSourceArray = isArray(source); | ||
| if (isSourceArray && source.length > 1 && !destExist && mkdirp || isSourceString && !destExist) { | ||
| mkdirpSync(dest); | ||
| } | ||
| if (!errorMsg(source, dest)) { | ||
| return; | ||
| } | ||
| if (!destExist || clobber || !clobber && (isSourceString && !isExistedInDest(source, dest) || isSourceArray && source.length === 1 && !isExistedInDest(source[0], dest))) { | ||
| if (isSourceString) { | ||
| moveFile(source, dest); | ||
| } else { | ||
| source.forEach((s) => { | ||
| moveFile(s, dest); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| export { errorLog as e, mv as m, name as n }; |
| 'use strict'; | ||
| const fs = require('node:fs'); | ||
| const makedirp = require('makedirp'); | ||
| const nodeCpr = require('node-cpr'); | ||
| const nodeRmrf = require('node-rmrf'); | ||
| const path = require('node:path'); | ||
| function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } | ||
| const fs__default = /*#__PURE__*/_interopDefaultCompat(fs); | ||
| const path__default = /*#__PURE__*/_interopDefaultCompat(path); | ||
| const name = "nodemv"; | ||
| const errorLog = (str) => { | ||
| console.log("\x1B[31m%s\x1B[0m", str); | ||
| }; | ||
| function isPathExist(filePath) { | ||
| try { | ||
| return fs__default.existsSync(filePath); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function isFile(filePath) { | ||
| try { | ||
| const stat = fs__default.statSync(path__default.resolve(filePath)); | ||
| return stat.isFile(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| function isDirectory(filePath) { | ||
| try { | ||
| const stat = fs__default.statSync(path__default.resolve(filePath)); | ||
| return stat.isDirectory(); | ||
| } catch (error) { | ||
| return false; | ||
| } | ||
| } | ||
| const isArray = Array.isArray; | ||
| function isExistedInDest(source, dest) { | ||
| if (isDirectory(dest) && isPathExist(`${dest}/${source}`)) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| function errorMsg(source, dest, mkdirp) { | ||
| if (typeof source === "string" || source.length === 1) { | ||
| const sourcePath = typeof source === "string" ? source : source[0]; | ||
| if (!isPathExist(sourcePath)) { | ||
| errorLog( | ||
| `${name}: cannot stat '${sourcePath}': No such file or directory` | ||
| ); | ||
| return false; | ||
| } else if (isDirectory(sourcePath) && !isDirectory(dest) && isFile(dest)) { | ||
| errorLog( | ||
| `${name}: cannot overwrite non-directory '${dest}' with directory '${sourcePath}'` | ||
| ); | ||
| return false; | ||
| } else if (isDirectory(sourcePath) && isDirectory(dest) && sourcePath === dest) { | ||
| errorLog( | ||
| `${name}: cannot move '${sourcePath}' to a subdirectory of itself, '${dest}/${sourcePath}'` | ||
| ); | ||
| return false; | ||
| } else if (!isPathExist(sourcePath) && !mkdirp) { | ||
| errorLog( | ||
| `${name}: cannot move '${sourcePath}' to '${dest}': No such file or directory` | ||
| ); | ||
| return false; | ||
| } | ||
| return true; | ||
| } else { | ||
| if (!isDirectory(dest) && !mkdirp) { | ||
| errorLog(`${name}: target '${dest}' is not a directory`); | ||
| return false; | ||
| } else { | ||
| source.forEach((s) => { | ||
| errorMsg(s, dest); | ||
| }); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| function moveFile(source, dest) { | ||
| try { | ||
| fs__default.renameSync(source, dest); | ||
| } catch (error) { | ||
| const err = error; | ||
| if (err?.code === "EPERM" || err?.code === "EISDIR" || err?.code === "EXDEV") { | ||
| nodeCpr.cpr(source, dest); | ||
| nodeRmrf.rmrfSync(source); | ||
| } | ||
| } | ||
| } | ||
| function mv(source, dest, options) { | ||
| const { clobber = true, mkdirp } = options; | ||
| const destExist = isPathExist(dest); | ||
| const isSourceString = typeof source === "string"; | ||
| const isSourceArray = isArray(source); | ||
| if (isSourceArray && source.length > 1 && !destExist && mkdirp || isSourceString && !destExist) { | ||
| makedirp.mkdirpSync(dest); | ||
| } | ||
| if (!errorMsg(source, dest)) { | ||
| return; | ||
| } | ||
| if (!destExist || clobber || !clobber && (isSourceString && !isExistedInDest(source, dest) || isSourceArray && source.length === 1 && !isExistedInDest(source[0], dest))) { | ||
| if (isSourceString) { | ||
| moveFile(source, dest); | ||
| } else { | ||
| source.forEach((s) => { | ||
| moveFile(s, dest); | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| exports.errorLog = errorLog; | ||
| exports.mv = mv; | ||
| exports.name = name; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
6
-14.29%15794
-23.49%419
-31.31%1
Infinity%Updated
Updated
Updated