ttsc 0.3.1 → 0.4.0-dev.20260424

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.
Files changed (112) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +216 -302
  3. package/cmd/ttsc/build.go +128 -0
  4. package/cmd/ttsc/main.go +222 -0
  5. package/cmd/ttsc/main_test.go +288 -0
  6. package/cmd/ttsc/transform.go +166 -0
  7. package/driver/host.go +31 -0
  8. package/driver/program.go +298 -0
  9. package/driver/rewrite.go +315 -0
  10. package/go.mod +48 -0
  11. package/go.sum +22 -0
  12. package/lib/api.d.ts +91 -0
  13. package/lib/api.js +325 -0
  14. package/lib/api.js.map +1 -0
  15. package/lib/cli.d.ts +1 -0
  16. package/lib/cli.js +481 -0
  17. package/lib/cli.js.map +1 -0
  18. package/lib/index.d.ts +17 -0
  19. package/lib/index.js +34 -0
  20. package/lib/index.js.map +1 -0
  21. package/lib/native.d.ts +15 -0
  22. package/lib/native.js +34 -0
  23. package/lib/native.js.map +1 -0
  24. package/lib/platform.d.ts +66 -0
  25. package/lib/platform.js +170 -0
  26. package/lib/platform.js.map +1 -0
  27. package/lib/plugin.d.ts +47 -0
  28. package/lib/plugin.js +150 -0
  29. package/lib/plugin.js.map +1 -0
  30. package/lib/project.d.ts +32 -0
  31. package/lib/project.js +303 -0
  32. package/lib/project.js.map +1 -0
  33. package/package.json +70 -63
  34. package/shim/ast/extra-shim.json +4 -0
  35. package/shim/ast/go.mod +5 -0
  36. package/shim/ast/shim.go +117 -0
  37. package/shim/bundled/extra-shim.json +1 -0
  38. package/shim/bundled/go.mod +5 -0
  39. package/shim/bundled/shim.go +19 -0
  40. package/shim/checker/extra-shim.json +31 -0
  41. package/shim/checker/go.mod +5 -0
  42. package/shim/checker/shim.go +146 -0
  43. package/shim/compiler/extra-shim.json +4 -0
  44. package/shim/compiler/go.mod +5 -0
  45. package/shim/compiler/shim.go +50 -0
  46. package/shim/core/extra-shim.json +4 -0
  47. package/shim/core/go.mod +5 -0
  48. package/shim/core/shim.go +11 -0
  49. package/shim/diagnosticwriter/go.mod +5 -0
  50. package/shim/diagnosticwriter/shim.go +29 -0
  51. package/shim/parser/extra-shim.json +4 -0
  52. package/shim/parser/go.mod +5 -0
  53. package/shim/parser/shim.go +55 -0
  54. package/shim/scanner/extra-shim.json +4 -0
  55. package/shim/scanner/go.mod +5 -0
  56. package/shim/scanner/shim.go +96 -0
  57. package/shim/tsoptions/extra-shim.json +4 -0
  58. package/shim/tsoptions/go.mod +5 -0
  59. package/shim/tsoptions/shim.go +123 -0
  60. package/shim/tspath/extra-shim.json +4 -0
  61. package/shim/tspath/go.mod +5 -0
  62. package/shim/tspath/shim.go +165 -0
  63. package/shim/vfs/cachedvfs/extra-shim.json +4 -0
  64. package/shim/vfs/cachedvfs/go.mod +5 -0
  65. package/shim/vfs/cachedvfs/shim.go +12 -0
  66. package/shim/vfs/extra-shim.json +4 -0
  67. package/shim/vfs/go.mod +5 -0
  68. package/shim/vfs/osvfs/extra-shim.json +4 -0
  69. package/shim/vfs/osvfs/go.mod +5 -0
  70. package/shim/vfs/osvfs/shim.go +13 -0
  71. package/shim/vfs/shim.go +19 -0
  72. package/src/api.ts +416 -0
  73. package/src/cli.ts +492 -0
  74. package/src/index.ts +18 -0
  75. package/src/launcher/ttsc-dev.js +42 -0
  76. package/src/launcher/ttsc.js +19 -0
  77. package/src/native.ts +60 -0
  78. package/src/platform.ts +163 -0
  79. package/src/plugin.ts +241 -0
  80. package/src/project.ts +330 -0
  81. package/test/native.test.ts +60 -0
  82. package/test/package.test.ts +123 -0
  83. package/test/platform.test.ts +58 -0
  84. package/test/project.test.ts +195 -0
  85. package/tools/gen_shims/go.mod +14 -0
  86. package/tools/gen_shims/go.sum +12 -0
  87. package/tools/gen_shims/main.go +446 -0
  88. package/CHANGELOG.md +0 -2
  89. package/bin/tsc +0 -2
  90. package/bin/tsserver +0 -2
  91. package/lib/PluginCreator.d.ts +0 -67
  92. package/lib/PluginCreator.js +0 -190
  93. package/lib/cancelationToken.d.ts +0 -0
  94. package/lib/cancelationToken.js +0 -2
  95. package/lib/loadTypescript.d.ts +0 -7
  96. package/lib/loadTypescript.js +0 -56
  97. package/lib/patchCreateProgram.d.ts +0 -21
  98. package/lib/patchCreateProgram.js +0 -190
  99. package/lib/tsc.d.ts +0 -1
  100. package/lib/tsc.js +0 -24
  101. package/lib/tsserver.d.ts +0 -0
  102. package/lib/tsserver.js +0 -2
  103. package/lib/tsserverlibrary.d.ts +0 -3
  104. package/lib/tsserverlibrary.js +0 -4
  105. package/lib/typescript.d.ts +0 -3
  106. package/lib/typescript.js +0 -4
  107. package/lib/typescriptServices.d.ts +0 -3
  108. package/lib/typescriptServices.js +0 -4
  109. package/lib/typingsInstaller.d.ts +0 -0
  110. package/lib/typingsInstaller.js +0 -2
  111. package/lib/watchGuard.d.ts +0 -0
  112. package/lib/watchGuard.js +0 -2
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 sunrabbit123
3
+ Copyright (c) 2026 Jeongho Nam
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,396 +1,310 @@
1
- # ttsc
1
+ # `ttsc`
2
2
 
3
- [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/solar-religion/ttsc/blob/main/LICENSE)
4
- [![npm version](https://img.shields.io/npm/v/ttsc.svg)](https://www.npmjs.com/package/ttsc)
5
- [![Downloads](https://img.shields.io/npm/dm/ttsc.svg)](https://www.npmjs.com/package/ttsc)
3
+ ![banner of ttsc and ttsx](https://private-user-images.githubusercontent.com/13158709/583518390-6df1deb5-9e8c-4f4b-9d0f-eae1cc3bb55c.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzcwNTQ2NzUsIm5iZiI6MTc3NzA1NDM3NSwicGF0aCI6Ii8xMzE1ODcwOS81ODM1MTgzOTAtNmRmMWRlYjUtOWU4Yy00ZjRiLTlkMGYtZWFlMWNjM2JiNTVjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDI0VDE4MTI1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEzMzUxNTE4YThlZDYyNDZjYTVjYmRiMmZiYzAwYzYyZTkyNDk4MjVlYmI4OGZkYjE3NDllNWQzY2IxNmRhYWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.7MYb2S99lZfQV-BqD09ZrZwdj1C3XDyJ9nkaSEr901M)
6
4
 
7
- This repository was created due to a perceived lack of management of `ttypescript`.
5
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samchon/ttsc/blob/master/LICENSE)
6
+ [![NPM Version](https://img.shields.io/npm/v/ttsc.svg)](https://www.npmjs.com/package/ttsc)
7
+ [![NPM Downloads](https://img.shields.io/npm/dm/ttsc.svg)](https://www.npmjs.com/package/ttsc)
8
+ [![Build Status](https://github.com/samchon/ttsc/workflows/test/badge.svg)](https://github.com/samchon/ttsc/actions?query=workflow%3Atest)
8
9
 
9
- Also, we don't currently support `ts-node` and `cache systems`, as they weren't supported in the original, and we need time to figure out a way around that.
10
+ A `typescript-go` compiler host for build-time transforms.
10
11
 
11
- And it supports TS5.
12
+ - **Build and check**: run the project through the native TypeScript compiler lane.
13
+ - **Transformer support**: load `compilerOptions.plugins` from `tsconfig.json`.
14
+ - **Library author surface**: publish `ttsc` plugins with native backends or JS output hooks.
12
15
 
13
- [![npm version](https://badge.fury.io/js/ttypescript.svg)](https://badge.fury.io/js/ttypescript) [![Build Status](https://travis-ci.org/cevek/ttypescript.svg?branch=master)](https://travis-ci.org/cevek/ttypescript)
16
+ `ttsc` is the compiler host used by `ttsx`. Use `ttsc` when you want one project-aware path for type checking, JavaScript emit, transformer loading, and native backend selection.
14
17
 
15
- # ttypescript
18
+ ## Setup
16
19
 
17
- ## Existing contributors
20
+ Install the native TypeScript preview package with `ttsc`:
18
21
 
19
- - @cevek
20
- - @zerkalica
21
- - @SalvatorePreviti
22
- - @timocov
23
- - @SlurpTheo
24
- - @samchon
25
- - @henriquehbr
26
- - @JiangWeixian
27
- - @mdmitry01
28
- - @jirutka
29
- - @alexgorbatchev
30
- - @oscard0m
31
- - @sveyret
32
- - @Jack-Works
33
- - @MicahZoltu
34
- - @Igorbek
35
- - @gfx
36
- - @danielpza
37
- - @mikeyhew
38
- - @huafu
39
- - @dsherret
40
- - @SupernaviX
41
- - @HitkoDev
42
-
43
- ## What it is
44
-
45
- Currently TypeScript doesn't support custom transformers in the tsconfig.json, but supports it programmatically.
46
-
47
- And there is no way to compile your files using custom transformers using `tsc` command.
48
-
49
- TTypescript (Transformer TypeScript) solves this problem by patching on the fly the compile module to use transformers from `tsconfig.json`.
50
-
51
- <!---
52
- TTypescript is a drop-in replacement for all typescript modules, located in ``` node_modules/typescript/lib ``` directory:
53
-
54
- ```ts
55
- import * as ts from 'ttypescript'
56
- import * as tsServer from 'ttypescript/lib/tsserver'
57
- import * as watchGuard from 'ttypescript/lib/watchGuard'
22
+ ```bash
23
+ npm i -D ttsc @typescript/native-preview
58
24
  ```
59
- --->
60
-
61
- Instead of tsc and tsserver, use ttsc and ttsserver wrappers. This wrappers try to use locally installed typescript first.
62
25
 
63
- No version lock-ins - typescript used as peer dependency.
26
+ Build, check, or watch the project:
64
27
 
65
- ## How to install
66
-
67
- ```
68
- npm i ttypescript -D
28
+ ```bash
29
+ npx ttsc
30
+ npx ttsc --noEmit
31
+ npx ttsc --watch
69
32
  ```
70
33
 
71
- ttypescript uses your installed `typescript` in your `node_modules`
34
+ Transform a single file:
72
35
 
73
- ## How to use
36
+ ```bash
37
+ npx ttsc transform --file src/index.ts
38
+ ```
74
39
 
75
- ### tsconfig.json
40
+ ## Transformer Configuration
76
41
 
77
- Set a transformer path to the `tsconfig.json` in `compilerOptions` section `plugin` array:
42
+ `ttsc` reads `compilerOptions.plugins` from `tsconfig.json`.
78
43
 
79
- ```
44
+ ```json
80
45
  {
81
- "compilerOptions": {
82
- "plugins": [
83
- { "transform": "transformer-module" },
84
- ]
85
- }
86
- }
87
- ```
88
-
89
- plugin entries described in `PluginConfig`:
90
-
91
- ```ts
92
- export interface PluginConfig {
93
- /**
94
- * Path to transformer or transformer module name
95
- */
96
- transform?: string;
97
-
98
- /**
99
- * The optional name of the exported transform plugin in the transform module.
100
- */
101
- import?: string;
102
-
103
- /**
104
- * Plugin entry point format type, default is program
105
- */
106
- type?: 'program' | 'config' | 'checker' | 'raw' | 'compilerOptions';
107
-
108
- /**
109
- * Should transformer applied after all ones
110
- */
111
- after?: boolean;
112
-
113
- /**
114
- * Should transformer applied for d.ts files, supports from TS2.9
115
- */
116
- afterDeclarations?: boolean;
117
- /**
118
- * any other properties provided to the transformer as config argument
119
- * */
120
- [options: string]: any;
46
+ "compilerOptions": {
47
+ "plugins": [
48
+ { "transform": "typia/lib/transform" }
49
+ ]
50
+ }
121
51
  }
122
52
  ```
123
53
 
124
- You just need to add the `transform` block with optional `import`, `type`, `after`, `afterDeclarations` and plugin-related options.
125
-
126
- `transform` can accept npm module or local file path (.ts or .js) related to `tsconfig.json`
54
+ The same configuration is used by `ttsc` and `ttsx`.
127
55
 
128
- ### PluginConfig.type
56
+ ```bash
57
+ # compile
58
+ npx ttsc
129
59
 
130
- Because currently transformers can run only programmatically, most of them use factory wrapper with different signatures.
131
- For the possible to work with any of them you can specify `type` in the plugin config.
132
-
133
- By default will be used a `program` type.
134
-
135
- <!---
136
-
137
- Most of transformers exports ``` ts.TransformerFactory<ts.SourceFile> ```.
138
- But better to export TransformerBasePlugin, described below. In most cases it's a plugin responsibility to when run a transformer.
139
-
140
- ```ts
141
- export interface TransformerBasePlugin {
142
- before?: ts.TransformerFactory<ts.SourceFile>;
143
- after?: ts.TransformerFactory<ts.SourceFile>;
144
- afterDeclarations?: ts.TransformerFactory<ts.SourceFile>;
145
- }
146
-
147
- export type TransformerPlugin = TransformerBasePlugin | ts.TransformerFactory<ts.SourceFile>;
60
+ # execute
61
+ npx ttsx src/index.ts
148
62
  ```
149
- --->
150
63
 
151
- #### program
64
+ This gives compiler-powered libraries one transform path for build-time and runtime execution.
152
65
 
153
- If the transformer has a factory signature using `program` as first argument:
66
+ ## CLI
154
67
 
155
- ```ts
156
- (program: ts.Program, config?: PluginConfig) => ts.TransformerFactory;
157
- where;
158
- ts.TransformerFactory = (context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => ts.SourceFile;
68
+ ```bash
69
+ ttsc [options]
70
+ ttsc transform --file <path> [options]
71
+ ttsc version
159
72
  ```
160
73
 
161
- Plugin config entry: `{ "transform": "transformer-module" }`.
162
-
163
- #### config
164
-
165
- For the signature with transformer's config:
74
+ Common commands:
166
75
 
167
- ```ts
168
- (config: PluginConfig) => ts.TransformerFactory;
76
+ ```bash
77
+ ttsc
78
+ ttsc -p tsconfig.json
79
+ ttsc --noEmit
80
+ ttsc --watch
81
+ ttsc --outDir lib
82
+ ttsc --verbose
83
+ ttsc transform --file src/index.ts
84
+ ttsc transform --file src/index.ts --out tmp/index.js
169
85
  ```
170
86
 
171
- Plugin config entry: `{ "transform": "transformer-module", type: "config" }`.
172
-
173
- #### checker
174
-
175
- For the signature with ts.TypeChecker:
176
-
177
- ```ts
178
- (checker: ts.TypeChecker, config?: PluginConfig) => ts.TransformerFactory;
87
+ Supported options:
88
+
89
+ - `-p, --project <file>`: resolve project settings from this config file.
90
+ - `--tsconfig <file>`: alias for an explicit project config file.
91
+ - `--cwd <dir>`: resolve project-relative paths from another directory.
92
+ - `--emit`: force emitted files during build.
93
+ - `--noEmit`: type check and transform without writing emitted files.
94
+ - `-w, --watch`: rebuild when project files change.
95
+ - `--preserveWatchOutput`: keep watch output on screen.
96
+ - `--outDir <dir>`: override `compilerOptions.outDir`.
97
+ - `--rewrite-mode <mode>`: force a native rewrite backend id.
98
+ - `--quiet`: keep native build output quiet.
99
+ - `--verbose`: print the native build summary and emitted files.
100
+ - `--out <path>`: write single-file transform output to a file.
101
+ - `--binary <path>`: use an explicit native backend binary.
102
+
103
+ Compatibility aliases:
104
+
105
+ ```bash
106
+ ttsc build
107
+ ttsc check
179
108
  ```
180
109
 
181
- Plugin config entry: `{ "transform": "transformer-module", type: "checker" }`.
110
+ `ttsc build` is the same project build lane as `ttsc`. `ttsc check` is the same as `ttsc --noEmit`.
182
111
 
183
- #### raw
112
+ ## JS API
184
113
 
185
- For the signature without factory wrapper:
114
+ `ttsc` exposes a small JS API for bundlers, runners, and higher-level tools.
186
115
 
187
116
  ```ts
188
- ts.TransformerFactory;
117
+ import { build, check, transform, version } from "ttsc";
189
118
  ```
190
119
 
191
- Plugin config entry: `{ "transform": "transformer-module", type: "raw" }`.
192
-
193
- #### compilerOptions
120
+ Transform one file:
194
121
 
195
122
  ```ts
196
- (compilerOpts: ts.CompilerOptions, config?: PluginConfig) => ts.TransformerFactory;
197
- ```
198
-
199
- Plugin config entry: `{ "transform": "transformer-module", type: "compilerOptions" }`.
123
+ import { transform } from "ttsc";
200
124
 
201
- ```json
202
- {
203
- "compilerOptions": {
204
- "plugins": [
205
- { "transform": "transformer-module", "someOption1": 123, "someOption2": 321 },
206
- { "transform": "./transformers/my-transformer.ts" },
207
- { "transform": "transformer-module", "after": true },
208
- { "transform": "transformer-module", "afterDeclarations": true },
209
- { "transform": "transformer-module", "type": "ls" }
210
- ]
211
- }
212
- }
213
- ```
214
-
215
- ### Command line
216
-
217
- Like usual `tsc`, all arguments work the same way.
218
-
219
- ```
220
- ttsc
125
+ const code = transform({
126
+ cwd: "/project",
127
+ file: "/project/src/index.ts",
128
+ tsconfig: "/project/tsconfig.json",
129
+ });
221
130
  ```
222
131
 
223
- ### ts-node
132
+ Build or check a project:
224
133
 
225
- ```
226
- ts-node --compiler ttypescript index.ts
227
- or
228
- ts-node -C ttypescript index.ts
229
- ```
230
-
231
- ### Parcel
134
+ ```ts
135
+ import { build, check } from "ttsc";
232
136
 
233
- Just install a parcel plugin
137
+ const built = build({
138
+ cwd: process.cwd(),
139
+ tsconfig: "tsconfig.json",
140
+ emit: true,
141
+ });
234
142
 
235
- ```
236
- npm i parcel-plugin-ttypescript
237
- ```
238
-
239
- ### Webpack
240
-
241
- ```js
242
- {
243
- test: /\.(ts|tsx)$/,
244
- loader: require.resolve('awesome-typescript-loader'),
245
- // or
246
- loader: require.resolve('ts-loader'),
247
- options: {
248
- compiler: 'ttypescript'
249
- }
250
- }
251
- ```
143
+ if (built.status !== 0) {
144
+ console.error(built.stderr);
145
+ }
252
146
 
253
- ### Rollup
254
-
255
- ```js
256
- // rollup.config.js
257
- import ttypescript from 'ttypescript';
258
- import tsPlugin from 'rollup-plugin-typescript2';
259
-
260
- export default {
261
- // ...
262
- plugins: [
263
- // ...
264
- tsPlugin({
265
- typescript: ttypescript,
266
- }),
267
- ],
268
- };
147
+ const checked = check({
148
+ tsconfig: "tsconfig.json",
149
+ });
269
150
  ```
270
151
 
271
- ### VS Code
272
-
273
- If you want to compile your project with VS Code task runner you need to overwrite the config `typescript.tsdk` to path of the installed `ttypescript`:
274
-
275
- ```
276
- "typescript.tsdk": "/usr/local/lib/node_modules/ttypescript/lib",
277
- or
278
- "typescript.tsdk": "node_modules/ttypescript/lib",
279
- ```
152
+ `transform()` throws when the native compiler exits with an error. `build()` and `check()` return `{ status, stdout, stderr }`, so callers can decide how to surface compiler failures.
280
153
 
281
- ### Jest, ts-jest
282
-
283
- ```js
284
- module.exports = {
285
- // [...]
286
- globals: {
287
- 'ts-jest': {
288
- compiler: 'ttypescript',
289
- },
290
- },
291
- };
292
- ```
154
+ ## Transformer Library Authors
293
155
 
294
- or in `package.json`
156
+ Transformer libraries publish a normal tsconfig plugin entry:
295
157
 
296
158
  ```json
297
159
  {
298
- "jest": {
299
- "globals": {
300
- "ts-jest": {
301
- "compiler": "ttypescript"
302
- }
303
- }
304
- }
160
+ "compilerOptions": {
161
+ "plugins": [
162
+ { "transform": "my-lib/lib/transform" }
163
+ ]
164
+ }
305
165
  }
306
166
  ```
307
167
 
308
- ## Transformers
168
+ The `transform` value may be:
169
+
170
+ - a package specifier.
171
+ - an absolute path.
172
+ - a relative path from the project root.
309
173
 
310
- You can use transformers written in ts or js
174
+ The plugin module may export a plugin object directly, a default export, a `plugin` export, or a `createTtscPlugin` factory.
311
175
 
312
176
  ```ts
313
- // transformer1-module
314
- import * as ts from 'typescript';
315
- export default function (program: ts.Program, pluginOptions: {}) {
316
- return (ctx: ts.TransformationContext) => {
317
- return (sourceFile: ts.SourceFile) => {
318
- function visitor(node: ts.Node): ts.Node {
319
- // if (ts.isCallExpression(node)) {
320
- // return ts.createLiteral('call');
321
- // }
322
- return ts.visitEachChild(node, visitor, ctx);
323
- }
324
- return ts.visitEachChild(sourceFile, visitor, ctx);
325
- };
326
- };
327
- }
177
+ import { definePlugin } from "ttsc";
178
+
179
+ export default definePlugin((config, context) => ({
180
+ name: "my-lib",
181
+ native: {
182
+ mode: "my-lib",
183
+ binary: require.resolve("my-lib-native/bin/ttsc-my-lib.js"),
184
+ contractVersion: 1,
185
+ capabilities: ["rewrite", "diagnostics"],
186
+ },
187
+ }));
328
188
  ```
329
189
 
330
- Examples of transformers:
331
-
332
- [`{ "transform": "ts-nameof", type: "raw"}`](https://github.com/dsherret/ts-nameof)
190
+ The factory receives:
333
191
 
334
- [`{ "transform": "ts-optchain/transform" }`](https://github.com/rimeto/ts-optchain)
192
+ - `config`: the raw `compilerOptions.plugins[]` entry.
193
+ - `context.binary`: the fallback `ttsc` native binary path.
194
+ - `context.cwd`: the invocation working directory.
195
+ - `context.projectRoot`: the resolved project root.
196
+ - `context.tsconfig`: the resolved config file path.
335
197
 
336
- [`{ "transform": "ts-transform-asset" }`](https://github.com/slune-org/ts-transform-asset)
198
+ Keep this Node-side entry small. Use it for package discovery, feature flags, native binary selection, and manifest construction. Put compiler-sensitive work in the native backend.
337
199
 
338
- [`{ "transform": "ts-transform-auto-require" }`](https://github.com/slune-org/ts-transform-auto-require)
200
+ ## Native Backend Contract
339
201
 
340
- [`{ "transform": "ts-transform-css-modules/dist/transform", type: "config" }`](https://github.com/longlho/ts-transform-css-modules)
202
+ A native transform plugin describes the backend that owns type analysis and rewrite work.
341
203
 
342
- [`{ "transform": "ts-transform-graphql-tag/dist/transformer" }`](https://github.com/firede/ts-transform-graphql-tag)
343
-
344
- [`{ "transform": "ts-transform-img/dist/transform", type: "config" }`](https://github.com/longlho/ts-transform-img)
204
+ ```ts
205
+ import { definePlugin } from "ttsc";
206
+
207
+ export default definePlugin(() => ({
208
+ name: "my-lib",
209
+ native: {
210
+ mode: "my-lib",
211
+ binary: require.resolve("my-lib-native/bin/ttsc-my-lib.js"),
212
+ contractVersion: 1,
213
+ capabilities: ["rewrite", "diagnostics", "assets"],
214
+ },
215
+ }));
216
+ ```
345
217
 
346
- [`{ "transform": "ts-transform-react-intl/dist/transform", import: "transform", type: "config" }`](https://github.com/longlho/ts-transform-react-intl)
218
+ Descriptor shape:
347
219
 
348
- [`{ "transform": "ts-transformer-enumerate/transformer" }`](https://github.com/kimamula/ts-transformer-enumerate)
220
+ ```ts
221
+ interface TtscNativeBackend {
222
+ mode: string;
223
+ binary?: string;
224
+ contractVersion?: 1;
225
+ capabilities?: readonly string[];
226
+ }
227
+ ```
349
228
 
350
- [`{ "transform": "ts-transformer-keys/transformer" }`](https://github.com/kimamula/ts-transformer-keys)
229
+ - `mode` is the rewrite backend id passed to the native compiler process.
230
+ - `binary` points at a consumer-owned native binary.
231
+ - `contractVersion` pins the plugin to the current host protocol.
232
+ - `capabilities` records the backend responsibilities.
351
233
 
352
- [`{ "transform": "ts-transformer-minify-privates" }`](https://github.com/timocov/ts-transformer-minify-privates)
234
+ The backend is responsible for the work old TypeScript transformer libraries used to do through in-process compiler APIs:
353
235
 
354
- [`{ "transform": "typescript-is/lib/transform-inline/transformer" }`](https://github.com/woutervh-/typescript-is)
236
+ - loading the project through the `typescript-go` lane.
237
+ - finding marker calls such as `typia.is<T>()`.
238
+ - analyzing types through native checker access or a serialized IR.
239
+ - emitting replacement JavaScript.
240
+ - reporting plugin-specific diagnostics.
241
+ - emitting plugin-owned assets when needed.
355
242
 
356
- [`{ "transform": "typescript-plugin-styled-components", type: "config" }`](https://github.com/Igorbek/typescript-plugin-styled-components#ttypescript-compiler)
243
+ ## JS Output Hooks
357
244
 
358
- [`{ "transform": "typescript-transform-jsx" }`](https://github.com/LeDDGroup/typescript-transform-jsx)
245
+ For text-level post-processing, a plugin can provide `transformOutput()`.
359
246
 
360
- [`{ "transform": "typescript-transform-macros" }`](https://github.com/LeDDGroup/typescript-transform-macros)
247
+ ```ts
248
+ import { definePlugin } from "ttsc";
361
249
 
362
- [`{ "transform": "typescript-transform-paths" }`](https://github.com/LeDDGroup/typescript-transform-paths)
250
+ export default definePlugin((config) => ({
251
+ name: "banner-plugin",
252
+ transformOutput(context) {
253
+ if (context.command === "build") {
254
+ return `/* generated by ${config.transform} */\n${context.code}`;
255
+ }
256
+ return context.code;
257
+ },
258
+ }));
259
+ ```
363
260
 
364
- [`{ "transform": "@zerollup/ts-transform-paths" }`](https://github.com/zerkalica/zerollup/tree/master/packages/ts-transform-paths)
261
+ `transformOutput()` receives JavaScript text after native emit. Use it for:
365
262
 
366
- [`{ "transform": "@zoltu/typescript-transformer-append-js-extension" }`](https://github.com/Zoltu/typescript-transformer-append-js-extension)
263
+ - banner injection.
264
+ - output string patching.
265
+ - runtime helper import rewrites.
266
+ - consumer-specific output normalization.
367
267
 
368
- [`{ "transform": "@magic-works/ttypescript-browser-like-import-transformer" }`](https://github.com/Jack-Works/ttypescript-browser-like-import-transformer)
268
+ Use a native backend for compiler-sensitive work:
369
269
 
370
- [`{ "transform": "typescript-transform-react-jsx-source" }`](https://github.com/alexgorbatchev/typescript-transform-react-jsx-source)
270
+ - type analysis.
271
+ - AST mutation.
272
+ - call-site recognition.
273
+ - `ts.Program` / `ts.TypeChecker` transformer compatibility.
371
274
 
372
- [`{ "transform": "ts-transformer-remove-named-export" }`](https://github.com/dominguezcelada/ts-transformer-remove-named-export)
275
+ ## Current Constraints
373
276
 
374
- [`{ "transform": "ts-transformer-export-default-name" }`](https://github.com/jirutka/ts-transformer-export-default-name)
277
+ These are current host constraints transformer authors should design around.
375
278
 
376
- [`{ "transform": "ts-transformer-inline-file/transformer" }`](https://github.com/jirutka/ts-transformer-inline-file)
279
+ - One invocation can select one native `mode` / `binary` pair.
280
+ - Multiple text-only `transformOutput()` plugins can run in order.
281
+ - Passing `plugins` to the JS API replaces the tsconfig plugin list.
282
+ - `transformOutput()` is a JS text hook, not a JS AST hook.
283
+ - The current setup lane is `@typescript/native-preview`.
377
284
 
378
- [`{ "transform": "ts-transformer-strip-const-enums", "entrySourceFiles": ["./src/index.ts" }`](https://github.com/timocov/ts-transformer-strip-const-enums)
285
+ ## Integration Patterns
379
286
 
380
- [`{ "transform": "ts-transformer-properties-rename", "entrySourceFiles": ["./src/index.ts"] }`](https://github.com/timocov/ts-transformer-properties-rename)
287
+ Consumer library:
381
288
 
382
- [`{ "transform": "tsc-progress", "name": "TSC", "color": "green" }`](https://github.com/JiangWeixian/tsc-progress)
289
+ - publish a tsconfig plugin entry such as `my-lib/lib/transform`.
290
+ - resolve a consumer-owned native backend binary from that entry.
291
+ - keep type analysis and rewrite logic in the native backend.
292
+ - optionally layer `transformOutput()` for final JavaScript text normalization.
383
293
 
384
- [Tutorial how to write a typescript transformer](https://dev.doctorevidence.com/how-to-write-a-typescript-transform-plugin-fc5308fdd943)
294
+ Bundler adapter:
385
295
 
386
- - [Tutorial how to write a typescript transformer](https://dev.doctorevidence.com/how-to-write-a-typescript-transform-plugin-fc5308fdd943)
387
- - [Transformer framework](https://github.com/slune-org/simple-ts-transform)
388
- - [Unit testing transformer compiler](https://github.com/slune-org/ts-transform-test-compiler)
296
+ - call `transform()` for per-file rewrites.
297
+ - pass `plugins` when the adapter needs deterministic plugin state.
298
+ - let `ttsc` resolve the native backend instead of spawning it manually.
389
299
 
390
- ## Example
300
+ Runner:
391
301
 
392
- An example project is in the [example](./packages/ttypescript-examples) directory
302
+ - use `ttsx` for direct execution.
303
+ - reuse the same `compilerOptions.plugins` contract.
304
+ - keep build-time and runtime transform behavior aligned.
393
305
 
394
- ## License
306
+ ## References
395
307
 
396
- MIT License
308
+ - TypeScript runners: [`ts-node`](https://github.com/TypeStrong/ts-node) and [`tsx`](https://github.com/privatenumber/tsx)
309
+ - Transformer tooling: [`ttypescript`](https://github.com/cevek/ttypescript) and [`ts-patch`](https://github.com/nonara/ts-patch)
310
+ - Inspired by: [`typical`](https://github.com/samchon/typical) and [`tsgonest`](https://github.com/samchon/tsgonest)