plumberjs/plumber — pull request #13 by OliverJAsh (2014-10-08 13:58:52+00:00)
Title: Erroneous directory detection – resources (and paths) missing filenames

If you create a `Resource` with a path such as `foo/bar/LICENSE`, the corresponding `Path` will be identified as a directory due to its lack of type, which means the `Path` will be incorrectly missing a filename.

I see there's some WIP regarding this issue over at: https://github.com/plumberjs/plumber/blob/master/lib/util/string-to-path.js#L19.

Using the file system to test whether a path is a directory or not seems sensible, although this will only work for existing files. How should we handle non-existing files? I dislike the heuristic of testing for a type because of the errors it produces (as per above), but I'm failing to think of an alternative.

--

Once that's fixed, there's another separate but related issue on the `Resource`. [We try to extract the "file name" by removing the type](https://github.com/plumberjs/plumber/blob/c972376ac0a55d3cb91c3c59b09d08dfff2d8fdb/lib/model/resource.js#L36), but if you have a path to file with no type (e.g. `foo/bar/LICENSE`), the file name will be empty because of the heuristic we are currently using.

--

I've submitted fixes for both of these issues. The former still needs some more thought about how to handle non-existing files, but it solves my problems for now. I'm hoping to get your input on this.

A few questions I came up with whilst dealing with these issues:

* What is `_file_trns` used for? What does it stand for? Transforms?
* It's confusing how `Path`’s definition of filename includes the type, whereas `Resource`’s definition does not (albeit with a space: "file name"). Is the space strong enough of a convention to really spot the difference? Took me awhile.
* We really need tests for the `plumber` module: `stringToPath`, `Resource`, etc.

I'm trying to take Plumber more seriously, because there's really no decent alternative at the moment. If you could provide feedback to my pull requests/questions, then I will have more and more confidence to implement solutions and add the missing tests :smile:.