memfs 3.5.0 → 3.5.2

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/node.d.ts CHANGED
@@ -9,17 +9,31 @@ export declare const SEP = "/";
9
9
  */
10
10
  export declare class Node extends EventEmitter {
11
11
  ino: number;
12
- uid: number;
13
- gid: number;
14
- atime: Date;
15
- mtime: Date;
16
- ctime: Date;
12
+ private _uid;
13
+ private _gid;
14
+ private _atime;
15
+ private _mtime;
16
+ private _ctime;
17
17
  buf: Buffer;
18
- perm: number;
18
+ private _perm;
19
19
  mode: number;
20
- nlink: number;
20
+ private _nlink;
21
21
  symlink: string[];
22
22
  constructor(ino: number, perm?: number);
23
+ set ctime(ctime: Date);
24
+ get ctime(): Date;
25
+ set uid(uid: number);
26
+ get uid(): number;
27
+ set gid(gid: number);
28
+ get gid(): number;
29
+ set atime(atime: Date);
30
+ get atime(): Date;
31
+ set mtime(mtime: Date);
32
+ get mtime(): Date;
33
+ set perm(perm: number);
34
+ get perm(): number;
35
+ set nlink(nlink: number);
36
+ get nlink(): number;
23
37
  getString(encoding?: string): string;
24
38
  setString(str: string): void;
25
39
  getBuffer(): Buffer;
package/lib/node.js CHANGED
@@ -34,22 +34,99 @@ var Node = /** @class */ (function (_super) {
34
34
  if (perm === void 0) { perm = 438; }
35
35
  var _this = _super.call(this) || this;
36
36
  // User ID and group ID.
37
- _this.uid = getuid();
38
- _this.gid = getgid();
39
- _this.atime = new Date();
40
- _this.mtime = new Date();
41
- _this.ctime = new Date();
42
- _this.perm = 438; // Permissions `chmod`, `fchmod`
37
+ _this._uid = getuid();
38
+ _this._gid = getgid();
39
+ _this._atime = new Date();
40
+ _this._mtime = new Date();
41
+ _this._ctime = new Date();
42
+ _this._perm = 438; // Permissions `chmod`, `fchmod`
43
43
  _this.mode = S_IFREG; // S_IFDIR, S_IFREG, etc.. (file by default?)
44
44
  // Number of hard links pointing at this Node.
45
- _this.nlink = 1;
46
- _this.perm = perm;
45
+ _this._nlink = 1;
46
+ _this._perm = perm;
47
47
  _this.mode |= perm;
48
48
  _this.ino = ino;
49
49
  return _this;
50
50
  }
51
+ Object.defineProperty(Node.prototype, "ctime", {
52
+ get: function () {
53
+ return this._ctime;
54
+ },
55
+ set: function (ctime) {
56
+ this._ctime = ctime;
57
+ },
58
+ enumerable: false,
59
+ configurable: true
60
+ });
61
+ Object.defineProperty(Node.prototype, "uid", {
62
+ get: function () {
63
+ return this._uid;
64
+ },
65
+ set: function (uid) {
66
+ this._uid = uid;
67
+ this.ctime = new Date();
68
+ },
69
+ enumerable: false,
70
+ configurable: true
71
+ });
72
+ Object.defineProperty(Node.prototype, "gid", {
73
+ get: function () {
74
+ return this._gid;
75
+ },
76
+ set: function (gid) {
77
+ this._gid = gid;
78
+ this.ctime = new Date();
79
+ },
80
+ enumerable: false,
81
+ configurable: true
82
+ });
83
+ Object.defineProperty(Node.prototype, "atime", {
84
+ get: function () {
85
+ return this._atime;
86
+ },
87
+ set: function (atime) {
88
+ this._atime = atime;
89
+ this.ctime = new Date();
90
+ },
91
+ enumerable: false,
92
+ configurable: true
93
+ });
94
+ Object.defineProperty(Node.prototype, "mtime", {
95
+ get: function () {
96
+ return this._mtime;
97
+ },
98
+ set: function (mtime) {
99
+ this._mtime = mtime;
100
+ this.ctime = new Date();
101
+ },
102
+ enumerable: false,
103
+ configurable: true
104
+ });
105
+ Object.defineProperty(Node.prototype, "perm", {
106
+ get: function () {
107
+ return this._perm;
108
+ },
109
+ set: function (perm) {
110
+ this._perm = perm;
111
+ this.ctime = new Date();
112
+ },
113
+ enumerable: false,
114
+ configurable: true
115
+ });
116
+ Object.defineProperty(Node.prototype, "nlink", {
117
+ get: function () {
118
+ return this._nlink;
119
+ },
120
+ set: function (nlink) {
121
+ this._nlink = nlink;
122
+ this.ctime = new Date();
123
+ },
124
+ enumerable: false,
125
+ configurable: true
126
+ });
51
127
  Node.prototype.getString = function (encoding) {
52
128
  if (encoding === void 0) { encoding = 'utf8'; }
129
+ this.atime = new Date();
53
130
  return this.getBuffer().toString(encoding);
54
131
  };
55
132
  Node.prototype.setString = function (str) {
@@ -58,6 +135,7 @@ var Node = /** @class */ (function (_super) {
58
135
  this.touch();
59
136
  };
60
137
  Node.prototype.getBuffer = function () {
138
+ this.atime = new Date();
61
139
  if (!this.buf)
62
140
  this.setBuffer((0, buffer_1.bufferAllocUnsafe)(0));
63
141
  return (0, buffer_1.bufferFrom)(this.buf); // Return a copy.
@@ -115,6 +193,7 @@ var Node = /** @class */ (function (_super) {
115
193
  if (off === void 0) { off = 0; }
116
194
  if (len === void 0) { len = buf.byteLength; }
117
195
  if (pos === void 0) { pos = 0; }
196
+ this.atime = new Date();
118
197
  if (!this.buf)
119
198
  this.buf = (0, buffer_1.bufferAllocUnsafe)(0);
120
199
  var actualLen = len;
@@ -244,9 +323,12 @@ var Link = /** @class */ (function (_super) {
244
323
  // Recursively sync children steps, e.g. in case of dir rename
245
324
  set: function (val) {
246
325
  this._steps = val;
247
- for (var _i = 0, _a = Object.values(this.children); _i < _a.length; _i++) {
248
- var child = _a[_i];
249
- child === null || child === void 0 ? void 0 : child.syncSteps();
326
+ for (var _i = 0, _a = Object.entries(this.children); _i < _a.length; _i++) {
327
+ var _b = _a[_i], child = _b[0], link = _b[1];
328
+ if (child === '.' || child === '..') {
329
+ continue;
330
+ }
331
+ link === null || link === void 0 ? void 0 : link.syncSteps();
250
332
  }
251
333
  },
252
334
  enumerable: false,
@@ -264,10 +346,8 @@ var Link = /** @class */ (function (_super) {
264
346
  var link = new Link(this.vol, this, name);
265
347
  link.setNode(node);
266
348
  if (node.isDirectory()) {
267
- // link.setChild('.', link);
268
- // link.getNode().nlink++;
269
- // link.setChild('..', this);
270
- // this.getNode().nlink++;
349
+ link.children['.'] = link;
350
+ link.getNode().nlink++;
271
351
  }
272
352
  this.setChild(name, link);
273
353
  return link;
@@ -277,15 +357,28 @@ var Link = /** @class */ (function (_super) {
277
357
  this.children[name] = link;
278
358
  link.parent = this;
279
359
  this.length++;
360
+ var node = link.getNode();
361
+ if (node.isDirectory()) {
362
+ link.children['..'] = this;
363
+ this.getNode().nlink++;
364
+ }
365
+ this.getNode().mtime = new Date();
280
366
  this.emit('child:add', link, this);
281
367
  return link;
282
368
  };
283
369
  Link.prototype.deleteChild = function (link) {
370
+ var node = link.getNode();
371
+ if (node.isDirectory()) {
372
+ delete link.children['..'];
373
+ this.getNode().nlink--;
374
+ }
284
375
  delete this.children[link.getName()];
285
376
  this.length--;
377
+ this.getNode().mtime = new Date();
286
378
  this.emit('child:delete', link, this);
287
379
  };
288
380
  Link.prototype.getChild = function (name) {
381
+ this.getNode().mtime = new Date();
289
382
  if (Object.hasOwnProperty.call(this.children, name)) {
290
383
  return this.children[name];
291
384
  }
package/lib/volume.js CHANGED
@@ -500,10 +500,10 @@ var Volume = /** @class */ (function () {
500
500
  }
501
501
  return FSWatcher;
502
502
  }(FSWatcher));
503
- // root.setChild('.', root);
504
- // root.getNode().nlink++;
505
- // root.setChild('..', root);
506
- // root.getNode().nlink++;
503
+ root.setChild('.', root);
504
+ root.getNode().nlink++;
505
+ root.setChild('..', root);
506
+ root.getNode().nlink++;
507
507
  this.root = root;
508
508
  }
509
509
  Volume.fromJSON = function (json, cwd) {
@@ -715,6 +715,9 @@ var Volume = /** @class */ (function () {
715
715
  link = link.parent;
716
716
  }
717
717
  for (var name_1 in children) {
718
+ if (name_1 === '.' || name_1 === '..') {
719
+ continue;
720
+ }
718
721
  isEmpty = false;
719
722
  var child = link.getChild(name_1);
720
723
  if (!child) {
@@ -1423,7 +1426,7 @@ var Volume = /** @class */ (function () {
1423
1426
  var list_1 = [];
1424
1427
  for (var name_2 in link.children) {
1425
1428
  var child = link.getChild(name_2);
1426
- if (!child) {
1429
+ if (!child || name_2 === '.' || name_2 === '..') {
1427
1430
  continue;
1428
1431
  }
1429
1432
  list_1.push(Dirent_1.default.build(child, options.encoding));
@@ -1440,6 +1443,9 @@ var Volume = /** @class */ (function () {
1440
1443
  }
1441
1444
  var list = [];
1442
1445
  for (var name_3 in link.children) {
1446
+ if (name_3 === '.' || name_3 === '..') {
1447
+ continue;
1448
+ }
1443
1449
  list.push((0, encoding_1.strToEncoding)(name_3, options.encoding));
1444
1450
  }
1445
1451
  if (!isWin && options.encoding !== 'buffer')
@@ -2273,7 +2279,13 @@ var FSWatcher = /** @class */ (function (_super) {
2273
2279
  var _a;
2274
2280
  var filepath = link.getPath();
2275
2281
  var node = link.getNode();
2276
- var onNodeChange = function () { return _this.emit('change', 'change', relative(_this._filename, filepath)); };
2282
+ var onNodeChange = function () {
2283
+ var filename = relative(_this._filename, filepath);
2284
+ if (!filename) {
2285
+ filename = _this._getName();
2286
+ }
2287
+ return _this.emit('change', 'change', filename);
2288
+ };
2277
2289
  node.on('change', onNodeChange);
2278
2290
  var removers = (_a = _this._listenerRemovers.get(node.ino)) !== null && _a !== void 0 ? _a : [];
2279
2291
  removers.push(function () { return node.removeListener('change', onNodeChange); });
@@ -2312,8 +2324,9 @@ var FSWatcher = /** @class */ (function (_super) {
2312
2324
  _this.emit('change', 'rename', relative(_this._filename, l.getPath()));
2313
2325
  };
2314
2326
  // children nodes changed
2315
- Object.values(link.children).forEach(function (childLink) {
2316
- if (childLink) {
2327
+ Object.entries(link.children).forEach(function (_a) {
2328
+ var name = _a[0], childLink = _a[1];
2329
+ if (childLink && name !== '.' && name !== '..') {
2317
2330
  watchLinkNodeChanged(childLink);
2318
2331
  }
2319
2332
  });
@@ -2326,8 +2339,9 @@ var FSWatcher = /** @class */ (function (_super) {
2326
2339
  link.removeListener('child:delete', onLinkChildDelete);
2327
2340
  });
2328
2341
  if (recursive) {
2329
- Object.values(link.children).forEach(function (childLink) {
2330
- if (childLink) {
2342
+ Object.entries(link.children).forEach(function (_a) {
2343
+ var name = _a[0], childLink = _a[1];
2344
+ if (childLink && name !== '.' && name !== '..') {
2331
2345
  watchLinkChildrenChanged(childLink);
2332
2346
  }
2333
2347
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memfs",
3
- "version": "3.5.0",
3
+ "version": "3.5.2",
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",