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

Half complete outputs after using factor-bundle #350

Open
jjgonecrypto opened this issue Aug 20, 2015 · 4 comments
Open

Half complete outputs after using factor-bundle #350

jjgonecrypto opened this issue Aug 20, 2015 · 4 comments

Comments

@jjgonecrypto
Copy link
Contributor

Similar to #330. That was closed due to node version however I believe that was a red herring, as I've noticed this now on

grunt-browserify: 3.3.0 & 4.0.0
browserify: 8.x+
factor-bundle: 2.5.0

On node 0.10.40, 0.12.7 and iojs 3.0.0

I have been getting inconsistent results with factor-bundle and grunt-browserify and I believe the issue to be a race condition.

To reproduce:

git clone git@github.com:jmreidy/grunt-browserify.git
cd grunt-browserify
npm install
cd examples/factor-bundle
npm install
grunt
cat ./public/x.js

Expected: A fully formed bundle
Actual: Sometimes just require=, sometimes a full line ending with an open brace, sometimes the actual bundle

Issue: When next() is invoked then the plugin may still be producing output. When run via the browserify CLI, everything works as expected. When run via grunt-browserify, next seems to immediately interrupt the browserify process, when factor-bundle might still be streaming its output.

Adding a simple timeout of 100ms to the above seems to fix it. I will investigate further and try to submit a PR.

Note: I would like to add a test, but will need to expand the test suite to actually output files to determine if the write successfully completed. I may not have time to expand the suite to actually monitor output.

@jjgonecrypto
Copy link
Contributor Author

Seems to be related to browserify/factor-bundle#61

@jjgonecrypto
Copy link
Contributor Author

So, the solution I have is non-trivial. It involves using a slightly modified fork of factor-bundle which emits the output stream for each bundle, and then modifying grunt-browserify to use a simple promise to emit with or without factor bundles.

master...justinjmoses:master

I don't expect this to get merged in, though I will try to get my factor-bundle fork into that repo, which is a step forward.

@shiftie
Copy link

shiftie commented Mar 28, 2017

Hi,
I encountered the same problem & I think I have an easy fix by adding a timeout function to the post bundle callback.
Just add this to your browserify config:

postBundleCB: (err, src, next) => { setTimeout(()=>{ next(err, src); }, 0); }

shiftie added a commit to shiftie/browserify-tetsts that referenced this issue Mar 28, 2017
@andrewsantarin
Copy link

andrewsantarin commented Aug 16, 2017

Grunt & Browserify beginner here.

I found this to be a problem, too, while trying to create the production build of this tutorial repo: https://github.com/mitchgavan/grunt-browserify-babel/blob/master/gruntfile.js

Like @shiftie, I had to add this to the production.options settings, just below line 40.

production: {
  ..., // all other kinds of settings
  options: {
    browserifyOptions: { debug: false },
    transform: [["babelify", { "presets": ["es2015"] }]],
    plugin: [ ... ],

    // @shiftie's fix here.
    postBundleCB: (err, src, next) => { setTimeout(()=>{ next(err, src); }, 0); }
  }
}

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

No branches or pull requests

3 participants