Skip to content

Commit c3f391f

Browse files
authored
Merge pull request #3 from EladBezalel/feat/packageJsonPath
feat: support different package.json location
2 parents 3786281 + 9fdf7de commit c3f391f

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,20 @@ export default {
3030
],
3131
}
3232
```
33+
34+
## Options
35+
### packageJsonPath
36+
If your `package.json` is not in the current working directory you can specify the path to the file
37+
```javascript
38+
// Add to plugins array in rollup.config.js
39+
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
40+
41+
export default {
42+
plugins: [
43+
// Preferably set as first plugin.
44+
peerDepsExternal({
45+
packageJsonPath: 'my/folder/package.json'
46+
}),
47+
],
48+
}
49+
```

src/get-peer-deps.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
export default function getPeerDeps() {
1+
const { resolve } = require('path');
2+
3+
export default function getPeerDeps(path = resolve(process.cwd(), 'package.json')) {
24
try {
3-
const { resolve } = require('path');
4-
const pkg = require(resolve(process.cwd(), 'package.json'));
5+
const pkg = require(path);
56
return Object.keys(pkg.peerDependencies);
67
} catch (err) {
78
return [];

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import externalToFn from './external-to-fn';
33
import getModulesMatcher from './get-modules-matcher';
44
import getPeerDeps from './get-peer-deps';
55

6-
export default function PeerDepsExternalPlugin() {
6+
export default function PeerDepsExternalPlugin({packageJsonPath} = {}) {
77
return {
88
name: 'peer-deps-external',
99
options: opts => {
1010
opts.external = either(
1111
// Retain existing `external` config
1212
externalToFn(opts.external),
1313
// Add `peerDependencies` to `external` config
14-
getModulesMatcher(getPeerDeps())
14+
getModulesMatcher(getPeerDeps(packageJsonPath))
1515
);
1616

1717
return opts;

0 commit comments

Comments
 (0)