@reliverse/relifso 1.2.8 → 1.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/impl/copy.js +34 -4
- package/package.json +3 -1
package/bin/impl/copy.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { copyFileSync, statSync, constants as fsConstants } from "node:fs";
|
|
2
|
-
import {
|
|
1
|
+
import { copyFileSync, statSync, constants as fsConstants, readdirSync, rmSync } from "node:fs";
|
|
2
|
+
import {
|
|
3
|
+
stat as statAsync,
|
|
4
|
+
copyFile as copyFileAsync,
|
|
5
|
+
constants as fsConstantsAsync,
|
|
6
|
+
readdir,
|
|
7
|
+
rm
|
|
8
|
+
} from "node:fs/promises";
|
|
3
9
|
import { dirname, join as joinPath, basename as basenamePath } from "node:path";
|
|
4
10
|
import { mkdirsSync } from "./mkdirs.js";
|
|
5
11
|
import { mkdirs } from "./mkdirs.js";
|
|
@@ -10,7 +16,7 @@ export function copySync(src, dest, options = {}) {
|
|
|
10
16
|
}
|
|
11
17
|
let destFinal = dest;
|
|
12
18
|
const destStat = statSync(dest, { throwIfNoEntry: false });
|
|
13
|
-
if (destStat?.isDirectory()) {
|
|
19
|
+
if (!srcStat.isDirectory() && destStat?.isDirectory()) {
|
|
14
20
|
destFinal = joinPath(dest, basenamePath(src));
|
|
15
21
|
}
|
|
16
22
|
const destExists = statSync(destFinal, { throwIfNoEntry: false });
|
|
@@ -20,8 +26,20 @@ export function copySync(src, dest, options = {}) {
|
|
|
20
26
|
const destDir = dirname(destFinal);
|
|
21
27
|
mkdirsSync(destDir);
|
|
22
28
|
if (srcStat.isDirectory()) {
|
|
29
|
+
if (overwrite && destExists) {
|
|
30
|
+
rmSync(destFinal, { recursive: true, force: true });
|
|
31
|
+
}
|
|
23
32
|
mkdirsSync(destFinal);
|
|
33
|
+
const entries = readdirSync(src);
|
|
34
|
+
for (const entry of entries) {
|
|
35
|
+
const srcEntry = joinPath(src, entry);
|
|
36
|
+
const destEntry = joinPath(destFinal, entry);
|
|
37
|
+
copySync(srcEntry, destEntry, options);
|
|
38
|
+
}
|
|
24
39
|
} else {
|
|
40
|
+
if (overwrite && destExists) {
|
|
41
|
+
rmSync(destFinal, { force: true });
|
|
42
|
+
}
|
|
25
43
|
copyFileSync(src, destFinal, preserveTimestamps ? fsConstants.COPYFILE_FICLONE : 0);
|
|
26
44
|
if (preserveTimestamps) {
|
|
27
45
|
console.warn("preserveTimestamps: utimesSync is not implemented for the moment.");
|
|
@@ -41,7 +59,7 @@ export async function copy(src, dest, options = {}) {
|
|
|
41
59
|
if (e.code === "ENOENT") return null;
|
|
42
60
|
throw e;
|
|
43
61
|
});
|
|
44
|
-
if (destStat?.isDirectory()) {
|
|
62
|
+
if (!srcStat?.isDirectory() && destStat?.isDirectory()) {
|
|
45
63
|
destFinal = joinPath(dest, basenamePath(src));
|
|
46
64
|
}
|
|
47
65
|
const destExists = await statAsync(destFinal).catch((e) => {
|
|
@@ -54,8 +72,20 @@ export async function copy(src, dest, options = {}) {
|
|
|
54
72
|
const destDir = dirname(destFinal);
|
|
55
73
|
await mkdirs(destDir);
|
|
56
74
|
if (srcStat?.isDirectory()) {
|
|
75
|
+
if (overwrite && destExists) {
|
|
76
|
+
await rm(destFinal, { recursive: true, force: true });
|
|
77
|
+
}
|
|
57
78
|
await mkdirs(destFinal);
|
|
79
|
+
const entries = await readdir(src);
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
const srcEntry = joinPath(src, entry);
|
|
82
|
+
const destEntry = joinPath(destFinal, entry);
|
|
83
|
+
await copy(srcEntry, destEntry, options);
|
|
84
|
+
}
|
|
58
85
|
} else {
|
|
86
|
+
if (overwrite && destExists) {
|
|
87
|
+
await rm(destFinal, { force: true });
|
|
88
|
+
}
|
|
59
89
|
await copyFileAsync(src, destFinal, preserveTimestamps ? fsConstantsAsync.COPYFILE_FICLONE : 0);
|
|
60
90
|
if (preserveTimestamps) {
|
|
61
91
|
console.warn("preserveTimestamps: utimes is not implemented for the moment.");
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"name": "@reliverse/relifso",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"version": "1.2.
|
|
8
|
+
"version": "1.2.10",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"fs",
|
|
11
11
|
"file",
|
|
@@ -36,6 +36,8 @@
|
|
|
36
36
|
"@cspotcode/source-map-support": "^0.8.1",
|
|
37
37
|
"@eslint/js": "^9.27.0",
|
|
38
38
|
"@reliverse/dler": "^1.3.6",
|
|
39
|
+
"@reliverse/pathkit": "^1.0.4",
|
|
40
|
+
"@reliverse/pathkit-plus": "^1.0.4",
|
|
39
41
|
"@rollup/plugin-alias": "^5.1.1",
|
|
40
42
|
"@rollup/plugin-babel": "^6.0.4",
|
|
41
43
|
"@rollup/plugin-commonjs": "^28.0.3",
|