-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
bundle.require doesn't appear to work in prebundle hook #63
Comments
Did a little investigation and this would have worked with karma-bro < 0.7 |
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 bundle.require('./foo', {expose: 'foo'});
bundle.on('reset', function () {
bundle.require('./foo', {expose: 'foo'});
});
|
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 |
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:
We could then rename the actual method to something like |
Looks like this is absolutely equivalent:
The initial configuration is not needed as we always reset the bundle prior to any bundling operations. |
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). |
As described in the GitHub issue[1]. Unfortunately now we fail further down the stack... [1]: nikku/karma-browserify#63 (comment)
As described in the GitHub issue[1]. Unfortunately now we fail further down the stack... [1]: nikku/karma-browserify#63 (comment)
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 module.exports = 4; and var foo = require('./foo');
console.log("foo =", foo); then I can still browserify this using
and the relative require continues to work. |
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. |
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
|
This commit removes the prebundle hook to configure and adds the prebundle event that may be used to perform additional configuration. This allows users to reliably hook into the bundling process in browserify@7 times. Closes #63
This commit removes the prebundle hook to configure and adds the prebundle event that may be used to perform additional configuration. This allows users to reliably hook into the bundling process in browserify@7 times. Closes #63
Forget what I posted before 😀. The next version of karma-browserify will remove the prebundle hook in favor of a configure hook. Example configuration:
|
Thank you! 🍰 |
I'm currently in the process of trying to work out why a set of tests have recently started failing, and while I'm not certain that karma-browserify is at fault, I have been able to reduce the testcase to a point where I figured it would be useful to open a discussion here.
Here's the code, in the form of a gist: https://gist.github.com/nickstenning/d70fea282c5897658452
Specifically, I was previously able to call
bundle.require(...)
in a prebundle hook in order to expose a library to the browserify bundle with a specific name (using browserify'sexpose
option). This no longer appears to work.Here's the output of
karma start karma.conf.js --single-run
on the above-linked project:The text was updated successfully, but these errors were encountered: