core-3nweb-client-lib 0.47.2 → 0.47.4

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,5 +1,5 @@
1
1
  import { Abortable } from 'events';
2
- import type { BufferEncodingOption, Dirent, promises as fsFns, MakeDirectoryOptions, Mode, ObjectEncodingOptions, OpenMode, RmDirOptions, StatOptions, Stats } from 'fs';
2
+ import type { BufferEncodingOption, promises as fsFns, Mode, ObjectEncodingOptions, OpenMode, RmDirOptions, StatOptions, Stats } from 'fs';
3
3
  import { FlagAndOpenMode } from 'fs/promises';
4
4
  import type Stream = require('stream');
5
5
  export type { Stats } from 'fs';
@@ -51,45 +51,17 @@ declare function writeFile(file: string, data: string | NodeJS.ArrayBufferView |
51
51
  declare function appendFile(path: string, data: string | Uint8Array, options?: (ObjectEncodingOptions & FlagAndOpenMode & {
52
52
  flush?: boolean | undefined;
53
53
  }) | BufferEncoding | null): Promise<void>;
54
- declare function mkdir(path: string, options: MakeDirectoryOptions & {
55
- recursive: true;
54
+ declare function mkdir(path: string, options?: {
55
+ recursive?: boolean;
56
56
  }): Promise<string | undefined>;
57
- declare function mkdir(path: string, options?: Mode | (MakeDirectoryOptions & {
58
- recursive?: false | undefined;
59
- }) | null): Promise<void>;
60
- declare function mkdir(path: string, options?: Mode | MakeDirectoryOptions | null): Promise<string | undefined>;
61
57
  declare function open(path: string, flags?: string | number, mode?: Mode): Promise<FileHandle>;
62
58
  declare function symlink(target: string, path: string, type?: string | null): Promise<void>;
63
59
  declare function readlink(path: string, options?: ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
64
60
  declare function readlink(path: string, options: BufferEncodingOption): Promise<Buffer>;
65
61
  declare function readlink(path: string, options?: ObjectEncodingOptions | string | null): Promise<string | Buffer>;
66
- declare function lstat(path: string, opts?: StatOptions & {
67
- bigint?: false | undefined;
68
- }): Promise<Stats>;
69
62
  declare function lstat(path: string, opts?: StatOptions): Promise<Stats>;
70
63
  declare function stat(path: string, opts?: StatOptions): Promise<Stats>;
71
- declare function readdir(path: string, options?: (ObjectEncodingOptions & {
72
- withFileTypes?: false | undefined;
73
- recursive?: boolean | undefined;
74
- }) | BufferEncoding | null): Promise<string[]>;
75
- declare function readdir(path: string, options: {
76
- encoding: "buffer";
77
- withFileTypes?: false | undefined;
78
- recursive?: boolean | undefined;
79
- } | "buffer"): Promise<Buffer[]>;
80
- declare function readdir(path: string, options?: (ObjectEncodingOptions & {
81
- withFileTypes?: false | undefined;
82
- recursive?: boolean | undefined;
83
- }) | BufferEncoding | null): Promise<string[] | Buffer[]>;
84
- declare function readdir(path: string, options: ObjectEncodingOptions & {
85
- withFileTypes: true;
86
- recursive?: boolean | undefined;
87
- }): Promise<Dirent[]>;
88
- declare function readdir(path: string, options: {
89
- encoding: "buffer";
90
- withFileTypes: true;
91
- recursive?: boolean | undefined;
92
- }): Promise<Dirent<Buffer>[]>;
64
+ declare function readdir(path: string): Promise<string[]>;
93
65
  declare function rmdir(path: string, options?: RmDirOptions): Promise<void>;
94
66
  declare function unlink(path: string): Promise<void>;
95
67
  declare function rename(oldPath: string, newPath: string): Promise<void>;
@@ -43,31 +43,26 @@ async function makeFolder(root, path, exclusive = false) {
43
43
  if (path.length === 0) {
44
44
  throw new Error('Invalid file path');
45
45
  }
46
- let pathStr = root;
47
- const lastIndex = path.length - 1;
48
- for (let i = 0; i < path.length; i += 1) {
49
- pathStr += '/' + path[i];
50
- const stats = await fs.lstat(pathStr).catch((exc) => {
46
+ const pathStr = pathMod.join(root, ...path);
47
+ if (exclusive) {
48
+ const stats = await fs.lstat(pathStr).catch(async (exc) => {
51
49
  if (exc.code !== file_1.Code.notFound) {
52
50
  throw (0, file_1.maskPathInExc)(root.length, exc);
53
51
  }
54
- return fs.mkdir(pathStr)
55
- .catch((exc) => {
56
- if (!exc.alreadyExists) {
57
- throw exc;
58
- }
59
- }); // resolves to undefined, leading to !stats
60
52
  });
61
53
  if (!stats) {
62
- continue;
54
+ await fs.mkdir(pathStr, { recursive: true });
63
55
  }
64
- if (!stats.isDirectory()) {
65
- throw (0, file_1.makeFileException)('notDirectory', path.slice(0, i + 1).join('/'));
56
+ else if (!stats.isDirectory()) {
57
+ throw (0, file_1.makeFileException)('notDirectory', path.join('/'));
66
58
  }
67
- else if ((i === lastIndex) && exclusive) {
59
+ else {
68
60
  throw (0, file_1.makeFileException)('alreadyExists', path.join('/'));
69
61
  }
70
62
  }
63
+ else {
64
+ await fs.mkdir(pathStr, { recursive: true });
65
+ }
71
66
  }
72
67
  async function checkPresence(type, root, path, throwIfMissing) {
73
68
  try {
@@ -7,20 +7,9 @@ export type { FileHandle, FileException, Stats } from '../injected-globals/platf
7
7
  */
8
8
  export declare const appendFile: (path: string, data: string | Uint8Array, options?: (import("fs").ObjectEncodingOptions & import("fs/promises").FlagAndOpenMode & {
9
9
  flush?: boolean | undefined;
10
- }) | BufferEncoding | null) => Promise<void>, lstat: {
11
- (path: string, opts?: import("fs").StatOptions & {
12
- bigint?: false | undefined;
13
- }): Promise<import("fs").Stats>;
14
- (path: string, opts?: import("fs").StatOptions): Promise<import("fs").Stats>;
15
- }, mkdir: {
16
- (path: string, options: import("fs").MakeDirectoryOptions & {
17
- recursive: true;
18
- }): Promise<string | undefined>;
19
- (path: string, options?: import("fs").Mode | (import("fs").MakeDirectoryOptions & {
20
- recursive?: false | undefined;
21
- }) | null): Promise<void>;
22
- (path: string, options?: import("fs").Mode | import("fs").MakeDirectoryOptions | null): Promise<string | undefined>;
23
- }, open: (path: string, flags?: string | number, mode?: import("fs").Mode) => Promise<FileHandle>, readFile: {
10
+ }) | BufferEncoding | null) => Promise<void>, lstat: (path: string, opts?: import("fs").StatOptions) => Promise<import("fs").Stats>, mkdir: (path: string, options?: {
11
+ recursive?: boolean;
12
+ }) => Promise<string | undefined>, open: (path: string, flags?: string | number, mode?: import("fs").Mode) => Promise<FileHandle>, readFile: {
24
13
  (path: string, options?: ({
25
14
  encoding?: null | undefined;
26
15
  flag?: import("fs").OpenMode | undefined;
@@ -32,30 +21,7 @@ export declare const appendFile: (path: string, data: string | Uint8Array, optio
32
21
  (path: string, options?: (import("fs").ObjectEncodingOptions & import("events").Abortable & {
33
22
  flag?: import("fs").OpenMode | undefined;
34
23
  }) | BufferEncoding | null): Promise<string | Buffer>;
35
- }, readdir: {
36
- (path: string, options?: (import("fs").ObjectEncodingOptions & {
37
- withFileTypes?: false | undefined;
38
- recursive?: boolean | undefined;
39
- }) | BufferEncoding | null): Promise<string[]>;
40
- (path: string, options: {
41
- encoding: "buffer";
42
- withFileTypes?: false | undefined;
43
- recursive?: boolean | undefined;
44
- } | "buffer"): Promise<Buffer[]>;
45
- (path: string, options?: (import("fs").ObjectEncodingOptions & {
46
- withFileTypes?: false | undefined;
47
- recursive?: boolean | undefined;
48
- }) | BufferEncoding | null): Promise<string[] | Buffer[]>;
49
- (path: string, options: import("fs").ObjectEncodingOptions & {
50
- withFileTypes: true;
51
- recursive?: boolean | undefined;
52
- }): Promise<import("fs").Dirent[]>;
53
- (path: string, options: {
54
- encoding: "buffer";
55
- withFileTypes: true;
56
- recursive?: boolean | undefined;
57
- }): Promise<import("fs").Dirent<Buffer>[]>;
58
- }, readlink: {
24
+ }, readdir: (path: string) => Promise<string[]>, readlink: {
59
25
  (path: string, options?: import("fs").ObjectEncodingOptions | BufferEncoding | null): Promise<string>;
60
26
  (path: string, options: import("fs").BufferEncodingOption): Promise<Buffer>;
61
27
  (path: string, options?: import("fs").ObjectEncodingOptions | string | null): Promise<string | Buffer>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.47.2",
3
+ "version": "0.47.4",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",