@shibanet0/datamitsu-config 0.0.3-alpha-17 → 0.0.3-alpha-19
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/TSCONFIG.md +244 -0
- package/bin/datamitsu.js +4 -2
- package/bin/tsc.js +4 -2
- package/bin/tsx.js +4 -4
- package/datamitsu.config.js +4693 -5382
- package/dist/apps/knip/index.js +8 -0
- package/dist/datamitsu-config/inline-config/commitlint.d.ts +1 -1
- package/dist/datamitsu-config/inline-config/cspell.d.ts +1 -1
- package/dist/datamitsu-config/inline-config/eslint.d.ts +1 -1
- package/dist/datamitsu-config/inline-config/knip.d.ts +1 -1
- package/dist/datamitsu-config/inline-config/prettier.d.ts +1 -1
- package/dist/datamitsu.config.d.ts +17 -0
- package/dist/s0/index.js +442 -506
- package/package.json +5 -6
package/TSCONFIG.md
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# TypeScript Configuration Guide
|
|
2
|
+
|
|
3
|
+
This package provides reusable TypeScript configurations for different project types.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- **TypeScript 6.0+** required
|
|
8
|
+
- Modern bundler (tsup, vite, esbuild)
|
|
9
|
+
|
|
10
|
+
## Quick Selection
|
|
11
|
+
|
|
12
|
+
| Project Type | Monorepo? | Config |
|
|
13
|
+
| ------------------- | --------- | ----------------------------- |
|
|
14
|
+
| Next.js app | Any | `nextjs.json` |
|
|
15
|
+
| React + Vite app | Any | `base.json` |
|
|
16
|
+
| React library | Yes | `shared-react-library.json` |
|
|
17
|
+
| React library | No | `react-library.json` |
|
|
18
|
+
| Node.js library | Yes | `shared-library.json` |
|
|
19
|
+
| Node.js library | No | `library.json` |
|
|
20
|
+
| Backend API/service | Any | `service.json` |
|
|
21
|
+
| Node.js CLI | Any | `base.json` or `service.json` |
|
|
22
|
+
| E2E tests | Any | `base.json` |
|
|
23
|
+
|
|
24
|
+
## Configuration Descriptions
|
|
25
|
+
|
|
26
|
+
### `base.json`
|
|
27
|
+
|
|
28
|
+
**For:** CLI tools, tests, build scripts, React apps (Vite, CRA)
|
|
29
|
+
|
|
30
|
+
**Features:**
|
|
31
|
+
|
|
32
|
+
- Strict typing by default
|
|
33
|
+
- `src/` → `dist/` structure
|
|
34
|
+
- Explicit configuration (all options specified)
|
|
35
|
+
|
|
36
|
+
**Example:**
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"extends": "@shibanet0/datamitsu-config/tsconfig/base.json"
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
### `library.json`
|
|
47
|
+
|
|
48
|
+
**For:** Standalone npm package (NOT in monorepo)
|
|
49
|
+
|
|
50
|
+
**Adds:** `noEmit: true` - bundler handles all output
|
|
51
|
+
|
|
52
|
+
**Example:** Standalone npm utility package
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
### `react-library.json`
|
|
57
|
+
|
|
58
|
+
**For:** Standalone React library (NOT in monorepo)
|
|
59
|
+
|
|
60
|
+
**Adds:**
|
|
61
|
+
|
|
62
|
+
- DOM types
|
|
63
|
+
- JSX support
|
|
64
|
+
- `noEmit: true`
|
|
65
|
+
|
|
66
|
+
**⚠️ WARNING:** DO NOT use for Node.js projects! Adds DOM types that don't exist in Node.js.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
### `service.json`
|
|
71
|
+
|
|
72
|
+
**For:** Backend APIs, serverless functions, microservices
|
|
73
|
+
|
|
74
|
+
**Adds:**
|
|
75
|
+
|
|
76
|
+
- `types: ["node"]`
|
|
77
|
+
- `noEmit: true`
|
|
78
|
+
|
|
79
|
+
**Example:** Express API, AWS Lambda
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
### `shared-library.json`
|
|
84
|
+
|
|
85
|
+
**For:** Library INSIDE a monorepo
|
|
86
|
+
|
|
87
|
+
**Adds:**
|
|
88
|
+
|
|
89
|
+
- `composite: true` - project references
|
|
90
|
+
- `declaration: true` - emits .d.ts
|
|
91
|
+
- `declarationMap: true`
|
|
92
|
+
|
|
93
|
+
**Why NOT noEmit:** Project references require TypeScript to emit declarations for IDE "go to definition".
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
### `shared-react-library.json`
|
|
98
|
+
|
|
99
|
+
**For:** React library INSIDE a monorepo
|
|
100
|
+
|
|
101
|
+
**Adds:**
|
|
102
|
+
|
|
103
|
+
- DOM types + JSX
|
|
104
|
+
- `composite: true`
|
|
105
|
+
- Declaration emit
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
### `nextjs.json`
|
|
110
|
+
|
|
111
|
+
**For:** Next.js apps (Pages/App Router)
|
|
112
|
+
|
|
113
|
+
**Features:**
|
|
114
|
+
|
|
115
|
+
- `jsx: "preserve"` - Next.js transforms itself
|
|
116
|
+
- `noEmit: true`
|
|
117
|
+
- Next.js plugin
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Common Mistakes
|
|
122
|
+
|
|
123
|
+
### ❌ react-library for Node.js projects
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
// WRONG for Node.js API
|
|
127
|
+
{
|
|
128
|
+
"extends": "@shibanet0/datamitsu-config/tsconfig/react-library.json"
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Problem:** Adds DOM types (`document`, `window`) to Node.js environment.
|
|
133
|
+
|
|
134
|
+
**Solution:** Use `service.json`
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
### ❌ library instead of shared-library in monorepo
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
// WRONG in monorepo
|
|
142
|
+
{
|
|
143
|
+
"extends": "@shibanet0/datamitsu-config/tsconfig/library.json"
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**Problem:** `noEmit: true` disables declaration emit, IDE can't "go to definition".
|
|
148
|
+
|
|
149
|
+
**Solution:** Use `shared-library.json`
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
### ❌ Forgot explicit types after TS6
|
|
154
|
+
|
|
155
|
+
**Problem:**
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { readFile } from "node:fs/promises";
|
|
159
|
+
// Error: Cannot find module 'node:fs/promises'
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Solution:**
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
{
|
|
166
|
+
"extends": "@shibanet0/datamitsu-config/tsconfig/service.json",
|
|
167
|
+
"compilerOptions": {
|
|
168
|
+
"types": ["node"]
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Path Aliases
|
|
176
|
+
|
|
177
|
+
**These configurations DO NOT include path aliases (`~/*`, `@/*`).**
|
|
178
|
+
|
|
179
|
+
**Why?**
|
|
180
|
+
|
|
181
|
+
- Require duplication in tsconfig, bundler, jest, eslint
|
|
182
|
+
- Problems when publishing libraries
|
|
183
|
+
- Different syntax across tools
|
|
184
|
+
|
|
185
|
+
**Use relative paths:**
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { helper } from "../../utils/helper";
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Benefits:**
|
|
192
|
+
|
|
193
|
+
- Work everywhere without configuration
|
|
194
|
+
- ES modules standard
|
|
195
|
+
- IDE auto-updates
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## Philosophy
|
|
200
|
+
|
|
201
|
+
**Bundler-centric approach:**
|
|
202
|
+
|
|
203
|
+
- TypeScript only for type checking
|
|
204
|
+
- Bundler handles compilation, sourcemaps, declarations
|
|
205
|
+
- Exception: monorepo `shared-*` configs emit declarations for project references
|
|
206
|
+
|
|
207
|
+
**Explicit configuration:**
|
|
208
|
+
|
|
209
|
+
- All options specified explicitly, even if they're TS6 defaults
|
|
210
|
+
- No magic, maximum compatibility
|
|
211
|
+
- "Just works" everywhere
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Migration to TS6
|
|
216
|
+
|
|
217
|
+
**TypeScript 6.0+ required:**
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
pnpm add -D typescript@latest
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
**Add explicit types:**
|
|
224
|
+
|
|
225
|
+
```json
|
|
226
|
+
{
|
|
227
|
+
"extends": "@shibanet0/datamitsu-config/tsconfig/service.json",
|
|
228
|
+
"compilerOptions": {
|
|
229
|
+
"types": ["node"]
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
**Check types:**
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
tsc --noEmit
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Based on
|
|
243
|
+
|
|
244
|
+
[@codecompose/typescript-config](https://github.com/0x80/typescript-config) by 0x80.
|
package/bin/datamitsu.js
CHANGED
package/bin/tsc.js
CHANGED
|
@@ -10,8 +10,10 @@ const child = spawn(getBinaryFilepath("typescript/package.json", "../bin/tsc"),
|
|
|
10
10
|
stdio: "inherit",
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
child.on("exit", (code) => {
|
|
14
|
-
if (
|
|
13
|
+
child.on("exit", (code, signal) => {
|
|
14
|
+
if (signal) {
|
|
15
|
+
process.kill(process.pid, signal);
|
|
16
|
+
} else if (code !== 0) {
|
|
15
17
|
process.exit(code);
|
|
16
18
|
}
|
|
17
19
|
});
|
package/bin/tsx.js
CHANGED
|
@@ -4,16 +4,16 @@ import { spawn } from "node:child_process";
|
|
|
4
4
|
|
|
5
5
|
import { getBinaryFilepath } from "./utils.js";
|
|
6
6
|
|
|
7
|
-
console.log(getBinaryFilepath("tsx", "../../dist/cli.mjs"));
|
|
8
|
-
|
|
9
7
|
const args = process.argv.slice(2);
|
|
10
8
|
|
|
11
9
|
const child = spawn("node", [getBinaryFilepath("tsx", "../../dist/cli.mjs"), ...args], {
|
|
12
10
|
stdio: "inherit",
|
|
13
11
|
});
|
|
14
12
|
|
|
15
|
-
child.on("exit", (code) => {
|
|
16
|
-
if (
|
|
13
|
+
child.on("exit", (code, signal) => {
|
|
14
|
+
if (signal) {
|
|
15
|
+
process.kill(process.pid, signal);
|
|
16
|
+
} else if (code !== 0) {
|
|
17
17
|
process.exit(code);
|
|
18
18
|
}
|
|
19
19
|
});
|