@elliots/typical 0.1.8 → 0.1.10
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 +253 -7
- package/dist/src/cli.js +33 -6
- package/dist/src/cli.js.map +1 -1
- package/dist/src/config.d.ts +56 -0
- package/dist/src/config.js +93 -1
- package/dist/src/config.js.map +1 -1
- package/dist/src/esm-loader.d.ts +1 -0
- package/dist/src/esm-loader.js +13 -3
- package/dist/src/esm-loader.js.map +1 -1
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/source-map.d.ts +78 -0
- package/dist/src/source-map.js +133 -0
- package/dist/src/source-map.js.map +1 -0
- package/dist/src/transformer.d.ts +71 -4
- package/dist/src/transformer.js +773 -330
- package/dist/src/transformer.js.map +1 -1
- package/dist/src/tsc-plugin.js +2 -2
- package/dist/src/tsc-plugin.js.map +1 -1
- package/package.json +8 -2
- package/src/cli.ts +44 -10
- package/src/config.ts +145 -3
- package/src/esm-loader.ts +15 -3
- package/src/index.ts +10 -2
- package/src/source-map.ts +202 -0
- package/src/transformer.ts +1047 -419
- package/src/tsc-plugin.ts +2 -2
package/README.md
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Typical adds runtime validation to typescript, making TypeScript type-safe at runtime *with no changes to your code*.
|
|
4
4
|
|
|
5
|
-
It can be used as a TSC plugin,
|
|
6
|
-
|
|
7
|
-
(Could add unplugin/vite plugin, bun plugin etc. if needed.)
|
|
5
|
+
It can be used as a TSC plugin, ESM loader for Node.js, or with bundlers like Vite, Webpack, and Rollup via unplugin.
|
|
8
6
|
|
|
9
7
|
## Why?
|
|
10
8
|
|
|
@@ -25,6 +23,7 @@ Why not.
|
|
|
25
23
|
- ✅ TSC plugin
|
|
26
24
|
- ✅ ESM loader for runtime transformation with `node --import @elliots/typical/esm` (or `node --loader @elliots/typical/esm-loader` for older Node versions)
|
|
27
25
|
- ✅ tsx wrapper (ttsx) for easy use like `npx ttsx script.ts`
|
|
26
|
+
- ✅ Unplugin for Vite, Webpack, Rollup, esbuild, and more
|
|
28
27
|
|
|
29
28
|
## Installation
|
|
30
29
|
|
|
@@ -36,16 +35,58 @@ npm add typical
|
|
|
36
35
|
|
|
37
36
|
Optional: Create a `typical.json` file in your project root.
|
|
38
37
|
|
|
39
|
-
If not provided, these default settings will be used
|
|
38
|
+
If not provided, these default settings will be used (optimized for development):
|
|
40
39
|
|
|
41
40
|
```json
|
|
42
41
|
{
|
|
43
|
-
"include": ["
|
|
44
|
-
"exclude": ["node_modules/**", "**/*.d.ts", "dist/**"],
|
|
45
|
-
"
|
|
42
|
+
"include": ["**/*.ts", "**/*.tsx"],
|
|
43
|
+
"exclude": ["node_modules/**", "**/*.d.ts", "dist/**", "build/**"],
|
|
44
|
+
"reusableValidators": false,
|
|
45
|
+
"validateFunctions": true,
|
|
46
|
+
"validateCasts": false,
|
|
47
|
+
"hoistRegex": true,
|
|
48
|
+
"ignoreDOMTypes": true,
|
|
49
|
+
"ignoreTypes": [],
|
|
50
|
+
"sourceMap": {
|
|
51
|
+
"enabled": true,
|
|
52
|
+
"includeContent": true,
|
|
53
|
+
"inline": false
|
|
54
|
+
}
|
|
46
55
|
}
|
|
47
56
|
```
|
|
48
57
|
|
|
58
|
+
### Configuration Options
|
|
59
|
+
|
|
60
|
+
| Option | Default | Description |
|
|
61
|
+
|--------|---------|-------------|
|
|
62
|
+
| `include` | `["**/*.ts", "**/*.tsx"]` | Glob patterns for files to transform |
|
|
63
|
+
| `exclude` | `["node_modules/**", "**/*.d.ts", "dist/**", "build/**"]` | Glob patterns for files to skip |
|
|
64
|
+
| `reusableValidators` | `false` | Create shared validators for identical types (smaller output). Incompatible with source maps. |
|
|
65
|
+
| `validateFunctions` | `true` | Validate function parameters and return types at runtime |
|
|
66
|
+
| `validateCasts` | `false` | Validate type assertions (`as Type`) at runtime |
|
|
67
|
+
| `hoistRegex` | `true` | Hoist regex patterns to top-level constants (improves performance) |
|
|
68
|
+
| `ignoreDOMTypes` | `true` | Skip validation for DOM types (Document, Element, etc.) |
|
|
69
|
+
| `ignoreTypes` | `[]` | Type patterns to skip validation for (supports wildcards, e.g., `["React.*"]`) |
|
|
70
|
+
| `sourceMap.enabled` | `true` | Generate source maps for transformed code |
|
|
71
|
+
| `sourceMap.includeContent` | `true` | Include original source content in source maps |
|
|
72
|
+
| `sourceMap.inline` | `false` | Use inline source maps (data URL) instead of external files |
|
|
73
|
+
| `debug.writeIntermediateFiles` | `false` | Write `.typical.ts` files showing code before typia transform |
|
|
74
|
+
|
|
75
|
+
### Production Configuration
|
|
76
|
+
|
|
77
|
+
For production builds, disable source maps and enable reusable validators for smaller output:
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"reusableValidators": true,
|
|
82
|
+
"sourceMap": {
|
|
83
|
+
"enabled": false
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Note: `reusableValidators` and `sourceMap.enabled` are mutually exclusive. Source maps require inline validators so each validation call can map back to its original type annotation. If both are enabled, `reusableValidators` will be automatically disabled with a warning.
|
|
89
|
+
|
|
49
90
|
## Usage
|
|
50
91
|
|
|
51
92
|
See ./samples/esm and ./samples/tsc and ./samples/ttsx
|
|
@@ -64,6 +105,78 @@ npm add -g @elliots/typical
|
|
|
64
105
|
ttsx your-script.ts
|
|
65
106
|
```
|
|
66
107
|
|
|
108
|
+
## Vite / Webpack / Rollup (unplugin)
|
|
109
|
+
|
|
110
|
+
Install the unplugin:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
npm add @elliots/unplugin-typical
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Vite
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
// vite.config.ts
|
|
120
|
+
import Typical from '@elliots/unplugin-typical/vite'
|
|
121
|
+
|
|
122
|
+
export default defineConfig({
|
|
123
|
+
plugins: [
|
|
124
|
+
Typical(),
|
|
125
|
+
],
|
|
126
|
+
})
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Webpack
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
// webpack.config.js
|
|
133
|
+
const Typical = require('@elliots/unplugin-typical/webpack').default
|
|
134
|
+
|
|
135
|
+
module.exports = {
|
|
136
|
+
plugins: [
|
|
137
|
+
Typical(),
|
|
138
|
+
],
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Rollup
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
// rollup.config.js
|
|
146
|
+
import Typical from '@elliots/unplugin-typical/rollup'
|
|
147
|
+
|
|
148
|
+
export default {
|
|
149
|
+
plugins: [
|
|
150
|
+
Typical(),
|
|
151
|
+
],
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### esbuild
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { build } from 'esbuild'
|
|
159
|
+
import Typical from '@elliots/unplugin-typical/esbuild'
|
|
160
|
+
|
|
161
|
+
build({
|
|
162
|
+
plugins: [Typical()],
|
|
163
|
+
})
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Plugin Configuration
|
|
167
|
+
|
|
168
|
+
Pass options directly to the plugin:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
Typical({
|
|
172
|
+
validateFunctions: true,
|
|
173
|
+
validateCasts: false,
|
|
174
|
+
// ... other options
|
|
175
|
+
})
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Or use a `typical.json` file in your project root (shared with other entry points like TSC plugin and ESM loader).
|
|
179
|
+
|
|
67
180
|
## Example
|
|
68
181
|
|
|
69
182
|
This code will run without errors when compiled normally, but will throw an error when using Typical.
|
|
@@ -85,6 +198,139 @@ But basically you shouldn't need to care about how it works internally, it makes
|
|
|
85
198
|
|
|
86
199
|
* sort of. probably. something like it anyway.
|
|
87
200
|
|
|
201
|
+
## Flow Analysis
|
|
202
|
+
|
|
203
|
+
Typical includes smart flow analysis to avoid redundant validations. When you return a value that was already validated (either as a parameter or via a type-annotated const), the return statement won't be wrapped in another validation call.
|
|
204
|
+
|
|
205
|
+
### When return validation is skipped:
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
interface User { name: string; }
|
|
209
|
+
|
|
210
|
+
// Direct parameter return - no redundant validation
|
|
211
|
+
function validate(user: User): User {
|
|
212
|
+
return user; // Already validated on entry, skip return validation
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Property access from validated parameter
|
|
216
|
+
function getAddress(user: User): Address {
|
|
217
|
+
return user.address; // user was validated, address is safe
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Type-annotated const
|
|
221
|
+
function getUser(): User {
|
|
222
|
+
const user: User = fetchData(); // const is validated here
|
|
223
|
+
return user; // skip redundant validation
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### When return validation IS applied (tainting):
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
// After mutation
|
|
231
|
+
function updateUser(user: User): User {
|
|
232
|
+
user.name = "modified"; // Mutation taints the value
|
|
233
|
+
return user; // Must re-validate
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// After passing to another function
|
|
237
|
+
function processUser(user: User): User {
|
|
238
|
+
someFunction(user); // Could have mutated user
|
|
239
|
+
return user; // Must re-validate
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// After await (async boundary)
|
|
243
|
+
async function asyncProcess(user: User): Promise<User> {
|
|
244
|
+
await delay(); // Async boundary taints values
|
|
245
|
+
return user; // Must re-validate
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Spread into new object
|
|
249
|
+
function cloneUser(user: User): User {
|
|
250
|
+
return { ...user }; // New object, must validate
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Debugging
|
|
255
|
+
|
|
256
|
+
### Intermediate Files
|
|
257
|
+
|
|
258
|
+
To see what code Typical generates before typia processes it, enable intermediate file output:
|
|
259
|
+
|
|
260
|
+
```json
|
|
261
|
+
{
|
|
262
|
+
"debug": {
|
|
263
|
+
"writeIntermediateFiles": true
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
This creates `.typical.ts` files alongside your output showing the code with typia calls injected but not yet transformed.
|
|
269
|
+
|
|
270
|
+
### Verbose Logging
|
|
271
|
+
|
|
272
|
+
Set `DEBUG=1` environment variable for detailed logging:
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
DEBUG=1 npm run build
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Troubleshooting
|
|
279
|
+
|
|
280
|
+
### "Failed to transform the following types"
|
|
281
|
+
|
|
282
|
+
This error means typia couldn't generate validation code for certain types. Common causes:
|
|
283
|
+
|
|
284
|
+
1. **DOM types**: Types like `HTMLElement`, `Document`, etc. have complex intersections typia can't process.
|
|
285
|
+
- Solution: Enable `ignoreDOMTypes: true` (default) or add specific types to `ignoreTypes`
|
|
286
|
+
|
|
287
|
+
2. **React types**: Event handlers, refs, and other React types often can't be validated.
|
|
288
|
+
- Solution: Add `"React.*"` to `ignoreTypes`
|
|
289
|
+
|
|
290
|
+
3. **Third-party library types**: Some library types are too complex.
|
|
291
|
+
- Solution: Add the specific type patterns to `ignoreTypes`
|
|
292
|
+
|
|
293
|
+
```json
|
|
294
|
+
{
|
|
295
|
+
"ignoreTypes": ["React.*", "Express.Request", "Prisma.*"]
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### "Window & typeof globalThis" errors
|
|
300
|
+
|
|
301
|
+
This occurs when a type includes DOM globals. Enable `ignoreDOMTypes: true` or add the specific type to `ignoreTypes`.
|
|
302
|
+
|
|
303
|
+
### Generic type parameters not validated
|
|
304
|
+
|
|
305
|
+
Type parameters (`T`, `U`, etc.) cannot be validated at runtime because the actual type isn't known until the function is called. This is by design:
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
function identity<T>(value: T): T {
|
|
309
|
+
return value; // T is not validated - no runtime type info
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Concrete types in the same function ARE validated:
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
function process<T>(value: T, user: User): User {
|
|
317
|
+
return user; // User IS validated
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### Constructor parameters not validated
|
|
322
|
+
|
|
323
|
+
Currently, class constructors are not transformed. This is a known limitation. Validate in the constructor body if needed:
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
class Client {
|
|
327
|
+
constructor(options: Options) {
|
|
328
|
+
// Manual validation if needed
|
|
329
|
+
if (!options.timeout) throw new Error("timeout required");
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
88
334
|
## Credits
|
|
89
335
|
The actual validation work is done by [typia](https://github.com/samchon/typia). This package just generates the necessary code to call typia's functions based on your TypeScript types.
|
|
90
336
|
|
package/dist/src/cli.js
CHANGED
|
@@ -3,7 +3,8 @@ import { Command } from 'commander';
|
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import * as path from 'path';
|
|
5
5
|
import { TypicalTransformer } from './transformer.js';
|
|
6
|
-
import { loadConfig } from './config.js';
|
|
6
|
+
import { loadConfig, validateConfig } from './config.js';
|
|
7
|
+
import { inlineSourceMapComment, externalSourceMapComment } from './source-map.js';
|
|
7
8
|
const program = new Command();
|
|
8
9
|
program
|
|
9
10
|
.name('typical')
|
|
@@ -16,19 +17,45 @@ program
|
|
|
16
17
|
.option('-o, --output <file>', 'Output file')
|
|
17
18
|
.option('-c, --config <file>', 'Config file path', 'typical.json')
|
|
18
19
|
.option('-m, --mode <mode>', 'Transformation mode: basic, typia, js', 'basic')
|
|
20
|
+
.option('--source-map', 'Generate external source map file')
|
|
21
|
+
.option('--inline-source-map', 'Include inline source map in output')
|
|
22
|
+
.option('--no-source-map', 'Disable source map generation')
|
|
19
23
|
.action(async (file, options) => {
|
|
20
24
|
try {
|
|
21
|
-
const config = loadConfig(options.config);
|
|
25
|
+
const config = validateConfig(loadConfig(options.config));
|
|
22
26
|
const transformer = new TypicalTransformer(config);
|
|
23
27
|
if (!fs.existsSync(file)) {
|
|
24
28
|
console.error(`File not found: ${file}`);
|
|
25
29
|
process.exit(1);
|
|
26
30
|
}
|
|
31
|
+
// Determine source map behavior
|
|
32
|
+
const generateSourceMap = options.inlineSourceMap || options.sourceMap !== false;
|
|
27
33
|
console.log(`Transforming ${file}...`);
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
const result = transformer.transform(path.resolve(file), options.mode ?? 'basic', {
|
|
35
|
+
sourceMap: generateSourceMap,
|
|
36
|
+
});
|
|
37
|
+
// Determine output file path
|
|
38
|
+
const outputFile = options.output
|
|
39
|
+
? path.resolve(options.output)
|
|
40
|
+
: options.mode === 'js'
|
|
41
|
+
? file.replace(/\.tsx?$/, '.js')
|
|
42
|
+
: file + '.transformed.ts';
|
|
43
|
+
let outputCode = result.code;
|
|
44
|
+
// Handle source maps
|
|
45
|
+
if (result.map) {
|
|
46
|
+
if (options.inlineSourceMap) {
|
|
47
|
+
// Inline source map as data URL
|
|
48
|
+
outputCode += '\n' + inlineSourceMapComment(result.map);
|
|
49
|
+
}
|
|
50
|
+
else if (options.sourceMap !== false) {
|
|
51
|
+
// Write external source map file
|
|
52
|
+
const mapFile = outputFile + '.map';
|
|
53
|
+
fs.writeFileSync(mapFile, JSON.stringify(result.map, null, 2));
|
|
54
|
+
outputCode += '\n' + externalSourceMapComment(path.basename(mapFile));
|
|
55
|
+
console.log(`Source map written to ${mapFile}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
fs.writeFileSync(outputFile, outputCode);
|
|
32
59
|
console.log(`Transformed code written to ${outputFile}`);
|
|
33
60
|
}
|
|
34
61
|
catch (error) {
|
package/dist/src/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAEnF,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,SAAS,CAAC;KACf,WAAW,CAAC,iDAAiD,CAAC;KAC9D,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,WAAW,CAAC;KACpB,WAAW,CAAC,qDAAqD,CAAC;KAClE,QAAQ,CAAC,QAAQ,EAAE,8BAA8B,CAAC;KAClD,MAAM,CAAC,qBAAqB,EAAE,aAAa,CAAC;KAC5C,MAAM,CAAC,qBAAqB,EAAE,kBAAkB,EAAE,cAAc,CAAC;KACjE,MAAM,CAAC,mBAAmB,EAAE,wC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4BAA4B;AAC5B,cAAc;AACd,kCAAkC;AAClC,UAAU;AAEV,iEAAiE;AAEjE,8BAA8B;AAC9B,0EAA0E;AAC1E,kBAAkB;AAClB,UAAU;AAEV,6BAA6B;AAE7B,oCAAoC;AACpC,0DAA0D;AAC1D,kDAAkD;AAClD,mEAAmE;AACnE,sBAAsB;AACtB,YAAY;AAEZ,gBAAgB;AAChB,oDAAoD;AACpD,yEAAyE;AACzE,qDAAqD;AACrD,2BAA2B;AAC3B,4BAA4B;AAC5B,kEAAkE;AAClE,YAAY;AACZ,UAAU;AAEV,sFAAsF;AACtF,wBAAwB;AACxB,+CAA+C;AAC/C,yBAAyB;AACzB,QAAQ;AACR,QAAQ;AAER,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
package/dist/src/config.d.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
export interface TypicalDebugConfig {
|
|
2
2
|
writeIntermediateFiles?: boolean;
|
|
3
3
|
}
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for source map generation.
|
|
6
|
+
*/
|
|
7
|
+
export interface TypicalSourceMapConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Generate source maps. Default: true
|
|
10
|
+
*/
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Include original source content in the map. Default: true
|
|
14
|
+
*/
|
|
15
|
+
includeContent?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Use inline source maps (data URL) instead of external files. Default: false
|
|
18
|
+
*/
|
|
19
|
+
inline?: boolean;
|
|
20
|
+
}
|
|
4
21
|
export interface TypicalConfig {
|
|
5
22
|
include?: string[];
|
|
6
23
|
exclude?: string[];
|
|
@@ -26,6 +43,23 @@ export interface TypicalConfig {
|
|
|
26
43
|
* Default: true
|
|
27
44
|
*/
|
|
28
45
|
validateFunctions?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Source map generation settings.
|
|
48
|
+
* Controls whether and how source maps are generated for transformed code.
|
|
49
|
+
*/
|
|
50
|
+
sourceMap?: TypicalSourceMapConfig;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Pre-compiled regex patterns for ignore type matching.
|
|
54
|
+
* This is populated during config loading for performance.
|
|
55
|
+
*/
|
|
56
|
+
export interface CompiledIgnorePatterns {
|
|
57
|
+
/** Compiled patterns from user ignoreTypes config */
|
|
58
|
+
userPatterns: RegExp[];
|
|
59
|
+
/** Compiled patterns from DOM_TYPES_TO_IGNORE (when ignoreDOMTypes is true) */
|
|
60
|
+
domPatterns: RegExp[];
|
|
61
|
+
/** All patterns combined for quick checking */
|
|
62
|
+
allPatterns: RegExp[];
|
|
29
63
|
}
|
|
30
64
|
export declare const defaultConfig: TypicalConfig;
|
|
31
65
|
/**
|
|
@@ -33,4 +67,26 @@ export declare const defaultConfig: TypicalConfig;
|
|
|
33
67
|
* These are the base DOM types - classes extending them are checked separately.
|
|
34
68
|
*/
|
|
35
69
|
export declare const DOM_TYPES_TO_IGNORE: string[];
|
|
70
|
+
/**
|
|
71
|
+
* Convert a glob pattern to a RegExp for type matching.
|
|
72
|
+
* Supports wildcards: "React.*" -> /^React\..*$/
|
|
73
|
+
*/
|
|
74
|
+
export declare function compileIgnorePattern(pattern: string): RegExp | null;
|
|
75
|
+
/**
|
|
76
|
+
* Pre-compile all ignore patterns for efficient matching.
|
|
77
|
+
*/
|
|
78
|
+
export declare function compileIgnorePatterns(config: TypicalConfig): CompiledIgnorePatterns;
|
|
79
|
+
/**
|
|
80
|
+
* Get compiled ignore patterns, using cache if config hasn't changed.
|
|
81
|
+
*/
|
|
82
|
+
export declare function getCompiledIgnorePatterns(config: TypicalConfig): CompiledIgnorePatterns;
|
|
36
83
|
export declare function loadConfig(configPath?: string): TypicalConfig;
|
|
84
|
+
/**
|
|
85
|
+
* Validate and adjust config for consistency.
|
|
86
|
+
* Currently handles:
|
|
87
|
+
* - Disabling reusableValidators when source maps are enabled (required for accurate mappings)
|
|
88
|
+
*
|
|
89
|
+
* @param config The config to validate
|
|
90
|
+
* @returns Validated/adjusted config
|
|
91
|
+
*/
|
|
92
|
+
export declare function validateConfig(config: TypicalConfig): TypicalConfig;
|
package/dist/src/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const defaultConfig = {
|
|
2
2
|
include: ["**/*.ts", "**/*.tsx"],
|
|
3
3
|
exclude: ["node_modules/**", "**/*.d.ts", "dist/**", "build/**"],
|
|
4
|
-
reusableValidators: true
|
|
4
|
+
reusableValidators: false, // Off by default for accurate source maps (set to true for production)
|
|
5
5
|
validateCasts: false,
|
|
6
6
|
validateFunctions: true,
|
|
7
7
|
hoistRegex: true,
|
|
@@ -9,6 +9,11 @@ export const defaultConfig = {
|
|
|
9
9
|
debug: {
|
|
10
10
|
writeIntermediateFiles: false,
|
|
11
11
|
},
|
|
12
|
+
sourceMap: {
|
|
13
|
+
enabled: true, // On by default for debugging (set to false for production)
|
|
14
|
+
includeContent: true,
|
|
15
|
+
inline: false,
|
|
16
|
+
},
|
|
12
17
|
};
|
|
13
18
|
// FIXME: find a better way to work out which types to ignore
|
|
14
19
|
/**
|
|
@@ -53,6 +58,65 @@ export const DOM_TYPES_TO_IGNORE = [
|
|
|
53
58
|
];
|
|
54
59
|
import fs from 'fs';
|
|
55
60
|
import path from 'path';
|
|
61
|
+
/**
|
|
62
|
+
* Convert a glob pattern to a RegExp for type matching.
|
|
63
|
+
* Supports wildcards: "React.*" -> /^React\..*$/
|
|
64
|
+
*/
|
|
65
|
+
export function compileIgnorePattern(pattern) {
|
|
66
|
+
try {
|
|
67
|
+
const regexStr = '^' + pattern
|
|
68
|
+
.replace(/[.+^${}()|[\]\\]/g, '\\$&') // Escape special regex chars except *
|
|
69
|
+
.replace(/\*/g, '.*') + '$';
|
|
70
|
+
return new RegExp(regexStr);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.warn(`TYPICAL: Invalid ignoreTypes pattern "${pattern}": ${error}`);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Pre-compile all ignore patterns for efficient matching.
|
|
79
|
+
*/
|
|
80
|
+
export function compileIgnorePatterns(config) {
|
|
81
|
+
const userPatterns = [];
|
|
82
|
+
const domPatterns = [];
|
|
83
|
+
// Compile user patterns
|
|
84
|
+
for (const pattern of config.ignoreTypes ?? []) {
|
|
85
|
+
const compiled = compileIgnorePattern(pattern);
|
|
86
|
+
if (compiled) {
|
|
87
|
+
userPatterns.push(compiled);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Compile DOM patterns if enabled (default: true)
|
|
91
|
+
if (config.ignoreDOMTypes !== false) {
|
|
92
|
+
for (const pattern of DOM_TYPES_TO_IGNORE) {
|
|
93
|
+
const compiled = compileIgnorePattern(pattern);
|
|
94
|
+
if (compiled) {
|
|
95
|
+
domPatterns.push(compiled);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
userPatterns,
|
|
101
|
+
domPatterns,
|
|
102
|
+
allPatterns: [...userPatterns, ...domPatterns],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// Cache for compiled patterns, keyed by config identity
|
|
106
|
+
let cachedPatterns = null;
|
|
107
|
+
let cachedConfig = null;
|
|
108
|
+
/**
|
|
109
|
+
* Get compiled ignore patterns, using cache if config hasn't changed.
|
|
110
|
+
*/
|
|
111
|
+
export function getCompiledIgnorePatterns(config) {
|
|
112
|
+
// Simple identity check - if same config object, use cache
|
|
113
|
+
if (cachedConfig === config && cachedPatterns) {
|
|
114
|
+
return cachedPatterns;
|
|
115
|
+
}
|
|
116
|
+
cachedConfig = config;
|
|
117
|
+
cachedPatterns = compileIgnorePatterns(config);
|
|
118
|
+
return cachedPatterns;
|
|
119
|
+
}
|
|
56
120
|
export function loadConfig(configPath) {
|
|
57
121
|
const configFile = configPath || path.join(process.cwd(), 'typical.json');
|
|
58
122
|
if (fs.existsSync(configFile)) {
|
|
@@ -71,4 +135,32 @@ export function loadConfig(configPath) {
|
|
|
71
135
|
}
|
|
72
136
|
return defaultConfig;
|
|
73
137
|
}
|
|
138
|
+
let warnedAboutSourceMaps = false;
|
|
139
|
+
/**
|
|
140
|
+
* Validate and adjust config for consistency.
|
|
141
|
+
* Currently handles:
|
|
142
|
+
* - Disabling reusableValidators when source maps are enabled (required for accurate mappings)
|
|
143
|
+
*
|
|
144
|
+
* @param config The config to validate
|
|
145
|
+
* @returns Validated/adjusted config
|
|
146
|
+
*/
|
|
147
|
+
export function validateConfig(config) {
|
|
148
|
+
let result = config;
|
|
149
|
+
// Source maps require inline validators (not reusable) because each validation
|
|
150
|
+
// call needs its own source map marker pointing to the correct type annotation.
|
|
151
|
+
// With reusable validators, the expanded typia code would all map to the validator
|
|
152
|
+
// declaration rather than the individual usage sites.
|
|
153
|
+
const sourceMapEnabled = config.sourceMap?.enabled !== false;
|
|
154
|
+
const reusableValidatorsEnabled = config.reusableValidators === true;
|
|
155
|
+
if (sourceMapEnabled && reusableValidatorsEnabled) {
|
|
156
|
+
if (!warnedAboutSourceMaps) {
|
|
157
|
+
warnedAboutSourceMaps = true;
|
|
158
|
+
console.warn("TYPICAL: Both sourceMap and reusableValidators are enabled. " +
|
|
159
|
+
"Disabling reusableValidators for accurate source mapping. " +
|
|
160
|
+
"For production builds, set sourceMap.enabled: false to use reusableValidators.");
|
|
161
|
+
}
|
|
162
|
+
result = { ...result, reusableValidators: false };
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
74
166
|
//# sourceMappingURL=config.js.map
|
package/dist/src/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAmEA,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,OAAO,EAAE,C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BAC5D,gFAAgF,CACjF,CAAC;QACJ,CAAC;QACD,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC;IACpD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/src/esm-loader.d.ts
CHANGED
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
export declare function resolve(specifier: string, context: any, nextResolve: any): Promise<any>;
|
|
5
5
|
/**
|
|
6
6
|
* Load hook - transforms TypeScript files on the fly
|
|
7
|
+
* Includes inline source maps for proper error stack traces in Node.js
|
|
7
8
|
*/
|
|
8
9
|
export declare function load(url: string, context: any, nextLoad: any): Promise<any>;
|
package/dist/src/esm-loader.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
2
2
|
import { existsSync } from "fs";
|
|
3
3
|
import { TypicalTransformer } from "./transformer.js";
|
|
4
|
-
|
|
4
|
+
import { inlineSourceMapComment } from "./source-map.js";
|
|
5
|
+
import { loadConfig, validateConfig } from "./config.js";
|
|
6
|
+
const config = validateConfig(loadConfig());
|
|
7
|
+
const transformer = new TypicalTransformer(config);
|
|
5
8
|
/**
|
|
6
9
|
* Resolve hook - rewrites .js imports to .ts if the .ts file exists
|
|
7
10
|
*/
|
|
@@ -25,6 +28,7 @@ export async function resolve(specifier, context, nextResolve) {
|
|
|
25
28
|
}
|
|
26
29
|
/**
|
|
27
30
|
* Load hook - transforms TypeScript files on the fly
|
|
31
|
+
* Includes inline source maps for proper error stack traces in Node.js
|
|
28
32
|
*/
|
|
29
33
|
export async function load(url, context, nextLoad) {
|
|
30
34
|
if (!url.endsWith(".ts")) {
|
|
@@ -32,10 +36,16 @@ export async function load(url, context, nextLoad) {
|
|
|
32
36
|
}
|
|
33
37
|
const filePath = fileURLToPath(url);
|
|
34
38
|
try {
|
|
35
|
-
|
|
39
|
+
// Transform with source map support enabled
|
|
40
|
+
const result = transformer.transform(filePath, 'js', { sourceMap: true });
|
|
41
|
+
// Append inline source map for Node.js source map support
|
|
42
|
+
let source = result.code;
|
|
43
|
+
if (result.map) {
|
|
44
|
+
source += '\n' + inlineSourceMapComment(result.map);
|
|
45
|
+
}
|
|
36
46
|
return {
|
|
37
47
|
format: "module",
|
|
38
|
-
source
|
|
48
|
+
source,
|
|
39
49
|
shortCircuit: true,
|
|
40
50
|
};
|
|
41
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esm-loader.js","sourceRoot":"","sources":["../../src/esm-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"esm-loader.js","sourceRoot":"","sources":["../../src/esm-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAEzD,MAAM,MAAM,GAAG,cAAc,CAAC,UAAU,EAAE,CAAC,CAAC;AAC5C,MAAM,WAAW,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,SAAiB,EAAE,OAAY,EAAE,WAAgB;IAC7E,6CAA6C;IAC7C,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3D,MAAM,EAAE,S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M,EAAE,QAAQ;YAChB,MAAM;YACN,YAAY,EAAE,IAAI;SACnB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,sBAAsB,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;QACxD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export { TypicalTransformer } from './transformer.js';
|
|
2
|
-
export { loadConfig, defaultConfig, TypicalConfig } from './config.js';
|
|
1
|
+
export { TypicalTransformer, TransformResult } from './transformer.js';
|
|
2
|
+
export { loadConfig, validateConfig, defaultConfig, TypicalConfig, TypicalSourceMapConfig } from './config.js';
|
|
3
|
+
export { composeSourceMaps, inlineSourceMapComment, externalSourceMapComment, createIdentityMap, stripSourceMapComment, } from './source-map.js';
|
|
4
|
+
export type { SourceMapOptions } from './source-map.js';
|
package/dist/src/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { TypicalTransformer } from './transformer.js';
|
|
2
|
-
export { loadConfig, defaultConfig } from './config.js';
|
|
2
|
+
export { loadConfig, validateConfig, defaultConfig } from './config.js';
|
|
3
|
+
export { composeSourceMaps, inlineSourceMapComment, externalSourceMapComment, createIdentityMap, stripSourceMapComment, } from './source-map.js';
|
|
3
4
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAmB,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAyC,MAAM,aAAa,CAAC;AAC/G,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,EACxB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC"}
|