@jmlweb/tsconfig-node 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +248 -0
- package/package.json +40 -0
- package/tsconfig.json +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# @jmlweb/tsconfig-node
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@jmlweb/tsconfig-node)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
|
|
8
|
+
> TypeScript configuration for Node.js and CLI projects. Extends `@jmlweb/tsconfig-base` with Node.js-specific settings, excluding DOM types and including only ES library types.
|
|
9
|
+
|
|
10
|
+
## ✨ Features
|
|
11
|
+
|
|
12
|
+
- 🔒 **Strict Type Checking**: Inherits all strict TypeScript rules from base config
|
|
13
|
+
- 🖥️ **Node.js Optimized**: Excludes DOM types, includes only ES2022 library types
|
|
14
|
+
- 📦 **NodeNext Modules**: Uses NodeNext module resolution (inherited from base)
|
|
15
|
+
- 🎯 **Clean Types**: No browser/DOM APIs, only Node.js and ES APIs
|
|
16
|
+
- 🚀 **Extensible**: Extends base config, easy to customize
|
|
17
|
+
|
|
18
|
+
## 📦 Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install --save-dev @jmlweb/tsconfig-node typescript @jmlweb/tsconfig-base
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 🚀 Quick Start
|
|
25
|
+
|
|
26
|
+
Create a `tsconfig.json` file in your project root:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"extends": "@jmlweb/tsconfig-node",
|
|
31
|
+
"compilerOptions": {
|
|
32
|
+
"outDir": "./dist",
|
|
33
|
+
"rootDir": "./src"
|
|
34
|
+
},
|
|
35
|
+
"include": ["src/**/*"],
|
|
36
|
+
"exclude": ["node_modules", "dist"]
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 💡 Examples
|
|
41
|
+
|
|
42
|
+
### Basic Node.js API
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"extends": "@jmlweb/tsconfig-node",
|
|
47
|
+
"compilerOptions": {
|
|
48
|
+
"outDir": "./dist",
|
|
49
|
+
"rootDir": "./src"
|
|
50
|
+
},
|
|
51
|
+
"include": ["src/**/*"],
|
|
52
|
+
"exclude": ["node_modules", "dist"]
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### CLI Tool
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"extends": "@jmlweb/tsconfig-node",
|
|
61
|
+
"compilerOptions": {
|
|
62
|
+
"outDir": "./dist",
|
|
63
|
+
"rootDir": "./src"
|
|
64
|
+
},
|
|
65
|
+
"include": ["src/**/*"],
|
|
66
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Library Package
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"extends": "@jmlweb/tsconfig-node",
|
|
75
|
+
"compilerOptions": {
|
|
76
|
+
"outDir": "./dist",
|
|
77
|
+
"rootDir": "./src",
|
|
78
|
+
"composite": true,
|
|
79
|
+
"declarationDir": "./dist"
|
|
80
|
+
},
|
|
81
|
+
"include": ["src/**/*"],
|
|
82
|
+
"exclude": ["node_modules", "dist"]
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### With Path Mapping
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{
|
|
90
|
+
"extends": "@jmlweb/tsconfig-node",
|
|
91
|
+
"compilerOptions": {
|
|
92
|
+
"outDir": "./dist",
|
|
93
|
+
"baseUrl": ".",
|
|
94
|
+
"paths": {
|
|
95
|
+
"@/*": ["./src/*"],
|
|
96
|
+
"@/utils/*": ["./src/utils/*"]
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"include": ["src/**/*"],
|
|
100
|
+
"exclude": ["node_modules", "dist"]
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 📋 Configuration Details
|
|
105
|
+
|
|
106
|
+
### What's Included
|
|
107
|
+
|
|
108
|
+
This configuration extends `@jmlweb/tsconfig-base` and adds:
|
|
109
|
+
|
|
110
|
+
- ✅ **ES Library Types Only**: `lib: ["ES2022"]` - excludes DOM types
|
|
111
|
+
- ✅ **Node.js Module Resolution**: Inherits `NodeNext` from base config
|
|
112
|
+
- ✅ **All Base Config**: Inherits strict type checking and best practices
|
|
113
|
+
|
|
114
|
+
### Library Types
|
|
115
|
+
|
|
116
|
+
This config explicitly sets `lib: ["ES2022"]` to:
|
|
117
|
+
|
|
118
|
+
- ✅ Include ES2022 language features and APIs
|
|
119
|
+
- ✅ Exclude DOM types (no `window`, `document`, etc.)
|
|
120
|
+
- ✅ Rely on `@types/node` for Node.js-specific types (installed separately)
|
|
121
|
+
|
|
122
|
+
**Why exclude DOM types?**
|
|
123
|
+
|
|
124
|
+
For Node.js projects, DOM types are unnecessary and can lead to:
|
|
125
|
+
|
|
126
|
+
- Accidental use of browser APIs
|
|
127
|
+
- Larger type definitions
|
|
128
|
+
- Confusion between Node.js and browser APIs
|
|
129
|
+
|
|
130
|
+
### Module Resolution
|
|
131
|
+
|
|
132
|
+
Uses `NodeNext` (inherited from base config), which:
|
|
133
|
+
|
|
134
|
+
- ✅ Supports both CommonJS and ESM
|
|
135
|
+
- ✅ Respects `package.json` `type` field
|
|
136
|
+
- ✅ Works with modern Node.js module systems
|
|
137
|
+
- ✅ Supports `.mjs` and `.cjs` extensions
|
|
138
|
+
|
|
139
|
+
## 🎯 When to Use
|
|
140
|
+
|
|
141
|
+
Use this configuration when you want:
|
|
142
|
+
|
|
143
|
+
- ✅ Node.js API servers
|
|
144
|
+
- ✅ CLI tools and utilities
|
|
145
|
+
- ✅ Node.js libraries and packages
|
|
146
|
+
- ✅ Backend services
|
|
147
|
+
- ✅ Scripts and automation tools
|
|
148
|
+
- ✅ Pure Node.js projects (no browser code)
|
|
149
|
+
|
|
150
|
+
**For React projects**, use [`@jmlweb/tsconfig-react`](../tsconfig-react) instead.
|
|
151
|
+
|
|
152
|
+
**For Next.js projects**, use [`@jmlweb/tsconfig-nextjs`](../tsconfig-nextjs) instead.
|
|
153
|
+
|
|
154
|
+
**For internal tooling projects**, use [`@jmlweb/tsconfig-internal`](../tsconfig-internal) instead.
|
|
155
|
+
|
|
156
|
+
## 🔧 Extending the Configuration
|
|
157
|
+
|
|
158
|
+
You can extend or override the configuration for your specific needs:
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"extends": "@jmlweb/tsconfig-node",
|
|
163
|
+
"compilerOptions": {
|
|
164
|
+
"outDir": "./dist",
|
|
165
|
+
"target": "ES2020",
|
|
166
|
+
"paths": {
|
|
167
|
+
"@/*": ["./src/*"]
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
"include": ["src/**/*"],
|
|
171
|
+
"exclude": ["node_modules", "dist"]
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## 📝 Usage with Scripts
|
|
176
|
+
|
|
177
|
+
TypeScript compilation is typically handled by your build tool. For manual compilation:
|
|
178
|
+
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"scripts": {
|
|
182
|
+
"build": "tsc",
|
|
183
|
+
"typecheck": "tsc --noEmit",
|
|
184
|
+
"watch": "tsc --watch"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Usage with Build Tools
|
|
190
|
+
|
|
191
|
+
#### tsup
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
// tsup.config.ts
|
|
195
|
+
import { defineConfig } from 'tsup';
|
|
196
|
+
|
|
197
|
+
export default defineConfig({
|
|
198
|
+
entry: ['src/index.ts'],
|
|
199
|
+
format: ['cjs', 'esm'],
|
|
200
|
+
dts: true,
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### tsx (for development)
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# Run TypeScript files directly
|
|
208
|
+
tsx src/index.ts
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## 📋 Requirements
|
|
212
|
+
|
|
213
|
+
- **Node.js** >= 18.0.0
|
|
214
|
+
- **TypeScript** >= 5.0.0
|
|
215
|
+
- **@types/node** (recommended) - Install separately for Node.js type definitions
|
|
216
|
+
|
|
217
|
+
## 📦 Peer Dependencies
|
|
218
|
+
|
|
219
|
+
This package requires the following peer dependencies:
|
|
220
|
+
|
|
221
|
+
- `typescript` (>= 5.0.0)
|
|
222
|
+
- `@jmlweb/tsconfig-base` (^1.0.0)
|
|
223
|
+
|
|
224
|
+
### Recommended Dependencies
|
|
225
|
+
|
|
226
|
+
For Node.js projects, you should also install:
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
npm install --save-dev @types/node
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
This provides Node.js-specific type definitions like `Buffer`, `process`, `fs`, etc.
|
|
233
|
+
|
|
234
|
+
## 📚 Examples
|
|
235
|
+
|
|
236
|
+
See real-world usage examples:
|
|
237
|
+
|
|
238
|
+
- [`example-nodejs-typescript-api`](../../apps/example-nodejs-typescript-api) - Node.js TypeScript API example
|
|
239
|
+
|
|
240
|
+
## 🔗 Related Packages
|
|
241
|
+
|
|
242
|
+
- [`@jmlweb/tsconfig-base`](../tsconfig-base) - Base TypeScript configuration (extended by this package)
|
|
243
|
+
- [`@jmlweb/eslint-config-base`](../eslint-config-base) - ESLint configuration for TypeScript projects
|
|
244
|
+
- [`@jmlweb/prettier-config-base`](../prettier-config-base) - Prettier config for consistent formatting
|
|
245
|
+
|
|
246
|
+
## 📄 License
|
|
247
|
+
|
|
248
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jmlweb/tsconfig-node",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript configuration for Node.js and CLI projects. Extends @jmlweb/tsconfig-base with Node.js-specific settings excluding DOM types.",
|
|
5
|
+
"main": "tsconfig.json",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./tsconfig.json"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"tsconfig.json",
|
|
11
|
+
"README.md",
|
|
12
|
+
"CHANGELOG.md"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"config",
|
|
16
|
+
"node",
|
|
17
|
+
"nodejs",
|
|
18
|
+
"cli",
|
|
19
|
+
"strict",
|
|
20
|
+
"tsconfig",
|
|
21
|
+
"type-checking",
|
|
22
|
+
"typescript"
|
|
23
|
+
],
|
|
24
|
+
"author": "jmlweb",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": "jmlweb/tooling.git",
|
|
27
|
+
"bugs": "https://github.com/jmlweb/tooling/issues",
|
|
28
|
+
"homepage": "https://github.com/jmlweb/tooling/tree/main/packages/tsconfig-node#readme",
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18.0.0"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@jmlweb/tsconfig-base": "^1.0.0",
|
|
37
|
+
"typescript": ">=5.0.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {}
|
|
40
|
+
}
|