@reliverse/relifso 1.3.1 → 1.4.0
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/README.md +67 -12
- package/bin/impl/bun.d.ts +34 -0
- package/bin/impl/bun.js +147 -0
- package/bin/impl/{node/copy.d.ts → copy.d.ts} +15 -3
- package/bin/impl/copy.js +228 -0
- package/bin/impl/dive-async.d.ts +11 -0
- package/bin/impl/dive-async.js +88 -0
- package/bin/impl/{utils/additional.js → extras.js} +2 -2
- package/bin/impl/file-utils.d.ts +20 -0
- package/bin/impl/file-utils.js +63 -0
- package/bin/impl/logger.d.ts +1 -0
- package/bin/impl/logger.js +7 -0
- package/bin/impl/{node/mkdirs.js → mkdirs.js} +10 -3
- package/bin/impl/{node/move.d.ts → move.d.ts} +10 -0
- package/bin/impl/move.js +140 -0
- package/bin/impl/read-file.d.ts +20 -0
- package/bin/impl/read-file.js +87 -0
- package/bin/impl/{node/read-json.d.ts → read-json.d.ts} +3 -0
- package/bin/impl/read-json.js +129 -0
- package/bin/impl/write-file.js +48 -0
- package/bin/impl/write-json.d.ts +30 -0
- package/bin/impl/write-json.js +96 -0
- package/bin/mod.d.ts +39 -55
- package/bin/mod.js +60 -162
- package/package.json +2 -2
- package/bin/impl/node/copy.js +0 -94
- package/bin/impl/node/move.js +0 -93
- package/bin/impl/node/read-file.d.ts +0 -30
- package/bin/impl/node/read-file.js +0 -30
- package/bin/impl/node/read-json.js +0 -50
- package/bin/impl/node/write-file.js +0 -23
- package/bin/impl/node/write-json.d.ts +0 -28
- package/bin/impl/node/write-json.js +0 -22
- /package/bin/impl/{node/create-file.d.ts → create-file.d.ts} +0 -0
- /package/bin/impl/{node/create-file.js → create-file.js} +0 -0
- /package/bin/impl/{node/dive.d.ts → dive.d.ts} +0 -0
- /package/bin/impl/{node/dive.js → dive.js} +0 -0
- /package/bin/impl/{node/empty-dir.d.ts → empty-dir.d.ts} +0 -0
- /package/bin/impl/{node/empty-dir.js → empty-dir.js} +0 -0
- /package/bin/impl/{utils/additional.d.ts → extras.d.ts} +0 -0
- /package/bin/impl/{node/mkdirs.d.ts → mkdirs.d.ts} +0 -0
- /package/bin/impl/{node/output-file.d.ts → output-file.d.ts} +0 -0
- /package/bin/impl/{node/output-file.js → output-file.js} +0 -0
- /package/bin/impl/{node/output-json.d.ts → output-json.d.ts} +0 -0
- /package/bin/impl/{node/output-json.js → output-json.js} +0 -0
- /package/bin/impl/{node/path-exists.d.ts → path-exists.d.ts} +0 -0
- /package/bin/impl/{node/path-exists.js → path-exists.js} +0 -0
- /package/bin/impl/{node/remove.d.ts → remove.d.ts} +0 -0
- /package/bin/impl/{node/remove.js → remove.js} +0 -0
- /package/bin/impl/{node/write-file.d.ts → write-file.d.ts} +0 -0
package/bin/impl/node/move.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { renameSync, statSync, unlinkSync, copyFileSync } from "node:fs";
|
|
2
|
-
import { rename, stat, unlink, copyFile } from "node:fs/promises";
|
|
3
|
-
import { dirname, basename, join as joinPath } from "node:path";
|
|
4
|
-
import { mkdirsSync } from "./mkdirs.js";
|
|
5
|
-
import { mkdirs } from "./mkdirs.js";
|
|
6
|
-
export function moveSync(src, dest, options = {}) {
|
|
7
|
-
let overwrite;
|
|
8
|
-
if (options.overwrite !== void 0) {
|
|
9
|
-
overwrite = options.overwrite;
|
|
10
|
-
} else if (options.clobber !== void 0) {
|
|
11
|
-
console.warn(
|
|
12
|
-
"Warning: The 'clobber' option in moveSync is deprecated and will be removed in a future version. Please use 'overwrite' instead."
|
|
13
|
-
);
|
|
14
|
-
overwrite = options.clobber;
|
|
15
|
-
} else {
|
|
16
|
-
overwrite = false;
|
|
17
|
-
}
|
|
18
|
-
const srcStat = statSync(src, { throwIfNoEntry: true });
|
|
19
|
-
if (!srcStat) {
|
|
20
|
-
}
|
|
21
|
-
let destFinal = dest;
|
|
22
|
-
const destStat = statSync(dest, { throwIfNoEntry: false });
|
|
23
|
-
if (destStat?.isDirectory()) {
|
|
24
|
-
destFinal = joinPath(dest, basename(src));
|
|
25
|
-
}
|
|
26
|
-
if (statSync(destFinal, { throwIfNoEntry: false }) && !overwrite) {
|
|
27
|
-
throw new Error(`Destination ${destFinal} already exists and overwrite is false.`);
|
|
28
|
-
}
|
|
29
|
-
const destDir = dirname(destFinal);
|
|
30
|
-
mkdirsSync(destDir);
|
|
31
|
-
try {
|
|
32
|
-
renameSync(src, destFinal);
|
|
33
|
-
} catch (err) {
|
|
34
|
-
if (err.code === "EXDEV") {
|
|
35
|
-
copyFileSync(src, destFinal);
|
|
36
|
-
unlinkSync(src);
|
|
37
|
-
} else if (err.code === "EISDIR" || err.code === "EPERM") {
|
|
38
|
-
copyFileSync(src, destFinal);
|
|
39
|
-
unlinkSync(src);
|
|
40
|
-
} else {
|
|
41
|
-
throw err;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export async function move(src, dest, options = {}) {
|
|
46
|
-
let overwrite;
|
|
47
|
-
if (options.overwrite !== void 0) {
|
|
48
|
-
overwrite = options.overwrite;
|
|
49
|
-
} else if (options.clobber !== void 0) {
|
|
50
|
-
console.warn(
|
|
51
|
-
"Warning: The 'clobber' option in move is deprecated and will be removed in a future version. Please use 'overwrite' instead."
|
|
52
|
-
);
|
|
53
|
-
overwrite = options.clobber;
|
|
54
|
-
} else {
|
|
55
|
-
overwrite = false;
|
|
56
|
-
}
|
|
57
|
-
const srcStat = await stat(src).catch((e) => {
|
|
58
|
-
if (e.code === "ENOENT") return null;
|
|
59
|
-
throw e;
|
|
60
|
-
});
|
|
61
|
-
if (!srcStat) {
|
|
62
|
-
}
|
|
63
|
-
let destFinal = dest;
|
|
64
|
-
const destStat = await stat(dest).catch((e) => {
|
|
65
|
-
if (e.code === "ENOENT") return null;
|
|
66
|
-
throw e;
|
|
67
|
-
});
|
|
68
|
-
if (destStat?.isDirectory()) {
|
|
69
|
-
destFinal = joinPath(dest, basename(src));
|
|
70
|
-
}
|
|
71
|
-
const destFinalStat = await stat(destFinal).catch((e) => {
|
|
72
|
-
if (e.code === "ENOENT") return null;
|
|
73
|
-
throw e;
|
|
74
|
-
});
|
|
75
|
-
if (destFinalStat && !overwrite) {
|
|
76
|
-
throw new Error(`Destination ${destFinal} already exists and overwrite is false.`);
|
|
77
|
-
}
|
|
78
|
-
const destDir = dirname(destFinal);
|
|
79
|
-
await mkdirs(destDir);
|
|
80
|
-
try {
|
|
81
|
-
await rename(src, destFinal);
|
|
82
|
-
} catch (err) {
|
|
83
|
-
if (err.code === "EXDEV") {
|
|
84
|
-
await copyFile(src, destFinal);
|
|
85
|
-
await unlink(src);
|
|
86
|
-
} else if (err.code === "EISDIR" || err.code === "EPERM") {
|
|
87
|
-
await copyFile(src, destFinal);
|
|
88
|
-
await unlink(src);
|
|
89
|
-
} else {
|
|
90
|
-
throw err;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export interface ReadFileOptions {
|
|
2
|
-
encoding?: BufferEncoding | null;
|
|
3
|
-
flag?: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Reads the entire contents of a file.
|
|
7
|
-
*
|
|
8
|
-
* @param path - The path to the file.
|
|
9
|
-
* @param options - Options for reading the file. Can be an encoding string or an object.
|
|
10
|
-
* @returns The file content as a string or Buffer.
|
|
11
|
-
*/
|
|
12
|
-
export declare function readFileSync(path: string, options: BufferEncoding | (ReadFileOptions & {
|
|
13
|
-
encoding: BufferEncoding;
|
|
14
|
-
})): string;
|
|
15
|
-
export declare function readFileSync(path: string, options?: (ReadFileOptions & {
|
|
16
|
-
encoding?: null;
|
|
17
|
-
}) | null): Buffer;
|
|
18
|
-
/**
|
|
19
|
-
* Asynchronously reads the entire contents of a file.
|
|
20
|
-
*
|
|
21
|
-
* @param path - The path to the file.
|
|
22
|
-
* @param options - Options for reading the file. Can be an encoding string or an object.
|
|
23
|
-
* @returns A promise that resolves with the file content as a string or Buffer.
|
|
24
|
-
*/
|
|
25
|
-
export declare function readFile(path: string, options: BufferEncoding | (ReadFileOptions & {
|
|
26
|
-
encoding: BufferEncoding;
|
|
27
|
-
})): Promise<string>;
|
|
28
|
-
export declare function readFile(path: string, options?: (ReadFileOptions & {
|
|
29
|
-
encoding?: null;
|
|
30
|
-
}) | null): Promise<Buffer>;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { readFileSync as nodeReadFileSync } from "node:fs";
|
|
2
|
-
import { readFile as nodeReadFileAsync } from "node:fs/promises";
|
|
3
|
-
export function readFileSync(path, options) {
|
|
4
|
-
let encoding;
|
|
5
|
-
let flag;
|
|
6
|
-
if (typeof options === "string") {
|
|
7
|
-
encoding = options;
|
|
8
|
-
} else if (options) {
|
|
9
|
-
encoding = options.encoding;
|
|
10
|
-
flag = options.flag;
|
|
11
|
-
}
|
|
12
|
-
if (encoding) {
|
|
13
|
-
return nodeReadFileSync(path, { encoding, flag });
|
|
14
|
-
}
|
|
15
|
-
return nodeReadFileSync(path, { encoding: null, flag });
|
|
16
|
-
}
|
|
17
|
-
export async function readFile(path, options) {
|
|
18
|
-
let encoding;
|
|
19
|
-
let flag;
|
|
20
|
-
if (typeof options === "string") {
|
|
21
|
-
encoding = options;
|
|
22
|
-
} else if (options) {
|
|
23
|
-
encoding = options.encoding;
|
|
24
|
-
flag = options.flag;
|
|
25
|
-
}
|
|
26
|
-
if (encoding) {
|
|
27
|
-
return nodeReadFileAsync(path, { encoding, flag });
|
|
28
|
-
}
|
|
29
|
-
return nodeReadFileAsync(path, { encoding: null, flag });
|
|
30
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
export function readJsonSync(file, options) {
|
|
4
|
-
let encoding = "utf8";
|
|
5
|
-
let reviver;
|
|
6
|
-
let throws = true;
|
|
7
|
-
if (typeof options === "string") {
|
|
8
|
-
encoding = options;
|
|
9
|
-
} else if (options) {
|
|
10
|
-
encoding = options.encoding ?? encoding;
|
|
11
|
-
reviver = options.reviver;
|
|
12
|
-
if (options.throws !== void 0) {
|
|
13
|
-
throws = options.throws;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
const data = readFileSync(file, { encoding });
|
|
18
|
-
return JSON.parse(data, reviver);
|
|
19
|
-
} catch (err) {
|
|
20
|
-
if (throws) {
|
|
21
|
-
throw err;
|
|
22
|
-
}
|
|
23
|
-
return void 0;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export async function readJson(file, options) {
|
|
27
|
-
let encoding = "utf8";
|
|
28
|
-
let reviver;
|
|
29
|
-
let throws = true;
|
|
30
|
-
let flag;
|
|
31
|
-
if (typeof options === "string") {
|
|
32
|
-
encoding = options;
|
|
33
|
-
} else if (options) {
|
|
34
|
-
encoding = options.encoding ?? encoding;
|
|
35
|
-
reviver = options.reviver;
|
|
36
|
-
flag = options.flag;
|
|
37
|
-
if (options.throws !== void 0) {
|
|
38
|
-
throws = options.throws;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
const data = await readFile(file, { encoding, flag });
|
|
43
|
-
return JSON.parse(data, reviver);
|
|
44
|
-
} catch (err) {
|
|
45
|
-
if (throws) {
|
|
46
|
-
throw err;
|
|
47
|
-
}
|
|
48
|
-
return void 0;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync as nodeWriteFileSync } from "node:fs";
|
|
2
|
-
import { mkdir, writeFile as nodeWriteFileAsync, stat } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
export function writeFileSync(file, data, options) {
|
|
5
|
-
const dir = path.dirname(file.toString());
|
|
6
|
-
if (!existsSync(dir)) {
|
|
7
|
-
mkdirSync(dir, { recursive: true });
|
|
8
|
-
}
|
|
9
|
-
nodeWriteFileSync(file, data, options);
|
|
10
|
-
}
|
|
11
|
-
export async function writeFile(file, data, options) {
|
|
12
|
-
const dir = path.dirname(file.toString());
|
|
13
|
-
try {
|
|
14
|
-
await stat(dir);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
if (error.code === "ENOENT") {
|
|
17
|
-
await mkdir(dir, { recursive: true });
|
|
18
|
-
} else {
|
|
19
|
-
throw error;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return nodeWriteFileAsync(file, data, options);
|
|
23
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Mode, OpenMode } from "node:fs";
|
|
2
|
-
export interface JsonStringifyOptions {
|
|
3
|
-
replacer?: (key: string, value: unknown) => unknown | (number | string)[] | null;
|
|
4
|
-
spaces?: string | number;
|
|
5
|
-
}
|
|
6
|
-
export interface WriteJsonOptions {
|
|
7
|
-
encoding?: BufferEncoding | null;
|
|
8
|
-
mode?: Mode;
|
|
9
|
-
flag?: OpenMode;
|
|
10
|
-
replacer?: (key: string, value: unknown) => unknown | (number | string)[] | null;
|
|
11
|
-
spaces?: string | number;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Synchronously writes an object to a JSON file.
|
|
15
|
-
*
|
|
16
|
-
* @param file - The path to the file.
|
|
17
|
-
* @param object - The object to stringify and write.
|
|
18
|
-
* @param options - Options for stringifying JSON or writing the file.
|
|
19
|
-
*/
|
|
20
|
-
export declare function writeJsonSync(file: string, object: unknown, options?: WriteJsonOptions): void;
|
|
21
|
-
/**
|
|
22
|
-
* Asynchronously writes an object to a JSON file.
|
|
23
|
-
*
|
|
24
|
-
* @param file - The path to the file.
|
|
25
|
-
* @param object - The object to stringify and write.
|
|
26
|
-
* @param options - Options for stringifying JSON or writing the file.
|
|
27
|
-
*/
|
|
28
|
-
export declare function writeJson(file: string, object: unknown, options?: WriteJsonOptions): Promise<void>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { writeFileSync } from "./write-file.js";
|
|
2
|
-
import { writeFile } from "./write-file.js";
|
|
3
|
-
export function writeJsonSync(file, object, options = {}) {
|
|
4
|
-
const replacer = options.replacer === void 0 ? null : options.replacer;
|
|
5
|
-
const spaces = options.spaces === void 0 ? 2 : options.spaces;
|
|
6
|
-
const fileWriteOpts = {};
|
|
7
|
-
if (options.encoding !== void 0) fileWriteOpts.encoding = options.encoding;
|
|
8
|
-
if (options.mode !== void 0) fileWriteOpts.mode = options.mode;
|
|
9
|
-
if (options.flag !== void 0) fileWriteOpts.flag = options.flag.toString();
|
|
10
|
-
const str = JSON.stringify(object, replacer, spaces);
|
|
11
|
-
writeFileSync(file, str, fileWriteOpts);
|
|
12
|
-
}
|
|
13
|
-
export async function writeJson(file, object, options = {}) {
|
|
14
|
-
const replacer = options.replacer === void 0 ? null : options.replacer;
|
|
15
|
-
const spaces = options.spaces === void 0 ? 2 : options.spaces;
|
|
16
|
-
const fileWriteOpts = {};
|
|
17
|
-
if (options.encoding !== void 0) fileWriteOpts.encoding = options.encoding;
|
|
18
|
-
if (options.mode !== void 0) fileWriteOpts.mode = options.mode;
|
|
19
|
-
if (options.flag !== void 0) fileWriteOpts.flag = options.flag.toString();
|
|
20
|
-
const str = JSON.stringify(object, replacer, spaces);
|
|
21
|
-
await writeFile(file, str, fileWriteOpts);
|
|
22
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|