memfs 3.4.11 → 3.4.13

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/lib/Stats.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Node } from './node';
2
- export declare type TStatNumber = number | bigint;
2
+ export type TStatNumber = number | bigint;
3
3
  /**
4
4
  * Statistics about a file/directory, like `fs.Stats`.
5
5
  */
package/lib/encoding.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
- export declare type TDataOut = string | Buffer;
3
- export declare type TEncodingExtended = BufferEncoding | 'buffer';
2
+ export type TDataOut = string | Buffer;
3
+ export type TEncodingExtended = BufferEncoding | 'buffer';
4
4
  export declare const ENCODING_UTF8: BufferEncoding;
5
5
  export declare function assertEncoding(encoding: string | undefined): void;
6
6
  export declare function strToEncoding(str: string, encoding?: TEncodingExtended): TDataOut;
package/lib/promises.d.ts CHANGED
@@ -28,7 +28,7 @@ export interface IFileHandle {
28
28
  write(buffer: Buffer | Uint8Array, offset?: number, length?: number, position?: number): Promise<TFileHandleWriteResult>;
29
29
  writeFile(data: TData, options?: IWriteFileOptions): Promise<void>;
30
30
  }
31
- export declare type TFileHandle = PathLike | IFileHandle;
31
+ export type TFileHandle = PathLike | IFileHandle;
32
32
  export interface IPromisesAPI {
33
33
  FileHandle: any;
34
34
  access(path: PathLike, mode?: number): Promise<void>;
@@ -1,3 +1,3 @@
1
- declare type TSetImmediate = (callback: (...args: any[]) => void, args?: any) => void;
1
+ type TSetImmediate = (callback: (...args: any[]) => void, args?: any) => void;
2
2
  declare const _default: TSetImmediate;
3
3
  export default _default;
@@ -1,4 +1,4 @@
1
- export declare type TSetTimeout = (callback: (...args: any[]) => void, time?: number, args?: any[]) => any;
1
+ export type TSetTimeout = (callback: (...args: any[]) => void, time?: number, args?: any[]) => any;
2
2
  /**
3
3
  * `setTimeoutUnref` is just like `setTimeout`,
4
4
  * only in Node's environment it will "unref" its macro task.
package/lib/volume.d.ts CHANGED
@@ -14,12 +14,12 @@ import { TEncodingExtended, TDataOut } from './encoding';
14
14
  export interface IError extends Error {
15
15
  code?: string;
16
16
  }
17
- export declare type TFileId = PathLike | number;
18
- export declare type TData = TDataOut | Uint8Array;
19
- export declare type TFlags = string | number;
20
- export declare type TMode = string | number;
21
- export declare type TTime = number | string | Date;
22
- export declare type TCallback<TData> = (error?: IError | null, data?: TData) => void;
17
+ export type TFileId = PathLike | number;
18
+ export type TData = TDataOut | Uint8Array;
19
+ export type TFlags = string | number;
20
+ export type TMode = string | number;
21
+ export type TTime = number | string | Date;
22
+ export type TCallback<TData> = (error?: IError | null, data?: TData) => void;
23
23
  export declare enum FLAGS {
24
24
  r,
25
25
  'r+',
@@ -40,7 +40,7 @@ export declare enum FLAGS {
40
40
  'ax+',
41
41
  'xa+'
42
42
  }
43
- export declare type TFlagsCopy = typeof constants.COPYFILE_EXCL | typeof constants.COPYFILE_FICLONE | typeof constants.COPYFILE_FICLONE_FORCE;
43
+ export type TFlagsCopy = typeof constants.COPYFILE_EXCL | typeof constants.COPYFILE_FICLONE | typeof constants.COPYFILE_FICLONE_FORCE;
44
44
  export declare function flagsToNumber(flags: TFlags | undefined): number;
45
45
  export interface IOptions {
46
46
  encoding?: BufferEncoding | TEncodingExtended;
@@ -114,7 +114,7 @@ export declare function dataToStr(data: TData, encoding?: string): string;
114
114
  export declare function dataToBuffer(data: TData, encoding?: string): Buffer;
115
115
  export declare function bufferToEncoding(buffer: Buffer, encoding?: TEncodingExtended): TDataOut;
116
116
  export declare function toUnixTimestamp(time: any): any;
117
- declare type DirectoryContent = string | null;
117
+ type DirectoryContent = string | null;
118
118
  export interface DirectoryJSON {
119
119
  [key: string]: DirectoryContent;
120
120
  }
@@ -347,12 +347,24 @@ export declare class Volume {
347
347
  * @param modeNum
348
348
  */
349
349
  private mkdirpBase;
350
- mkdirSync(path: PathLike, options?: TMode | IMkdirOptions): void;
350
+ mkdirSync(path: PathLike, options: IMkdirOptions & {
351
+ recursive: true;
352
+ }): string | undefined;
353
+ mkdirSync(path: PathLike, options?: TMode | (IMkdirOptions & {
354
+ recursive?: false;
355
+ })): void;
356
+ mkdirSync(path: PathLike, options?: TMode | IMkdirOptions): string | undefined;
351
357
  mkdir(path: PathLike, callback: TCallback<void>): any;
352
- mkdir(path: PathLike, mode: TMode | IMkdirOptions, callback: TCallback<void>): any;
353
- mkdirpSync(path: PathLike, mode?: TMode): void;
354
- mkdirp(path: PathLike, callback: TCallback<void>): any;
355
- mkdirp(path: PathLike, mode: TMode, callback: TCallback<void>): any;
358
+ mkdir(path: PathLike, mode: TMode | (IMkdirOptions & {
359
+ recursive?: false;
360
+ }), callback: TCallback<void>): any;
361
+ mkdir(path: PathLike, mode: IMkdirOptions & {
362
+ recursive: true;
363
+ }, callback: TCallback<string>): any;
364
+ mkdir(path: PathLike, mode: TMode | IMkdirOptions, callback: TCallback<string>): any;
365
+ mkdirpSync(path: PathLike, mode?: TMode): string | undefined;
366
+ mkdirp(path: PathLike, callback: TCallback<string>): any;
367
+ mkdirp(path: PathLike, mode: TMode, callback: TCallback<string>): any;
356
368
  private mkdtempBase;
357
369
  mkdtempSync(prefix: string, options?: IOptions): TDataOut;
358
370
  mkdtemp(prefix: string, callback: TCallback<void>): any;
package/lib/volume.js CHANGED
@@ -127,6 +127,9 @@ function createError(errorCode, func, path, path2, Constructor) {
127
127
  if (Constructor === void 0) { Constructor = Error; }
128
128
  var error = new Constructor(formatError(errorCode, func, path, path2));
129
129
  error.code = errorCode;
130
+ if (path) {
131
+ error.path = path;
132
+ }
130
133
  return error;
131
134
  }
132
135
  // ---------------------------------------- Flags
@@ -313,7 +316,7 @@ if (isWin) {
313
316
  }
314
317
  function filenameToSteps(filename, base) {
315
318
  var fullPath = resolve(filename, base);
316
- var fullPathSansSlash = fullPath.substr(1);
319
+ var fullPathSansSlash = fullPath.substring(1);
317
320
  if (!fullPathSansSlash)
318
321
  return [];
319
322
  return fullPathSansSlash.split(sep);
@@ -571,7 +574,7 @@ var Volume = /** @class */ (function () {
571
574
  };
572
575
  // Generates 6 character long random string, used by `mkdtemp`.
573
576
  Volume.prototype.genRndStr = function () {
574
- var str = (Math.random() + 1).toString(36).substr(2, 6);
577
+ var str = (Math.random() + 1).toString(36).substring(2, 8);
575
578
  if (str.length === 6)
576
579
  return str;
577
580
  else
@@ -1568,8 +1571,11 @@ var Volume = /** @class */ (function () {
1568
1571
  * @param modeNum
1569
1572
  */
1570
1573
  Volume.prototype.mkdirpBase = function (filename, modeNum) {
1571
- var steps = filenameToSteps(filename);
1574
+ var fullPath = resolve(filename);
1575
+ var fullPathSansSlash = fullPath.substring(1);
1576
+ var steps = !fullPathSansSlash ? [] : fullPathSansSlash.split(sep);
1572
1577
  var link = this.root;
1578
+ var created = false;
1573
1579
  for (var i = 0; i < steps.length; i++) {
1574
1580
  var step = steps[i];
1575
1581
  if (!link.getNode().isDirectory())
@@ -1583,17 +1589,18 @@ var Volume = /** @class */ (function () {
1583
1589
  }
1584
1590
  else {
1585
1591
  link = link.createChild(step, this.createNode(true, modeNum));
1592
+ created = true;
1586
1593
  }
1587
1594
  }
1595
+ return created ? fullPath : undefined;
1588
1596
  };
1589
1597
  Volume.prototype.mkdirSync = function (path, options) {
1590
1598
  var opts = getMkdirOptions(options);
1591
1599
  var modeNum = modeToNumber(opts.mode, 511);
1592
1600
  var filename = pathToFilename(path);
1593
1601
  if (opts.recursive)
1594
- this.mkdirpBase(filename, modeNum);
1595
- else
1596
- this.mkdirBase(filename, modeNum);
1602
+ return this.mkdirpBase(filename, modeNum);
1603
+ this.mkdirBase(filename, modeNum);
1597
1604
  };
1598
1605
  Volume.prototype.mkdir = function (path, a, b) {
1599
1606
  var opts = getMkdirOptions(a);
@@ -1607,7 +1614,7 @@ var Volume = /** @class */ (function () {
1607
1614
  };
1608
1615
  // legacy interface
1609
1616
  Volume.prototype.mkdirpSync = function (path, mode) {
1610
- this.mkdirSync(path, { mode: mode, recursive: true });
1617
+ return this.mkdirSync(path, { mode: mode, recursive: true });
1611
1618
  };
1612
1619
  Volume.prototype.mkdirp = function (path, a, b) {
1613
1620
  var mode = typeof a === 'function' ? undefined : a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memfs",
3
- "version": "3.4.11",
3
+ "version": "3.4.13",
4
4
  "description": "In-memory file-system with Node's fs API.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",