ttsc 0.6.0-dev.20250501-2 → 0.7.0

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 (261) hide show
  1. package/cmd/ttsc/api_compile.go +134 -0
  2. package/cmd/ttsc/build.go +1 -7
  3. package/cmd/ttsc/main.go +2 -2
  4. package/cmd/ttsc/transform.go +0 -6
  5. package/driver/program.go +11 -1
  6. package/lib/TtscCompiler.d.ts +76 -0
  7. package/lib/TtscCompiler.js +245 -0
  8. package/lib/TtscCompiler.js.map +1 -0
  9. package/lib/compiler/internal/buildNativeCompiler.d.ts +6 -0
  10. package/lib/compiler/internal/buildNativeCompiler.js +72 -0
  11. package/lib/compiler/internal/buildNativeCompiler.js.map +1 -0
  12. package/lib/compiler/internal/compileProjectInMemory.d.ts +7 -0
  13. package/lib/compiler/internal/compileProjectInMemory.js +176 -0
  14. package/lib/compiler/internal/compileProjectInMemory.js.map +1 -0
  15. package/lib/compiler/internal/project/readProjectConfig.d.ts +4 -0
  16. package/lib/{project.js → compiler/internal/project/readProjectConfig.js} +12 -82
  17. package/lib/compiler/internal/project/readProjectConfig.js.map +1 -0
  18. package/lib/compiler/internal/project/resolveProjectConfig.d.ts +3 -0
  19. package/lib/compiler/internal/project/resolveProjectConfig.js +94 -0
  20. package/lib/compiler/internal/project/resolveProjectConfig.js.map +1 -0
  21. package/lib/compiler/internal/resolveBinary.d.ts +4 -0
  22. package/lib/compiler/internal/resolveBinary.js +65 -0
  23. package/lib/compiler/internal/resolveBinary.js.map +1 -0
  24. package/lib/compiler/internal/resolveEmittedJavaScript.d.ts +7 -0
  25. package/lib/compiler/internal/resolveEmittedJavaScript.js +118 -0
  26. package/lib/compiler/internal/resolveEmittedJavaScript.js.map +1 -0
  27. package/lib/compiler/internal/resolveTsgo.d.ts +20 -0
  28. package/lib/{tsgo.js → compiler/internal/resolveTsgo.js} +5 -10
  29. package/lib/compiler/internal/resolveTsgo.js.map +1 -0
  30. package/lib/compiler/internal/runBuild.d.ts +10 -0
  31. package/lib/compiler/internal/runBuild.js +480 -0
  32. package/lib/compiler/internal/runBuild.js.map +1 -0
  33. package/lib/compiler/internal/runTransform.d.ts +3 -0
  34. package/lib/compiler/internal/runTransform.js +100 -0
  35. package/lib/compiler/internal/runTransform.js.map +1 -0
  36. package/lib/index.d.ts +6 -15
  37. package/lib/index.js +6 -15
  38. package/lib/index.js.map +1 -1
  39. package/lib/launcher/internal/getCompilerVersionText.d.ts +3 -0
  40. package/lib/launcher/internal/getCompilerVersionText.js +71 -0
  41. package/lib/launcher/internal/getCompilerVersionText.js.map +1 -0
  42. package/lib/launcher/internal/prepareExecution.d.ts +10 -0
  43. package/lib/launcher/internal/prepareExecution.js +120 -0
  44. package/lib/launcher/internal/prepareExecution.js.map +1 -0
  45. package/lib/launcher/internal/runTtsc.d.ts +1 -0
  46. package/lib/{cli.js → launcher/internal/runTtsc.js} +48 -47
  47. package/lib/launcher/internal/runTtsc.js.map +1 -0
  48. package/lib/launcher/internal/runTtsx.d.ts +1 -0
  49. package/lib/{runner/cli.js → launcher/internal/runTtsx.js} +13 -35
  50. package/lib/launcher/internal/runTtsx.js.map +1 -0
  51. package/lib/launcher/ttsc.js +2 -2
  52. package/lib/launcher/ttsc.js.map +1 -1
  53. package/lib/launcher/ttsx.js +2 -2
  54. package/lib/launcher/ttsx.js.map +1 -1
  55. package/lib/plugin/internal/buildSourcePlugin.d.ts +12 -0
  56. package/lib/{source-build.js → plugin/internal/buildSourcePlugin.js} +77 -84
  57. package/lib/plugin/internal/buildSourcePlugin.js.map +1 -0
  58. package/lib/plugin/internal/loadProjectPlugins.d.ts +14 -0
  59. package/lib/{plugin.js → plugin/internal/loadProjectPlugins.js} +38 -76
  60. package/lib/plugin/internal/loadProjectPlugins.js.map +1 -0
  61. package/lib/structures/ITtscCompilerContext.d.ts +78 -0
  62. package/lib/structures/ITtscCompilerContext.js +3 -0
  63. package/lib/structures/ITtscCompilerContext.js.map +1 -0
  64. package/lib/structures/ITtscCompilerDiagnostic.d.ts +83 -0
  65. package/lib/structures/ITtscCompilerDiagnostic.js +3 -0
  66. package/lib/structures/ITtscCompilerDiagnostic.js.map +1 -0
  67. package/lib/structures/ITtscCompilerResult.d.ts +83 -0
  68. package/lib/structures/{ITtscCacheKeyInput.js → ITtscCompilerResult.js} +1 -1
  69. package/lib/structures/ITtscCompilerResult.js.map +1 -0
  70. package/lib/structures/ITtscPlugin.d.ts +52 -7
  71. package/lib/structures/ITtscPluginFactoryContext.d.ts +47 -0
  72. package/lib/structures/ITtscProjectPluginConfig.d.ts +41 -0
  73. package/lib/structures/TtscPluginStage.d.ts +15 -0
  74. package/lib/structures/{ITtscBuildResult.js → TtscPluginStage.js} +1 -1
  75. package/lib/structures/TtscPluginStage.js.map +1 -0
  76. package/lib/structures/index.d.ts +7 -0
  77. package/lib/structures/index.js +24 -0
  78. package/lib/structures/index.js.map +1 -0
  79. package/lib/structures/internal/ITtscLoadedNativePlugin.d.ts +13 -0
  80. package/lib/structures/internal/ITtscLoadedNativePlugin.js.map +1 -0
  81. package/lib/structures/internal/ITtscParsedProjectConfig.d.ts +15 -0
  82. package/lib/structures/internal/ITtscParsedProjectConfig.js.map +1 -0
  83. package/lib/structures/internal/ITtscProjectLocatorOptions.d.ts +9 -0
  84. package/lib/structures/internal/ITtscProjectLocatorOptions.js.map +1 -0
  85. package/lib/structures/internal/TtscBuildOptions.d.ts +18 -0
  86. package/lib/structures/{ITtscBuildOptions.js → internal/TtscBuildOptions.js} +1 -1
  87. package/lib/structures/internal/TtscBuildOptions.js.map +1 -0
  88. package/lib/structures/internal/TtscBuildResult.d.ts +14 -0
  89. package/lib/structures/{ITtscCheckOptions.js → internal/TtscBuildResult.js} +1 -1
  90. package/lib/structures/internal/TtscBuildResult.js.map +1 -0
  91. package/lib/structures/internal/TtscCommonOptions.d.ts +27 -0
  92. package/lib/structures/{ITtscNativeSource.js → internal/TtscCommonOptions.js} +1 -1
  93. package/lib/structures/internal/TtscCommonOptions.js.map +1 -0
  94. package/lib/structures/internal/TtscTransformOptions.d.ts +14 -0
  95. package/lib/structures/internal/TtscTransformOptions.js +3 -0
  96. package/lib/structures/internal/TtscTransformOptions.js.map +1 -0
  97. package/package.json +9 -9
  98. package/src/TtscCompiler.ts +241 -0
  99. package/src/compiler/internal/buildNativeCompiler.ts +43 -0
  100. package/src/compiler/internal/compileProjectInMemory.ts +189 -0
  101. package/src/{project.ts → compiler/internal/project/readProjectConfig.ts} +36 -111
  102. package/src/compiler/internal/project/resolveProjectConfig.ts +67 -0
  103. package/src/compiler/internal/resolveBinary.ts +41 -0
  104. package/src/compiler/internal/resolveEmittedJavaScript.ts +102 -0
  105. package/src/{tsgo.ts → compiler/internal/resolveTsgo.ts} +20 -23
  106. package/src/compiler/internal/runBuild.ts +644 -0
  107. package/src/compiler/internal/runTransform.ts +69 -0
  108. package/src/index.ts +6 -15
  109. package/src/launcher/internal/getCompilerVersionText.ts +44 -0
  110. package/src/launcher/internal/prepareExecution.ts +115 -0
  111. package/src/{cli.ts → launcher/internal/runTtsc.ts} +61 -70
  112. package/src/{runner/cli.ts → launcher/internal/runTtsx.ts} +21 -49
  113. package/src/launcher/ttsc.ts +2 -2
  114. package/src/launcher/ttsx.ts +2 -2
  115. package/src/{source-build.ts → plugin/internal/buildSourcePlugin.ts} +121 -115
  116. package/src/plugin/internal/loadProjectPlugins.ts +214 -0
  117. package/src/structures/ITtscCompilerContext.ts +84 -0
  118. package/src/structures/ITtscCompilerDiagnostic.ts +91 -0
  119. package/src/structures/ITtscCompilerResult.ts +94 -0
  120. package/src/structures/ITtscPlugin.ts +54 -7
  121. package/src/structures/ITtscPluginFactoryContext.ts +51 -0
  122. package/src/structures/ITtscProjectPluginConfig.ts +43 -0
  123. package/src/structures/TtscPluginStage.ts +15 -0
  124. package/src/structures/index.ts +7 -0
  125. package/src/structures/internal/ITtscLoadedNativePlugin.ts +14 -0
  126. package/src/structures/internal/ITtscParsedProjectConfig.ts +16 -0
  127. package/src/structures/internal/ITtscProjectLocatorOptions.ts +9 -0
  128. package/src/structures/internal/TtscBuildOptions.ts +19 -0
  129. package/src/structures/internal/TtscBuildResult.ts +15 -0
  130. package/src/structures/internal/TtscCommonOptions.ts +28 -0
  131. package/src/structures/internal/TtscTransformOptions.ts +15 -0
  132. package/test/compiler.test.ts +234 -0
  133. package/test/platform.test.ts +1 -45
  134. package/test/project.test.ts +3 -1
  135. package/test/source-build.test.ts +33 -220
  136. package/test/tsgo.test.ts +1 -8
  137. package/lib/api.d.ts +0 -40
  138. package/lib/api.js +0 -680
  139. package/lib/api.js.map +0 -1
  140. package/lib/cli.d.ts +0 -1
  141. package/lib/cli.js.map +0 -1
  142. package/lib/native.d.ts +0 -8
  143. package/lib/native.js +0 -42
  144. package/lib/native.js.map +0 -1
  145. package/lib/platform.d.ts +0 -52
  146. package/lib/platform.js +0 -175
  147. package/lib/platform.js.map +0 -1
  148. package/lib/plugin.d.ts +0 -13
  149. package/lib/plugin.js.map +0 -1
  150. package/lib/project.d.ts +0 -14
  151. package/lib/project.js.map +0 -1
  152. package/lib/runner/cli.d.ts +0 -1
  153. package/lib/runner/cli.js.map +0 -1
  154. package/lib/runner/register.d.ts +0 -6
  155. package/lib/runner/register.js +0 -358
  156. package/lib/runner/register.js.map +0 -1
  157. package/lib/source-build.d.ts +0 -19
  158. package/lib/source-build.js.map +0 -1
  159. package/lib/structures/ITtscBuildOptions.d.ts +0 -14
  160. package/lib/structures/ITtscBuildOptions.js.map +0 -1
  161. package/lib/structures/ITtscBuildResult.d.ts +0 -6
  162. package/lib/structures/ITtscBuildResult.js.map +0 -1
  163. package/lib/structures/ITtscBuildSourcePluginOptions.d.ts +0 -8
  164. package/lib/structures/ITtscBuildSourcePluginOptions.js +0 -3
  165. package/lib/structures/ITtscBuildSourcePluginOptions.js.map +0 -1
  166. package/lib/structures/ITtscCacheKeyInput.d.ts +0 -7
  167. package/lib/structures/ITtscCacheKeyInput.js.map +0 -1
  168. package/lib/structures/ITtscCheckOptions.d.ts +0 -2
  169. package/lib/structures/ITtscCheckOptions.js.map +0 -1
  170. package/lib/structures/ITtscCommonOptions.d.ts +0 -22
  171. package/lib/structures/ITtscCommonOptions.js +0 -3
  172. package/lib/structures/ITtscCommonOptions.js.map +0 -1
  173. package/lib/structures/ITtscLoadPluginsOptions.d.ts +0 -8
  174. package/lib/structures/ITtscLoadPluginsOptions.js +0 -3
  175. package/lib/structures/ITtscLoadPluginsOptions.js.map +0 -1
  176. package/lib/structures/ITtscLoadedNativePlugin.d.ts +0 -7
  177. package/lib/structures/ITtscLoadedNativePlugin.js.map +0 -1
  178. package/lib/structures/ITtscLoadedPlugins.d.ts +0 -11
  179. package/lib/structures/ITtscLoadedPlugins.js +0 -3
  180. package/lib/structures/ITtscLoadedPlugins.js.map +0 -1
  181. package/lib/structures/ITtscNativeBackend.d.ts +0 -10
  182. package/lib/structures/ITtscNativeBackend.js +0 -3
  183. package/lib/structures/ITtscNativeBackend.js.map +0 -1
  184. package/lib/structures/ITtscNativePluginContractVersion.d.ts +0 -1
  185. package/lib/structures/ITtscNativePluginContractVersion.js +0 -3
  186. package/lib/structures/ITtscNativePluginContractVersion.js.map +0 -1
  187. package/lib/structures/ITtscNativePluginShape.d.ts +0 -8
  188. package/lib/structures/ITtscNativePluginShape.js +0 -3
  189. package/lib/structures/ITtscNativePluginShape.js.map +0 -1
  190. package/lib/structures/ITtscNativeRewriteMode.d.ts +0 -1
  191. package/lib/structures/ITtscNativeRewriteMode.js +0 -3
  192. package/lib/structures/ITtscNativeRewriteMode.js.map +0 -1
  193. package/lib/structures/ITtscNativeSource.d.ts +0 -4
  194. package/lib/structures/ITtscNativeSource.js.map +0 -1
  195. package/lib/structures/ITtscParsedProjectConfig.d.ts +0 -9
  196. package/lib/structures/ITtscParsedProjectConfig.js.map +0 -1
  197. package/lib/structures/ITtscPluginFactory.d.ts +0 -4
  198. package/lib/structures/ITtscPluginFactory.js +0 -3
  199. package/lib/structures/ITtscPluginFactory.js.map +0 -1
  200. package/lib/structures/ITtscPluginModule.d.ts +0 -3
  201. package/lib/structures/ITtscPluginModule.js +0 -3
  202. package/lib/structures/ITtscPluginModule.js.map +0 -1
  203. package/lib/structures/ITtscPreparedExecution.d.ts +0 -5
  204. package/lib/structures/ITtscPreparedExecution.js +0 -3
  205. package/lib/structures/ITtscPreparedExecution.js.map +0 -1
  206. package/lib/structures/ITtscProjectLocatorOptions.d.ts +0 -5
  207. package/lib/structures/ITtscProjectLocatorOptions.js.map +0 -1
  208. package/lib/structures/ITtscRegisterOptions.d.ts +0 -6
  209. package/lib/structures/ITtscRegisterOptions.js +0 -3
  210. package/lib/structures/ITtscRegisterOptions.js.map +0 -1
  211. package/lib/structures/ITtscResolveGoBinaryOptions.d.ts +0 -7
  212. package/lib/structures/ITtscResolveGoBinaryOptions.js +0 -3
  213. package/lib/structures/ITtscResolveGoBinaryOptions.js.map +0 -1
  214. package/lib/structures/ITtscResolveOptions.d.ts +0 -20
  215. package/lib/structures/ITtscResolveOptions.js +0 -3
  216. package/lib/structures/ITtscResolveOptions.js.map +0 -1
  217. package/lib/structures/ITtscResolvedTsgo.d.ts +0 -8
  218. package/lib/structures/ITtscResolvedTsgo.js +0 -3
  219. package/lib/structures/ITtscResolvedTsgo.js.map +0 -1
  220. package/lib/structures/ITtscTransformOptions.d.ts +0 -12
  221. package/lib/structures/ITtscTransformOptions.js +0 -3
  222. package/lib/structures/ITtscTransformOptions.js.map +0 -1
  223. package/lib/structures/ITtscTsgoResolveOptions.d.ts +0 -14
  224. package/lib/structures/ITtscTsgoResolveOptions.js +0 -3
  225. package/lib/structures/ITtscTsgoResolveOptions.js.map +0 -1
  226. package/lib/tsgo.d.ts +0 -6
  227. package/lib/tsgo.js.map +0 -1
  228. package/src/api.ts +0 -872
  229. package/src/native.ts +0 -64
  230. package/src/platform.ts +0 -151
  231. package/src/plugin.ts +0 -253
  232. package/src/runner/register.ts +0 -406
  233. package/src/structures/ITtscBuildOptions.ts +0 -19
  234. package/src/structures/ITtscBuildResult.ts +0 -6
  235. package/src/structures/ITtscBuildSourcePluginOptions.ts +0 -9
  236. package/src/structures/ITtscCacheKeyInput.ts +0 -7
  237. package/src/structures/ITtscCheckOptions.ts +0 -3
  238. package/src/structures/ITtscCommonOptions.ts +0 -23
  239. package/src/structures/ITtscLoadPluginsOptions.ts +0 -9
  240. package/src/structures/ITtscLoadedNativePlugin.ts +0 -8
  241. package/src/structures/ITtscLoadedPlugins.ts +0 -12
  242. package/src/structures/ITtscNativeBackend.ts +0 -11
  243. package/src/structures/ITtscNativePluginContractVersion.ts +0 -1
  244. package/src/structures/ITtscNativePluginShape.ts +0 -9
  245. package/src/structures/ITtscNativeRewriteMode.ts +0 -1
  246. package/src/structures/ITtscNativeSource.ts +0 -4
  247. package/src/structures/ITtscParsedProjectConfig.ts +0 -10
  248. package/src/structures/ITtscPluginFactory.ts +0 -7
  249. package/src/structures/ITtscPluginModule.ts +0 -4
  250. package/src/structures/ITtscPreparedExecution.ts +0 -5
  251. package/src/structures/ITtscProjectLocatorOptions.ts +0 -5
  252. package/src/structures/ITtscRegisterOptions.ts +0 -7
  253. package/src/structures/ITtscResolveGoBinaryOptions.ts +0 -7
  254. package/src/structures/ITtscResolveOptions.ts +0 -20
  255. package/src/structures/ITtscResolvedTsgo.ts +0 -8
  256. package/src/structures/ITtscTransformOptions.ts +0 -13
  257. package/src/structures/ITtscTsgoResolveOptions.ts +0 -14
  258. package/test/native.test.ts +0 -103
  259. /package/lib/structures/{ITtscLoadedNativePlugin.js → internal/ITtscLoadedNativePlugin.js} +0 -0
  260. /package/lib/structures/{ITtscParsedProjectConfig.js → internal/ITtscParsedProjectConfig.js} +0 -0
  261. /package/lib/structures/{ITtscProjectLocatorOptions.js → internal/ITtscProjectLocatorOptions.js} +0 -0
@@ -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
+ }
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
@@ -54,6 +54,8 @@ 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:])
57
59
  case "check":
58
60
  // `ttsc check` runs the analyze pipeline without emitting JS — useful
59
61
  // in CI and pre-commit hooks that only need schema validation.
@@ -153,14 +155,12 @@ Build options:
153
155
  --noEmit Force analysis-only run even when tsconfig would emit.
154
156
  --quiet Suppress the per-call summary banner (default).
155
157
  --verbose Print the per-call summary banner and emitted file list.
156
- --rewrite-mode=M Native rewrite backend id.
157
158
  --manifest=FILE Write emitted file paths as JSON to FILE after build --emit.
158
159
 
159
160
  Transform options:
160
161
  --file=PATH Absolute or cwd-relative path of the .ts file to transform.
161
162
  --tsconfig=FILE tsconfig.json owning --file (default: tsconfig.json).
162
163
  --out=PATH Write output JS to PATH. Default: stdout.
163
- --rewrite-mode=M Native rewrite backend id.
164
164
 
165
165
  Demo options:
166
166
  --type=T Atomic TypeScript type to simulate. One of:
@@ -33,7 +33,6 @@ func runTransform(args []string) int {
33
33
  tsconfigPath := fs.String("tsconfig", "tsconfig.json", "tsconfig.json owning --file")
34
34
  cwdOverride := fs.String("cwd", "", "override the working directory")
35
35
  out := fs.String("out", "", "write output JS to PATH (default: stdout)")
36
- rewriteMode := fs.String("rewrite-mode", "none", "native rewrite backend id")
37
36
  if err := fs.Parse(args); err != nil {
38
37
  return 2
39
38
  }
@@ -76,11 +75,6 @@ func runTransform(args []string) int {
76
75
  absFile = filepath.ToSlash(absFile)
77
76
 
78
77
  rewrites := driver.NewRewriteSet()
79
- if *rewriteMode != "none" {
80
- fmt.Fprintf(stderr, "ttsc transform: rewrite backend %q is not built into the standalone ttsc binary\n", *rewriteMode)
81
- fmt.Fprintln(stderr, "ttsc transform: run through the JS host with the matching compiler plugin so it can select the consumer-provided native binary")
82
- return 2
83
- }
84
78
 
85
79
  target := prog.SourceFile(absFile)
86
80
  if target == nil {
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
@@ -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,76 @@
1
+ import type { ITtscCompilerContext } from "./structures/ITtscCompilerContext";
2
+ import type { ITtscCompilerResult } from "./structures/ITtscCompilerResult";
3
+ /**
4
+ * Programmatic compiler host for the `ttsc` TypeScript-Go pipeline.
5
+ *
6
+ * `TtscCompiler` is the root JavaScript API exported by the `ttsc` package.
7
+ * It represents one resolved project context: a working directory, an optional
8
+ * project config path, an optional native toolchain override, an environment,
9
+ * a cache root, and a plugin list. Those values are captured by the
10
+ * constructor and are intentionally not replaceable per method call.
11
+ *
12
+ * The class exposes only the operations that make sense for an embedded
13
+ * compiler host:
14
+ *
15
+ * - {@link TtscCompiler.prepare}: build configured Go source plugins into the
16
+ * cache before a later compile.
17
+ * - {@link TtscCompiler.clean}: remove the cache owned by this compiler
18
+ * context.
19
+ * - {@link TtscCompiler.compile}: compile the configured project and return a
20
+ * structured result instead of terminal text.
21
+ */
22
+ export declare class TtscCompiler {
23
+ private readonly context;
24
+ constructor(context?: ITtscCompilerContext);
25
+ /**
26
+ * Build every configured source plugin into the instance cache.
27
+ *
28
+ * This method loads the project plugin descriptors, resolves their
29
+ * {@link ITtscPlugin.source} paths, and compiles those Go command packages
30
+ * into the ttsc cache. It is useful when a host application wants to pay the
31
+ * lazy build cost before the first compile call.
32
+ *
33
+ * `prepare()` is not a project check. It does not create a TypeScript-Go
34
+ * Program, does not run diagnostics, and does not emit output files.
35
+ *
36
+ * @returns Compiled native plugin binary paths.
37
+ */
38
+ prepare(): string[];
39
+ /**
40
+ * Remove compiled cache artifacts for this compiler instance.
41
+ *
42
+ * When the constructor received `cacheDir`, this method removes exactly that
43
+ * directory. Otherwise it removes the default ttsc cache locations for the
44
+ * resolved project root, plus the `TTSC_CACHE_DIR/plugins` cache when that
45
+ * environment variable is active.
46
+ *
47
+ * The cache target comes from the constructor context. Create another
48
+ * `TtscCompiler` instance to clean another project or another cache root.
49
+ *
50
+ * @returns Cache directories that were removed.
51
+ */
52
+ clean(): string[];
53
+ /**
54
+ * Compile the configured project.
55
+ *
56
+ * The public API does not write emitted files into the caller's project tree.
57
+ * For projects without plugins, ttsc uses its native TypeScript-Go host's
58
+ * `WriteFile` callback to capture output in memory. For projects with
59
+ * native plugins, ttsc runs the plugin pipeline against a temporary output
60
+ * directory, reads the generated text artifacts, and removes the temporary
61
+ * directory before returning.
62
+ *
63
+ * The result uses an `embed-typescript`-style discriminated union:
64
+ * `success` for clean compiles, `failure` for normal compiler diagnostics,
65
+ * and `exception` for host setup or process failures.
66
+ *
67
+ * @returns Structured compilation result containing diagnostics or output.
68
+ */
69
+ compile(): ITtscCompilerResult;
70
+ private compilerContext;
71
+ private resolveProjectExecution;
72
+ private resolveCleanProjectRoot;
73
+ private resolveCwd;
74
+ private resolveCacheDir;
75
+ private resolvePluginCacheDir;
76
+ }
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.TtscCompiler = void 0;
37
+ const fs = __importStar(require("node:fs"));
38
+ const path = __importStar(require("node:path"));
39
+ const compileProjectInMemory_1 = require("./compiler/internal/compileProjectInMemory");
40
+ const resolveProjectConfig_1 = require("./compiler/internal/project/resolveProjectConfig");
41
+ const resolveBinary_1 = require("./compiler/internal/resolveBinary");
42
+ const loadProjectPlugins_1 = require("./plugin/internal/loadProjectPlugins");
43
+ /**
44
+ * Programmatic compiler host for the `ttsc` TypeScript-Go pipeline.
45
+ *
46
+ * `TtscCompiler` is the root JavaScript API exported by the `ttsc` package.
47
+ * It represents one resolved project context: a working directory, an optional
48
+ * project config path, an optional native toolchain override, an environment,
49
+ * a cache root, and a plugin list. Those values are captured by the
50
+ * constructor and are intentionally not replaceable per method call.
51
+ *
52
+ * The class exposes only the operations that make sense for an embedded
53
+ * compiler host:
54
+ *
55
+ * - {@link TtscCompiler.prepare}: build configured Go source plugins into the
56
+ * cache before a later compile.
57
+ * - {@link TtscCompiler.clean}: remove the cache owned by this compiler
58
+ * context.
59
+ * - {@link TtscCompiler.compile}: compile the configured project and return a
60
+ * structured result instead of terminal text.
61
+ */
62
+ class TtscCompiler {
63
+ context;
64
+ constructor(context = {}) {
65
+ this.context = {
66
+ ...context,
67
+ env: context.env ? { ...context.env } : undefined,
68
+ plugins: Array.isArray(context.plugins)
69
+ ? [...context.plugins]
70
+ : context.plugins,
71
+ };
72
+ }
73
+ /**
74
+ * Build every configured source plugin into the instance cache.
75
+ *
76
+ * This method loads the project plugin descriptors, resolves their
77
+ * {@link ITtscPlugin.source} paths, and compiles those Go command packages
78
+ * into the ttsc cache. It is useful when a host application wants to pay the
79
+ * lazy build cost before the first compile call.
80
+ *
81
+ * `prepare()` is not a project check. It does not create a TypeScript-Go
82
+ * Program, does not run diagnostics, and does not emit output files.
83
+ *
84
+ * @returns Compiled native plugin binary paths.
85
+ */
86
+ prepare() {
87
+ const execution = this.resolveProjectExecution();
88
+ const loaded = (0, loadProjectPlugins_1.loadProjectPlugins)({
89
+ binary: (0, resolveBinary_1.resolveBinary)(this.compilerContext()) ?? "",
90
+ cacheDir: this.resolvePluginCacheDir(),
91
+ cwd: execution.cwd,
92
+ entries: this.context.plugins,
93
+ tsconfig: execution.tsconfig,
94
+ });
95
+ return loaded.nativePlugins.map((plugin) => plugin.binary);
96
+ }
97
+ /**
98
+ * Remove compiled cache artifacts for this compiler instance.
99
+ *
100
+ * When the constructor received `cacheDir`, this method removes exactly that
101
+ * directory. Otherwise it removes the default ttsc cache locations for the
102
+ * resolved project root, plus the `TTSC_CACHE_DIR/plugins` cache when that
103
+ * environment variable is active.
104
+ *
105
+ * The cache target comes from the constructor context. Create another
106
+ * `TtscCompiler` instance to clean another project or another cache root.
107
+ *
108
+ * @returns Cache directories that were removed.
109
+ */
110
+ clean() {
111
+ const cacheDir = this.resolveCacheDir();
112
+ if (cacheDir !== undefined) {
113
+ return removeExistingDirectories([cacheDir]);
114
+ }
115
+ const envCacheDir = this.context.env?.TTSC_CACHE_DIR ?? process.env.TTSC_CACHE_DIR;
116
+ const projectRoot = this.resolveCleanProjectRoot();
117
+ return removeExistingDirectories([
118
+ ...(envCacheDir ? [path.resolve(envCacheDir, "plugins")] : []),
119
+ path.join(projectRoot, "node_modules", ".ttsc"),
120
+ path.join(projectRoot, ".ttsc"),
121
+ ]);
122
+ }
123
+ /**
124
+ * Compile the configured project.
125
+ *
126
+ * The public API does not write emitted files into the caller's project tree.
127
+ * For projects without plugins, ttsc uses its native TypeScript-Go host's
128
+ * `WriteFile` callback to capture output in memory. For projects with
129
+ * native plugins, ttsc runs the plugin pipeline against a temporary output
130
+ * directory, reads the generated text artifacts, and removes the temporary
131
+ * directory before returning.
132
+ *
133
+ * The result uses an `embed-typescript`-style discriminated union:
134
+ * `success` for clean compiles, `failure` for normal compiler diagnostics,
135
+ * and `exception` for host setup or process failures.
136
+ *
137
+ * @returns Structured compilation result containing diagnostics or output.
138
+ */
139
+ compile() {
140
+ return runProject(() => (0, compileProjectInMemory_1.compileProjectInMemory)(this.compilerContext()));
141
+ }
142
+ compilerContext() {
143
+ return {
144
+ ...this.context,
145
+ cacheDir: this.resolveCacheDir(),
146
+ };
147
+ }
148
+ resolveProjectExecution() {
149
+ const cwd = this.resolveCwd();
150
+ const tsconfig = (0, resolveProjectConfig_1.resolveProjectConfig)({
151
+ cwd,
152
+ tsconfig: this.context.tsconfig,
153
+ });
154
+ return {
155
+ cwd,
156
+ projectRoot: path.dirname(tsconfig),
157
+ tsconfig,
158
+ };
159
+ }
160
+ resolveCleanProjectRoot() {
161
+ try {
162
+ return this.resolveProjectExecution().projectRoot;
163
+ }
164
+ catch (error) {
165
+ if (this.context.tsconfig) {
166
+ throw error;
167
+ }
168
+ return this.resolveCwd();
169
+ }
170
+ }
171
+ resolveCwd() {
172
+ return path.resolve(this.context.cwd ?? process.cwd());
173
+ }
174
+ resolveCacheDir() {
175
+ if (!this.context.cacheDir) {
176
+ return undefined;
177
+ }
178
+ return path.isAbsolute(this.context.cacheDir)
179
+ ? this.context.cacheDir
180
+ : path.resolve(this.resolveCwd(), this.context.cacheDir);
181
+ }
182
+ resolvePluginCacheDir() {
183
+ return this.resolveCacheDir() ?? this.context.env?.TTSC_CACHE_DIR;
184
+ }
185
+ }
186
+ exports.TtscCompiler = TtscCompiler;
187
+ function removeExistingDirectories(directories) {
188
+ const removed = [];
189
+ for (const directory of [...new Set(directories)]) {
190
+ if (!fs.existsSync(directory)) {
191
+ continue;
192
+ }
193
+ fs.rmSync(directory, { recursive: true, force: true });
194
+ removed.push(directory);
195
+ }
196
+ return removed;
197
+ }
198
+ function runProject(task) {
199
+ try {
200
+ return toCompilerResult(task());
201
+ }
202
+ catch (error) {
203
+ return {
204
+ error: normalizeError(error),
205
+ type: "exception",
206
+ };
207
+ }
208
+ }
209
+ function toCompilerResult(project) {
210
+ const { output, result } = project;
211
+ if (result.status === 0 && result.diagnostics.length === 0) {
212
+ return {
213
+ output,
214
+ type: "success",
215
+ };
216
+ }
217
+ return {
218
+ diagnostics: result.diagnostics.length === 0
219
+ ? [createProcessDiagnostic(result)]
220
+ : result.diagnostics,
221
+ output,
222
+ type: "failure",
223
+ };
224
+ }
225
+ function createProcessDiagnostic(result) {
226
+ const messageText = (result.stderr || result.stdout).trim() ||
227
+ `ttsc exited with status ${result.status}`;
228
+ return {
229
+ category: "error",
230
+ code: "TTSC_PROCESS",
231
+ file: null,
232
+ messageText,
233
+ };
234
+ }
235
+ function normalizeError(error) {
236
+ if (!(error instanceof Error)) {
237
+ return error;
238
+ }
239
+ return {
240
+ message: error.message,
241
+ name: error.name,
242
+ stack: error.stack,
243
+ };
244
+ }
245
+ //# sourceMappingURL=TtscCompiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TtscCompiler.js","sourceRoot":"","sources":["../src/TtscCompiler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,EAAE,oCAAgB;AAC9B,MAAY,IAAI,sCAAkB;AAElC,uFAAoF;AACpF,2FAAwF;AACxF,qEAAkE;AAClE,6EAA0E;AAM1E;;;;;;;;;;;;;;;;;;GAkBG;AACH;IACmB,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AAK,EAAE,cAAc,CAAC,KAAK,CAAC;YAC5B,IAAI,EAAE,WAAW;SAClB,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,OAAsB;IAC9C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IACnC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3D,OAAO;YACL,MAAM;YACN,IAAI,EAAE,SAAS;SAChB,CAAC;IACJ,CAAC;IACD,OAAO;QACL,WAAW,EACT,MAAM,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC;YAC7B,CAAC,CAAC,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;YACnC,CAAC,CAAC,MAAM,CAAC,WAAW;QACxB,MAAM;QACN,IAAI,EAAE,SAAS;KAChB,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAC9B,MAAuB;IAEvB,MAAM,WAAW,GACf,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE;QACvC,2BAA2B,MAAM,CAAC,MAAM,EAAE,CAAC;IAC7C,OAAO;QACL,QAAQ,EAAE,OAAO;QACjB,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,IAAI;QACV,WAAW;KACZ,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** Build the native ttsc compiler host used by in-memory API compilation. */
2
+ export declare function buildNativeCompiler(options: {
3
+ cacheBaseDir: string;
4
+ cacheDir?: string;
5
+ packageRoot: string;
6
+ }): string;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.buildNativeCompiler = buildNativeCompiler;
37
+ const fs = __importStar(require("node:fs"));
38
+ const path = __importStar(require("node:path"));
39
+ const buildSourcePlugin_1 = require("../../plugin/internal/buildSourcePlugin");
40
+ /** Build the native ttsc compiler host used by in-memory API compilation. */
41
+ function buildNativeCompiler(options) {
42
+ return (0, buildSourcePlugin_1.buildSourcePlugin)({
43
+ baseDir: options.cacheBaseDir,
44
+ cacheDir: options.cacheDir,
45
+ label: "compiler host",
46
+ overlayDirs: [],
47
+ pluginName: "ttsc",
48
+ quiet: true,
49
+ source: path.join(options.packageRoot, "cmd", "ttsc"),
50
+ ttscVersion: readOwnPackageVersion(options.packageRoot),
51
+ tsgoVersion: readGoModuleVersion(options.packageRoot),
52
+ });
53
+ }
54
+ function readOwnPackageVersion(packageRoot) {
55
+ try {
56
+ const pkg = JSON.parse(fs.readFileSync(path.join(packageRoot, "package.json"), "utf8"));
57
+ return typeof pkg.version === "string" ? pkg.version : "0.0.0";
58
+ }
59
+ catch {
60
+ return "0.0.0";
61
+ }
62
+ }
63
+ function readGoModuleVersion(packageRoot) {
64
+ try {
65
+ const goMod = fs.readFileSync(path.join(packageRoot, "go.mod"), "utf8");
66
+ return goMod;
67
+ }
68
+ catch {
69
+ return "unknown";
70
+ }
71
+ }
72
+ //# sourceMappingURL=buildNativeCompiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildNativeCompiler.js","sourceRoot":"","sources":["../../../src/compiler/internal/buildNativeCompiler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,EAAE,oCAAgB;AAC9B,MAAY,IAAI,sCAAkB;AAElC,+EAA4E;AAE5E,6EAA6E;AAC7E,6BAAoC,OAInC;IACC,OAAO,IAAA,qCAAiB,EAAC;QACvB,OAAO,EAAE,OAAO,CAAC,YAAY;QAC7B,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,KAAK,EAAE,eAAe;QACtB,WAAW,EAAE,EAAE;QACf,UAAU,EAAE,MAAM;QAClB,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC;QACrD,WAAW,EAAE,qBAAqB,CAAC,OAAO,CAAC,WAAW,CAAC;QACvD,WAAW,EAAE,mBAAmB,CAAC,OAAO,CAAC,WAAW,CAAC;KACtD,CAAC,CAAC;AACL,CAAC;AAED,SAAS,qBAAqB,CAAC,WAAmB;IAChD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CACpB,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CACvC,CAAC;QAC3B,OAAO,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;IACjE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC;AAED,SAAS,mBAAmB,CAAC,WAAmB;IAC9C,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;QACxE,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { ITtscCompilerContext } from "../../structures/ITtscCompilerContext";
2
+ import type { TtscBuildResult } from "../../structures/internal/TtscBuildResult";
3
+ /** Compile a project and capture emitted files without writing to the project tree. */
4
+ export declare function compileProjectInMemory(options: ITtscCompilerContext): {
5
+ output: Record<string, string>;
6
+ result: TtscBuildResult;
7
+ };