Using bundleDependencies in npm when your bundles have dependencies

Note: you can reproduce this precisely by running npm install hotplate. I am writing hotplate, a simple module that is plugin-based:

https://github.com/mercmobily/hotplate

It's basically a small module, and then a whole lot of "plugin" modules which get loaded. Please note that because of this huge file system reshuffling hotplate is not currently functional.

Now... basically the structure is:

hotplate
|
 - hotplate.js
 - package.json
 - node_modules
   |
   - hotCoreClientFiles
   - hotCorePage
   - hotCoreSharedCode
   - hotDojoAuth
     ...

Hotplate then loads the relevant "plugins" (depending on what the user wants to do) etc. These plugins are to be bundled with the main module. Now... I am having a lot of grief figuring out how to automatically load the plugin's dependencies. This is what package.json looks like:

{
  "name": "hotplate",
  "description": "Hotplate SaaS development framework",
  "version": "0.0.13",
  "private": false,
  "dependencies": {
    "express": "3.x",
    "async": "*",

    "hotCoreClientFiles": "*",
     [...]
    "hotDojoSubmit": "*",
    "hotDojoWidgetHooks": "*",
    "hotDojoWidgets": "*",
    "hotMongoAuth": "*",
    "hotMongoCometMessages": "*",
    "hotMongoLogger": "*"

  },
  "bundleDependencies": [
    "hotCoreClientFiles",
     [...]
    "hotDojoSubmit",
    "hotDojoWidgetHooks",
    "hotDojoWidgets",
    "hotMongoAuth",
    "hotMongoCometMessages",
    "hotMongoLogger"
  ],
}    

Basically, some of the sub-modules also have dependencies (outlined in their own package.json files); after installation, this is the result:

/home/chiara
└─┬ hotplate@0.0.12
  ├── async@0.2.6
  ├─┬ express@3.1.0
  [...]
  ├── hotCoreClientFiles@0.0.4
  ├── hotCoreCommonValidators@0.0.4
  ├── hotCoreError@0.0.4
  [...]
  ├── hotDojoWidgets@0.0.4
  ├─┬ hotMongoAuth@0.0.4
  │ ├── UNMET DEPENDENCY allhttperrors *
  │ ├── UNMET DEPENDENCY bcrypt *
  │ ├── UNMET DEPENDENCY hat *
  │ ├── UNMET DEPENDENCY mongowrapper *
  │ └── UNMET DEPENDENCY simpleschema-mongo *
  ├─┬ hotMongoCometMessages@0.0.4
  │ ├── UNMET DEPENDENCY allhttperrors *
  │ └── UNMET DEPENDENCY mongowrapper *
  └─┬ hotMongoLogger@0.0.4
    ├── UNMET DEPENDENCY jsonreststores-mongo *
    ├── UNMET DEPENDENCY mongowrapper *
    └── UNMET DEPENDENCY simpledeclare *

This is not good! If you then run npm update... well, a bit of a disaster happens. The module mongowrapper depends on mongodb, which gets downloaded and compiled N times.

I don't really want to set mongodb, mongowrapper, simpledeclare etc. as dependencies as the main hotplate module because... well, because they are not. Hotplate is only a loader. If simpledeclare is already required by a package on a higher level, then OK it won't need to be installed again. Otherwise, I would like it to stay in the sub module's node_modules directory.

Now, I must be doing something very wrong. I just cannot figure out what it is...

Thank you!

Merc.

The bundleDependencies field is to be used in your plugins package.json. Not your main loader.