You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[`patchRequire(vol[, Module])`](#patchrequirevol-module) - rewrites `require` function, patches Node's `module` module to use a give *fs-like* object `vol` for module loading
27
-
28
-
29
-
# `patchFs(vol[, fs])`
30
-
31
-
Rewrites Node's filesystem module `fs` with *fs-like* object.
32
-
33
-
-`vol` - fs-like object
34
-
-`fs`*(optional)* - a filesystem to patch, defaults to `require('fs')`
35
-
36
-
```js
37
-
import {patchFs} from'fs-monkey';
38
-
39
-
constmyfs= {
40
-
readFileSync: () =>'hello world',
41
-
};
42
-
43
-
patchFs(myfs);
44
-
console.log(require('fs').readFileSync('/foo/bar')); // hello world
45
-
```
46
-
47
-
You don't need to create *fs-like* objects yourself, use [`memfs`](https://github.com/streamich/memfs)
-[`patchRequire`](./docs/api/patchRequire.md) - rewrites `require` function, patches Node's `module` module to use the give *fs-like* object `vol` for module loading
59
35
60
-
# `patchRequire(vol[, unixifyPaths[, Module]])`
61
-
62
-
Patches Node's `module` module to use a given *fs-like* object `vol` for module loading.
63
-
64
-
-`vol` - fs-like object
65
-
-`unixifyPaths`*(optional)* - whether to convert Windows paths to unix style paths, defaults to `false`.
66
-
-`Module`*(optional)* - a module to patch, defaults to `require('module')`
67
-
68
-
Monkey-patches the `require` function in Node, this way you can make
69
-
Node.js to *require* modules from your custom filesystem.
70
-
71
-
It expects an object with three filesystem methods implemented that are
72
-
needed for the `require` function to work.
73
-
74
-
```js
75
-
let vol = {
76
-
readFileSync: () => {},
77
-
realpathSync: () => {},
78
-
statSync: () => {},
79
-
};
80
-
```
81
-
82
-
If you want to make Node.js to *require* your files from memory, you
83
-
don't need to implement those functions yourself, just use the
0 commit comments