Skip to content

Commit

Permalink
fix: adding shareFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedAlchemy committed May 14, 2020
1 parent c35e69a commit df35664
Show file tree
Hide file tree
Showing 5 changed files with 5,220 additions and 5 deletions.
14 changes: 12 additions & 2 deletions AutomaticVendorFederation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@ const AutomaticVendorFederation = ({
ignoreVersion,
packageJson,
ignorePatchVersion = true,
shareFrom = ["dependencies"],
}) => {
let combinedDependencies;
if (!packageJson) {
throw new Error(
"AutomaticVendorFederation: You must pass the package.json file of your app"
);
}
const { dependencies, devDependencies } = packageJson;
const combinedDependencies = { ...dependencies, ...devDependencies };
if (shareFrom) {
if (!Array.isArray(shareFrom)) {
throw new Error("AutomaticVendorFederation: shareFrom must be an array");
}
combinedDependencies = shareFrom.reduce((acc, jsonKey) => {
Object.assign(acc, packageJson[jsonKey]);
return acc;
}, {});
}

const shareableDependencies = Object.keys(combinedDependencies).filter(
(dependency) => {
if (exclude.some((dep) => dependency.includes(dep))) return false;
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ There are a few arguments you can pass to the utility.
`pkgJson` : pass your apps `package.json`: eg: `require("./package.json");`
`ignoreVersion`: you can ignore versions on some shared packages. This utility supports versioned dependencies, which is a problem when using React as there can only be one version on the page
`ignorePatchVersion` : ignore patch numbers and share dependencies based on a minor version matching. lodash-4.11 instead of lodash-4.11.7
`shareFrom`: choose where in package.json the utility should share from. `['dependencies','peerDependencies']`/ (default: `dependencies`)

```js
const AutomaticVendorFederation = require("@module-federation/automatic-vendor-sharing");
Expand Down
3 changes: 1 addition & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# 1.0.0 (2020-05-14)


### Bug Fixes

* adding release configs ([47b507f](https://github.com/module-federation/automatic-vendor-sharing/commit/47b507f5740b98cb70f8551461ada4a67ecb869b))
- adding release configs ([47b507f](https://github.com/module-federation/automatic-vendor-sharing/commit/47b507f5740b98cb70f8551461ada4a67ecb869b))
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"private": true,
"name": "@module-federation/automatic-vendor-federation",
"version": "1.0.0",
"main": "AutomaticVendorFederation.js",
Expand Down
Loading

0 comments on commit df35664

Please sign in to comment.