rejoice icon indicating copy to clipboard operation
rejoice copied to clipboard

-p option documentation inconsistent with code

Open ambrons opened this issue 11 years ago • 6 comments

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.

ambrons avatar Sep 19 '15 02:09 ambrons

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.

lloydbenson avatar Sep 19 '15 11:09 lloydbenson

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.

  1. -p supplied without -r, then -p is the { relativeTo: ...} options passed to Glue.
  2. -p supplied with -r, then -p is used as a base path for node_modules directory to look for the -r supplied module. The -p is still supplied to Glue via relativeTo.

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'

ambrons avatar Sep 25 '15 14:09 ambrons

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.

lloydbenson avatar Sep 25 '15 14:09 lloydbenson

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.

ambrons avatar Sep 25 '15 16:09 ambrons

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!

lloydbenson avatar Sep 25 '15 16:09 lloydbenson

Closing due to PR #39

lloydbenson avatar Sep 25 '15 17:09 lloydbenson