@rsdk/common.node 5.11.0-next.1 → 5.11.0-next.3
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/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/readdir-recursive.d.ts +6 -0
- package/dist/readdir-recursive.js +34 -0
- package/dist/readdir-recursive.js.map +1 -0
- package/dist/try-read-file.d.ts +5 -0
- package/dist/try-read-file.js +21 -0
- package/dist/try-read-file.js.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +3 -0
- package/src/readdir-recursive.ts +34 -0
- package/src/try-read-file.ts +33 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Deferred = exports.Concurrency = exports.omitUndefined = void 0;
|
|
17
|
+
exports.readdirRecursive = exports.tryReadFile = exports.Deferred = exports.Concurrency = exports.omitUndefined = void 0;
|
|
18
18
|
var object_1 = require("./object");
|
|
19
19
|
Object.defineProperty(exports, "omitUndefined", { enumerable: true, get: function () { return object_1.omitUndefined; } });
|
|
20
20
|
var concurrency_decorator_1 = require("./concurrency.decorator");
|
|
@@ -23,4 +23,8 @@ var deferred_1 = require("./deferred");
|
|
|
23
23
|
Object.defineProperty(exports, "Deferred", { enumerable: true, get: function () { return deferred_1.Deferred; } });
|
|
24
24
|
__exportStar(require("./misc"), exports);
|
|
25
25
|
__exportStar(require("./serialization"), exports);
|
|
26
|
+
var try_read_file_1 = require("./try-read-file");
|
|
27
|
+
Object.defineProperty(exports, "tryReadFile", { enumerable: true, get: function () { return try_read_file_1.tryReadFile; } });
|
|
28
|
+
var readdir_recursive_1 = require("./readdir-recursive");
|
|
29
|
+
Object.defineProperty(exports, "readdirRecursive", { enumerable: true, get: function () { return readdir_recursive_1.readdirRecursive; } });
|
|
26
30
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAyC;AAAhC,uGAAA,aAAa,OAAA;AAEtB,iEAAsD;AAA7C,oHAAA,WAAW,OAAA;AAEpB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AAIjB,yCAAuB;AACvB,kDAAgC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mCAAyC;AAAhC,uGAAA,aAAa,OAAA;AAEtB,iEAAsD;AAA7C,oHAAA,WAAW,OAAA;AAEpB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AAIjB,yCAAuB;AACvB,kDAAgC;AAEhC,iDAA8C;AAArC,4GAAA,WAAW,OAAA;AACpB,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readdirRecursive = readdirRecursive;
|
|
7
|
+
const promises_1 = require("node:fs/promises");
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
/**
|
|
10
|
+
* Функция для рекурсивного чтения указанной директории
|
|
11
|
+
* @param dir - директория для чтения файлов
|
|
12
|
+
* @returns Список находящихся в директории файлов и информации о них
|
|
13
|
+
*/
|
|
14
|
+
async function readdirRecursive(dir) {
|
|
15
|
+
const result = [];
|
|
16
|
+
for (const file of await (0, promises_1.readdir)(dir)) {
|
|
17
|
+
const filepath = node_path_1.default.resolve(dir, file);
|
|
18
|
+
const s = await (0, promises_1.stat)(filepath);
|
|
19
|
+
if (s.isFile()) {
|
|
20
|
+
result.push(file);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
if (s.isDirectory()) {
|
|
24
|
+
const subfiles = await readdirRecursive(filepath);
|
|
25
|
+
result.push(...subfiles.map((x) => node_path_1.default.resolve(file, x)));
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Симлинки игнорируем
|
|
30
|
+
*/
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=readdir-recursive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readdir-recursive.js","sourceRoot":"","sources":["../src/readdir-recursive.ts"],"names":[],"mappings":";;;;;AAQA,4CAyBC;AAjCD,+CAAiD;AACjD,0DAA6B;AAE7B;;;;GAIG;AACI,KAAK,UAAU,gBAAgB,CAAC,GAAW;IAChD,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,KAAK,MAAM,IAAI,IAAI,MAAM,IAAA,kBAAO,EAAC,GAAG,CAAC,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAG,mBAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACzC,MAAM,CAAC,GAAG,MAAM,IAAA,eAAI,EAAC,QAAQ,CAAC,CAAC;QAE/B,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClB,MAAM;QACR,CAAC;QAED,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;YACpB,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,QAAQ,CAAC,CAAC;YAElD,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,mBAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,MAAM;QACR,CAAC;QAED;;WAEG;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Abortable } from 'node:events';
|
|
2
|
+
import type { ObjectEncodingOptions, OpenMode, PathLike } from 'node:fs';
|
|
3
|
+
export declare function tryReadFile(path: PathLike, options?: (ObjectEncodingOptions & Abortable & {
|
|
4
|
+
flag?: OpenMode | undefined;
|
|
5
|
+
}) | BufferEncoding | null): Promise<string | undefined>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tryReadFile = tryReadFile;
|
|
4
|
+
const promises_1 = require("node:fs/promises");
|
|
5
|
+
function isErrorWithCode(e) {
|
|
6
|
+
return e instanceof Error && 'code' in e && typeof e.code === 'string';
|
|
7
|
+
}
|
|
8
|
+
async function tryReadFile(path, options) {
|
|
9
|
+
try {
|
|
10
|
+
await (0, promises_1.access)(path, promises_1.constants.R_OK);
|
|
11
|
+
const buf = await (0, promises_1.readFile)(path, options);
|
|
12
|
+
return buf.toString();
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (isErrorWithCode(error) && error.code === 'ENOENT') {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=try-read-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"try-read-file.js","sourceRoot":"","sources":["../src/try-read-file.ts"],"names":[],"mappings":";;AAUA,kCAsBC;AA9BD,+CAA+D;AAI/D,SAAS,eAAe,CAAC,CAAU;IACjC,OAAO,CAAC,YAAY,KAAK,IAAI,MAAM,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;AACzE,CAAC;AAEM,KAAK,UAAU,WAAW,CAC/B,IAAc,EACd,OAMQ;IAER,IAAI,CAAC;QACH,MAAM,IAAA,iBAAM,EAAC,IAAI,EAAE,oBAAS,CAAC,IAAI,CAAC,CAAC;QACnC,MAAM,GAAG,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAE1C,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,eAAe,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtD,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdk/common.node",
|
|
3
|
-
"version": "5.11.0-next.
|
|
3
|
+
"version": "5.11.0-next.3",
|
|
4
4
|
"description": "Useful common classes, functions and types",
|
|
5
5
|
"license": "Apache License 2.0",
|
|
6
6
|
"publishConfig": {
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"rxjs": "^7.1.0"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "aa43c0b62a5a8fb72694f3d9112ab19960e30265"
|
|
25
25
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { readdir, stat } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Функция для рекурсивного чтения указанной директории
|
|
6
|
+
* @param dir - директория для чтения файлов
|
|
7
|
+
* @returns Список находящихся в директории файлов и информации о них
|
|
8
|
+
*/
|
|
9
|
+
export async function readdirRecursive(dir: string): Promise<string[]> {
|
|
10
|
+
const result: string[] = [];
|
|
11
|
+
|
|
12
|
+
for (const file of await readdir(dir)) {
|
|
13
|
+
const filepath = path.resolve(dir, file);
|
|
14
|
+
const s = await stat(filepath);
|
|
15
|
+
|
|
16
|
+
if (s.isFile()) {
|
|
17
|
+
result.push(file);
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (s.isDirectory()) {
|
|
22
|
+
const subfiles = await readdirRecursive(filepath);
|
|
23
|
+
|
|
24
|
+
result.push(...subfiles.map((x) => path.resolve(file, x)));
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Симлинки игнорируем
|
|
30
|
+
*/
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Abortable } from 'node:events';
|
|
2
|
+
import type { ObjectEncodingOptions, OpenMode, PathLike } from 'node:fs';
|
|
3
|
+
import { access, constants, readFile } from 'node:fs/promises';
|
|
4
|
+
|
|
5
|
+
type ErrorWithCode = Error & { code: string };
|
|
6
|
+
|
|
7
|
+
function isErrorWithCode(e: unknown): e is ErrorWithCode {
|
|
8
|
+
return e instanceof Error && 'code' in e && typeof e.code === 'string';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function tryReadFile(
|
|
12
|
+
path: PathLike,
|
|
13
|
+
options?:
|
|
14
|
+
| (ObjectEncodingOptions &
|
|
15
|
+
Abortable & {
|
|
16
|
+
flag?: OpenMode | undefined;
|
|
17
|
+
})
|
|
18
|
+
| BufferEncoding
|
|
19
|
+
| null,
|
|
20
|
+
): Promise<string | undefined> {
|
|
21
|
+
try {
|
|
22
|
+
await access(path, constants.R_OK);
|
|
23
|
+
const buf = await readFile(path, options);
|
|
24
|
+
|
|
25
|
+
return buf.toString();
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (isErrorWithCode(error) && error.code === 'ENOENT') {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|