chore(package.json): add dynamic dependencies as optional dependencies (#1228)

In order to package the Etcher CLI, we concatenate all the code from the
`lib/cli/etcher.js` entry point using browserify.

There are some dependencies down the hierarchy that dynamically require
other dependencies, by enclosing `require()` calls in `try`/`catch`
blocks. The dynamic dependencies these modules require are not even
present in the `package.json`, and thus rightfully confuse browserify.

See https://github.com/ForbesLindesay/spawn-sync/blob/master/lib/spawn-sync.js#L10
See https://github.com/IndigoUnited/node-cross-spawn/blob/master/index.js#L32

There are two solutions to this problem:

- Make browserify stub these problematic dependencies with a blank file
  by using `--ignore`

This approach initially looks like the way to go, however it means that
every module that requires this particular dependency will receive just
a blank stub. It might be that some other dependencies rely on them, so
this approach could cause very obscure bugs later on.

- Add them to `package.json`

This is the approach taken by this commit. We add them to
`optionalDependencies` instead of `dependencies`, so we can still make
use of tools that analyse the code base for unused dependencies.

Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
This commit is contained in:
Juan Cruz Viotti 2017-03-28 09:41:53 -04:00 committed by GitHub
parent da85aa31aa
commit 396145d625

View File

@ -59,7 +59,9 @@
},
"optionalDependencies": {
"elevator": "^2.1.0",
"removedrive": "^1.1.1"
"removedrive": "^1.1.1",
"spawn-sync": "^1.0.15",
"try-thread-sleep": "^1.0.2"
},
"dependencies": {
"angular": "1.6.3",