gulpjs / vinyl

Virtual file format.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Virtual directories

darsain opened this issue · comments

Working on path normalization I've noticed that currently, file.isDirectory() check looks like this:

File.prototype.isDirectory = function() {
  return this.isNull() && this.stat && this.stat.isDirectory();
};

This makes creating purely virtual directories quite awkward, since you basically have to mock the fs.stat object. How about we extend it with something like:

File.prototype.isDirectory = function() {
  return this._isDirectory || this.isNull() && this.stat && this.stat.isDirectory();
};

Where this._isDirectory will be a flag configurable only on creation via constructor options:

new Vinyl({isDirectory: true});

Readable only, since there is no meaningful folder to file conversion (and the other way around).

I'm not too keen on this. We need to look into a better "stats" abstraction but I don't like being able to force a behavior different from the stats object. I've been mocking this everywhere (you just need to give an object with .isDirectory() attached). I know that it's not totally proper to leak those implementation details but leaving isDirectory, isSymbolicLink, etc up to stats as the 1 source of truth seems proper.

Side note: we should be assigning stat in the constructor if we aren't already and if it doesn't exist, it should probably be a new fs.Stat()

Hm... yeah, having 2 different places that define directory would be messy. But still, declaring that object is a directory should be easier. So if this is gonna happen:

we should be assigning stat in the constructor if we aren't already and if it doesn't exist, it should probably be a new fs.Stat()

There should still be a new Vinyl({isDirectory: true}) option that will mark that stat object as a directory. Thoughts?

I don't think there should be a top level option called isDirectory. That is too easy to confuse with the top-level isDirectory() method because we traditionally copy all the properties over.

So I'm than out of ideas how to make a user friendly creation of virtual directories :)

Closing in favor of #105