List up libraries that are defined in dependencies and devDependencies in package.json but not used in your codes.
You can use depcheck to check if the libraries defined in package.json are used in your code.
The result of the confirmation can be notified to the user in a PR comment at the time the GitHub Actions are executed, as shown in the example below.
- Unused dependencies section indicates that the libraries defined in the package.json dependencies are not used in your
.js
,.ts
,.jsx
,.tsx
,.coffee
,.sass
,.scss
, and.vue
files. - Unused devDpendencies section also shows that the libraries defined in devDependencies in package.json are not present in each file.
- Missing section indicates that the library used in the code is not present in package.json. It is likely that you are using a library that is imported from CDN or declared globally.
Use the depcheck aciton in your repository's GitHub Actions, which requires GitHub Token and PR comment URL as inputs, both of which can be retrieved as environment variables in GitHub Actions. Both of them can be retrieved as GitHub Actions environment variables. (Make sure to set the Action trigger to pull_request.)
- GITHUB_TOKEN
- It can be retrieved as
secrets.GITHUB_TOKEN
.
- It can be retrieved as
- PR_COMMENT_URL
- You can retrieve them from
github.event.pull_request.comments_url
during PR events.
- You can retrieve them from
on:
pull_request:
branches:
- master
build:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: "depcheck"
uses: tubone24/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_COMMENT_URL: ${{ github.event.pull_request.comments_url }}
PRs accepted.
Small note: If editing the Readme, please conform to the standard-readme specification.