diff --git a/lib/install/get-requested.js b/lib/install/get-requested.js index ab410ffc9b6e3..b6d3968db6985 100644 --- a/lib/install/get-requested.js +++ b/lib/install/get-requested.js @@ -7,6 +7,8 @@ module.exports = function (child, reqBy) { if (!reqBy) reqBy = child.requiredBy[0] const deps = reqBy.package.dependencies || {} const devDeps = reqBy.package.devDependencies || {} + const optDeps = reqBy.package.optionalDependencies || {} const name = moduleName(child) - return npa.resolve(name, deps[name] || devDeps[name], reqBy.realpath) + const spec = deps[name] || devDeps[name] || optDeps[name] + return npa.resolve(name, spec, reqBy.realpath) } diff --git a/test/tap/install-dep-classification.js b/test/tap/install-dep-classification.js index 257fc99fc123f..1c9995cedc8a0 100644 --- a/test/tap/install-dep-classification.js +++ b/test/tap/install-dep-classification.js @@ -126,7 +126,7 @@ test('optional dependency identification', function (t) { optional: true }, example: { - version: '1.0.0', + version: 'file:../example-1.0.0.tgz', optional: true } } @@ -150,7 +150,7 @@ test('development dependency identification', function (t) { dev: true }, example: { - version: '1.0.0', + version: 'file:../example-1.0.0.tgz', dev: true } } @@ -173,7 +173,7 @@ test('default dependency identification', function (t) { optional: true }, example: { - version: '1.0.0', + version: 'file:../example-1.0.0.tgz', optional: true } }