feat(ospec): Accept list of filenames through stdin#2137
feat(ospec): Accept list of filenames through stdin#2137maranomynet wants to merge 4 commits intoMithrilJS:nextfrom maranomynet:feat_ospec_filelist_via_stdin
Conversation
|
This is my first time playing with |
|
@maranomynet thanks for the PR! Indeed, there are some issues with how you handle the |
|
Once this is merged I'll release ospec v2.0 (or it could be part of v2.1, actually, no hurry @maranomynet). |
|
Thanks for the pointer. I've amended the PR accordingly. |
|
Thanks @maranomynet, but actually the chunks will not necessarily split between file names (that's a non-obvious caveat that I should have pointed out explicitly, sorry). It would be best to accumulate the whole thing into a string before splitting on Something along this (also taking Windows into account): let fileList = ""
let chunk
while ((chunk = process.stdin.read()) !== null) fileList += chunk
fileList.toString().split(/\r?\n/).forEach(function(fileName) {
if (fileName) {
require(path.join(process.cwd(), fileName)) // eslint-disable-line global-require
}
})
o.run()It may be best to wait for @tivac's input before updating the PR, he may have other suggestions. The try/catch block isn't very useful here... the BTW, shouldn't that |
|
Ah interesting. All this is sort of obvious in hindsight. :-) But my assumption was that the ...and yes |
|
Yes, |
|
Removed try |
|
We're getting there :-) In the example
I hoped that |
|
In what way does it not "work"? |
|
On macOS, find doesn't expand globs: $ ls *.js
foo.js bar.js
$ find *.js
find: *.js: No such file or directoryEdit: could it be a badly configured shell? Is the shell supposed to expand globs before passing them to commands? |
|
Hmm.. really? |
|
Ah, I just realised that there seems to be a huge difference between globs in zsh and bash. Nontheless, bash still gives me a list of files - it just takes the |
|
I'll update the example to use a dumber/simpler file pattern. |
...because globbing support is not universal across all shell environments.
|
I'm still a bit baffled about the bit you quoted: Regardless of which shell I run (bash, zsh, sh) this sort of command always returns the same thing as the
Anyway, what do you suggest I do? |
|
Even with globs, actually, in bash, |
|
OK, I'm leaving the example in its current simpler state, as it seems good enough to get the general point across. |
|
https://github.com/latentflip/node-glob-cli would be a suitable cross-platform solution. ( |
|
Sure, but what are we trying to accomplish at this point? So ospec supports reading a list of files through stdin and the documentation explains that, showing a simple, non-exhaustive example. User's are then left to choose the file-listing strategy suitable to their use case. Right? |
|
I wanted to make sure the feature was equally useful on all supported platforms. Thanks to I'll add a note about |
|
This is all mostly new for me too. |
|
Windows is a supported platform too, and cross-platform use cases are important for teams with a non-uniform dev setup. |
|
Superseeded by #2141 |
Description
In response to suggestions made in #2133
Motivation and Context
See rationale in #2133 ...plus add support for custom file-name and folder patterns.
How Has This Been Tested?
(Same as #2133 except with piping)
Tested on the command line within the mithril repo itself.
etc. etc...
It should be safe to pass multiple instances of the same file as multiple
require()calls to the same file only result in a single invocation of their side-effects.Types of changes
Checklist:
docs/change-log.md