@line/ts-remove-unused
Advanced tools
Comparing version 0.2.0 to 0.3.0
{ | ||
"name": "@line/ts-remove-unused", | ||
"version": "0.2.0", | ||
"description": "Remove unused code from your TypeScript project", | ||
@@ -11,12 +10,16 @@ "type": "module", | ||
"license": "Apache-2.0", | ||
"bin": "dist/index.js", | ||
"bin": "dist/cli.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"exports": { | ||
".": "./dist/main.js" | ||
}, | ||
"types": "./dist/main.d.ts", | ||
"scripts": { | ||
"lint": "eslint . --ext .ts,.cjs,.js", | ||
"build": "rm -rf dist && tsc --outDir dist", | ||
"type-check": "tsc --noEmit", | ||
"build": "rm -rf dist && node ./build.js", | ||
"type-check": "tsc -b", | ||
"prepublishOnly": "npm run build", | ||
"test": "glob -c 'node --loader ts-node/esm --test' 'src/**/*.test.ts'" | ||
"test": "TS_NODE_PROJECT=tsconfig.test.json glob -c 'node --loader ts-node/esm --test' 'lib/**/*.test.ts' 'test/**/*.test.ts'" | ||
}, | ||
@@ -27,2 +30,3 @@ "devDependencies": { | ||
"@typescript-eslint/parser": "^6.4.1", | ||
"esbuild": "^0.23.1", | ||
"eslint": "^8.48.0", | ||
@@ -37,7 +41,8 @@ "eslint-config-prettier": "^9.0.0", | ||
"cac": "^6.7.14", | ||
"ts-morph": "^17.0.1" | ||
"chalk": "^5.3.0" | ||
}, | ||
"peerDependencies": { | ||
"typescript": ">=4.0.0" | ||
} | ||
}, | ||
"version": "0.3.0" | ||
} |
@@ -16,3 +16,3 @@ # ts-remove-unused | ||
Usage: | ||
$ ts-remove-unused | ||
$ ts-remove-unused | ||
@@ -26,8 +26,8 @@ Commands: | ||
Options: | ||
--project <file> Path to your tsconfig.json | ||
--skip <regexp_pattern> Specify the regexp pattern to match files that should be skipped from transforming | ||
--include-d-ts Include .d.ts files in target for transformation | ||
-h, --help Display this message | ||
-v, --version Display version number | ||
--project <file> Path to your tsconfig.json | ||
--skip <regexp_pattern> Specify the regexp pattern to match files that should be skipped from transforming | ||
--include-d-ts Include .d.ts files in target for transformation | ||
--check Check if there are any unused exports without removing them | ||
-h, --help Display this message | ||
-v, --version Display version number | ||
``` | ||
@@ -40,5 +40,29 @@ | ||
``` | ||
ts-remove-unused --skip 'src\/index\.ts' | ||
npx ts-remove-unused --skip 'src\/index\.ts' | ||
``` | ||
### Check | ||
Use `--check` to check for unused files and exports without making changes to project files. The command will exit with | ||
code: 1 if there are any unused files or exports discovered. | ||
``` | ||
npx ts-remove-unused --check | ||
``` | ||
### Use the JavaScript API | ||
Alternatively, you can use the JavaScript API to execute ts-remove-unused. | ||
```typescript | ||
import { remove } from '@line/ts-remove-unused'; | ||
remove({ | ||
configPath: '/path/to/project/tsconfig.json', | ||
projectRoot: '/path/to/project', | ||
skip: [/main.ts/], | ||
mode: 'write', | ||
}); | ||
``` | ||
### Skip removing unused exports | ||
@@ -55,14 +79,2 @@ | ||
## Known Issue | ||
Since this CLI uses TypeScript's transformer API, it can't preserve the original format of the file. Although most of the format change can be restored using linters like prettier, empty lines will be omitted. Here's a workaround for this issue using git. | ||
```bash | ||
npx ts-remove-unused ## execute the cli | ||
npx prettier --write . ## fix the format | ||
git add . | ||
git commit ## commit first | ||
git checkout HEAD~1 -- . && git diff HEAD~1 HEAD --ignore-blank-lines | git apply && git reset ## this will try to restore irrelevant changes of empty lines caused by the first commit | ||
``` | ||
## License | ||
@@ -69,0 +81,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
54894
1397
93
10
16
1
+ Addedchalk@^5.3.0
+ Addedchalk@5.4.1(transitive)
- Removedts-morph@^17.0.1
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removed@ts-morph/common@0.18.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@2.0.1(transitive)
- Removedbraces@3.0.3(transitive)
- Removedcode-block-writer@11.0.3(transitive)
- Removedfast-glob@3.3.3(transitive)
- Removedfastq@1.18.0(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@7.0.0(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedminimatch@5.1.6(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removedpath-browserify@1.0.1(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedts-morph@17.0.1(transitive)