@reliverse/relifso 1.1.2 → 1.2.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 +6 -1
- package/bin/impl/async.d.ts +7 -0
- package/bin/impl/async.js +9 -0
- package/bin/impl/copy.d.ts +20 -0
- package/bin/impl/copy.js +28 -0
- package/bin/impl/create-file.d.ts +1 -0
- package/bin/impl/create-file.js +8 -0
- package/bin/impl/dive.d.ts +17 -0
- package/bin/impl/dive.js +56 -0
- package/bin/impl/empty-dir.d.ts +1 -0
- package/bin/impl/empty-dir.js +10 -0
- package/bin/impl/mkdirs.d.ts +1 -0
- package/bin/impl/mkdirs.js +7 -0
- package/bin/impl/move.d.ts +14 -0
- package/bin/impl/move.js +42 -0
- package/bin/impl/output-file.d.ts +8 -0
- package/bin/impl/output-file.js +8 -0
- package/bin/impl/output-json.d.ts +8 -0
- package/bin/impl/output-json.js +8 -0
- package/bin/impl/path-exists.d.ts +1 -0
- package/bin/impl/path-exists.js +4 -0
- package/bin/impl/read-file.d.ts +12 -0
- package/bin/impl/read-file.js +12 -0
- package/bin/impl/read-json.d.ts +14 -0
- package/bin/impl/read-json.js +24 -0
- package/bin/impl/remove.d.ts +1 -0
- package/bin/impl/remove.js +4 -0
- package/bin/impl/write-file.d.ts +11 -0
- package/bin/impl/write-file.js +9 -0
- package/bin/impl/write-json.d.ts +20 -0
- package/bin/impl/write-json.js +11 -0
- package/bin/mod.d.ts +50 -2
- package/bin/mod.js +158 -2
- package/package.json +7 -9
- package/bin/d.ts.txt +0 -1000
- package/bin/impl/args-impl.d.ts +0 -0
- package/bin/impl/args-impl.js +0 -0
- package/bin/impl/array-polyfill.d.ts +0 -15
- package/bin/impl/external/path-is-inside.d.ts +0 -1
- package/bin/impl/external/path-is-inside.js +0 -16
- package/bin/impl/external/vacuum.d.ts +0 -26
- package/bin/impl/external/vacuum.js +0 -95
- package/bin/impl/fs/dive.d.ts +0 -8
- package/bin/impl/fs/dive.js +0 -91
- package/bin/impl/fs/exists.d.ts +0 -31
- package/bin/impl/fs/exists.js +0 -10
- package/bin/impl/fs/for-each-child.d.ts +0 -34
- package/bin/impl/fs/for-each-child.js +0 -37
- package/bin/impl/fs/index.d.ts +0 -1118
- package/bin/impl/fs/index.js +0 -66
- package/bin/impl/fs/is-directory.d.ts +0 -14
- package/bin/impl/fs/is-directory.js +0 -16
- package/bin/impl/fs/map-children.d.ts +0 -17
- package/bin/impl/fs/map-children.js +0 -31
- package/bin/impl/fs/map-structure.d.ts +0 -35
- package/bin/impl/fs/map-structure.js +0 -44
- package/bin/impl/fs/read-lines.d.ts +0 -16
- package/bin/impl/fs/read-lines.js +0 -32
- package/bin/impl/fs/read-text.d.ts +0 -13
- package/bin/impl/fs/read-text.js +0 -10
- package/bin/impl/fs/universalify.d.ts +0 -18
- package/bin/impl/fs/universalify.js +0 -38
- package/bin/impl/fs/write-file.d.ts +0 -93
- package/bin/impl/fs/write-file.js +0 -47
- package/bin/impl/helpers.d.ts +0 -1
- package/bin/impl/helpers.js +0 -37
- package/bin/impl/json.d.ts +0 -16
- package/bin/impl/json.js +0 -90
- package/bin/impl/lib/copy/copy-sync.d.ts +0 -25
- package/bin/impl/lib/copy/copy-sync.js +0 -119
- package/bin/impl/lib/copy/copy.d.ts +0 -7
- package/bin/impl/lib/copy/copy.js +0 -144
- package/bin/impl/lib/copy/index.d.ts +0 -5
- package/bin/impl/lib/copy/index.js +0 -2
- package/bin/impl/lib/empty/index.d.ts +0 -1
- package/bin/impl/lib/empty/index.js +0 -29
- package/bin/impl/lib/ensure/file.d.ts +0 -2
- package/bin/impl/lib/ensure/file.js +0 -56
- package/bin/impl/lib/ensure/index.d.ts +0 -8
- package/bin/impl/lib/ensure/index.js +0 -12
- package/bin/impl/lib/ensure/link.d.ts +0 -2
- package/bin/impl/lib/ensure/link.js +0 -53
- package/bin/impl/lib/ensure/symlink-paths.d.ts +0 -5
- package/bin/impl/lib/ensure/symlink-paths.js +0 -63
- package/bin/impl/lib/ensure/symlink-type.d.ts +0 -2
- package/bin/impl/lib/ensure/symlink-type.js +0 -23
- package/bin/impl/lib/ensure/symlink.d.ts +0 -2
- package/bin/impl/lib/ensure/symlink.js +0 -59
- package/bin/impl/lib/fs/index.d.ts +0 -1
- package/bin/impl/lib/fs/index.js +0 -1
- package/bin/impl/lib/index.d.ts +0 -15
- package/bin/impl/lib/index.js +0 -34
- package/bin/impl/lib/index_rollup.d.ts +0 -10
- package/bin/impl/lib/index_rollup.js +0 -10
- package/bin/impl/lib/json/index.d.ts +0 -3
- package/bin/impl/lib/json/index.js +0 -10
- package/bin/impl/lib/json/output-json-sync.d.ts +0 -1
- package/bin/impl/lib/json/output-json-sync.js +0 -6
- package/bin/impl/lib/json/output-json.d.ts +0 -1
- package/bin/impl/lib/json/output-json.js +0 -6
- package/bin/impl/lib/mkdirs/index.d.ts +0 -1
- package/bin/impl/lib/mkdirs/index.js +0 -4
- package/bin/impl/lib/mkdirs/make-dir.d.ts +0 -2
- package/bin/impl/lib/mkdirs/make-dir.js +0 -21
- package/bin/impl/lib/mkdirs/utils.d.ts +0 -1
- package/bin/impl/lib/mkdirs/utils.js +0 -13
- package/bin/impl/lib/move/index.d.ts +0 -30
- package/bin/impl/lib/move/index.js +0 -2
- package/bin/impl/lib/move/move-sync.d.ts +0 -8
- package/bin/impl/lib/move/move-sync.js +0 -51
- package/bin/impl/lib/move/move.d.ts +0 -6
- package/bin/impl/lib/move/move.js +0 -48
- package/bin/impl/lib/output-file/index.d.ts +0 -1
- package/bin/impl/lib/output-file/index.js +0 -24
- package/bin/impl/lib/remove/index.d.ts +0 -53
- package/bin/impl/lib/remove/index.js +0 -8
- package/bin/impl/lib/util/stat.d.ts +0 -39
- package/bin/impl/lib/util/stat.js +0 -140
- package/bin/impl/lib/util/utimes.d.ts +0 -7
- package/bin/impl/lib/util/utimes.js +0 -31
- package/bin/impl/subindex.d.ts +0 -38
- package/bin/impl/subindex.js +0 -148
- package/bin/types.d.ts +0 -100
- package/bin/types.js +0 -1
package/bin/impl/fs/index.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import * as gfs from "graceful-fs";
|
|
2
|
-
export * from "graceful-fs";
|
|
3
|
-
import rfs from "node:fs";
|
|
4
|
-
import { universalify } from "./universalify.js";
|
|
5
|
-
export const rename = universalify(gfs.rename);
|
|
6
|
-
export const truncate = universalify(gfs.truncate);
|
|
7
|
-
export const ftruncate = universalify(gfs.ftruncate);
|
|
8
|
-
export const chown = universalify(gfs.chown);
|
|
9
|
-
export const fchown = universalify(gfs.fchown);
|
|
10
|
-
export const lchown = universalify(gfs.lchown);
|
|
11
|
-
export const lutimes = universalify(gfs.lutimes);
|
|
12
|
-
export const chmod = universalify(gfs.chmod);
|
|
13
|
-
export const fchmod = universalify(gfs.fchmod);
|
|
14
|
-
export const lchmod = universalify(gfs.lchmod);
|
|
15
|
-
export const stat = universalify(
|
|
16
|
-
gfs.stat
|
|
17
|
-
);
|
|
18
|
-
export const fstat = universalify(gfs.fstat);
|
|
19
|
-
export const lstat = universalify(gfs.lstat);
|
|
20
|
-
export const statfs = universalify(gfs.statfs);
|
|
21
|
-
export const link = universalify(
|
|
22
|
-
gfs.link
|
|
23
|
-
);
|
|
24
|
-
export const symlink = universalify(gfs.symlink);
|
|
25
|
-
export const readlink = universalify(gfs.readlink);
|
|
26
|
-
export const realpath = universalify(gfs.realpath);
|
|
27
|
-
export const unlink = universalify(gfs.unlink);
|
|
28
|
-
export const rmdir = universalify(gfs.rmdir);
|
|
29
|
-
export const rm = universalify(
|
|
30
|
-
gfs.rm
|
|
31
|
-
);
|
|
32
|
-
export const mkdir = universalify(gfs.mkdir);
|
|
33
|
-
export const mkdtemp = universalify(gfs.mkdtemp);
|
|
34
|
-
export const readdir = universalify(gfs.readdir);
|
|
35
|
-
export const close = universalify(gfs.close);
|
|
36
|
-
export const open = universalify(
|
|
37
|
-
gfs.open
|
|
38
|
-
);
|
|
39
|
-
export const utimes = universalify(gfs.utimes);
|
|
40
|
-
export const futimes = universalify(gfs.futimes);
|
|
41
|
-
export const write = universalify(gfs.write, (bytesWritten, buffer) => ({ bytesWritten, buffer }));
|
|
42
|
-
export const read = universalify(
|
|
43
|
-
gfs.read,
|
|
44
|
-
(bytesRead, buffer) => ({ bytesRead, buffer })
|
|
45
|
-
);
|
|
46
|
-
export const readFile = universalify(gfs.readFile);
|
|
47
|
-
export const writeFile = universalify(gfs.writeFile);
|
|
48
|
-
export const appendFile = universalify(gfs.appendFile);
|
|
49
|
-
export const access = universalify(gfs.access);
|
|
50
|
-
export const copyFile = universalify(gfs.copyFile);
|
|
51
|
-
export const writev = universalify(gfs.writev, (bytesWritten, buffers) => ({
|
|
52
|
-
bytesWritten,
|
|
53
|
-
buffers
|
|
54
|
-
}));
|
|
55
|
-
export const readv = universalify(gfs.readv, (bytesRead, buffers) => ({ bytesRead, buffers }));
|
|
56
|
-
export const opendir = universalify(gfs.opendir);
|
|
57
|
-
export const cp = universalify(gfs.cp);
|
|
58
|
-
if (typeof rfs.realpath.native === "function") {
|
|
59
|
-
realpath.native = universalify(rfs.realpath.native);
|
|
60
|
-
} else {
|
|
61
|
-
process.emitWarning(
|
|
62
|
-
"fs.realpath.native is not a function. Is fs being monkey-patched?",
|
|
63
|
-
"Warning",
|
|
64
|
-
"fs-extra-WARN0003"
|
|
65
|
-
);
|
|
66
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check if the file at a path is a directory.
|
|
3
|
-
* @param path the path to the file to check
|
|
4
|
-
* @param callback callback function to call with whether or not the file is a directory, or a value for `err` if the
|
|
5
|
-
* operation fails
|
|
6
|
-
*/
|
|
7
|
-
export declare function isDirectory(path: string, callback: (err: NodeJS.ErrnoException | null, text?: boolean) => void): void;
|
|
8
|
-
export declare function isDirectory(path: string): Promise<boolean>;
|
|
9
|
-
/**
|
|
10
|
-
* Check if the file at a path is a directory.
|
|
11
|
-
* @param path the path to the file to check
|
|
12
|
-
* @returns whether or not the file is a directory
|
|
13
|
-
*/
|
|
14
|
-
export declare function isDirectorySync(path: string): boolean;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as fs from "./index.js";
|
|
2
|
-
async function _isDirectoryHelper(path) {
|
|
3
|
-
return (await fs.stat(path)).isDirectory();
|
|
4
|
-
}
|
|
5
|
-
export function isDirectory(path, callback) {
|
|
6
|
-
if (!callback) {
|
|
7
|
-
return _isDirectoryHelper(path);
|
|
8
|
-
}
|
|
9
|
-
fs.stat(path, (err, stats) => {
|
|
10
|
-
if (err) return callback(err);
|
|
11
|
-
callback(null, stats.isDirectory());
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
export function isDirectorySync(path) {
|
|
15
|
-
return fs.statSync(path).isDirectory();
|
|
16
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { MapChildrenFunction } from "../../types.js";
|
|
2
|
-
import * as fs from "./index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Iterate through every file child of a folder, call a mapper function with each file's contents and write the returned
|
|
5
|
-
* value of the mapper to the files. This will not recurse into subdirectories.
|
|
6
|
-
* @param path folder path to iterate through
|
|
7
|
-
* @param mapper mapping function to call on each file
|
|
8
|
-
* @param readOptions options to pass to [[readFile]]
|
|
9
|
-
* @param writeOptions options to pass to [[writeFile]]
|
|
10
|
-
* @returns a [[Promise]] resolving to an array of the children files, once the mapping is finished.
|
|
11
|
-
*/
|
|
12
|
-
export declare function mapChildren(path: string, mapper: MapChildrenFunction<string>, readOptions: {
|
|
13
|
-
encoding: BufferEncoding;
|
|
14
|
-
} | BufferEncoding, writeOptions?: fs.WriteFileOptions | BufferEncoding): Promise<string[]>;
|
|
15
|
-
export declare function mapChildren(path: string, mapper: MapChildrenFunction<Buffer>, readOptions?: {
|
|
16
|
-
encoding?: null | "buffer";
|
|
17
|
-
} | "buffer" | null, writeOptions?: fs.WriteFileOptions | BufferEncoding): Promise<string[]>;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Array_fromAsync } from "../helpers.js";
|
|
2
|
-
import * as fs from "./index.js";
|
|
3
|
-
import { isDirectory } from "./is-directory.js";
|
|
4
|
-
async function* _asyncFilter(iterable, condition) {
|
|
5
|
-
let i = 0;
|
|
6
|
-
for (const value of iterable) {
|
|
7
|
-
if (await condition(value, i++, iterable)) {
|
|
8
|
-
yield value;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export async function mapChildren(path, mapper, readOptions, writeOptions) {
|
|
13
|
-
const children = await Array_fromAsync(
|
|
14
|
-
_asyncFilter(
|
|
15
|
-
(await fs.readdir(path)).map((child) => path + "/" + child),
|
|
16
|
-
async (e) => !await isDirectory(e)
|
|
17
|
-
)
|
|
18
|
-
);
|
|
19
|
-
for (const e of children) {
|
|
20
|
-
const contents = await fs.readFile(e, readOptions);
|
|
21
|
-
const filename = e.slice(e.lastIndexOf("/") + 1);
|
|
22
|
-
let result = mapper(contents, filename, path, e);
|
|
23
|
-
if (result instanceof Promise) {
|
|
24
|
-
result = await result;
|
|
25
|
-
}
|
|
26
|
-
if (result != contents) {
|
|
27
|
-
await fs.writeFile(e, result, writeOptions);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return children;
|
|
31
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { MapStructureResult, MapStructureFunction } from "../../types.js";
|
|
2
|
-
import * as fs from "./index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Iterate through every file child of a folder recursively, call a mapper function with each file's contents and write
|
|
5
|
-
* the returned value of the mapper to the files. **when passing [[MapStructureFunctionAsync]] as a parameter,
|
|
6
|
-
* operations are done in parallel; to avoid running out of file handles, or to maintain the order (as provided by
|
|
7
|
-
* `dive`), use [[mapStructureOrdered]].**
|
|
8
|
-
* @param path folder path to iterate through
|
|
9
|
-
* @param mapper mapping function to call on each file
|
|
10
|
-
* @param readOptions options to pass to [[readFile]]
|
|
11
|
-
* @param writeOptions options to pass to [[writeFile]]
|
|
12
|
-
* @returns a [[Promise]] resolving to an array of all processed files
|
|
13
|
-
*/
|
|
14
|
-
export declare function mapStructure(path: string, mapper: MapStructureFunction<string>, readOptions: {
|
|
15
|
-
encoding: BufferEncoding;
|
|
16
|
-
} | BufferEncoding, writeOptions?: fs.WriteFileOptions | BufferEncoding): Promise<MapStructureResult[]>;
|
|
17
|
-
export declare function mapStructure(path: string, mapper: MapStructureFunction<Buffer>, readOptions?: {
|
|
18
|
-
encoding?: null | "buffer";
|
|
19
|
-
} | "buffer" | null, writeOptions?: fs.WriteFileOptions | BufferEncoding): Promise<MapStructureResult[]>;
|
|
20
|
-
/**
|
|
21
|
-
* Iterate through every file child of a folder recursively, call a mapper function with each file's contents and write
|
|
22
|
-
* the returned value of the mapper to the files. **Mapper functions are invoked one at a time; to run them all at once,
|
|
23
|
-
* use [[mapStructure]].**
|
|
24
|
-
* @param path folder path to iterate through
|
|
25
|
-
* @param mapper mapping function to call on each file
|
|
26
|
-
* @param readOptions options to pass to [[readFile]]
|
|
27
|
-
* @param writeOptions options to pass to [[writeFile]]
|
|
28
|
-
* @returns a [[Promise]] resolving to an array of all processed files
|
|
29
|
-
*/
|
|
30
|
-
export declare function mapStructureOrdered(path: string, mapper: MapStructureFunction<string>, readOptions: {
|
|
31
|
-
encoding: BufferEncoding;
|
|
32
|
-
} | BufferEncoding, writeOptions?: fs.WriteFileOptions | BufferEncoding): Promise<MapStructureResult[]>;
|
|
33
|
-
export declare function mapStructureOrdered(path: string, mapper: MapStructureFunction<Buffer>, readOptions?: {
|
|
34
|
-
encoding?: null | "buffer";
|
|
35
|
-
} | "buffer" | null, writeOptions?: fs.WriteFileOptions | BufferEncoding): Promise<MapStructureResult[]>;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { _diveWorker, dive } from "./dive.js";
|
|
2
|
-
import * as fs from "./index.js";
|
|
3
|
-
async function _mapStructureProcessFile(file, stat, mapper, readOptions, writeOptions) {
|
|
4
|
-
const contents = await fs.readFile(file, readOptions);
|
|
5
|
-
let result = mapper(contents, file, stat);
|
|
6
|
-
if (result instanceof Promise) {
|
|
7
|
-
result = await result;
|
|
8
|
-
}
|
|
9
|
-
if (result != contents) {
|
|
10
|
-
await fs.writeFile(file, result, writeOptions);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export async function mapStructure(path, mapper, readOptions, writeOptions) {
|
|
14
|
-
const promiseArr = [];
|
|
15
|
-
const results = [];
|
|
16
|
-
await dive(path, { all: true }, (file, stat) => {
|
|
17
|
-
promiseArr.push(
|
|
18
|
-
_mapStructureProcessFile(
|
|
19
|
-
file,
|
|
20
|
-
stat,
|
|
21
|
-
mapper,
|
|
22
|
-
readOptions,
|
|
23
|
-
writeOptions
|
|
24
|
-
)
|
|
25
|
-
);
|
|
26
|
-
results.push({ file, stat });
|
|
27
|
-
});
|
|
28
|
-
await Promise.all(promiseArr);
|
|
29
|
-
return results;
|
|
30
|
-
}
|
|
31
|
-
export async function mapStructureOrdered(path, mapper, readOptions, writeOptions) {
|
|
32
|
-
const entries = [];
|
|
33
|
-
for await (const [file, stat] of _diveWorker(path)) {
|
|
34
|
-
entries.push({ file, stat });
|
|
35
|
-
await _mapStructureProcessFile(
|
|
36
|
-
file,
|
|
37
|
-
stat,
|
|
38
|
-
mapper,
|
|
39
|
-
readOptions,
|
|
40
|
-
writeOptions
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
return entries;
|
|
44
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Read a file into a string array of its lines.
|
|
3
|
-
* @param path the path to the file to read
|
|
4
|
-
* @param encoding the encoding to use to read the file
|
|
5
|
-
* @param callback callback function to call with the file's lines, or a value for `err` if the operation fails
|
|
6
|
-
*/
|
|
7
|
-
export declare function readLines(path: string, encoding: BufferEncoding, callback: (err: NodeJS.ErrnoException | null, lines?: string[]) => void): void;
|
|
8
|
-
export declare function readLines(path: string, callback: (err: NodeJS.ErrnoException | null, lines?: string[]) => void): void;
|
|
9
|
-
export declare function readLines(path: string, encoding?: BufferEncoding): Promise<string[]>;
|
|
10
|
-
/**
|
|
11
|
-
* Synchronously read a file into a string array of its lines.
|
|
12
|
-
* @param path the path to the file to read
|
|
13
|
-
* @param encoding the encoding to use to read the file, default is UTF-8
|
|
14
|
-
* @returns the file's lines
|
|
15
|
-
*/
|
|
16
|
-
export declare function readLinesSync(path: string, encoding?: BufferEncoding): string[];
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as fs from "./index.js";
|
|
2
|
-
function _readLinesHelper(path, encoding, resolve, reject) {
|
|
3
|
-
fs.readFile(path, encoding, (err, data) => {
|
|
4
|
-
if (err) {
|
|
5
|
-
reject(err);
|
|
6
|
-
} else if (data.indexOf("\r\n") > -1) {
|
|
7
|
-
resolve(data.split("\r\n"));
|
|
8
|
-
} else if (data.indexOf("\n") > -1) {
|
|
9
|
-
resolve(data.split("\n"));
|
|
10
|
-
} else resolve([data]);
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
export function readLines(path, o1, o2) {
|
|
14
|
-
const encoding = typeof o1 == "string" ? o1 : "utf8";
|
|
15
|
-
const callback = typeof o1 == "string" ? o2 : o1;
|
|
16
|
-
if (!callback) {
|
|
17
|
-
return new Promise((resolve, reject) => {
|
|
18
|
-
_readLinesHelper(path, encoding, resolve, reject);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
_readLinesHelper(path, encoding, (e) => callback(null, e), callback);
|
|
22
|
-
}
|
|
23
|
-
export function readLinesSync(path, encoding = "utf8") {
|
|
24
|
-
const data = fs.readFileSync(path, encoding);
|
|
25
|
-
if (data.indexOf("\r\n") > -1) {
|
|
26
|
-
return data.split("\r\n");
|
|
27
|
-
}
|
|
28
|
-
if (data.indexOf("\n") > -1) {
|
|
29
|
-
return data.split("\n");
|
|
30
|
-
}
|
|
31
|
-
return [data];
|
|
32
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shorter version of [[readFile]] where the encoding is UTF-8.
|
|
3
|
-
* @param path the path to the file to read
|
|
4
|
-
* @param callback callback function to call with the file's text contents, or a value for `err` if the operation fails
|
|
5
|
-
*/
|
|
6
|
-
export declare function readText(path: string, callback: (err: NodeJS.ErrnoException | null, text: string) => void): void;
|
|
7
|
-
export declare function readText(path: string): Promise<string>;
|
|
8
|
-
/**
|
|
9
|
-
* Shorter version of [[readFileSync]] where the encoding is UTF-8.
|
|
10
|
-
* @param path the path to the file to read
|
|
11
|
-
* @returns the file's text contents
|
|
12
|
-
*/
|
|
13
|
-
export declare function readTextSync(path: string): string;
|
package/bin/impl/fs/read-text.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as fs from "./index.js";
|
|
2
|
-
export function readText(path, callback) {
|
|
3
|
-
if (!callback) {
|
|
4
|
-
return fs.readFile(path, "utf8");
|
|
5
|
-
}
|
|
6
|
-
fs.readFile(path, "utf8", callback);
|
|
7
|
-
}
|
|
8
|
-
export function readTextSync(path) {
|
|
9
|
-
return fs.readFileSync(path, "utf8");
|
|
10
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { type CustomPromisify } from "node:util";
|
|
2
|
-
type LastElement<Arr extends any[]> = Arr extends [...any[], infer B] ? B : never;
|
|
3
|
-
type CallbackArgs<T extends (...args: any) => any> = LastElement<Parameters<T>> extends (err: any, ...cbArgs: infer CbArgs) => void ? CbArgs : never;
|
|
4
|
-
export declare function universalify<TFunction extends CustomPromisify<TCustom> & ((...args: any) => any), TCustom extends (...args: any) => any>(fn: TFunction & CustomPromisify<TCustom>, fallbackMultiResultObjectCreator: (...args: CallbackArgs<TFunction>) => Awaited<ReturnType<TCustom>>): TFunction & TCustom;
|
|
5
|
-
export declare function universalify<A extends unknown[], X extends (...args: any[]) => any, R extends any[], F>(fn: X & ((...args: [...A, (err: any, ...cbArgs: R) => void]) => void), fallbackMultiResultObjectCreator: (...args: R) => F): {
|
|
6
|
-
(...args: Parameters<X>): void;
|
|
7
|
-
(...args: A): Promise<F>;
|
|
8
|
-
};
|
|
9
|
-
export declare function universalify<TFunction extends CustomPromisify<TCustom>, TCustom extends (...args: any) => any>(fn: TFunction & CustomPromisify<TCustom>): TFunction & TCustom;
|
|
10
|
-
export declare function universalify<A extends unknown[], X extends (...args: any[]) => any, R>(fn: X & ((...args: [...A, (err: any, result: R) => void]) => void)): {
|
|
11
|
-
(...args: Parameters<X>): void;
|
|
12
|
-
(...args: A): Promise<R>;
|
|
13
|
-
};
|
|
14
|
-
export declare function universalify<A extends unknown[], X extends (...args: any[]) => any, R>(fn: X & ((...args: [...A, (err?: any) => void]) => void)): {
|
|
15
|
-
(...args: Parameters<X>): void;
|
|
16
|
-
(...args: A): Promise<void>;
|
|
17
|
-
};
|
|
18
|
-
export {};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { promisify } from "node:util";
|
|
2
|
-
const universalifiedSymbol = Symbol();
|
|
3
|
-
export function universalify(fn, fallbackMultiResultObjectCreator) {
|
|
4
|
-
if (!fn) return fn;
|
|
5
|
-
if (universalifiedSymbol in fn) {
|
|
6
|
-
return fn[universalifiedSymbol];
|
|
7
|
-
}
|
|
8
|
-
const promisified = fallbackMultiResultObjectCreator ? promisifyFallback(fn, fallbackMultiResultObjectCreator) : promisify(fn);
|
|
9
|
-
const f = (...args) => {
|
|
10
|
-
const cb = args[args.length - 1];
|
|
11
|
-
if (typeof cb === "function") {
|
|
12
|
-
return fn(...args);
|
|
13
|
-
}
|
|
14
|
-
return promisified(...args);
|
|
15
|
-
};
|
|
16
|
-
const attr = {
|
|
17
|
-
value: f,
|
|
18
|
-
enumerable: false,
|
|
19
|
-
writable: false,
|
|
20
|
-
configurable: true
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(fn, universalifiedSymbol, attr);
|
|
23
|
-
Object.defineProperty(f, universalifiedSymbol, attr);
|
|
24
|
-
return f;
|
|
25
|
-
}
|
|
26
|
-
function promisifyFallback(fn, fallbackObjectCreator) {
|
|
27
|
-
if ("__promisify__" in fn || promisify.custom in fn) {
|
|
28
|
-
return promisify(fn);
|
|
29
|
-
}
|
|
30
|
-
return (...args) => {
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
fn(...args, (err, ...results) => {
|
|
33
|
-
if (err) reject(err);
|
|
34
|
-
resolve(fallbackObjectCreator(...results));
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type * as streamWeb from "node:stream/web";
|
|
2
|
-
import type * as fs from "./index.js";
|
|
3
|
-
/**
|
|
4
|
-
* When `file` is a filename, asynchronously writes data to the file, replacing the
|
|
5
|
-
* file if it already exists. `data` can be a string or a buffer.
|
|
6
|
-
*
|
|
7
|
-
* When `file` is a file descriptor, the behavior is similar to calling`fs.write()` directly (which is recommended). See the notes below on using
|
|
8
|
-
* a file descriptor.
|
|
9
|
-
*
|
|
10
|
-
* The `encoding` option is ignored if `data` is a buffer.
|
|
11
|
-
*
|
|
12
|
-
* The `mode` option only affects the newly created file. See {@link open} for more details.
|
|
13
|
-
*
|
|
14
|
-
* ```js
|
|
15
|
-
* import { writeFile } from 'node:fs';
|
|
16
|
-
* import { Buffer } from 'node:buffer';
|
|
17
|
-
*
|
|
18
|
-
* const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
|
19
|
-
* writeFile('message.txt', data, (err) => {
|
|
20
|
-
* if (err) throw err;
|
|
21
|
-
* console.log('The file has been saved!');
|
|
22
|
-
* });
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* If `options` is a string, then it specifies the encoding:
|
|
26
|
-
*
|
|
27
|
-
* ```js
|
|
28
|
-
* import { writeFile } from 'node:fs';
|
|
29
|
-
*
|
|
30
|
-
* writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* It is unsafe to use `fs.writeFile()` multiple times on the same file without
|
|
34
|
-
* waiting for the callback. For this scenario, {@link createWriteStream} is
|
|
35
|
-
* recommended.
|
|
36
|
-
*
|
|
37
|
-
* Similarly to `fs.readFile` \- `fs.writeFile` is a convenience method that
|
|
38
|
-
* performs multiple `write` calls internally to write the buffer passed to it.
|
|
39
|
-
* For performance sensitive code consider using {@link createWriteStream}.
|
|
40
|
-
*
|
|
41
|
-
* It is possible to use an `AbortSignal` to cancel an `fs.writeFile()`.
|
|
42
|
-
* Cancelation is "best effort", and some amount of data is likely still
|
|
43
|
-
* to be written.
|
|
44
|
-
*
|
|
45
|
-
* ```js
|
|
46
|
-
* import { writeFile } from 'node:fs';
|
|
47
|
-
* import { Buffer } from 'node:buffer';
|
|
48
|
-
*
|
|
49
|
-
* const controller = new AbortController();
|
|
50
|
-
* const { signal } = controller;
|
|
51
|
-
* const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
|
52
|
-
* writeFile('message.txt', data, { signal }, (err) => {
|
|
53
|
-
* // When a request is aborted - the callback is called with an AbortError
|
|
54
|
-
* });
|
|
55
|
-
* // When the request should be aborted
|
|
56
|
-
* controller.abort();
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
* Aborting an ongoing request does not abort individual operating
|
|
60
|
-
* system requests but rather the internal buffering `fs.writeFile` performs.
|
|
61
|
-
* @since v0.1.29
|
|
62
|
-
* @param file filename or file descriptor
|
|
63
|
-
* @param data The data to write. If a stream is provided, it will be read to completion.
|
|
64
|
-
* @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
|
|
65
|
-
* If `encoding` is not supplied, the default of `'utf8'` is used.
|
|
66
|
-
* If `mode` is not supplied, the default of `0o666` is used.
|
|
67
|
-
* If `mode` is a string, it is parsed as an octal integer.
|
|
68
|
-
* If `flag` is not supplied, the default of `'w'` is used.
|
|
69
|
-
* @since Web Streams API support since Node v17.0.0
|
|
70
|
-
*/
|
|
71
|
-
export declare function writeFile(file: fs.PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer | NodeJS.ReadableStream | streamWeb.ReadableStream, options: fs.WriteFileOptions, callback: fs.NoParamCallback): void;
|
|
72
|
-
/**
|
|
73
|
-
* Asynchronously writes data to a file, replacing the file if it already exists.
|
|
74
|
-
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
75
|
-
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
|
|
76
|
-
* @param data The data to write. If a stream is provided, it will be read to completion.
|
|
77
|
-
* @since Web Streams API support since Node v17.0.0
|
|
78
|
-
*/
|
|
79
|
-
export declare function writeFile(path: fs.PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer | NodeJS.ReadableStream | streamWeb.ReadableStream, callback: fs.NoParamCallback): void;
|
|
80
|
-
/**
|
|
81
|
-
* Asynchronously writes data to a file, replacing the file if it already exists.
|
|
82
|
-
* @param path A path to a file. If a URL is provided, it must use the `file:` protocol.
|
|
83
|
-
* URL support is _experimental_.
|
|
84
|
-
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
|
|
85
|
-
* @param data The data to write. If a stream is provided, it will be read to completion.
|
|
86
|
-
* @param options Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag.
|
|
87
|
-
* If `encoding` is not supplied, the default of `'utf8'` is used.
|
|
88
|
-
* If `mode` is not supplied, the default of `0o666` is used.
|
|
89
|
-
* If `mode` is a string, it is parsed as an octal integer.
|
|
90
|
-
* If `flag` is not supplied, the default of `'w'` is used.
|
|
91
|
-
* @since Web Streams API support since Node v17.0.0
|
|
92
|
-
*/
|
|
93
|
-
export declare function writeFile(path: fs.PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer | NodeJS.ReadableStream | streamWeb.ReadableStream, options?: fs.WriteFileOptions): Promise<void>;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { createWriteStream, writeFile as _writeFile } from "graceful-fs";
|
|
2
|
-
import { Readable, isReadable } from "node:stream";
|
|
3
|
-
import { finished } from "node:stream/promises";
|
|
4
|
-
import { ReadableStream } from "node:stream/web";
|
|
5
|
-
import { fromPromise } from "universalify";
|
|
6
|
-
import { universalify } from "./universalify.js";
|
|
7
|
-
const backingWriteFile = universalify(_writeFile);
|
|
8
|
-
const _writeFileStreamHelper = fromPromise(
|
|
9
|
-
async (path, data, options) => {
|
|
10
|
-
function getOptions(options2) {
|
|
11
|
-
return options2 ? typeof options2 === "string" ? { encoding: options2 } : {
|
|
12
|
-
encoding: options2.encoding || void 0,
|
|
13
|
-
mode: typeof options2.mode === "string" ? Number.parseInt(options2.mode, 8) : options2.mode,
|
|
14
|
-
flush: options2.flush
|
|
15
|
-
} : void 0;
|
|
16
|
-
}
|
|
17
|
-
let stream;
|
|
18
|
-
if (typeof path === "number") {
|
|
19
|
-
stream = createWriteStream("", { ...getOptions(options), fd: path });
|
|
20
|
-
} else {
|
|
21
|
-
stream = createWriteStream(path, getOptions(options));
|
|
22
|
-
}
|
|
23
|
-
await finished(data.pipe(stream));
|
|
24
|
-
}
|
|
25
|
-
);
|
|
26
|
-
export function writeFile(path, data, optionsOrCallback, optionalCallback) {
|
|
27
|
-
const options = typeof optionsOrCallback !== "function" ? optionsOrCallback : void 0;
|
|
28
|
-
const callback = optionalCallback ?? (typeof optionsOrCallback === "function" ? optionsOrCallback : void 0);
|
|
29
|
-
if (data instanceof ReadableStream) {
|
|
30
|
-
data = Readable.fromWeb(data);
|
|
31
|
-
}
|
|
32
|
-
if (isNodeReadableStream(data)) {
|
|
33
|
-
return _writeFileStreamHelper(path, data, options, callback);
|
|
34
|
-
}
|
|
35
|
-
if (data instanceof SharedArrayBuffer || data instanceof ArrayBuffer) {
|
|
36
|
-
data = new Uint8Array(data);
|
|
37
|
-
}
|
|
38
|
-
return backingWriteFile(
|
|
39
|
-
path,
|
|
40
|
-
data,
|
|
41
|
-
optionsOrCallback,
|
|
42
|
-
optionalCallback
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
function isNodeReadableStream(stream) {
|
|
46
|
-
return typeof stream === "object" && "readable" in stream && isReadable(stream);
|
|
47
|
-
}
|
package/bin/impl/helpers.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const Array_fromAsync: any;
|
package/bin/impl/helpers.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export const Array_fromAsync = Array.fromAsync ?? async function fromAsync(iterableOrArrayLike, mapperFn) {
|
|
2
|
-
const items = [];
|
|
3
|
-
if (mapperFn) {
|
|
4
|
-
if (Symbol.asyncIterator in iterableOrArrayLike) {
|
|
5
|
-
for await (const item of iterableOrArrayLike) {
|
|
6
|
-
items.push(await mapperFn(item));
|
|
7
|
-
}
|
|
8
|
-
} else if (Symbol.iterator in iterableOrArrayLike) {
|
|
9
|
-
for (const item of iterableOrArrayLike) {
|
|
10
|
-
items.push(await mapperFn(await item));
|
|
11
|
-
}
|
|
12
|
-
} else {
|
|
13
|
-
const length = iterableOrArrayLike.length;
|
|
14
|
-
for (let i = 0; i < length; i++) {
|
|
15
|
-
const item = await iterableOrArrayLike[i];
|
|
16
|
-
items.push(await mapperFn(item));
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
} else {
|
|
20
|
-
if (Symbol.asyncIterator in iterableOrArrayLike) {
|
|
21
|
-
for await (const item of iterableOrArrayLike) {
|
|
22
|
-
items.push(item);
|
|
23
|
-
}
|
|
24
|
-
} else if (Symbol.iterator in iterableOrArrayLike) {
|
|
25
|
-
for (const item of iterableOrArrayLike) {
|
|
26
|
-
items.push(await item);
|
|
27
|
-
}
|
|
28
|
-
} else {
|
|
29
|
-
const length = iterableOrArrayLike.length;
|
|
30
|
-
for (let i = 0; i < length; i++) {
|
|
31
|
-
const item = await iterableOrArrayLike[i];
|
|
32
|
-
items.push(item);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return items;
|
|
37
|
-
};
|
package/bin/impl/json.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { JsonOutputOptions } from 'fs-extra';
|
|
2
|
-
import type { ReadCallback, WriteCallback } from 'jsonfile';
|
|
3
|
-
import type { JsonReadOptions, JsonWriteOptions } from '../types.js';
|
|
4
|
-
import * as fs from './fs/index.js';
|
|
5
|
-
export declare function readJson(file: fs.PathOrFileDescriptor, options: JsonReadOptions, callback: ReadCallback): void;
|
|
6
|
-
export declare function readJson(file: fs.PathOrFileDescriptor, callback: ReadCallback): void;
|
|
7
|
-
export declare function readJson<T>(file: fs.PathOrFileDescriptor, options?: JsonReadOptions): Promise<T>;
|
|
8
|
-
export declare function readJsonSync<T = any>(file: fs.PathOrFileDescriptor, options?: JsonReadOptions): T | null;
|
|
9
|
-
export declare function writeJson(file: fs.PathOrFileDescriptor, obj: unknown, options: JsonWriteOptions, callback: WriteCallback): void;
|
|
10
|
-
export declare function writeJson(file: fs.PathOrFileDescriptor, obj: unknown, callback: WriteCallback): void;
|
|
11
|
-
export declare function writeJson(file: fs.PathOrFileDescriptor, obj: unknown, options?: JsonWriteOptions): Promise<void>;
|
|
12
|
-
export declare function writeJsonSync(file: fs.PathOrFileDescriptor, obj: unknown, options?: JsonWriteOptions): void;
|
|
13
|
-
export declare function outputJson(file: string, data: unknown, options?: JsonOutputOptions): Promise<void>;
|
|
14
|
-
export declare function outputJson(file: string, data: unknown, options: JsonOutputOptions, callback: fs.NoParamCallback): void;
|
|
15
|
-
export declare function outputJson(file: string, data: unknown, callback: fs.NoParamCallback): void;
|
|
16
|
-
export declare function outputJsonSync(file: string, data: unknown, options?: JsonOutputOptions): void;
|
package/bin/impl/json.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync } from "graceful-fs";
|
|
2
|
-
import * as fs from "./fs/index.js";
|
|
3
|
-
import { universalify } from "./fs/universalify.js";
|
|
4
|
-
import { outputFile, outputFileSync } from "./lib/output-file/index.js";
|
|
5
|
-
const stripBom = (content) => Buffer.isBuffer(content) ? content.toString("utf8").replace(/^\uFEFF/, "") : content.replace(/^\uFEFF/, "");
|
|
6
|
-
const stringify = (obj, {
|
|
7
|
-
EOL = "\n",
|
|
8
|
-
finalEOL = true,
|
|
9
|
-
replacer,
|
|
10
|
-
spaces
|
|
11
|
-
}) => {
|
|
12
|
-
const eof = finalEOL ? EOL : "";
|
|
13
|
-
return JSON.stringify(obj, replacer, spaces).replace(/\n/g, EOL) + eof;
|
|
14
|
-
};
|
|
15
|
-
async function _readJson(file, options = {}) {
|
|
16
|
-
if (typeof options === "string") options = { encoding: options };
|
|
17
|
-
const read = options.fs?.readFile ? universalify(options.fs.readFile) : fs.readFile;
|
|
18
|
-
const data = stripBom(await read(file, options));
|
|
19
|
-
try {
|
|
20
|
-
return JSON.parse(data, options.reviver);
|
|
21
|
-
} catch (err) {
|
|
22
|
-
if (options.throws ?? true) {
|
|
23
|
-
const e = err instanceof Error ? err : new Error(String(err));
|
|
24
|
-
e.message = `${file}: ${e.message}`;
|
|
25
|
-
throw e;
|
|
26
|
-
}
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export function readJson(file, o1, o2) {
|
|
31
|
-
const options = typeof o1 === "object" ? o1 : void 0;
|
|
32
|
-
const cb = typeof o1 === "function" ? o1 : o2;
|
|
33
|
-
if (!cb) return _readJson(file, options);
|
|
34
|
-
void _readJson(file, options).then(
|
|
35
|
-
(res) => cb(null, res),
|
|
36
|
-
(err) => cb(err, void 0)
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
export function readJsonSync(file, options = {}) {
|
|
40
|
-
if (typeof options === "string") options = { encoding: options };
|
|
41
|
-
const read = options.fs?.readFileSync ?? readFileSync;
|
|
42
|
-
try {
|
|
43
|
-
const data = stripBom(read(file, options));
|
|
44
|
-
return JSON.parse(data, options.reviver);
|
|
45
|
-
} catch (err) {
|
|
46
|
-
if (options.throws ?? true) {
|
|
47
|
-
const e = err instanceof Error ? err : new Error(String(err));
|
|
48
|
-
e.message = `${file}: ${e.message}`;
|
|
49
|
-
throw e;
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async function _writeJson(file, obj, options = {}) {
|
|
55
|
-
if (typeof options === "string") options = { encoding: options };
|
|
56
|
-
const write = options.fs?.writeFile ? universalify(options.fs.writeFile) : fs.writeFile;
|
|
57
|
-
await write(file, stringify(obj, options), options);
|
|
58
|
-
}
|
|
59
|
-
export function writeJson(file, obj, o1, o2) {
|
|
60
|
-
const options = typeof o1 === "object" ? o1 : void 0;
|
|
61
|
-
const cb = typeof o1 === "function" ? o1 : o2;
|
|
62
|
-
if (!cb) return _writeJson(file, obj, options);
|
|
63
|
-
void _writeJson(file, obj, options).then(
|
|
64
|
-
() => cb(null),
|
|
65
|
-
(err) => cb(err)
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
export function writeJsonSync(file, obj, options = {}) {
|
|
69
|
-
if (typeof options === "string") options = { encoding: options };
|
|
70
|
-
const write = options.fs?.writeFileSync ?? writeFileSync;
|
|
71
|
-
write(file, stringify(obj, options), options);
|
|
72
|
-
}
|
|
73
|
-
export function outputJson(file, data, o1, o2) {
|
|
74
|
-
const options = typeof o1 === "object" ? o1 : {};
|
|
75
|
-
const cb = typeof o1 === "function" ? o1 : o2;
|
|
76
|
-
if (cb) {
|
|
77
|
-
return outputFile(file, stringify(data, options), options, cb);
|
|
78
|
-
}
|
|
79
|
-
return new Promise((res, rej) => {
|
|
80
|
-
outputFile(
|
|
81
|
-
file,
|
|
82
|
-
stringify(data, options),
|
|
83
|
-
options,
|
|
84
|
-
(err) => err ? rej(err) : res()
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
export function outputJsonSync(file, data, options = {}) {
|
|
89
|
-
outputFileSync(file, stringify(data, options), options);
|
|
90
|
-
}
|