@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
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface CopyOptions {
|
|
2
|
-
/** Overwrite destination if it exists (falls back to `clobber`) */
|
|
3
|
-
overwrite?: boolean;
|
|
4
|
-
/** Throw if destination exists and won’t be overwritten */
|
|
5
|
-
errorOnExist?: boolean;
|
|
6
|
-
/** Preserve atime / mtime – ⚠︎ slow on >4 GiB files on 32‑bit Node */
|
|
7
|
-
preserveTimestamps?: boolean;
|
|
8
|
-
/** Follow symlinks instead of copying the link itself */
|
|
9
|
-
dereference?: boolean;
|
|
10
|
-
/** Filter callback: return false to skip a file/directory */
|
|
11
|
-
filter?: (src: string, dest: string) => boolean;
|
|
12
|
-
/** Explicit chmod bits for new files/dirs */
|
|
13
|
-
mode?: number;
|
|
14
|
-
/** *Deprecated* in fs‑extra – kept for BC; default `true` */
|
|
15
|
-
clobber?: boolean;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Synchronous, fully‑typed variant of `fs‑extra`’s `copySync`.
|
|
19
|
-
*
|
|
20
|
-
* ```ts
|
|
21
|
-
* copySync('src', 'dest', { overwrite: false, filter: /\\.png$/i.test });
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
export declare function copySync(src: string, dest: string, options?: CopyOptions | ((src: string, dest: string) => boolean)): void;
|
|
25
|
-
export default copySync;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
existsSync,
|
|
3
|
-
statSync as _statSync,
|
|
4
|
-
lstatSync,
|
|
5
|
-
unlinkSync,
|
|
6
|
-
copyFileSync,
|
|
7
|
-
chmodSync,
|
|
8
|
-
mkdirSync,
|
|
9
|
-
readdirSync,
|
|
10
|
-
readlinkSync,
|
|
11
|
-
symlinkSync
|
|
12
|
-
} from "graceful-fs";
|
|
13
|
-
import { dirname, join, resolve } from "node:path";
|
|
14
|
-
import { mkdirsSync } from "../mkdirs/index.js";
|
|
15
|
-
import {
|
|
16
|
-
checkParentPathsSync,
|
|
17
|
-
checkPathsSync,
|
|
18
|
-
isSrcSubdir
|
|
19
|
-
} from "../util/stat.js";
|
|
20
|
-
import { utimesMillisSync } from "../util/utimes.js";
|
|
21
|
-
export function copySync(src, dest, options = {}) {
|
|
22
|
-
const opts = typeof options === "function" ? { filter: options } : { ...options };
|
|
23
|
-
const clobber = "clobber" in opts ? !!opts.clobber : true;
|
|
24
|
-
opts.overwrite = opts.overwrite ?? clobber;
|
|
25
|
-
if (opts.preserveTimestamps && process.arch === "ia32") {
|
|
26
|
-
process.emitWarning(
|
|
27
|
-
"Using preserveTimestamps on 32-bit Node is discouraged - it may overflow",
|
|
28
|
-
{ code: "FS_EXTRA_WARN0002", type: "Warning" }
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
const { srcStat, destStat } = checkPathsSync(src, dest, "copy", opts);
|
|
32
|
-
checkParentPathsSync(src, srcStat, dest, "copy");
|
|
33
|
-
if (opts.filter && !opts.filter(src, dest)) return;
|
|
34
|
-
const destParent = dirname(dest);
|
|
35
|
-
if (!existsSync(destParent)) mkdirsSync(destParent, {});
|
|
36
|
-
processEntry(destStat, src, dest, opts);
|
|
37
|
-
}
|
|
38
|
-
export default copySync;
|
|
39
|
-
const processEntry = (destStat, src, dest, opts) => {
|
|
40
|
-
const statSync = opts.dereference ? _statSync : lstatSync;
|
|
41
|
-
const srcStat = statSync(src);
|
|
42
|
-
if (srcStat.isDirectory()) onDir(srcStat, destStat, src, dest, opts);
|
|
43
|
-
else if (srcStat.isFile() || srcStat.isCharacterDevice() || srcStat.isBlockDevice())
|
|
44
|
-
onFile(srcStat, destStat, src, dest, opts);
|
|
45
|
-
else if (srcStat.isSymbolicLink()) onLink(destStat, src, dest, opts);
|
|
46
|
-
else if (srcStat.isSocket())
|
|
47
|
-
throw new Error(`Cannot copy a socket file: ${src}`);
|
|
48
|
-
else if (srcStat.isFIFO())
|
|
49
|
-
throw new Error(`Cannot copy a FIFO pipe: ${src}`);
|
|
50
|
-
else throw new Error(`Unknown file type: ${src}`);
|
|
51
|
-
};
|
|
52
|
-
const onFile = (srcStat, destStat, src, dest, opts) => {
|
|
53
|
-
if (!destStat) return copyFile(srcStat.mode, src, dest, opts);
|
|
54
|
-
if (opts.overwrite) {
|
|
55
|
-
unlinkSync(dest);
|
|
56
|
-
return copyFile(srcStat.mode, src, dest, opts);
|
|
57
|
-
}
|
|
58
|
-
if (opts.errorOnExist) {
|
|
59
|
-
throw new Error(`'${String(dest)}' already exists`);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const copyFile = (srcMode, src, dest, opts) => {
|
|
63
|
-
copyFileSync(src, dest);
|
|
64
|
-
if (opts.preserveTimestamps) handleTimestamps(srcMode, src, dest);
|
|
65
|
-
chmodSync(dest, srcMode);
|
|
66
|
-
};
|
|
67
|
-
const handleTimestamps = (srcMode, src, dest) => {
|
|
68
|
-
if ((srcMode & 128) === 0) chmodSync(dest, srcMode | 128);
|
|
69
|
-
const { atime, mtime } = _statSync(src);
|
|
70
|
-
utimesMillisSync(dest, atime, mtime);
|
|
71
|
-
};
|
|
72
|
-
const onDir = (srcStat, destStat, src, dest, opts) => {
|
|
73
|
-
if (!destStat) {
|
|
74
|
-
mkdirSync(dest);
|
|
75
|
-
chmodSync(dest, srcStat.mode);
|
|
76
|
-
}
|
|
77
|
-
copyDir(src, dest, opts);
|
|
78
|
-
};
|
|
79
|
-
const copyDir = (src, dest, opts) => {
|
|
80
|
-
for (const item of readdirSync(src)) {
|
|
81
|
-
const srcItem = join(src, item);
|
|
82
|
-
const destItem = join(dest, item);
|
|
83
|
-
if (opts.filter && !opts.filter(srcItem, destItem)) continue;
|
|
84
|
-
const { destStat } = checkPathsSync(srcItem, destItem, "copy", opts);
|
|
85
|
-
processEntry(destStat, srcItem, destItem, opts);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const onLink = (destStat, src, dest, opts) => {
|
|
89
|
-
let resolvedSrc = readlinkSync(src);
|
|
90
|
-
if (opts.dereference) resolvedSrc = resolve(process.cwd(), resolvedSrc);
|
|
91
|
-
if (!destStat) {
|
|
92
|
-
symlinkSync(resolvedSrc, dest);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
let resolvedDest;
|
|
96
|
-
try {
|
|
97
|
-
resolvedDest = readlinkSync(dest);
|
|
98
|
-
} catch (err) {
|
|
99
|
-
const e = err;
|
|
100
|
-
if (e.code === "EINVAL" || e.code === "UNKNOWN") {
|
|
101
|
-
symlinkSync(resolvedSrc, dest);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
throw err;
|
|
105
|
-
}
|
|
106
|
-
if (opts.dereference) resolvedDest = resolve(process.cwd(), resolvedDest);
|
|
107
|
-
if (isSrcSubdir(resolvedSrc, resolvedDest)) {
|
|
108
|
-
throw new Error(
|
|
109
|
-
`Cannot copy '${resolvedSrc}' into its own subdirectory '${resolvedDest}'.`
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
if (isSrcSubdir(resolvedDest, resolvedSrc)) {
|
|
113
|
-
throw new Error(
|
|
114
|
-
`Cannot overwrite '${resolvedDest}' with its parent '${resolvedSrc}'.`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
unlinkSync(dest);
|
|
118
|
-
symlinkSync(resolvedSrc, dest);
|
|
119
|
-
};
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { dirname, join, resolve } from "node:path";
|
|
2
|
-
import { fromPromise } from "universalify";
|
|
3
|
-
import { exists as pathExists } from "../../fs/exists.js";
|
|
4
|
-
import {
|
|
5
|
-
stat as _stat,
|
|
6
|
-
lstat,
|
|
7
|
-
unlink,
|
|
8
|
-
copyFile as _copyFile,
|
|
9
|
-
chmod,
|
|
10
|
-
mkdir,
|
|
11
|
-
readdir,
|
|
12
|
-
readlink,
|
|
13
|
-
symlink
|
|
14
|
-
} from "../../fs/index.js";
|
|
15
|
-
import { mkdirs } from "../mkdirs/index.js";
|
|
16
|
-
import {
|
|
17
|
-
checkPaths,
|
|
18
|
-
checkParentPaths,
|
|
19
|
-
isSrcSubdir
|
|
20
|
-
} from "../util/stat.js";
|
|
21
|
-
import { utimesMillis } from "../util/utimes.js";
|
|
22
|
-
export default fromPromise(async function copy(src, dest, opts = {}) {
|
|
23
|
-
if (typeof opts === "function") {
|
|
24
|
-
opts = { filter: opts };
|
|
25
|
-
}
|
|
26
|
-
opts.clobber = "clobber" in opts ? !!opts.clobber : true;
|
|
27
|
-
opts.overwrite = "overwrite" in opts ? !!opts.overwrite : opts.clobber;
|
|
28
|
-
if (opts.preserveTimestamps && process.arch === "ia32") {
|
|
29
|
-
process.emitWarning(
|
|
30
|
-
"Using the preserveTimestamps option in 32-bit node is not recommended;\n\n see https://github.com/jprichardson/node-fs-extra/issues/269",
|
|
31
|
-
"Warning",
|
|
32
|
-
"fs-extra-WARN0001"
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
const { srcStat, destStat } = await checkPaths(src, dest, "copy", opts);
|
|
36
|
-
await checkParentPaths(src, srcStat, dest, "copy");
|
|
37
|
-
const include = await runFilter(src, dest, opts);
|
|
38
|
-
if (!include) return;
|
|
39
|
-
const destParent = dirname(dest);
|
|
40
|
-
const dirExists = await pathExists(destParent);
|
|
41
|
-
if (!dirExists) {
|
|
42
|
-
await mkdirs(destParent);
|
|
43
|
-
}
|
|
44
|
-
await getStatsAndPerformCopy(destStat, src, dest, opts);
|
|
45
|
-
});
|
|
46
|
-
async function runFilter(src, dest, opts) {
|
|
47
|
-
if (!opts.filter) return true;
|
|
48
|
-
return opts.filter(src, dest);
|
|
49
|
-
}
|
|
50
|
-
async function getStatsAndPerformCopy(destStat, src, dest, opts) {
|
|
51
|
-
const statFn = opts.dereference ? _stat : lstat;
|
|
52
|
-
const srcStat = await statFn(src);
|
|
53
|
-
if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts);
|
|
54
|
-
if (srcStat.isFile() || srcStat.isCharacterDevice() || srcStat.isBlockDevice())
|
|
55
|
-
return onFile(srcStat, destStat, src, dest, opts);
|
|
56
|
-
if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts);
|
|
57
|
-
if (srcStat.isSocket()) throw new Error(`Cannot copy a socket file: ${src}`);
|
|
58
|
-
if (srcStat.isFIFO()) throw new Error(`Cannot copy a FIFO pipe: ${src}`);
|
|
59
|
-
throw new Error(`Unknown file: ${src}`);
|
|
60
|
-
}
|
|
61
|
-
async function onFile(srcStat, destStat, src, dest, opts) {
|
|
62
|
-
if (!destStat) return copyFile(srcStat, src, dest, opts);
|
|
63
|
-
if (opts.overwrite) {
|
|
64
|
-
await unlink(dest);
|
|
65
|
-
return copyFile(srcStat, src, dest, opts);
|
|
66
|
-
}
|
|
67
|
-
if (opts.errorOnExist) {
|
|
68
|
-
throw new Error(`'${dest}' already exists`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
async function copyFile(srcStat, src, dest, opts) {
|
|
72
|
-
await _copyFile(src, dest);
|
|
73
|
-
if (opts.preserveTimestamps) {
|
|
74
|
-
if (fileIsNotWritable(srcStat.mode)) {
|
|
75
|
-
await makeFileWritable(dest, srcStat.mode);
|
|
76
|
-
}
|
|
77
|
-
const updatedSrcStat = await _stat(src);
|
|
78
|
-
await utimesMillis(dest, updatedSrcStat.atime, updatedSrcStat.mtime);
|
|
79
|
-
}
|
|
80
|
-
return chmod(dest, srcStat.mode);
|
|
81
|
-
}
|
|
82
|
-
function fileIsNotWritable(srcMode) {
|
|
83
|
-
return (srcMode & 128) === 0;
|
|
84
|
-
}
|
|
85
|
-
function makeFileWritable(dest, srcMode) {
|
|
86
|
-
return chmod(dest, srcMode | 128);
|
|
87
|
-
}
|
|
88
|
-
async function onDir(srcStat, destStat, src, dest, opts) {
|
|
89
|
-
if (!destStat) {
|
|
90
|
-
await mkdir(dest);
|
|
91
|
-
}
|
|
92
|
-
const items = await readdir(src);
|
|
93
|
-
await Promise.all(
|
|
94
|
-
items.map(async (item) => {
|
|
95
|
-
const srcItem = join(src, item);
|
|
96
|
-
const destItem = join(dest, item);
|
|
97
|
-
const include = await runFilter(srcItem, destItem, opts);
|
|
98
|
-
if (!include) return;
|
|
99
|
-
const { destStat: destStat2 } = await checkPaths(srcItem, destItem, "copy", opts);
|
|
100
|
-
return getStatsAndPerformCopy(destStat2, srcItem, destItem, opts);
|
|
101
|
-
})
|
|
102
|
-
);
|
|
103
|
-
if (!destStat) {
|
|
104
|
-
await chmod(dest, srcStat.mode);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
async function onLink(destStat, src, dest, opts) {
|
|
108
|
-
let resolvedSrc = await readlink(src);
|
|
109
|
-
if (opts.dereference) {
|
|
110
|
-
resolvedSrc = resolve(process.cwd(), resolvedSrc);
|
|
111
|
-
}
|
|
112
|
-
if (!destStat) {
|
|
113
|
-
return symlink(resolvedSrc, dest);
|
|
114
|
-
}
|
|
115
|
-
let resolvedDest = null;
|
|
116
|
-
try {
|
|
117
|
-
resolvedDest = await readlink(dest);
|
|
118
|
-
} catch (e) {
|
|
119
|
-
if (
|
|
120
|
-
// @ts-expect-error TODO: fix ts
|
|
121
|
-
/** @type {NodeJS.ErrnoException} */
|
|
122
|
-
e.code === "EINVAL" || // @ts-expect-error TODO: fix ts
|
|
123
|
-
/** @type {NodeJS.ErrnoException} */
|
|
124
|
-
e.code === "UNKNOWN"
|
|
125
|
-
)
|
|
126
|
-
return symlink(resolvedSrc, dest);
|
|
127
|
-
throw e;
|
|
128
|
-
}
|
|
129
|
-
if (opts.dereference) {
|
|
130
|
-
resolvedDest = resolve(process.cwd(), resolvedDest);
|
|
131
|
-
}
|
|
132
|
-
if (isSrcSubdir(resolvedSrc, resolvedDest)) {
|
|
133
|
-
throw new Error(
|
|
134
|
-
`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
if (isSrcSubdir(resolvedDest, resolvedSrc)) {
|
|
138
|
-
throw new Error(
|
|
139
|
-
`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
await unlink(dest);
|
|
143
|
-
return symlink(resolvedSrc, dest);
|
|
144
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { emptyDir, emptyDirSync } from "fs-extra";
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import { fromPromise as u } from "universalify";
|
|
3
|
-
import { readdir, readdirSync } from "../../fs/index.js";
|
|
4
|
-
import { mkdirs, mkdirsSync } from "../mkdirs/index.js";
|
|
5
|
-
import {
|
|
6
|
-
remove as _remove,
|
|
7
|
-
removeSync
|
|
8
|
-
} from "../remove/index.js";
|
|
9
|
-
export const emptyDir = u(async function emptyDir2(dir) {
|
|
10
|
-
let items;
|
|
11
|
-
try {
|
|
12
|
-
items = await readdir(dir);
|
|
13
|
-
} catch {
|
|
14
|
-
return mkdirs(dir);
|
|
15
|
-
}
|
|
16
|
-
return Promise.all(items.map((item) => _remove(join(dir, item))));
|
|
17
|
-
});
|
|
18
|
-
export function emptyDirSync(dir) {
|
|
19
|
-
let items;
|
|
20
|
-
try {
|
|
21
|
-
items = readdirSync(dir);
|
|
22
|
-
} catch {
|
|
23
|
-
return mkdirsSync(dir);
|
|
24
|
-
}
|
|
25
|
-
for (let item of items) {
|
|
26
|
-
item = join(dir, item);
|
|
27
|
-
removeSync(item);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { dirname } from "node:path";
|
|
2
|
-
import { fromPromise } from "universalify";
|
|
3
|
-
import {
|
|
4
|
-
writeFile,
|
|
5
|
-
stat,
|
|
6
|
-
readdir,
|
|
7
|
-
statSync,
|
|
8
|
-
readdirSync,
|
|
9
|
-
writeFileSync
|
|
10
|
-
} from "../../fs/index.js";
|
|
11
|
-
import { mkdirs, mkdirsSync } from "../mkdirs/index.js";
|
|
12
|
-
async function _createFile(file) {
|
|
13
|
-
let stats;
|
|
14
|
-
try {
|
|
15
|
-
stats = await stat(file);
|
|
16
|
-
} catch {
|
|
17
|
-
}
|
|
18
|
-
if (stats?.isFile()) return;
|
|
19
|
-
const dir = dirname(file);
|
|
20
|
-
let dirStats = null;
|
|
21
|
-
try {
|
|
22
|
-
dirStats = await stat(dir);
|
|
23
|
-
} catch (err) {
|
|
24
|
-
if (err.code === "ENOENT") {
|
|
25
|
-
await mkdirs(dir);
|
|
26
|
-
await writeFile(file, "");
|
|
27
|
-
return;
|
|
28
|
-
} else {
|
|
29
|
-
throw err;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (dirStats.isDirectory()) {
|
|
33
|
-
await writeFile(file, "");
|
|
34
|
-
} else {
|
|
35
|
-
await readdir(dir);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export const createFile = fromPromise(_createFile);
|
|
39
|
-
export function createFileSync(file) {
|
|
40
|
-
let stats;
|
|
41
|
-
try {
|
|
42
|
-
stats = statSync(file);
|
|
43
|
-
} catch {
|
|
44
|
-
}
|
|
45
|
-
if (stats?.isFile()) return;
|
|
46
|
-
const dir = dirname(file);
|
|
47
|
-
try {
|
|
48
|
-
if (!statSync(dir).isDirectory()) {
|
|
49
|
-
readdirSync(dir);
|
|
50
|
-
}
|
|
51
|
-
} catch (err) {
|
|
52
|
-
if (err && err.code === "ENOENT") mkdirsSync(dir);
|
|
53
|
-
else throw err;
|
|
54
|
-
}
|
|
55
|
-
writeFileSync(file, "");
|
|
56
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
createFile as ensureFile,
|
|
3
|
-
createFileSync as ensureFileSync
|
|
4
|
-
} from "./file.js";
|
|
5
|
-
export {
|
|
6
|
-
createLink as ensureLink,
|
|
7
|
-
createLinkSync as ensureLinkSync
|
|
8
|
-
} from "./link.js";
|
|
9
|
-
export {
|
|
10
|
-
createSymlink as ensureSymlink,
|
|
11
|
-
createSymlinkSync as ensureSymlinkSync
|
|
12
|
-
} from "./symlink.js";
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { dirname } from "node:path";
|
|
2
|
-
import { fromPromise } from "universalify";
|
|
3
|
-
import { exists as pathExists } from "../../fs/exists.js";
|
|
4
|
-
import {
|
|
5
|
-
link,
|
|
6
|
-
lstat,
|
|
7
|
-
lstatSync,
|
|
8
|
-
existsSync,
|
|
9
|
-
linkSync
|
|
10
|
-
} from "../../fs/index.js";
|
|
11
|
-
import { mkdirs, mkdirsSync } from "../mkdirs/index.js";
|
|
12
|
-
import { areIdentical } from "../util/stat.js";
|
|
13
|
-
async function _createLink(srcpath, dstpath) {
|
|
14
|
-
let dstStat;
|
|
15
|
-
try {
|
|
16
|
-
dstStat = await lstat(dstpath);
|
|
17
|
-
} catch {
|
|
18
|
-
}
|
|
19
|
-
let srcStat;
|
|
20
|
-
try {
|
|
21
|
-
srcStat = await lstat(srcpath);
|
|
22
|
-
} catch (err) {
|
|
23
|
-
err.message = err.message.replace("lstat", "ensureLink");
|
|
24
|
-
throw err;
|
|
25
|
-
}
|
|
26
|
-
if (dstStat && areIdentical(srcStat, dstStat)) return;
|
|
27
|
-
const dir = dirname(dstpath);
|
|
28
|
-
const dirExists = await pathExists(dir);
|
|
29
|
-
if (!dirExists) {
|
|
30
|
-
await mkdirs(dir);
|
|
31
|
-
}
|
|
32
|
-
await link(srcpath, dstpath);
|
|
33
|
-
}
|
|
34
|
-
export const createLink = fromPromise(_createLink);
|
|
35
|
-
export function createLinkSync(srcpath, dstpath) {
|
|
36
|
-
let dstStat;
|
|
37
|
-
try {
|
|
38
|
-
dstStat = lstatSync(dstpath);
|
|
39
|
-
} catch {
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
const srcStat = lstatSync(srcpath);
|
|
43
|
-
if (dstStat && areIdentical(srcStat, dstStat)) return;
|
|
44
|
-
} catch (err) {
|
|
45
|
-
err.message = err.message.replace("lstat", "ensureLink");
|
|
46
|
-
throw err;
|
|
47
|
-
}
|
|
48
|
-
const dir = dirname(dstpath);
|
|
49
|
-
const dirExists = existsSync(dir);
|
|
50
|
-
if (dirExists) return linkSync(srcpath, dstpath);
|
|
51
|
-
mkdirsSync(dir);
|
|
52
|
-
return linkSync(srcpath, dstpath);
|
|
53
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { isAbsolute, dirname, join, relative } from "node:path";
|
|
2
|
-
import { fromPromise } from "universalify";
|
|
3
|
-
import { exists as pathExists } from "../../fs/exists.js";
|
|
4
|
-
import { lstat, existsSync } from "../../fs/index.js";
|
|
5
|
-
async function _symlinkPaths(srcpath, dstpath) {
|
|
6
|
-
if (isAbsolute(srcpath)) {
|
|
7
|
-
try {
|
|
8
|
-
await lstat(srcpath);
|
|
9
|
-
} catch (err) {
|
|
10
|
-
err.message = err.message.replace("lstat", "ensureSymlink");
|
|
11
|
-
throw err;
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
14
|
-
toCwd: srcpath,
|
|
15
|
-
toDst: srcpath
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
const dstdir = dirname(dstpath);
|
|
19
|
-
const relativeToDst = join(dstdir, srcpath);
|
|
20
|
-
const exists = await pathExists(relativeToDst);
|
|
21
|
-
if (exists) {
|
|
22
|
-
return {
|
|
23
|
-
toCwd: relativeToDst,
|
|
24
|
-
toDst: srcpath
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
await lstat(srcpath);
|
|
29
|
-
} catch (err) {
|
|
30
|
-
err.message = err.message.replace("lstat", "ensureSymlink");
|
|
31
|
-
throw err;
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
toCwd: srcpath,
|
|
35
|
-
toDst: relative(dstdir, srcpath)
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
export const symlinkPaths = fromPromise(_symlinkPaths);
|
|
39
|
-
export function symlinkPathsSync(srcpath, dstpath) {
|
|
40
|
-
if (isAbsolute(srcpath)) {
|
|
41
|
-
const exists2 = existsSync(srcpath);
|
|
42
|
-
if (!exists2) throw new Error("absolute srcpath does not exist");
|
|
43
|
-
return {
|
|
44
|
-
toCwd: srcpath,
|
|
45
|
-
toDst: srcpath
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
const dstdir = dirname(dstpath);
|
|
49
|
-
const relativeToDst = join(dstdir, srcpath);
|
|
50
|
-
const exists = existsSync(relativeToDst);
|
|
51
|
-
if (exists) {
|
|
52
|
-
return {
|
|
53
|
-
toCwd: relativeToDst,
|
|
54
|
-
toDst: srcpath
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const srcExists = existsSync(srcpath);
|
|
58
|
-
if (!srcExists) throw new Error("relative srcpath does not exist");
|
|
59
|
-
return {
|
|
60
|
-
toCwd: srcpath,
|
|
61
|
-
toDst: relative(dstdir, srcpath)
|
|
62
|
-
};
|
|
63
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { fromPromise } from "universalify";
|
|
2
|
-
import { lstat, lstatSync } from "../../fs/index.js";
|
|
3
|
-
async function _symlinkType(srcpath, type) {
|
|
4
|
-
if (type) return type;
|
|
5
|
-
let stats;
|
|
6
|
-
try {
|
|
7
|
-
stats = await lstat(srcpath);
|
|
8
|
-
} catch {
|
|
9
|
-
return "file";
|
|
10
|
-
}
|
|
11
|
-
return stats?.isDirectory() ? "dir" : "file";
|
|
12
|
-
}
|
|
13
|
-
export const symlinkType = fromPromise(_symlinkType);
|
|
14
|
-
export function symlinkTypeSync(srcpath, type) {
|
|
15
|
-
if (type) return type;
|
|
16
|
-
let stats;
|
|
17
|
-
try {
|
|
18
|
-
stats = lstatSync(srcpath);
|
|
19
|
-
} catch {
|
|
20
|
-
return "file";
|
|
21
|
-
}
|
|
22
|
-
return stats?.isDirectory() ? "dir" : "file";
|
|
23
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { dirname } from "node:path";
|
|
2
|
-
import { fromPromise } from "universalify";
|
|
3
|
-
import { exists as pathExists } from "../../fs/exists.js";
|
|
4
|
-
import {
|
|
5
|
-
lstat,
|
|
6
|
-
stat,
|
|
7
|
-
symlink,
|
|
8
|
-
lstatSync,
|
|
9
|
-
statSync,
|
|
10
|
-
existsSync,
|
|
11
|
-
symlinkSync
|
|
12
|
-
} from "../../fs/index.js";
|
|
13
|
-
import { mkdirs, mkdirsSync } from "../mkdirs/index.js";
|
|
14
|
-
import { areIdentical } from "../util/stat.js";
|
|
15
|
-
import { symlinkPaths, symlinkPathsSync } from "./symlink-paths.js";
|
|
16
|
-
import { symlinkType, symlinkTypeSync } from "./symlink-type.js";
|
|
17
|
-
async function _createSymlink(srcpath, dstpath, type) {
|
|
18
|
-
let stats;
|
|
19
|
-
try {
|
|
20
|
-
stats = await lstat(dstpath);
|
|
21
|
-
} catch {
|
|
22
|
-
}
|
|
23
|
-
if (stats?.isSymbolicLink()) {
|
|
24
|
-
const [srcStat, dstStat] = await Promise.all([
|
|
25
|
-
stat(srcpath),
|
|
26
|
-
stat(dstpath)
|
|
27
|
-
]);
|
|
28
|
-
if (areIdentical(srcStat, dstStat)) return;
|
|
29
|
-
}
|
|
30
|
-
const relative = await symlinkPaths(srcpath, dstpath);
|
|
31
|
-
srcpath = relative.toDst;
|
|
32
|
-
const toType = await symlinkType(relative.toCwd, type);
|
|
33
|
-
const dir = dirname(dstpath);
|
|
34
|
-
if (!await pathExists(dir)) {
|
|
35
|
-
await mkdirs(dir);
|
|
36
|
-
}
|
|
37
|
-
return symlink(srcpath, dstpath, toType);
|
|
38
|
-
}
|
|
39
|
-
export const createSymlink = fromPromise(_createSymlink);
|
|
40
|
-
export function createSymlinkSync(srcpath, dstpath, type) {
|
|
41
|
-
let stats;
|
|
42
|
-
try {
|
|
43
|
-
stats = lstatSync(dstpath);
|
|
44
|
-
} catch {
|
|
45
|
-
}
|
|
46
|
-
if (stats?.isSymbolicLink()) {
|
|
47
|
-
const srcStat = statSync(srcpath);
|
|
48
|
-
const dstStat = statSync(dstpath);
|
|
49
|
-
if (areIdentical(srcStat, dstStat)) return;
|
|
50
|
-
}
|
|
51
|
-
const relative = symlinkPathsSync(srcpath, dstpath);
|
|
52
|
-
srcpath = relative.toDst;
|
|
53
|
-
type = symlinkTypeSync(relative.toCwd, type);
|
|
54
|
-
const dir = dirname(dstpath);
|
|
55
|
-
const exists = existsSync(dir);
|
|
56
|
-
if (exists) return symlinkSync(srcpath, dstpath, type);
|
|
57
|
-
mkdirsSync(dir);
|
|
58
|
-
return symlinkSync(srcpath, dstpath, type);
|
|
59
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../fs/index.js";
|
package/bin/impl/lib/fs/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../fs/index.js";
|
package/bin/impl/lib/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export * from "../fs/index.js";
|
|
2
|
-
export * from "./copy/index.js";
|
|
3
|
-
export * from "./empty/index.js";
|
|
4
|
-
export * from "./ensure/index.js";
|
|
5
|
-
export * from "../json.js";
|
|
6
|
-
export * from "./mkdirs/index.js";
|
|
7
|
-
export * from "./move/index.js";
|
|
8
|
-
export * from "./output-file/index.js";
|
|
9
|
-
export * from "./remove/index.js";
|
|
10
|
-
export { exists } from "../fs/exists.js";
|
|
11
|
-
export { existsSync as pathExistsSync } from "../fs/index.js";
|
|
12
|
-
export { exists as pathExists } from "../fs/exists.js";
|
|
13
|
-
export { readJson as readJSON, readJsonSync as readJSONSync, writeJson as writeJSON, writeJsonSync as writeJSONSync, outputJson as outputJSON, outputJsonSync as outputJSONSync, } from "../json.js";
|
|
14
|
-
export { mkdirs as mkdirp, mkdirsSync as mkdirpSync, mkdirs as ensureDir, mkdirsSync as ensureDirSync, } from "./mkdirs/index.js";
|
|
15
|
-
export { ensureFile as createFile, ensureFileSync as createFileSync, ensureLink as createLink, ensureLinkSync as createLinkSync, ensureSymlink as createSymlink, ensureSymlinkSync as createSymlinkSync, } from "./ensure/index.js";
|