ttsc 0.23.0 → 0.25.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.
- package/LICENSE +21 -21
- package/README.md +66 -63
- package/cmd/ttscgraph/serve.go +264 -48
- package/cmd/ttscgraph/serve_answers_a_project_that_implements_its_own_ambient_declaration_test.go +69 -0
- package/cmd/ttscgraph/serve_early_error_encode_failure_is_observable_test.go +40 -0
- package/cmd/ttscgraph/serve_graph_snapshot_version_matches_typescript_client_test.go +32 -0
- package/cmd/ttscgraph/serve_phase_trace_accounts_for_load_failure_test.go +45 -0
- package/cmd/ttscgraph/serve_phase_trace_is_opt_in_and_payload_free_test.go +52 -0
- package/cmd/ttscgraph/serve_protocol_negotiates_incremental_shards_test.go +44 -0
- package/cmd/ttscgraph/serve_session_reloads_commonjs_package_entry_for_esm_test.go +2 -2
- package/cmd/ttscgraph/serve_session_reloads_superseding_module_candidates_test.go +46 -20
- package/cmd/ttscgraph/serve_session_retries_failed_dump_test.go +9 -9
- package/cmd/ttscgraph/serve_shards.go +1390 -0
- package/cmd/ttscgraph/serve_shards_abandoned_generation_converges_on_retry_test.go +92 -0
- package/cmd/ttscgraph/serve_shards_delete_removed_source_test.go +57 -0
- package/cmd/ttscgraph/serve_shards_external_endpoints_test.go +53 -0
- package/cmd/ttscgraph/serve_shards_keep_source_distributed_dependencies_at_the_boundary_test.go +108 -0
- package/cmd/ttscgraph/serve_shards_match_full_dump_oracle_test.go +88 -0
- package/cmd/ttscgraph/serve_shards_merge_pending_and_new_edits_test.go +50 -0
- package/cmd/ttscgraph/serve_shards_prune_unreferenced_external_endpoints_test.go +65 -0
- package/cmd/ttscgraph/serve_shards_publish_created_source_test.go +92 -0
- package/cmd/ttscgraph/serve_shards_rebuild_declaration_edit_test.go +43 -0
- package/cmd/ttscgraph/serve_shards_refresh_cross_file_implementation_test.go +63 -0
- package/cmd/ttscgraph/serve_shards_refresh_dependent_diagnostics_test.go +80 -0
- package/cmd/ttscgraph/serve_shards_rename_moves_source_identity_test.go +95 -0
- package/cmd/ttscgraph/serve_shards_retry_preserves_committed_generation_test.go +48 -0
- package/cmd/ttscgraph/serve_shards_reuse_unaffected_sources_test.go +121 -0
- package/driver/declaration_shape.go +85 -0
- package/driver/program.go +39 -10
- package/go.sum +22 -22
- package/internal/graph/assigned_implementations_of_declaration_file_symbols_leave_no_edge_source_test.go +84 -0
- package/internal/graph/assigned_implementations_of_node_modules_symbols_leave_no_edge_source_test.go +85 -0
- package/internal/graph/build.go +62 -10
- package/internal/graph/build_files_reuses_committed_cross_file_endpoints_test.go +87 -0
- package/internal/graph/build_keeps_source_distributed_dependencies_at_the_external_boundary_test.go +74 -0
- package/internal/graph/dump.go +84 -43
- package/internal/graph/dump_path_mapper_caches_alias_resolution_test.go +29 -0
- package/internal/graph/dump_paths.go +134 -11
- package/internal/graph/dump_paths_canonicalize_windows_short_root_test.go +39 -0
- package/internal/graph/dump_rejects_provenance_only_path_errors_test.go +32 -0
- package/internal/graph/dump_serializes_the_full_graph_test.go +2 -2
- package/internal/graph/dump_symlink_project_publishes_matching_base_test.go +82 -0
- package/internal/graph/edges.go +73 -17
- package/internal/graph/exports.go +9 -2
- package/internal/graph/graph.go +47 -7
- package/internal/graph/graph_kind_contracts_match_their_producers_test.go +121 -0
- package/internal/graph/node_modifiers_emit_union_strings_test.go +1 -1
- package/internal/graph/provenance.go +11 -1
- package/internal/graph/resolve.go +1 -4
- package/internal/graph/source.go +23 -0
- package/internal/graph/wire_node_ids_share_alias_resolution_test.go +29 -0
- package/internal/lspserver/lsp_native_plugin_source.go +5 -6
- package/internal/lspserver/lsp_native_resident.go +17 -24
- package/lib/TtscService.d.ts +1 -6
- package/lib/TtscService.js +2 -2
- package/lib/TtscService.js.map +1 -1
- package/lib/compiler/internal/captureProcessOutput.d.ts +26 -0
- package/lib/compiler/internal/captureProcessOutput.js +92 -0
- package/lib/compiler/internal/captureProcessOutput.js.map +1 -0
- package/lib/compiler/internal/compileProjectInMemory.js +4 -7
- package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
- package/lib/compiler/internal/residentCheckProcess.d.ts +0 -2
- package/lib/compiler/internal/residentCheckProcess.js +1 -15
- package/lib/compiler/internal/residentCheckProcess.js.map +1 -1
- package/lib/compiler/internal/residentTransformProcess.d.ts +0 -6
- package/lib/compiler/internal/residentTransformProcess.js +0 -25
- package/lib/compiler/internal/residentTransformProcess.js.map +1 -1
- package/lib/compiler/internal/spawnNative.d.ts +14 -6
- package/lib/compiler/internal/spawnNative.js +32 -11
- package/lib/compiler/internal/spawnNative.js.map +1 -1
- package/lib/compiler/internal/startResidentTransform.d.ts +1 -5
- package/lib/compiler/internal/startResidentTransform.js +1 -3
- package/lib/compiler/internal/startResidentTransform.js.map +1 -1
- package/lib/launcher/internal/prepareExecution.d.ts +2 -1
- package/lib/launcher/internal/prepareExecution.js +269 -23
- package/lib/launcher/internal/prepareExecution.js.map +1 -1
- package/lib/launcher/internal/registerRuntimeHooks.js +6 -1
- package/lib/launcher/internal/registerRuntimeHooks.js.map +1 -1
- package/lib/launcher/internal/runTtscserver.js +4 -9
- package/lib/launcher/internal/runTtscserver.js.map +1 -1
- package/lib/launcher/internal/runTtsx.js +2 -55
- package/lib/launcher/internal/runTtsx.js.map +1 -1
- package/lib/launcher/internal/runtimeHooks.d.ts +25 -2
- package/lib/launcher/internal/runtimeHooks.js +344 -69
- package/lib/launcher/internal/runtimeHooks.js.map +1 -1
- package/lib/plugin/internal/buildSourcePlugin.js +31 -3
- package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
- package/lib/plugin/internal/descriptorProcessFailure.d.ts +23 -19
- package/lib/plugin/internal/descriptorProcessFailure.js +40 -51
- package/lib/plugin/internal/descriptorProcessFailure.js.map +1 -1
- package/lib/plugin/internal/loadProjectPlugins.d.ts +12 -0
- package/lib/plugin/internal/loadProjectPlugins.js +77 -28
- package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
- package/package.json +8 -8
- package/shim/ast/extra-shim.json +4 -4
- package/shim/ast/go.mod +14 -14
- package/shim/ast/go.sum +20 -20
- package/shim/astnav/go.mod +14 -14
- package/shim/astnav/go.sum +20 -20
- package/shim/bundled/extra-shim.json +1 -1
- package/shim/bundled/go.mod +5 -5
- package/shim/checker/extra-shim.json +31 -31
- package/shim/checker/go.mod +5 -5
- package/shim/compiler/extra-shim.json +4 -4
- package/shim/compiler/go.mod +14 -14
- package/shim/compiler/go.sum +22 -22
- package/shim/core/extra-shim.json +4 -4
- package/shim/core/go.mod +5 -5
- package/shim/diagnosticwriter/go.mod +5 -5
- package/shim/lsp/extra-shim.json +4 -4
- package/shim/lsp/go.mod +16 -16
- package/shim/lsp/go.sum +26 -26
- package/shim/parser/extra-shim.json +4 -4
- package/shim/parser/go.mod +5 -5
- package/shim/printer/go.mod +14 -14
- package/shim/printer/go.sum +22 -22
- package/shim/scanner/extra-shim.json +4 -4
- package/shim/scanner/go.mod +5 -5
- package/shim/transformers/go.mod +14 -14
- package/shim/transformers/go.sum +20 -20
- package/shim/tsoptions/extra-shim.json +4 -4
- package/shim/tsoptions/go.mod +5 -5
- package/shim/tspath/extra-shim.json +4 -4
- package/shim/tspath/go.mod +5 -5
- package/shim/vfs/cachedvfs/extra-shim.json +4 -4
- package/shim/vfs/cachedvfs/go.mod +5 -5
- package/shim/vfs/extra-shim.json +4 -4
- package/shim/vfs/go.mod +5 -5
- package/shim/vfs/osvfs/extra-shim.json +4 -4
- package/shim/vfs/osvfs/go.mod +5 -5
- package/src/TtscService.ts +8 -20
- package/src/compiler/internal/captureProcessOutput.ts +96 -0
- package/src/compiler/internal/compileProjectInMemory.ts +7 -7
- package/src/compiler/internal/residentCheckProcess.ts +1 -21
- package/src/compiler/internal/residentTransformProcess.ts +0 -42
- package/src/compiler/internal/spawnNative.ts +39 -18
- package/src/compiler/internal/startResidentTransform.ts +1 -12
- package/src/launcher/internal/prepareExecution.ts +297 -26
- package/src/launcher/internal/registerRuntimeHooks.ts +11 -2
- package/src/launcher/internal/runTtscserver.ts +4 -9
- package/src/launcher/internal/runTtsx.ts +2 -78
- package/src/launcher/internal/runtimeHooks.ts +385 -82
- package/src/plugin/internal/buildSourcePlugin.ts +36 -3
- package/src/plugin/internal/descriptorProcessFailure.ts +34 -65
- package/src/plugin/internal/loadProjectPlugins.ts +78 -39
- package/tools/gen_shims/go.mod +14 -14
- package/tools/gen_shims/go.sum +12 -12
- package/tools/shim_audit/go.mod +10 -10
- package/tools/shim_audit/go.sum +8 -8
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
1
|
import fs from "node:fs";
|
|
3
2
|
import os from "node:os";
|
|
4
3
|
import path from "node:path";
|
|
@@ -12,6 +11,7 @@ import { buildNativeCompiler } from "./buildNativeCompiler";
|
|
|
12
11
|
import { isOutsideRelativePath, packageRootDir } from "./paths";
|
|
13
12
|
import { readProjectConfig } from "./project/readProjectConfig";
|
|
14
13
|
import { runBuild } from "./runBuild";
|
|
14
|
+
import { outputText, spawnNative } from "./spawnNative";
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Compile a project and capture emitted files without writing to the project
|
|
@@ -45,15 +45,12 @@ export function compileProjectInMemory(options: ITtscCompilerContext): {
|
|
|
45
45
|
cacheDir: options.cacheDir ?? options.env?.TTSC_CACHE_DIR,
|
|
46
46
|
packageRoot: packageRootDir(),
|
|
47
47
|
});
|
|
48
|
-
const res =
|
|
48
|
+
const res = spawnNative(
|
|
49
49
|
binary,
|
|
50
50
|
["api-compile", "--cwd", project.root, "--tsconfig", tsconfig],
|
|
51
51
|
{
|
|
52
52
|
cwd: project.root,
|
|
53
|
-
encoding: "utf8",
|
|
54
53
|
env: { ...process.env, ...options.env },
|
|
55
|
-
maxBuffer: 1024 * 1024 * 256,
|
|
56
|
-
windowsHide: true,
|
|
57
54
|
},
|
|
58
55
|
);
|
|
59
56
|
if (res.error) {
|
|
@@ -62,14 +59,17 @@ export function compileProjectInMemory(options: ITtscCompilerContext): {
|
|
|
62
59
|
);
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
const output = parseNativeCompileOutput(
|
|
62
|
+
const output = parseNativeCompileOutput(
|
|
63
|
+
outputText(res.stdout),
|
|
64
|
+
outputText(res.stderr),
|
|
65
|
+
);
|
|
66
66
|
return {
|
|
67
67
|
output: output.output,
|
|
68
68
|
result: {
|
|
69
69
|
diagnostics: output.diagnostics,
|
|
70
70
|
status: res.status ?? 1,
|
|
71
71
|
stdout: "",
|
|
72
|
-
stderr: res.stderr,
|
|
72
|
+
stderr: outputText(res.stderr),
|
|
73
73
|
},
|
|
74
74
|
};
|
|
75
75
|
}
|
|
@@ -2,7 +2,6 @@ import { type ChildProcess, spawn } from "node:child_process";
|
|
|
2
2
|
import { type Interface, createInterface } from "node:readline";
|
|
3
3
|
|
|
4
4
|
import type { TtscBuildResult } from "../../structures/internal/TtscBuildResult";
|
|
5
|
-
import { normalizeRequestTimeoutMs } from "./residentTransformProcess";
|
|
6
5
|
|
|
7
6
|
const STDERR_TAIL_LIMIT = 64 * 1024;
|
|
8
7
|
const REPLY_ECHO_LIMIT = 200;
|
|
@@ -13,7 +12,6 @@ export interface ResidentCheckProcessOptions {
|
|
|
13
12
|
binary: string;
|
|
14
13
|
cwd: string;
|
|
15
14
|
env: NodeJS.ProcessEnv;
|
|
16
|
-
requestTimeoutMs?: number;
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
export interface ResidentCheckRequest {
|
|
@@ -36,7 +34,6 @@ export type ResidentCheckResult = TtscBuildResult & {
|
|
|
36
34
|
type PendingRequest = {
|
|
37
35
|
reject(reason: Error): void;
|
|
38
36
|
resolve(result: ResidentCheckResult): void;
|
|
39
|
-
timer: NodeJS.Timeout;
|
|
40
37
|
};
|
|
41
38
|
|
|
42
39
|
/**
|
|
@@ -51,12 +48,10 @@ export class ResidentCheckProcess {
|
|
|
51
48
|
private readonly child: ChildProcess;
|
|
52
49
|
private readonly pending: PendingRequest[] = [];
|
|
53
50
|
private readonly reader: Interface;
|
|
54
|
-
private readonly requestTimeoutMs: number;
|
|
55
51
|
private failure: Error | undefined;
|
|
56
52
|
private stderr = "";
|
|
57
53
|
|
|
58
54
|
public constructor(options: ResidentCheckProcessOptions) {
|
|
59
|
-
this.requestTimeoutMs = normalizeRequestTimeoutMs(options.requestTimeoutMs);
|
|
60
55
|
this.child = spawn(options.binary, [...options.args], {
|
|
61
56
|
cwd: options.cwd,
|
|
62
57
|
env: options.env,
|
|
@@ -98,21 +93,7 @@ export class ResidentCheckProcess {
|
|
|
98
93
|
return Promise.reject(asError(error));
|
|
99
94
|
}
|
|
100
95
|
return new Promise<ResidentCheckResult>((resolve, reject) => {
|
|
101
|
-
const pending: PendingRequest = {
|
|
102
|
-
reject,
|
|
103
|
-
resolve,
|
|
104
|
-
timer: setTimeout(() => {
|
|
105
|
-
const detail = stderrSuffix(this.stderr);
|
|
106
|
-
const timeout = new Error(
|
|
107
|
-
`ttsc: resident check request timed out after ${String(
|
|
108
|
-
this.requestTimeoutMs,
|
|
109
|
-
)} ms${detail}`,
|
|
110
|
-
);
|
|
111
|
-
this.settle(pending, timeout);
|
|
112
|
-
this.fail(timeout);
|
|
113
|
-
}, this.requestTimeoutMs),
|
|
114
|
-
};
|
|
115
|
-
pending.timer.unref();
|
|
96
|
+
const pending: PendingRequest = { reject, resolve };
|
|
116
97
|
this.pending.push(pending);
|
|
117
98
|
try {
|
|
118
99
|
stdin.write(line, (error) => {
|
|
@@ -161,7 +142,6 @@ export class ResidentCheckProcess {
|
|
|
161
142
|
const index = this.pending.indexOf(pending);
|
|
162
143
|
if (index === -1) return;
|
|
163
144
|
this.pending.splice(index, 1);
|
|
164
|
-
clearTimeout(pending.timer);
|
|
165
145
|
if (result instanceof Error) pending.reject(result);
|
|
166
146
|
else pending.resolve(result);
|
|
167
147
|
}
|
|
@@ -7,12 +7,6 @@ const STDERR_TAIL_LIMIT = 64 * 1024;
|
|
|
7
7
|
/** Cap on how much of an offending line an error message echoes back. */
|
|
8
8
|
const REPLY_ECHO_LIMIT = 200;
|
|
9
9
|
|
|
10
|
-
/** Default deadline for one request to the resident transform host. */
|
|
11
|
-
const DEFAULT_REQUEST_TIMEOUT_MS = 300_000;
|
|
12
|
-
|
|
13
|
-
/** Node clamps timers beyond this signed 32-bit millisecond duration. */
|
|
14
|
-
const MAX_TIMER_MS = 2_147_483_647;
|
|
15
|
-
|
|
16
10
|
/** Allow a cooperative host a short shutdown window before forcing it down. */
|
|
17
11
|
const TERMINATION_GRACE_MS = 1_000;
|
|
18
12
|
|
|
@@ -32,8 +26,6 @@ export interface ResidentTransformProcessOptions {
|
|
|
32
26
|
binary: string;
|
|
33
27
|
cwd?: string;
|
|
34
28
|
env?: NodeJS.ProcessEnv;
|
|
35
|
-
/** Maximum time one request may wait for the resident host's reply. */
|
|
36
|
-
requestTimeoutMs?: number;
|
|
37
29
|
}
|
|
38
30
|
|
|
39
31
|
/** Per-request lifecycle controls for a resident transform host. */
|
|
@@ -49,7 +41,6 @@ interface PendingRequest {
|
|
|
49
41
|
resolve: (reply: Record<string, unknown>) => void;
|
|
50
42
|
settled: boolean;
|
|
51
43
|
signal?: AbortSignal;
|
|
52
|
-
timer: NodeJS.Timeout;
|
|
53
44
|
}
|
|
54
45
|
|
|
55
46
|
/**
|
|
@@ -70,12 +61,10 @@ export class ResidentTransformProcess {
|
|
|
70
61
|
private readonly child: ChildProcess;
|
|
71
62
|
private readonly reader: Interface;
|
|
72
63
|
private readonly pending: PendingRequest[] = [];
|
|
73
|
-
private readonly requestTimeoutMs: number;
|
|
74
64
|
private stderr = "";
|
|
75
65
|
private failure: Error | undefined;
|
|
76
66
|
|
|
77
67
|
public constructor(options: ResidentTransformProcessOptions) {
|
|
78
|
-
this.requestTimeoutMs = normalizeRequestTimeoutMs(options.requestTimeoutMs);
|
|
79
68
|
// Default stdio is "pipe" for stdin/stdout/stderr, which is exactly what the
|
|
80
69
|
// line protocol needs; spelling it out as a string[] would not narrow to
|
|
81
70
|
// StdioOptions, so it is left implicit.
|
|
@@ -153,9 +142,7 @@ export class ResidentTransformProcess {
|
|
|
153
142
|
resolve,
|
|
154
143
|
settled: false,
|
|
155
144
|
signal: options.signal,
|
|
156
|
-
timer: setTimeout(() => this.timeout(pending), this.requestTimeoutMs),
|
|
157
145
|
};
|
|
158
|
-
pending.timer.unref();
|
|
159
146
|
if (options.signal !== undefined) {
|
|
160
147
|
pending.abort = () => this.cancel(pending, options.signal!);
|
|
161
148
|
options.signal.addEventListener("abort", pending.abort, { once: true });
|
|
@@ -285,7 +272,6 @@ export class ResidentTransformProcess {
|
|
|
285
272
|
pending.settled = true;
|
|
286
273
|
const index = this.pending.indexOf(pending);
|
|
287
274
|
if (index !== -1) this.pending.splice(index, 1);
|
|
288
|
-
clearTimeout(pending.timer);
|
|
289
275
|
if (pending.signal !== undefined && pending.abort !== undefined) {
|
|
290
276
|
pending.signal.removeEventListener("abort", pending.abort);
|
|
291
277
|
}
|
|
@@ -293,23 +279,6 @@ export class ResidentTransformProcess {
|
|
|
293
279
|
else pending.resolve(result);
|
|
294
280
|
}
|
|
295
281
|
|
|
296
|
-
private timeout(pending: PendingRequest): void {
|
|
297
|
-
if (pending.settled) return;
|
|
298
|
-
const timeout = new Error(
|
|
299
|
-
`ttsc: resident transform request timed out after ${String(
|
|
300
|
-
this.requestTimeoutMs,
|
|
301
|
-
)} ms${stderrSuffix(this.stderr)}`,
|
|
302
|
-
);
|
|
303
|
-
this.settlePending(pending, timeout);
|
|
304
|
-
this.fail(
|
|
305
|
-
new Error(
|
|
306
|
-
`ttsc: resident transform host retired after another request timed out${stderrSuffix(
|
|
307
|
-
this.stderr,
|
|
308
|
-
)}`,
|
|
309
|
-
),
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
282
|
private cancel(pending: PendingRequest, signal: AbortSignal): void {
|
|
314
283
|
if (pending.settled) return;
|
|
315
284
|
this.settlePending(pending, cancelledError(signal));
|
|
@@ -362,17 +331,6 @@ export class ResidentTransformProcess {
|
|
|
362
331
|
}
|
|
363
332
|
}
|
|
364
333
|
|
|
365
|
-
/** Validate and normalize the caller-visible resident request deadline. */
|
|
366
|
-
export function normalizeRequestTimeoutMs(requestTimeoutMs?: number): number {
|
|
367
|
-
const value = requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
368
|
-
if (!Number.isSafeInteger(value) || value <= 0 || value > MAX_TIMER_MS) {
|
|
369
|
-
throw new TypeError(
|
|
370
|
-
`ttsc: requestTimeoutMs must be an integer between 1 and ${String(MAX_TIMER_MS)}`,
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
return value;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
334
|
function cancelledError(signal: AbortSignal): Error {
|
|
377
335
|
const error = new Error(
|
|
378
336
|
`ttsc: resident transform request cancelled${abortDetail(signal)}`,
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
1
|
+
import { type SpawnSyncReturns, spawnSync } from "node:child_process";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
|
|
4
|
+
import { captureProcessOutput } from "./captureProcessOutput";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Spawn a native binary (or a Node.js script when the path has a JS/TS
|
|
6
|
-
* extension)
|
|
7
|
-
*
|
|
8
|
+
* extension) and return its result with `stdout` and `stderr` as text.
|
|
9
|
+
*
|
|
10
|
+
* The child's streams are written to files rather than piped, and the files are
|
|
11
|
+
* read once it exits. `spawnSync` buffers a _piped_ stream in this process's
|
|
12
|
+
* memory and refuses to hold more than `maxBuffer` bytes, so a piped capture
|
|
13
|
+
* has to name a ceiling — and any ceiling is a number nobody chose for this
|
|
14
|
+
* machine, deciding that a large but legitimate compile said too much. A file
|
|
15
|
+
* has no such limit: the bytes never pass through this heap on their way out of
|
|
16
|
+
* the child, and how many there may be is the filesystem's business.
|
|
8
17
|
*
|
|
9
|
-
* When `options.encoding` is omitted it defaults to `"utf8"`. Pass
|
|
10
|
-
*
|
|
18
|
+
* When `options.encoding` is omitted it defaults to `"utf8"`. Pass `"buffer"`
|
|
19
|
+
* when the caller needs raw bytes.
|
|
11
20
|
*/
|
|
12
21
|
export function spawnNative(
|
|
13
22
|
binary: string,
|
|
@@ -15,24 +24,36 @@ export function spawnNative(
|
|
|
15
24
|
options: {
|
|
16
25
|
cwd?: string;
|
|
17
26
|
env?: NodeJS.ProcessEnv;
|
|
18
|
-
encoding?: BufferEncoding;
|
|
27
|
+
encoding?: BufferEncoding | "buffer";
|
|
19
28
|
},
|
|
20
|
-
) {
|
|
29
|
+
): SpawnSyncReturns<string | Buffer> {
|
|
21
30
|
const viaNode = /\.(?:[cm]?js|ts)$/i.test(binary);
|
|
22
31
|
if (!viaNode) {
|
|
23
32
|
ensureExecutable(binary);
|
|
24
33
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const capture = captureProcessOutput();
|
|
35
|
+
try {
|
|
36
|
+
const result = spawnSync(
|
|
37
|
+
viaNode ? process.execPath : binary,
|
|
38
|
+
viaNode ? [binary, ...args] : [...args],
|
|
39
|
+
{
|
|
40
|
+
cwd: options.cwd,
|
|
41
|
+
env: options.env,
|
|
42
|
+
stdio: ["ignore", capture.stdoutFd, capture.stderrFd],
|
|
43
|
+
windowsHide: true,
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
const stdout = capture.read("stdout", options.encoding);
|
|
47
|
+
const stderr = capture.read("stderr", options.encoding);
|
|
48
|
+
return {
|
|
49
|
+
...result,
|
|
50
|
+
output: [null, stdout, stderr],
|
|
51
|
+
stderr,
|
|
52
|
+
stdout,
|
|
53
|
+
} as SpawnSyncReturns<string | Buffer>;
|
|
54
|
+
} finally {
|
|
55
|
+
capture.dispose();
|
|
56
|
+
}
|
|
36
57
|
}
|
|
37
58
|
|
|
38
59
|
/**
|
|
@@ -4,10 +4,7 @@ import { loadProjectPlugins } from "../../plugin/internal/loadProjectPlugins";
|
|
|
4
4
|
import type { ITtscCompilerContext } from "../../structures/ITtscCompilerContext";
|
|
5
5
|
import type { ITtscLoadedNativePlugin } from "../../structures/internal/ITtscLoadedNativePlugin";
|
|
6
6
|
import { readProjectConfig } from "./project/readProjectConfig";
|
|
7
|
-
import {
|
|
8
|
-
ResidentTransformProcess,
|
|
9
|
-
normalizeRequestTimeoutMs,
|
|
10
|
-
} from "./residentTransformProcess";
|
|
7
|
+
import { ResidentTransformProcess } from "./residentTransformProcess";
|
|
11
8
|
import { resolveBinary } from "./resolveBinary";
|
|
12
9
|
import { resolveTsgo } from "./resolveTsgo";
|
|
13
10
|
import {
|
|
@@ -26,11 +23,6 @@ export interface StartedResidentTransform {
|
|
|
26
23
|
projectRoot: string;
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
/** Construction controls owned by the resident request client. */
|
|
30
|
-
export interface StartResidentTransformOptions {
|
|
31
|
-
requestTimeoutMs?: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
26
|
/**
|
|
35
27
|
* Start a resident `serve` host for the configured project.
|
|
36
28
|
*
|
|
@@ -48,9 +40,7 @@ export interface StartResidentTransformOptions {
|
|
|
48
40
|
*/
|
|
49
41
|
export function startResidentTransform(
|
|
50
42
|
context: ITtscCompilerContext,
|
|
51
|
-
options: StartResidentTransformOptions = {},
|
|
52
43
|
): StartedResidentTransform {
|
|
53
|
-
const requestTimeoutMs = normalizeRequestTimeoutMs(options.requestTimeoutMs);
|
|
54
44
|
const cwd = path.resolve(context.cwd ?? process.cwd());
|
|
55
45
|
const project = readProjectConfig({
|
|
56
46
|
cwd,
|
|
@@ -90,7 +80,6 @@ export function startResidentTransform(
|
|
|
90
80
|
binary: host.binary,
|
|
91
81
|
cwd: project.root,
|
|
92
82
|
env: residentEnv(context, tsgoBinary, loaded.nativePlugins),
|
|
93
|
-
requestTimeoutMs,
|
|
94
83
|
});
|
|
95
84
|
return { process: resident, projectRoot: project.root };
|
|
96
85
|
}
|