Skip to content

Commit

Permalink
Merge pull request #3 from EladBezalel/feat/packageJsonPath
Browse files Browse the repository at this point in the history
feat: support different package.json location
  • Loading branch information
pmowrer authored Feb 27, 2018
2 parents 3786281 + 9fdf7de commit c3f391f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,20 @@ export default {
],
}
```

## Options
### packageJsonPath
If your `package.json` is not in the current working directory you can specify the path to the file
```javascript
// Add to plugins array in rollup.config.js
import peerDepsExternal from 'rollup-plugin-peer-deps-external';

export default {
plugins: [
// Preferably set as first plugin.
peerDepsExternal({
packageJsonPath: 'my/folder/package.json'
}),
],
}
```
7 changes: 4 additions & 3 deletions src/get-peer-deps.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export default function getPeerDeps() {
const { resolve } = require('path');

export default function getPeerDeps(path = resolve(process.cwd(), 'package.json')) {
try {
const { resolve } = require('path');
const pkg = require(resolve(process.cwd(), 'package.json'));
const pkg = require(path);
return Object.keys(pkg.peerDependencies);
} catch (err) {
return [];
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import externalToFn from './external-to-fn';
import getModulesMatcher from './get-modules-matcher';
import getPeerDeps from './get-peer-deps';

export default function PeerDepsExternalPlugin() {
export default function PeerDepsExternalPlugin({packageJsonPath} = {}) {
return {
name: 'peer-deps-external',
options: opts => {
opts.external = either(
// Retain existing `external` config
externalToFn(opts.external),
// Add `peerDependencies` to `external` config
getModulesMatcher(getPeerDeps())
getModulesMatcher(getPeerDeps(packageJsonPath))
);

return opts;
Expand Down

0 comments on commit c3f391f

Please sign in to comment.