@visulima/fs 3.1.7 → 3.1.8
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/CHANGELOG.md +11 -0
- package/README.md +153 -153
- package/dist/eol.cjs +3 -28
- package/dist/eol.mjs +3 -20
- package/dist/error.cjs +1 -21
- package/dist/error.mjs +1 -7
- package/dist/index.cjs +1 -80
- package/dist/index.mjs +1 -31
- package/dist/packem_shared/AlreadyExistsError-CEu6_Tjb.mjs +1 -0
- package/dist/packem_shared/AlreadyExistsError-GC2XUgzJ.cjs +1 -0
- package/dist/packem_shared/DirectoryError-aGtmQVph.cjs +1 -0
- package/dist/packem_shared/DirectoryError-ddlbUV8C.mjs +1 -0
- package/dist/packem_shared/F_OK-7T91O6Oz.cjs +1 -0
- package/dist/packem_shared/F_OK-B71i3mUa.mjs +1 -0
- package/dist/packem_shared/JSONError-CVkb3xZ3.mjs +4 -0
- package/dist/packem_shared/JSONError-CWuiGmNc.cjs +4 -0
- package/dist/packem_shared/NotEmptyError-BWGfec5K.cjs +1 -0
- package/dist/packem_shared/NotEmptyError-DMh1o7UL.mjs +1 -0
- package/dist/packem_shared/NotFoundError-BPiW0icm.mjs +1 -0
- package/dist/packem_shared/NotFoundError-Diij7oqe.cjs +1 -0
- package/dist/packem_shared/PermissionError-B1Emi5a9.mjs +1 -0
- package/dist/packem_shared/PermissionError-Ck1Es7al.cjs +1 -0
- package/dist/packem_shared/WalkError-BsngoIKJ.mjs +1 -0
- package/dist/packem_shared/WalkError-gKgp0TWD.cjs +1 -0
- package/dist/packem_shared/assertValidFileContents-BZFnXa7K.mjs +1 -0
- package/dist/packem_shared/assertValidFileContents-CrbDz09d.cjs +1 -0
- package/dist/packem_shared/assertValidFileOrDirectoryPath-DgPIPmZT.mjs +1 -0
- package/dist/packem_shared/assertValidFileOrDirectoryPath-HOUs73Jk.cjs +1 -0
- package/dist/packem_shared/collect-Bl2Oc1qs.cjs +1 -0
- package/dist/packem_shared/collect-CyYPQFMs.mjs +1 -0
- package/dist/packem_shared/collectSync-BHjyXWq4.cjs +1 -0
- package/dist/packem_shared/collectSync-CD9cXw2g.mjs +1 -0
- package/dist/packem_shared/emptyDir-BdjO-6Gu.mjs +1 -0
- package/dist/packem_shared/emptyDir-DGRw4yE9.cjs +1 -0
- package/dist/packem_shared/emptyDirSync-C1vsMEp-.mjs +1 -0
- package/dist/packem_shared/emptyDirSync-DzjDZxOx.cjs +1 -0
- package/dist/packem_shared/ensureDir-BuIFF_6B.mjs +1 -0
- package/dist/packem_shared/ensureDir-DtQzyA70.cjs +1 -0
- package/dist/packem_shared/ensureDirSync-BuPHxdP4.mjs +1 -0
- package/dist/packem_shared/ensureDirSync-C8hIoS3o.cjs +1 -0
- package/dist/packem_shared/ensureFile-DcAODM6a.mjs +1 -0
- package/dist/packem_shared/ensureFile-wR8zBfXh.cjs +1 -0
- package/dist/packem_shared/ensureFileSync-BI1fIdNf.cjs +1 -0
- package/dist/packem_shared/ensureFileSync-CzPN6ucX.mjs +1 -0
- package/dist/packem_shared/ensureLink-BaZLXxgx.mjs +1 -0
- package/dist/packem_shared/ensureLink-DCPuU0Za.cjs +1 -0
- package/dist/packem_shared/ensureLinkSync-9C2JL-Sl.mjs +1 -0
- package/dist/packem_shared/ensureLinkSync-CuRZmQlV.cjs +1 -0
- package/dist/packem_shared/ensureSymlink-BH6wbylb.mjs +1 -0
- package/dist/packem_shared/ensureSymlink-J83jhdfA.cjs +1 -0
- package/dist/packem_shared/ensureSymlinkSync-CZSPodAm.mjs +1 -0
- package/dist/packem_shared/ensureSymlinkSync-VNtMTaV8.cjs +1 -0
- package/dist/packem_shared/findUp-C5aWsLuD.cjs +1 -0
- package/dist/packem_shared/findUp-CMGMYNty.mjs +1 -0
- package/dist/packem_shared/findUpSync-QP_ZEsJN.mjs +1 -0
- package/dist/packem_shared/findUpSync-U1lTgv4y.cjs +1 -0
- package/dist/packem_shared/get-file-info-type-CaWGXRjY.mjs +1 -0
- package/dist/packem_shared/get-file-info-type-DDbpRlDl.cjs +1 -0
- package/dist/packem_shared/index-BSjF-5vj.mjs +1 -0
- package/dist/packem_shared/index-DPla58ce.cjs +1 -0
- package/dist/packem_shared/is-stats-identical-Bti7K05l.cjs +1 -0
- package/dist/packem_shared/is-stats-identical-CohsLtWy.mjs +1 -0
- package/dist/packem_shared/isAccessible-BQZd1_xn.cjs +1 -0
- package/dist/packem_shared/isAccessible-CL4eE5VL.mjs +1 -0
- package/dist/packem_shared/isAccessibleSync-BP5N8k_-.cjs +1 -0
- package/dist/packem_shared/isAccessibleSync-_HU_ppdG.mjs +1 -0
- package/dist/packem_shared/move--o4NZLpD.mjs +1 -0
- package/dist/packem_shared/move-DwG6APiG.cjs +1 -0
- package/dist/packem_shared/parseJson-B_GwHpKj.cjs +6 -0
- package/dist/packem_shared/parseJson-Bqic0nN8.mjs +6 -0
- package/dist/packem_shared/readFile-BvefDyr_.cjs +1 -0
- package/dist/packem_shared/readFile-Cix_ijtX.mjs +1 -0
- package/dist/packem_shared/readFileSync-B0O-8BH0.mjs +1 -0
- package/dist/packem_shared/readFileSync-Ct8Ql4Vs.cjs +1 -0
- package/dist/packem_shared/readJson-BLvd2Bsj.mjs +1 -0
- package/dist/packem_shared/readJson-cP5ArpPg.cjs +1 -0
- package/dist/packem_shared/readJsonSync-B6h6A3Un.cjs +1 -0
- package/dist/packem_shared/readJsonSync-Br5dHGAI.mjs +1 -0
- package/dist/packem_shared/readYaml-BOYTR5D1.mjs +1 -0
- package/dist/packem_shared/readYaml-BzMFDsYe.cjs +1 -0
- package/dist/packem_shared/readYamlSync-BbK0khJu.cjs +1 -0
- package/dist/packem_shared/readYamlSync-md9g88k7.mjs +1 -0
- package/dist/packem_shared/remove-CtnFqEpd.mjs +1 -0
- package/dist/packem_shared/remove-DPCf2Qdb.cjs +1 -0
- package/dist/packem_shared/removeSync-Cyriz7r8.cjs +1 -0
- package/dist/packem_shared/removeSync-DI-IjqVp.mjs +1 -0
- package/dist/packem_shared/resolve-symlink-target-BofZSDIc.mjs +1 -0
- package/dist/packem_shared/resolve-symlink-target-zilkQ_AU.cjs +1 -0
- package/dist/packem_shared/stripJsonComments-Cp5SNAB7.mjs +1 -0
- package/dist/packem_shared/stripJsonComments-CvZSDnYT.cjs +1 -0
- package/dist/packem_shared/to-uint-8-array-2-3EvGd7.cjs +1 -0
- package/dist/packem_shared/to-uint-8-array-DwgaTasY.mjs +1 -0
- package/dist/packem_shared/walk-BZTXbT87.mjs +1 -0
- package/dist/packem_shared/walk-DyN_HVFW.cjs +1 -0
- package/dist/packem_shared/walk-include-C9pVST87.mjs +1 -0
- package/dist/packem_shared/walk-include-DkK-WJl4.cjs +1 -0
- package/dist/packem_shared/walkSync-BHlEzV_m.mjs +1 -0
- package/dist/packem_shared/walkSync-Bqi7L2yG.cjs +1 -0
- package/dist/packem_shared/writeFile-COOAkvOE.mjs +1 -0
- package/dist/packem_shared/writeFile-CjgQEfur.cjs +1 -0
- package/dist/packem_shared/writeFileSync-CQuRHo9n.cjs +1 -0
- package/dist/packem_shared/writeFileSync-rhu-y_zx.mjs +1 -0
- package/dist/packem_shared/writeJson-BYT4WInm.mjs +4 -0
- package/dist/packem_shared/writeJson-CJIciZ_Q.cjs +4 -0
- package/dist/packem_shared/writeJsonSync-BIsrhRbV.cjs +4 -0
- package/dist/packem_shared/writeJsonSync-CLlXOFDm.mjs +4 -0
- package/dist/packem_shared/writeYaml-CjzVd0K-.mjs +1 -0
- package/dist/packem_shared/writeYaml-VmX1VKhN.cjs +1 -0
- package/dist/packem_shared/writeYamlSync-D9A9Ixe1.mjs +1 -0
- package/dist/packem_shared/writeYamlSync-DYsM6XBi.cjs +1 -0
- package/dist/size.cjs +1 -118
- package/dist/size.mjs +1 -109
- package/dist/utils.cjs +1 -19
- package/dist/utils.mjs +1 -6
- package/dist/yaml.cjs +1 -15
- package/dist/yaml.mjs +1 -4
- package/package.json +1 -1
- package/dist/packem_shared/AlreadyExistsError-DpxtwQot.cjs +0 -34
- package/dist/packem_shared/AlreadyExistsError-GK7J9fVA.mjs +0 -32
- package/dist/packem_shared/DirectoryError-D8FHcAqu.cjs +0 -34
- package/dist/packem_shared/DirectoryError-DByTWE7t.mjs +0 -32
- package/dist/packem_shared/F_OK-CWSqQIdF.cjs +0 -17
- package/dist/packem_shared/F_OK-JER1LjUr.mjs +0 -8
- package/dist/packem_shared/JSONError-5-wHnrxX.cjs +0 -34
- package/dist/packem_shared/JSONError-CaKt7MhC.mjs +0 -32
- package/dist/packem_shared/NotEmptyError-BCS_5pPt.cjs +0 -34
- package/dist/packem_shared/NotEmptyError-DCXooh5l.mjs +0 -32
- package/dist/packem_shared/NotFoundError-B_1nPl3K.cjs +0 -34
- package/dist/packem_shared/NotFoundError-CUdcC61I.mjs +0 -32
- package/dist/packem_shared/PermissionError-CqGMI9qC.mjs +0 -32
- package/dist/packem_shared/PermissionError-QFMKgk2l.cjs +0 -34
- package/dist/packem_shared/WalkError-B4-yr8Kk.cjs +0 -31
- package/dist/packem_shared/WalkError-DvEBTTaj.mjs +0 -29
- package/dist/packem_shared/assertValidFileContents-CRVvyM6b.cjs +0 -11
- package/dist/packem_shared/assertValidFileContents-Ox-ScfeK.mjs +0 -9
- package/dist/packem_shared/assertValidFileOrDirectoryPath-BMbgA-eI.cjs +0 -11
- package/dist/packem_shared/assertValidFileOrDirectoryPath-BWWgA1wj.mjs +0 -9
- package/dist/packem_shared/collect-3Paj1Vqw.mjs +0 -16
- package/dist/packem_shared/collect-DnfQeSOL.cjs +0 -18
- package/dist/packem_shared/collectSync-D4vym4QD.cjs +0 -18
- package/dist/packem_shared/collectSync-DwJLL8SD.mjs +0 -16
- package/dist/packem_shared/emptyDir-DcCfiNcf.cjs +0 -22
- package/dist/packem_shared/emptyDir-Dw5xSBox.mjs +0 -20
- package/dist/packem_shared/emptyDirSync-BWA4n6TB.cjs +0 -21
- package/dist/packem_shared/emptyDirSync-DMAaCiC_.mjs +0 -19
- package/dist/packem_shared/ensureDir-BOfUZlxG.cjs +0 -35
- package/dist/packem_shared/ensureDir-BnA_fY1A.mjs +0 -33
- package/dist/packem_shared/ensureDirSync-DHmWi3CF.cjs +0 -35
- package/dist/packem_shared/ensureDirSync-Dm4az3YF.mjs +0 -33
- package/dist/packem_shared/ensureFile-BKrJMHfr.mjs +0 -27
- package/dist/packem_shared/ensureFile-CeGryLJI.cjs +0 -29
- package/dist/packem_shared/ensureFileSync-B7THM1sN.cjs +0 -29
- package/dist/packem_shared/ensureFileSync-BnhFBXaR.mjs +0 -27
- package/dist/packem_shared/ensureLink-ChsWDTK5.mjs +0 -34
- package/dist/packem_shared/ensureLink-CrxLNmHE.cjs +0 -36
- package/dist/packem_shared/ensureLinkSync-CG-DTUoV.mjs +0 -34
- package/dist/packem_shared/ensureLinkSync-D8uMqLh4.cjs +0 -36
- package/dist/packem_shared/ensureSymlink-BwJ_QhzJ.mjs +0 -52
- package/dist/packem_shared/ensureSymlink-D_ieOVYa.cjs +0 -54
- package/dist/packem_shared/ensureSymlinkSync-BamG29QK.mjs +0 -56
- package/dist/packem_shared/ensureSymlinkSync-DTMvUYZD.cjs +0 -58
- package/dist/packem_shared/findUp-D5W-MTpT.mjs +0 -63
- package/dist/packem_shared/findUp-DVIYN2wV.cjs +0 -65
- package/dist/packem_shared/findUpSync-BOiVyUOx.cjs +0 -65
- package/dist/packem_shared/findUpSync-DL3NPCYg.mjs +0 -63
- package/dist/packem_shared/get-file-info-type-BlryFnpp.cjs +0 -18
- package/dist/packem_shared/get-file-info-type-ButUVD6d.mjs +0 -16
- package/dist/packem_shared/index-BVZL6YMm.cjs +0 -110
- package/dist/packem_shared/index-r9Pk9gBe.mjs +0 -108
- package/dist/packem_shared/is-stats-identical-BfdEfO6i.cjs +0 -7
- package/dist/packem_shared/is-stats-identical-ByTYZ2Aw.mjs +0 -5
- package/dist/packem_shared/isAccessible-Bonsm1Ez.mjs +0 -20
- package/dist/packem_shared/isAccessible-ZNVGsSb7.cjs +0 -22
- package/dist/packem_shared/isAccessibleSync-3gnUWUwX.mjs +0 -20
- package/dist/packem_shared/isAccessibleSync-VWjQa-US.cjs +0 -22
- package/dist/packem_shared/move-DgF7Ul9L.mjs +0 -114
- package/dist/packem_shared/move-Dh925GL9.cjs +0 -121
- package/dist/packem_shared/parseJson-BA7Xrggq.mjs +0 -248
- package/dist/packem_shared/parseJson-LgPGI5ic.cjs +0 -250
- package/dist/packem_shared/readFile-b7UBVv17.mjs +0 -46
- package/dist/packem_shared/readFile-iFUhZHnh.cjs +0 -48
- package/dist/packem_shared/readFileSync-B3NTOR-W.cjs +0 -33
- package/dist/packem_shared/readFileSync-CkEJBqZB.mjs +0 -31
- package/dist/packem_shared/readJson-CEBHyuYq.cjs +0 -27
- package/dist/packem_shared/readJson-Ce9b06cu.mjs +0 -25
- package/dist/packem_shared/readJsonSync-B22hej0y.cjs +0 -27
- package/dist/packem_shared/readJsonSync-CkUI9_z5.mjs +0 -25
- package/dist/packem_shared/readYaml-C5MSs2GE.mjs +0 -13
- package/dist/packem_shared/readYaml-sR4bqUel.cjs +0 -15
- package/dist/packem_shared/readYamlSync-C3oOzxiN.cjs +0 -15
- package/dist/packem_shared/readYamlSync-CPjA-DLv.mjs +0 -13
- package/dist/packem_shared/remove-B2nxUObP.mjs +0 -18
- package/dist/packem_shared/remove-BpDiVPns.cjs +0 -20
- package/dist/packem_shared/removeSync-BosXW624.cjs +0 -20
- package/dist/packem_shared/removeSync-C87yepDI.mjs +0 -18
- package/dist/packem_shared/resolve-symlink-target-BbpEHdU2.mjs +0 -18
- package/dist/packem_shared/resolve-symlink-target-DImIddt6.cjs +0 -20
- package/dist/packem_shared/stripJsonComments-B66nRaTZ.mjs +0 -21
- package/dist/packem_shared/stripJsonComments-eDrcJvBT.cjs +0 -23
- package/dist/packem_shared/to-uint-8-array-B4CjMOD3.mjs +0 -21
- package/dist/packem_shared/to-uint-8-array-BaTEyX3D.cjs +0 -23
- package/dist/packem_shared/walk-CI3ygmrw.cjs +0 -100
- package/dist/packem_shared/walk-D7YA43g8.mjs +0 -98
- package/dist/packem_shared/walk-include-CMUSRa86.mjs +0 -20
- package/dist/packem_shared/walk-include-yUdRrF16.cjs +0 -23
- package/dist/packem_shared/walkSync-DLTsnwuJ.mjs +0 -103
- package/dist/packem_shared/walkSync-oXkmn9ZA.cjs +0 -105
- package/dist/packem_shared/writeFile-BZ4JBQxc.mjs +0 -58
- package/dist/packem_shared/writeFile-DgCFRCe5.cjs +0 -60
- package/dist/packem_shared/writeFileSync-Ctw5pNQH.mjs +0 -58
- package/dist/packem_shared/writeFileSync-DzXhx1pF.cjs +0 -60
- package/dist/packem_shared/writeJson-Bh4sU1Ly.cjs +0 -33
- package/dist/packem_shared/writeJson-axO_14yL.mjs +0 -31
- package/dist/packem_shared/writeJsonSync-CzngmuKb.mjs +0 -31
- package/dist/packem_shared/writeJsonSync-HFdHjunl.cjs +0 -33
- package/dist/packem_shared/writeYaml-3XQT2qtb.cjs +0 -29
- package/dist/packem_shared/writeYaml-BSFEuWp2.mjs +0 -27
- package/dist/packem_shared/writeYamlSync-B6VcXXIb.mjs +0 -27
- package/dist/packem_shared/writeYamlSync-BZR3If9v.cjs +0 -29
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { readdir, realpath, stat } from 'node:fs/promises';
|
|
2
|
-
import { resolve, join, normalize, basename } from '@visulima/path';
|
|
3
|
-
import { toPath } from '@visulima/path/utils';
|
|
4
|
-
import WalkError from './WalkError-DvEBTTaj.mjs';
|
|
5
|
-
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-BWWgA1wj.mjs';
|
|
6
|
-
import { g as globToRegExp, w as walkInclude } from './walk-include-CMUSRa86.mjs';
|
|
7
|
-
|
|
8
|
-
var __defProp = Object.defineProperty;
|
|
9
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
-
const _createWalkEntry = /* @__PURE__ */ __name(async (path) => {
|
|
11
|
-
const normalizePath = normalize(path);
|
|
12
|
-
const name = basename(normalizePath);
|
|
13
|
-
const info = await stat(normalizePath);
|
|
14
|
-
return {
|
|
15
|
-
isDirectory: /* @__PURE__ */ __name(() => info.isDirectory(), "isDirectory"),
|
|
16
|
-
isFile: /* @__PURE__ */ __name(() => info.isFile(), "isFile"),
|
|
17
|
-
isSymbolicLink: /* @__PURE__ */ __name(() => info.isSymbolicLink(), "isSymbolicLink"),
|
|
18
|
-
name,
|
|
19
|
-
path: normalizePath
|
|
20
|
-
};
|
|
21
|
-
}, "_createWalkEntry");
|
|
22
|
-
async function* walk(directory, {
|
|
23
|
-
extensions,
|
|
24
|
-
followSymlinks = false,
|
|
25
|
-
includeDirs: includeDirectories = true,
|
|
26
|
-
includeFiles = true,
|
|
27
|
-
includeSymlinks = true,
|
|
28
|
-
match,
|
|
29
|
-
maxDepth = Number.POSITIVE_INFINITY,
|
|
30
|
-
skip
|
|
31
|
-
} = {}) {
|
|
32
|
-
assertValidFileOrDirectoryPath(directory);
|
|
33
|
-
if (maxDepth < 0) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const mappedMatch = match ? match.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : void 0;
|
|
37
|
-
const mappedSkip = skip ? skip.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : void 0;
|
|
38
|
-
directory = resolve(toPath(directory));
|
|
39
|
-
if (includeDirectories && walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
|
|
40
|
-
yield await _createWalkEntry(directory);
|
|
41
|
-
}
|
|
42
|
-
if (maxDepth < 1 || !walkInclude(directory, void 0, void 0, mappedSkip)) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
for await (const entry of await readdir(directory, {
|
|
47
|
-
withFileTypes: true
|
|
48
|
-
})) {
|
|
49
|
-
let path = join(directory, entry.name);
|
|
50
|
-
if (entry.isSymbolicLink()) {
|
|
51
|
-
if (followSymlinks) {
|
|
52
|
-
path = await realpath(path);
|
|
53
|
-
} else if (includeSymlinks && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
54
|
-
yield {
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
56
|
-
isDirectory: entry.isDirectory,
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
58
|
-
isFile: entry.isFile,
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
60
|
-
isSymbolicLink: entry.isSymbolicLink,
|
|
61
|
-
name: entry.name,
|
|
62
|
-
path
|
|
63
|
-
};
|
|
64
|
-
} else {
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (entry.isSymbolicLink() || entry.isDirectory()) {
|
|
69
|
-
yield* walk(path, {
|
|
70
|
-
extensions,
|
|
71
|
-
followSymlinks,
|
|
72
|
-
includeDirs: includeDirectories,
|
|
73
|
-
includeFiles,
|
|
74
|
-
includeSymlinks,
|
|
75
|
-
match: mappedMatch,
|
|
76
|
-
maxDepth: maxDepth - 1,
|
|
77
|
-
skip: mappedSkip
|
|
78
|
-
});
|
|
79
|
-
} else if (entry.isFile() && includeFiles && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
80
|
-
yield {
|
|
81
|
-
isDirectory: /* @__PURE__ */ __name(() => entry.isDirectory(), "isDirectory"),
|
|
82
|
-
isFile: /* @__PURE__ */ __name(() => entry.isFile(), "isFile"),
|
|
83
|
-
isSymbolicLink: /* @__PURE__ */ __name(() => entry.isSymbolicLink(), "isSymbolicLink"),
|
|
84
|
-
name: entry.name,
|
|
85
|
-
path
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} catch (error) {
|
|
90
|
-
if (error instanceof WalkError) {
|
|
91
|
-
throw error;
|
|
92
|
-
}
|
|
93
|
-
throw new WalkError(error, directory);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
__name(walk, "walk");
|
|
97
|
-
|
|
98
|
-
export { walk as default };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
var __defProp$1 = Object.defineProperty;
|
|
2
|
-
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
3
|
-
const globToRegExp = /* @__PURE__ */ __name$1((glob) => {
|
|
4
|
-
const reString = glob.replace(/\.\*/g, ".([^/]*)").replace(/\*\*/g, "(.*)").replace(/(?<!\.)\*(?!\*)/g, "([^/]*)").replace(/\?/g, "[^/]").replace(/\.(?!\*)/g, "\\.").replace(/\{/g, "(").replace(/\}/g, ")").replace(/,/g, "|").replace(/\[!(.*?)\]/g, "[^$1]");
|
|
5
|
-
return new RegExp(`^${reString}$`);
|
|
6
|
-
}, "globToRegExp");
|
|
7
|
-
|
|
8
|
-
var __defProp = Object.defineProperty;
|
|
9
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
-
const walkInclude = /* @__PURE__ */ __name((path, extensions, match, skip) => {
|
|
11
|
-
if (Array.isArray(extensions) && extensions.length > 0 && !extensions.some((extension) => path.endsWith(extension))) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
if (match && !match.some((pattern) => pattern.test(path))) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
return !skip?.some((pattern) => pattern.test(path));
|
|
18
|
-
}, "walkInclude");
|
|
19
|
-
|
|
20
|
-
export { globToRegExp as g, walkInclude as w };
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var __defProp$1 = Object.defineProperty;
|
|
4
|
-
var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
|
|
5
|
-
const globToRegExp = /* @__PURE__ */ __name$1((glob) => {
|
|
6
|
-
const reString = glob.replace(/\.\*/g, ".([^/]*)").replace(/\*\*/g, "(.*)").replace(/(?<!\.)\*(?!\*)/g, "([^/]*)").replace(/\?/g, "[^/]").replace(/\.(?!\*)/g, "\\.").replace(/\{/g, "(").replace(/\}/g, ")").replace(/,/g, "|").replace(/\[!(.*?)\]/g, "[^$1]");
|
|
7
|
-
return new RegExp(`^${reString}$`);
|
|
8
|
-
}, "globToRegExp");
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
-
const walkInclude = /* @__PURE__ */ __name((path, extensions, match, skip) => {
|
|
13
|
-
if (Array.isArray(extensions) && extensions.length > 0 && !extensions.some((extension) => path.endsWith(extension))) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
if (match && !match.some((pattern) => pattern.test(path))) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return !skip?.some((pattern) => pattern.test(path));
|
|
20
|
-
}, "walkInclude");
|
|
21
|
-
|
|
22
|
-
exports.globToRegExp = globToRegExp;
|
|
23
|
-
exports.walkInclude = walkInclude;
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { readdirSync, realpathSync, statSync } from 'node:fs';
|
|
2
|
-
import { resolve, join, normalize, basename } from '@visulima/path';
|
|
3
|
-
import { toPath } from '@visulima/path/utils';
|
|
4
|
-
import WalkError from './WalkError-DvEBTTaj.mjs';
|
|
5
|
-
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-BWWgA1wj.mjs';
|
|
6
|
-
import { g as globToRegExp, w as walkInclude } from './walk-include-CMUSRa86.mjs';
|
|
7
|
-
|
|
8
|
-
var __defProp = Object.defineProperty;
|
|
9
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
-
const _createWalkEntry = /* @__PURE__ */ __name((path) => {
|
|
11
|
-
const normalizePath = normalize(path);
|
|
12
|
-
const info = statSync(normalizePath);
|
|
13
|
-
return {
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
15
|
-
isDirectory: info.isDirectory,
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
17
|
-
isFile: info.isFile,
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
19
|
-
isSymbolicLink: info.isSymbolicLink,
|
|
20
|
-
name: basename(normalizePath),
|
|
21
|
-
path: normalizePath
|
|
22
|
-
};
|
|
23
|
-
}, "_createWalkEntry");
|
|
24
|
-
function* walkSync(directory, {
|
|
25
|
-
extensions,
|
|
26
|
-
followSymlinks = false,
|
|
27
|
-
includeDirs: includeDirectories = true,
|
|
28
|
-
includeFiles = true,
|
|
29
|
-
includeSymlinks = true,
|
|
30
|
-
match,
|
|
31
|
-
maxDepth = Number.POSITIVE_INFINITY,
|
|
32
|
-
skip
|
|
33
|
-
} = {}) {
|
|
34
|
-
assertValidFileOrDirectoryPath(directory);
|
|
35
|
-
if (maxDepth < 0) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const mappedMatch = match ? match.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : void 0;
|
|
39
|
-
const mappedSkip = skip ? skip.map((pattern) => typeof pattern === "string" ? globToRegExp(pattern) : pattern) : void 0;
|
|
40
|
-
directory = resolve(toPath(directory));
|
|
41
|
-
if (includeDirectories && walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
|
|
42
|
-
yield _createWalkEntry(directory);
|
|
43
|
-
}
|
|
44
|
-
if (maxDepth < 1 || !walkInclude(directory, void 0, void 0, mappedSkip)) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
try {
|
|
48
|
-
for (const entry of readdirSync(directory, {
|
|
49
|
-
withFileTypes: true
|
|
50
|
-
})) {
|
|
51
|
-
let path = join(directory, entry.name);
|
|
52
|
-
if (entry.isSymbolicLink()) {
|
|
53
|
-
if (followSymlinks) {
|
|
54
|
-
path = realpathSync(path);
|
|
55
|
-
} else if (includeSymlinks && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
56
|
-
yield {
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
58
|
-
isDirectory: entry.isDirectory,
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
60
|
-
isFile: entry.isFile,
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
62
|
-
isSymbolicLink: entry.isSymbolicLink,
|
|
63
|
-
name: entry.name,
|
|
64
|
-
path: normalize(path)
|
|
65
|
-
};
|
|
66
|
-
} else {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (entry.isSymbolicLink() || entry.isDirectory()) {
|
|
71
|
-
yield* walkSync(path, {
|
|
72
|
-
extensions,
|
|
73
|
-
followSymlinks,
|
|
74
|
-
includeDirs: includeDirectories,
|
|
75
|
-
includeFiles,
|
|
76
|
-
includeSymlinks,
|
|
77
|
-
match: mappedMatch,
|
|
78
|
-
maxDepth: maxDepth - 1,
|
|
79
|
-
skip: mappedSkip
|
|
80
|
-
});
|
|
81
|
-
} else if (entry.isFile() && includeFiles && walkInclude(path, extensions, mappedMatch, mappedSkip)) {
|
|
82
|
-
yield {
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
84
|
-
isDirectory: entry.isDirectory,
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
86
|
-
isFile: entry.isFile,
|
|
87
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
88
|
-
isSymbolicLink: entry.isSymbolicLink,
|
|
89
|
-
name: entry.name,
|
|
90
|
-
path: normalize(path)
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
} catch (error) {
|
|
95
|
-
if (error instanceof WalkError) {
|
|
96
|
-
throw error;
|
|
97
|
-
}
|
|
98
|
-
throw new WalkError(error, directory);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
__name(walkSync, "walkSync");
|
|
102
|
-
|
|
103
|
-
export { walkSync as default };
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const node_fs = require('node:fs');
|
|
4
|
-
const path = require('@visulima/path');
|
|
5
|
-
const utils = require('@visulima/path/utils');
|
|
6
|
-
const WalkError = require('./WalkError-B4-yr8Kk.cjs');
|
|
7
|
-
const assertValidFileOrDirectoryPath = require('./assertValidFileOrDirectoryPath-BMbgA-eI.cjs');
|
|
8
|
-
const walkInclude = require('./walk-include-yUdRrF16.cjs');
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
-
const _createWalkEntry = /* @__PURE__ */ __name((path$1) => {
|
|
13
|
-
const normalizePath = path.normalize(path$1);
|
|
14
|
-
const info = node_fs.statSync(normalizePath);
|
|
15
|
-
return {
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
17
|
-
isDirectory: info.isDirectory,
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
19
|
-
isFile: info.isFile,
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
21
|
-
isSymbolicLink: info.isSymbolicLink,
|
|
22
|
-
name: path.basename(normalizePath),
|
|
23
|
-
path: normalizePath
|
|
24
|
-
};
|
|
25
|
-
}, "_createWalkEntry");
|
|
26
|
-
function* walkSync(directory, {
|
|
27
|
-
extensions,
|
|
28
|
-
followSymlinks = false,
|
|
29
|
-
includeDirs: includeDirectories = true,
|
|
30
|
-
includeFiles = true,
|
|
31
|
-
includeSymlinks = true,
|
|
32
|
-
match,
|
|
33
|
-
maxDepth = Number.POSITIVE_INFINITY,
|
|
34
|
-
skip
|
|
35
|
-
} = {}) {
|
|
36
|
-
assertValidFileOrDirectoryPath(directory);
|
|
37
|
-
if (maxDepth < 0) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const mappedMatch = match ? match.map((pattern) => typeof pattern === "string" ? walkInclude.globToRegExp(pattern) : pattern) : void 0;
|
|
41
|
-
const mappedSkip = skip ? skip.map((pattern) => typeof pattern === "string" ? walkInclude.globToRegExp(pattern) : pattern) : void 0;
|
|
42
|
-
directory = path.resolve(utils.toPath(directory));
|
|
43
|
-
if (includeDirectories && walkInclude.walkInclude(directory, extensions, mappedMatch, mappedSkip)) {
|
|
44
|
-
yield _createWalkEntry(directory);
|
|
45
|
-
}
|
|
46
|
-
if (maxDepth < 1 || !walkInclude.walkInclude(directory, void 0, void 0, mappedSkip)) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
try {
|
|
50
|
-
for (const entry of node_fs.readdirSync(directory, {
|
|
51
|
-
withFileTypes: true
|
|
52
|
-
})) {
|
|
53
|
-
let path$1 = path.join(directory, entry.name);
|
|
54
|
-
if (entry.isSymbolicLink()) {
|
|
55
|
-
if (followSymlinks) {
|
|
56
|
-
path$1 = node_fs.realpathSync(path$1);
|
|
57
|
-
} else if (includeSymlinks && walkInclude.walkInclude(path$1, extensions, mappedMatch, mappedSkip)) {
|
|
58
|
-
yield {
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
60
|
-
isDirectory: entry.isDirectory,
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
62
|
-
isFile: entry.isFile,
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
64
|
-
isSymbolicLink: entry.isSymbolicLink,
|
|
65
|
-
name: entry.name,
|
|
66
|
-
path: path.normalize(path$1)
|
|
67
|
-
};
|
|
68
|
-
} else {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (entry.isSymbolicLink() || entry.isDirectory()) {
|
|
73
|
-
yield* walkSync(path$1, {
|
|
74
|
-
extensions,
|
|
75
|
-
followSymlinks,
|
|
76
|
-
includeDirs: includeDirectories,
|
|
77
|
-
includeFiles,
|
|
78
|
-
includeSymlinks,
|
|
79
|
-
match: mappedMatch,
|
|
80
|
-
maxDepth: maxDepth - 1,
|
|
81
|
-
skip: mappedSkip
|
|
82
|
-
});
|
|
83
|
-
} else if (entry.isFile() && includeFiles && walkInclude.walkInclude(path$1, extensions, mappedMatch, mappedSkip)) {
|
|
84
|
-
yield {
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
86
|
-
isDirectory: entry.isDirectory,
|
|
87
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
88
|
-
isFile: entry.isFile,
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
90
|
-
isSymbolicLink: entry.isSymbolicLink,
|
|
91
|
-
name: entry.name,
|
|
92
|
-
path: path.normalize(path$1)
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
} catch (error) {
|
|
97
|
-
if (error instanceof WalkError) {
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
throw new WalkError(error, directory);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
__name(walkSync, "walkSync");
|
|
104
|
-
|
|
105
|
-
module.exports = walkSync;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { mkdir, writeFile as writeFile$1, stat, rename, chown, chmod, unlink } from 'node:fs/promises';
|
|
2
|
-
import { dirname } from '@visulima/path';
|
|
3
|
-
import { toPath } from '@visulima/path/utils';
|
|
4
|
-
import { F_OK } from './F_OK-JER1LjUr.mjs';
|
|
5
|
-
import isAccessible from './isAccessible-Bonsm1Ez.mjs';
|
|
6
|
-
import assertValidFileContents from './assertValidFileContents-Ox-ScfeK.mjs';
|
|
7
|
-
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-BWWgA1wj.mjs';
|
|
8
|
-
import { t as toUint8Array } from './to-uint-8-array-B4CjMOD3.mjs';
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
-
const writeFile = /* @__PURE__ */ __name(async (path, content, options) => {
|
|
13
|
-
options = {
|
|
14
|
-
encoding: "utf8",
|
|
15
|
-
flag: "w",
|
|
16
|
-
overwrite: true,
|
|
17
|
-
recursive: true,
|
|
18
|
-
...options
|
|
19
|
-
};
|
|
20
|
-
assertValidFileOrDirectoryPath(path);
|
|
21
|
-
assertValidFileContents(content);
|
|
22
|
-
path = toPath(path);
|
|
23
|
-
const temporaryPath = `${path}.tmp`;
|
|
24
|
-
try {
|
|
25
|
-
const pathExists = await isAccessible(path, F_OK);
|
|
26
|
-
if (!pathExists && options.recursive) {
|
|
27
|
-
const directory = dirname(path);
|
|
28
|
-
if (!await isAccessible(directory, F_OK)) {
|
|
29
|
-
await mkdir(directory, { recursive: true });
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
let stat$1;
|
|
33
|
-
await writeFile$1(temporaryPath, toUint8Array(content), { encoding: options.encoding, flag: options.flag });
|
|
34
|
-
if (pathExists && !options.overwrite) {
|
|
35
|
-
stat$1 = await stat(path);
|
|
36
|
-
if (options.chown === void 0) {
|
|
37
|
-
options.chown = { gid: stat$1.gid, uid: stat$1.uid };
|
|
38
|
-
}
|
|
39
|
-
await rename(path, `${path}.bak`);
|
|
40
|
-
}
|
|
41
|
-
if (options.chown) {
|
|
42
|
-
try {
|
|
43
|
-
await chown(temporaryPath, options.chown.uid, options.chown.gid);
|
|
44
|
-
} catch {
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
await chmod(temporaryPath, stat$1 && !options.mode ? stat$1.mode : options.mode ?? 438);
|
|
48
|
-
await rename(temporaryPath, path);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
throw new Error(`Failed to write file at: ${path} - ${error.message}`, { cause: error });
|
|
51
|
-
} finally {
|
|
52
|
-
if (await isAccessible(temporaryPath)) {
|
|
53
|
-
await unlink(`${path}.tmp`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}, "writeFile");
|
|
57
|
-
|
|
58
|
-
export { writeFile as default };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const promises = require('node:fs/promises');
|
|
4
|
-
const path = require('@visulima/path');
|
|
5
|
-
const utils = require('@visulima/path/utils');
|
|
6
|
-
const F_OK = require('./F_OK-CWSqQIdF.cjs');
|
|
7
|
-
const isAccessible = require('./isAccessible-ZNVGsSb7.cjs');
|
|
8
|
-
const assertValidFileContents = require('./assertValidFileContents-CRVvyM6b.cjs');
|
|
9
|
-
const assertValidFileOrDirectoryPath = require('./assertValidFileOrDirectoryPath-BMbgA-eI.cjs');
|
|
10
|
-
const toUint8Array = require('./to-uint-8-array-BaTEyX3D.cjs');
|
|
11
|
-
|
|
12
|
-
var __defProp = Object.defineProperty;
|
|
13
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
14
|
-
const writeFile = /* @__PURE__ */ __name(async (path$1, content, options) => {
|
|
15
|
-
options = {
|
|
16
|
-
encoding: "utf8",
|
|
17
|
-
flag: "w",
|
|
18
|
-
overwrite: true,
|
|
19
|
-
recursive: true,
|
|
20
|
-
...options
|
|
21
|
-
};
|
|
22
|
-
assertValidFileOrDirectoryPath(path$1);
|
|
23
|
-
assertValidFileContents(content);
|
|
24
|
-
path$1 = utils.toPath(path$1);
|
|
25
|
-
const temporaryPath = `${path$1}.tmp`;
|
|
26
|
-
try {
|
|
27
|
-
const pathExists = await isAccessible(path$1, F_OK.F_OK);
|
|
28
|
-
if (!pathExists && options.recursive) {
|
|
29
|
-
const directory = path.dirname(path$1);
|
|
30
|
-
if (!await isAccessible(directory, F_OK.F_OK)) {
|
|
31
|
-
await promises.mkdir(directory, { recursive: true });
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
let stat;
|
|
35
|
-
await promises.writeFile(temporaryPath, toUint8Array.toUint8Array(content), { encoding: options.encoding, flag: options.flag });
|
|
36
|
-
if (pathExists && !options.overwrite) {
|
|
37
|
-
stat = await promises.stat(path$1);
|
|
38
|
-
if (options.chown === void 0) {
|
|
39
|
-
options.chown = { gid: stat.gid, uid: stat.uid };
|
|
40
|
-
}
|
|
41
|
-
await promises.rename(path$1, `${path$1}.bak`);
|
|
42
|
-
}
|
|
43
|
-
if (options.chown) {
|
|
44
|
-
try {
|
|
45
|
-
await promises.chown(temporaryPath, options.chown.uid, options.chown.gid);
|
|
46
|
-
} catch {
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
await promises.chmod(temporaryPath, stat && !options.mode ? stat.mode : options.mode ?? 438);
|
|
50
|
-
await promises.rename(temporaryPath, path$1);
|
|
51
|
-
} catch (error) {
|
|
52
|
-
throw new Error(`Failed to write file at: ${path$1} - ${error.message}`, { cause: error });
|
|
53
|
-
} finally {
|
|
54
|
-
if (await isAccessible(temporaryPath)) {
|
|
55
|
-
await promises.unlink(`${path$1}.tmp`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}, "writeFile");
|
|
59
|
-
|
|
60
|
-
module.exports = writeFile;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync as writeFileSync$1, statSync, renameSync, chownSync, chmodSync, unlinkSync } from 'node:fs';
|
|
2
|
-
import { dirname } from '@visulima/path';
|
|
3
|
-
import { toPath } from '@visulima/path/utils';
|
|
4
|
-
import { F_OK } from './F_OK-JER1LjUr.mjs';
|
|
5
|
-
import isAccessibleSync from './isAccessibleSync-3gnUWUwX.mjs';
|
|
6
|
-
import assertValidFileContents from './assertValidFileContents-Ox-ScfeK.mjs';
|
|
7
|
-
import assertValidFileOrDirectoryPath from './assertValidFileOrDirectoryPath-BWWgA1wj.mjs';
|
|
8
|
-
import { t as toUint8Array } from './to-uint-8-array-B4CjMOD3.mjs';
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
-
const writeFileSync = /* @__PURE__ */ __name((path, content, options) => {
|
|
13
|
-
options = {
|
|
14
|
-
encoding: "utf8",
|
|
15
|
-
flag: "w",
|
|
16
|
-
overwrite: true,
|
|
17
|
-
recursive: true,
|
|
18
|
-
...options
|
|
19
|
-
};
|
|
20
|
-
assertValidFileOrDirectoryPath(path);
|
|
21
|
-
assertValidFileContents(content);
|
|
22
|
-
path = toPath(path);
|
|
23
|
-
const temporaryPath = `${path}.tmp`;
|
|
24
|
-
try {
|
|
25
|
-
const pathExists = isAccessibleSync(path, F_OK);
|
|
26
|
-
if (!pathExists && options.recursive) {
|
|
27
|
-
const directory = dirname(path);
|
|
28
|
-
if (!isAccessibleSync(directory, F_OK)) {
|
|
29
|
-
mkdirSync(directory, { recursive: true });
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
let stat;
|
|
33
|
-
writeFileSync$1(temporaryPath, toUint8Array(content), { encoding: options.encoding, flag: options.flag });
|
|
34
|
-
if (pathExists && !options.overwrite) {
|
|
35
|
-
stat = statSync(path);
|
|
36
|
-
if (options.chown === void 0) {
|
|
37
|
-
options.chown = { gid: stat.gid, uid: stat.uid };
|
|
38
|
-
}
|
|
39
|
-
renameSync(path, `${path}.bak`);
|
|
40
|
-
}
|
|
41
|
-
if (options.chown) {
|
|
42
|
-
try {
|
|
43
|
-
chownSync(temporaryPath, options.chown.uid, options.chown.gid);
|
|
44
|
-
} catch {
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
chmodSync(temporaryPath, stat && !options.mode ? stat.mode : options.mode ?? 438);
|
|
48
|
-
renameSync(temporaryPath, path);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
throw new Error(`Failed to write file at: ${path} - ${error.message}`, { cause: error });
|
|
51
|
-
} finally {
|
|
52
|
-
if (isAccessibleSync(temporaryPath)) {
|
|
53
|
-
unlinkSync(`${path}.tmp`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}, "writeFileSync");
|
|
57
|
-
|
|
58
|
-
export { writeFileSync as default };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const node_fs = require('node:fs');
|
|
4
|
-
const path = require('@visulima/path');
|
|
5
|
-
const utils = require('@visulima/path/utils');
|
|
6
|
-
const F_OK = require('./F_OK-CWSqQIdF.cjs');
|
|
7
|
-
const isAccessibleSync = require('./isAccessibleSync-VWjQa-US.cjs');
|
|
8
|
-
const assertValidFileContents = require('./assertValidFileContents-CRVvyM6b.cjs');
|
|
9
|
-
const assertValidFileOrDirectoryPath = require('./assertValidFileOrDirectoryPath-BMbgA-eI.cjs');
|
|
10
|
-
const toUint8Array = require('./to-uint-8-array-BaTEyX3D.cjs');
|
|
11
|
-
|
|
12
|
-
var __defProp = Object.defineProperty;
|
|
13
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
14
|
-
const writeFileSync = /* @__PURE__ */ __name((path$1, content, options) => {
|
|
15
|
-
options = {
|
|
16
|
-
encoding: "utf8",
|
|
17
|
-
flag: "w",
|
|
18
|
-
overwrite: true,
|
|
19
|
-
recursive: true,
|
|
20
|
-
...options
|
|
21
|
-
};
|
|
22
|
-
assertValidFileOrDirectoryPath(path$1);
|
|
23
|
-
assertValidFileContents(content);
|
|
24
|
-
path$1 = utils.toPath(path$1);
|
|
25
|
-
const temporaryPath = `${path$1}.tmp`;
|
|
26
|
-
try {
|
|
27
|
-
const pathExists = isAccessibleSync(path$1, F_OK.F_OK);
|
|
28
|
-
if (!pathExists && options.recursive) {
|
|
29
|
-
const directory = path.dirname(path$1);
|
|
30
|
-
if (!isAccessibleSync(directory, F_OK.F_OK)) {
|
|
31
|
-
node_fs.mkdirSync(directory, { recursive: true });
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
let stat;
|
|
35
|
-
node_fs.writeFileSync(temporaryPath, toUint8Array.toUint8Array(content), { encoding: options.encoding, flag: options.flag });
|
|
36
|
-
if (pathExists && !options.overwrite) {
|
|
37
|
-
stat = node_fs.statSync(path$1);
|
|
38
|
-
if (options.chown === void 0) {
|
|
39
|
-
options.chown = { gid: stat.gid, uid: stat.uid };
|
|
40
|
-
}
|
|
41
|
-
node_fs.renameSync(path$1, `${path$1}.bak`);
|
|
42
|
-
}
|
|
43
|
-
if (options.chown) {
|
|
44
|
-
try {
|
|
45
|
-
node_fs.chownSync(temporaryPath, options.chown.uid, options.chown.gid);
|
|
46
|
-
} catch {
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
node_fs.chmodSync(temporaryPath, stat && !options.mode ? stat.mode : options.mode ?? 438);
|
|
50
|
-
node_fs.renameSync(temporaryPath, path$1);
|
|
51
|
-
} catch (error) {
|
|
52
|
-
throw new Error(`Failed to write file at: ${path$1} - ${error.message}`, { cause: error });
|
|
53
|
-
} finally {
|
|
54
|
-
if (isAccessibleSync(temporaryPath)) {
|
|
55
|
-
node_fs.unlinkSync(`${path$1}.tmp`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}, "writeFileSync");
|
|
59
|
-
|
|
60
|
-
module.exports = writeFileSync;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const promises = require('node:fs/promises');
|
|
4
|
-
const index = require('./index-BVZL6YMm.cjs');
|
|
5
|
-
const F_OK = require('./F_OK-CWSqQIdF.cjs');
|
|
6
|
-
const isAccessible = require('./isAccessible-ZNVGsSb7.cjs');
|
|
7
|
-
const writeFile = require('./writeFile-DgCFRCe5.cjs');
|
|
8
|
-
|
|
9
|
-
var __defProp = Object.defineProperty;
|
|
10
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
-
const writeJson = /* @__PURE__ */ __name(async (path, data, options = {}) => {
|
|
12
|
-
const { detectIndent, indent: indentOption, replacer, stringify = JSON.stringify, ...writeOptions } = { indent: " ", ...options };
|
|
13
|
-
let indent = indentOption;
|
|
14
|
-
let trailingNewline = "\n";
|
|
15
|
-
if (await isAccessible(path, F_OK.R_OK)) {
|
|
16
|
-
try {
|
|
17
|
-
const file = await promises.readFile(path, "utf8");
|
|
18
|
-
if (detectIndent) {
|
|
19
|
-
const { indent: dIndent } = index.detectIndent(file);
|
|
20
|
-
indent = dIndent;
|
|
21
|
-
}
|
|
22
|
-
trailingNewline = file.endsWith("\n") ? "\n" : "";
|
|
23
|
-
} catch (error) {
|
|
24
|
-
if (error.code !== "ENOENT") {
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const json = stringify(data, replacer, indent);
|
|
30
|
-
await writeFile(path, `${json}${trailingNewline}`, writeOptions);
|
|
31
|
-
}, "writeJson");
|
|
32
|
-
|
|
33
|
-
module.exports = writeJson;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { d as detectIndent } from './index-r9Pk9gBe.mjs';
|
|
3
|
-
import { R_OK } from './F_OK-JER1LjUr.mjs';
|
|
4
|
-
import isAccessible from './isAccessible-Bonsm1Ez.mjs';
|
|
5
|
-
import writeFile from './writeFile-BZ4JBQxc.mjs';
|
|
6
|
-
|
|
7
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
const writeJson = /* @__PURE__ */ __name(async (path, data, options = {}) => {
|
|
10
|
-
const { detectIndent: detectIndent$1, indent: indentOption, replacer, stringify = JSON.stringify, ...writeOptions } = { indent: " ", ...options };
|
|
11
|
-
let indent = indentOption;
|
|
12
|
-
let trailingNewline = "\n";
|
|
13
|
-
if (await isAccessible(path, R_OK)) {
|
|
14
|
-
try {
|
|
15
|
-
const file = await readFile(path, "utf8");
|
|
16
|
-
if (detectIndent$1) {
|
|
17
|
-
const { indent: dIndent } = detectIndent(file);
|
|
18
|
-
indent = dIndent;
|
|
19
|
-
}
|
|
20
|
-
trailingNewline = file.endsWith("\n") ? "\n" : "";
|
|
21
|
-
} catch (error) {
|
|
22
|
-
if (error.code !== "ENOENT") {
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const json = stringify(data, replacer, indent);
|
|
28
|
-
await writeFile(path, `${json}${trailingNewline}`, writeOptions);
|
|
29
|
-
}, "writeJson");
|
|
30
|
-
|
|
31
|
-
export { writeJson as default };
|