Giter VIP home page Giter VIP logo

Comments (11)

bendrucker avatar bendrucker commented on June 5, 2024

Did a little investigation and this would have worked with karma-bro < 0.7

from karma-browserify.

bendrucker avatar bendrucker commented on June 5, 2024

So the reason this is happening is that the bundle gets reset on rebuilds:

https://github.com/Nikku/karma-browserify/blob/master/lib/bro.js#L208

Immediate fix is to do this in prebundle:

bundle.require('./foo', {expose: 'foo'});
bundle.on('reset', function () {
    bundle.require('./foo', {expose: 'foo'});
});

external among other bundle configuration calls is not reset on reset. Technically running prebundle on every run wouldn't break anything but it would balloon arrays like b._external with long running watchify instances. I think the answer here is to provide an extra hook that runs on every bundle call but I'll wait on @nikku's thoughts before we ship anything.

from karma-browserify.

nickstenning avatar nickstenning commented on June 5, 2024

Thanks for digging @bendrucker.

To pre-empt questions about why on earth I'd want or need to do this: I have a project, "foo", which contains some plugins. These plugins depend on "foo-plugintool", an external dependency which in turn depends on "foo". When testing, I'd like that require('foo') to resolve back to the working copy of the project rather than the released version. Hope that makes sense.

from karma-browserify.

nikku avatar nikku commented on June 5, 2024

Haha, I already had an update for that behavior implemented but reverted it again because no reported a bug on it yet.

The intention during early karma-bro times was to actually be able to configure the whole bundle thing once. Too bad browserify nowadays resets file configurations and so forth.

My suggestion is: We fire a custom event users can listen to that resembles the configuration before actual bundling for the users:

bundle.on('prebundle', function () {
  bundle.require('./foo', {expose: 'foo'});
});

We could then rename the actual method to something like configure or the like to indicate manual configuration of browserify. Prebundle is definitely the wrong name for what it offers today.

from karma-browserify.

nikku avatar nikku commented on June 5, 2024

Looks like this is absolutely equivalent:

bundle.on('reset', function () {
  bundle.require('./foo', {expose: 'foo'});
});

The initial configuration is not needed as we always reset the bundle prior to any bundling operations.

from karma-browserify.

bendrucker avatar bendrucker commented on June 5, 2024

You're right. Honestly I'm inclined to just document this. The gain from having a clearer event name isn't worth creating code that isn't portable (i.e. wouldn't work with regular watchify). configure makes sense but would also mean a major version change.

from karma-browserify.

nickstenning avatar nickstenning commented on June 5, 2024

This sounds fine as far as it goes, but it seems that it introduces another related bug. If you do

bundle.on('reset', function () {
  bundle.require('./foo', {expose: 'foo'});
});

then certainly require('foo') works, but oddly require('./foo') no longer does. This is at odds with the usual behaviour of browserify AFAICT. If I have foo.js:

module.exports = 4;

and relative.js:

var foo = require('./foo');
console.log("foo =", foo);

then I can still browserify this using

browserify -r ./foo.js:foo relative.js | node

and the relative require continues to work.

from karma-browserify.

nikku avatar nikku commented on June 5, 2024

This is related to #52 and a browserify/watchify bug. It looks as if watchify cannot handle files that are required using their relative path names and a global alias at the same time.

As much as I can tell there are two options to fix this, none of them is without pain.

from karma-browserify.

nikku avatar nikku commented on June 5, 2024

We are going to fix this in karma-browserify by exposing all files via their absolute path.

This is something watchify requires. In order for the above code to work, you should use

bundle.require('abs-path-to-foo', {expose: 'foo'});

from karma-browserify.

nikku avatar nikku commented on June 5, 2024

Forget what I posted before 😀.

The next version of karma-browserify will remove the prebundle hook in favor of a configure hook.
Users may hook into prebundle actions by listening to the prebundle event.

Example configuration:

{

  files: [ ],
  preprocessors: [ ],

  browserify: {
    configure: function(b) {
      b.on('prebundle', function() {
        b.external('lib/external.js');
      });
    }
  }
}

from karma-browserify.

nickstenning avatar nickstenning commented on June 5, 2024

Thank you! 🍰

from karma-browserify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.