Skip to content

Commit e8fdc3f

Browse files
committed
feat: --unpatch option
1 parent 3cfdffd commit e8fdc3f

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ import ts from 'unleashed-typescript';
3737

3838
# CLI
3939

40+
With no arguments `unleashed-typescript` patches your current version of typescript **if it is not already patched**. If you want to sync your version after an update you can use the `--force-patch` option.
41+
4042
```bash
4143
Usage: unleashed-typescript [options]
4244

4345
Options:
44-
--upgrade Upgrade the unleashed version from your current version.
46+
--unpatch Revert the patch (useful before a build/publish).
47+
--force-patch Force patch from your current typescript version.
4548
```
4649

4750
# Alternatives

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"typescript": "^4.7.4"
5757
},
5858
"peerDependencies": {
59-
"typescript": "^4.7.4"
59+
"typescript": "*"
6060
},
6161
"keywords": [
6262
"typescript",

src/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@ export function build(): void {
2323
const typescript: Patch = { version: '', path: '' };
2424
let unleashed: Patch = { version: '', path: '' };
2525

26-
const upgradeFlag = process.argv.includes('--upgrade');
26+
const unpatchFlag = process.argv.includes('--unpatch');
27+
const forcePatchFlag = process.argv.includes('--force-patch');
2728

2829
const unleashedDir = resolve(__dirname, '../unleashed-typescript');
2930
const unleashedJSON = resolve(unleashedDir, 'unleashed-typescript.json');
3031

3132
// Clean build
32-
if (upgradeFlag) {
33+
if (unpatchFlag || forcePatchFlag) {
34+
info('Unpatch unleashed-typescript.');
3335
removeSync(unleashedDir);
36+
37+
if (unpatchFlag) {
38+
info('Done!');
39+
process.exit(0);
40+
}
3441
}
3542

3643
// Try to find the local typescript package
@@ -43,7 +50,7 @@ export function build(): void {
4350
}
4451

4552
// Test if we already have a patched version.
46-
if (!upgradeFlag && existsSync(unleashedDir)) {
53+
if (!forcePatchFlag && existsSync(unleashedDir)) {
4754
try {
4855
unleashed = readJsonSync(unleashedJSON) as Patch;
4956
} catch (_err) {
@@ -53,7 +60,7 @@ export function build(): void {
5360
}
5461
}
5562

56-
if (!upgradeFlag && unleashed.version) {
63+
if (!forcePatchFlag && unleashed.version) {
5764
const message = `Already build from typescript@${unleashed.version}.`;
5865

5966
if (typescript.version === unleashed.version) {
@@ -71,7 +78,7 @@ export function build(): void {
7178
info(`Found typescript@${typescript.version} at ${typescript.path}`);
7279
info(`Copy typescript@${typescript.version} to ${unleashedDir}`);
7380

74-
copySync(typescript.path, unleashedDir, { overwrite: upgradeFlag });
81+
copySync(typescript.path, unleashedDir, { overwrite: forcePatchFlag });
7582
writeJSONSync(unleashedJSON, typescript);
7683

7784
// Apply all rules

0 commit comments

Comments
 (0)