-p option documentation inconsistent with code
I read over the documentation for rejoice -p option:
You can specify a specific node_modules top level path by using the -p flag.
rejoice -c app.json -p /full/path/node_modules
This is in contridiction to the code here: https://github.com/hapijs/rejoice/blob/master/lib/index.js#L46-L48
The code performs a Path.join(*, 'node_modules'). There fore the result of the example above would be /full/path/node_modules/node_modules.
This part of the code is around using the -r option. Since in this case, -r isn't there, it never makes it to that section. However, if it was there, it seems like it should indeed not be doing node_modules again. I haven't had time to fully track this down but it seems like this is supposed to add a 'relativeTo' option that gets passed glue, which then gets passed to Hapi.Server() as an option. I suspect in hapi 8, the relativeTo likely changed locations. So I suspect currently the -p is being ignored but will investigate further. Just wanted to provide a little update in case someone else finds a little more time.
You're right @lloydbenson the behavior of -p is completely different when -r is also called. I guess it's still a documentation bug.
So after doing some digging. Here's the behavior.
-psupplied without-r, then-pis the{ relativeTo: ...}options passed to Glue.-psupplied with-r, then-pis used as a base path fornode_modulesdirectory to look for the-rsupplied module. The-pis still supplied to Glue viarelativeTo.
So I think the issue is that when both -p and -r are supplied they have competing purposes.
Here's a use case where this fails:
Directory structure:
project
| -- node_modules
| -- rejoice
| -- module-with-hapi
| -- node_modules
| -- some-module
| -- lib
| -- plugins
| -- plugin1
| -- plugin2
| -- package.json
| -- cfg
| -- manifest.json
My cfg/manifest.json file:
{
"connections": [
{
"port": 8080,
"labels": [
"api",
"http"
]
}
],
"plugins": {
"./plugins/plugin1": {},
"./plugins/plugin2": {},
}
}
So in this case I want to use -p to reference the path to my plugins, but I also want -p to reference the to the nested node_modules folder to be able to use -r some_module.
Following the logic on -r + -p there is a work around. If I use an absolute path for the -r argument then -p is more or less ignored for the purpose of finding -r some_module.
So here's a working command to navigate the issue above.
project/node_modules/.bin/rejoice -r 'project/node_modules/module-with-hapi/node_modules/some_module' -p './node_modules/module-with-hapi/lib'
Ok, for now do you mind opening up a PR for the documentation updates to reflect this? I am ok with changing the -p behavior to be the actual node_modules directory as well, but that would be a breaking change. Sounds like for now we can get by with just updating the doc.
Yeah I agree for now a documentation update will be adequate . I was thinking about it a little more this morning. I almost wonder if -p should always do what it does without -r and add a new option parameter (maybe -m) or something to represent the node_modules path and only available with -r is also supplied.
There are definitely a few things to investigate in general but I'll keep that in mind in a newer major release. Look forward to seeing the doc improvements and appreciate your patience!
Closing due to PR #39