ttsc 0.6.0 → 0.7.1

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 (271) hide show
  1. package/cmd/platform/main.go +1 -1
  2. package/cmd/ttsc/api_compile.go +134 -0
  3. package/cmd/ttsc/api_transform.go +64 -0
  4. package/cmd/ttsc/build.go +1 -7
  5. package/cmd/ttsc/main.go +6 -20
  6. package/driver/program.go +13 -3
  7. package/lib/TtscCompiler.d.ts +96 -0
  8. package/lib/TtscCompiler.js +294 -0
  9. package/lib/TtscCompiler.js.map +1 -0
  10. package/lib/compiler/internal/buildNativeCompiler.d.ts +6 -0
  11. package/lib/compiler/internal/buildNativeCompiler.js +72 -0
  12. package/lib/compiler/internal/buildNativeCompiler.js.map +1 -0
  13. package/lib/compiler/internal/compileProjectInMemory.d.ts +7 -0
  14. package/lib/compiler/internal/compileProjectInMemory.js +176 -0
  15. package/lib/compiler/internal/compileProjectInMemory.js.map +1 -0
  16. package/lib/compiler/internal/project/readProjectConfig.d.ts +4 -0
  17. package/lib/{project.js → compiler/internal/project/readProjectConfig.js} +12 -82
  18. package/lib/compiler/internal/project/readProjectConfig.js.map +1 -0
  19. package/lib/compiler/internal/project/resolveProjectConfig.d.ts +3 -0
  20. package/lib/compiler/internal/project/resolveProjectConfig.js +94 -0
  21. package/lib/compiler/internal/project/resolveProjectConfig.js.map +1 -0
  22. package/lib/compiler/internal/resolveBinary.d.ts +4 -0
  23. package/lib/compiler/internal/resolveBinary.js +65 -0
  24. package/lib/compiler/internal/resolveBinary.js.map +1 -0
  25. package/lib/compiler/internal/resolveEmittedJavaScript.d.ts +7 -0
  26. package/lib/compiler/internal/resolveEmittedJavaScript.js +118 -0
  27. package/lib/compiler/internal/resolveEmittedJavaScript.js.map +1 -0
  28. package/lib/compiler/internal/resolveTsgo.d.ts +20 -0
  29. package/lib/{tsgo.js → compiler/internal/resolveTsgo.js} +5 -10
  30. package/lib/compiler/internal/resolveTsgo.js.map +1 -0
  31. package/lib/compiler/internal/runBuild.d.ts +10 -0
  32. package/lib/compiler/internal/runBuild.js +480 -0
  33. package/lib/compiler/internal/runBuild.js.map +1 -0
  34. package/lib/compiler/internal/runSingleFileEmit.d.ts +3 -0
  35. package/lib/compiler/internal/runSingleFileEmit.js +102 -0
  36. package/lib/compiler/internal/runSingleFileEmit.js.map +1 -0
  37. package/lib/compiler/internal/transformProjectInMemory.d.ts +7 -0
  38. package/lib/compiler/internal/transformProjectInMemory.js +275 -0
  39. package/lib/compiler/internal/transformProjectInMemory.js.map +1 -0
  40. package/lib/index.d.ts +6 -15
  41. package/lib/index.js +6 -15
  42. package/lib/index.js.map +1 -1
  43. package/lib/launcher/internal/getCompilerVersionText.d.ts +3 -0
  44. package/lib/launcher/internal/getCompilerVersionText.js +71 -0
  45. package/lib/launcher/internal/getCompilerVersionText.js.map +1 -0
  46. package/lib/launcher/internal/prepareExecution.d.ts +10 -0
  47. package/lib/launcher/internal/prepareExecution.js +120 -0
  48. package/lib/launcher/internal/prepareExecution.js.map +1 -0
  49. package/lib/launcher/internal/runTtsc.d.ts +1 -0
  50. package/lib/{cli.js → launcher/internal/runTtsc.js} +45 -118
  51. package/lib/launcher/internal/runTtsc.js.map +1 -0
  52. package/lib/launcher/internal/runTtsx.d.ts +1 -0
  53. package/lib/{runner/cli.js → launcher/internal/runTtsx.js} +13 -35
  54. package/lib/launcher/internal/runTtsx.js.map +1 -0
  55. package/lib/launcher/ttsc.js +2 -2
  56. package/lib/launcher/ttsc.js.map +1 -1
  57. package/lib/launcher/ttsx.js +2 -2
  58. package/lib/launcher/ttsx.js.map +1 -1
  59. package/lib/plugin/internal/buildSourcePlugin.d.ts +12 -0
  60. package/lib/{source-build.js → plugin/internal/buildSourcePlugin.js} +77 -84
  61. package/lib/plugin/internal/buildSourcePlugin.js.map +1 -0
  62. package/lib/plugin/internal/loadProjectPlugins.d.ts +14 -0
  63. package/lib/{plugin.js → plugin/internal/loadProjectPlugins.js} +38 -76
  64. package/lib/plugin/internal/loadProjectPlugins.js.map +1 -0
  65. package/lib/structures/ITtscCompilerContext.d.ts +78 -0
  66. package/lib/structures/ITtscCompilerContext.js +3 -0
  67. package/lib/structures/ITtscCompilerContext.js.map +1 -0
  68. package/lib/structures/ITtscCompilerDiagnostic.d.ts +83 -0
  69. package/lib/structures/ITtscCompilerDiagnostic.js +3 -0
  70. package/lib/structures/ITtscCompilerDiagnostic.js.map +1 -0
  71. package/lib/structures/ITtscCompilerResult.d.ts +83 -0
  72. package/lib/structures/{ITtscCacheKeyInput.js → ITtscCompilerResult.js} +1 -1
  73. package/lib/structures/ITtscCompilerResult.js.map +1 -0
  74. package/lib/structures/ITtscCompilerTransformation.d.ts +35 -0
  75. package/lib/structures/ITtscCompilerTransformation.js +3 -0
  76. package/lib/structures/ITtscCompilerTransformation.js.map +1 -0
  77. package/lib/structures/ITtscPlugin.d.ts +52 -7
  78. package/lib/structures/ITtscPluginFactoryContext.d.ts +47 -0
  79. package/lib/structures/ITtscProjectPluginConfig.d.ts +41 -0
  80. package/lib/structures/TtscPluginStage.d.ts +18 -0
  81. package/lib/structures/{ITtscBuildResult.js → TtscPluginStage.js} +1 -1
  82. package/lib/structures/TtscPluginStage.js.map +1 -0
  83. package/lib/structures/index.d.ts +8 -0
  84. package/lib/structures/index.js +25 -0
  85. package/lib/structures/index.js.map +1 -0
  86. package/lib/structures/internal/ITtscLoadedNativePlugin.d.ts +13 -0
  87. package/lib/structures/internal/ITtscLoadedNativePlugin.js.map +1 -0
  88. package/lib/structures/internal/ITtscParsedProjectConfig.d.ts +15 -0
  89. package/lib/structures/internal/ITtscParsedProjectConfig.js.map +1 -0
  90. package/lib/structures/internal/ITtscProjectLocatorOptions.d.ts +9 -0
  91. package/lib/structures/internal/ITtscProjectLocatorOptions.js.map +1 -0
  92. package/lib/structures/internal/TtscBuildOptions.d.ts +18 -0
  93. package/lib/structures/{ITtscBuildOptions.js → internal/TtscBuildOptions.js} +1 -1
  94. package/lib/structures/internal/TtscBuildOptions.js.map +1 -0
  95. package/lib/structures/internal/TtscBuildResult.d.ts +14 -0
  96. package/lib/structures/{ITtscCheckOptions.js → internal/TtscBuildResult.js} +1 -1
  97. package/lib/structures/internal/TtscBuildResult.js.map +1 -0
  98. package/lib/structures/internal/TtscCommonOptions.d.ts +27 -0
  99. package/lib/structures/{ITtscNativeSource.js → internal/TtscCommonOptions.js} +1 -1
  100. package/lib/structures/internal/TtscCommonOptions.js.map +1 -0
  101. package/lib/structures/internal/TtscSingleFileEmitOptions.d.ts +14 -0
  102. package/lib/structures/internal/TtscSingleFileEmitOptions.js +3 -0
  103. package/lib/structures/internal/TtscSingleFileEmitOptions.js.map +1 -0
  104. package/package.json +9 -9
  105. package/src/TtscCompiler.ts +305 -0
  106. package/src/compiler/internal/buildNativeCompiler.ts +43 -0
  107. package/src/compiler/internal/compileProjectInMemory.ts +189 -0
  108. package/src/{project.ts → compiler/internal/project/readProjectConfig.ts} +36 -111
  109. package/src/compiler/internal/project/resolveProjectConfig.ts +67 -0
  110. package/src/compiler/internal/resolveBinary.ts +41 -0
  111. package/src/compiler/internal/resolveEmittedJavaScript.ts +102 -0
  112. package/src/{tsgo.ts → compiler/internal/resolveTsgo.ts} +20 -23
  113. package/src/compiler/internal/runBuild.ts +644 -0
  114. package/src/compiler/internal/runSingleFileEmit.ts +73 -0
  115. package/src/compiler/internal/transformProjectInMemory.ts +368 -0
  116. package/src/index.ts +6 -15
  117. package/src/launcher/internal/getCompilerVersionText.ts +44 -0
  118. package/src/launcher/internal/prepareExecution.ts +115 -0
  119. package/src/{cli.ts → launcher/internal/runTtsc.ts} +58 -140
  120. package/src/{runner/cli.ts → launcher/internal/runTtsx.ts} +21 -49
  121. package/src/launcher/ttsc.ts +2 -2
  122. package/src/launcher/ttsx.ts +2 -2
  123. package/src/{source-build.ts → plugin/internal/buildSourcePlugin.ts} +121 -115
  124. package/src/plugin/internal/loadProjectPlugins.ts +214 -0
  125. package/src/structures/ITtscCompilerContext.ts +84 -0
  126. package/src/structures/ITtscCompilerDiagnostic.ts +91 -0
  127. package/src/structures/ITtscCompilerResult.ts +94 -0
  128. package/src/structures/ITtscCompilerTransformation.ts +46 -0
  129. package/src/structures/ITtscPlugin.ts +54 -7
  130. package/src/structures/ITtscPluginFactoryContext.ts +51 -0
  131. package/src/structures/ITtscProjectPluginConfig.ts +43 -0
  132. package/src/structures/TtscPluginStage.ts +18 -0
  133. package/src/structures/index.ts +8 -0
  134. package/src/structures/internal/ITtscLoadedNativePlugin.ts +14 -0
  135. package/src/structures/internal/ITtscParsedProjectConfig.ts +16 -0
  136. package/src/structures/internal/ITtscProjectLocatorOptions.ts +9 -0
  137. package/src/structures/internal/TtscBuildOptions.ts +19 -0
  138. package/src/structures/internal/TtscBuildResult.ts +15 -0
  139. package/src/structures/internal/TtscCommonOptions.ts +28 -0
  140. package/src/structures/internal/TtscSingleFileEmitOptions.ts +15 -0
  141. package/test/compiler.test.ts +422 -0
  142. package/test/platform.test.ts +1 -45
  143. package/test/project.test.ts +3 -1
  144. package/test/source-build.test.ts +33 -220
  145. package/test/tsgo.test.ts +1 -8
  146. package/cmd/ttsc/transform.go +0 -166
  147. package/lib/api.d.ts +0 -40
  148. package/lib/api.js +0 -680
  149. package/lib/api.js.map +0 -1
  150. package/lib/cli.d.ts +0 -1
  151. package/lib/cli.js.map +0 -1
  152. package/lib/native.d.ts +0 -8
  153. package/lib/native.js +0 -42
  154. package/lib/native.js.map +0 -1
  155. package/lib/platform.d.ts +0 -52
  156. package/lib/platform.js +0 -175
  157. package/lib/platform.js.map +0 -1
  158. package/lib/plugin.d.ts +0 -13
  159. package/lib/plugin.js.map +0 -1
  160. package/lib/project.d.ts +0 -14
  161. package/lib/project.js.map +0 -1
  162. package/lib/runner/cli.d.ts +0 -1
  163. package/lib/runner/cli.js.map +0 -1
  164. package/lib/runner/register.d.ts +0 -6
  165. package/lib/runner/register.js +0 -358
  166. package/lib/runner/register.js.map +0 -1
  167. package/lib/source-build.d.ts +0 -19
  168. package/lib/source-build.js.map +0 -1
  169. package/lib/structures/ITtscBuildOptions.d.ts +0 -14
  170. package/lib/structures/ITtscBuildOptions.js.map +0 -1
  171. package/lib/structures/ITtscBuildResult.d.ts +0 -6
  172. package/lib/structures/ITtscBuildResult.js.map +0 -1
  173. package/lib/structures/ITtscBuildSourcePluginOptions.d.ts +0 -8
  174. package/lib/structures/ITtscBuildSourcePluginOptions.js +0 -3
  175. package/lib/structures/ITtscBuildSourcePluginOptions.js.map +0 -1
  176. package/lib/structures/ITtscCacheKeyInput.d.ts +0 -7
  177. package/lib/structures/ITtscCacheKeyInput.js.map +0 -1
  178. package/lib/structures/ITtscCheckOptions.d.ts +0 -2
  179. package/lib/structures/ITtscCheckOptions.js.map +0 -1
  180. package/lib/structures/ITtscCommonOptions.d.ts +0 -22
  181. package/lib/structures/ITtscCommonOptions.js +0 -3
  182. package/lib/structures/ITtscCommonOptions.js.map +0 -1
  183. package/lib/structures/ITtscLoadPluginsOptions.d.ts +0 -8
  184. package/lib/structures/ITtscLoadPluginsOptions.js +0 -3
  185. package/lib/structures/ITtscLoadPluginsOptions.js.map +0 -1
  186. package/lib/structures/ITtscLoadedNativePlugin.d.ts +0 -7
  187. package/lib/structures/ITtscLoadedNativePlugin.js.map +0 -1
  188. package/lib/structures/ITtscLoadedPlugins.d.ts +0 -11
  189. package/lib/structures/ITtscLoadedPlugins.js +0 -3
  190. package/lib/structures/ITtscLoadedPlugins.js.map +0 -1
  191. package/lib/structures/ITtscNativeBackend.d.ts +0 -10
  192. package/lib/structures/ITtscNativeBackend.js +0 -3
  193. package/lib/structures/ITtscNativeBackend.js.map +0 -1
  194. package/lib/structures/ITtscNativePluginContractVersion.d.ts +0 -1
  195. package/lib/structures/ITtscNativePluginContractVersion.js +0 -3
  196. package/lib/structures/ITtscNativePluginContractVersion.js.map +0 -1
  197. package/lib/structures/ITtscNativePluginShape.d.ts +0 -8
  198. package/lib/structures/ITtscNativePluginShape.js +0 -3
  199. package/lib/structures/ITtscNativePluginShape.js.map +0 -1
  200. package/lib/structures/ITtscNativeRewriteMode.d.ts +0 -1
  201. package/lib/structures/ITtscNativeRewriteMode.js +0 -3
  202. package/lib/structures/ITtscNativeRewriteMode.js.map +0 -1
  203. package/lib/structures/ITtscNativeSource.d.ts +0 -4
  204. package/lib/structures/ITtscNativeSource.js.map +0 -1
  205. package/lib/structures/ITtscParsedProjectConfig.d.ts +0 -9
  206. package/lib/structures/ITtscParsedProjectConfig.js.map +0 -1
  207. package/lib/structures/ITtscPluginFactory.d.ts +0 -4
  208. package/lib/structures/ITtscPluginFactory.js +0 -3
  209. package/lib/structures/ITtscPluginFactory.js.map +0 -1
  210. package/lib/structures/ITtscPluginModule.d.ts +0 -3
  211. package/lib/structures/ITtscPluginModule.js +0 -3
  212. package/lib/structures/ITtscPluginModule.js.map +0 -1
  213. package/lib/structures/ITtscPreparedExecution.d.ts +0 -5
  214. package/lib/structures/ITtscPreparedExecution.js +0 -3
  215. package/lib/structures/ITtscPreparedExecution.js.map +0 -1
  216. package/lib/structures/ITtscProjectLocatorOptions.d.ts +0 -5
  217. package/lib/structures/ITtscProjectLocatorOptions.js.map +0 -1
  218. package/lib/structures/ITtscRegisterOptions.d.ts +0 -6
  219. package/lib/structures/ITtscRegisterOptions.js +0 -3
  220. package/lib/structures/ITtscRegisterOptions.js.map +0 -1
  221. package/lib/structures/ITtscResolveGoBinaryOptions.d.ts +0 -7
  222. package/lib/structures/ITtscResolveGoBinaryOptions.js +0 -3
  223. package/lib/structures/ITtscResolveGoBinaryOptions.js.map +0 -1
  224. package/lib/structures/ITtscResolveOptions.d.ts +0 -20
  225. package/lib/structures/ITtscResolveOptions.js +0 -3
  226. package/lib/structures/ITtscResolveOptions.js.map +0 -1
  227. package/lib/structures/ITtscResolvedTsgo.d.ts +0 -8
  228. package/lib/structures/ITtscResolvedTsgo.js +0 -3
  229. package/lib/structures/ITtscResolvedTsgo.js.map +0 -1
  230. package/lib/structures/ITtscTransformOptions.d.ts +0 -12
  231. package/lib/structures/ITtscTransformOptions.js +0 -3
  232. package/lib/structures/ITtscTransformOptions.js.map +0 -1
  233. package/lib/structures/ITtscTsgoResolveOptions.d.ts +0 -14
  234. package/lib/structures/ITtscTsgoResolveOptions.js +0 -3
  235. package/lib/structures/ITtscTsgoResolveOptions.js.map +0 -1
  236. package/lib/tsgo.d.ts +0 -6
  237. package/lib/tsgo.js.map +0 -1
  238. package/src/api.ts +0 -872
  239. package/src/native.ts +0 -64
  240. package/src/platform.ts +0 -151
  241. package/src/plugin.ts +0 -253
  242. package/src/runner/register.ts +0 -406
  243. package/src/structures/ITtscBuildOptions.ts +0 -19
  244. package/src/structures/ITtscBuildResult.ts +0 -6
  245. package/src/structures/ITtscBuildSourcePluginOptions.ts +0 -9
  246. package/src/structures/ITtscCacheKeyInput.ts +0 -7
  247. package/src/structures/ITtscCheckOptions.ts +0 -3
  248. package/src/structures/ITtscCommonOptions.ts +0 -23
  249. package/src/structures/ITtscLoadPluginsOptions.ts +0 -9
  250. package/src/structures/ITtscLoadedNativePlugin.ts +0 -8
  251. package/src/structures/ITtscLoadedPlugins.ts +0 -12
  252. package/src/structures/ITtscNativeBackend.ts +0 -11
  253. package/src/structures/ITtscNativePluginContractVersion.ts +0 -1
  254. package/src/structures/ITtscNativePluginShape.ts +0 -9
  255. package/src/structures/ITtscNativeRewriteMode.ts +0 -1
  256. package/src/structures/ITtscNativeSource.ts +0 -4
  257. package/src/structures/ITtscParsedProjectConfig.ts +0 -10
  258. package/src/structures/ITtscPluginFactory.ts +0 -7
  259. package/src/structures/ITtscPluginModule.ts +0 -4
  260. package/src/structures/ITtscPreparedExecution.ts +0 -5
  261. package/src/structures/ITtscProjectLocatorOptions.ts +0 -5
  262. package/src/structures/ITtscRegisterOptions.ts +0 -7
  263. package/src/structures/ITtscResolveGoBinaryOptions.ts +0 -7
  264. package/src/structures/ITtscResolveOptions.ts +0 -20
  265. package/src/structures/ITtscResolvedTsgo.ts +0 -8
  266. package/src/structures/ITtscTransformOptions.ts +0 -13
  267. package/src/structures/ITtscTsgoResolveOptions.ts +0 -14
  268. package/test/native.test.ts +0 -103
  269. /package/lib/structures/{ITtscLoadedNativePlugin.js → internal/ITtscLoadedNativePlugin.js} +0 -0
  270. /package/lib/structures/{ITtscParsedProjectConfig.js → internal/ITtscParsedProjectConfig.js} +0 -0
  271. /package/lib/structures/{ITtscProjectLocatorOptions.js → internal/ITtscProjectLocatorOptions.js} +0 -0
@@ -39,7 +39,7 @@ func run(args []string) int {
39
39
  return 0
40
40
  case "demo":
41
41
  return runDemo(args[1:])
42
- case "build", "check", "transform":
42
+ case "build", "check":
43
43
  fmt.Fprintf(
44
44
  stderr,
45
45
  "ttsc platform helper: %s is provided by the JavaScript ttsc CLI using the consuming project's @typescript/native-preview, or by a plugin-selected native sidecar.\n",
@@ -0,0 +1,134 @@
1
+ package main
2
+
3
+ import (
4
+ "encoding/json"
5
+ "flag"
6
+ "fmt"
7
+ "os"
8
+ "path/filepath"
9
+ "strings"
10
+
11
+ shimcompiler "github.com/microsoft/typescript-go/shim/compiler"
12
+
13
+ "github.com/samchon/ttsc/packages/ttsc/driver"
14
+ )
15
+
16
+ type apiCompileResult struct {
17
+ Diagnostics []apiCompileDiagnostic `json:"diagnostics,omitempty"`
18
+ Output map[string]string `json:"output"`
19
+ }
20
+
21
+ type apiCompileDiagnostic struct {
22
+ File *string `json:"file"`
23
+ Category string `json:"category"`
24
+ Code int32 `json:"code"`
25
+ Start *int `json:"start,omitempty"`
26
+ Length *int `json:"length,omitempty"`
27
+ Line int `json:"line,omitempty"`
28
+ Character int `json:"character,omitempty"`
29
+ MessageText string `json:"messageText"`
30
+ }
31
+
32
+ func runAPICompile(args []string) int {
33
+ fs := flag.NewFlagSet("api-compile", flag.ContinueOnError)
34
+ fs.SetOutput(stderr)
35
+ tsconfigPath := fs.String("tsconfig", "tsconfig.json", "path to tsconfig.json")
36
+ cwdOverride := fs.String("cwd", "", "override the working directory")
37
+ if err := fs.Parse(args); err != nil {
38
+ return 2
39
+ }
40
+
41
+ cwd, ok := resolveBuildCwd(*cwdOverride)
42
+ if !ok {
43
+ return 2
44
+ }
45
+
46
+ prog, diags, err := driver.LoadProgram(cwd, *tsconfigPath, driver.LoadProgramOptions{
47
+ ForceEmit: true,
48
+ })
49
+ if err != nil {
50
+ fmt.Fprintf(stderr, "ttsc api-compile: %v\n", err)
51
+ return 2
52
+ }
53
+ if prog != nil {
54
+ defer prog.Close()
55
+ diags = append(diags, prog.Diagnostics()...)
56
+ }
57
+
58
+ output := map[string]string{}
59
+ if prog != nil {
60
+ rewrites := driver.NewRewriteSet()
61
+ writeFile := shimcompiler.WriteFile(
62
+ func(fileName, text string, _ *shimcompiler.WriteFileData) error {
63
+ output[apiOutputKey(cwd, fileName)] = text
64
+ return nil
65
+ },
66
+ )
67
+ _, emitDiags, err := prog.EmitAll(rewrites, writeFile)
68
+ if err != nil {
69
+ fmt.Fprintf(stderr, "ttsc api-compile: emit failed: %v\n", err)
70
+ return 3
71
+ }
72
+ diags = append(diags, emitDiags...)
73
+ }
74
+
75
+ result := apiCompileResult{
76
+ Diagnostics: make([]apiCompileDiagnostic, 0, len(diags)),
77
+ Output: output,
78
+ }
79
+ for _, diag := range diags {
80
+ result.Diagnostics = append(result.Diagnostics, toAPICompileDiagnostic(diag))
81
+ }
82
+
83
+ data, err := json.Marshal(result)
84
+ if err != nil {
85
+ fmt.Fprintf(stderr, "ttsc api-compile: result marshal failed: %v\n", err)
86
+ return 3
87
+ }
88
+ fmt.Fprintln(stdout, string(data))
89
+ if driver.CountErrors(diags) > 0 {
90
+ return 2
91
+ }
92
+ return 0
93
+ }
94
+
95
+ func resolveBuildCwd(cwdOverride string) (string, bool) {
96
+ if cwdOverride != "" {
97
+ return cwdOverride, true
98
+ }
99
+ cwd, err := os.Getwd()
100
+ if err != nil {
101
+ fmt.Fprintf(stderr, "ttsc: could not get working directory: %v\n", err)
102
+ return "", false
103
+ }
104
+ return cwd, true
105
+ }
106
+
107
+ func toAPICompileDiagnostic(diag driver.Diagnostic) apiCompileDiagnostic {
108
+ var file *string
109
+ if diag.File != "" {
110
+ value := diag.File
111
+ file = &value
112
+ }
113
+ category := "error"
114
+ if diag.Severity == driver.SeverityWarning {
115
+ category = "warning"
116
+ }
117
+ return apiCompileDiagnostic{
118
+ File: file,
119
+ Category: category,
120
+ Code: diag.Code,
121
+ Start: diag.Start,
122
+ Length: diag.Length,
123
+ Line: diag.Line,
124
+ Character: diag.Column,
125
+ MessageText: diag.Message,
126
+ }
127
+ }
128
+
129
+ func apiOutputKey(cwd, fileName string) string {
130
+ if rel, err := filepath.Rel(cwd, fileName); err == nil && !strings.HasPrefix(rel, "..") {
131
+ return filepath.ToSlash(rel)
132
+ }
133
+ return filepath.ToSlash(fileName)
134
+ }
@@ -0,0 +1,64 @@
1
+ package main
2
+
3
+ import (
4
+ "encoding/json"
5
+ "flag"
6
+ "fmt"
7
+
8
+ "github.com/samchon/ttsc/packages/ttsc/driver"
9
+ )
10
+
11
+ type apiTransformResult struct {
12
+ Diagnostics []apiCompileDiagnostic `json:"diagnostics,omitempty"`
13
+ TypeScript map[string]string `json:"typescript"`
14
+ }
15
+
16
+ func runAPITransform(args []string) int {
17
+ fs := flag.NewFlagSet("api-transform", flag.ContinueOnError)
18
+ fs.SetOutput(stderr)
19
+ tsconfigPath := fs.String("tsconfig", "tsconfig.json", "path to tsconfig.json")
20
+ cwdOverride := fs.String("cwd", "", "override the working directory")
21
+ if err := fs.Parse(args); err != nil {
22
+ return 2
23
+ }
24
+
25
+ cwd, ok := resolveBuildCwd(*cwdOverride)
26
+ if !ok {
27
+ return 2
28
+ }
29
+
30
+ prog, diags, err := driver.LoadProgram(cwd, *tsconfigPath, driver.LoadProgramOptions{
31
+ ForceNoEmit: true,
32
+ })
33
+ if err != nil {
34
+ fmt.Fprintf(stderr, "ttsc api-transform: %v\n", err)
35
+ return 2
36
+ }
37
+ typescript := map[string]string{}
38
+ if prog != nil {
39
+ defer prog.Close()
40
+ for _, file := range prog.SourceFiles() {
41
+ typescript[apiOutputKey(cwd, file.FileName())] = file.Text()
42
+ }
43
+ diags = append(diags, prog.Diagnostics()...)
44
+ }
45
+
46
+ result := apiTransformResult{
47
+ Diagnostics: make([]apiCompileDiagnostic, 0, len(diags)),
48
+ TypeScript: typescript,
49
+ }
50
+ for _, diag := range diags {
51
+ result.Diagnostics = append(result.Diagnostics, toAPICompileDiagnostic(diag))
52
+ }
53
+
54
+ data, err := json.Marshal(result)
55
+ if err != nil {
56
+ fmt.Fprintf(stderr, "ttsc api-transform: result marshal failed: %v\n", err)
57
+ return 3
58
+ }
59
+ fmt.Fprintln(stdout, string(data))
60
+ if driver.CountErrors(diags) > 0 {
61
+ return 2
62
+ }
63
+ return 0
64
+ }
package/cmd/ttsc/build.go CHANGED
@@ -28,7 +28,6 @@ func runBuild(args []string) int {
28
28
  noEmit := fs.Bool("noEmit", false, "force analysis-only run with no file writes")
29
29
  outDir := fs.String("outDir", "", "override compilerOptions.outDir for this build")
30
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
31
  if err := fs.Parse(args); err != nil {
33
32
  return 2
34
33
  }
@@ -71,13 +70,8 @@ func runBuild(args []string) int {
71
70
 
72
71
  rewrites := driver.NewRewriteSet()
73
72
  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
73
  if !*quiet {
80
- fmt.Fprintf(stdout, "// ttsc: tsconfig=%s cwd=%s sites=%d emit=%v rewrite=%s\n", *tsconfigPath, cwd, 0, shouldEmit, *rewriteMode)
74
+ fmt.Fprintf(stdout, "// ttsc: tsconfig=%s cwd=%s sites=%d emit=%v\n", *tsconfigPath, cwd, 0, shouldEmit)
81
75
  }
82
76
 
83
77
  if shouldEmit {
package/cmd/ttsc/main.go CHANGED
@@ -4,8 +4,8 @@
4
4
  // - Report version and platform (`ttsc --version`).
5
5
  // - Exercise a native rewrite backend end-to-end (`ttsc demo --type=string`)
6
6
  // so smoke tests can verify the Go binary really runs.
7
- // - Host the native project build, check, and single-file transform paths used
8
- // by plugin-selected sidecars and smoke tests.
7
+ // - Host the native project build and check paths used by plugin-selected
8
+ // sidecars and smoke tests.
9
9
  //
10
10
  // Everything below is deliberately dependency-free so that the standalone binary
11
11
  // stays small and its behavior is trivial to audit.
@@ -54,15 +54,14 @@ func run(args []string) int {
54
54
  return runDemo(args[1:])
55
55
  case "build":
56
56
  return runBuild(args[1:])
57
+ case "api-compile":
58
+ return runAPICompile(args[1:])
59
+ case "api-transform":
60
+ return runAPITransform(args[1:])
57
61
  case "check":
58
62
  // `ttsc check` runs the analyze pipeline without emitting JS — useful
59
63
  // in CI and pre-commit hooks that only need schema validation.
60
64
  return runBuild(append([]string{"--noEmit"}, args[1:]...))
61
- case "transform":
62
- // Single-file transform for bundler plugin integration (unplugin,
63
- // vite, esbuild, webpack, …). Emits only the requested file's JS to
64
- // stdout or a chosen path — no project-wide write.
65
- return runTransform(args[1:])
66
65
  case "-p", "--project":
67
66
  if len(args) < 2 {
68
67
  fmt.Fprintln(stderr, "ttsc: -p/--project requires a path argument")
@@ -135,13 +134,11 @@ Usage:
135
134
  ttsc -p tsconfig.json
136
135
  ttsc --watch
137
136
  ttsc --noEmit
138
- ttsc transform --file=src/main.ts
139
137
 
140
138
  Project build:
141
139
  ttsc compiles the current tsconfig.json, matching the tsc/tsgo shape.
142
140
  build Compatibility alias for the same project build lane.
143
141
  check Compatibility alias for --noEmit validation.
144
- transform Emit a single file's rewritten JS (bundler plugin hook).
145
142
  demo Run a native backend smoke pipeline with synthetic input.
146
143
  version Print version, build info, and platform.
147
144
  help Show this help.
@@ -153,15 +150,8 @@ Build options:
153
150
  --noEmit Force analysis-only run even when tsconfig would emit.
154
151
  --quiet Suppress the per-call summary banner (default).
155
152
  --verbose Print the per-call summary banner and emitted file list.
156
- --rewrite-mode=M Native rewrite backend id.
157
153
  --manifest=FILE Write emitted file paths as JSON to FILE after build --emit.
158
154
 
159
- Transform options:
160
- --file=PATH Absolute or cwd-relative path of the .ts file to transform.
161
- --tsconfig=FILE tsconfig.json owning --file (default: tsconfig.json).
162
- --out=PATH Write output JS to PATH. Default: stdout.
163
- --rewrite-mode=M Native rewrite backend id.
164
-
165
155
  Demo options:
166
156
  --type=T Atomic TypeScript type to simulate. One of:
167
157
  string, number, boolean, bigint, any (default: string).
@@ -171,13 +161,9 @@ Examples:
171
161
  ttsc
172
162
  ttsc -p ./tsconfig.json
173
163
  ttsc --noEmit
174
- ttsc transform --file=src/main.ts
175
164
  ttsc demo --type=number
176
165
 
177
166
  Integration guide (bundlers):
178
- - vite / webpack / rollup / esbuild: shell out to "ttsc transform" per file,
179
- forward stdout as the bundler transform result. A bundler adapter can wrap
180
- this command without depending on the Go internals.
181
167
  - Next.js / Nuxt / Bun: "ttsc" in your pipeline replaces tsc and
182
168
  the rewritten .js feeds the runtime directly.
183
169
  - Monorepo / pnpm workspace: share one ttsc binary via a root script;
package/driver/program.go CHANGED
@@ -30,6 +30,9 @@ type Diagnostic struct {
30
30
  File string
31
31
  Line int
32
32
  Column int
33
+ Code int32
34
+ Start *int
35
+ Length *int
33
36
  Message string
34
37
  Severity Severity
35
38
  raw *ast.Diagnostic
@@ -72,6 +75,7 @@ func NewLintDiagnostic(
72
75
  }
73
76
  lint := shimdiagnosticwriter.NewLintDiagnostic(file, pos, end, code, cat, message)
74
77
  d := Diagnostic{
78
+ Code: code,
75
79
  Message: message,
76
80
  Severity: severity,
77
81
  lint: lint,
@@ -79,6 +83,9 @@ func NewLintDiagnostic(
79
83
  if file != nil {
80
84
  d.File = file.FileName()
81
85
  if pos >= 0 {
86
+ length := end - pos
87
+ d.Start = &pos
88
+ d.Length = &length
82
89
  line, col := shimscanner.GetECMALineAndByteOffsetOfPosition(file, pos)
83
90
  d.Line = line + 1
84
91
  d.Column = col + 1
@@ -187,8 +194,8 @@ type Program struct {
187
194
  }
188
195
 
189
196
  // LoadProgramOptions controls tsconfig overrides applied before tsgo creates
190
- // the program. `ForceEmit` is used by `ttsc --emit` and `ttsc transform`
191
- // so runtime compilation still works when the project defaults to `noEmit`.
197
+ // the program. `ForceEmit` is used by `ttsc --emit` and runtime compilation
198
+ // so execution still works when the project defaults to `noEmit`.
192
199
  type LoadProgramOptions struct {
193
200
  ForceEmit bool
194
201
  ForceNoEmit bool
@@ -388,10 +395,13 @@ func convertDiagnostics(in []*ast.Diagnostic) []Diagnostic {
388
395
  if d == nil {
389
396
  continue
390
397
  }
391
- diag := Diagnostic{Message: d.String(), raw: d}
398
+ diag := Diagnostic{Code: d.Code(), Message: d.String(), raw: d}
392
399
  if file := d.File(); file != nil {
393
400
  diag.File = file.FileName()
394
401
  if pos := d.Pos(); pos >= 0 {
402
+ length := d.Len()
403
+ diag.Start = &pos
404
+ diag.Length = &length
395
405
  line, col := shimscanner.GetECMALineAndByteOffsetOfPosition(file, pos)
396
406
  diag.Line = line + 1
397
407
  diag.Column = col + 1
@@ -0,0 +1,96 @@
1
+ import type { ITtscCompilerContext } from "./structures/ITtscCompilerContext";
2
+ import type { ITtscCompilerResult } from "./structures/ITtscCompilerResult";
3
+ import type { ITtscCompilerTransformation } from "./structures/ITtscCompilerTransformation";
4
+ /**
5
+ * Programmatic compiler host for the `ttsc` TypeScript-Go pipeline.
6
+ *
7
+ * `TtscCompiler` is the root JavaScript API exported by the `ttsc` package.
8
+ * It represents one resolved project context: a working directory, an optional
9
+ * project config path, an optional native toolchain override, an environment,
10
+ * a cache root, and a plugin list. Those values are captured by the
11
+ * constructor and are intentionally not replaceable per method call.
12
+ *
13
+ * The class exposes only the operations that make sense for an embedded
14
+ * compiler host:
15
+ *
16
+ * - {@link TtscCompiler.prepare}: build configured Go source plugins into the
17
+ * cache before a later compile.
18
+ * - {@link TtscCompiler.clean}: remove the cache owned by this compiler
19
+ * context.
20
+ * - {@link TtscCompiler.compile}: compile the configured project and return a
21
+ * structured result instead of terminal text.
22
+ * - {@link TtscCompiler.transform}: transform the configured project and
23
+ * return an embed-style transformation result.
24
+ */
25
+ export declare class TtscCompiler {
26
+ private readonly context;
27
+ constructor(context?: ITtscCompilerContext);
28
+ /**
29
+ * Build every configured source plugin into the instance cache.
30
+ *
31
+ * This method loads the project plugin descriptors, resolves their
32
+ * {@link ITtscPlugin.source} paths, and compiles those Go command packages
33
+ * into the ttsc cache. It is useful when a host application wants to pay the
34
+ * lazy build cost before the first compile call.
35
+ *
36
+ * `prepare()` is not a project check. It does not create a TypeScript-Go
37
+ * Program, does not run diagnostics, and does not emit output files.
38
+ *
39
+ * @returns Compiled native plugin binary paths.
40
+ */
41
+ prepare(): string[];
42
+ /**
43
+ * Remove compiled cache artifacts for this compiler instance.
44
+ *
45
+ * When the constructor received `cacheDir`, this method removes exactly that
46
+ * directory. Otherwise it removes the default ttsc cache locations for the
47
+ * resolved project root, plus the `TTSC_CACHE_DIR/plugins` cache when that
48
+ * environment variable is active.
49
+ *
50
+ * The cache target comes from the constructor context. Create another
51
+ * `TtscCompiler` instance to clean another project or another cache root.
52
+ *
53
+ * @returns Cache directories that were removed.
54
+ */
55
+ clean(): string[];
56
+ /**
57
+ * Compile the configured project.
58
+ *
59
+ * The public API does not write emitted files into the caller's project tree.
60
+ * For projects without plugins, ttsc uses its native TypeScript-Go host's
61
+ * `WriteFile` callback to capture output in memory. For projects with
62
+ * native plugins, ttsc runs the plugin pipeline against a temporary output
63
+ * directory, reads the generated text artifacts, and removes the temporary
64
+ * directory before returning.
65
+ *
66
+ * The result uses an `embed-typescript`-style discriminated union:
67
+ * `success` for clean compiles, `failure` for normal compiler diagnostics,
68
+ * and `exception` for host setup or process failures.
69
+ *
70
+ * @returns Structured compilation result containing diagnostics or output.
71
+ */
72
+ compile(): ITtscCompilerResult;
73
+ /**
74
+ * Transform the configured project and return TypeScript text by file path.
75
+ *
76
+ * This is the source-to-source API for plugin authors. It must not return
77
+ * JavaScript emit, declaration files, or source maps; those artifacts belong
78
+ * to {@link TtscCompiler.compile}. A transform sidecar is expected to write
79
+ * JSON shaped as `{ "typescript": { "src/file.ts": "..." } }` to stdout.
80
+ * When no transform sidecar is configured, ttsc returns the TypeScript files
81
+ * loaded by the TypeScript-Go Program together with normal diagnostics.
82
+ *
83
+ * The returned shape mirrors `embed-typescript`'s transformation API:
84
+ * `success` and `failure` carry a `typescript` map, while unexpected host
85
+ * errors return `exception`.
86
+ *
87
+ * @returns Transformation result containing TypeScript text or diagnostics.
88
+ */
89
+ transform(): ITtscCompilerTransformation;
90
+ private compilerContext;
91
+ private resolveProjectExecution;
92
+ private resolveCleanProjectRoot;
93
+ private resolveCwd;
94
+ private resolveCacheDir;
95
+ private resolvePluginCacheDir;
96
+ }