ttsc 0.3.1 → 0.4.0-dev.20260425
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +93 -362
- package/cmd/ttsc/build.go +128 -0
- package/cmd/ttsc/main.go +222 -0
- package/cmd/ttsc/main_test.go +288 -0
- package/cmd/ttsc/transform.go +166 -0
- package/driver/host.go +31 -0
- package/driver/program.go +298 -0
- package/driver/rewrite.go +315 -0
- package/go.mod +48 -0
- package/go.sum +22 -0
- package/lib/api.d.ts +91 -0
- package/lib/api.js +325 -0
- package/lib/api.js.map +1 -0
- package/lib/cli.d.ts +1 -0
- package/lib/cli.js +481 -0
- package/lib/cli.js.map +1 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.js +35 -0
- package/lib/index.js.map +1 -0
- package/lib/native.d.ts +15 -0
- package/lib/native.js +34 -0
- package/lib/native.js.map +1 -0
- package/lib/platform.d.ts +66 -0
- package/lib/platform.js +170 -0
- package/lib/platform.js.map +1 -0
- package/lib/plugin.d.ts +47 -0
- package/lib/plugin.js +150 -0
- package/lib/plugin.js.map +1 -0
- package/lib/project.d.ts +32 -0
- package/lib/project.js +303 -0
- package/lib/project.js.map +1 -0
- package/lib/runner/cli.d.ts +1 -0
- package/lib/runner/cli.js +284 -0
- package/lib/runner/cli.js.map +1 -0
- package/lib/runner/register.d.ts +13 -0
- package/lib/runner/register.js +424 -0
- package/lib/runner/register.js.map +1 -0
- package/package.json +72 -63
- package/shim/ast/extra-shim.json +4 -0
- package/shim/ast/go.mod +5 -0
- package/shim/ast/shim.go +117 -0
- package/shim/bundled/extra-shim.json +1 -0
- package/shim/bundled/go.mod +5 -0
- package/shim/bundled/shim.go +19 -0
- package/shim/checker/extra-shim.json +31 -0
- package/shim/checker/go.mod +5 -0
- package/shim/checker/shim.go +146 -0
- package/shim/compiler/extra-shim.json +4 -0
- package/shim/compiler/go.mod +5 -0
- package/shim/compiler/shim.go +50 -0
- package/shim/core/extra-shim.json +4 -0
- package/shim/core/go.mod +5 -0
- package/shim/core/shim.go +11 -0
- package/shim/diagnosticwriter/go.mod +5 -0
- package/shim/diagnosticwriter/shim.go +29 -0
- package/shim/parser/extra-shim.json +4 -0
- package/shim/parser/go.mod +5 -0
- package/shim/parser/shim.go +55 -0
- package/shim/scanner/extra-shim.json +4 -0
- package/shim/scanner/go.mod +5 -0
- package/shim/scanner/shim.go +96 -0
- package/shim/tsoptions/extra-shim.json +4 -0
- package/shim/tsoptions/go.mod +5 -0
- package/shim/tsoptions/shim.go +123 -0
- package/shim/tspath/extra-shim.json +4 -0
- package/shim/tspath/go.mod +5 -0
- package/shim/tspath/shim.go +165 -0
- package/shim/vfs/cachedvfs/extra-shim.json +4 -0
- package/shim/vfs/cachedvfs/go.mod +5 -0
- package/shim/vfs/cachedvfs/shim.go +12 -0
- package/shim/vfs/extra-shim.json +4 -0
- package/shim/vfs/go.mod +5 -0
- package/shim/vfs/osvfs/extra-shim.json +4 -0
- package/shim/vfs/osvfs/go.mod +5 -0
- package/shim/vfs/osvfs/shim.go +13 -0
- package/shim/vfs/shim.go +19 -0
- package/src/api.ts +416 -0
- package/src/cli.ts +492 -0
- package/src/index.ts +19 -0
- package/src/launcher/ttsc-dev.js +42 -0
- package/src/launcher/ttsc.js +19 -0
- package/src/launcher/ttsx.js +19 -0
- package/src/native.ts +60 -0
- package/src/platform.ts +163 -0
- package/src/plugin.ts +241 -0
- package/src/project.ts +330 -0
- package/src/runner/cli.ts +286 -0
- package/src/runner/register.ts +487 -0
- package/test/native.test.ts +60 -0
- package/test/package.test.ts +131 -0
- package/test/platform.test.ts +58 -0
- package/test/project.test.ts +195 -0
- package/tools/gen_shims/go.mod +14 -0
- package/tools/gen_shims/go.sum +12 -0
- package/tools/gen_shims/main.go +446 -0
- package/CHANGELOG.md +0 -2
- package/bin/tsc +0 -2
- package/bin/tsserver +0 -2
- package/lib/PluginCreator.d.ts +0 -67
- package/lib/PluginCreator.js +0 -190
- package/lib/cancelationToken.d.ts +0 -0
- package/lib/cancelationToken.js +0 -2
- package/lib/loadTypescript.d.ts +0 -7
- package/lib/loadTypescript.js +0 -56
- package/lib/patchCreateProgram.d.ts +0 -21
- package/lib/patchCreateProgram.js +0 -190
- package/lib/tsc.d.ts +0 -1
- package/lib/tsc.js +0 -24
- package/lib/tsserver.d.ts +0 -0
- package/lib/tsserver.js +0 -2
- package/lib/tsserverlibrary.d.ts +0 -3
- package/lib/tsserverlibrary.js +0 -4
- package/lib/typescript.d.ts +0 -3
- package/lib/typescript.js +0 -4
- package/lib/typescriptServices.d.ts +0 -3
- package/lib/typescriptServices.js +0 -4
- package/lib/typingsInstaller.d.ts +0 -0
- package/lib/typingsInstaller.js +0 -2
- package/lib/watchGuard.d.ts +0 -0
- package/lib/watchGuard.js +0 -2
package/lib/api.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type ResolveOptions } from "./platform";
|
|
2
|
+
import { type ProjectPluginConfig } from "./project";
|
|
3
|
+
/**
|
|
4
|
+
* Options shared by every API call. `binary` takes precedence over platform
|
|
5
|
+
* resolution; `cwd` defaults to `process.cwd()`; `env` layers on top of the
|
|
6
|
+
* current process env.
|
|
7
|
+
*/
|
|
8
|
+
export interface CommonOptions extends ResolveOptions {
|
|
9
|
+
/** Absolute path to an already-resolved ttsc binary. Skips resolution. */
|
|
10
|
+
binary?: string;
|
|
11
|
+
/** Working directory passed to the child process. */
|
|
12
|
+
cwd?: string;
|
|
13
|
+
/** Extra environment variables; merged onto `process.env`. */
|
|
14
|
+
env?: NodeJS.ProcessEnv;
|
|
15
|
+
/**
|
|
16
|
+
* Override project plugin loading. `false` disables tsconfig plugins; an
|
|
17
|
+
* array replaces the tsconfig `compilerOptions.plugins` list.
|
|
18
|
+
*/
|
|
19
|
+
plugins?: readonly ProjectPluginConfig[] | false;
|
|
20
|
+
/**
|
|
21
|
+
* Override the native rewrite backend. Defaults to the loaded plugin mode.
|
|
22
|
+
*
|
|
23
|
+
* @deprecated Prefer plugin-declared `native.mode`; this override is for
|
|
24
|
+
* low-level tests and migration probes.
|
|
25
|
+
*/
|
|
26
|
+
rewriteMode?: string;
|
|
27
|
+
}
|
|
28
|
+
/** Options for `transform()`. */
|
|
29
|
+
export interface TransformOptions extends CommonOptions {
|
|
30
|
+
/** Path to the .ts file to transform. Absolute or `cwd`-relative. */
|
|
31
|
+
file: string;
|
|
32
|
+
/** Path to the tsconfig owning `file`. Default: `tsconfig.json`. */
|
|
33
|
+
tsconfig?: string;
|
|
34
|
+
/**
|
|
35
|
+
* When provided, the binary writes JS directly to this path instead of piping
|
|
36
|
+
* stdout. Useful when the emitted text is large.
|
|
37
|
+
*/
|
|
38
|
+
out?: string;
|
|
39
|
+
}
|
|
40
|
+
/** Options for `build()`. */
|
|
41
|
+
export interface BuildOptions extends CommonOptions {
|
|
42
|
+
/** Path to tsconfig.json. Default: `tsconfig.json`. */
|
|
43
|
+
tsconfig?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Emit override. `true` forces emit, `false` forces noEmit, `undefined`
|
|
46
|
+
* follows tsconfig.
|
|
47
|
+
*/
|
|
48
|
+
emit?: boolean;
|
|
49
|
+
/** Override compilerOptions.outDir for this invocation. */
|
|
50
|
+
outDir?: string;
|
|
51
|
+
/** Suppress the per-call summary banner. Default: `true`. */
|
|
52
|
+
quiet?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** Options for `check()`. */
|
|
55
|
+
export type CheckOptions = Omit<BuildOptions, "emit">;
|
|
56
|
+
/**
|
|
57
|
+
* Transform a single .ts file and return the rewritten JS as a string.
|
|
58
|
+
*
|
|
59
|
+
* Intended for bundler per-file transforms (unplugin `transform()`). The caller
|
|
60
|
+
* passes the absolute path; ttsc loads the enclosing tsconfig, compiles with
|
|
61
|
+
* tsgo, and returns the rewritten JS.
|
|
62
|
+
*
|
|
63
|
+
* Throws when the binary exits non-zero — the error includes stderr so bundler
|
|
64
|
+
* error overlays surface the real cause.
|
|
65
|
+
*/
|
|
66
|
+
export declare function transform(options: TransformOptions): string;
|
|
67
|
+
/** Result of `build()`. Non-zero `status` means the build failed. */
|
|
68
|
+
export interface BuildResult {
|
|
69
|
+
status: number;
|
|
70
|
+
stdout: string;
|
|
71
|
+
stderr: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Run `ttsc` against a tsconfig. Returns once the binary exits so the caller
|
|
75
|
+
* can decide how to surface diagnostics. Does not throw on non-zero exit —
|
|
76
|
+
* bundler pipelines often want to continue and collect errors.
|
|
77
|
+
*/
|
|
78
|
+
export declare function build(options?: BuildOptions): BuildResult;
|
|
79
|
+
/**
|
|
80
|
+
* Run `ttsc check` (build without emit) — CI gate / pre-commit hook use.
|
|
81
|
+
* Resolves with an exit-code record; does not throw.
|
|
82
|
+
*/
|
|
83
|
+
export declare function check(options?: CheckOptions): BuildResult;
|
|
84
|
+
/** Ask the binary for its version banner. Handy for user-agent strings. */
|
|
85
|
+
export declare function version(options?: CommonOptions): string;
|
|
86
|
+
/**
|
|
87
|
+
* Promise-facing variant of `transform()`. The plugin host keeps the transform
|
|
88
|
+
* pipeline synchronous so plugin modules can stay dependency-free, but many
|
|
89
|
+
* adapter surfaces still prefer a Promise-returning function.
|
|
90
|
+
*/
|
|
91
|
+
export declare function transformAsync(options: TransformOptions): Promise<string>;
|
package/lib/api.js
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
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.transform = transform;
|
|
37
|
+
exports.build = build;
|
|
38
|
+
exports.check = check;
|
|
39
|
+
exports.version = version;
|
|
40
|
+
exports.transformAsync = transformAsync;
|
|
41
|
+
/**
|
|
42
|
+
* Programmatic API for ttsc.
|
|
43
|
+
*
|
|
44
|
+
* This module is the TypeScript surface bundler adapters (unplugin, vite,
|
|
45
|
+
* webpack, rollup, esbuild, rspack, farm, next/swc, bun) consume. Everything
|
|
46
|
+
* here is a thin wrapper around the Go binary resolved by `platform.ts` —
|
|
47
|
+
* adapters never have to spawn the process themselves.
|
|
48
|
+
*
|
|
49
|
+
* Contract:
|
|
50
|
+
*
|
|
51
|
+
* - `transform()` emits one file's rewritten JS, returning the text.
|
|
52
|
+
* - `build()` runs the whole project (tsgo + ttsc rewrite + --emit).
|
|
53
|
+
* - `check()` runs the analysis pass without emitting (CI gate use).
|
|
54
|
+
* - `version()` returns the binary's version banner for user-agent logs.
|
|
55
|
+
*
|
|
56
|
+
* All helpers accept a `binary` override so tests can point at a specific
|
|
57
|
+
* executable without touching PATH or node_modules.
|
|
58
|
+
*/
|
|
59
|
+
const node_child_process_1 = require("node:child_process");
|
|
60
|
+
const fs = __importStar(require("node:fs"));
|
|
61
|
+
const os = __importStar(require("node:os"));
|
|
62
|
+
const path = __importStar(require("node:path"));
|
|
63
|
+
const platform_1 = require("./platform");
|
|
64
|
+
const plugin_1 = require("./plugin");
|
|
65
|
+
const project_1 = require("./project");
|
|
66
|
+
/**
|
|
67
|
+
* Resolve the binary or throw a user-friendly error. Extracted so every API
|
|
68
|
+
* helper shares the same failure mode.
|
|
69
|
+
*/
|
|
70
|
+
function resolveOrThrow(opts) {
|
|
71
|
+
if (opts.binary &&
|
|
72
|
+
path.isAbsolute(opts.binary) &&
|
|
73
|
+
fs.existsSync(opts.binary)) {
|
|
74
|
+
return opts.binary;
|
|
75
|
+
}
|
|
76
|
+
const bin = (0, platform_1.resolveBinary)(opts);
|
|
77
|
+
if (!bin) {
|
|
78
|
+
throw new Error((0, platform_1.installHint)(opts));
|
|
79
|
+
}
|
|
80
|
+
return bin;
|
|
81
|
+
}
|
|
82
|
+
/** Merge spawn env without clobbering unrelated vars. */
|
|
83
|
+
function mergeEnv(extra) {
|
|
84
|
+
if (!extra)
|
|
85
|
+
return process.env;
|
|
86
|
+
return { ...process.env, ...extra };
|
|
87
|
+
}
|
|
88
|
+
function spawnBinary(binary, args, options) {
|
|
89
|
+
const viaNode = shouldSpawnViaNode(binary);
|
|
90
|
+
if (!viaNode) {
|
|
91
|
+
ensureExecutable(binary);
|
|
92
|
+
}
|
|
93
|
+
return (0, node_child_process_1.spawnSync)(viaNode ? process.execPath : binary, viaNode ? [binary, ...args] : [...args], {
|
|
94
|
+
cwd: options.cwd,
|
|
95
|
+
env: options.env,
|
|
96
|
+
encoding: options.encoding,
|
|
97
|
+
maxBuffer: 1024 * 1024 * 256,
|
|
98
|
+
windowsHide: true,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function shouldSpawnViaNode(binary) {
|
|
102
|
+
return /\.(?:[cm]?js|ts)$/i.test(binary);
|
|
103
|
+
}
|
|
104
|
+
function ensureExecutable(binary) {
|
|
105
|
+
if (process.platform === "win32") {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
const mode = fs.statSync(binary).mode & 0o777;
|
|
110
|
+
if ((mode & 0o111) !== 0) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
fs.chmodSync(binary, mode | 0o755);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
/* keep the original spawn error path */
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function outputText(value) {
|
|
120
|
+
if (value == null) {
|
|
121
|
+
return "";
|
|
122
|
+
}
|
|
123
|
+
return typeof value === "string" ? value : value.toString("utf8");
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Transform a single .ts file and return the rewritten JS as a string.
|
|
127
|
+
*
|
|
128
|
+
* Intended for bundler per-file transforms (unplugin `transform()`). The caller
|
|
129
|
+
* passes the absolute path; ttsc loads the enclosing tsconfig, compiles with
|
|
130
|
+
* tsgo, and returns the rewritten JS.
|
|
131
|
+
*
|
|
132
|
+
* Throws when the binary exits non-zero — the error includes stderr so bundler
|
|
133
|
+
* error overlays surface the real cause.
|
|
134
|
+
*/
|
|
135
|
+
function transform(options) {
|
|
136
|
+
const execution = resolveExecutionContext(options);
|
|
137
|
+
const sourceFile = realpathIfExists(path.isAbsolute(options.file)
|
|
138
|
+
? options.file
|
|
139
|
+
: path.resolve(options.cwd ?? process.cwd(), options.file));
|
|
140
|
+
const args = [
|
|
141
|
+
"transform",
|
|
142
|
+
"--file=" + sourceFile,
|
|
143
|
+
"--tsconfig=" + execution.tsconfig,
|
|
144
|
+
"--rewrite-mode=" + execution.nativeMode,
|
|
145
|
+
];
|
|
146
|
+
const res = spawnBinary(execution.bin, args, {
|
|
147
|
+
cwd: options.cwd,
|
|
148
|
+
env: mergeEnv(options.env),
|
|
149
|
+
encoding: "utf8",
|
|
150
|
+
});
|
|
151
|
+
if (res.error) {
|
|
152
|
+
throw new Error("ttsc.transform: failed to spawn " +
|
|
153
|
+
execution.bin +
|
|
154
|
+
": " +
|
|
155
|
+
res.error.message);
|
|
156
|
+
}
|
|
157
|
+
if (res.status !== 0) {
|
|
158
|
+
throw new Error("ttsc.transform exited " + res.status + "\n" + (res.stderr || ""));
|
|
159
|
+
}
|
|
160
|
+
const transformed = finalizeTransformText(execution.plugins, {
|
|
161
|
+
command: "transform",
|
|
162
|
+
cwd: execution.cwd,
|
|
163
|
+
projectRoot: execution.projectRoot,
|
|
164
|
+
sourceFile,
|
|
165
|
+
tsconfig: execution.tsconfig,
|
|
166
|
+
}, outputText(res.stdout));
|
|
167
|
+
if (options.out) {
|
|
168
|
+
fs.mkdirSync(path.dirname(options.out), { recursive: true });
|
|
169
|
+
fs.writeFileSync(options.out, transformed, "utf8");
|
|
170
|
+
}
|
|
171
|
+
return transformed;
|
|
172
|
+
}
|
|
173
|
+
function realpathIfExists(file) {
|
|
174
|
+
try {
|
|
175
|
+
return fs.realpathSync(file);
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return file;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Run `ttsc` against a tsconfig. Returns once the binary exits so the caller
|
|
183
|
+
* can decide how to surface diagnostics. Does not throw on non-zero exit —
|
|
184
|
+
* bundler pipelines often want to continue and collect errors.
|
|
185
|
+
*/
|
|
186
|
+
function build(options = {}) {
|
|
187
|
+
const execution = resolveExecutionContext(options);
|
|
188
|
+
const args = [
|
|
189
|
+
"build",
|
|
190
|
+
"--tsconfig=" + execution.tsconfig,
|
|
191
|
+
"--rewrite-mode=" + execution.nativeMode,
|
|
192
|
+
];
|
|
193
|
+
if (options.emit === true)
|
|
194
|
+
args.push("--emit");
|
|
195
|
+
else if (options.emit === false)
|
|
196
|
+
args.push("--noEmit");
|
|
197
|
+
if (options.outDir)
|
|
198
|
+
args.push("--outDir=" + options.outDir);
|
|
199
|
+
if (options.quiet === false)
|
|
200
|
+
args.push("--verbose");
|
|
201
|
+
else if (options.quiet === true)
|
|
202
|
+
args.push("--quiet");
|
|
203
|
+
const needsManifest = options.emit !== false && execution.plugins.length > 0;
|
|
204
|
+
const manifest = needsManifest ? createTempManifestPath() : null;
|
|
205
|
+
if (manifest)
|
|
206
|
+
args.push("--manifest=" + manifest);
|
|
207
|
+
const res = spawnBinary(execution.bin, args, {
|
|
208
|
+
cwd: options.cwd,
|
|
209
|
+
env: mergeEnv(options.env),
|
|
210
|
+
encoding: "utf8",
|
|
211
|
+
});
|
|
212
|
+
if (res.error) {
|
|
213
|
+
throw new Error("ttsc.build: failed to spawn " + execution.bin + ": " + res.error.message);
|
|
214
|
+
}
|
|
215
|
+
if ((res.status ?? 1) === 0 && manifest) {
|
|
216
|
+
try {
|
|
217
|
+
const emittedFiles = JSON.parse(fs.readFileSync(manifest, "utf8"));
|
|
218
|
+
applyBuildPlugins(execution.plugins, execution, emittedFiles);
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
fs.rmSync(path.dirname(manifest), { recursive: true, force: true });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
status: res.status ?? 1,
|
|
226
|
+
stdout: outputText(res.stdout),
|
|
227
|
+
stderr: outputText(res.stderr),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Run `ttsc check` (build without emit) — CI gate / pre-commit hook use.
|
|
232
|
+
* Resolves with an exit-code record; does not throw.
|
|
233
|
+
*/
|
|
234
|
+
function check(options = {}) {
|
|
235
|
+
return build({ ...options, emit: false });
|
|
236
|
+
}
|
|
237
|
+
/** Ask the binary for its version banner. Handy for user-agent strings. */
|
|
238
|
+
function version(options = {}) {
|
|
239
|
+
const bin = resolveOrThrow(options);
|
|
240
|
+
const res = spawnBinary(bin, ["version"], {
|
|
241
|
+
encoding: "utf8",
|
|
242
|
+
});
|
|
243
|
+
if (res.error || res.status !== 0) {
|
|
244
|
+
throw new Error("ttsc.version: failed: " + (outputText(res.stderr) || res.error?.message));
|
|
245
|
+
}
|
|
246
|
+
return outputText(res.stdout).trim();
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Promise-facing variant of `transform()`. The plugin host keeps the transform
|
|
250
|
+
* pipeline synchronous so plugin modules can stay dependency-free, but many
|
|
251
|
+
* adapter surfaces still prefer a Promise-returning function.
|
|
252
|
+
*/
|
|
253
|
+
function transformAsync(options) {
|
|
254
|
+
return Promise.resolve().then(() => transform(options));
|
|
255
|
+
}
|
|
256
|
+
function resolveExecutionContext(options) {
|
|
257
|
+
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
258
|
+
const fallbackBinary = options.binary &&
|
|
259
|
+
path.isAbsolute(options.binary) &&
|
|
260
|
+
fs.existsSync(options.binary)
|
|
261
|
+
? options.binary
|
|
262
|
+
: (0, platform_1.resolveBinary)(options);
|
|
263
|
+
const tsconfig = (0, project_1.resolveProjectConfig)({
|
|
264
|
+
cwd,
|
|
265
|
+
tsconfig: options.tsconfig,
|
|
266
|
+
});
|
|
267
|
+
const projectRoot = (0, project_1.resolveProjectRoot)({ cwd, tsconfig });
|
|
268
|
+
const loaded = (0, plugin_1.loadProjectPlugins)({
|
|
269
|
+
binary: fallbackBinary ?? "",
|
|
270
|
+
cwd,
|
|
271
|
+
entries: options.plugins,
|
|
272
|
+
tsconfig,
|
|
273
|
+
});
|
|
274
|
+
const bin = options.binary ?? loaded.nativeBinary ?? fallbackBinary;
|
|
275
|
+
if (!bin) {
|
|
276
|
+
throw new Error((0, platform_1.installHint)(options));
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
bin,
|
|
280
|
+
cwd,
|
|
281
|
+
nativeMode: options.rewriteMode ?? loaded.nativeMode,
|
|
282
|
+
plugins: loaded.plugins.filter((plugin) => plugin.transformOutput),
|
|
283
|
+
projectRoot,
|
|
284
|
+
tsconfig,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function finalizeTransformText(plugins, context, text) {
|
|
288
|
+
if (plugins.length === 0) {
|
|
289
|
+
return text;
|
|
290
|
+
}
|
|
291
|
+
return (0, plugin_1.applyPluginTransforms)(plugins, {
|
|
292
|
+
...context,
|
|
293
|
+
code: text,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
function applyBuildPlugins(plugins, execution, emittedFiles) {
|
|
297
|
+
if (plugins.length === 0) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
for (const file of emittedFiles) {
|
|
301
|
+
if (!isJavaScriptOutput(file) || !fs.existsSync(file)) {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
const current = fs.readFileSync(file, "utf8");
|
|
305
|
+
const next = (0, plugin_1.applyPluginTransforms)(plugins, {
|
|
306
|
+
code: current,
|
|
307
|
+
command: "build",
|
|
308
|
+
cwd: execution.cwd,
|
|
309
|
+
outputFile: file,
|
|
310
|
+
projectRoot: execution.projectRoot,
|
|
311
|
+
tsconfig: execution.tsconfig,
|
|
312
|
+
});
|
|
313
|
+
if (next !== current) {
|
|
314
|
+
fs.writeFileSync(file, next, "utf8");
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function isJavaScriptOutput(file) {
|
|
319
|
+
return /\.(?:[cm]?js)$/i.test(file);
|
|
320
|
+
}
|
|
321
|
+
function createTempManifestPath() {
|
|
322
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-build-"));
|
|
323
|
+
return path.join(dir, "manifest.json");
|
|
324
|
+
}
|
|
325
|
+
//# sourceMappingURL=api.js.map
|
package/lib/api.js.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