ttsc 0.5.0 → 0.6.0-dev.20250430

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 (162) hide show
  1. package/README.md +1 -1
  2. package/go.mod +1 -1
  3. package/go.sum +2 -2
  4. package/lib/api.d.ts +15 -67
  5. package/lib/api.js +14 -3
  6. package/lib/api.js.map +1 -1
  7. package/lib/cli.js.map +1 -1
  8. package/lib/native.d.ts +8 -20
  9. package/lib/native.js.map +1 -1
  10. package/lib/platform.d.ts +7 -25
  11. package/lib/platform.js.map +1 -1
  12. package/lib/plugin.d.ts +13 -41
  13. package/lib/plugin.js +2 -2
  14. package/lib/plugin.js.map +1 -1
  15. package/lib/project.d.ts +11 -29
  16. package/lib/project.js.map +1 -1
  17. package/lib/runner/cli.js.map +1 -1
  18. package/lib/runner/register.d.ts +6 -13
  19. package/lib/runner/register.js.map +1 -1
  20. package/lib/source-build.d.ts +11 -22
  21. package/lib/source-build.js +25 -1
  22. package/lib/source-build.js.map +1 -1
  23. package/lib/structures/ITtscBuildOptions.d.ts +14 -0
  24. package/lib/structures/ITtscBuildOptions.js +3 -0
  25. package/lib/structures/ITtscBuildOptions.js.map +1 -0
  26. package/lib/structures/ITtscBuildResult.d.ts +6 -0
  27. package/lib/structures/ITtscBuildResult.js +3 -0
  28. package/lib/structures/ITtscBuildResult.js.map +1 -0
  29. package/lib/structures/ITtscBuildSourcePluginOptions.d.ts +8 -0
  30. package/lib/structures/ITtscBuildSourcePluginOptions.js +3 -0
  31. package/lib/structures/ITtscBuildSourcePluginOptions.js.map +1 -0
  32. package/lib/structures/ITtscCacheKeyInput.d.ts +7 -0
  33. package/lib/structures/ITtscCacheKeyInput.js +3 -0
  34. package/lib/structures/ITtscCacheKeyInput.js.map +1 -0
  35. package/lib/structures/ITtscCheckOptions.d.ts +2 -0
  36. package/lib/structures/ITtscCheckOptions.js +3 -0
  37. package/lib/structures/ITtscCheckOptions.js.map +1 -0
  38. package/lib/structures/ITtscCommonOptions.d.ts +22 -0
  39. package/lib/structures/ITtscCommonOptions.js +3 -0
  40. package/lib/structures/ITtscCommonOptions.js.map +1 -0
  41. package/lib/structures/ITtscLoadPluginsOptions.d.ts +8 -0
  42. package/lib/structures/ITtscLoadPluginsOptions.js +3 -0
  43. package/lib/structures/ITtscLoadPluginsOptions.js.map +1 -0
  44. package/lib/structures/ITtscLoadedNativePlugin.d.ts +7 -0
  45. package/lib/structures/ITtscLoadedNativePlugin.js +3 -0
  46. package/lib/structures/ITtscLoadedNativePlugin.js.map +1 -0
  47. package/lib/structures/ITtscLoadedPlugins.d.ts +11 -0
  48. package/lib/structures/ITtscLoadedPlugins.js +3 -0
  49. package/lib/structures/ITtscLoadedPlugins.js.map +1 -0
  50. package/lib/structures/ITtscNativeBackend.d.ts +10 -0
  51. package/lib/structures/ITtscNativeBackend.js +3 -0
  52. package/lib/structures/ITtscNativeBackend.js.map +1 -0
  53. package/lib/structures/ITtscNativePluginContractVersion.d.ts +1 -0
  54. package/lib/structures/ITtscNativePluginContractVersion.js +3 -0
  55. package/lib/structures/ITtscNativePluginContractVersion.js.map +1 -0
  56. package/lib/structures/ITtscNativePluginShape.d.ts +8 -0
  57. package/lib/structures/ITtscNativePluginShape.js +3 -0
  58. package/lib/structures/ITtscNativePluginShape.js.map +1 -0
  59. package/lib/structures/ITtscNativeRewriteMode.d.ts +1 -0
  60. package/lib/structures/ITtscNativeRewriteMode.js +3 -0
  61. package/lib/structures/ITtscNativeRewriteMode.js.map +1 -0
  62. package/lib/structures/ITtscNativeSource.d.ts +4 -0
  63. package/lib/structures/ITtscNativeSource.js +3 -0
  64. package/lib/structures/ITtscNativeSource.js.map +1 -0
  65. package/lib/structures/ITtscParsedProjectConfig.d.ts +9 -0
  66. package/lib/structures/ITtscParsedProjectConfig.js +3 -0
  67. package/lib/structures/ITtscParsedProjectConfig.js.map +1 -0
  68. package/lib/structures/ITtscPlugin.d.ts +10 -0
  69. package/lib/structures/ITtscPlugin.js +3 -0
  70. package/lib/structures/ITtscPlugin.js.map +1 -0
  71. package/lib/structures/ITtscPluginFactory.d.ts +4 -0
  72. package/lib/structures/ITtscPluginFactory.js +3 -0
  73. package/lib/structures/ITtscPluginFactory.js.map +1 -0
  74. package/lib/structures/ITtscPluginFactoryContext.d.ts +8 -0
  75. package/lib/structures/ITtscPluginFactoryContext.js +3 -0
  76. package/lib/structures/ITtscPluginFactoryContext.js.map +1 -0
  77. package/lib/structures/ITtscPluginModule.d.ts +3 -0
  78. package/lib/structures/ITtscPluginModule.js +3 -0
  79. package/lib/structures/ITtscPluginModule.js.map +1 -0
  80. package/lib/structures/ITtscPreparedExecution.d.ts +5 -0
  81. package/lib/structures/ITtscPreparedExecution.js +3 -0
  82. package/lib/structures/ITtscPreparedExecution.js.map +1 -0
  83. package/lib/structures/ITtscProjectLocatorOptions.d.ts +5 -0
  84. package/lib/structures/ITtscProjectLocatorOptions.js +3 -0
  85. package/lib/structures/ITtscProjectLocatorOptions.js.map +1 -0
  86. package/lib/structures/ITtscProjectPluginConfig.d.ts +5 -0
  87. package/lib/structures/ITtscProjectPluginConfig.js +3 -0
  88. package/lib/structures/ITtscProjectPluginConfig.js.map +1 -0
  89. package/lib/structures/ITtscRegisterOptions.d.ts +6 -0
  90. package/lib/structures/ITtscRegisterOptions.js +3 -0
  91. package/lib/structures/ITtscRegisterOptions.js.map +1 -0
  92. package/lib/structures/ITtscResolveGoBinaryOptions.d.ts +7 -0
  93. package/lib/structures/ITtscResolveGoBinaryOptions.js +3 -0
  94. package/lib/structures/ITtscResolveGoBinaryOptions.js.map +1 -0
  95. package/lib/structures/ITtscResolveOptions.d.ts +20 -0
  96. package/lib/structures/ITtscResolveOptions.js +3 -0
  97. package/lib/structures/ITtscResolveOptions.js.map +1 -0
  98. package/lib/structures/ITtscResolvedTsgo.d.ts +8 -0
  99. package/lib/structures/ITtscResolvedTsgo.js +3 -0
  100. package/lib/structures/ITtscResolvedTsgo.js.map +1 -0
  101. package/lib/structures/ITtscTransformOptions.d.ts +12 -0
  102. package/lib/structures/ITtscTransformOptions.js +3 -0
  103. package/lib/structures/ITtscTransformOptions.js.map +1 -0
  104. package/lib/structures/ITtscTsgoResolveOptions.d.ts +14 -0
  105. package/lib/structures/ITtscTsgoResolveOptions.js +3 -0
  106. package/lib/structures/ITtscTsgoResolveOptions.js.map +1 -0
  107. package/lib/tsgo.d.ts +6 -24
  108. package/lib/tsgo.js.map +1 -1
  109. package/package.json +10 -10
  110. package/shim/ast/go.mod +1 -1
  111. package/shim/ast/lint.go +2 -0
  112. package/shim/bundled/go.mod +1 -1
  113. package/shim/checker/go.mod +1 -1
  114. package/shim/compiler/go.mod +1 -1
  115. package/shim/core/go.mod +1 -1
  116. package/shim/diagnosticwriter/go.mod +1 -1
  117. package/shim/parser/go.mod +1 -1
  118. package/shim/scanner/go.mod +1 -1
  119. package/shim/tsoptions/go.mod +1 -1
  120. package/shim/tspath/go.mod +1 -1
  121. package/shim/vfs/cachedvfs/go.mod +1 -1
  122. package/shim/vfs/go.mod +1 -1
  123. package/shim/vfs/osvfs/go.mod +1 -1
  124. package/src/api.ts +108 -155
  125. package/src/cli.ts +10 -10
  126. package/src/native.ts +9 -23
  127. package/src/platform.ts +10 -27
  128. package/src/plugin.ts +37 -74
  129. package/src/project.ts +18 -37
  130. package/src/runner/cli.ts +5 -5
  131. package/src/runner/register.ts +32 -43
  132. package/src/source-build.ts +45 -25
  133. package/src/structures/ITtscBuildOptions.ts +19 -0
  134. package/src/structures/ITtscBuildResult.ts +6 -0
  135. package/src/structures/ITtscBuildSourcePluginOptions.ts +9 -0
  136. package/src/structures/ITtscCacheKeyInput.ts +7 -0
  137. package/src/structures/ITtscCheckOptions.ts +3 -0
  138. package/src/structures/ITtscCommonOptions.ts +23 -0
  139. package/src/structures/ITtscLoadPluginsOptions.ts +9 -0
  140. package/src/structures/ITtscLoadedNativePlugin.ts +8 -0
  141. package/src/structures/ITtscLoadedPlugins.ts +12 -0
  142. package/src/structures/ITtscNativeBackend.ts +11 -0
  143. package/src/structures/ITtscNativePluginContractVersion.ts +1 -0
  144. package/src/structures/ITtscNativePluginShape.ts +9 -0
  145. package/src/structures/ITtscNativeRewriteMode.ts +1 -0
  146. package/src/structures/ITtscNativeSource.ts +4 -0
  147. package/src/structures/ITtscParsedProjectConfig.ts +10 -0
  148. package/src/structures/ITtscPlugin.ts +11 -0
  149. package/src/structures/ITtscPluginFactory.ts +7 -0
  150. package/src/structures/ITtscPluginFactoryContext.ts +9 -0
  151. package/src/structures/ITtscPluginModule.ts +4 -0
  152. package/src/structures/ITtscPreparedExecution.ts +5 -0
  153. package/src/structures/ITtscProjectLocatorOptions.ts +5 -0
  154. package/src/structures/ITtscProjectPluginConfig.ts +5 -0
  155. package/src/structures/ITtscRegisterOptions.ts +7 -0
  156. package/src/structures/ITtscResolveGoBinaryOptions.ts +7 -0
  157. package/src/structures/ITtscResolveOptions.ts +20 -0
  158. package/src/structures/ITtscResolvedTsgo.ts +8 -0
  159. package/src/structures/ITtscTransformOptions.ts +13 -0
  160. package/src/structures/ITtscTsgoResolveOptions.ts +14 -0
  161. package/src/tsgo.ts +6 -24
  162. package/test/source-build.test.ts +13 -0
package/src/api.ts CHANGED
@@ -21,83 +21,44 @@ import * as fs from "node:fs";
21
21
  import * as os from "node:os";
22
22
  import * as path from "node:path";
23
23
 
24
- import { type ResolveOptions, resolveBinary } from "./platform";
25
- import {
26
- type LoadedNativePlugin,
27
- loadProjectPlugins,
28
- } from "./plugin";
29
- import {
30
- type ProjectPluginConfig,
31
- resolveProjectConfig,
32
- resolveProjectRoot,
33
- } from "./project";
34
- import { type ResolvedTsgo, resolveTsgo } from "./tsgo";
35
-
36
- /**
37
- * Options shared by every API call. `binary` takes precedence over platform
38
- * resolution; `cwd` defaults to `process.cwd()`; `env` layers on top of the
39
- * current process env.
40
- */
41
- export interface CommonOptions extends ResolveOptions {
42
- /** Absolute path to an already-resolved tsgo binary. Skips package resolution. */
43
- binary?: string;
44
- /** Working directory passed to the child process. */
45
- cwd?: string;
46
- /** Extra environment variables; merged onto `process.env`. */
47
- env?: NodeJS.ProcessEnv;
48
- /**
49
- * Override project plugin loading. `false` disables tsconfig plugins; an
50
- * array replaces the tsconfig `compilerOptions.plugins` list.
51
- */
52
- plugins?: readonly ProjectPluginConfig[] | false;
53
- /**
54
- * Override the native rewrite backend. Defaults to the loaded plugin mode.
55
- *
56
- * @deprecated Prefer plugin-declared `native.mode`; this override is for
57
- * low-level tests and migration probes.
58
- */
59
- rewriteMode?: string;
60
- }
61
-
62
- /** Options for `transform()`. */
63
- export interface TransformOptions extends CommonOptions {
64
- /** Path to the .ts file to transform. Absolute or `cwd`-relative. */
65
- file: string;
66
- /** Path to the tsconfig owning `file`. Default: `tsconfig.json`. */
67
- tsconfig?: string;
68
- /**
69
- * When provided, the binary writes JS directly to this path instead of piping
70
- * stdout. Useful when the emitted text is large.
71
- */
72
- out?: string;
73
- }
74
-
75
- /** Options for `build()`. */
76
- export interface BuildOptions extends CommonOptions {
77
- /** Path to tsconfig.json. Default: `tsconfig.json`. */
78
- tsconfig?: string;
79
- /**
80
- * Emit override. `true` forces emit, `false` forces noEmit, `undefined`
81
- * follows tsconfig.
82
- */
83
- emit?: boolean;
84
- /** Override compilerOptions.outDir for this invocation. */
85
- outDir?: string;
86
- /** Suppress the per-call summary banner. Default: `true`. */
87
- quiet?: boolean;
88
- /** @internal Caller already ran diagnostics and accepts responsibility. */
89
- skipDiagnosticsCheck?: boolean;
90
- /** @internal Force `tsgo --listEmittedFiles` for caller-side output discovery. */
91
- forceListEmittedFiles?: boolean;
92
- }
93
-
94
- /** Options for `check()`. */
95
- export type CheckOptions = Omit<BuildOptions, "emit">;
24
+ import type { ITtscBuildOptions } from "./structures/ITtscBuildOptions";
25
+ import type { ITtscBuildResult } from "./structures/ITtscBuildResult";
26
+ import type { ITtscCheckOptions } from "./structures/ITtscCheckOptions";
27
+ import type { ITtscCommonOptions } from "./structures/ITtscCommonOptions";
28
+ import type { ITtscLoadedNativePlugin } from "./structures/ITtscLoadedNativePlugin";
29
+ import type { ITtscResolvedTsgo } from "./structures/ITtscResolvedTsgo";
30
+ import type { ITtscTransformOptions } from "./structures/ITtscTransformOptions";
31
+ import { resolveBinary } from "./platform";
32
+ import { loadProjectPlugins } from "./plugin";
33
+ import { resolveProjectConfig, resolveProjectRoot } from "./project";
34
+ import { resolveTsgo } from "./tsgo";
35
+
36
+ export type { ITtscBuildOptions } from "./structures/ITtscBuildOptions";
37
+ export type { ITtscBuildResult } from "./structures/ITtscBuildResult";
38
+ export type { ITtscCheckOptions } from "./structures/ITtscCheckOptions";
39
+ export type { ITtscCommonOptions } from "./structures/ITtscCommonOptions";
40
+ export type { ITtscTransformOptions } from "./structures/ITtscTransformOptions";
96
41
 
97
42
  /** Merge spawn env without clobbering unrelated vars. */
98
43
  function mergeEnv(extra?: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
99
- if (!extra) return process.env;
100
- return { ...process.env, ...extra };
44
+ const base = {
45
+ ...process.env,
46
+ TTSC_NODE_BINARY: process.env.TTSC_NODE_BINARY ?? process.execPath,
47
+ };
48
+ if (!extra) return base;
49
+ return { ...base, ...extra };
50
+ }
51
+
52
+ function nativePluginEnv(
53
+ extra: NodeJS.ProcessEnv | undefined,
54
+ execution: ITtscExecutionContext,
55
+ ): NodeJS.ProcessEnv {
56
+ return mergeEnv({
57
+ TTSC_TSGO_BINARY: process.env.TTSC_TSGO_BINARY ?? execution.tsgo.binary,
58
+ TTSC_TTSX_BINARY:
59
+ process.env.TTSC_TTSX_BINARY ?? path.join(__dirname, "launcher", "ttsx.js"),
60
+ ...extra,
61
+ });
101
62
  }
102
63
 
103
64
  function spawnBinary(
@@ -153,17 +114,17 @@ function outputText(value: string | Buffer | null | undefined): string {
153
114
  }
154
115
 
155
116
  function hasCapability(
156
- plugin: LoadedNativePlugin,
117
+ plugin: ITtscLoadedNativePlugin,
157
118
  capability: string,
158
119
  ): boolean {
159
120
  return plugin.backend.capabilities?.includes(capability) === true;
160
121
  }
161
122
 
162
- function isOutputPlugin(plugin: LoadedNativePlugin): boolean {
123
+ function isOutputPlugin(plugin: ITtscLoadedNativePlugin): boolean {
163
124
  return hasCapability(plugin, "output");
164
125
  }
165
126
 
166
- function isCheckOnlyPlugin(plugin: LoadedNativePlugin): boolean {
127
+ function isCheckOnlyPlugin(plugin: ITtscLoadedNativePlugin): boolean {
167
128
  const capabilities = plugin.backend.capabilities ?? [];
168
129
  return (
169
130
  capabilities.length > 0 &&
@@ -171,25 +132,25 @@ function isCheckOnlyPlugin(plugin: LoadedNativePlugin): boolean {
171
132
  );
172
133
  }
173
134
 
174
- function isCompilerPlugin(plugin: LoadedNativePlugin): boolean {
135
+ function isCompilerPlugin(plugin: ITtscLoadedNativePlugin): boolean {
175
136
  return !isOutputPlugin(plugin) && !isCheckOnlyPlugin(plugin);
176
137
  }
177
138
 
178
139
  function outputPlugins(
179
- plugins: readonly LoadedNativePlugin[],
180
- ): LoadedNativePlugin[] {
140
+ plugins: readonly ITtscLoadedNativePlugin[],
141
+ ): ITtscLoadedNativePlugin[] {
181
142
  return plugins.filter(isOutputPlugin);
182
143
  }
183
144
 
184
145
  function checkOnlyPlugins(
185
- plugins: readonly LoadedNativePlugin[],
186
- ): LoadedNativePlugin[] {
146
+ plugins: readonly ITtscLoadedNativePlugin[],
147
+ ): ITtscLoadedNativePlugin[] {
187
148
  return plugins.filter(isCheckOnlyPlugin);
188
149
  }
189
150
 
190
151
  function compilerPlugins(
191
- plugins: readonly LoadedNativePlugin[],
192
- ): LoadedNativePlugin[] {
152
+ plugins: readonly ITtscLoadedNativePlugin[],
153
+ ): ITtscLoadedNativePlugin[] {
193
154
  return plugins.filter(isCompilerPlugin);
194
155
  }
195
156
 
@@ -203,7 +164,7 @@ function compilerPlugins(
203
164
  * Throws when the binary exits non-zero — the error includes stderr so bundler
204
165
  * error overlays surface the real cause.
205
166
  */
206
- export function transform(options: TransformOptions): string {
167
+ export function transform(options: ITtscTransformOptions): string {
207
168
  const execution = resolveExecutionContext(options);
208
169
  const sourceFile = realpathIfExists(
209
170
  path.isAbsolute(options.file)
@@ -247,8 +208,8 @@ export function transform(options: TransformOptions): string {
247
208
  }
248
209
 
249
210
  function transformWithNativePlugins(
250
- options: TransformOptions,
251
- execution: ExecutionContext,
211
+ options: ITtscTransformOptions,
212
+ execution: ITtscExecutionContext,
252
213
  sourceFile: string,
253
214
  ): string {
254
215
  const checked = runNativeCheckPlugins(options, execution);
@@ -335,20 +296,12 @@ function realpathIfExists(file: string): string {
335
296
  }
336
297
  }
337
298
 
338
- /** Result of `build()`. Non-zero `status` means the build failed. */
339
- export interface BuildResult {
340
- emittedFiles?: string[];
341
- status: number;
342
- stdout: string;
343
- stderr: string;
344
- }
345
-
346
299
  /**
347
300
  * Run `ttsc` against a tsconfig. Returns once the binary exits so the caller
348
301
  * can decide how to surface diagnostics. Does not throw on non-zero exit —
349
302
  * bundler pipelines often want to continue and collect errors.
350
303
  */
351
- export function build(options: BuildOptions = {}): BuildResult {
304
+ export function build(options: ITtscBuildOptions = {}): ITtscBuildResult {
352
305
  const execution = resolveExecutionContext(options);
353
306
  if (execution.nativePlugins.length > 0) {
354
307
  const compilers = compilerPlugins(execution.nativePlugins);
@@ -372,7 +325,7 @@ export function build(options: BuildOptions = {}): BuildResult {
372
325
  return runTsgo(execution, ["--noEmit"], options);
373
326
  }
374
327
 
375
- let result: BuildResult;
328
+ let result: ITtscBuildResult;
376
329
  if (compilers.length !== 0) {
377
330
  assertSingleCompilerHost(compilers);
378
331
  result = appendBuildOutput(
@@ -422,10 +375,10 @@ export function build(options: BuildOptions = {}): BuildResult {
422
375
  }
423
376
 
424
377
  function buildWithNativeCompilerPlugins(
425
- options: BuildOptions,
426
- execution: ExecutionContext,
427
- plugins: readonly LoadedNativePlugin[],
428
- ): BuildResult {
378
+ options: ITtscBuildOptions,
379
+ execution: ITtscExecutionContext,
380
+ plugins: readonly ITtscLoadedNativePlugin[],
381
+ ): ITtscBuildResult {
429
382
  return runNativePluginCommand(
430
383
  plugins[0]!,
431
384
  createNativeBuildArgs(execution, options, plugins),
@@ -439,15 +392,15 @@ function buildWithNativeCompilerPlugins(
439
392
  * Run `ttsc check` (build without emit) — CI gate / pre-commit hook use.
440
393
  * Resolves with an exit-code record; does not throw.
441
394
  */
442
- export function check(options: CheckOptions = {}): BuildResult {
395
+ export function check(options: ITtscCheckOptions = {}): ITtscBuildResult {
443
396
  return build({ ...options, emit: false });
444
397
  }
445
398
 
446
399
  function runTsgo(
447
- execution: ExecutionContext,
400
+ execution: ITtscExecutionContext,
448
401
  extraArgs: readonly string[],
449
- options: BuildOptions,
450
- ): BuildResult {
402
+ options: ITtscBuildOptions,
403
+ ): ITtscBuildResult {
451
404
  const res = spawnBinary(
452
405
  execution.tsgo.binary,
453
406
  ["-p", execution.tsconfig, ...extraArgs],
@@ -470,10 +423,10 @@ function runTsgo(
470
423
  }
471
424
 
472
425
  function runTsgoBuild(
473
- execution: ExecutionContext,
474
- options: BuildOptions,
426
+ execution: ITtscExecutionContext,
427
+ options: ITtscBuildOptions,
475
428
  args: readonly string[],
476
- ): BuildResult {
429
+ ): ITtscBuildResult {
477
430
  const res = spawnBinary(execution.tsgo.binary, args, {
478
431
  cwd: execution.projectRoot,
479
432
  env: mergeEnv(options.env),
@@ -500,8 +453,8 @@ function runTsgoBuild(
500
453
  }
501
454
 
502
455
  function createTsgoBuildArgs(
503
- execution: ExecutionContext,
504
- options: BuildOptions,
456
+ execution: ITtscExecutionContext,
457
+ options: ITtscBuildOptions,
505
458
  flags: { listEmittedFiles: boolean },
506
459
  ): string[] {
507
460
  const args = ["-p", execution.tsconfig];
@@ -520,9 +473,9 @@ function createTsgoBuildArgs(
520
473
  }
521
474
 
522
475
  function createNativeBuildArgs(
523
- execution: ExecutionContext,
524
- options: BuildOptions,
525
- plugins: readonly LoadedNativePlugin[],
476
+ execution: ITtscExecutionContext,
477
+ options: ITtscBuildOptions,
478
+ plugins: readonly ITtscLoadedNativePlugin[],
526
479
  ): string[] {
527
480
  const args = [
528
481
  options.emit === false ? "check" : "build",
@@ -548,9 +501,9 @@ function createNativeBuildArgs(
548
501
  }
549
502
 
550
503
  function createNativeCheckArgs(
551
- execution: ExecutionContext,
552
- options: BuildOptions | TransformOptions,
553
- plugin: LoadedNativePlugin,
504
+ execution: ITtscExecutionContext,
505
+ options: ITtscBuildOptions | ITtscTransformOptions,
506
+ plugin: ITtscLoadedNativePlugin,
554
507
  ): string[] {
555
508
  const args = [
556
509
  "check",
@@ -571,9 +524,9 @@ function createNativeCheckArgs(
571
524
  }
572
525
 
573
526
  function createNativeOutputArgs(
574
- execution: ExecutionContext,
575
- options: BuildOptions | TransformOptions,
576
- plugin: LoadedNativePlugin,
527
+ execution: ITtscExecutionContext,
528
+ options: ITtscBuildOptions | ITtscTransformOptions,
529
+ plugin: ITtscLoadedNativePlugin,
577
530
  file: string,
578
531
  ): string[] {
579
532
  const args = [
@@ -591,11 +544,11 @@ function createNativeOutputArgs(
591
544
  }
592
545
 
593
546
  function createNativeTransformArgs(
594
- execution: ExecutionContext,
595
- options: TransformOptions,
547
+ execution: ITtscExecutionContext,
548
+ options: ITtscTransformOptions,
596
549
  sourceFile: string,
597
550
  out: string,
598
- plugins: readonly LoadedNativePlugin[],
551
+ plugins: readonly ITtscLoadedNativePlugin[],
599
552
  ): string[] {
600
553
  return [
601
554
  "transform",
@@ -607,7 +560,7 @@ function createNativeTransformArgs(
607
560
  ];
608
561
  }
609
562
 
610
- function serializeNativePlugins(plugins: readonly LoadedNativePlugin[]): string {
563
+ function serializeNativePlugins(plugins: readonly ITtscLoadedNativePlugin[]): string {
611
564
  return JSON.stringify(
612
565
  plugins.map((plugin) => ({
613
566
  config: plugin.config,
@@ -619,10 +572,10 @@ function serializeNativePlugins(plugins: readonly LoadedNativePlugin[]): string
619
572
  }
620
573
 
621
574
  function runNativeCheckPlugins(
622
- options: BuildOptions | TransformOptions,
623
- execution: ExecutionContext,
624
- ): BuildResult {
625
- let out: BuildResult = { status: 0, stdout: "", stderr: "" };
575
+ options: ITtscBuildOptions | ITtscTransformOptions,
576
+ execution: ITtscExecutionContext,
577
+ ): ITtscBuildResult {
578
+ let out: ITtscBuildResult = { status: 0, stdout: "", stderr: "" };
626
579
  for (const plugin of checkOnlyPlugins(execution.nativePlugins)) {
627
580
  const result = runNativePluginCommand(
628
581
  plugin,
@@ -640,12 +593,12 @@ function runNativeCheckPlugins(
640
593
  }
641
594
 
642
595
  function runNativeCompilerTransform(
643
- options: TransformOptions,
644
- execution: ExecutionContext,
596
+ options: ITtscTransformOptions,
597
+ execution: ITtscExecutionContext,
645
598
  sourceFile: string,
646
599
  out: string,
647
- plugins: readonly LoadedNativePlugin[],
648
- ): BuildResult {
600
+ plugins: readonly ITtscLoadedNativePlugin[],
601
+ ): ITtscBuildResult {
649
602
  return runNativePluginCommand(
650
603
  plugins[0]!,
651
604
  createNativeTransformArgs(execution, options, sourceFile, out, plugins),
@@ -656,12 +609,12 @@ function runNativeCompilerTransform(
656
609
  }
657
610
 
658
611
  function applyOutputPlugins(
659
- options: BuildOptions,
660
- execution: ExecutionContext,
612
+ options: ITtscBuildOptions,
613
+ execution: ITtscExecutionContext,
661
614
  emittedFiles: readonly string[],
662
- plugins: readonly LoadedNativePlugin[],
663
- ): BuildResult {
664
- let out: BuildResult = { status: 0, stdout: "", stderr: "" };
615
+ plugins: readonly ITtscLoadedNativePlugin[],
616
+ ): ITtscBuildResult {
617
+ let out: ITtscBuildResult = { status: 0, stdout: "", stderr: "" };
665
618
  for (const plugin of plugins) {
666
619
  for (const file of emittedFiles) {
667
620
  if (!fs.existsSync(file)) {
@@ -678,11 +631,11 @@ function applyOutputPlugins(
678
631
  }
679
632
 
680
633
  function runNativeOutputPlugin(
681
- options: BuildOptions | TransformOptions,
682
- execution: ExecutionContext,
683
- plugin: LoadedNativePlugin,
634
+ options: ITtscBuildOptions | ITtscTransformOptions,
635
+ execution: ITtscExecutionContext,
636
+ plugin: ITtscLoadedNativePlugin,
684
637
  file: string,
685
- ): BuildResult {
638
+ ): ITtscBuildResult {
686
639
  return runNativePluginCommand(
687
640
  plugin,
688
641
  createNativeOutputArgs(execution, options, plugin, file),
@@ -693,12 +646,12 @@ function runNativeOutputPlugin(
693
646
  }
694
647
 
695
648
  function runNativePluginCommand(
696
- plugin: LoadedNativePlugin,
649
+ plugin: ITtscLoadedNativePlugin,
697
650
  args: readonly string[],
698
- options: BuildOptions | TransformOptions,
699
- execution: ExecutionContext,
651
+ options: ITtscBuildOptions | ITtscTransformOptions,
652
+ execution: ITtscExecutionContext,
700
653
  label: string,
701
- ): BuildResult {
654
+ ): ITtscBuildResult {
702
655
  const binary = plugin.backend.binary;
703
656
  if (!binary) {
704
657
  return {
@@ -709,7 +662,7 @@ function runNativePluginCommand(
709
662
  }
710
663
  const res = spawnBinary(binary, args, {
711
664
  cwd: execution.projectRoot,
712
- env: mergeEnv(options.env),
665
+ env: nativePluginEnv(options.env, execution),
713
666
  encoding: "utf8",
714
667
  });
715
668
  if (res.error) {
@@ -724,7 +677,7 @@ function runNativePluginCommand(
724
677
  });
725
678
  }
726
679
 
727
- function appendBuildOutput(left: BuildResult, right: BuildResult): BuildResult {
680
+ function appendBuildOutput(left: ITtscBuildResult, right: ITtscBuildResult): ITtscBuildResult {
728
681
  return normalizeFailedDiagnostics({
729
682
  emittedFiles:
730
683
  right.emittedFiles !== undefined ? right.emittedFiles : left.emittedFiles,
@@ -734,7 +687,7 @@ function appendBuildOutput(left: BuildResult, right: BuildResult): BuildResult {
734
687
  });
735
688
  }
736
689
 
737
- function assertSingleCompilerHost(plugins: readonly LoadedNativePlugin[]): void {
690
+ function assertSingleCompilerHost(plugins: readonly ITtscLoadedNativePlugin[]): void {
738
691
  const binaries = [
739
692
  ...new Set(
740
693
  plugins
@@ -751,7 +704,7 @@ function assertSingleCompilerHost(plugins: readonly LoadedNativePlugin[]): void
751
704
  }
752
705
 
753
706
  /** Ask the binary for its version banner. Handy for user-agent strings. */
754
- export function version(options: CommonOptions = {}): string {
707
+ export function version(options: ITtscCommonOptions = {}): string {
755
708
  const tsgo = resolveTsgo(options);
756
709
  const res = spawnBinary(tsgo.binary, ["--version"], {
757
710
  encoding: "utf8",
@@ -769,22 +722,22 @@ export function version(options: CommonOptions = {}): string {
769
722
  * plugin descriptors can stay dependency-free, but many adapter surfaces still
770
723
  * prefer a Promise-returning function.
771
724
  */
772
- export function transformAsync(options: TransformOptions): Promise<string> {
725
+ export function transformAsync(options: ITtscTransformOptions): Promise<string> {
773
726
  return Promise.resolve().then(() => transform(options));
774
727
  }
775
728
 
776
- interface ExecutionContext {
729
+ interface ITtscExecutionContext {
777
730
  compilerOptions: Record<string, unknown>;
778
731
  cwd: string;
779
- nativePlugins: readonly LoadedNativePlugin[];
732
+ nativePlugins: readonly ITtscLoadedNativePlugin[];
780
733
  projectRoot: string;
781
- tsgo: ResolvedTsgo;
734
+ tsgo: ITtscResolvedTsgo;
782
735
  tsconfig: string;
783
736
  }
784
737
 
785
738
  function resolveExecutionContext(
786
- options: CommonOptions & { tsconfig?: string },
787
- ): ExecutionContext {
739
+ options: ITtscCommonOptions & { tsconfig?: string },
740
+ ): ITtscExecutionContext {
788
741
  const cwd = path.resolve(options.cwd ?? process.cwd());
789
742
  const tsconfig = resolveProjectConfig({
790
743
  cwd,
@@ -832,7 +785,7 @@ function stripEmittedFileLines(stdout: string): string {
832
785
  .replace(/\n+$/, "");
833
786
  }
834
787
 
835
- function normalizeFailedDiagnostics(result: BuildResult): BuildResult {
788
+ function normalizeFailedDiagnostics(result: ITtscBuildResult): ITtscBuildResult {
836
789
  if (result.status === 0 || result.stderr.trim().length !== 0) {
837
790
  return result;
838
791
  }
package/src/cli.ts CHANGED
@@ -3,8 +3,8 @@ import * as fs from "node:fs";
3
3
  import * as path from "node:path";
4
4
 
5
5
  import {
6
- type BuildOptions,
7
- type TransformOptions,
6
+ type ITtscBuildOptions,
7
+ type ITtscTransformOptions,
8
8
  build,
9
9
  check,
10
10
  transform,
@@ -70,7 +70,7 @@ function isBuildAlias(command: string): boolean {
70
70
  );
71
71
  }
72
72
 
73
- interface BuildInvocation extends BuildOptions {
73
+ interface ITtscBuildInvocation extends ITtscBuildOptions {
74
74
  files: string[];
75
75
  preserveWatchOutput: boolean;
76
76
  watch: boolean;
@@ -102,7 +102,7 @@ function runTransform(argv: readonly string[]): number {
102
102
  return 0;
103
103
  }
104
104
 
105
- interface CleanInvocation {
105
+ interface ITtscCleanInvocation {
106
106
  cwd?: string;
107
107
  tsconfig?: string;
108
108
  }
@@ -168,7 +168,7 @@ function delegateToNative(argv: readonly string[]): number {
168
168
  return result.status ?? 1;
169
169
  }
170
170
 
171
- function parseCleanArgs(argv: readonly string[]): CleanInvocation {
171
+ function parseCleanArgs(argv: readonly string[]): ITtscCleanInvocation {
172
172
  let cwd: string | undefined;
173
173
  let tsconfig: string | undefined;
174
174
 
@@ -203,7 +203,7 @@ function parseCleanArgs(argv: readonly string[]): CleanInvocation {
203
203
  function parseBuildArgs(
204
204
  argv: readonly string[],
205
205
  checkOnly: boolean,
206
- ): BuildInvocation {
206
+ ): ITtscBuildInvocation {
207
207
  let binary: string | undefined;
208
208
  let cwd: string | undefined;
209
209
  let emit: boolean | undefined = checkOnly ? false : undefined;
@@ -299,7 +299,7 @@ function parseBuildArgs(
299
299
  };
300
300
  }
301
301
 
302
- function parseTransformArgs(argv: readonly string[]): TransformOptions {
302
+ function parseTransformArgs(argv: readonly string[]): ITtscTransformOptions {
303
303
  let binary: string | undefined;
304
304
  let cwd: string | undefined;
305
305
  let file: string | undefined;
@@ -410,7 +410,7 @@ function printHelp(): void {
410
410
  process.stdout.write("\n");
411
411
  }
412
412
 
413
- function runSingleFile(options: BuildInvocation): number {
413
+ function runSingleFile(options: ITtscBuildInvocation): number {
414
414
  if (options.files.length !== 1) {
415
415
  throw new Error(
416
416
  "ttsc: single-file mode currently accepts exactly one input file",
@@ -448,9 +448,9 @@ function resolveSingleFileOut(
448
448
  return file.replace(/\.[cm]?tsx?$/i, ".js");
449
449
  }
450
450
 
451
- function runWatch(options: BuildInvocation, checkOnly: boolean): number {
451
+ function runWatch(options: ITtscBuildInvocation, checkOnly: boolean): number {
452
452
  const cwd = path.resolve(options.cwd ?? process.cwd());
453
- const invocation: BuildInvocation = {
453
+ const invocation: ITtscBuildInvocation = {
454
454
  ...options,
455
455
  cwd,
456
456
  quiet: true,
package/src/native.ts CHANGED
@@ -1,29 +1,15 @@
1
- export type NativeRewriteMode = string;
2
- export type NativePluginContractVersion = 1;
1
+ import type { ITtscNativeBackend } from "./structures/ITtscNativeBackend";
2
+ import type { ITtscNativePluginShape } from "./structures/ITtscNativePluginShape";
3
3
 
4
- export interface TtscNativeSource {
5
- dir: string;
6
- entry?: string;
7
- }
8
-
9
- export interface TtscNativeBackend {
10
- mode: NativeRewriteMode;
11
- binary?: string;
12
- source?: TtscNativeSource;
13
- contractVersion?: NativePluginContractVersion;
14
- capabilities?: readonly string[];
15
- }
16
-
17
- export interface TtscNativePluginShape {
18
- name: string;
19
- native?: TtscNativeBackend;
20
- nativeMode?: NativeRewriteMode;
21
- nativeBinary?: string;
22
- }
4
+ export type { ITtscNativeBackend } from "./structures/ITtscNativeBackend";
5
+ export type { ITtscNativePluginContractVersion } from "./structures/ITtscNativePluginContractVersion";
6
+ export type { ITtscNativePluginShape } from "./structures/ITtscNativePluginShape";
7
+ export type { ITtscNativeRewriteMode } from "./structures/ITtscNativeRewriteMode";
8
+ export type { ITtscNativeSource } from "./structures/ITtscNativeSource";
23
9
 
24
10
  export function resolveNativeBackend(
25
- plugin: TtscNativePluginShape,
26
- ): TtscNativeBackend | null {
11
+ plugin: ITtscNativePluginShape,
12
+ ): ITtscNativeBackend | null {
27
13
  if (plugin.native && (plugin.nativeMode || plugin.nativeBinary)) {
28
14
  throw new Error(
29
15
  `ttsc: plugin "${plugin.name}" must use either native or nativeMode/nativeBinary, not both`,