@jakubmazanec/fs-utils 0.1.2 → 0.2.0-next.2fa8a2c
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 +1 -1
- package/build/createTempDirectory.js +8 -0
- package/build/createTempDirectory.js.map +7 -0
- package/build/ensureEmptyDirectory.d.ts +13 -0
- package/build/ensureEmptyDirectory.js +23 -0
- package/build/ensureEmptyDirectory.js.map +7 -0
- package/build/findDirectories.js +6 -0
- package/build/findDirectories.js.map +7 -0
- package/build/findExistingDirectory.js +18 -0
- package/build/findExistingDirectory.js.map +7 -0
- package/build/isDirectory.js +7 -0
- package/build/isDirectory.js.map +7 -0
- package/build/isEmptyDirectory.js +13 -0
- package/build/isEmptyDirectory.js.map +7 -0
- package/build/isRootPath.js +6 -0
- package/build/isRootPath.js.map +7 -0
- package/build/main.js +10 -0
- package/build/main.js.map +7 -0
- package/build/pathToPosixPath.js +6 -0
- package/build/pathToPosixPath.js.map +7 -0
- package/package.json +26 -14
- package/source/ensureEmptyDirectory.ts +44 -0
- package/dist/createTempDirectory.js +0 -13
- package/dist/createTempDirectory.js.map +0 -1
- package/dist/ensureEmptyDirectory.d.ts +0 -6
- package/dist/ensureEmptyDirectory.js +0 -14
- package/dist/ensureEmptyDirectory.js.map +0 -1
- package/dist/findDirectories.js +0 -13
- package/dist/findDirectories.js.map +0 -1
- package/dist/findExistingDirectory.js +0 -26
- package/dist/findExistingDirectory.js.map +0 -1
- package/dist/isDirectory.js +0 -12
- package/dist/isDirectory.js.map +0 -1
- package/dist/isEmptyDirectory.js +0 -18
- package/dist/isEmptyDirectory.js.map +0 -1
- package/dist/isRootPath.js +0 -11
- package/dist/isRootPath.js.map +0 -1
- package/dist/main.js +0 -10
- package/dist/main.js.map +0 -1
- package/dist/pathToPosixPath.js +0 -11
- package/dist/pathToPosixPath.js.map +0 -1
- package/src/ensureEmptyDirectory.ts +0 -16
- /package/{dist → build}/createTempDirectory.d.ts +0 -0
- /package/{dist → build}/findDirectories.d.ts +0 -0
- /package/{dist → build}/findExistingDirectory.d.ts +0 -0
- /package/{dist → build}/isDirectory.d.ts +0 -0
- /package/{dist → build}/isEmptyDirectory.d.ts +0 -0
- /package/{dist → build}/isRootPath.d.ts +0 -0
- /package/{dist → build}/main.d.ts +0 -0
- /package/{dist → build}/pathToPosixPath.d.ts +0 -0
- /package/{src → source}/createTempDirectory.ts +0 -0
- /package/{src → source}/findDirectories.ts +0 -0
- /package/{src → source}/findExistingDirectory.ts +0 -0
- /package/{src → source}/isDirectory.ts +0 -0
- /package/{src → source}/isEmptyDirectory.ts +0 -0
- /package/{src → source}/isRootPath.ts +0 -0
- /package/{src → source}/main.ts +0 -0
- /package/{src → source}/pathToPosixPath.ts +0 -0
package/README.md
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
export async function createTempDirectory(prefix) {
|
|
6
|
+
return fs.mkdtemp(path.join(os.tmpdir(), prefix ?? "/"));
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=createTempDirectory.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* {@link ensureEmptyDirectory} options parameter.
|
|
3
|
+
*/
|
|
4
|
+
export type EnsureEmptyDirectoryOptions = {
|
|
5
|
+
/** Allows presence of a `.git` directory */
|
|
6
|
+
allowGit?: boolean | undefined;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* 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.
|
|
10
|
+
*
|
|
11
|
+
* @param path The target path.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ensureEmptyDirectory(targetPath: string, { allowGit }?: EnsureEmptyDirectoryOptions): Promise<void>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import fs from "fs-extra";
|
|
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
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=ensureEmptyDirectory.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
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);
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=findDirectories.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import fs from "fs-extra";
|
|
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;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=findExistingDirectory.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
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
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=isEmptyDirectory.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
ADDED
|
@@ -0,0 +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
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakubmazanec/fs-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-next.2fa8a2c",
|
|
4
4
|
"description": "Collection of utilities for working with file system.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,29 +11,41 @@
|
|
|
11
11
|
"author": "Jakub Mazanec <jakub@mazanec.dev>",
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"type": "module",
|
|
14
|
-
"exports": "./
|
|
14
|
+
"exports": "./build/main.js",
|
|
15
15
|
"files": [
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
"build",
|
|
17
|
+
"source"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "
|
|
21
|
-
"clean": "del-cli coverage
|
|
22
|
-
"
|
|
23
|
-
"
|
|
20
|
+
"build": "del-cli build tsconfig.tsbuildinfo && esbuild \"source/**/*\" --platform=node --target=node20.8 --outdir=build --sourcemap && tsc",
|
|
21
|
+
"clean": "del-cli coverage build *.tsbuildinfo",
|
|
22
|
+
"develop": "concurrently \"esbuild \"source/**/*\" --platform=node --target=node20.8 --outdir=build --sourcemap --watch\" \"tsc --watch\"",
|
|
23
|
+
"document": "del-cli docs && typedoc --options typedoc.config.cjs",
|
|
24
|
+
"format": "prettier . --write --ignore-unknown",
|
|
24
25
|
"lint": "eslint .",
|
|
25
|
-
"test": "
|
|
26
|
+
"test": "del-cli coverage && vitest run --coverage --passWithNoTests",
|
|
26
27
|
"typecheck": "tsc --project tsconfig.typecheck.json"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"fs-extra": "^
|
|
30
|
+
"fs-extra": "^11.2.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@
|
|
33
|
-
"@types/
|
|
33
|
+
"@types/fs-extra": "^11.0.4",
|
|
34
|
+
"@types/node": "^20.8.5",
|
|
35
|
+
"@vitest/coverage-v8": "^1.2.2",
|
|
36
|
+
"concurrently": "^8.2.2",
|
|
37
|
+
"del-cli": "^5.1.0",
|
|
38
|
+
"esbuild": "^0.20.0",
|
|
39
|
+
"eslint": "^8.56.0",
|
|
40
|
+
"prettier": "^3.2.5",
|
|
41
|
+
"prettier-plugin-packagejson": "^2.4.10",
|
|
42
|
+
"typedoc": "^0.25.7",
|
|
43
|
+
"typedoc-plugin-markdown": "^3.17.1",
|
|
44
|
+
"typescript": "^5.3.3",
|
|
45
|
+
"vitest": "^1.2.2"
|
|
34
46
|
},
|
|
35
|
-
"packageManager": "npm@
|
|
47
|
+
"packageManager": "npm@10.1.0",
|
|
36
48
|
"engines": {
|
|
37
|
-
"node": "
|
|
49
|
+
"node": "^20.8.0"
|
|
38
50
|
}
|
|
39
51
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import {isEmptyDirectory} from './isEmptyDirectory.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* {@link ensureEmptyDirectory} options parameter.
|
|
8
|
+
*/
|
|
9
|
+
export type EnsureEmptyDirectoryOptions = {
|
|
10
|
+
/** Allows presence of a `.git` directory */
|
|
11
|
+
allowGit?: boolean | undefined;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 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.
|
|
16
|
+
*
|
|
17
|
+
* @param path The target path.
|
|
18
|
+
*/
|
|
19
|
+
export async function ensureEmptyDirectory(
|
|
20
|
+
targetPath: string,
|
|
21
|
+
{allowGit}: EnsureEmptyDirectoryOptions = {},
|
|
22
|
+
) {
|
|
23
|
+
await fs.ensureDir(targetPath);
|
|
24
|
+
|
|
25
|
+
if (!(await isEmptyDirectory(targetPath))) {
|
|
26
|
+
if (!allowGit) {
|
|
27
|
+
throw new Error(`Directory "${targetPath}" must be empty.`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let files = await fs.readdir(targetPath);
|
|
31
|
+
|
|
32
|
+
if (files.length !== 1) {
|
|
33
|
+
throw new Error(`Directory "${targetPath}" can contain only ".git" directory.`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (files[0] !== '.git') {
|
|
37
|
+
throw new Error(`Directory "${targetPath}" can contain only ".git" directory.`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!(await fs.stat(path.join(targetPath, files[0] as string))).isDirectory()) {
|
|
41
|
+
throw new Error(`Directory "${targetPath}" can contain only ".git" directory.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
/**
|
|
5
|
-
* 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.
|
|
6
|
-
*
|
|
7
|
-
* @param prefix The new directory name prefix.
|
|
8
|
-
* @returns The new directory name.
|
|
9
|
-
* */ export async function createTempDirectory(prefix) {
|
|
10
|
-
return fs.mkdtemp(path.join(os.tmpdir(), prefix ?? '/'));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=createTempDirectory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createTempDirectory.ts"],"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"],"names":["fs","os","path","createTempDirectory","prefix","mkdtemp","join","tmpdir"],"mappings":"AAAA,OAAOA,QAAQ,WAAW;AAC1B,OAAOC,QAAQ,UAAU;AACzB,OAAOC,UAAU,YAAY;AAE7B;;;;;GAKG,GACH,OAAO,eAAeC,oBAAoBC,MAAe;IACvD,OAAOJ,GAAGK,OAAO,CAACH,KAAKI,IAAI,CAACL,GAAGM,MAAM,IAAIH,UAAU;AACrD"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 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.
|
|
3
|
-
*
|
|
4
|
-
* @param path The target path.
|
|
5
|
-
*/
|
|
6
|
-
export declare function ensureEmptyDirectory(targetPath: string): Promise<void>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import { isEmptyDirectory } from './isEmptyDirectory.js';
|
|
3
|
-
/**
|
|
4
|
-
* 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.
|
|
5
|
-
*
|
|
6
|
-
* @param path The target path.
|
|
7
|
-
*/ export async function ensureEmptyDirectory(targetPath) {
|
|
8
|
-
await fs.ensureDir(targetPath);
|
|
9
|
-
if (!await isEmptyDirectory(targetPath)) {
|
|
10
|
-
throw new Error(`Directory "${targetPath}" must be empty.`);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
//# sourceMappingURL=ensureEmptyDirectory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ensureEmptyDirectory.ts"],"sourcesContent":["import fs from 'fs-extra';\n\nimport {isEmptyDirectory} from './isEmptyDirectory.js';\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(targetPath: string) {\n await fs.ensureDir(targetPath);\n\n if (!(await isEmptyDirectory(targetPath))) {\n throw new Error(`Directory \"${targetPath}\" must be empty.`);\n }\n}\n"],"names":["fs","isEmptyDirectory","ensureEmptyDirectory","targetPath","ensureDir","Error"],"mappings":"AAAA,OAAOA,QAAQ,WAAW;AAE1B,SAAQC,gBAAgB,QAAO,wBAAwB;AAEvD;;;;CAIC,GACD,OAAO,eAAeC,qBAAqBC,UAAkB;IAC3D,MAAMH,GAAGI,SAAS,CAACD;IAEnB,IAAI,CAAE,MAAMF,iBAAiBE,aAAc;QACzC,MAAM,IAAIE,MAAM,CAAC,WAAW,EAAEF,WAAW,gBAAgB,CAAC;IAC5D;AACF"}
|
package/dist/findDirectories.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
/**
|
|
3
|
-
* Finds all directories that are direct sub-directories of a path.
|
|
4
|
-
*
|
|
5
|
-
* @param searchPath Search path.
|
|
6
|
-
* @returns The list of directory names.
|
|
7
|
-
*/ export async function findDirectories(searchPath) {
|
|
8
|
-
return (await fs.readdir(searchPath, {
|
|
9
|
-
withFileTypes: true
|
|
10
|
-
})).filter((dirent)=>dirent.isDirectory()).map((dirent)=>dirent.name);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
//# sourceMappingURL=findDirectories.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findDirectories.ts"],"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"],"names":["fs","findDirectories","searchPath","readdir","withFileTypes","filter","dirent","isDirectory","map","name"],"mappings":"AAAA,OAAOA,QAAQ,WAAW;AAE1B;;;;;CAKC,GACD,OAAO,eAAeC,gBAAgBC,UAAkB;IACtD,OAAO,AAAC,CAAA,MAAMF,GAAGG,OAAO,CAACD,YAAY;QAACE,eAAe;IAAI,EAAC,EACvDC,MAAM,CAAC,CAACC,SAAWA,OAAOC,WAAW,IACrCC,GAAG,CAAC,CAACF,SAAWA,OAAOG,IAAI;AAChC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { isDirectory } from './isDirectory.js';
|
|
4
|
-
/**
|
|
5
|
-
* Travels up the file system tree from a starting path and returns path of the first existing directory.
|
|
6
|
-
*
|
|
7
|
-
* ```TypeScript
|
|
8
|
-
* let result = findExistingDirectory('/foo/bar/baz'); // if there is no `bar` directory, `result` is `'/foo'`
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* @param searchPath Search path.
|
|
12
|
-
*/ export async function findExistingDirectory(searchPath) {
|
|
13
|
-
let result = searchPath;
|
|
14
|
-
let pathExists = await fs.pathExists(result);
|
|
15
|
-
while(!pathExists){
|
|
16
|
-
result = path.dirname(result);
|
|
17
|
-
pathExists = await fs.pathExists(result);
|
|
18
|
-
}
|
|
19
|
-
let isResultDirectory = await isDirectory(result);
|
|
20
|
-
if (!isResultDirectory) {
|
|
21
|
-
result = path.dirname(result);
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=findExistingDirectory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/findExistingDirectory.ts"],"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"],"names":["fs","path","isDirectory","findExistingDirectory","searchPath","result","pathExists","dirname","isResultDirectory"],"mappings":"AAAA,OAAOA,QAAQ,WAAW;AAC1B,OAAOC,UAAU,YAAY;AAE7B,SAAQC,WAAW,QAAO,mBAAmB;AAE7C;;;;;;;;CAQC,GACD,OAAO,eAAeC,sBAAsBC,UAAkB;IAC5D,IAAIC,SAASD;IACb,IAAIE,aAAa,MAAMN,GAAGM,UAAU,CAACD;IAErC,MAAO,CAACC,WAAY;QAClBD,SAASJ,KAAKM,OAAO,CAACF;QACtBC,aAAa,MAAMN,GAAGM,UAAU,CAACD;IACnC;IAEA,IAAIG,oBAAoB,MAAMN,YAAYG;IAE1C,IAAI,CAACG,mBAAmB;QACtBH,SAASJ,KAAKM,OAAO,CAACF;IACxB;IAEA,OAAOA;AACT"}
|
package/dist/isDirectory.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
/**
|
|
3
|
-
* Checks if a path is a directory.
|
|
4
|
-
*
|
|
5
|
-
* @param path The path to check.
|
|
6
|
-
* @returns `true` if path is a directory, `false` otherwise.
|
|
7
|
-
*/ export async function isDirectory(path) {
|
|
8
|
-
let stat = await fs.lstat(path);
|
|
9
|
-
return stat.isDirectory();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
//# sourceMappingURL=isDirectory.js.map
|
package/dist/isDirectory.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/isDirectory.ts"],"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"],"names":["fs","isDirectory","path","stat","lstat"],"mappings":"AAAA,OAAOA,QAAQ,WAAW;AAE1B;;;;;CAKC,GACD,OAAO,eAAeC,YAAYC,IAAY;IAC5C,IAAIC,OAAO,MAAMH,GAAGI,KAAK,CAACF;IAE1B,OAAOC,KAAKF,WAAW;AACzB"}
|
package/dist/isEmptyDirectory.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
/**
|
|
3
|
-
* Checks if a path is an empty directory.
|
|
4
|
-
*
|
|
5
|
-
* @param path The path to check.
|
|
6
|
-
* @returns `true` if path is an empty directory, `false` otherwise.
|
|
7
|
-
*/ export async function isEmptyDirectory(path) {
|
|
8
|
-
try {
|
|
9
|
-
let directory = await fs.opendir(path);
|
|
10
|
-
let entry = await directory.read();
|
|
11
|
-
await directory.close();
|
|
12
|
-
return entry === null;
|
|
13
|
-
} catch {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=isEmptyDirectory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/isEmptyDirectory.ts"],"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"],"names":["fs","isEmptyDirectory","path","directory","opendir","entry","read","close"],"mappings":"AAAA,OAAOA,QAAQ,WAAW;AAE1B;;;;;CAKC,GACD,OAAO,eAAeC,iBAAiBC,IAAY;IACjD,IAAI;QACF,IAAIC,YAAY,MAAMH,GAAGI,OAAO,CAACF;QACjC,IAAIG,QAAQ,MAAMF,UAAUG,IAAI;QAEhC,MAAMH,UAAUI,KAAK;QAErB,OAAOF,UAAU;IACnB,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
|
package/dist/isRootPath.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
/**
|
|
3
|
-
* Checks if a path is a file system root path.
|
|
4
|
-
*
|
|
5
|
-
* @param path The path to check.
|
|
6
|
-
* @returns `true` if path is the root, `false` otherwise.
|
|
7
|
-
*/ export function isRootPath(value) {
|
|
8
|
-
return value.toLowerCase() === path.parse(value).root.toLowerCase();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=isRootPath.js.map
|
package/dist/isRootPath.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/isRootPath.ts"],"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"],"names":["path","isRootPath","value","toLowerCase","parse","root"],"mappings":"AAAA,OAAOA,UAAU,YAAY;AAE7B;;;;;CAKC,GACD,OAAO,SAASC,WAAWC,KAAa;IACtC,OAAOA,MAAMC,WAAW,OAAOH,KAAKI,KAAK,CAACF,OAAOG,IAAI,CAACF,WAAW;AACnE"}
|
package/dist/main.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './createTempDirectory.js';
|
|
2
|
-
export * from './ensureEmptyDirectory.js';
|
|
3
|
-
export * from './findDirectories.js';
|
|
4
|
-
export * from './findExistingDirectory.js';
|
|
5
|
-
export * from './isDirectory.js';
|
|
6
|
-
export * from './isEmptyDirectory.js';
|
|
7
|
-
export * from './isRootPath.js';
|
|
8
|
-
export * from './pathToPosixPath.js';
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/main.ts"],"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"],"names":[],"mappings":"AAAA,cAAc,2BAA2B;AACzC,cAAc,4BAA4B;AAC1C,cAAc,uBAAuB;AACrC,cAAc,6BAA6B;AAC3C,cAAc,mBAAmB;AACjC,cAAc,wBAAwB;AACtC,cAAc,kBAAkB;AAChC,cAAc,uBAAuB"}
|
package/dist/pathToPosixPath.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
/**
|
|
3
|
-
* Converts path to POSIX path.
|
|
4
|
-
*
|
|
5
|
-
* @param value The path to convert.
|
|
6
|
-
* @returns The converted path.
|
|
7
|
-
*/ export function pathToPosixPath(value) {
|
|
8
|
-
return value.split(path.win32.sep).join(path.posix.sep);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=pathToPosixPath.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/pathToPosixPath.ts"],"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"],"names":["path","pathToPosixPath","value","split","win32","sep","join","posix"],"mappings":"AAAA,OAAOA,UAAU,YAAY;AAE7B;;;;;CAKC,GACD,OAAO,SAASC,gBAAgBC,KAAa;IAC3C,OAAOA,MAAMC,KAAK,CAACH,KAAKI,KAAK,CAACC,GAAG,EAAEC,IAAI,CAACN,KAAKO,KAAK,CAACF,GAAG;AACxD"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
|
|
3
|
-
import {isEmptyDirectory} from './isEmptyDirectory.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 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.
|
|
7
|
-
*
|
|
8
|
-
* @param path The target path.
|
|
9
|
-
*/
|
|
10
|
-
export async function ensureEmptyDirectory(targetPath: string) {
|
|
11
|
-
await fs.ensureDir(targetPath);
|
|
12
|
-
|
|
13
|
-
if (!(await isEmptyDirectory(targetPath))) {
|
|
14
|
-
throw new Error(`Directory "${targetPath}" must be empty.`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{src → source}/main.ts
RENAMED
|
File without changes
|
|
File without changes
|