Node-fs-extra: Use with memory-fs?

Created on 11 Sep 2016  路  23Comments  路  Source: jprichardson/node-fs-extra

Hi, i love your library, but can you add support for change native fs to https://www.npmjs.com/package/memory-fs or other fs?

enhancement wont-fix

Most helpful comment

@kenberkeley I made a PR in March, now I'm just using my fork.

All 23 comments

I actually have a local branch where I've been working on this but got side-tracked. If you'd want to tackle this, I'd welcome this change. Maybe start with one function at a time, or maybe we need to create a factory method. Not sure yet.

I think, we have a good example here already. Ok, i will try pull requests, thank you.

Ok great, but start with one function at a time please :)

@arvitaly @jprichardson What is the plan/status on this? Is the whole library going to do something like mkdirs?

@RyanZim my plan is to allow fs-extra to take in any fs object, by default require('fs') to allow for mock / memory filesystems. Some methods already have this support. I really like https://github.com/tschaub/mock-fs

:+1: I was wondering what API you were planning.

Possible ways:

var fs = require('fs-extra')
fs.registerFS(require('mock-fs'))
var fse = require('fs-extra')
var fs = new fse.Mock(require('mock-fs'))
var fs = require('fs-extra')
fs.mkdirp(path, {fs: require('mock-fs')}, callback)

Thoughts? I personally would favor the first one, or a combination of the first and third.

I think fs.registerFS(require('mock-fs')) is a great first start. I'd eventually like the ability to override at the functional level as well. That's where I started first... I believe you can see it in action in some functions... may just be in jsonfile though.

Sorry, just a newbie question, so currently fs-extra cannot be used together with mock-fs?

@borekb mock-fs changed quite a bit since we discussed this. I think you'd be able to use it with fs-extra now.

@jprichardson @RyanZim so you mean all functions would accept an optional custom fs object the same as mkdirs?

mock-fs 4.4.2 and fs-extra 5.0.0 do not play well with each other. After mocking, fs-extra keeps using the un-stubbed fs module.

Could one of the maintainers of the project please let me know whether using ES6 features like object spread and arrow functions in the codebase is acceptable? The refactoring required is more or less straightforward, but it needs function composition and re-exporting of things in several places, which makes the code verbose and ugly when not using these features.

@masaeedu Anything supported in Node v4 is allowed. However, we'll be dropping Node 4 support April-May, so after that, it'd be anything supported in Node 6. Handy chart: http://node.green/

@RyanZim I'm going to assume that is a "yes" 馃榿

Node 6 supports a lot of stuff, but not object spreads.

@RyanZim My bad, I was referring to object destructuring (const { foo, bar } = { foo: 1, bar: 2}), got mixed up with the terminology. Object spread would be handy in some places, but you can just use Object.assign.

So how's it going, may I ask?

@kenberkeley I made a PR in March, now I'm just using my fork.

Can I use it with memory-fs or WebSocket-fs? Because many times, fs only represents this machine, expecting to pass in fs

Given these two facts, I propose we close this out as wontfix. If we want to investigate playing better with mock-fs's monkey-patching (I haven't tested how well it works currently), that should be a separate issue.

@manidlou @JPeer264 @jprichardson thoughts?

Even though memory-fs is unmaintained, I still think this module should play nice with it.

Besides, memfs do exist too, so I think it is reasonable to have an option to provide a custom node-compatible fs option in fs-extra.

Closing as wontfix; reasoning in https://github.com/jprichardson/node-fs-extra/pull/733#issuecomment-580432843.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

louwers picture louwers  路  4Comments

monolithed picture monolithed  路  5Comments

CharlieStras picture CharlieStras  路  4Comments

JPeer264 picture JPeer264  路  4Comments

EsTharian picture EsTharian  路  3Comments