Skip to content

Commit

Permalink
Merge pull request #542 from 20minutes/fix/remove-optional-peer-deps
Browse files Browse the repository at this point in the history
Remove optional peer dependencies
  • Loading branch information
miguel-a-calles-mba authored Jun 11, 2020
2 parents 98a9592 + 0563222 commit 6507cff
Show file tree
Hide file tree
Showing 3 changed files with 330 additions and 102 deletions.
35 changes: 27 additions & 8 deletions lib/packExternalModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,32 @@ function getProdModules(externalModules, packagePath, dependencyGraph, forceExcl
const peerDependencies = require(modulePackagePath).peerDependencies;
if (!_.isEmpty(peerDependencies)) {
this.options.verbose && this.serverless.cli.log(`Adding explicit peers for dependency ${module.external}`);
const peerModules = getProdModules.call(
this,
_.map(peerDependencies, (value, key) => ({ external: key })),
packagePath,
dependencyGraph,
forceExcludes
);
Array.prototype.push.apply(prodModules, peerModules);

const peerDependenciesMeta = require(modulePackagePath).peerDependenciesMeta;

if (!_.isEmpty(peerDependenciesMeta)) {
_.forEach(peerDependencies, (value, key) => {
if (peerDependenciesMeta[key] && peerDependenciesMeta[key].optional === true) {
this.options.verbose &&
this.serverless.cli.log(
`Skipping peers dependency ${key} for dependency ${module.external} because it's optional`
);

_.unset(peerDependencies, key);
}
});
}

if (!_.isEmpty(peerDependencies)) {
const peerModules = getProdModules.call(
this,
_.map(peerDependencies, (value, key) => ({ external: key })),
packagePath,
dependencyGraph,
forceExcludes
);
Array.prototype.push.apply(prodModules, peerModules);
}
}
} catch (e) {
this.serverless.cli.log(`WARNING: Could not check for peer dependencies of ${module.external}`);
Expand Down Expand Up @@ -424,3 +442,4 @@ module.exports = {
});
}
};

94 changes: 94 additions & 0 deletions tests/data/rp-package-optional.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"_from": "request-promise",
"_id": "[email protected]",
"_inBundle": false,
"_integrity": "sha1-fuxWyJMXqCLL/qmbA5zlQ8LhX2c=",
"_location": "/request-promise",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "request-promise",
"name": "request-promise",
"escapedName": "request-promise",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/request-promise/-/request-promise-4.2.1.tgz",
"_shasum": "7eec56c89317a822cbfea99b039ce543c2e15f67",
"_spec": "request-promise",
"_where": "C:\\Projects\\serverless\\test\\babel-dynamically-entries",
"author": {
"name": "Nicolai Kamenzky",
"url": "https://github.com/analog-nico"
},
"bugs": {
"url": "https://github.com/request/request-promise/issues"
},
"bundleDependencies": false,
"dependencies": {
"bluebird": "^3.5.0",
"request-promise-core": "1.1.1",
"stealthy-require": "^1.1.0",
"tough-cookie": ">=2.3.0"
},
"deprecated": false,
"description": "The simplified HTTP request client 'request' with Promise support. Powered by Bluebird.",
"devDependencies": {
"body-parser": "~1.15.2",
"chai": "~3.5.0",
"chalk": "~1.1.3",
"gulp": "~3.9.1",
"gulp-coveralls": "~0.1.4",
"gulp-eslint": "~2.1.0",
"gulp-istanbul": "~1.0.0",
"gulp-mocha": "~2.2.0",
"lodash": "~4.13.1",
"publish-please": "~2.1.4",
"request": "^2.34.0",
"rimraf": "~2.5.3",
"run-sequence": "~1.2.2"
},
"engines": {
"node": ">=0.10.0"
},
"homepage": "https://github.com/request/request-promise#readme",
"keywords": [
"xhr",
"http",
"https",
"promise",
"request",
"then",
"thenable",
"bluebird"
],
"license": "ISC",
"main": "./lib/rp.js",
"name": "request-promise",
"peerDependencies": {
"request": "^2.34",
"canvas": "^2.5.0"
},
"peerDependenciesMeta": {
"canvas": {
"optional": true
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/request/request-promise.git"
},
"scripts": {
"prepublish": "publish-please guard",
"publish-please": "publish-please",
"test": "gulp ci",
"test-publish": "gulp ci-no-cov"
},
"version": "4.2.1"
}
Loading

0 comments on commit 6507cff

Please sign in to comment.