mem-fs-editor 7.0.1 → 7.1.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/README.md CHANGED
@@ -106,10 +106,11 @@ Move/rename a file from the `from` path to the `to` path.
106
106
 
107
107
  Returns `true` if a file exists. Returns `false` if the file is not found or deleted.
108
108
 
109
- ### `#commit([filters,] callback)`
109
+ ### `#commit([filters,] [stream,] callback)`
110
110
 
111
111
  Persist every changes made to files in the mem-fs store to disk.
112
112
 
113
113
  If provided, `filters` is an array of TransformStream to be applied on a stream of vinyl files (like gulp plugins).
114
+ If provided, `stream` is a stream of vinyl files.
114
115
 
115
116
  `callback` is called once the files are updated on disk.
@@ -21,14 +21,19 @@ function remove(file) {
21
21
  rimraf.sync(file.path);
22
22
  }
23
23
 
24
- module.exports = function (filters, cb) {
24
+ module.exports = function (filters, stream, cb) {
25
25
  var store = this.store;
26
26
 
27
- if (arguments.length === 1) {
27
+ if (typeof filters === 'function') {
28
28
  cb = filters;
29
29
  filters = [];
30
+ stream = undefined;
31
+ } else if (typeof stream === 'function') {
32
+ cb = stream;
33
+ stream = undefined;
30
34
  }
31
35
 
36
+ stream = stream || this.store.stream();
32
37
  var modifiedFilter = through.obj(function (file, enc, cb) {
33
38
  // Don't process deleted file who haven't been commited yet.
34
39
  if (file.state === 'modified' || (file.state === 'deleted' && !file.isNew)) {
@@ -42,8 +47,10 @@ module.exports = function (filters, cb) {
42
47
  store.add(file);
43
48
  if (file.state === 'modified') {
44
49
  write(file);
50
+ file.committed = true;
45
51
  } else if (file.state === 'deleted') {
46
52
  remove(file);
53
+ file.committed = true;
47
54
  }
48
55
 
49
56
  delete file.state;
@@ -54,9 +61,9 @@ module.exports = function (filters, cb) {
54
61
  filters.unshift(modifiedFilter);
55
62
  filters.push(commitFilter);
56
63
 
57
- var stream = filters.reduce(function (stream, filter) {
64
+ stream = filters.reduce(function (stream, filter) {
58
65
  return stream.pipe(filter);
59
- }, this.store.stream());
66
+ }, stream);
60
67
 
61
68
  stream.on('finish', cb);
62
69
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mem-fs-editor",
3
- "version": "7.0.1",
3
+ "version": "7.1.0",
4
4
  "description": "File edition helpers working on top of mem-fs",
5
5
  "scripts": {
6
6
  "pretest": "eslint .",
@@ -16,15 +16,15 @@
16
16
  "dependencies": {
17
17
  "commondir": "^1.0.1",
18
18
  "deep-extend": "^0.6.0",
19
- "ejs": "^3.0.1",
19
+ "ejs": "^3.1.5",
20
20
  "glob": "^7.1.4",
21
21
  "globby": "^9.2.0",
22
22
  "isbinaryfile": "^4.0.0",
23
23
  "mkdirp": "^1.0.0",
24
24
  "multimatch": "^4.0.0",
25
25
  "rimraf": "^3.0.0",
26
- "through2": "^3.0.1",
27
- "vinyl": "^2.2.0"
26
+ "through2": "^3.0.2",
27
+ "vinyl": "^2.2.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "coveralls": "^3.0.3",