Skip to content

Commit 9787607

Browse files
committed
docs: improve ts-plugin installation and usage instructions (#14)
Some parts are from: https://github.com/nonara/ts-patch?tab=readme-ov-file#usage
1 parent c21d3de commit 9787607

File tree

2 files changed

+79
-27
lines changed

2 files changed

+79
-27
lines changed

README.md

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,16 @@ _(See more advanced `tryCatch` usage examples and API reference further down.)_
163163
## Installation
164164

165165
```bash
166+
# 1. Install the utility (prod dependency):
167+
npm i @maxmorozoff/try-catch-tuple
168+
169+
# 2. Install ts plugin (dev dependencies):
170+
166171
# If using the build transformer, ts-patch is also required
167-
npm i -D @maxmorozoff/try-catch-tuple @maxmorozoff/try-catch-tuple-ts-plugin ts-patch typescript
172+
npm i -D @maxmorozoff/try-catch-tuple-ts-plugin ts-patch typescript
168173

169174
# Or for utility + LSP only:
170-
npm i -D @maxmorozoff/try-catch-tuple @maxmorozoff/try-catch-tuple-ts-plugin typescript
171-
172-
# Or for utility only:
173-
npm i -D @maxmorozoff/try-catch-tuple typescript
175+
npm i -D @maxmorozoff/try-catch-tuple-ts-plugin typescript
174176
```
175177

176178
## Configuration (`tsconfig.json`)
@@ -222,16 +224,47 @@ Configure the tooling under `compilerOptions.plugins`.
222224

223225
## Usage
224226

225-
**1. IDE (Language Service Plugin):**
227+
### 1. IDE (Language Service Plugin)
226228

229+
- **Select Workspace TypeScript Version:** Ensure your editor is using the workspace's TypeScript version instead of the built-in one (e.g., VS Code: `TypeScript: Select TypeScript Version`).
227230
- **Restart TS Server:** After configuring the plugin, **restart the TypeScript Server** (e.g., VS Code: `TypeScript: Restart TS server`).
228231
- Errors will be underlined, and Quick Fixes will be available.
229232

230-
**2. Build (Transformer):**
233+
### 2. Build (Transformer)
234+
235+
#### Method 1: Live Compiler
236+
237+
The live compiler patches on-the-fly, each time it is run.
238+
239+
**Via commandline:** Simply use `tspc` (instead of `tsc`)
240+
241+
**With tools such as ts-node, webpack, ts-jest, etc:** specify the compiler as `ts-patch/compiler`
242+
243+
#### Method 2: Persistent Patch
244+
245+
Persistent patch modifies the typescript installation within the `node_modules` path. It requires additional configuration
246+
to remain persisted, but it carries less load time and complexity compared to the live compiler.
247+
248+
1. Install the patch
249+
250+
```shell
251+
# For advanced options, see: ts-patch /?
252+
ts-patch install
253+
```
254+
255+
2. Add `prepare` script (keeps patch persisted after npm install)
256+
257+
`package.json`
258+
```jsonc
259+
{
260+
/* ... */
261+
"scripts": {
262+
"prepare": "ts-patch install -s"
263+
}
264+
}
265+
```
231266

232-
- **Install `ts-patch`:** `npm i -D ts-patch` (if needed).
233-
- **Patch TypeScript:** `npx ts-patch install` (run once).
234-
- **Run Build:** Use `tspc` in your build scripts: `"build": "tspc -p tsconfig.json"`. Errors/warnings appear in `tsc` output.
267+
For advanced options, see: [ts-patch docs](https://github.com/nonara/ts-patch?tab=readme-ov-file#usage)
235268

236269
## Configuration Options (Plugin & Transformer)
237270

packages/ts-plugin/README.md

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ The primary goal is to prevent developers from incorrectly handling the results
2626

2727
## Installation
2828

29+
Add the following packages to your _development_ dependencies:
30+
2931
```bash
3032
# If using the build transformer, ts-patch is also required
3133
npm i -D @maxmorozoff/try-catch-tuple-ts-plugin ts-patch typescript
3234
# Or for LSP only:
33-
# npm i -D @maxmorozoff/try-catch-tuple-ts-plugin typescript
35+
npm i -D @maxmorozoff/try-catch-tuple-ts-plugin typescript
3436
```
3537

3638
## Configuration (`tsconfig.json`)
@@ -104,32 +106,49 @@ This is the preferred way if using both, as configuration is shared.
104106
}
105107
```
106108

107-
108109
## Usage
109110

110-
**1. IDE (Language Service Plugin):**
111+
### 1. IDE (Language Service Plugin)
112+
113+
- **Select Workspace TypeScript Version:** Ensure your editor is using the workspace's TypeScript version instead of the built-in one (e.g., VS Code: `TypeScript: Select TypeScript Version`).
114+
- **Restart TS Server:** After configuring the plugin, **restart the TypeScript Server** (e.g., VS Code: `TypeScript: Restart TS server`).
115+
- Errors will be underlined, and Quick Fixes will be available.
116+
117+
### 2. Build (Transformer)
118+
119+
#### Method 1: Live Compiler
120+
121+
The live compiler patches on-the-fly, each time it is run.
122+
123+
**Via commandline:** Simply use `tspc` (instead of `tsc`)
111124

112-
- **Restart TS Server:** After adding/changing the plugin configuration in `tsconfig.json`, you **must restart the TypeScript Server** in your editor.
113-
- _VS Code:_ Open the Command Palette (`Ctrl+Shift+P` or `Cmd+Shift+P`) and run `TypeScript: Restart TS server`.
114-
- You should now see errors/warnings underlined in your code and have Quick Fixes available.
125+
**With tools such as ts-node, webpack, ts-jest, etc:** specify the compiler as `ts-patch/compiler`
115126

116-
**2. Build (Transformer):**
127+
#### Method 2: Persistent Patch
117128

118-
- **Install `ts-patch`:** (If not already done) `npm i -D ts-patch`
119-
- **Patch TypeScript:** Run `npx ts-patch install` (or `yarn ts-patch install`) in your project root. This only needs to be done once or after updating TypeScript/ts-patch.
120-
- **Run Build:** Use `tspc` instead of `tsc` in your build scripts/commands.
129+
Persistent patch modifies the typescript installation within the `node_modules` path. It requires additional configuration
130+
to remain persisted, but it carries less load time and complexity compared to the live compiler.
121131

122-
```bash
123-
# Example command
124-
npx tspc -p tsconfig.json
132+
1. Install the patch
125133

126-
# Example package.json script
134+
```shell
135+
# For advanced options, see: ts-patch /?
136+
ts-patch install
137+
```
138+
139+
2. Add `prepare` script (keeps patch persisted after npm install)
140+
141+
`package.json`
142+
```jsonc
143+
{
144+
/* ... */
127145
"scripts": {
128-
"build": "tspc -p tsconfig.json"
146+
"prepare": "ts-patch install -s"
129147
}
130-
```
148+
}
149+
```
131150

132-
Build errors/warnings from the transformer will appear in the `tsc` output.
151+
For advanced options, see: [ts-patch docs](https://github.com/nonara/ts-patch?tab=readme-ov-file#usage)
133152

134153
## Configuration Options
135154

0 commit comments

Comments
 (0)