Skip to content

Commit

Permalink
Basic knip configuration to replace ts-prune (#2418)
Browse files Browse the repository at this point in the history
<!--
  How to write a good PR title:
- Follow [the Conventional Commits
specification](https://www.conventionalcommits.org/en/v1.0.0/).
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->

## Self Checklist

- [x] I wrote a PR title in **English** and added an appropriate
**label** to the PR.
- [x] I wrote the commit message in **English** and to follow [**the
Conventional Commits
specification**](https://www.conventionalcommits.org/en/v1.0.0/).
- [x] I [added the
**changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)
about the changes that needed to be released. (or didn't have to)
- [x] I wrote or updated **documentation** related to the changes. (or
didn't have to)
- [x] I wrote or updated **tests** related to the changes. (or didn't
have to)
- [x] I tested the changes in various browsers. (or didn't have to)
  - Windows: Chrome, Edge, (Optional) Firefox
  - macOS: Chrome, Edge, Safari, (Optional) Firefox

## Related Issue

<!-- Please link to issue if one exists -->

<!-- Fixes #0000 -->

It resolves #2092 

## Summary

<!-- Please brief explanation of the changes made -->

- Replace usage of `ts-prune`to `knip` as `ts-prune` will no longer be
maintained

## Details

<!-- Please elaborate description of the changes -->

- Uninstall `ts-prune` and delete `tsconfig.prune.json` (which was
originally setup in `packages/bezier-react`)
- Install `knip` and add basic configuration on `knip.json` at the root
directory (to allow future expansion to other workspaces)
- To match the original `ts-prune` setup, only "files", "exports",
"types", "nsExports", "nsTypes" will be checked as errors (refer to the
[knip
documentation](https://knip.dev/explanations/comparison-and-migration#ts-prune))
- Although it is possible to check all workspaces within the monorepo,
it is currently restricted to check `packages/bezier-react` only (refer
to the [knip
documentation](https://knip.dev/features/monorepos-and-workspaces#lint-a-single-workspace))

### Breaking change? (No)

<!-- If Yes, please describe the impact and migration path for users -->

- To make `knip` work for all the other workspaces too (not only
`packages/bezier-react`), additional configuration in `knip.json` is
needed (refer to the [knip
documentation](https://knip.dev/explanations/entry-files))

## References

<!-- Please list any other resources or points the reviewer should be
aware of -->

---------

Co-authored-by: Yang Wooseong (Andrew) <[email protected]>
  • Loading branch information
babycroc and yangwooseong authored Oct 16, 2024
1 parent c74a48c commit b25b60c
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 66 deletions.
27 changes: 27 additions & 0 deletions knip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"workspaces": {
".": {
"project": "src/**/*!"
},
"packages/bezier-react": {
"entry": "src/index.ts!",
"project": "src/**/*!",
"ignore": ["**/__mocks__/**", "src/utils/test.tsx"]
}
},
"rules": {
"files": "error",
"dependencies": "off",
"unlisted": "off",
"binaries": "off",
"unresolved": "off",
"exports": "error",
"types": "error",
"nsExports": "error",
"nsTypes": "error",
"enumMembers": "off",
"classMembers": "off",
"duplicates": "off"
},
"ignore": []
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"release": "turbo run build --filter='@channel.io/*' && changeset publish",
"update-snapshot": "yarn workspace @channel.io/bezier-react update-snapshot",
"changeset": "changeset",
"postinstall": "husky install"
"postinstall": "husky install",
"knip": "knip --config knip.json --workspace packages/bezier-react --cache"
},
"devDependencies": {
"@changesets/cli": "^2.27.1",
Expand All @@ -37,6 +38,7 @@
"husky": "^9.0.11",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"knip": "^5.27.3",
"npm-run-all2": "^6.1.2",
"prettier": "^3.2.5",
"stylelint": "^16.3.0",
Expand Down
4 changes: 1 addition & 3 deletions packages/bezier-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
"lint": "run-p 'lint:*'",
"lint:js": "TIMING=1 eslint --cache .",
"lint:style": "stylelint --cache '**/*.scss'",
"typecheck": "yarn find-deadcode && tsc --noEmit",
"find-deadcode": "ts-prune -e -p ./tsconfig.prune.json",
"typecheck": "tsc --noEmit",
"test": "jest --coverage",
"test:watch": "jest --watch",
"update-snapshot": "jest --updateSnapshot",
Expand Down Expand Up @@ -114,7 +113,6 @@
"sass-loader": "^14.2.1",
"storybook": "^8.1.10",
"ts-patch": "^3.1.2",
"ts-prune": "^0.10.3",
"tsconfig": "workspace:*",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"typescript-plugin-css-modules": "^5.1.0",
Expand Down
5 changes: 0 additions & 5 deletions packages/bezier-react/tsconfig.prune.json

This file was deleted.

5 changes: 5 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
"outputs": [".jestcache/**", "coverage/*"],
"inputs": ["src/**/*.tsx", "src/**/*.ts", "src/**/*.js"]
},
"//#knip": {
"outputs": ["node_modules/.cache/knip"],
"inputs": ["knip.json", "packages/bezier-react/src/**/*"]
},

"dev": {
"cache": false,
"persistent": true
Expand Down
Loading

0 comments on commit b25b60c

Please sign in to comment.