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.
- package/README.md +1 -1
- package/go.mod +1 -1
- package/go.sum +2 -2
- package/lib/api.d.ts +15 -67
- package/lib/api.js +14 -3
- package/lib/api.js.map +1 -1
- package/lib/cli.js.map +1 -1
- package/lib/native.d.ts +8 -20
- package/lib/native.js.map +1 -1
- package/lib/platform.d.ts +7 -25
- package/lib/platform.js.map +1 -1
- package/lib/plugin.d.ts +13 -41
- package/lib/plugin.js +2 -2
- package/lib/plugin.js.map +1 -1
- package/lib/project.d.ts +11 -29
- package/lib/project.js.map +1 -1
- package/lib/runner/cli.js.map +1 -1
- package/lib/runner/register.d.ts +6 -13
- package/lib/runner/register.js.map +1 -1
- package/lib/source-build.d.ts +11 -22
- package/lib/source-build.js +25 -1
- package/lib/source-build.js.map +1 -1
- package/lib/structures/ITtscBuildOptions.d.ts +14 -0
- package/lib/structures/ITtscBuildOptions.js +3 -0
- package/lib/structures/ITtscBuildOptions.js.map +1 -0
- package/lib/structures/ITtscBuildResult.d.ts +6 -0
- package/lib/structures/ITtscBuildResult.js +3 -0
- package/lib/structures/ITtscBuildResult.js.map +1 -0
- package/lib/structures/ITtscBuildSourcePluginOptions.d.ts +8 -0
- package/lib/structures/ITtscBuildSourcePluginOptions.js +3 -0
- package/lib/structures/ITtscBuildSourcePluginOptions.js.map +1 -0
- package/lib/structures/ITtscCacheKeyInput.d.ts +7 -0
- package/lib/structures/ITtscCacheKeyInput.js +3 -0
- package/lib/structures/ITtscCacheKeyInput.js.map +1 -0
- package/lib/structures/ITtscCheckOptions.d.ts +2 -0
- package/lib/structures/ITtscCheckOptions.js +3 -0
- package/lib/structures/ITtscCheckOptions.js.map +1 -0
- package/lib/structures/ITtscCommonOptions.d.ts +22 -0
- package/lib/structures/ITtscCommonOptions.js +3 -0
- package/lib/structures/ITtscCommonOptions.js.map +1 -0
- package/lib/structures/ITtscLoadPluginsOptions.d.ts +8 -0
- package/lib/structures/ITtscLoadPluginsOptions.js +3 -0
- package/lib/structures/ITtscLoadPluginsOptions.js.map +1 -0
- package/lib/structures/ITtscLoadedNativePlugin.d.ts +7 -0
- package/lib/structures/ITtscLoadedNativePlugin.js +3 -0
- package/lib/structures/ITtscLoadedNativePlugin.js.map +1 -0
- package/lib/structures/ITtscLoadedPlugins.d.ts +11 -0
- package/lib/structures/ITtscLoadedPlugins.js +3 -0
- package/lib/structures/ITtscLoadedPlugins.js.map +1 -0
- package/lib/structures/ITtscNativeBackend.d.ts +10 -0
- package/lib/structures/ITtscNativeBackend.js +3 -0
- package/lib/structures/ITtscNativeBackend.js.map +1 -0
- package/lib/structures/ITtscNativePluginContractVersion.d.ts +1 -0
- package/lib/structures/ITtscNativePluginContractVersion.js +3 -0
- package/lib/structures/ITtscNativePluginContractVersion.js.map +1 -0
- package/lib/structures/ITtscNativePluginShape.d.ts +8 -0
- package/lib/structures/ITtscNativePluginShape.js +3 -0
- package/lib/structures/ITtscNativePluginShape.js.map +1 -0
- package/lib/structures/ITtscNativeRewriteMode.d.ts +1 -0
- package/lib/structures/ITtscNativeRewriteMode.js +3 -0
- package/lib/structures/ITtscNativeRewriteMode.js.map +1 -0
- package/lib/structures/ITtscNativeSource.d.ts +4 -0
- package/lib/structures/ITtscNativeSource.js +3 -0
- package/lib/structures/ITtscNativeSource.js.map +1 -0
- package/lib/structures/ITtscParsedProjectConfig.d.ts +9 -0
- package/lib/structures/ITtscParsedProjectConfig.js +3 -0
- package/lib/structures/ITtscParsedProjectConfig.js.map +1 -0
- package/lib/structures/ITtscPlugin.d.ts +10 -0
- package/lib/structures/ITtscPlugin.js +3 -0
- package/lib/structures/ITtscPlugin.js.map +1 -0
- package/lib/structures/ITtscPluginFactory.d.ts +4 -0
- package/lib/structures/ITtscPluginFactory.js +3 -0
- package/lib/structures/ITtscPluginFactory.js.map +1 -0
- package/lib/structures/ITtscPluginFactoryContext.d.ts +8 -0
- package/lib/structures/ITtscPluginFactoryContext.js +3 -0
- package/lib/structures/ITtscPluginFactoryContext.js.map +1 -0
- package/lib/structures/ITtscPluginModule.d.ts +3 -0
- package/lib/structures/ITtscPluginModule.js +3 -0
- package/lib/structures/ITtscPluginModule.js.map +1 -0
- package/lib/structures/ITtscPreparedExecution.d.ts +5 -0
- package/lib/structures/ITtscPreparedExecution.js +3 -0
- package/lib/structures/ITtscPreparedExecution.js.map +1 -0
- package/lib/structures/ITtscProjectLocatorOptions.d.ts +5 -0
- package/lib/structures/ITtscProjectLocatorOptions.js +3 -0
- package/lib/structures/ITtscProjectLocatorOptions.js.map +1 -0
- package/lib/structures/ITtscProjectPluginConfig.d.ts +5 -0
- package/lib/structures/ITtscProjectPluginConfig.js +3 -0
- package/lib/structures/ITtscProjectPluginConfig.js.map +1 -0
- package/lib/structures/ITtscRegisterOptions.d.ts +6 -0
- package/lib/structures/ITtscRegisterOptions.js +3 -0
- package/lib/structures/ITtscRegisterOptions.js.map +1 -0
- package/lib/structures/ITtscResolveGoBinaryOptions.d.ts +7 -0
- package/lib/structures/ITtscResolveGoBinaryOptions.js +3 -0
- package/lib/structures/ITtscResolveGoBinaryOptions.js.map +1 -0
- package/lib/structures/ITtscResolveOptions.d.ts +20 -0
- package/lib/structures/ITtscResolveOptions.js +3 -0
- package/lib/structures/ITtscResolveOptions.js.map +1 -0
- package/lib/structures/ITtscResolvedTsgo.d.ts +8 -0
- package/lib/structures/ITtscResolvedTsgo.js +3 -0
- package/lib/structures/ITtscResolvedTsgo.js.map +1 -0
- package/lib/structures/ITtscTransformOptions.d.ts +12 -0
- package/lib/structures/ITtscTransformOptions.js +3 -0
- package/lib/structures/ITtscTransformOptions.js.map +1 -0
- package/lib/structures/ITtscTsgoResolveOptions.d.ts +14 -0
- package/lib/structures/ITtscTsgoResolveOptions.js +3 -0
- package/lib/structures/ITtscTsgoResolveOptions.js.map +1 -0
- package/lib/tsgo.d.ts +6 -24
- package/lib/tsgo.js.map +1 -1
- package/package.json +10 -10
- package/shim/ast/go.mod +1 -1
- package/shim/ast/lint.go +2 -0
- package/shim/bundled/go.mod +1 -1
- package/shim/checker/go.mod +1 -1
- package/shim/compiler/go.mod +1 -1
- package/shim/core/go.mod +1 -1
- package/shim/diagnosticwriter/go.mod +1 -1
- package/shim/parser/go.mod +1 -1
- package/shim/scanner/go.mod +1 -1
- package/shim/tsoptions/go.mod +1 -1
- package/shim/tspath/go.mod +1 -1
- package/shim/vfs/cachedvfs/go.mod +1 -1
- package/shim/vfs/go.mod +1 -1
- package/shim/vfs/osvfs/go.mod +1 -1
- package/src/api.ts +108 -155
- package/src/cli.ts +10 -10
- package/src/native.ts +9 -23
- package/src/platform.ts +10 -27
- package/src/plugin.ts +37 -74
- package/src/project.ts +18 -37
- package/src/runner/cli.ts +5 -5
- package/src/runner/register.ts +32 -43
- package/src/source-build.ts +45 -25
- package/src/structures/ITtscBuildOptions.ts +19 -0
- package/src/structures/ITtscBuildResult.ts +6 -0
- package/src/structures/ITtscBuildSourcePluginOptions.ts +9 -0
- package/src/structures/ITtscCacheKeyInput.ts +7 -0
- package/src/structures/ITtscCheckOptions.ts +3 -0
- package/src/structures/ITtscCommonOptions.ts +23 -0
- package/src/structures/ITtscLoadPluginsOptions.ts +9 -0
- package/src/structures/ITtscLoadedNativePlugin.ts +8 -0
- package/src/structures/ITtscLoadedPlugins.ts +12 -0
- package/src/structures/ITtscNativeBackend.ts +11 -0
- package/src/structures/ITtscNativePluginContractVersion.ts +1 -0
- package/src/structures/ITtscNativePluginShape.ts +9 -0
- package/src/structures/ITtscNativeRewriteMode.ts +1 -0
- package/src/structures/ITtscNativeSource.ts +4 -0
- package/src/structures/ITtscParsedProjectConfig.ts +10 -0
- package/src/structures/ITtscPlugin.ts +11 -0
- package/src/structures/ITtscPluginFactory.ts +7 -0
- package/src/structures/ITtscPluginFactoryContext.ts +9 -0
- package/src/structures/ITtscPluginModule.ts +4 -0
- package/src/structures/ITtscPreparedExecution.ts +5 -0
- package/src/structures/ITtscProjectLocatorOptions.ts +5 -0
- package/src/structures/ITtscProjectPluginConfig.ts +5 -0
- package/src/structures/ITtscRegisterOptions.ts +7 -0
- package/src/structures/ITtscResolveGoBinaryOptions.ts +7 -0
- package/src/structures/ITtscResolveOptions.ts +20 -0
- package/src/structures/ITtscResolvedTsgo.ts +8 -0
- package/src/structures/ITtscTransformOptions.ts +13 -0
- package/src/structures/ITtscTsgoResolveOptions.ts +14 -0
- package/src/tsgo.ts +6 -24
- 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
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} from "./
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} from "./project";
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
100
|
-
|
|
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:
|
|
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:
|
|
123
|
+
function isOutputPlugin(plugin: ITtscLoadedNativePlugin): boolean {
|
|
163
124
|
return hasCapability(plugin, "output");
|
|
164
125
|
}
|
|
165
126
|
|
|
166
|
-
function isCheckOnlyPlugin(plugin:
|
|
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:
|
|
135
|
+
function isCompilerPlugin(plugin: ITtscLoadedNativePlugin): boolean {
|
|
175
136
|
return !isOutputPlugin(plugin) && !isCheckOnlyPlugin(plugin);
|
|
176
137
|
}
|
|
177
138
|
|
|
178
139
|
function outputPlugins(
|
|
179
|
-
plugins: readonly
|
|
180
|
-
):
|
|
140
|
+
plugins: readonly ITtscLoadedNativePlugin[],
|
|
141
|
+
): ITtscLoadedNativePlugin[] {
|
|
181
142
|
return plugins.filter(isOutputPlugin);
|
|
182
143
|
}
|
|
183
144
|
|
|
184
145
|
function checkOnlyPlugins(
|
|
185
|
-
plugins: readonly
|
|
186
|
-
):
|
|
146
|
+
plugins: readonly ITtscLoadedNativePlugin[],
|
|
147
|
+
): ITtscLoadedNativePlugin[] {
|
|
187
148
|
return plugins.filter(isCheckOnlyPlugin);
|
|
188
149
|
}
|
|
189
150
|
|
|
190
151
|
function compilerPlugins(
|
|
191
|
-
plugins: readonly
|
|
192
|
-
):
|
|
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:
|
|
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:
|
|
251
|
-
execution:
|
|
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:
|
|
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:
|
|
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:
|
|
426
|
-
execution:
|
|
427
|
-
plugins: readonly
|
|
428
|
-
):
|
|
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:
|
|
395
|
+
export function check(options: ITtscCheckOptions = {}): ITtscBuildResult {
|
|
443
396
|
return build({ ...options, emit: false });
|
|
444
397
|
}
|
|
445
398
|
|
|
446
399
|
function runTsgo(
|
|
447
|
-
execution:
|
|
400
|
+
execution: ITtscExecutionContext,
|
|
448
401
|
extraArgs: readonly string[],
|
|
449
|
-
options:
|
|
450
|
-
):
|
|
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:
|
|
474
|
-
options:
|
|
426
|
+
execution: ITtscExecutionContext,
|
|
427
|
+
options: ITtscBuildOptions,
|
|
475
428
|
args: readonly string[],
|
|
476
|
-
):
|
|
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:
|
|
504
|
-
options:
|
|
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:
|
|
524
|
-
options:
|
|
525
|
-
plugins: readonly
|
|
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:
|
|
552
|
-
options:
|
|
553
|
-
plugin:
|
|
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:
|
|
575
|
-
options:
|
|
576
|
-
plugin:
|
|
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:
|
|
595
|
-
options:
|
|
547
|
+
execution: ITtscExecutionContext,
|
|
548
|
+
options: ITtscTransformOptions,
|
|
596
549
|
sourceFile: string,
|
|
597
550
|
out: string,
|
|
598
|
-
plugins: readonly
|
|
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
|
|
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:
|
|
623
|
-
execution:
|
|
624
|
-
):
|
|
625
|
-
let out:
|
|
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:
|
|
644
|
-
execution:
|
|
596
|
+
options: ITtscTransformOptions,
|
|
597
|
+
execution: ITtscExecutionContext,
|
|
645
598
|
sourceFile: string,
|
|
646
599
|
out: string,
|
|
647
|
-
plugins: readonly
|
|
648
|
-
):
|
|
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:
|
|
660
|
-
execution:
|
|
612
|
+
options: ITtscBuildOptions,
|
|
613
|
+
execution: ITtscExecutionContext,
|
|
661
614
|
emittedFiles: readonly string[],
|
|
662
|
-
plugins: readonly
|
|
663
|
-
):
|
|
664
|
-
let out:
|
|
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:
|
|
682
|
-
execution:
|
|
683
|
-
plugin:
|
|
634
|
+
options: ITtscBuildOptions | ITtscTransformOptions,
|
|
635
|
+
execution: ITtscExecutionContext,
|
|
636
|
+
plugin: ITtscLoadedNativePlugin,
|
|
684
637
|
file: string,
|
|
685
|
-
):
|
|
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:
|
|
649
|
+
plugin: ITtscLoadedNativePlugin,
|
|
697
650
|
args: readonly string[],
|
|
698
|
-
options:
|
|
699
|
-
execution:
|
|
651
|
+
options: ITtscBuildOptions | ITtscTransformOptions,
|
|
652
|
+
execution: ITtscExecutionContext,
|
|
700
653
|
label: string,
|
|
701
|
-
):
|
|
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:
|
|
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:
|
|
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
|
|
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:
|
|
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:
|
|
725
|
+
export function transformAsync(options: ITtscTransformOptions): Promise<string> {
|
|
773
726
|
return Promise.resolve().then(() => transform(options));
|
|
774
727
|
}
|
|
775
728
|
|
|
776
|
-
interface
|
|
729
|
+
interface ITtscExecutionContext {
|
|
777
730
|
compilerOptions: Record<string, unknown>;
|
|
778
731
|
cwd: string;
|
|
779
|
-
nativePlugins: readonly
|
|
732
|
+
nativePlugins: readonly ITtscLoadedNativePlugin[];
|
|
780
733
|
projectRoot: string;
|
|
781
|
-
tsgo:
|
|
734
|
+
tsgo: ITtscResolvedTsgo;
|
|
782
735
|
tsconfig: string;
|
|
783
736
|
}
|
|
784
737
|
|
|
785
738
|
function resolveExecutionContext(
|
|
786
|
-
options:
|
|
787
|
-
):
|
|
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:
|
|
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
|
|
7
|
-
type
|
|
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
|
|
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
|
|
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[]):
|
|
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
|
-
):
|
|
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[]):
|
|
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:
|
|
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:
|
|
451
|
+
function runWatch(options: ITtscBuildInvocation, checkOnly: boolean): number {
|
|
452
452
|
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
453
|
-
const invocation:
|
|
453
|
+
const invocation: ITtscBuildInvocation = {
|
|
454
454
|
...options,
|
|
455
455
|
cwd,
|
|
456
456
|
quiet: true,
|
package/src/native.ts
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { ITtscNativeBackend } from "./structures/ITtscNativeBackend";
|
|
2
|
+
import type { ITtscNativePluginShape } from "./structures/ITtscNativePluginShape";
|
|
3
3
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
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:
|
|
26
|
-
):
|
|
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`,
|