-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add PREFER_PEER_DEPS doctor rule (#617)
- Loading branch information
1 parent
d6da2a1
commit 376407b
Showing
3 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { IDoctorReport } from '..'; | ||
import type { IApi } from '../../types'; | ||
|
||
const PREFER_PEER_DEPS = ['react', 'react-dom', 'antd']; | ||
|
||
export default (api: IApi) => { | ||
api.addRegularCheckup(() => { | ||
const warns: IDoctorReport = []; | ||
|
||
if (api.pkg.dependencies) { | ||
Object.keys(api.pkg.dependencies).forEach((pkg) => { | ||
if ( | ||
PREFER_PEER_DEPS.includes(pkg) && | ||
!api.pkg.peerDependencies?.[pkg] | ||
) { | ||
warns.push({ | ||
type: 'warn', | ||
problem: `The dependency \`${pkg}\` has multi-instance risk in host project`, | ||
solution: 'Move it into `peerDependencies` from `dependencies`', | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
return warns; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters