mem-fs-editor 9.0.2 → 9.4.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 +18 -6
- package/lib/actions/commit-file-async.js +5 -1
- package/lib/actions/copy.js +10 -3
- package/lib/actions/dump.js +7 -1
- package/lib/actions/write.js +13 -5
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
# mem-fs-editor
|
|
1
|
+
# mem-fs-editor
|
|
2
|
+
|
|
3
|
+
[](https://github.com/SBoudrias/mem-fs-editor/actions?query=workflow%3A%22Node.js+CI%22)
|
|
4
|
+
[](http://badge.fury.io/js/mem-fs-editor)
|
|
5
|
+
[](https://codecov.io/gh/SBoudrias/mem-fs-editor)
|
|
2
6
|
|
|
3
7
|
File edition helpers working on top of [mem-fs](https://github.com/SBoudrias/mem-fs)
|
|
4
8
|
|
|
5
9
|
## Usage
|
|
6
10
|
|
|
7
11
|
```js
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
import memFs from 'mem-fs';
|
|
13
|
+
import editor from 'mem-fs-editor';
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
const store = memFs.create();
|
|
16
|
+
const fs = editor.create(store);
|
|
13
17
|
|
|
14
|
-
fs.write(
|
|
18
|
+
fs.write('somefile.js', 'var a = 1;');
|
|
15
19
|
```
|
|
16
20
|
|
|
17
21
|
### `#read(filepath, [options])`
|
|
@@ -82,6 +86,8 @@ Optionally, pass an `options.process` function (`process(contents)`) returning a
|
|
|
82
86
|
|
|
83
87
|
Optionally, when `from` is a glob pattern, pass an `options.processDestinationPath` function (`processDestinationPath(destinationFile)`) returning a string who'll become the new file name.
|
|
84
88
|
|
|
89
|
+
`options.noGlob` can be used to by bypass glob matching entirely. In that case, `from` will directly match file paths against the file system.
|
|
90
|
+
|
|
85
91
|
### `#copyAsync(from, to, [options], context[, templateOptions ])`
|
|
86
92
|
|
|
87
93
|
Async version of `copy`.
|
|
@@ -140,3 +146,9 @@ If provided, `filters` is an array of TransformStream to be applied on a stream
|
|
|
140
146
|
If provided, `stream` is a stream of vinyl files.
|
|
141
147
|
|
|
142
148
|
`callback` is called once the files are updated on disk.
|
|
149
|
+
|
|
150
|
+
### `#dump([cwd,] [filter])`
|
|
151
|
+
|
|
152
|
+
Dump files to compare expected result.
|
|
153
|
+
Provide a `cwd` for relative path. Allows to omit temporary path.
|
|
154
|
+
Provide a `filter` function or glob to focus on specific files.
|
|
@@ -32,7 +32,11 @@ async function remove(file) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
module.exports = async function (file) {
|
|
35
|
-
this.store.
|
|
35
|
+
const existingFile = this.store.get(file.path);
|
|
36
|
+
if (!existingFile || existingFile !== file) {
|
|
37
|
+
this.store.add(file);
|
|
38
|
+
}
|
|
39
|
+
|
|
36
40
|
if (isFileStateModified(file)) {
|
|
37
41
|
setCommittedFile(file);
|
|
38
42
|
await write(file);
|
package/lib/actions/copy.js
CHANGED
|
@@ -19,8 +19,15 @@ exports.copy = function (from, to, options, context, tplSettings) {
|
|
|
19
19
|
options = options || {};
|
|
20
20
|
const fromGlob = util.globify(from);
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
let diskFiles = [];
|
|
23
|
+
if (options.noGlob) {
|
|
24
|
+
const fromFiles = Array.isArray(fromGlob) ? fromGlob : [fromGlob];
|
|
25
|
+
diskFiles = fromFiles.filter(filepath => fs.existsSync(filepath));
|
|
26
|
+
} else {
|
|
27
|
+
const globOptions = {...options.globOptions, nodir: true};
|
|
28
|
+
diskFiles = globby.sync(fromGlob, globOptions).map(file => path.resolve(file));
|
|
29
|
+
}
|
|
30
|
+
|
|
24
31
|
const storeFiles = [];
|
|
25
32
|
this.store.each(file => {
|
|
26
33
|
// The store may have a glob path and when we try to copy it will fail because not real file
|
|
@@ -31,7 +38,7 @@ exports.copy = function (from, to, options, context, tplSettings) {
|
|
|
31
38
|
const files = diskFiles.concat(storeFiles);
|
|
32
39
|
|
|
33
40
|
let generateDestination = () => to;
|
|
34
|
-
if (Array.isArray(from) || !this.exists(from) || globby.hasMagic(normalize(from))) {
|
|
41
|
+
if (Array.isArray(from) || !this.exists(from) || (globby.hasMagic(normalize(from)) && !options.noGlob)) {
|
|
35
42
|
assert(
|
|
36
43
|
!this.exists(to) || fs.statSync(to).isDirectory(),
|
|
37
44
|
'When copying multiple files, provide a directory as destination',
|
package/lib/actions/dump.js
CHANGED
|
@@ -2,12 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const normalize = require('normalize-path');
|
|
5
|
+
const minimatch = require('minimatch');
|
|
5
6
|
|
|
6
7
|
const {hasClearedState, hasState, STATE, STATE_CLEARED} = require('../state');
|
|
7
8
|
|
|
8
9
|
module.exports = function (cwd = process.cwd(), filter = file => hasClearedState(file) || hasState(file)) {
|
|
10
|
+
if (typeof filter === 'string') {
|
|
11
|
+
const pattern = filter;
|
|
12
|
+
filter = file => minimatch(file.path, pattern);
|
|
13
|
+
}
|
|
14
|
+
|
|
9
15
|
return Object.fromEntries(
|
|
10
|
-
this.store.all().filter(file => filter(file)).map(file => {
|
|
16
|
+
this.store.all().filter(file => filter(file, cwd)).map(file => {
|
|
11
17
|
const filePath = normalize(cwd ? path.relative(cwd, file.path) : file.path);
|
|
12
18
|
const fileDump = {
|
|
13
19
|
contents: file.contents ? file.contents.toString() : file.contents,
|
package/lib/actions/write.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const assert = require('assert');
|
|
4
|
-
const {setModifiedFileState} = require('../state');
|
|
4
|
+
const {isFileStateModified, setModifiedFileState} = require('../state');
|
|
5
5
|
|
|
6
6
|
module.exports = function (filepath, contents, stat) {
|
|
7
7
|
assert(
|
|
@@ -10,10 +10,18 @@ module.exports = function (filepath, contents, stat) {
|
|
|
10
10
|
);
|
|
11
11
|
|
|
12
12
|
const file = this.store.get(filepath);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const newContents = Buffer.isBuffer(contents) ? contents : Buffer.from(contents);
|
|
14
|
+
if (
|
|
15
|
+
!isFileStateModified(file)
|
|
16
|
+
|| !Buffer.isBuffer(file.contents)
|
|
17
|
+
|| !newContents.equals(file.contents)
|
|
18
|
+
|| (stat !== undefined && file.stat !== stat)
|
|
19
|
+
) {
|
|
20
|
+
setModifiedFileState(file);
|
|
21
|
+
file.contents = newContents;
|
|
22
|
+
file.stat = stat;
|
|
23
|
+
this.store.add(file);
|
|
24
|
+
}
|
|
17
25
|
|
|
18
26
|
return file.contents.toString();
|
|
19
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mem-fs-editor",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.4.0",
|
|
4
4
|
"description": "File edition helpers working on top of mem-fs",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"fix": "eslint . --fix",
|
|
@@ -15,15 +15,16 @@
|
|
|
15
15
|
"lib"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"binaryextensions": "^4.
|
|
18
|
+
"binaryextensions": "^4.16.0",
|
|
19
19
|
"commondir": "^1.0.1",
|
|
20
20
|
"deep-extend": "^0.6.0",
|
|
21
21
|
"ejs": "^3.1.6",
|
|
22
22
|
"globby": "^11.0.3",
|
|
23
23
|
"isbinaryfile": "^4.0.8",
|
|
24
|
+
"minimatch": "^3.0.4",
|
|
24
25
|
"multimatch": "^5.0.0",
|
|
25
26
|
"normalize-path": "^3.0.0",
|
|
26
|
-
"textextensions": "^5.
|
|
27
|
+
"textextensions": "^5.13.0"
|
|
27
28
|
},
|
|
28
29
|
"peerDependencies": {
|
|
29
30
|
"mem-fs": "^2.1.0"
|
|
@@ -36,11 +37,11 @@
|
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"coveralls": "^3.0.3",
|
|
38
39
|
"escape-regexp": "0.0.1",
|
|
39
|
-
"eslint": "^
|
|
40
|
-
"eslint-config-xo-space": "^0.
|
|
40
|
+
"eslint": "^8.5.0",
|
|
41
|
+
"eslint-config-xo-space": "^0.30.0",
|
|
41
42
|
"jest": "^27.0.6",
|
|
42
|
-
"mem-fs": "^2.1
|
|
43
|
-
"sinon": "^
|
|
43
|
+
"mem-fs": "^2.2.1",
|
|
44
|
+
"sinon": "^12.0.1"
|
|
44
45
|
},
|
|
45
46
|
"jest": {
|
|
46
47
|
"collectCoverage": true,
|