browserify / watchify

watch mode for browserify builds
Other
1.79k stars 203 forks source link

Why is the "--output" (outpipe) option not available on Windows? It seems to work fine on XP #246

Closed jeffbski closed 8 years ago

jeffbski commented 9 years ago

Why is the "--output" (outpipe) option not available on Windows?

https://github.com/substack/watchify/blob/master/bin/cmd.js#L37 and it is documented in the readme as such.

I changed it to

var outStream = outpipe(outfile);

It seems to work fine on XP. I tested both writing to file and piping to multiple commands and then directing output to a file.

@zertosh I believe you were the author who added this feature, so I am including you into the discussion too.

I would like to use the piping to shell commands in windows just like I do for *nix.

Yes, the test https://github.com/substack/watchify/blob/master/test/bin_pipe.js#L29 would need to be changed to something that works on both windows and *nix, but otherwise I think this seems to work.

Am I missing something?

Thanks,

Jeff

zertosh commented 9 years ago

Sorry @jeffbski, I did add that feature but I must confess that I'm not a windows user and I know very little about windows. I think that when I first tried it, it was on Windows 7 with a simple pipe and it didn't work. It was a mission to get it all going: Get a VM, install git, install node, etc. and the command prompt was painful. I guess what I'm trying to say is that it's a bandwidth issue. If you can walk me through how to test and set this up, I'll be more than happy to enable it for windows.

As for the test, what's a good a command that is cross-platform and performs a testable transformation?

jeffbski commented 9 years ago

@zertosh I know what you mean. I don't use windows much either, and I only have a VirtualBox VM of Windows XP to test with.

You are right though, if you were to invoke the edge cases with a leading/training pipe or a leading > like -o "| foo" or -o "xyz |" or -o "> foo", none of those would work since they would invoke the outpipe clause that uses /bin/echo. The examples in the readme should work fine on all environments.

The most common things that people would want to do is to pipe to something like uglify or in my case I do something like -o "ntee bundle.js | uglifyjs - -cm | ntee bundle.min.js | ngzip > bundle.min.js.gz" which gives me bundle.js, minified bundle.min.js, and min and gzipped bundle.min.js.gz all from the same watchify output. ntee and ngzip are portable node.js commands that work similar to the native ones. So doing things like in the readme should work fine.

As for a test, that's a good question. I think we'd have to pull a dev dependency or two like ntee and ngzip. Adding in uglify match a common use case but it is much larger.

So with ntee and ngzip, we could do -o "ntee bundle.js | ngzip > bundle.js.gz" for the test, but if wanted to verify the gzipped file, the commands vary between windows and unix. "cat bundle.js.gz | ngzip -d > bundle.js" vs "type bundle.js.gz | ngzip -d > bundle.js".

If we'd be ok with just using ntee twice we could simply use that -o "ntee bundle.js | ntee bundle2.js > bundle3.js" which would give us three identical copies. It wouldn't transform anything but it uses pipe and output direction.