ttsc 0.3.1 → 0.4.0-dev.20260425

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 (121) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +93 -362
  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 +18 -0
  19. package/lib/index.js +35 -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/lib/runner/cli.d.ts +1 -0
  34. package/lib/runner/cli.js +284 -0
  35. package/lib/runner/cli.js.map +1 -0
  36. package/lib/runner/register.d.ts +13 -0
  37. package/lib/runner/register.js +424 -0
  38. package/lib/runner/register.js.map +1 -0
  39. package/package.json +72 -63
  40. package/shim/ast/extra-shim.json +4 -0
  41. package/shim/ast/go.mod +5 -0
  42. package/shim/ast/shim.go +117 -0
  43. package/shim/bundled/extra-shim.json +1 -0
  44. package/shim/bundled/go.mod +5 -0
  45. package/shim/bundled/shim.go +19 -0
  46. package/shim/checker/extra-shim.json +31 -0
  47. package/shim/checker/go.mod +5 -0
  48. package/shim/checker/shim.go +146 -0
  49. package/shim/compiler/extra-shim.json +4 -0
  50. package/shim/compiler/go.mod +5 -0
  51. package/shim/compiler/shim.go +50 -0
  52. package/shim/core/extra-shim.json +4 -0
  53. package/shim/core/go.mod +5 -0
  54. package/shim/core/shim.go +11 -0
  55. package/shim/diagnosticwriter/go.mod +5 -0
  56. package/shim/diagnosticwriter/shim.go +29 -0
  57. package/shim/parser/extra-shim.json +4 -0
  58. package/shim/parser/go.mod +5 -0
  59. package/shim/parser/shim.go +55 -0
  60. package/shim/scanner/extra-shim.json +4 -0
  61. package/shim/scanner/go.mod +5 -0
  62. package/shim/scanner/shim.go +96 -0
  63. package/shim/tsoptions/extra-shim.json +4 -0
  64. package/shim/tsoptions/go.mod +5 -0
  65. package/shim/tsoptions/shim.go +123 -0
  66. package/shim/tspath/extra-shim.json +4 -0
  67. package/shim/tspath/go.mod +5 -0
  68. package/shim/tspath/shim.go +165 -0
  69. package/shim/vfs/cachedvfs/extra-shim.json +4 -0
  70. package/shim/vfs/cachedvfs/go.mod +5 -0
  71. package/shim/vfs/cachedvfs/shim.go +12 -0
  72. package/shim/vfs/extra-shim.json +4 -0
  73. package/shim/vfs/go.mod +5 -0
  74. package/shim/vfs/osvfs/extra-shim.json +4 -0
  75. package/shim/vfs/osvfs/go.mod +5 -0
  76. package/shim/vfs/osvfs/shim.go +13 -0
  77. package/shim/vfs/shim.go +19 -0
  78. package/src/api.ts +416 -0
  79. package/src/cli.ts +492 -0
  80. package/src/index.ts +19 -0
  81. package/src/launcher/ttsc-dev.js +42 -0
  82. package/src/launcher/ttsc.js +19 -0
  83. package/src/launcher/ttsx.js +19 -0
  84. package/src/native.ts +60 -0
  85. package/src/platform.ts +163 -0
  86. package/src/plugin.ts +241 -0
  87. package/src/project.ts +330 -0
  88. package/src/runner/cli.ts +286 -0
  89. package/src/runner/register.ts +487 -0
  90. package/test/native.test.ts +60 -0
  91. package/test/package.test.ts +131 -0
  92. package/test/platform.test.ts +58 -0
  93. package/test/project.test.ts +195 -0
  94. package/tools/gen_shims/go.mod +14 -0
  95. package/tools/gen_shims/go.sum +12 -0
  96. package/tools/gen_shims/main.go +446 -0
  97. package/CHANGELOG.md +0 -2
  98. package/bin/tsc +0 -2
  99. package/bin/tsserver +0 -2
  100. package/lib/PluginCreator.d.ts +0 -67
  101. package/lib/PluginCreator.js +0 -190
  102. package/lib/cancelationToken.d.ts +0 -0
  103. package/lib/cancelationToken.js +0 -2
  104. package/lib/loadTypescript.d.ts +0 -7
  105. package/lib/loadTypescript.js +0 -56
  106. package/lib/patchCreateProgram.d.ts +0 -21
  107. package/lib/patchCreateProgram.js +0 -190
  108. package/lib/tsc.d.ts +0 -1
  109. package/lib/tsc.js +0 -24
  110. package/lib/tsserver.d.ts +0 -0
  111. package/lib/tsserver.js +0 -2
  112. package/lib/tsserverlibrary.d.ts +0 -3
  113. package/lib/tsserverlibrary.js +0 -4
  114. package/lib/typescript.d.ts +0 -3
  115. package/lib/typescript.js +0 -4
  116. package/lib/typescriptServices.d.ts +0 -3
  117. package/lib/typescriptServices.js +0 -4
  118. package/lib/typingsInstaller.d.ts +0 -0
  119. package/lib/typingsInstaller.js +0 -2
  120. package/lib/watchGuard.d.ts +0 -0
  121. 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,127 @@
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](https://raw.githubusercontent.com/samchon/ttsc/refs/heads/master/assets/og.jpg)
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` toolchain for compiler-powered transforms and type-safe execution.
10
11
 
11
- And it supports TS5.
12
+ - **`ttsc`**: build, check, and transform.
13
+ - **`ttsx`**: execute TypeScript with type checking.
14
+ - 10x faster than `ts-node`.
15
+ - type checking that `tsx` does not provide.
16
+ - **transformer support**: compiler-powered libraries, such as `typia`.
12
17
 
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)
18
+ > `ttsx` (CLI command) can run existing `typescript@6` projects.
14
19
 
15
- # ttypescript
20
+ ## Setup
16
21
 
17
- ## Existing contributors
18
-
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'
58
- ```
59
- --->
60
-
61
- Instead of tsc and tsserver, use ttsc and ttsserver wrappers. This wrappers try to use locally installed typescript first.
62
-
63
- No version lock-ins - typescript used as peer dependency.
64
-
65
- ## How to install
22
+ Install the native TypeScript preview package with `ttsc`:
66
23
 
24
+ ```bash
25
+ npm i -D ttsc @typescript/native-preview
67
26
  ```
68
- npm i ttypescript -D
69
- ```
70
-
71
- ttypescript uses your installed `typescript` in your `node_modules`
72
-
73
- ## How to use
74
-
75
- ### tsconfig.json
76
27
 
77
- Set a transformer path to the `tsconfig.json` in `compilerOptions` section `plugin` array:
28
+ Run TypeScript directly with `ttsx` (CLI command):
78
29
 
30
+ ```bash
31
+ npx ttsx src/index.ts
79
32
  ```
80
- {
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
33
 
108
- /**
109
- * Should transformer applied after all ones
110
- */
111
- after?: boolean;
34
+ Build, check, or watch the project with `ttsc`:
112
35
 
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;
121
- }
36
+ ```bash
37
+ npx ttsc
38
+ npx ttsc --noEmit
39
+ npx ttsc --watch
122
40
  ```
123
41
 
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`
127
-
128
- ### PluginConfig.type
129
-
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>;
148
- ```
149
- --->
150
-
151
- #### program
152
-
153
- If the transformer has a factory signature using `program` as first argument:
154
-
155
- ```ts
156
- (program: ts.Program, config?: PluginConfig) => ts.TransformerFactory;
157
- where;
158
- ts.TransformerFactory = (context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => ts.SourceFile;
159
- ```
160
-
161
- Plugin config entry: `{ "transform": "transformer-module" }`.
162
-
163
- #### config
164
-
165
- For the signature with transformer's config:
166
-
167
- ```ts
168
- (config: PluginConfig) => ts.TransformerFactory;
169
- ```
170
-
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;
179
- ```
180
-
181
- Plugin config entry: `{ "transform": "transformer-module", type: "checker" }`.
182
-
183
- #### raw
184
-
185
- For the signature without factory wrapper:
186
-
187
- ```ts
188
- ts.TransformerFactory;
189
- ```
190
-
191
- Plugin config entry: `{ "transform": "transformer-module", type: "raw" }`.
192
-
193
- #### compilerOptions
194
-
195
- ```ts
196
- (compilerOpts: ts.CompilerOptions, config?: PluginConfig) => ts.TransformerFactory;
197
- ```
42
+ ## Transformer Configuration
198
43
 
199
- Plugin config entry: `{ "transform": "transformer-module", type: "compilerOptions" }`.
44
+ `ttsc` reads `compilerOptions.plugins` from `tsconfig.json`.
200
45
 
201
46
  ```json
202
47
  {
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
- }
48
+ "compilerOptions": {
49
+ "plugins": [
50
+ { "transform": "typia/lib/transform" }
51
+ ]
52
+ }
212
53
  }
213
54
  ```
214
55
 
215
- ### Command line
216
-
217
- Like usual `tsc`, all arguments work the same way.
218
-
219
- ```
220
- ttsc
221
- ```
222
-
223
- ### ts-node
224
-
225
- ```
226
- ts-node --compiler ttypescript index.ts
227
- or
228
- ts-node -C ttypescript index.ts
229
- ```
230
-
231
- ### Parcel
232
-
233
- Just install a parcel plugin
234
-
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
- ```
252
-
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
- };
269
- ```
270
-
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
- ```
56
+ The same configuration is used by both `ttsc` commands.
280
57
 
281
- ### Jest, ts-jest
58
+ ```bash
59
+ # compile
60
+ npx ttsc
282
61
 
283
- ```js
284
- module.exports = {
285
- // [...]
286
- globals: {
287
- 'ts-jest': {
288
- compiler: 'ttypescript',
289
- },
290
- },
291
- };
62
+ # execute
63
+ npx ttsx src/index.ts
292
64
  ```
293
65
 
294
- or in `package.json`
295
-
296
- ```json
297
- {
298
- "jest": {
299
- "globals": {
300
- "ts-jest": {
301
- "compiler": "ttypescript"
302
- }
303
- }
304
- }
305
- }
306
- ```
66
+ This gives compiler-powered libraries one transform path for both build-time and runtime execution.
307
67
 
308
- ## Transformers
68
+ ## What Is a Transform?
309
69
 
310
- You can use transformers written in ts or js
70
+ A transform uses TypeScript types to generate JavaScript before runtime.
311
71
 
312
72
  ```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
- };
73
+ import typia, { tags } from "typia";
74
+ import { v4 } from "uuid";
75
+
76
+ const matched: boolean = typia.is<IMember>({
77
+ id: v4(),
78
+ email: "samchon.github@gmail.com",
79
+ age: 30,
80
+ });
81
+ console.log(matched); // true
82
+
83
+ interface IMember {
84
+ id: string & tags.Format<"uuid">;
85
+ email: string & tags.Format<"email">;
86
+ age: number &
87
+ tags.Type<"uint32"> &
88
+ tags.ExclusiveMinimum<19> &
89
+ tags.Maximum<100>;
327
90
  }
328
91
  ```
329
92
 
330
- Examples of transformers:
331
-
332
- [`{ "transform": "ts-nameof", type: "raw"}`](https://github.com/dsherret/ts-nameof)
333
-
334
- [`{ "transform": "ts-optchain/transform" }`](https://github.com/rimeto/ts-optchain)
335
-
336
- [`{ "transform": "ts-transform-asset" }`](https://github.com/slune-org/ts-transform-asset)
337
-
338
- [`{ "transform": "ts-transform-auto-require" }`](https://github.com/slune-org/ts-transform-auto-require)
339
-
340
- [`{ "transform": "ts-transform-css-modules/dist/transform", type: "config" }`](https://github.com/longlho/ts-transform-css-modules)
341
-
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)
345
-
346
- [`{ "transform": "ts-transform-react-intl/dist/transform", import: "transform", type: "config" }`](https://github.com/longlho/ts-transform-react-intl)
347
-
348
- [`{ "transform": "ts-transformer-enumerate/transformer" }`](https://github.com/kimamula/ts-transformer-enumerate)
349
-
350
- [`{ "transform": "ts-transformer-keys/transformer" }`](https://github.com/kimamula/ts-transformer-keys)
351
-
352
- [`{ "transform": "ts-transformer-minify-privates" }`](https://github.com/timocov/ts-transformer-minify-privates)
353
-
354
- [`{ "transform": "typescript-is/lib/transform-inline/transformer" }`](https://github.com/woutervh-/typescript-is)
355
-
356
- [`{ "transform": "typescript-plugin-styled-components", type: "config" }`](https://github.com/Igorbek/typescript-plugin-styled-components#ttypescript-compiler)
357
-
358
- [`{ "transform": "typescript-transform-jsx" }`](https://github.com/LeDDGroup/typescript-transform-jsx)
359
-
360
- [`{ "transform": "typescript-transform-macros" }`](https://github.com/LeDDGroup/typescript-transform-macros)
361
-
362
- [`{ "transform": "typescript-transform-paths" }`](https://github.com/LeDDGroup/typescript-transform-paths)
363
-
364
- [`{ "transform": "@zerollup/ts-transform-paths" }`](https://github.com/zerkalica/zerollup/tree/master/packages/ts-transform-paths)
365
-
366
- [`{ "transform": "@zoltu/typescript-transformer-append-js-extension" }`](https://github.com/Zoltu/typescript-transformer-append-js-extension)
367
-
368
- [`{ "transform": "@magic-works/ttypescript-browser-like-import-transformer" }`](https://github.com/Jack-Works/ttypescript-browser-like-import-transformer)
369
-
370
- [`{ "transform": "typescript-transform-react-jsx-source" }`](https://github.com/alexgorbatchev/typescript-transform-react-jsx-source)
371
-
372
- [`{ "transform": "ts-transformer-remove-named-export" }`](https://github.com/dominguezcelada/ts-transformer-remove-named-export)
373
-
374
- [`{ "transform": "ts-transformer-export-default-name" }`](https://github.com/jirutka/ts-transformer-export-default-name)
375
-
376
- [`{ "transform": "ts-transformer-inline-file/transformer" }`](https://github.com/jirutka/ts-transformer-inline-file)
377
-
378
- [`{ "transform": "ts-transformer-strip-const-enums", "entrySourceFiles": ["./src/index.ts" }`](https://github.com/timocov/ts-transformer-strip-const-enums)
379
-
380
- [`{ "transform": "ts-transformer-properties-rename", "entrySourceFiles": ["./src/index.ts"] }`](https://github.com/timocov/ts-transformer-properties-rename)
381
-
382
- [`{ "transform": "tsc-progress", "name": "TSC", "color": "green" }`](https://github.com/JiangWeixian/tsc-progress)
383
-
384
- [Tutorial how to write a typescript transformer](https://dev.doctorevidence.com/how-to-write-a-typescript-transform-plugin-fc5308fdd943)
385
-
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)
389
-
390
- ## Example
391
-
392
- An example project is in the [example](./packages/ttypescript-examples) directory
393
-
394
- ## License
395
-
396
- MIT License
93
+ It is transformed into dedicated JavaScript:
94
+
95
+ > ```js
96
+ > import typia from "typia";
97
+ > import * as __typia_transform__isFormatEmail from "typia/lib/internal/_isFormatEmail";
98
+ > import * as __typia_transform__isFormatUuid from "typia/lib/internal/_isFormatUuid";
99
+ > import * as __typia_transform__isTypeUint32 from "typia/lib/internal/_isTypeUint32";
100
+ > import { v4 } from "uuid";
101
+ >
102
+ > const matched = (() => {
103
+ > const _io0 = (input) =>
104
+ > "string" === typeof input.id &&
105
+ > __typia_transform__isFormatUuid._isFormatUuid(input.id) &&
106
+ > "string" === typeof input.email &&
107
+ > __typia_transform__isFormatEmail._isFormatEmail(input.email) &&
108
+ > "number" === typeof input.age &&
109
+ > __typia_transform__isTypeUint32._isTypeUint32(input.age) &&
110
+ > 19 < input.age &&
111
+ > input.age <= 100;
112
+ > return (input) => "object" === typeof input && null !== input && _io0(input);
113
+ > })()({
114
+ > id: v4(),
115
+ > email: "samchon.github@gmai19l.com",
116
+ > age: 30,
117
+ > });
118
+ > console.log(matched); // true
119
+ > ```
120
+
121
+ `ttsc` runs this transform during build, and `ttsx` runs through the same transform path during execution.
122
+
123
+ ## References
124
+
125
+ - TypeScript runners: [`ts-node`](https://github.com/TypeStrong/ts-node) and [`tsx`](https://github.com/privatenumber/tsx)
126
+ - Transformer tooling: [`ttypescript`](https://github.com/cevek/ttypescript) and [`ts-patch`](https://github.com/nonara/ts-patch)
127
+ - Inspired by: [`typical`](https://github.com/elliots/typical) and [`tsgonest`](https://github.com/tsgonest/tsgonest)
@@ -0,0 +1,128 @@
1
+ package main
2
+
3
+ import (
4
+ "encoding/json"
5
+ "flag"
6
+ "fmt"
7
+ "os"
8
+ "path/filepath"
9
+
10
+ shimcompiler "github.com/microsoft/typescript-go/shim/compiler"
11
+
12
+ "github.com/samchon/ttsc/packages/ttsc/driver"
13
+ )
14
+
15
+ // runBuild implements the `ttsc` project-build lane. Two modes:
16
+ //
17
+ // - default (dry run): analyze quietly, surfacing only diagnostics/errors.
18
+ // - --emit: also run tsgo's emit pipeline, patching every recognized native
19
+ // consumer call in the resulting .js files.
20
+ func runBuild(args []string) int {
21
+ fs := flag.NewFlagSet("build", flag.ContinueOnError)
22
+ fs.SetOutput(stderr)
23
+ tsconfigPath := fs.String("tsconfig", "tsconfig.json", "path to tsconfig.json")
24
+ cwdOverride := fs.String("cwd", "", "override the working directory (defaults to process cwd)")
25
+ quiet := fs.Bool("quiet", true, "suppress the per-call diagnostic summary")
26
+ verbose := fs.Bool("verbose", false, "print the per-call diagnostic summary")
27
+ emit := fs.Bool("emit", false, "force emitted .js files (runs tsgo + ttsc rewrite)")
28
+ noEmit := fs.Bool("noEmit", false, "force analysis-only run with no file writes")
29
+ outDir := fs.String("outDir", "", "override compilerOptions.outDir for this build")
30
+ manifestPath := fs.String("manifest", "", "write emitted file list as JSON to this path")
31
+ rewriteMode := fs.String("rewrite-mode", "none", "native rewrite backend id")
32
+ if err := fs.Parse(args); err != nil {
33
+ return 2
34
+ }
35
+ if *emit && *noEmit {
36
+ fmt.Fprintln(stderr, "ttsc: --emit and --noEmit are mutually exclusive")
37
+ return 2
38
+ }
39
+ if *verbose {
40
+ *quiet = false
41
+ }
42
+
43
+ cwd := *cwdOverride
44
+ if cwd == "" {
45
+ var err error
46
+ cwd, err = os.Getwd()
47
+ if err != nil {
48
+ fmt.Fprintf(stderr, "ttsc: could not get working directory: %v\n", err)
49
+ return 2
50
+ }
51
+ }
52
+
53
+ prog, diags, err := driver.LoadProgram(cwd, *tsconfigPath, driver.LoadProgramOptions{
54
+ ForceEmit: *emit,
55
+ ForceNoEmit: *noEmit,
56
+ OutDir: *outDir,
57
+ })
58
+ if err != nil {
59
+ fmt.Fprintf(stderr, "ttsc: %v\n", err)
60
+ return 2
61
+ }
62
+ if len(diags) > 0 {
63
+ driver.WritePrettyDiagnostics(stderr, diags, cwd)
64
+ return 2
65
+ }
66
+ defer prog.Close()
67
+ if diags := prog.Diagnostics(); len(diags) > 0 {
68
+ driver.WritePrettyDiagnostics(stderr, diags, cwd)
69
+ return 2
70
+ }
71
+
72
+ rewrites := driver.NewRewriteSet()
73
+ shouldEmit := !prog.ParsedConfig.ParsedConfig.CompilerOptions.NoEmit.IsTrue()
74
+ if *rewriteMode != "none" {
75
+ fmt.Fprintf(stderr, "ttsc: rewrite backend %q is not built into the standalone ttsc binary\n", *rewriteMode)
76
+ fmt.Fprintln(stderr, "ttsc: run through the JS host with the matching compiler plugin so it can select the consumer-provided native binary")
77
+ return 2
78
+ }
79
+ if !*quiet {
80
+ fmt.Fprintf(stdout, "// ttsc: tsconfig=%s cwd=%s sites=%d emit=%v rewrite=%s\n", *tsconfigPath, cwd, 0, shouldEmit, *rewriteMode)
81
+ }
82
+
83
+ if shouldEmit {
84
+ writeFile := shimcompiler.WriteFile(
85
+ func(fileName, text string, _ *shimcompiler.WriteFileData) error {
86
+ return driver.DefaultWriteFile(fileName, text)
87
+ },
88
+ )
89
+ res, eDiags, err := prog.EmitAll(rewrites, writeFile)
90
+ if err != nil {
91
+ fmt.Fprintf(stderr, "ttsc: emit failed: %v\n", err)
92
+ return 3
93
+ }
94
+ for _, d := range eDiags {
95
+ fmt.Fprintln(stderr, " -", d.String())
96
+ }
97
+ if !*quiet {
98
+ fmt.Fprintf(stdout, "// ttsc: emitted=%d files\n", len(res.EmittedFiles))
99
+ for _, f := range res.EmittedFiles {
100
+ rel := f
101
+ if abs, err := filepath.Rel(cwd, f); err == nil {
102
+ rel = abs
103
+ }
104
+ fmt.Fprintln(stdout, " +", rel)
105
+ }
106
+ }
107
+ if *manifestPath != "" {
108
+ data, err := json.Marshal(res.EmittedFiles)
109
+ if err != nil {
110
+ fmt.Fprintf(stderr, "ttsc: manifest marshal failed: %v\n", err)
111
+ return 3
112
+ }
113
+ if err := os.MkdirAll(filepath.Dir(*manifestPath), 0o755); err != nil {
114
+ fmt.Fprintf(stderr, "ttsc: manifest mkdir failed: %v\n", err)
115
+ return 3
116
+ }
117
+ if err := os.WriteFile(*manifestPath, data, 0o644); err != nil {
118
+ fmt.Fprintf(stderr, "ttsc: manifest write failed: %v\n", err)
119
+ return 3
120
+ }
121
+ }
122
+ }
123
+
124
+ if !*quiet {
125
+ fmt.Fprintf(stdout, "// ttsc: recognized=%d total=%d rewrites=%d\n", 0, 0, rewrites.Len())
126
+ }
127
+ return 0
128
+ }