+13
-17
| 'use strict'; | ||
| const async = require('async'); | ||
| const fs = require('node:fs'); | ||
| const nodePath = require('node:path'); | ||
| const node_fs = require('node:fs'); | ||
| const readdirSyncRecursive = require('@lxf2513/readdir-sync-recursive'); | ||
@@ -11,4 +10,2 @@ | ||
| const async__default = /*#__PURE__*/_interopDefaultCompat(async); | ||
| const fs__default = /*#__PURE__*/_interopDefaultCompat(fs); | ||
| const nodePath__default = /*#__PURE__*/_interopDefaultCompat(nodePath); | ||
| const readdirSyncRecursive__default = /*#__PURE__*/_interopDefaultCompat(readdirSyncRecursive); | ||
@@ -18,3 +15,3 @@ | ||
| try { | ||
| const stat = fs__default.statSync(path); | ||
| const stat = node_fs.statSync(path); | ||
| return stat.isFile(); | ||
@@ -27,3 +24,3 @@ } catch (error) { | ||
| try { | ||
| const stat = fs__default.statSync(path); | ||
| const stat = node_fs.statSync(path); | ||
| return stat.isDirectory(); | ||
@@ -35,10 +32,10 @@ } catch (error) { | ||
| function copyDir(source, dest, limit) { | ||
| const list = readdirSyncRecursive__default(source); | ||
| const files = list.filter((l) => isFile(nodePath__default.join(source, l))); | ||
| const dirs = list.filter((l) => isDirectory(nodePath__default.join(source, l))); | ||
| const list = readdirSyncRecursive__default(source, "relativePath"); | ||
| const files = list.filter((l) => isFile(l)); | ||
| const dirs = list.filter((l) => isDirectory(l)); | ||
| for (const dir of dirs) { | ||
| const destPath = nodePath__default.join(dest, dir); | ||
| if (!fs__default.existsSync(destPath)) { | ||
| fs__default.mkdirSync(destPath, { recursive: true }); | ||
| copyDir(nodePath__default.join(source, dir), destPath, void 0); | ||
| const destPath = dir.replace(source, dest); | ||
| if (!node_fs.existsSync(destPath)) { | ||
| node_fs.mkdirSync(destPath, { recursive: true }); | ||
| copyDir(dir, destPath, void 0); | ||
| } | ||
@@ -50,6 +47,5 @@ } | ||
| async__default.eachLimit(files, limit, (file, next) => { | ||
| const srcPath = nodePath__default.join(source, file); | ||
| const destPath = nodePath__default.join(dest, file); | ||
| const readStream = fs__default.createReadStream(srcPath); | ||
| const writeStream = fs__default.createWriteStream(destPath); | ||
| const destPath = file.replace(source, dest); | ||
| const readStream = node_fs.createReadStream(file); | ||
| const writeStream = node_fs.createWriteStream(destPath); | ||
| readStream.pipe(writeStream); | ||
@@ -56,0 +52,0 @@ writeStream.on("finish", next); |
+13
-15
| import async from 'async'; | ||
| import fs from 'node:fs'; | ||
| import nodePath from 'node:path'; | ||
| import { existsSync, mkdirSync, createReadStream, createWriteStream, statSync } from 'node:fs'; | ||
| import readdirSyncRecursive from '@lxf2513/readdir-sync-recursive'; | ||
@@ -8,3 +7,3 @@ | ||
| try { | ||
| const stat = fs.statSync(path); | ||
| const stat = statSync(path); | ||
| return stat.isFile(); | ||
@@ -17,3 +16,3 @@ } catch (error) { | ||
| try { | ||
| const stat = fs.statSync(path); | ||
| const stat = statSync(path); | ||
| return stat.isDirectory(); | ||
@@ -25,10 +24,10 @@ } catch (error) { | ||
| function copyDir(source, dest, limit) { | ||
| const list = readdirSyncRecursive(source); | ||
| const files = list.filter((l) => isFile(nodePath.join(source, l))); | ||
| const dirs = list.filter((l) => isDirectory(nodePath.join(source, l))); | ||
| const list = readdirSyncRecursive(source, "relativePath"); | ||
| const files = list.filter((l) => isFile(l)); | ||
| const dirs = list.filter((l) => isDirectory(l)); | ||
| for (const dir of dirs) { | ||
| const destPath = nodePath.join(dest, dir); | ||
| if (!fs.existsSync(destPath)) { | ||
| fs.mkdirSync(destPath, { recursive: true }); | ||
| copyDir(nodePath.join(source, dir), destPath, void 0); | ||
| const destPath = dir.replace(source, dest); | ||
| if (!existsSync(destPath)) { | ||
| mkdirSync(destPath, { recursive: true }); | ||
| copyDir(dir, destPath, void 0); | ||
| } | ||
@@ -40,6 +39,5 @@ } | ||
| async.eachLimit(files, limit, (file, next) => { | ||
| const srcPath = nodePath.join(source, file); | ||
| const destPath = nodePath.join(dest, file); | ||
| const readStream = fs.createReadStream(srcPath); | ||
| const writeStream = fs.createWriteStream(destPath); | ||
| const destPath = file.replace(source, dest); | ||
| const readStream = createReadStream(file); | ||
| const writeStream = createWriteStream(destPath); | ||
| readStream.pipe(writeStream); | ||
@@ -46,0 +44,0 @@ writeStream.on("finish", next); |
+5
-5
| { | ||
| "name": "cpr-dir", | ||
| "version": "1.0.1", | ||
| "version": "1.0.2", | ||
| "description": "Copy directory recursively like `cp -r` command", | ||
@@ -49,9 +49,9 @@ "type": "module", | ||
| "@types/async": "^3.2.24", | ||
| "@types/node": "^22.9.0", | ||
| "prettier": "^3.3.3", | ||
| "typescript": "^5.6.3", | ||
| "@types/node": "^22.10.0", | ||
| "prettier": "^3.4.1", | ||
| "typescript": "^5.7.2", | ||
| "unbuild": "^2.0.0" | ||
| }, | ||
| "dependencies": { | ||
| "@lxf2513/readdir-sync-recursive": "^1.0.0", | ||
| "@lxf2513/readdir-sync-recursive": "^1.1.0", | ||
| "async": "^3.2.6" | ||
@@ -58,0 +58,0 @@ }, |
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.
6495
-6.22%96
-5.88%