Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #899 - browserify removes output file if it didn't exist previously #1239

Closed
wants to merge 3 commits into from

Conversation

kika
Copy link

@kika kika commented May 2, 2015

The change is trivial. I didn't use fs.exists() because it's being deprecated soon according to the recent Node documentation.

@zertosh
Copy link
Member

zertosh commented May 6, 2015

Why the tmp stream? Instead of:

try {  fs.unlinkSync(outfile); } catch(err) { }

@kika
Copy link
Author

kika commented May 6, 2015

Generic answer : I personally hate software which does what it wasn't asked to do :-)
Specific answer: if, for whatever reason, the output file did exist before the browserify run it will get deleted without advance warning. So I check if the file exists before attempt to run and clean up after the failed run only if there was no output file before.

@zertosh
Copy link
Member

zertosh commented May 6, 2015

Ah makes sense. The fs.createWriteStream(outfile) will write to the file (thus emptying it if it existed before) pretty much always before any error ever gets emitted by browserify. But at least you're leaving the file behind. Ok cool, but that tmp stream 🙀

var outfileExists;

if (outfile) {
    try { outfileExists = !!fs.lstatSync(outfile); } catch (err) {}
    bundle.pipe(fs.createWriteStream(outfile));
}

@kika
Copy link
Author

kika commented May 6, 2015

makes sense, thanks. Updated.

@ghost
Copy link

ghost commented May 6, 2015

I'm against adding .sync calls. This patch also seems to add a lot more complexity that will probably break in strange ways. Writing to a tmp file was removed from watchify for this reason since it kept breaking on windows. I'm skeptical that this kind of patch won't ripple up to create problems.

@kika
Copy link
Author

kika commented May 6, 2015

@substack, are you against this PR entirely, or just against replacing the test for existence by opening the stream with lstatSync()? Without this PR (or equivalent) browserify breaks make-based workflows and forces use of make kludges like DELETE_ON_ERROR which do not exist in all flavors of make

@goto-bus-stop
Copy link
Member

It looks like #899 was addressed by #1673. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants