Skip to content

Commit

Permalink
Fixed browserify#899 - browserify removes output file if it didn't ex…
Browse files Browse the repository at this point in the history
…ist previously
  • Loading branch information
kika committed May 2, 2015
1 parent b9727cf commit 42aee9c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bin/cmd.js
Expand Up @@ -56,7 +56,12 @@ var bundle = b.bundle();
bundle.on('error', errorExit);

var outfile = b.argv.o || b.argv.outfile;
var outfileExists = true;

if (outfile) {
var tmp = fs.createReadStream(outfile);
tmp.on('error', function() { outfileExists = false; });
tmp.close();
bundle.pipe(fs.createWriteStream(outfile));
}
else {
Expand All @@ -78,5 +83,8 @@ function errorExit(err) {
else {
console.error(String(err));
}
if (!outfileExists) {
fs.unlinkSync(outfile);
}
process.exit(1);
}

0 comments on commit 42aee9c

Please sign in to comment.