ttsc 0.24.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +70 -63
  2. package/cmd/ttscgraph/serve_answers_a_project_that_implements_its_own_ambient_declaration_test.go +69 -0
  3. package/internal/graph/assigned_implementations_of_declaration_file_symbols_leave_no_edge_source_test.go +84 -0
  4. package/internal/graph/assigned_implementations_of_node_modules_symbols_leave_no_edge_source_test.go +85 -0
  5. package/internal/graph/edges.go +15 -1
  6. package/internal/lspserver/lsp_native_plugin_source.go +5 -6
  7. package/internal/lspserver/lsp_native_resident.go +17 -24
  8. package/lib/TtscService.d.ts +1 -6
  9. package/lib/TtscService.js +2 -2
  10. package/lib/TtscService.js.map +1 -1
  11. package/lib/compiler/internal/captureProcessOutput.d.ts +26 -0
  12. package/lib/compiler/internal/captureProcessOutput.js +92 -0
  13. package/lib/compiler/internal/captureProcessOutput.js.map +1 -0
  14. package/lib/compiler/internal/compileProjectInMemory.js +4 -7
  15. package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
  16. package/lib/compiler/internal/residentCheckProcess.d.ts +0 -2
  17. package/lib/compiler/internal/residentCheckProcess.js +1 -15
  18. package/lib/compiler/internal/residentCheckProcess.js.map +1 -1
  19. package/lib/compiler/internal/residentTransformProcess.d.ts +0 -6
  20. package/lib/compiler/internal/residentTransformProcess.js +0 -25
  21. package/lib/compiler/internal/residentTransformProcess.js.map +1 -1
  22. package/lib/compiler/internal/spawnNative.d.ts +14 -6
  23. package/lib/compiler/internal/spawnNative.js +32 -11
  24. package/lib/compiler/internal/spawnNative.js.map +1 -1
  25. package/lib/compiler/internal/startResidentTransform.d.ts +1 -5
  26. package/lib/compiler/internal/startResidentTransform.js +1 -3
  27. package/lib/compiler/internal/startResidentTransform.js.map +1 -1
  28. package/lib/launcher/internal/prepareExecution.d.ts +2 -1
  29. package/lib/launcher/internal/prepareExecution.js +269 -23
  30. package/lib/launcher/internal/prepareExecution.js.map +1 -1
  31. package/lib/launcher/internal/registerRuntimeHooks.js +6 -1
  32. package/lib/launcher/internal/registerRuntimeHooks.js.map +1 -1
  33. package/lib/launcher/internal/runTtscserver.js +4 -9
  34. package/lib/launcher/internal/runTtscserver.js.map +1 -1
  35. package/lib/launcher/internal/runTtsx.js +2 -55
  36. package/lib/launcher/internal/runTtsx.js.map +1 -1
  37. package/lib/launcher/internal/runtimeHooks.d.ts +25 -2
  38. package/lib/launcher/internal/runtimeHooks.js +344 -69
  39. package/lib/launcher/internal/runtimeHooks.js.map +1 -1
  40. package/lib/plugin/internal/buildSourcePlugin.js +31 -3
  41. package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
  42. package/lib/plugin/internal/descriptorProcessFailure.d.ts +23 -19
  43. package/lib/plugin/internal/descriptorProcessFailure.js +40 -51
  44. package/lib/plugin/internal/descriptorProcessFailure.js.map +1 -1
  45. package/lib/plugin/internal/loadProjectPlugins.d.ts +12 -0
  46. package/lib/plugin/internal/loadProjectPlugins.js +77 -28
  47. package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
  48. package/package.json +8 -8
  49. package/src/TtscService.ts +8 -20
  50. package/src/compiler/internal/captureProcessOutput.ts +96 -0
  51. package/src/compiler/internal/compileProjectInMemory.ts +7 -7
  52. package/src/compiler/internal/residentCheckProcess.ts +1 -21
  53. package/src/compiler/internal/residentTransformProcess.ts +0 -42
  54. package/src/compiler/internal/spawnNative.ts +39 -18
  55. package/src/compiler/internal/startResidentTransform.ts +1 -12
  56. package/src/launcher/internal/prepareExecution.ts +297 -26
  57. package/src/launcher/internal/registerRuntimeHooks.ts +11 -2
  58. package/src/launcher/internal/runTtscserver.ts +4 -9
  59. package/src/launcher/internal/runTtsx.ts +2 -78
  60. package/src/launcher/internal/runtimeHooks.ts +385 -82
  61. package/src/plugin/internal/buildSourcePlugin.ts +36 -3
  62. package/src/plugin/internal/descriptorProcessFailure.ts +34 -65
  63. package/src/plugin/internal/loadProjectPlugins.ts +78 -39
@@ -8,6 +8,7 @@ import { createNativeProjectContextArgs } from "../../compiler/internal/project/
8
8
  import { readProjectConfig } from "../../compiler/internal/project/readProjectConfig";
9
9
  import { resolveBinary } from "../../compiler/internal/resolveBinary";
10
10
  import { resolveTsgo } from "../../compiler/internal/resolveTsgo";
11
+ import { outputText, spawnNative } from "../../compiler/internal/spawnNative";
11
12
  import {
12
13
  type ProjectInputPathIdentityContext,
13
14
  createProjectInputPathIdentityContext,
@@ -43,8 +44,6 @@ type TtscserverEnvironment = {
43
44
  };
44
45
 
45
46
  const LSP_SELECTION_STABILITY_ATTEMPTS = 3;
46
- const LSP_PROJECT_INPUT_TIMEOUT_MS = 30_000;
47
- const LSP_PROJECT_INPUT_MAX_BUFFER = 4 * 1024 * 1024;
48
47
 
49
48
  /**
50
49
  * Drive the ttscserver native binary from a node launcher. The launcher is
@@ -359,22 +358,18 @@ function captureInitialLSPProjectInputs(options: {
359
358
  pluginConfigOrigin: options.pluginConfigOrigin,
360
359
  tsgoBinary: options.tsgoBinary,
361
360
  });
362
- const result = spawnSync(plugin.binary, args, {
361
+ const result = spawnNative(plugin.binary, args, {
363
362
  cwd: options.project.root,
364
- encoding: "utf8",
365
363
  env,
366
- maxBuffer: LSP_PROJECT_INPUT_MAX_BUFFER,
367
- timeout: LSP_PROJECT_INPUT_TIMEOUT_MS,
368
- windowsHide: true,
369
364
  });
370
365
  if (result.error) {
371
366
  throw new Error(
372
367
  `ttscserver: ${plugin.name ?? plugin.binary} project-inputs failed: ${result.error.message}`,
373
368
  );
374
369
  }
375
- const stdout = result.stdout.trim();
370
+ const stdout = outputText(result.stdout).trim();
376
371
  if (result.status !== 0) {
377
- const detail = result.stderr.trim() || stdout;
372
+ const detail = outputText(result.stderr).trim() || stdout;
378
373
  throw new Error(
379
374
  `ttscserver: ${plugin.name ?? plugin.binary} project-inputs failed${detail ? `: ${detail}` : ""}`,
380
375
  );
@@ -276,7 +276,7 @@ function runPreparedEntry(
276
276
  depCacheDir,
277
277
  emitDir: execution.emitDir,
278
278
  emittedFiles: execution.emittedFiles,
279
- moduleOption: execution.moduleOption,
279
+ moduleOptions: execution.moduleOptions,
280
280
  projectRoot: execution.projectRoot,
281
281
  rootDir: execution.rootDir,
282
282
  }),
@@ -299,7 +299,6 @@ function runPreparedEntry(
299
299
  sourceEntry,
300
300
  ...parsed.passthrough,
301
301
  ];
302
- const evaluatorBoundary = readEvaluatorBoundary(process.env);
303
302
  const runtimeEnv: NodeJS.ProcessEnv = {
304
303
  ...process.env,
305
304
  NODE_OPTIONS: appendNodeOption(
@@ -309,42 +308,12 @@ function runPreparedEntry(
309
308
  TTSC_TSGO_BINARY: process.env.TTSC_TSGO_BINARY ?? tsgo,
310
309
  TTSX_RUNTIME_MANIFEST: manifestPath,
311
310
  };
312
- delete runtimeEnv[TTSC_TTSX_EVALUATOR_DEADLINE_ENV];
313
- delete runtimeEnv[TTSC_TTSX_EVALUATOR_MAX_BUFFER_ENV];
314
- delete runtimeEnv[TTSC_TTSX_EVALUATOR_STATUS_FD_ENV];
315
-
316
311
  const result = spawnSync(process.execPath, args, {
317
312
  cwd,
318
313
  env: runtimeEnv,
319
- ...(evaluatorBoundary
320
- ? {
321
- killSignal: "SIGKILL" as const,
322
- timeout: Math.max(
323
- 1,
324
- Math.min(
325
- MAX_CHILD_PROCESS_TIMEOUT_MS,
326
- evaluatorBoundary.deadlineMs - Date.now(),
327
- ),
328
- ),
329
- maxBuffer: evaluatorBoundary.maxBuffer,
330
- stdio: ["inherit", "pipe", "pipe"] as const,
331
- }
332
- : { stdio: "inherit" as const }),
314
+ stdio: "inherit",
333
315
  windowsHide: true,
334
316
  });
335
- const nestedCode = (result.error as NodeJS.ErrnoException | undefined)
336
- ?.code;
337
- if (
338
- evaluatorBoundary &&
339
- (nestedCode === "ETIMEDOUT" || nestedCode === "ENOBUFS")
340
- ) {
341
- reportEvaluatorFailure(evaluatorBoundary.statusFd, nestedCode);
342
- return 1;
343
- }
344
- if (evaluatorBoundary) {
345
- if (result.stdout) process.stdout.write(result.stdout);
346
- if (result.stderr) process.stderr.write(result.stderr);
347
- }
348
317
  if (result.error) {
349
318
  process.stderr.write(`${result.error.message}\n`);
350
319
  return 1;
@@ -355,51 +324,6 @@ function runPreparedEntry(
355
324
  }
356
325
  }
357
326
 
358
- interface TtsxEvaluatorBoundary {
359
- deadlineMs: number;
360
- maxBuffer: number;
361
- statusFd: number;
362
- }
363
-
364
- const TTSC_TTSX_EVALUATOR_DEADLINE_ENV = "TTSC_TTSX_EVALUATOR_DEADLINE_MS";
365
- const TTSC_TTSX_EVALUATOR_MAX_BUFFER_ENV =
366
- "TTSC_TTSX_EVALUATOR_MAX_BUFFER_BYTES";
367
- const TTSC_TTSX_EVALUATOR_STATUS_FD_ENV = "TTSC_TTSX_EVALUATOR_STATUS_FD";
368
- const TTSC_TTSX_EVALUATOR_STATUS_FD = 3;
369
- const MAX_CHILD_PROCESS_TIMEOUT_MS = 2_147_483_647;
370
-
371
- function readEvaluatorBoundary(
372
- env: NodeJS.ProcessEnv,
373
- ): TtsxEvaluatorBoundary | undefined {
374
- const deadlineMs = Number(env[TTSC_TTSX_EVALUATOR_DEADLINE_ENV]);
375
- const maxBuffer = Number(env[TTSC_TTSX_EVALUATOR_MAX_BUFFER_ENV]);
376
- const statusFd = Number(env[TTSC_TTSX_EVALUATOR_STATUS_FD_ENV]);
377
- if (
378
- !Number.isSafeInteger(deadlineMs) ||
379
- deadlineMs <= 0 ||
380
- !Number.isSafeInteger(maxBuffer) ||
381
- maxBuffer <= 0 ||
382
- maxBuffer > MAX_CHILD_PROCESS_TIMEOUT_MS ||
383
- statusFd !== TTSC_TTSX_EVALUATOR_STATUS_FD
384
- ) {
385
- return undefined;
386
- }
387
- return { deadlineMs, maxBuffer, statusFd };
388
- }
389
-
390
- function reportEvaluatorFailure(
391
- statusFd: number,
392
- code: "ENOBUFS" | "ETIMEDOUT",
393
- ): void {
394
- try {
395
- fs.writeSync(statusFd, code);
396
- } catch {
397
- // The boundary is an internal parent/child protocol. If a standalone ttsx
398
- // caller supplied only the environment variables, preserve the ordinary
399
- // non-zero bounded-process result instead of replacing it with an fd error.
400
- }
401
- }
402
-
403
327
  function removeRuntimeOutput(directory: string): void {
404
328
  try {
405
329
  fs.rmSync(directory, { force: true, recursive: true });