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

6.x breaks plugin modules exporting functions #1728

Closed
garthk opened this issue Jun 18, 2014 · 4 comments
Closed

6.x breaks plugin modules exporting functions #1728

garthk opened this issue Jun 18, 2014 · 4 comments
Assignees
Labels
Milestone

Comments

@garthk
Copy link

@garthk garthk commented Jun 18, 2014

I wrote many Hapi plugin modules which export a function with a register function property. This lets me:

  • call the function directly for testing
  • register the function as a server method to get caching
  • register routes calling the server method

The update broke this plugin structure with one assertion:

// lib/pack.js:231
Hoek.assert(typeof plugin.register === 'function' || (typeof plugin.plugin === 'object' && typeof plugin.plugin.register === 'function'), 'Plugin register must be a function or a required plugin module', hint);

At this point, as invoked via hapi -c, plugin is { plugin: myModuleExport }. The first clause fails, then typeof plugin.plugin === 'object fails. typeof plugin.plugin.register === 'function' is true, but the expression never gets that far.

The next line is:

// lib/pack.js:233
var register = plugin.register || plugin.plugin.register;

If the assertion had not tripped, register would end up correct.

Any chance you can alter your assertion so I don't have to make breaking API changes to a dozen or so modules?

@chapel
Copy link

@chapel chapel commented Jun 18, 2014

As far as I can tell, it was never intended for a function with a register property to be supported. In fact it looks like the change in 6.x.x tightened up the expected behavior.

I understand it is an inconvenience to have to change your modules, but this change was expected to cause breakages. You can do the same thing you do already with slight modifications by exporting the function as a property on the exports and use that for testing or registering routes/methods.

With that said, I am unsure why you would need to use the exported function to do the above when you can do that from within the plugin itself, leaving it self contained.

Loading

@garthk
Copy link
Author

@garthk garthk commented Jun 18, 2014

Exporting the function is extremely helpful for the tests, @chapel. I can test without Hapi involved, with just the server method involved, or also with the route involved.

It might never have been intended for Hapi to support function plugins, but it did. That's no longer the case. If we don't intend fixing this, we should add the detail to the release notes (#1707).

Loading

@chapel
Copy link

@chapel chapel commented Jun 18, 2014

That's not how that works though. You were using an unintended bug as a
feature. There are usually no guarantees for undocumented functionality in
OSS.

I am not speaking for Hapi by the way, but as a user and fellow developer I
feel it is better to fix your code instead of introduce potential bugs.
On Jun 17, 2014 11:19 PM, "Garth Kidd" notifications@github.com wrote:

Exporting the function is extremely helpful for the tests, @chapel
https://github.com/chapel. I can test without Hapi involved, with just
the server method involved, or also with the route involved.

It might never have been intended for Hapi to support function plugins,
but it did. That's no longer the case. If we don't intend fixing this, we
should add the detail to the release notes.


Reply to this email directly or view it on GitHub
#1728 (comment).

Loading

@hueniverse
Copy link
Contributor

@hueniverse hueniverse commented Jun 18, 2014

I don't think this is a big deal either way. I can relax the test since ultimately I don't care what type the module itself is as long as it has a register property.

Loading

@hueniverse hueniverse added the bug label Jun 18, 2014
@hueniverse hueniverse added this to the 6.0.3 milestone Jun 18, 2014
@hueniverse hueniverse self-assigned this Jun 18, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jan 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants