{"action":"created","issue":{"url":"https://api.github.com/repos/hapijs/hapi/issues/2666","labels_url":"https://api.github.com/repos/hapijs/hapi/issues/2666/labels{/name}","comments_url":"https://api.github.com/repos/hapijs/hapi/issues/2666/comments","events_url":"https://api.github.com/repos/hapijs/hapi/issues/2666/events","html_url":"https://github.com/hapijs/hapi/issues/2666","id":97585114,"number":2666,"title":"Support for plugin alias option","user":{"login":"dylancwood","id":5280961,"avatar_url":"https://avatars.githubusercontent.com/u/5280961?v=3","gravatar_id":"","url":"https://api.github.com/users/dylancwood","html_url":"https://github.com/dylancwood","followers_url":"https://api.github.com/users/dylancwood/followers","following_url":"https://api.github.com/users/dylancwood/following{/other_user}","gists_url":"https://api.github.com/users/dylancwood/gists{/gist_id}","starred_url":"https://api.github.com/users/dylancwood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dylancwood/subscriptions","organizations_url":"https://api.github.com/users/dylancwood/orgs","repos_url":"https://api.github.com/users/dylancwood/repos","events_url":"https://api.github.com/users/dylancwood/events{/privacy}","received_events_url":"https://api.github.com/users/dylancwood/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hapijs/hapi/labels/request","name":"request","color":"c7def8"}],"state":"open","locked":false,"assignee":{"login":"hueniverse","id":56631,"avatar_url":"https://avatars.githubusercontent.com/u/56631?v=3","gravatar_id":"","url":"https://api.github.com/users/hueniverse","html_url":"https://github.com/hueniverse","followers_url":"https://api.github.com/users/hueniverse/followers","following_url":"https://api.github.com/users/hueniverse/following{/other_user}","gists_url":"https://api.github.com/users/hueniverse/gists{/gist_id}","starred_url":"https://api.github.com/users/hueniverse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hueniverse/subscriptions","organizations_url":"https://api.github.com/users/hueniverse/orgs","repos_url":"https://api.github.com/users/hueniverse/repos","events_url":"https://api.github.com/users/hueniverse/events{/privacy}","received_events_url":"https://api.github.com/users/hueniverse/received_events","type":"User","site_admin":false},"milestone":null,"comments":13,"created_at":"2015-07-28T00:27:57Z","updated_at":"2015-08-10T22:44:31Z","closed_at":null,"body":"# Background\r\n\r\nFor discoverability, plugins are often named quite verbosely, with the word *hapi* in them. Further, they are often hyphenated (e.g. `hapi-redis`). See https://github.com/sandfox/node-hapi-redis/issues/9 for a specific example.\r\n\r\n# Problem\r\n\r\n1. The hyphens used by most authors prevent developers from referencing the plugin with dot notation. They have to use bracket notation to reference the plugin (e.g. `server.plugins['hapi-redis']). IMO this adds up to wasted time, and ugly code. \r\n1. While it makes sense to prefix a plugin name with the the word *hapi* when interacting with it outside of hapi (e.g. `npm i hapi-redis`), it is redundant inside of hapi (e.g. `server.plugins['hapi-redis']`).\r\n\r\n# Solution\r\n\r\nPackages need to be discoverable, so prefixing them with *hapi-* is important. Further, it is important that the plugin name match the package name so that it is easy to understand where the plugin comes from. In order to maintain both of these requirements, and solve the above problem, I suggest that we support a user-defined `alias` option when registering a plugin. This idea was actually originally suggested by @Marsup on gitter when I asked for ideas about this problem. \r\n\r\nHere is how I envision the `alias` option being used:\r\n\r\n```js\r\nserver.register([\r\n    {\r\n      register: require('hapi-redis'),\r\n      options: {},\r\n      alias: 'redis'\r\n    },\r\n    require('boom')\r\n  ],\r\n  { /*hapi-options*/ },\r\ncallbackFn\r\n);\r\n```\r\n\r\nAt first glance, I think that this could be accomplished in [lib/plugin.js](https://github.com/hapijs/hapi/blob/master/lib/plugin.js#L340) just after line 340:\r\n\r\n```js\r\ninternals.Plugin.prototype.expose = function (key, value) {\r\n\r\n    Hoek.assert(this.realm.plugin, 'Cannot call expose() outside of a plugin');\r\n\r\n    var plugin = this.realm.plugin;\r\n    this.root.plugins[plugin] = this.root.plugins[plugin] || {};\r\n    // need to figure out how to grab alias :-(\r\n    this.root.plugins[alias] = this.root.plugins[plugin];\r\n    this.root.plugins[\r\n    if (typeof key === 'string') {\r\n        this.root.plugins[plugin][key] = value;\r\n    }\r\n    else {\r\n        Hoek.merge(this.root.plugins[plugin], key);\r\n    }\r\n};\r\n```\r\n\r\n# Discussion\r\n\r\n**What do you all think about adding a plugin alias for easier namespacing of plugins?**"},"comment":{"url":"https://api.github.com/repos/hapijs/hapi/issues/comments/129636706","html_url":"https://github.com/hapijs/hapi/issues/2666#issuecomment-129636706","issue_url":"https://api.github.com/repos/hapijs/hapi/issues/2666","id":129636706,"user":{"login":"dylancwood","id":5280961,"avatar_url":"https://avatars.githubusercontent.com/u/5280961?v=3","gravatar_id":"","url":"https://api.github.com/users/dylancwood","html_url":"https://github.com/dylancwood","followers_url":"https://api.github.com/users/dylancwood/followers","following_url":"https://api.github.com/users/dylancwood/following{/other_user}","gists_url":"https://api.github.com/users/dylancwood/gists{/gist_id}","starred_url":"https://api.github.com/users/dylancwood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dylancwood/subscriptions","organizations_url":"https://api.github.com/users/dylancwood/orgs","repos_url":"https://api.github.com/users/dylancwood/repos","events_url":"https://api.github.com/users/dylancwood/events{/privacy}","received_events_url":"https://api.github.com/users/dylancwood/received_events","type":"User","site_admin":false},"created_at":"2015-08-10T22:44:31Z","updated_at":"2015-08-10T22:44:31Z","body":"Good point @Marsup! I agree with you, and take back my previous suggestion. \r\n\r\nHapi guarantees that plugins will not overload each other (it throws an error unless the plugin is a `multi` plugin). However, tracking down which plugins are conflicting might be difficult if the plugin names do not match the package name (e.g. if some author decides to name their plugin `boom`, but the package name is `node-hapi-basic-object-oriented-methods-plugin`.). **Further, if both plugins are `multi` plugins, then I think that they the will both be registered to the same namespace.**\r\n\r\nA unique `pluginId` could help to prevent this as well. Perhaps a checksum of the plugin's attributes? "}}