memfs 3.1.0 → 3.2.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,36 @@
1
+ # [3.2.0](https://github.com/streamich/memfs/compare/v3.1.3...v3.2.0) (2020-05-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 'fromJSON()' did not consider cwd when creating directories ([3d6ee3b](https://github.com/streamich/memfs/commit/3d6ee3b2c0eef0345ba2bd400e9836f2d685321f))
7
+
8
+
9
+ ### Features
10
+
11
+ * support nested objects in 'fromJSON()' ([f8c329c](https://github.com/streamich/memfs/commit/f8c329c8e57c85cc4a394a74802af1f37dcedefd))
12
+
13
+ ## [3.1.3](https://github.com/streamich/memfs/compare/v3.1.2...v3.1.3) (2020-05-14)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * **deps:** update dependency fs-monkey to v1.0.1 ([10fc705](https://github.com/streamich/memfs/commit/10fc705c46d57a4354afb9372a98dcdfed9d551d))
19
+
20
+ ## [3.1.2](https://github.com/streamich/memfs/compare/v3.1.1...v3.1.2) (2020-03-12)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * should throw `EEXIST` instead of `EISDIR` on `mkdirSync('/')` ([f89eede](https://github.com/streamich/memfs/commit/f89eede9530c3f5bd8d8a523be1927d396cda662))
26
+
27
+ ## [3.1.1](https://github.com/streamich/memfs/compare/v3.1.0...v3.1.1) (2020-02-17)
28
+
29
+
30
+ ### Bug Fixes
31
+
32
+ * **deps:** update dependency fs-monkey to v1 ([ccd1be0](https://github.com/streamich/memfs/commit/ccd1be08c5b13dd620ed814def1a84b81614cab2))
33
+
1
34
  # [3.1.0](https://github.com/streamich/memfs/compare/v3.0.6...v3.1.0) (2020-02-17)
2
35
 
3
36
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # memfs
2
2
 
3
- [![][npm-badge]][npm-url] [![][travis-badge]][travis-url]
3
+ [![][chat-badge]][chat] [![][npm-badge]][npm-url] [![][travis-badge]][travis-url]
4
4
 
5
5
  In-memory file-system with [Node's `fs` API](https://nodejs.org/api/fs.html).
6
6
 
@@ -107,6 +107,8 @@ require('/index'); // hi world
107
107
  - [`fs-monkey`][fs-monkey] - monkey-patches Node's `fs` module and `require` function
108
108
  - [`libfs`](https://github.com/streamich/full-js/blob/master/src/lib/fs.ts) - real filesystem (that executes UNIX system calls) implemented in JavaScript
109
109
 
110
+ [chat]: https://onp4.com/@vadim/~memfs
111
+ [chat-badge]: https://img.shields.io/badge/Chat-%F0%9F%92%AC-green?style=flat&logo=chat&link=https://onp4.com/@vadim/~memfs
110
112
  [npm-url]: https://www.npmjs.com/package/memfs
111
113
  [npm-badge]: https://img.shields.io/npm/v/memfs.svg
112
114
  [travis-url]: https://travis-ci.org/streamich/memfs
package/lib/Dirent.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Dirent = void 0;
3
4
  var constants_1 = require("./constants");
4
5
  var encoding_1 = require("./encoding");
5
6
  var S_IFMT = constants_1.constants.S_IFMT, S_IFDIR = constants_1.constants.S_IFDIR, S_IFREG = constants_1.constants.S_IFREG, S_IFBLK = constants_1.constants.S_IFBLK, S_IFCHR = constants_1.constants.S_IFCHR, S_IFLNK = constants_1.constants.S_IFLNK, S_IFIFO = constants_1.constants.S_IFIFO, S_IFSOCK = constants_1.constants.S_IFSOCK;
package/lib/Stats.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Stats = void 0;
3
4
  var constants_1 = require("./constants");
4
5
  var getBigInt_1 = require("./getBigInt");
5
6
  var S_IFMT = constants_1.constants.S_IFMT, S_IFDIR = constants_1.constants.S_IFDIR, S_IFREG = constants_1.constants.S_IFREG, S_IFBLK = constants_1.constants.S_IFBLK, S_IFCHR = constants_1.constants.S_IFCHR, S_IFLNK = constants_1.constants.S_IFLNK, S_IFIFO = constants_1.constants.S_IFIFO, S_IFSOCK = constants_1.constants.S_IFSOCK;
package/lib/constants.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.constants = void 0;
3
4
  exports.constants = {
4
5
  O_RDONLY: 0,
5
6
  O_WRONLY: 1,
package/lib/encoding.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.strToEncoding = exports.assertEncoding = exports.ENCODING_UTF8 = void 0;
3
4
  var buffer_1 = require("./internal/buffer");
4
5
  var errors = require("./internal/errors");
5
6
  exports.ENCODING_UTF8 = 'utf8';
package/lib/index.js CHANGED
@@ -11,6 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.fs = exports.createFsFromVolume = exports.vol = exports.Volume = void 0;
14
15
  var Stats_1 = require("./Stats");
15
16
  var Dirent_1 = require("./Dirent");
16
17
  var volume_1 = require("./volume");
@@ -7,8 +7,9 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
7
7
  return r;
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.bufferFrom = exports.bufferAllocUnsafe = exports.Buffer = void 0;
10
11
  var buffer_1 = require("buffer");
11
- exports.Buffer = buffer_1.Buffer;
12
+ Object.defineProperty(exports, "Buffer", { enumerable: true, get: function () { return buffer_1.Buffer; } });
12
13
  function bufferV0P12Ponyfill(arg0) {
13
14
  var args = [];
14
15
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -18,6 +18,7 @@ var __extends = (this && this.__extends) || (function () {
18
18
  };
19
19
  })();
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.E = exports.AssertionError = exports.message = exports.RangeError = exports.TypeError = exports.Error = void 0;
21
22
  var assert = require("assert");
22
23
  var util = require("util");
23
24
  var kCode = typeof Symbol === 'undefined' ? '_kCode' : Symbol('code');
package/lib/node.js CHANGED
@@ -13,6 +13,7 @@ var __extends = (this && this.__extends) || (function () {
13
13
  };
14
14
  })();
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.File = exports.Link = exports.Node = exports.SEP = void 0;
16
17
  var process_1 = require("./process");
17
18
  var buffer_1 = require("./internal/buffer");
18
19
  var constants_1 = require("./constants");
package/lib/process.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  // Here we mock the global `process` variable in case we are not in Node's environment.
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createProcess = void 0;
4
5
  /**
5
6
  * Looks to return a `process` object, if one is available.
6
7
  *
package/lib/promises.js CHANGED
@@ -7,6 +7,7 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
7
7
  return r;
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.FileHandle = void 0;
10
11
  function promisify(vol, fn, getResult) {
11
12
  if (getResult === void 0) { getResult = function (input) { return input; }; }
12
13
  return function () {
@@ -13,6 +13,7 @@ var __extends = (this && this.__extends) || (function () {
13
13
  };
14
14
  })();
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.createVolume = exports.ObjectStore = void 0;
16
17
  var volume_1 = require("./volume");
17
18
  var node_1 = require("./node");
18
19
  var ObjectStore = /** @class */ (function () {
@@ -49,7 +50,7 @@ function createVolume(namespace, LS) {
49
50
  this._key = key('ino', this.ino);
50
51
  return this._key;
51
52
  },
52
- enumerable: true,
53
+ enumerable: false,
53
54
  configurable: true
54
55
  });
55
56
  NodeLocalStorage.prototype.sync = function () {
@@ -76,7 +77,7 @@ function createVolume(namespace, LS) {
76
77
  this._key = key('link', this.getPath());
77
78
  return this._key;
78
79
  },
79
- enumerable: true,
80
+ enumerable: false,
80
81
  configurable: true
81
82
  });
82
83
  LinkLocalStorage.prototype.sync = function () {
package/lib/volume.d.ts CHANGED
@@ -101,12 +101,19 @@ export declare function dataToStr(data: TData, encoding?: string): string;
101
101
  export declare function dataToBuffer(data: TData, encoding?: string): Buffer;
102
102
  export declare function bufferToEncoding(buffer: Buffer, encoding?: TEncodingExtended): TDataOut;
103
103
  export declare function toUnixTimestamp(time: any): any;
104
- export declare type DirectoryJSON = Record<string, string | null>;
104
+ declare type DirectoryContent = string | null;
105
+ export interface DirectoryJSON {
106
+ [key: string]: DirectoryContent;
107
+ }
108
+ export interface NestedDirectoryJSON {
109
+ [key: string]: DirectoryContent | NestedDirectoryJSON;
110
+ }
105
111
  /**
106
112
  * `Volume` represents a file system.
107
113
  */
108
114
  export declare class Volume {
109
115
  static fromJSON(json: DirectoryJSON, cwd?: string): Volume;
116
+ static fromNestedJSON(json: NestedDirectoryJSON, cwd?: string): Volume;
110
117
  /**
111
118
  * Global file descriptor counter. UNIX file descriptors start from 0 and go sequentially
112
119
  * up, so here, in order not to conflict with them, we choose some big number and descrease
@@ -163,6 +170,7 @@ export declare class Volume {
163
170
  private _toJSON;
164
171
  toJSON(paths?: PathLike | PathLike[], json?: {}, isRelative?: boolean): DirectoryJSON;
165
172
  fromJSON(json: DirectoryJSON, cwd?: string): void;
173
+ fromNestedJSON(json: NestedDirectoryJSON, cwd?: string): void;
166
174
  reset(): void;
167
175
  mountSync(mountpoint: string, json: DirectoryJSON): void;
168
176
  private openLink;
@@ -378,3 +386,4 @@ export declare class FSWatcher extends EventEmitter {
378
386
  start(path: PathLike, persistent?: boolean, recursive?: boolean, encoding?: BufferEncoding): void;
379
387
  close(): void;
380
388
  }
389
+ export {};
package/lib/volume.js CHANGED
@@ -20,6 +20,7 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
20
20
  return r;
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.FSWatcher = exports.StatWatcher = exports.Volume = exports.toUnixTimestamp = exports.bufferToEncoding = exports.dataToBuffer = exports.dataToStr = exports.pathToSteps = exports.filenameToSteps = exports.pathToFilename = exports.flagsToNumber = exports.FLAGS = void 0;
23
24
  var pathModule = require("path");
24
25
  var node_1 = require("./node");
25
26
  var Stats_1 = require("./Stats");
@@ -37,17 +38,7 @@ var util = require("util");
37
38
  var promises_1 = require("./promises");
38
39
  var resolveCrossPlatform = pathModule.resolve;
39
40
  var O_RDONLY = constants_1.constants.O_RDONLY, O_WRONLY = constants_1.constants.O_WRONLY, O_RDWR = constants_1.constants.O_RDWR, O_CREAT = constants_1.constants.O_CREAT, O_EXCL = constants_1.constants.O_EXCL, O_TRUNC = constants_1.constants.O_TRUNC, O_APPEND = constants_1.constants.O_APPEND, O_SYNC = constants_1.constants.O_SYNC, O_DIRECTORY = constants_1.constants.O_DIRECTORY, F_OK = constants_1.constants.F_OK, COPYFILE_EXCL = constants_1.constants.COPYFILE_EXCL, COPYFILE_FICLONE_FORCE = constants_1.constants.COPYFILE_FICLONE_FORCE;
40
- var sep;
41
- var relative;
42
- if (pathModule.posix) {
43
- var posix = pathModule.posix;
44
- sep = posix.sep;
45
- relative = posix.relative;
46
- }
47
- else {
48
- sep = pathModule.sep;
49
- relative = pathModule.relative;
50
- }
41
+ var _a = pathModule.posix ? pathModule.posix : pathModule, sep = _a.sep, relative = _a.relative, join = _a.join, dirname = _a.dirname;
51
42
  var isWin = process_1.default.platform === 'win32';
52
43
  var kMinPoolSpace = 128;
53
44
  // const kMaxLength = require('buffer').kMaxLength;
@@ -409,6 +400,29 @@ function validateGid(gid) {
409
400
  if (typeof gid !== 'number')
410
401
  throw TypeError(ERRSTR.GID);
411
402
  }
403
+ function flattenJSON(nestedJSON) {
404
+ var flatJSON = {};
405
+ function flatten(pathPrefix, node) {
406
+ for (var path in node) {
407
+ var contentOrNode = node[path];
408
+ var joinedPath = join(pathPrefix, path);
409
+ if (typeof contentOrNode === 'string') {
410
+ flatJSON[joinedPath] = contentOrNode;
411
+ }
412
+ else if (typeof contentOrNode === 'object' && contentOrNode !== null && Object.keys(contentOrNode).length > 0) {
413
+ // empty directories need an explicit entry and therefore get handled in `else`, non-empty ones are implicitly considered
414
+ flatten(joinedPath, contentOrNode);
415
+ }
416
+ else {
417
+ // without this branch null, empty-object or non-object entries would not be handled in the same way
418
+ // by both fromJSON() and fromNestedJSON()
419
+ flatJSON[joinedPath] = null;
420
+ }
421
+ }
422
+ }
423
+ flatten('', nestedJSON);
424
+ return flatJSON;
425
+ }
412
426
  /**
413
427
  * `Volume` represents a file system.
414
428
  */
@@ -485,13 +499,18 @@ var Volume = /** @class */ (function () {
485
499
  vol.fromJSON(json, cwd);
486
500
  return vol;
487
501
  };
502
+ Volume.fromNestedJSON = function (json, cwd) {
503
+ var vol = new Volume();
504
+ vol.fromNestedJSON(json, cwd);
505
+ return vol;
506
+ };
488
507
  Object.defineProperty(Volume.prototype, "promises", {
489
508
  get: function () {
490
509
  if (this.promisesApi === null)
491
510
  throw new Error('Promise is not supported in this environment.');
492
511
  return this.promisesApi;
493
512
  },
494
- enumerable: true,
513
+ enumerable: false,
495
514
  configurable: true
496
515
  });
497
516
  Volume.prototype.createLink = function (parent, name, isDirectory, perm) {
@@ -728,18 +747,14 @@ var Volume = /** @class */ (function () {
728
747
  }
729
748
  return json;
730
749
  };
731
- // fromJSON(json: {[filename: string]: string}, cwd: string = '/') {
732
750
  Volume.prototype.fromJSON = function (json, cwd) {
733
751
  if (cwd === void 0) { cwd = process_1.default.cwd(); }
734
752
  for (var filename in json) {
735
753
  var data = json[filename];
754
+ filename = resolve(filename, cwd);
736
755
  if (typeof data === 'string') {
737
- filename = resolve(filename, cwd);
738
- var steps = filenameToSteps(filename);
739
- if (steps.length > 1) {
740
- var dirname = sep + steps.slice(0, steps.length - 1).join(sep);
741
- this.mkdirpBase(dirname, 511 /* DIR */);
742
- }
756
+ var dir = dirname(filename);
757
+ this.mkdirpBase(dir, 511 /* DIR */);
743
758
  this.writeFileSync(filename, data);
744
759
  }
745
760
  else {
@@ -747,6 +762,9 @@ var Volume = /** @class */ (function () {
747
762
  }
748
763
  }
749
764
  };
765
+ Volume.prototype.fromNestedJSON = function (json, cwd) {
766
+ this.fromJSON(flattenJSON(json), cwd);
767
+ };
750
768
  Volume.prototype.reset = function () {
751
769
  this.ino = 0;
752
770
  this.inodes = {};
@@ -1500,7 +1518,7 @@ var Volume = /** @class */ (function () {
1500
1518
  var steps = filenameToSteps(filename);
1501
1519
  // This will throw if user tries to create root dir `fs.mkdirSync('/')`.
1502
1520
  if (!steps.length) {
1503
- throw createError(EISDIR, 'mkdir', filename);
1521
+ throw createError(EEXIST, 'mkdir', filename);
1504
1522
  }
1505
1523
  var dir = this.getLinkParentAsDirOrThrow(filename, 'mkdir');
1506
1524
  // Check path already exists.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memfs",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
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",
@@ -23,11 +23,11 @@
23
23
  "url": "https://github.com/streamich/memfs.git"
24
24
  },
25
25
  "dependencies": {
26
- "fs-monkey": "0.3.3"
26
+ "fs-monkey": "1.0.1"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/jest": "23.3.14",
30
- "@types/node": "10.17.15",
30
+ "@types/node": "10.17.21",
31
31
  "cpy-cli": "3.1.0",
32
32
  "husky": "3.1.0",
33
33
  "jest": "24.9.0",
@@ -35,10 +35,10 @@
35
35
  "pretty-quick": "2.0.1",
36
36
  "rimraf": "3.0.2",
37
37
  "ts-jest": "24.3.0",
38
- "ts-node": "8.6.2",
38
+ "ts-node": "8.10.1",
39
39
  "tslint": "5.20.1",
40
40
  "tslint-config-common": "1.6.0",
41
- "typescript": "3.7.5",
41
+ "typescript": "3.9.2",
42
42
  "semantic-release": "15.14.0",
43
43
  "@semantic-release/changelog": "3.0.6",
44
44
  "@semantic-release/git": "7.0.18",