From 396145d62586fa5c887f87303ecfc295b9668ea4 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 28 Mar 2017 09:41:53 -0400 Subject: [PATCH] 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 --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 9076b111..1f22f960 100644 --- a/package.json +++ b/package.json @@ -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",