@jakubmazanec/fs-utils 0.2.16-next.fac374fa → 0.2.16-unstable.2468857d

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.
@@ -1,8 +1,17 @@
1
- "use strict";
2
1
  import fs from "fs-extra";
3
2
  import os from "node:os";
4
3
  import path from "node:path";
5
- export async function createTempDirectory(prefix) {
6
- return fs.mkdtemp(path.join(os.tmpdir(), prefix ?? "/"));
4
+
5
+ //#region source/createTempDirectory.ts
6
+ /**
7
+ * Creates a unique temporary directory in the operating system's default directory for temporary files. The name of the directory is random, but can be prefixed with a custom string.
8
+ *
9
+ * @param prefix The new directory name prefix.
10
+ * @returns The new directory name.
11
+ * */
12
+ async function createTempDirectory(prefix) {
13
+ return fs.mkdtemp(path.join(os.tmpdir(), prefix ?? "/"));
7
14
  }
8
- //# sourceMappingURL=createTempDirectory.js.map
15
+
16
+ //#endregion
17
+ export { createTempDirectory };
@@ -1,23 +1,23 @@
1
- "use strict";
1
+ import { isEmptyDirectory } from "./isEmptyDirectory.js";
2
2
  import fs from "fs-extra";
3
3
  import path from "node:path";
4
- import { isEmptyDirectory } from "./isEmptyDirectory.js";
5
- export async function ensureEmptyDirectory(targetPath, { allowGit } = {}) {
6
- await fs.ensureDir(targetPath);
7
- if (!await isEmptyDirectory(targetPath)) {
8
- if (!allowGit) {
9
- throw new Error(`Directory "${targetPath}" must be empty.`);
10
- }
11
- let files = await fs.readdir(targetPath);
12
- if (files.length !== 1) {
13
- throw new Error(`Directory "${targetPath}" can contain only ".git" directory.`);
14
- }
15
- if (files[0] !== ".git") {
16
- throw new Error(`Directory "${targetPath}" can contain only ".git" directory.`);
17
- }
18
- if (!(await fs.stat(path.join(targetPath, files[0]))).isDirectory()) {
19
- throw new Error(`Directory "${targetPath}" can contain only ".git" directory.`);
20
- }
21
- }
4
+
5
+ //#region source/ensureEmptyDirectory.ts
6
+ /**
7
+ * Ensures that a path is actually an empty directory. If the path doesn't exist, the directory is created; if the path exists but isn't an ampty directory, error is thrown.
8
+ *
9
+ * @param path The target path.
10
+ */
11
+ async function ensureEmptyDirectory(targetPath, { allowGit } = {}) {
12
+ await fs.ensureDir(targetPath);
13
+ if (!await isEmptyDirectory(targetPath)) {
14
+ if (!allowGit) throw new Error(`Directory "${targetPath}" must be empty.`);
15
+ let files = await fs.readdir(targetPath);
16
+ if (files.length !== 1) throw new Error(`Directory "${targetPath}" can contain only ".git" directory.`);
17
+ if (files[0] !== ".git") throw new Error(`Directory "${targetPath}" can contain only ".git" directory.`);
18
+ if (!(await fs.stat(path.join(targetPath, files[0]))).isDirectory()) throw new Error(`Directory "${targetPath}" can contain only ".git" directory.`);
19
+ }
22
20
  }
23
- //# sourceMappingURL=ensureEmptyDirectory.js.map
21
+
22
+ //#endregion
23
+ export { ensureEmptyDirectory };
@@ -1,6 +1,15 @@
1
- "use strict";
2
1
  import fs from "fs-extra";
3
- export async function findDirectories(searchPath) {
4
- return (await fs.readdir(searchPath, { withFileTypes: true })).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
2
+
3
+ //#region source/findDirectories.ts
4
+ /**
5
+ * Finds all directories that are direct sub-directories of a path.
6
+ *
7
+ * @param searchPath Search path.
8
+ * @returns The list of directory names.
9
+ */
10
+ async function findDirectories(searchPath) {
11
+ return (await fs.readdir(searchPath, { withFileTypes: true })).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
5
12
  }
6
- //# sourceMappingURL=findDirectories.js.map
13
+
14
+ //#endregion
15
+ export { findDirectories };
@@ -1,18 +1,27 @@
1
- "use strict";
1
+ import { isDirectory } from "./isDirectory.js";
2
2
  import fs from "fs-extra";
3
3
  import path from "node:path";
4
- import { isDirectory } from "./isDirectory.js";
5
- export async function findExistingDirectory(searchPath) {
6
- let result = searchPath;
7
- let pathExists = await fs.pathExists(result);
8
- while (!pathExists) {
9
- result = path.dirname(result);
10
- pathExists = await fs.pathExists(result);
11
- }
12
- let isResultDirectory = await isDirectory(result);
13
- if (!isResultDirectory) {
14
- result = path.dirname(result);
15
- }
16
- return result;
4
+
5
+ //#region source/findExistingDirectory.ts
6
+ /**
7
+ * Travels up the file system tree from a starting path and returns path of the first existing directory.
8
+ *
9
+ * ```TypeScript
10
+ * let result = findExistingDirectory('/foo/bar/baz'); // if there is no `bar` directory, `result` is `'/foo'`
11
+ * ```
12
+ *
13
+ * @param searchPath Search path.
14
+ */
15
+ async function findExistingDirectory(searchPath) {
16
+ let result = searchPath;
17
+ let pathExists = await fs.pathExists(result);
18
+ while (!pathExists) {
19
+ result = path.dirname(result);
20
+ pathExists = await fs.pathExists(result);
21
+ }
22
+ if (!await isDirectory(result)) result = path.dirname(result);
23
+ return result;
17
24
  }
18
- //# sourceMappingURL=findExistingDirectory.js.map
25
+
26
+ //#endregion
27
+ export { findExistingDirectory };
@@ -1,7 +1,15 @@
1
- "use strict";
2
1
  import fs from "fs-extra";
3
- export async function isDirectory(path) {
4
- let stat = await fs.lstat(path);
5
- return stat.isDirectory();
2
+
3
+ //#region source/isDirectory.ts
4
+ /**
5
+ * Checks if a path is a directory.
6
+ *
7
+ * @param path The path to check.
8
+ * @returns `true` if path is a directory, `false` otherwise.
9
+ */
10
+ async function isDirectory(path) {
11
+ return (await fs.lstat(path)).isDirectory();
6
12
  }
7
- //# sourceMappingURL=isDirectory.js.map
13
+
14
+ //#endregion
15
+ export { isDirectory };
@@ -1,13 +1,22 @@
1
- "use strict";
2
1
  import fs from "fs-extra";
3
- export async function isEmptyDirectory(path) {
4
- try {
5
- let directory = await fs.opendir(path);
6
- let entry = await directory.read();
7
- await directory.close();
8
- return entry === null;
9
- } catch {
10
- return false;
11
- }
2
+
3
+ //#region source/isEmptyDirectory.ts
4
+ /**
5
+ * Checks if a path is an empty directory.
6
+ *
7
+ * @param path The path to check.
8
+ * @returns `true` if path is an empty directory, `false` otherwise.
9
+ */
10
+ async function isEmptyDirectory(path) {
11
+ try {
12
+ let directory = await fs.opendir(path);
13
+ let entry = await directory.read();
14
+ await directory.close();
15
+ return entry === null;
16
+ } catch {
17
+ return false;
18
+ }
12
19
  }
13
- //# sourceMappingURL=isEmptyDirectory.js.map
20
+
21
+ //#endregion
22
+ export { isEmptyDirectory };
@@ -1,6 +1,15 @@
1
- "use strict";
2
1
  import path from "node:path";
3
- export function isRootPath(value) {
4
- return value.toLowerCase() === path.parse(value).root.toLowerCase();
2
+
3
+ //#region source/isRootPath.ts
4
+ /**
5
+ * Checks if a path is a file system root path.
6
+ *
7
+ * @param path The path to check.
8
+ * @returns `true` if path is the root, `false` otherwise.
9
+ */
10
+ function isRootPath(value) {
11
+ return value.toLowerCase() === path.parse(value).root.toLowerCase();
5
12
  }
6
- //# sourceMappingURL=isRootPath.js.map
13
+
14
+ //#endregion
15
+ export { isRootPath };
package/build/main.js CHANGED
@@ -1,10 +1,10 @@
1
- "use strict";
2
- export * from "./createTempDirectory.js";
3
- export * from "./ensureEmptyDirectory.js";
4
- export * from "./findDirectories.js";
5
- export * from "./findExistingDirectory.js";
6
- export * from "./isDirectory.js";
7
- export * from "./isEmptyDirectory.js";
8
- export * from "./isRootPath.js";
9
- export * from "./pathToPosixPath.js";
10
- //# sourceMappingURL=main.js.map
1
+ import { createTempDirectory } from "./createTempDirectory.js";
2
+ import { isEmptyDirectory } from "./isEmptyDirectory.js";
3
+ import { ensureEmptyDirectory } from "./ensureEmptyDirectory.js";
4
+ import { findDirectories } from "./findDirectories.js";
5
+ import { isDirectory } from "./isDirectory.js";
6
+ import { findExistingDirectory } from "./findExistingDirectory.js";
7
+ import { isRootPath } from "./isRootPath.js";
8
+ import { pathToPosixPath } from "./pathToPosixPath.js";
9
+
10
+ export { createTempDirectory, ensureEmptyDirectory, findDirectories, findExistingDirectory, isDirectory, isEmptyDirectory, isRootPath, pathToPosixPath };
@@ -1,6 +1,15 @@
1
- "use strict";
2
1
  import path from "node:path";
3
- export function pathToPosixPath(value) {
4
- return value.split(path.win32.sep).join(path.posix.sep);
2
+
3
+ //#region source/pathToPosixPath.ts
4
+ /**
5
+ * Converts path to POSIX path.
6
+ *
7
+ * @param value The path to convert.
8
+ * @returns The converted path.
9
+ */
10
+ function pathToPosixPath(value) {
11
+ return value.split(path.win32.sep).join(path.posix.sep);
5
12
  }
6
- //# sourceMappingURL=pathToPosixPath.js.map
13
+
14
+ //#endregion
15
+ export { pathToPosixPath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jakubmazanec/fs-utils",
3
- "version": "0.2.16-next.fac374fa",
3
+ "version": "0.2.16-unstable.2468857d",
4
4
  "description": "Collection of utilities for working with file system.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,9 +17,9 @@
17
17
  "source"
18
18
  ],
19
19
  "scripts": {
20
- "build": "del-cli build tsconfig.tsbuildinfo && esbuild \"source/**/*\" --platform=node --target=node24.3 --outdir=build --sourcemap && tsc",
20
+ "build": "del-cli build tsconfig.tsbuildinfo && tsdown && tsc",
21
21
  "clean": "del-cli coverage build *.tsbuildinfo",
22
- "develop": "concurrently \"esbuild \"source/**/*\" --platform=node --target=node24.3 --outdir=build --sourcemap --watch\" \"tsc --watch\"",
22
+ "develop": "concurrently \"tsdown --watch\" \"tsc --watch\"",
23
23
  "document": "del-cli docs && typedoc --options typedoc.config.cjs",
24
24
  "format": "prettier . --write --ignore-unknown",
25
25
  "lint": "eslint .",
@@ -30,18 +30,18 @@
30
30
  "fs-extra": "^11.3.2"
31
31
  },
32
32
  "devDependencies": {
33
- "@jakubmazanec/eslint-config": "4.1.10-next.fac374fa",
33
+ "@jakubmazanec/eslint-config": "4.1.10-unstable.2468857d",
34
34
  "@types/fs-extra": "^11.0.4",
35
35
  "@types/lodash": "^4.17.21",
36
36
  "@types/node": "^24.0.4",
37
37
  "@vitest/coverage-v8": "^3.2.4",
38
38
  "concurrently": "^9.2.1",
39
39
  "del-cli": "^6.0.0",
40
- "esbuild": "^0.27.0",
41
40
  "eslint": "^9.33.0",
42
41
  "lodash": "^4.17.21",
43
42
  "prettier": "^3.6.2",
44
43
  "prettier-plugin-packagejson": "^2.5.19",
44
+ "tsdown": "^0.17.2",
45
45
  "typedoc": "^0.28.14",
46
46
  "typedoc-plugin-markdown": "^4.9.0",
47
47
  "typescript": "^5.9.3",
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../source/createTempDirectory.ts"],
4
- "sourcesContent": ["import fs from 'fs-extra';\nimport os from 'node:os';\nimport path from 'node:path';\n\n/**\n * Creates a unique temporary directory in the operating system's default directory for temporary files. The name of the directory is random, but can be prefixed with a custom string.\n *\n * @param prefix The new directory name prefix.\n * @returns The new directory name.\n * */\nexport async function createTempDirectory(prefix?: string) {\n return fs.mkdtemp(path.join(os.tmpdir(), prefix ?? '/'));\n}\n"],
5
- "mappings": ";AAAA,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AAQjB,sBAAsB,oBAAoB,QAAiB;AACzD,SAAO,GAAG,QAAQ,KAAK,KAAK,GAAG,OAAO,GAAG,UAAU,GAAG,CAAC;AACzD;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../source/ensureEmptyDirectory.ts"],
4
- "sourcesContent": ["import fs from 'fs-extra';\nimport path from 'node:path';\n\nimport {isEmptyDirectory} from './isEmptyDirectory.js';\n\n/**\n * {@link ensureEmptyDirectory} options parameter.\n */\nexport type EnsureEmptyDirectoryOptions = {\n /** Allows presence of a `.git` directory */\n allowGit?: boolean | undefined;\n};\n\n/**\n * Ensures that a path is actually an empty directory. If the path doesn't exist, the directory is created; if the path exists but isn't an ampty directory, error is thrown.\n *\n * @param path The target path.\n */\nexport async function ensureEmptyDirectory(\n targetPath: string,\n {allowGit}: EnsureEmptyDirectoryOptions = {},\n) {\n await fs.ensureDir(targetPath);\n\n if (!(await isEmptyDirectory(targetPath))) {\n if (!allowGit) {\n throw new Error(`Directory \"${targetPath}\" must be empty.`);\n }\n\n let files = await fs.readdir(targetPath);\n\n if (files.length !== 1) {\n throw new Error(`Directory \"${targetPath}\" can contain only \".git\" directory.`);\n }\n\n if (files[0] !== '.git') {\n throw new Error(`Directory \"${targetPath}\" can contain only \".git\" directory.`);\n }\n\n if (!(await fs.stat(path.join(targetPath, files[0] as string))).isDirectory()) {\n throw new Error(`Directory \"${targetPath}\" can contain only \".git\" directory.`);\n }\n }\n}\n"],
5
- "mappings": ";AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,SAAQ,wBAAuB;AAe/B,sBAAsB,qBACpB,YACA,EAAC,SAAQ,IAAiC,CAAC,GAC3C;AACA,QAAM,GAAG,UAAU,UAAU;AAE7B,MAAI,CAAE,MAAM,iBAAiB,UAAU,GAAI;AACzC,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,MAAM,cAAc,UAAU,kBAAkB;AAAA,IAC5D;AAEA,QAAI,QAAQ,MAAM,GAAG,QAAQ,UAAU;AAEvC,QAAI,MAAM,WAAW,GAAG;AACtB,YAAM,IAAI,MAAM,cAAc,UAAU,sCAAsC;AAAA,IAChF;AAEA,QAAI,MAAM,CAAC,MAAM,QAAQ;AACvB,YAAM,IAAI,MAAM,cAAc,UAAU,sCAAsC;AAAA,IAChF;AAEA,QAAI,EAAE,MAAM,GAAG,KAAK,KAAK,KAAK,YAAY,MAAM,CAAC,CAAW,CAAC,GAAG,YAAY,GAAG;AAC7E,YAAM,IAAI,MAAM,cAAc,UAAU,sCAAsC;AAAA,IAChF;AAAA,EACF;AACF;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../source/findDirectories.ts"],
4
- "sourcesContent": ["import fs from 'fs-extra';\n\n/**\n * Finds all directories that are direct sub-directories of a path.\n *\n * @param searchPath Search path.\n * @returns The list of directory names.\n */\nexport async function findDirectories(searchPath: string): Promise<string[]> {\n return (await fs.readdir(searchPath, {withFileTypes: true}))\n .filter((dirent) => dirent.isDirectory())\n .map((dirent) => dirent.name);\n}\n"],
5
- "mappings": ";AAAA,OAAO,QAAQ;AAQf,sBAAsB,gBAAgB,YAAuC;AAC3E,UAAQ,MAAM,GAAG,QAAQ,YAAY,EAAC,eAAe,KAAI,CAAC,GACvD,OAAO,CAAC,WAAW,OAAO,YAAY,CAAC,EACvC,IAAI,CAAC,WAAW,OAAO,IAAI;AAChC;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../source/findExistingDirectory.ts"],
4
- "sourcesContent": ["import fs from 'fs-extra';\nimport path from 'node:path';\n\nimport {isDirectory} from './isDirectory.js';\n\n/**\n * Travels up the file system tree from a starting path and returns path of the first existing directory.\n *\n * ```TypeScript\n * let result = findExistingDirectory('/foo/bar/baz'); // if there is no `bar` directory, `result` is `'/foo'`\n * ```\n *\n * @param searchPath Search path.\n */\nexport async function findExistingDirectory(searchPath: string) {\n let result = searchPath;\n let pathExists = await fs.pathExists(result);\n\n while (!pathExists) {\n result = path.dirname(result);\n pathExists = await fs.pathExists(result);\n }\n\n let isResultDirectory = await isDirectory(result);\n\n if (!isResultDirectory) {\n result = path.dirname(result);\n }\n\n return result;\n}\n"],
5
- "mappings": ";AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AAEjB,SAAQ,mBAAkB;AAW1B,sBAAsB,sBAAsB,YAAoB;AAC9D,MAAI,SAAS;AACb,MAAI,aAAa,MAAM,GAAG,WAAW,MAAM;AAE3C,SAAO,CAAC,YAAY;AAClB,aAAS,KAAK,QAAQ,MAAM;AAC5B,iBAAa,MAAM,GAAG,WAAW,MAAM;AAAA,EACzC;AAEA,MAAI,oBAAoB,MAAM,YAAY,MAAM;AAEhD,MAAI,CAAC,mBAAmB;AACtB,aAAS,KAAK,QAAQ,MAAM;AAAA,EAC9B;AAEA,SAAO;AACT;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../source/isDirectory.ts"],
4
- "sourcesContent": ["import fs from 'fs-extra';\n\n/**\n * Checks if a path is a directory.\n *\n * @param path The path to check.\n * @returns `true` if path is a directory, `false` otherwise.\n */\nexport async function isDirectory(path: string): Promise<boolean> {\n let stat = await fs.lstat(path);\n\n return stat.isDirectory();\n}\n"],
5
- "mappings": ";AAAA,OAAO,QAAQ;AAQf,sBAAsB,YAAY,MAAgC;AAChE,MAAI,OAAO,MAAM,GAAG,MAAM,IAAI;AAE9B,SAAO,KAAK,YAAY;AAC1B;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../source/isEmptyDirectory.ts"],
4
- "sourcesContent": ["import fs from 'fs-extra';\n\n/**\n * Checks if a path is an empty directory.\n *\n * @param path The path to check.\n * @returns `true` if path is an empty directory, `false` otherwise.\n */\nexport async function isEmptyDirectory(path: string) {\n try {\n let directory = await fs.opendir(path);\n let entry = await directory.read();\n\n await directory.close();\n\n return entry === null;\n } catch {\n return false;\n }\n}\n"],
5
- "mappings": ";AAAA,OAAO,QAAQ;AAQf,sBAAsB,iBAAiB,MAAc;AACnD,MAAI;AACF,QAAI,YAAY,MAAM,GAAG,QAAQ,IAAI;AACrC,QAAI,QAAQ,MAAM,UAAU,KAAK;AAEjC,UAAM,UAAU,MAAM;AAEtB,WAAO,UAAU;AAAA,EACnB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../source/isRootPath.ts"],
4
- "sourcesContent": ["import path from 'node:path';\n\n/**\n * Checks if a path is a file system root path.\n *\n * @param path The path to check.\n * @returns `true` if path is the root, `false` otherwise.\n */\nexport function isRootPath(value: string) {\n return value.toLowerCase() === path.parse(value).root.toLowerCase();\n}\n"],
5
- "mappings": ";AAAA,OAAO,UAAU;AAQV,gBAAS,WAAW,OAAe;AACxC,SAAO,MAAM,YAAY,MAAM,KAAK,MAAM,KAAK,EAAE,KAAK,YAAY;AACpE;",
6
- "names": []
7
- }
package/build/main.js.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../source/main.ts"],
4
- "sourcesContent": ["export * from './createTempDirectory.js';\nexport * from './ensureEmptyDirectory.js';\nexport * from './findDirectories.js';\nexport * from './findExistingDirectory.js';\nexport * from './isDirectory.js';\nexport * from './isEmptyDirectory.js';\nexport * from './isRootPath.js';\nexport * from './pathToPosixPath.js';\n"],
5
- "mappings": ";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../source/pathToPosixPath.ts"],
4
- "sourcesContent": ["import path from 'node:path';\n\n/**\n * Converts path to POSIX path.\n *\n * @param value The path to convert.\n * @returns The converted path.\n */\nexport function pathToPosixPath(value: string): string {\n return value.split(path.win32.sep).join(path.posix.sep);\n}\n"],
5
- "mappings": ";AAAA,OAAO,UAAU;AAQV,gBAAS,gBAAgB,OAAuB;AACrD,SAAO,MAAM,MAAM,KAAK,MAAM,GAAG,EAAE,KAAK,KAAK,MAAM,GAAG;AACxD;",
6
- "names": []
7
- }