ttsc 0.30.3 → 0.31.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 (2081) hide show
  1. package/cmd/graphbench/main.go +2 -3
  2. package/cmd/graphdump/main.go +42 -16
  3. package/cmd/graphdump/run_declares_the_capability_its_output_carries_test.go +32 -18
  4. package/cmd/graphdump/run_reports_an_unknown_flag_without_exiting_the_process_test.go +10 -9
  5. package/cmd/graphdump/run_reports_an_unloadable_project_without_printing_a_dump_test.go +8 -7
  6. package/cmd/platform/command_operation_families_test.go +192 -0
  7. package/cmd/platform/main.go +11 -1
  8. package/cmd/ttsc/api_compile.go +166 -46
  9. package/cmd/ttsc/api_compile_branches_test.go +97 -10
  10. package/cmd/ttsc/api_transform.go +134 -46
  11. package/cmd/ttsc/api_transform_branches_test.go +10 -7
  12. package/cmd/ttsc/build.go +177 -68
  13. package/cmd/ttsc/build_branches_test.go +35 -7
  14. package/cmd/ttsc/cli_command_operation_families_test.go +1287 -0
  15. package/cmd/ttsc/cli_contract_helpers_test.go +82 -0
  16. package/cmd/ttsc/compiler_argument_cwd_test.go +57 -0
  17. package/cmd/ttsc/filter.go +31 -14
  18. package/cmd/ttsc/filter_resolves_flag_names_case_insensitively_test.go +10 -13
  19. package/cmd/ttsc/filter_strips_unknown_forwarded_flag_test.go +10 -16
  20. package/cmd/ttsc/flags_gen.go +2 -2
  21. package/cmd/ttsc/helpers_test.go +67 -10
  22. package/cmd/ttsc/main.go +122 -21
  23. package/cmd/ttsc/main_alias_branches_test.go +35 -9
  24. package/cmd/ttsc/testdata/cli_operation_families/TestAPITransformEnvelopeCarriesReferenceGraph/ambient.d.ts +1 -0
  25. package/cmd/ttsc/testdata/cli_operation_families/TestAPITransformEnvelopeCarriesReferenceGraph/main.ts +2 -0
  26. package/cmd/ttsc/testdata/cli_operation_families/TestAPITransformEnvelopeCarriesReferenceGraph/mytype.ts +1 -0
  27. package/cmd/ttsc/testdata/cli_operation_families/TestAPITransformEnvelopeCarriesReferenceGraph/tsconfig.base.json +3 -0
  28. package/cmd/ttsc/testdata/cli_operation_families/TestAPITransformEnvelopeCarriesReferenceGraph/tsconfig.json +5 -0
  29. package/cmd/ttsc/testdata/cli_operation_families/TestCLIAPICompileAndTransform/index.ts +1 -0
  30. package/cmd/ttsc/testdata/cli_operation_families/TestCLIAPICompileAndTransform/src/decorated/main.ts +10 -0
  31. package/cmd/ttsc/testdata/cli_operation_families/TestCLIAPICompileAndTransform/src/decorated/types.ts +3 -0
  32. package/cmd/ttsc/testdata/cli_operation_families/TestCLIAPICompileAndTransform/src/helpers.ts +1 -0
  33. package/cmd/ttsc/testdata/cli_operation_families/TestCLIAPICompileAndTransform/src/isolated.ts +1 -0
  34. package/cmd/ttsc/testdata/cli_operation_families/TestCLIAPICompileAndTransform/src/main.ts +7 -0
  35. package/cmd/ttsc/testdata/cli_operation_families/TestCLIAPICompileAndTransform/src/nested/model.ts +1 -0
  36. package/cmd/ttsc/testdata/cli_operation_families/TestCLIAPICompileAndTransform/tsconfig.json +14 -0
  37. package/cmd/ttsc/testdata/cli_operation_families/TestCLIAPITransformUsesCurrentDirectory/index.ts +1 -0
  38. package/cmd/ttsc/testdata/cli_operation_families/TestCLIAPITransformUsesCurrentDirectory/tsconfig.json +7 -0
  39. package/cmd/ttsc/testdata/cli_operation_families/TestCLIProjectBuildAllowsUnusedTypeParametersOnOverloadSignatures/index.ts +4 -0
  40. package/cmd/ttsc/testdata/cli_operation_families/TestCLIProjectBuildAllowsUnusedTypeParametersOnOverloadSignatures/tsconfig.json +11 -0
  41. package/cmd/ttsc/testdata/cli_operation_families/TestCLIProjectBuildBlocksSemanticDiagnostics/index.ts +2 -0
  42. package/cmd/ttsc/testdata/cli_operation_families/TestCLIProjectBuildBlocksSemanticDiagnostics/tsconfig.json +9 -0
  43. package/cmd/ttsc/testdata/cli_operation_families/TestCLIProjectBuildBlocksSyntacticDiagnostics/index.ts +2 -0
  44. package/cmd/ttsc/testdata/cli_operation_families/TestCLIProjectBuildBlocksSyntacticDiagnostics/tsconfig.json +8 -0
  45. package/cmd/ttsc/testdata/cli_operation_families/TestCLIProjectBuildBlocksUnusedParameters/index.ts +3 -0
  46. package/cmd/ttsc/testdata/cli_operation_families/TestCLIProjectBuildBlocksUnusedParameters/tsconfig.json +10 -0
  47. package/cmd/ttsc/testdata/cli_operation_families/TestCLIProjectBuildEmitErrorRejectsManifest/index.ts +1 -0
  48. package/cmd/ttsc/testdata/cli_operation_families/TestCLIProjectBuildEmitErrorRejectsManifest/tsconfig.json +1 -0
  49. package/cmd/ttsc/testdata/cli_operation_families/TestCLIReportsDiagnosticsWithoutEmit/index.ts +1 -0
  50. package/cmd/ttsc/testdata/cli_operation_families/TestCLIReportsDiagnosticsWithoutEmit/tsconfig.json +8 -0
  51. package/cmd/ttsc/testdata/cli_operation_families/shared-value-one/project/emit.json +8 -0
  52. package/cmd/ttsc/testdata/cli_operation_families/shared-value-one/project/flag-shaped.json +7 -0
  53. package/cmd/ttsc/testdata/cli_operation_families/shared-value-one/project/index.ts +2 -0
  54. package/cmd/ttsc/testdata/cli_operation_families/shared-value-one/project/nested/tsconfig.app.json +11 -0
  55. package/cmd/ttsc/testdata/cli_operation_families/shared-value-one/project/outside.json +8 -0
  56. package/cmd/ttsc/testdata/cli_operation_families/shared-value-one/project/tsconfig.json +8 -0
  57. package/cmd/ttscgraph/auxiliary_identity_state_tracks_retargets_not_source_contents_test.go +26 -15
  58. package/cmd/ttscgraph/disk_realpath_other.go +2 -0
  59. package/cmd/ttscgraph/dump.go +46 -29
  60. package/cmd/ttscgraph/prepared_projection.go +61 -0
  61. package/cmd/ttscgraph/projection_fixture_test.go +96 -0
  62. package/cmd/ttscgraph/run_dump_claims_artifacts_only_when_it_asked_test.go +30 -5
  63. package/cmd/ttscgraph/run_dump_declares_the_capability_its_output_carries_test.go +6 -1
  64. package/cmd/ttscgraph/run_dump_emits_only_checker_verified_member_relations_test.go +12 -5
  65. package/cmd/ttscgraph/run_dump_prints_the_graph_as_json_test.go +17 -12
  66. package/cmd/ttscgraph/run_help_version_and_bad_flags_exit_codes_test.go +8 -3
  67. package/cmd/ttscgraph/serve.go +116 -79
  68. package/cmd/ttscgraph/serve_adopts_a_republished_artifact_set_test.go +16 -167
  69. package/cmd/ttscgraph/serve_adopts_a_republished_set_over_the_shard_protocol_test.go +122 -0
  70. package/cmd/ttscgraph/serve_answers_a_project_that_implements_its_own_ambient_declaration_test.go +35 -7
  71. package/cmd/ttscgraph/serve_early_error_encode_failure_is_observable_test.go +5 -0
  72. package/cmd/ttscgraph/serve_error_response_still_names_its_mode_test.go +10 -5
  73. package/cmd/ttscgraph/serve_git_ignore_projection_test.go +150 -0
  74. package/cmd/ttscgraph/serve_keeps_a_startup_set_a_client_never_mentions_test.go +69 -0
  75. package/cmd/ttscgraph/serve_object_members_refresh_without_identity_collisions_test.go +82 -0
  76. package/cmd/ttscgraph/serve_phase_trace_accounts_for_load_failure_test.go +9 -3
  77. package/cmd/ttscgraph/serve_phase_trace_is_opt_in_and_payload_free_test.go +12 -6
  78. package/cmd/ttscgraph/serve_projects_an_artifact_no_source_owns_test.go +13 -16
  79. package/cmd/ttscgraph/serve_protocol_fails_the_stream_on_an_unaddressable_request_line_test.go +10 -9
  80. package/cmd/ttscgraph/serve_protocol_negotiates_incremental_shards_test.go +37 -2
  81. package/cmd/ttscgraph/serve_protocol_retries_session_creation_test.go +7 -2
  82. package/cmd/ttscgraph/serve_protocol_reuses_session_test.go +13 -3
  83. package/cmd/ttscgraph/serve_session_applies_source_edit_incrementally_test.go +12 -7
  84. package/cmd/ttscgraph/serve_session_fails_closed_on_deleted_config_test.go +12 -7
  85. package/cmd/ttscgraph/serve_session_fails_closed_on_invalid_config_test.go +8 -3
  86. package/cmd/ttscgraph/serve_session_keeps_base_url_fallback_unchanged_test.go +7 -2
  87. package/cmd/ttscgraph/serve_session_keeps_change_detection_live_after_initial_dump_error_test.go +66 -0
  88. package/cmd/ttscgraph/serve_session_keeps_esm_directory_candidate_unchanged_test.go +12 -3
  89. package/cmd/ttscgraph/serve_session_keeps_exports_blocked_file_candidates_unchanged_test.go +8 -3
  90. package/cmd/ttscgraph/serve_session_keeps_inactive_conditional_export_unchanged_test.go +12 -3
  91. package/cmd/ttscgraph/serve_session_keeps_lower_priority_module_candidate_unchanged_test.go +14 -8
  92. package/cmd/ttscgraph/serve_session_keeps_lower_priority_paths_pattern_unchanged_test.go +12 -3
  93. package/cmd/ttscgraph/serve_session_keeps_missing_literal_root_unchanged_test.go +7 -2
  94. package/cmd/ttscgraph/serve_session_keeps_nonlongest_root_dirs_candidate_unchanged_test.go +12 -3
  95. package/cmd/ttscgraph/serve_session_rebuilds_import_graph_change_test.go +17 -8
  96. package/cmd/ttscgraph/serve_session_reloads_commonjs_package_entry_for_esm_test.go +11 -2
  97. package/cmd/ttscgraph/serve_session_reloads_created_literal_root_test.go +7 -2
  98. package/cmd/ttscgraph/serve_session_reloads_extended_config_change_test.go +9 -4
  99. package/cmd/ttscgraph/serve_session_reloads_module_suffix_candidate_test.go +13 -4
  100. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_conditional_export_test.go +13 -8
  101. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_config_types_test.go +7 -2
  102. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_excluded_import_test.go +11 -3
  103. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_package_export_test.go +11 -2
  104. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_package_import_test.go +11 -2
  105. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_path_alias_test.go +11 -2
  106. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_reference_path_test.go +11 -2
  107. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_root_dirs_target_test.go +11 -2
  108. package/cmd/ttscgraph/serve_session_reloads_newly_resolved_type_reference_test.go +11 -2
  109. package/cmd/ttscgraph/serve_session_reloads_root_file_set_test.go +11 -5
  110. package/cmd/ttscgraph/serve_session_reloads_source_deleted_during_load_test.go +16 -9
  111. package/cmd/ttscgraph/serve_session_reloads_superseding_module_candidates_test.go +18 -13
  112. package/cmd/ttscgraph/serve_session_reloads_transitive_project_reference_test.go +14 -5
  113. package/cmd/ttscgraph/serve_session_reloads_when_program_plugin_linked_test.go +13 -8
  114. package/cmd/ttscgraph/serve_session_retries_a_pending_dump_before_unchanged_test.go +62 -0
  115. package/cmd/ttscgraph/serve_session_reuses_unchanged_preamble_source_test.go +21 -0
  116. package/cmd/ttscgraph/serve_session_reuses_unchanged_snapshot_test.go +12 -7
  117. package/cmd/ttscgraph/serve_session_revisits_source_edited_during_load_test.go +18 -8
  118. package/cmd/ttscgraph/serve_session_tolerates_os_invalid_resolution_candidate_test.go +13 -9
  119. package/cmd/ttscgraph/serve_session_tracks_all_module_specifier_forms_test.go +12 -3
  120. package/cmd/ttscgraph/serve_session_tracks_diamond_project_references_once_test.go +12 -8
  121. package/cmd/ttscgraph/serve_shards.go +356 -279
  122. package/cmd/ttscgraph/serve_shards_abandoned_generation_converges_on_retry_test.go +41 -16
  123. package/cmd/ttscgraph/serve_shards_delete_removed_source_test.go +14 -4
  124. package/cmd/ttscgraph/serve_shards_external_endpoints_test.go +18 -2
  125. package/cmd/ttscgraph/serve_shards_keep_source_distributed_dependencies_at_the_boundary_test.go +36 -5
  126. package/cmd/ttscgraph/serve_shards_match_full_dump_oracle_test.go +12 -3
  127. package/cmd/ttscgraph/serve_shards_merge_pending_and_new_edits_test.go +36 -3
  128. package/cmd/ttscgraph/serve_shards_prune_unreferenced_external_endpoints_test.go +18 -2
  129. package/cmd/ttscgraph/serve_shards_publish_created_source_test.go +16 -13
  130. package/cmd/ttscgraph/serve_shards_rebuild_declaration_edit_test.go +14 -4
  131. package/cmd/ttscgraph/serve_shards_refresh_cross_file_implementation_test.go +24 -5
  132. package/cmd/ttscgraph/serve_shards_refresh_dependent_diagnostics_test.go +30 -7
  133. package/cmd/ttscgraph/serve_shards_rename_moves_source_identity_test.go +14 -11
  134. package/cmd/ttscgraph/serve_shards_retry_preserves_committed_generation_test.go +17 -7
  135. package/cmd/ttscgraph/serve_shards_reuse_unaffected_sources_test.go +21 -7
  136. package/cmd/ttscgraph/serve_snapshot_proves_its_program_without_a_second_read_test.go +57 -16
  137. package/cmd/ttscgraph/serve_source_encoding_test.go +133 -0
  138. package/cmd/ttscserver/command_operation_families_test.go +207 -0
  139. package/cmd/ttscserver/main.go +121 -39
  140. package/cmd/ttscserver/resolve_launch_uses_native_flag_authority_test.go +147 -0
  141. package/cmd/ttscserver/run_lsp_forwards_execute_command_advertisement_flags_test.go +7 -0
  142. package/cmd/ttscserver/run_lsp_prefers_tsgo_flag_test.go +13 -1
  143. package/cmd/ttscserver/run_lsp_reports_getwd_error_test.go +5 -0
  144. package/cmd/ttscserver/run_lsp_reports_server_error_test.go +10 -3
  145. package/cmd/ttscserver/run_lsp_uses_native_plugin_manifest_source_test.go +13 -10
  146. package/cmd/ttscserver/run_lsp_uses_tsgo_environment_test.go +10 -3
  147. package/driver/authored_region_maps_positions_around_the_preamble_test.go +95 -0
  148. package/driver/build_information_uses_selected_output_identity_test.go +148 -0
  149. package/driver/check_observations.go +67 -0
  150. package/driver/config_discovery.go +93 -24
  151. package/driver/declaration_shape.go +9 -0
  152. package/driver/diagnostics_preamble.go +8 -7
  153. package/driver/emit_containment.go +29 -8
  154. package/driver/emit_plugin.go +106 -36
  155. package/driver/emit_plugin_output.go +26 -2
  156. package/driver/emit_provenance.go +155 -0
  157. package/driver/graph.go +54 -20
  158. package/driver/host.go +26 -3
  159. package/driver/input_observation.go +78 -16
  160. package/driver/input_observation_test.go +34 -11
  161. package/driver/lsp.go +401 -30
  162. package/driver/overlay.go +69 -2
  163. package/driver/plugins.go +256 -24
  164. package/driver/private_result.go +43 -0
  165. package/driver/program.go +439 -95
  166. package/driver/resolution_candidates.go +63 -14
  167. package/driver/resolution_candidates_test.go +28 -0
  168. package/driver/resolutioninputs/recorder.cjs +1149 -0
  169. package/driver/resolutioninputs/resolutioninputs.go +37 -0
  170. package/driver/rewrite.go +373 -420
  171. package/driver/session.go +80 -12
  172. package/driver/sourcemap_preamble.go +38 -16
  173. package/driver/transform_dependencies.go +38 -10
  174. package/driver/transform_dependencies_declares_every_file_without_a_contributor_test.go +9 -8
  175. package/driver/transform_dependencies_drops_a_self_reported_dependency_test.go +7 -6
  176. package/driver/transform_dependencies_keys_a_reported_path_like_the_envelope_test.go +9 -9
  177. package/driver/transform_dependencies_requires_every_contributor_to_declare_test.go +10 -5
  178. package/driver/transform_dependencies_stays_silent_for_an_undeclared_contributor_test.go +8 -6
  179. package/driver/transform_dependencies_withdraws_completeness_after_an_unusable_dependency_test.go +9 -5
  180. package/driver/transform_source_map.go +388 -0
  181. package/driver/windowsjunction/create_preserves_existing_directory_windows_test.go +48 -0
  182. package/driver/windowsjunction/create_treats_paths_as_data_windows_test.go +55 -0
  183. package/driver/windowsjunction/windowsjunction.go +17 -1
  184. package/go.mod +10 -10
  185. package/go.sum +10 -10
  186. package/internal/cwd/cwd.go +13 -0
  187. package/internal/e2etrace/artifact.go +147 -0
  188. package/internal/e2etrace/completion_hints.go +35 -0
  189. package/internal/e2etrace/completion_hints_test.go +76 -0
  190. package/internal/e2etrace/e2etrace.go +303 -0
  191. package/internal/e2etrace/output.go +50 -0
  192. package/internal/graph/artifacts.go +69 -12
  193. package/internal/graph/artifacts_index_what_a_plugin_published_test.go +19 -8
  194. package/internal/graph/artifacts_survive_a_partial_rebuild_test.go +11 -12
  195. package/internal/graph/assigned_implementations_of_declaration_file_symbols_leave_no_edge_source_test.go +10 -12
  196. package/internal/graph/assigned_implementations_of_node_modules_symbols_leave_no_edge_source_test.go +7 -1
  197. package/internal/graph/build.go +122 -38
  198. package/internal/graph/build_files_reuses_committed_cross_file_endpoints_test.go +9 -3
  199. package/internal/graph/build_keeps_source_distributed_dependencies_at_the_external_boundary_test.go +10 -1
  200. package/internal/graph/build_records_a_node_per_top_level_declaration_test.go +10 -4
  201. package/internal/graph/build_releases_the_scratch_it_no_longer_reads_test.go +22 -15
  202. package/internal/graph/decorators.go +18 -0
  203. package/internal/graph/decorators_capture_name_and_literal_arguments_test.go +9 -4
  204. package/internal/graph/diagnostics.go +21 -8
  205. package/internal/graph/doc_refs_are_the_use_the_checker_already_counts_test.go +25 -13
  206. package/internal/graph/doc_refs_resolve_documentation_links_test.go +19 -15
  207. package/internal/graph/doc_tags.go +28 -19
  208. package/internal/graph/doc_tags_are_claimed_before_they_are_read_test.go +16 -6
  209. package/internal/graph/doc_tags_capture_every_unrecognized_tag_test.go +9 -2
  210. package/internal/graph/doc_tags_read_only_what_the_parser_attached_test.go +12 -8
  211. package/internal/graph/doc_tags_stop_at_the_external_boundary_test.go +11 -1
  212. package/internal/graph/doc_tags_survive_line_endings_and_repeated_blocks_test.go +16 -6
  213. package/internal/graph/dump.go +200 -51
  214. package/internal/graph/dump_checkout_paths_are_stable_test.go +9 -2
  215. package/internal/graph/dump_diagnostics_ride_the_generation_that_built_it_test.go +10 -11
  216. package/internal/graph/dump_evidence_skips_leading_trivia_test.go +8 -2
  217. package/internal/graph/dump_is_a_function_of_the_source_test.go +12 -13
  218. package/internal/graph/dump_never_serializes_a_list_as_null_test.go +9 -9
  219. package/internal/graph/dump_path_mapper_caches_alias_resolution_test.go +10 -2
  220. package/internal/graph/dump_path_mapper_rejects_unportable_roots_and_collisions_test.go +53 -0
  221. package/internal/graph/{dump_paths_are_portable_and_injective_test.go → dump_path_mapper_uses_portable_coordinates_test.go} +8 -43
  222. package/internal/graph/dump_paths.go +61 -25
  223. package/internal/graph/dump_paths_canonicalize_windows_short_root_test.go +45 -8
  224. package/internal/graph/dump_rejects_provenance_only_path_errors_test.go +5 -0
  225. package/internal/graph/dump_serializes_the_full_graph_test.go +13 -19
  226. package/internal/graph/dump_symlink_project_publishes_matching_base_test.go +8 -0
  227. package/internal/graph/dump_uses_ecma_line_terminators_test.go +12 -6
  228. package/internal/graph/duplicate_variable_object_members_keep_first_declaration_test.go +11 -8
  229. package/internal/graph/edge_spans_point_to_resolved_usage_test.go +13 -5
  230. package/internal/graph/edges.go +44 -47
  231. package/internal/graph/edges_cover_class_level_references_test.go +14 -11
  232. package/internal/graph/enum_initializer_calls_are_edges_test.go +13 -3
  233. package/internal/graph/enum_members_carry_their_names_on_the_enum_node_test.go +19 -26
  234. package/internal/graph/exports.go +3 -5
  235. package/internal/graph/file_diagnostics_match_tsgo_code_and_location_test.go +9 -4
  236. package/internal/graph/file_diagnostics_report_code_column_and_message_test.go +11 -5
  237. package/internal/graph/function_locals_do_not_collide_test.go +27 -7
  238. package/internal/graph/gitignore.go +25 -12
  239. package/internal/graph/graph.go +167 -52
  240. package/internal/graph/heritage_edges_cover_implements_and_interface_extends_test.go +11 -3
  241. package/internal/graph/heritage_edges_keep_extends_and_implements_to_same_base_test.go +6 -0
  242. package/internal/graph/heritage_edges_record_extends_versus_implements_origin_test.go +9 -3
  243. package/internal/graph/heritage_edges_traverse_barrels_and_stop_at_external_leaves_test.go +11 -4
  244. package/internal/graph/line_model.go +44 -25
  245. package/internal/graph/literals.go +6 -7
  246. package/internal/graph/literals_are_absent_when_the_type_admits_more_than_it_can_name_test.go +10 -5
  247. package/internal/graph/literals_cover_enum_members_the_graph_has_no_nodes_for_test.go +15 -17
  248. package/internal/graph/literals_do_not_depend_on_declaration_line_wrapping_test.go +10 -9
  249. package/internal/graph/literals_render_every_value_in_typescript_source_form_test.go +11 -11
  250. package/internal/graph/literals_resolve_through_alias_indirection_test.go +11 -11
  251. package/internal/graph/member_relation_edges_follow_checker_validity_test.go +11 -2
  252. package/internal/graph/member_relation_edges_preserve_checker_boundaries_test.go +11 -1
  253. package/internal/graph/member_relation_edges_reject_checker_invalid_pairs_test.go +12 -7
  254. package/internal/graph/namespace_dotted_form_qualifies_deeply_test.go +12 -3
  255. package/internal/graph/namespace_members_become_qualified_nodes_and_edges_test.go +12 -2
  256. package/internal/graph/node_identity_is_position_invariant_test.go +8 -2
  257. package/internal/graph/node_ids_preserve_hash_bearing_components_test.go +10 -2
  258. package/internal/graph/node_modifiers_emit_union_strings_test.go +13 -12
  259. package/internal/graph/nodes_are_marked_exported_through_the_export_table_test.go +12 -14
  260. package/internal/graph/object_literal_declarations_resolve_calls_test.go +170 -0
  261. package/internal/graph/object_literal_members_ride_on_the_snapshot_test.go +14 -13
  262. package/internal/graph/object_member_signatures_preserve_literal_whitespace_test.go +11 -7
  263. package/internal/graph/object_members.go +100 -1
  264. package/internal/graph/overload_implementation_replaces_signature_test.go +13 -2
  265. package/internal/graph/property_member_edges_remain_owner_visible_test.go +9 -3
  266. package/internal/graph/provenance.go +172 -87
  267. package/internal/graph/resolve.go +46 -12
  268. package/internal/graph/resolve_prefers_implementation_declaration_test.go +10 -2
  269. package/internal/graph/resolve_unwraps_barrel_reexport_to_real_declaration_test.go +16 -20
  270. package/internal/graph/source.go +16 -6
  271. package/internal/graph/source_texts_cover_every_resident_program_source_test.go +11 -7
  272. package/internal/graph/type_ref_edges_cover_typeof_as_satisfies_test.go +21 -2
  273. package/internal/graph/type_ref_edges_resolve_named_types_across_files_test.go +8 -3
  274. package/internal/graph/value_access_edges_cover_properties_test.go +11 -3
  275. package/internal/graph/value_call_edges_attribute_function_assignments_to_members_test.go +10 -4
  276. package/internal/graph/value_call_edges_cover_jsx_components_test.go +12 -8
  277. package/internal/graph/value_call_edges_cover_methods_and_constructors_test.go +12 -9
  278. package/internal/graph/value_call_edges_cover_variable_bound_callables_test.go +9 -3
  279. package/internal/graph/value_call_edges_do_not_double_record_invoked_member_access_test.go +10 -3
  280. package/internal/graph/value_call_edges_record_construct_versus_call_origin_test.go +12 -9
  281. package/internal/graph/value_call_edges_resolve_across_files_and_dedupe_test.go +10 -3
  282. package/internal/graph/value_call_edges_skip_self_and_unresolved_test.go +16 -5
  283. package/internal/graph/wire_node_ids_share_alias_resolution_test.go +10 -4
  284. package/internal/graphsymbols/position_helpers_follow_ecma_line_terminators_test.go +16 -4
  285. package/internal/graphsymbols/provider.go +278 -113
  286. package/internal/lspserver/lsp_clean_didopen_refreshes_compiler_state_test.go +14 -12
  287. package/internal/lspserver/lsp_completion_gate_never_refuses_a_matching_line_test.go +7 -1
  288. package/internal/lspserver/lsp_completion_hints_longest_trigger_wins_test.go +30 -5
  289. package/internal/lspserver/lsp_completion_hints_nearest_trigger_wins_test.go +5 -0
  290. package/internal/lspserver/lsp_completion_merges_into_upstream_response_test.go +23 -10
  291. package/internal/lspserver/lsp_completion_nearest_hint_replaces_nearest_filter_test.go +7 -1
  292. package/internal/lspserver/lsp_completion_preserves_completion_list_extensions_test.go +13 -5
  293. package/internal/lspserver/lsp_completion_refuses_hints_inside_a_string_literal_test.go +11 -7
  294. package/internal/lspserver/lsp_completion_replaces_full_filter_in_rank_order_test.go +12 -2
  295. package/internal/lspserver/lsp_completion_request.go +5 -26
  296. package/internal/lspserver/lsp_completion_scope.go +13 -10
  297. package/internal/lspserver/lsp_completion_scope_bench_test.go +11 -5
  298. package/internal/lspserver/lsp_completion_scope_classifies_regex_statement_and_operator_boundaries_test.go +8 -1
  299. package/internal/lspserver/lsp_completion_scope_ignores_jsdoc_bytes_in_literals_test.go +11 -10
  300. package/internal/lspserver/lsp_completion_scope_refuses_regex_hints_test.go +7 -3
  301. package/internal/lspserver/lsp_completion_trigger_uses_last_rune_test.go +6 -0
  302. package/internal/lspserver/lsp_deleted_watched_file_withdraws_plugin_diagnostics_test.go +11 -10
  303. package/internal/lspserver/lsp_didsave_keeps_the_incremental_changed_uri_path_test.go +12 -9
  304. package/internal/lspserver/lsp_document_diagnostics_omits_cached_project_when_current_result_has_none_test.go +17 -5
  305. package/internal/lspserver/lsp_envelope.go +84 -11
  306. package/internal/lspserver/lsp_executable_project_input_change_requests_launcher_restart_test.go +12 -9
  307. package/internal/lspserver/lsp_external_watched_change_retains_program_test.go +8 -2
  308. package/internal/lspserver/lsp_frame.go +42 -10
  309. package/internal/lspserver/lsp_hints_absence_is_not_an_error_test.go +16 -15
  310. package/internal/lspserver/lsp_hints_refresh_coalesces_concurrent_requests_test.go +21 -12
  311. package/internal/lspserver/lsp_hints_refresh_ignores_a_superseded_generation_test.go +20 -12
  312. package/internal/lspserver/lsp_hints_refresh_keeps_each_producer_isolated_test.go +30 -9
  313. package/internal/lspserver/lsp_hints_refresh_replaces_the_session_snapshot_test.go +25 -18
  314. package/internal/lspserver/lsp_hints_refresh_scheduled_by_editor_events_test.go +12 -12
  315. package/internal/lspserver/lsp_hints_refresh_serves_completion_while_running_test.go +21 -8
  316. package/internal/lspserver/lsp_index_byte_from_bounds_its_search_start_test.go +9 -7
  317. package/internal/lspserver/lsp_initialize_constrains_position_encoding_to_utf16_test.go +57 -21
  318. package/internal/lspserver/lsp_late_completion_trigger_is_reported_once_test.go +16 -17
  319. package/internal/lspserver/lsp_native_completion_hints_decode_flat_lint_wire_test.go +8 -2
  320. package/internal/lspserver/lsp_native_completion_hints_grouped_compatibility_boundary_test.go +5 -0
  321. package/internal/lspserver/lsp_native_plugin_source.go +381 -202
  322. package/internal/lspserver/lsp_native_plugin_source_ends_the_session_on_a_selection_input_test.go +234 -0
  323. package/internal/lspserver/lsp_native_reply_policies_test.go +475 -0
  324. package/internal/lspserver/lsp_native_reply_policy.go +232 -0
  325. package/internal/lspserver/lsp_native_resident.go +171 -57
  326. package/internal/lspserver/lsp_plugin.go +372 -68
  327. package/internal/lspserver/lsp_plugin_completion_resolve_stays_local_test.go +13 -4
  328. package/internal/lspserver/lsp_plugin_selection_inputs.go +283 -0
  329. package/internal/lspserver/lsp_plugin_selection_inputs_follow_directory_case_semantics_windows_test.go +81 -0
  330. package/internal/lspserver/lsp_position_conversions_span_astral_and_combining_runes_test.go +33 -11
  331. package/internal/lspserver/lsp_project_context_transport_identity_test.go +14 -2
  332. package/internal/lspserver/lsp_project_diagnostics.go +25 -4
  333. package/internal/lspserver/lsp_project_diagnostics_capability_is_independent_test.go +13 -2
  334. package/internal/lspserver/lsp_project_diagnostics_program_input_overlap_refreshes_all_producers_test.go +14 -4
  335. package/internal/lspserver/lsp_project_diagnostics_refresh_accumulates_owner_freshness_test.go +8 -2
  336. package/internal/lspserver/lsp_project_diagnostics_refresh_keeps_each_producer_last_good_test.go +10 -5
  337. package/internal/lspserver/lsp_project_diagnostics_refreshes_only_input_owners_test.go +14 -2
  338. package/internal/lspserver/lsp_project_diagnostics_resume_preserves_generation_test.go +8 -2
  339. package/internal/lspserver/lsp_project_diagnostics_translates_relative_client_project_test.go +15 -11
  340. package/internal/lspserver/lsp_project_input_ownership_resolves_declared_spellings_test.go +17 -8
  341. package/internal/lspserver/lsp_project_input_path_key_windows.go +16 -16
  342. package/internal/lspserver/lsp_project_input_path_key_windows_test.go +34 -18
  343. package/internal/lspserver/lsp_project_input_registration.go +5 -1
  344. package/internal/lspserver/lsp_project_input_registration_rechecks_selection_baseline_test.go +10 -4
  345. package/internal/lspserver/lsp_project_input_registration_reconciles_rejected_pending_request_test.go +5 -0
  346. package/internal/lspserver/lsp_project_input_registration_shapes_patterns_test.go +9 -3
  347. package/internal/lspserver/lsp_project_input_watchers_anchor_missing_paths_test.go +8 -3
  348. package/internal/lspserver/lsp_project_inputs.go +203 -59
  349. package/internal/lspserver/lsp_project_inputs_match_missing_exact_and_glob_test.go +10 -6
  350. package/internal/lspserver/lsp_project_inputs_reject_invalid_and_foreign_snapshots_test.go +25 -2
  351. package/internal/lspserver/lsp_proxy.go +239 -80
  352. package/internal/lspserver/lsp_refresh.go +16 -1
  353. package/internal/lspserver/lsp_reload_directories_compare_immediate_topology_test.go +66 -19
  354. package/internal/lspserver/lsp_reload_directories_separate_glob_territory_test.go +26 -6
  355. package/internal/lspserver/lsp_reload_file_fingerprint_preserves_raw_symlink_target_test.go +12 -6
  356. package/internal/lspserver/lsp_reload_fingerprints_read_a_junction_as_a_link_test.go +76 -0
  357. package/internal/lspserver/lsp_resident_falls_back_when_serve_unsupported_test.go +20 -13
  358. package/internal/lspserver/lsp_resident_invalidation_broadcasts_program_input_overlap_test.go +9 -4
  359. package/internal/lspserver/lsp_resident_invalidation_targets_project_input_owners_test.go +6 -1
  360. package/internal/lspserver/lsp_resident_maps_verb_args_test.go +5 -0
  361. package/internal/lspserver/lsp_same_transport_entries_are_deduplicated_test.go +10 -1
  362. package/internal/lspserver/lsp_server.go +124 -21
  363. package/internal/lspserver/lsp_symbols.go +92 -13
  364. package/internal/lspserver/lsp_watched_file_changes_reach_compiler_caches_test.go +11 -10
  365. package/internal/sourceprocess/complete_group.go +70 -0
  366. package/internal/sourceprocess/complete_group_preserves_original_wait_and_requires_independent_absence_test.go +145 -0
  367. package/internal/sourceprocess/contain_unix.go +143 -0
  368. package/internal/sourceprocess/contain_windows.go +442 -0
  369. package/internal/sourceprocess/darwin_group_retirement_preserves_phase_evidence_test.go +287 -0
  370. package/internal/sourceprocess/observe_exit_darwin.go +57 -0
  371. package/internal/sourceprocess/observe_exit_linux.go +27 -0
  372. package/internal/sourceprocess/observe_exit_other.go +11 -0
  373. package/internal/sourceprocess/reap_linux.go +31 -0
  374. package/internal/sourceprocess/reap_other.go +10 -0
  375. package/internal/sourceprocess/request_preserves_native_command_inputs_test.go +86 -0
  376. package/internal/sourceprocess/run.go +216 -0
  377. package/internal/sourceprocess/target_windows.go +211 -0
  378. package/internal/sourceprocess/windows_job_accounting_rejects_invalid_boundary_test.go +97 -0
  379. package/internal/sourceprocess/windows_target_owns_suspended_admission_test.go +179 -0
  380. package/internal/watchhelper/run.go +32 -0
  381. package/internal/watchhelper/run_linux.go +323 -0
  382. package/internal/watchhelper/run_linux_test.go +418 -0
  383. package/internal/watchhelper/run_other.go +16 -0
  384. package/internal/watchhelper/watchhelper.go +100 -0
  385. package/lib/TtscCompiler.d.ts +118 -21
  386. package/lib/TtscCompiler.js +175 -179
  387. package/lib/TtscCompiler.js.map +1 -1
  388. package/lib/TtscService.d.ts +66 -18
  389. package/lib/TtscService.js +81 -24
  390. package/lib/TtscService.js.map +1 -1
  391. package/lib/TtscServiceRequestOptions.d.ts +21 -0
  392. package/lib/TtscServiceRequestOptions.js +3 -0
  393. package/lib/TtscServiceRequestOptions.js.map +1 -0
  394. package/lib/compiler/internal/CapturedProcessOutput.d.ts +61 -0
  395. package/lib/compiler/internal/CapturedProcessOutput.js +3 -0
  396. package/lib/compiler/internal/CapturedProcessOutput.js.map +1 -0
  397. package/lib/compiler/internal/CompilerArgumentsInspection.d.ts +53 -0
  398. package/lib/compiler/internal/CompilerArgumentsInspection.js +173 -0
  399. package/lib/compiler/internal/CompilerArgumentsInspection.js.map +1 -0
  400. package/lib/compiler/internal/EmitOwnershipIndex.d.ts +92 -0
  401. package/lib/compiler/internal/EmitOwnershipIndex.js +215 -0
  402. package/lib/compiler/internal/EmitOwnershipIndex.js.map +1 -0
  403. package/lib/compiler/internal/PrivateCompilerOutput.d.ts +67 -0
  404. package/lib/compiler/internal/PrivateCompilerOutput.js +245 -0
  405. package/lib/compiler/internal/PrivateCompilerOutput.js.map +1 -0
  406. package/lib/compiler/internal/ResidentCheckProcess.d.ts +127 -0
  407. package/lib/compiler/internal/ResidentCheckProcess.js +403 -0
  408. package/lib/compiler/internal/ResidentCheckProcess.js.map +1 -0
  409. package/lib/compiler/internal/ResidentCheckProcessOptions.d.ts +29 -0
  410. package/lib/compiler/internal/ResidentCheckProcessOptions.js +3 -0
  411. package/lib/compiler/internal/ResidentCheckProcessOptions.js.map +1 -0
  412. package/lib/compiler/internal/ResidentCheckRequest.d.ts +37 -0
  413. package/lib/compiler/internal/ResidentCheckRequest.js +3 -0
  414. package/lib/compiler/internal/ResidentCheckRequest.js.map +1 -0
  415. package/lib/compiler/internal/ResidentCheckResult.d.ts +23 -0
  416. package/lib/compiler/internal/ResidentCheckResult.js +3 -0
  417. package/lib/compiler/internal/ResidentCheckResult.js.map +1 -0
  418. package/lib/compiler/internal/ResidentCheckTelemetry.d.ts +33 -0
  419. package/lib/compiler/internal/ResidentCheckTelemetry.js +3 -0
  420. package/lib/compiler/internal/ResidentCheckTelemetry.js.map +1 -0
  421. package/lib/compiler/internal/ResidentReplyKind.d.ts +18 -0
  422. package/lib/compiler/internal/ResidentReplyKind.js +3 -0
  423. package/lib/compiler/internal/ResidentReplyKind.js.map +1 -0
  424. package/lib/compiler/internal/ResidentTransformProcess.d.ts +83 -0
  425. package/lib/compiler/internal/ResidentTransformProcess.js +261 -0
  426. package/lib/compiler/internal/ResidentTransformProcess.js.map +1 -0
  427. package/lib/compiler/internal/ResidentTransformProcessOptions.d.ts +27 -0
  428. package/lib/compiler/internal/ResidentTransformProcessOptions.js +3 -0
  429. package/lib/compiler/internal/ResidentTransformProcessOptions.js.map +1 -0
  430. package/lib/compiler/internal/ResidentTransformReply.d.ts +51 -0
  431. package/lib/compiler/internal/ResidentTransformReply.js +79 -0
  432. package/lib/compiler/internal/ResidentTransformReply.js.map +1 -0
  433. package/lib/compiler/internal/ResidentTransformRequestOptions.d.ts +16 -0
  434. package/lib/compiler/internal/ResidentTransformRequestOptions.js +3 -0
  435. package/lib/compiler/internal/ResidentTransformRequestOptions.js.map +1 -0
  436. package/lib/compiler/internal/ResidentTransformRequests.d.ts +102 -0
  437. package/lib/compiler/internal/ResidentTransformRequests.js +172 -0
  438. package/lib/compiler/internal/ResidentTransformRequests.js.map +1 -0
  439. package/lib/compiler/internal/StartedResidentTransform.d.ts +27 -0
  440. package/lib/compiler/internal/StartedResidentTransform.js +3 -0
  441. package/lib/compiler/internal/StartedResidentTransform.js.map +1 -0
  442. package/lib/compiler/internal/TransformProjectWorkerReply.d.ts +34 -0
  443. package/lib/compiler/internal/TransformProjectWorkerReply.js +3 -0
  444. package/lib/compiler/internal/TransformProjectWorkerReply.js.map +1 -0
  445. package/lib/compiler/internal/TransformProjectWorkerRequest.d.ts +39 -0
  446. package/lib/compiler/internal/TransformProjectWorkerRequest.js +3 -0
  447. package/lib/compiler/internal/TransformProjectWorkerRequest.js.map +1 -0
  448. package/lib/compiler/internal/build/BuildExecution.d.ts +359 -0
  449. package/lib/compiler/internal/build/BuildExecution.js +977 -0
  450. package/lib/compiler/internal/build/BuildExecution.js.map +1 -0
  451. package/lib/compiler/internal/build/BuildTiming.d.ts +99 -0
  452. package/lib/compiler/internal/build/BuildTiming.js +113 -0
  453. package/lib/compiler/internal/build/BuildTiming.js.map +1 -0
  454. package/lib/compiler/internal/build/CompilerDiagnostics.d.ts +82 -0
  455. package/lib/compiler/internal/build/CompilerDiagnostics.js +270 -0
  456. package/lib/compiler/internal/build/CompilerDiagnostics.js.map +1 -0
  457. package/lib/compiler/internal/build/NativePluginArguments.d.ts +114 -0
  458. package/lib/compiler/internal/build/NativePluginArguments.js +255 -0
  459. package/lib/compiler/internal/build/NativePluginArguments.js.map +1 -0
  460. package/lib/compiler/internal/build/PassthroughFlags.d.ts +137 -0
  461. package/lib/compiler/internal/build/PassthroughFlags.js +213 -0
  462. package/lib/compiler/internal/build/PassthroughFlags.js.map +1 -0
  463. package/lib/compiler/internal/build/PluginFailureDiagnostics.d.ts +48 -0
  464. package/lib/compiler/internal/build/PluginFailureDiagnostics.js +68 -0
  465. package/lib/compiler/internal/build/PluginFailureDiagnostics.js.map +1 -0
  466. package/lib/compiler/internal/build/ResidentCheckEntryPlan.d.ts +38 -0
  467. package/lib/compiler/internal/build/ResidentCheckEntryPlan.js +3 -0
  468. package/lib/compiler/internal/build/ResidentCheckEntryPlan.js.map +1 -0
  469. package/lib/compiler/internal/build/ResidentCheckWatchChange.d.ts +30 -0
  470. package/lib/compiler/internal/build/ResidentCheckWatchChange.js +3 -0
  471. package/lib/compiler/internal/build/ResidentCheckWatchChange.js.map +1 -0
  472. package/lib/compiler/internal/build/ResidentCheckWatchSession.d.ts +113 -0
  473. package/lib/compiler/internal/build/ResidentCheckWatchSession.js +378 -0
  474. package/lib/compiler/internal/build/ResidentCheckWatchSession.js.map +1 -0
  475. package/lib/compiler/internal/build/RunBuildOptions.d.ts +130 -0
  476. package/lib/compiler/internal/build/RunBuildOptions.js +3 -0
  477. package/lib/compiler/internal/build/RunBuildOptions.js.map +1 -0
  478. package/lib/compiler/internal/build/TsgoArguments.d.ts +168 -0
  479. package/lib/compiler/internal/build/TsgoArguments.js +324 -0
  480. package/lib/compiler/internal/build/TsgoArguments.js.map +1 -0
  481. package/lib/compiler/internal/build/appendBuildOutput.d.ts +41 -0
  482. package/lib/compiler/internal/build/appendBuildOutput.js +182 -0
  483. package/lib/compiler/internal/build/appendBuildOutput.js.map +1 -0
  484. package/lib/compiler/internal/build/bufferResidentCheckEntryRequests.d.ts +20 -0
  485. package/lib/compiler/internal/build/bufferResidentCheckEntryRequests.js +40 -0
  486. package/lib/compiler/internal/build/bufferResidentCheckEntryRequests.js.map +1 -0
  487. package/lib/compiler/internal/build/createProcessDiagnostic.d.ts +19 -0
  488. package/lib/compiler/internal/build/createProcessDiagnostic.js +30 -0
  489. package/lib/compiler/internal/build/createProcessDiagnostic.js.map +1 -0
  490. package/lib/compiler/internal/build/isAbsoluteLocalProjectInputPath.d.ts +22 -0
  491. package/lib/compiler/internal/build/isAbsoluteLocalProjectInputPath.js +59 -0
  492. package/lib/compiler/internal/build/isAbsoluteLocalProjectInputPath.js.map +1 -0
  493. package/lib/compiler/internal/build/mergeProjectInputSnapshots.d.ts +28 -0
  494. package/lib/compiler/internal/build/mergeProjectInputSnapshots.js +121 -0
  495. package/lib/compiler/internal/build/mergeProjectInputSnapshots.js.map +1 -0
  496. package/lib/compiler/internal/build/normalizeBuildOutput.d.ts +29 -0
  497. package/lib/compiler/internal/build/normalizeBuildOutput.js +72 -0
  498. package/lib/compiler/internal/build/normalizeBuildOutput.js.map +1 -0
  499. package/lib/compiler/internal/build/parseProjectInputSnapshot.d.ts +26 -0
  500. package/lib/compiler/internal/build/parseProjectInputSnapshot.js +68 -0
  501. package/lib/compiler/internal/build/parseProjectInputSnapshot.js.map +1 -0
  502. package/lib/compiler/internal/build/planResidentCheckEntries.d.ts +21 -0
  503. package/lib/compiler/internal/build/planResidentCheckEntries.js +45 -0
  504. package/lib/compiler/internal/build/planResidentCheckEntries.js.map +1 -0
  505. package/lib/compiler/internal/build/privateRuntimeRootDir.d.ts +20 -0
  506. package/lib/compiler/internal/build/privateRuntimeRootDir.js +35 -0
  507. package/lib/compiler/internal/build/privateRuntimeRootDir.js.map +1 -0
  508. package/lib/compiler/internal/build/residentCheckRequest.d.ts +22 -0
  509. package/lib/compiler/internal/build/residentCheckRequest.js +42 -0
  510. package/lib/compiler/internal/build/residentCheckRequest.js.map +1 -0
  511. package/lib/compiler/internal/build/runBuild.d.ts +22 -0
  512. package/lib/compiler/internal/build/runBuild.js +44 -0
  513. package/lib/compiler/internal/build/runBuild.js.map +1 -0
  514. package/lib/compiler/internal/build/runExternalEmitProvenance.d.ts +61 -0
  515. package/lib/compiler/internal/build/runExternalEmitProvenance.js +451 -0
  516. package/lib/compiler/internal/build/runExternalEmitProvenance.js.map +1 -0
  517. package/lib/compiler/internal/build/takeResidentCheckEntryRequest.d.ts +18 -0
  518. package/lib/compiler/internal/build/takeResidentCheckEntryRequest.js +28 -0
  519. package/lib/compiler/internal/build/takeResidentCheckEntryRequest.js.map +1 -0
  520. package/lib/compiler/internal/buildNativeCompiler.d.ts +16 -1
  521. package/lib/compiler/internal/buildNativeCompiler.js +14 -2
  522. package/lib/compiler/internal/buildNativeCompiler.js.map +1 -1
  523. package/lib/compiler/internal/captureProcessOutput.d.ts +23 -21
  524. package/lib/compiler/internal/captureProcessOutput.js +40 -26
  525. package/lib/compiler/internal/captureProcessOutput.js.map +1 -1
  526. package/lib/compiler/internal/compileProjectInMemory.d.ts +30 -7
  527. package/lib/compiler/internal/compileProjectInMemory.js +103 -83
  528. package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
  529. package/lib/compiler/internal/ensureExecutable.d.ts +15 -0
  530. package/lib/compiler/internal/ensureExecutable.js +40 -0
  531. package/lib/compiler/internal/ensureExecutable.js.map +1 -0
  532. package/lib/compiler/internal/findNearestGoMod.d.ts +23 -0
  533. package/lib/compiler/internal/findNearestGoMod.js +48 -0
  534. package/lib/compiler/internal/findNearestGoMod.js.map +1 -0
  535. package/lib/compiler/internal/isOutsideRelativePath.d.ts +18 -0
  536. package/lib/compiler/internal/isOutsideRelativePath.js +30 -0
  537. package/lib/compiler/internal/isOutsideRelativePath.js.map +1 -0
  538. package/lib/compiler/internal/outputText.d.ts +16 -0
  539. package/lib/compiler/internal/outputText.js +25 -0
  540. package/lib/compiler/internal/outputText.js.map +1 -0
  541. package/lib/compiler/internal/packageRootDir.d.ts +25 -0
  542. package/lib/compiler/internal/packageRootDir.js +47 -0
  543. package/lib/compiler/internal/packageRootDir.js.map +1 -0
  544. package/lib/compiler/internal/parseNativeTransformOutput.d.ts +88 -0
  545. package/lib/compiler/internal/parseNativeTransformOutput.js +552 -0
  546. package/lib/compiler/internal/parseNativeTransformOutput.js.map +1 -0
  547. package/lib/compiler/internal/project/CompilerProjectSelection.d.ts +80 -0
  548. package/lib/compiler/internal/project/CompilerProjectSelection.js +187 -0
  549. package/lib/compiler/internal/project/CompilerProjectSelection.js.map +1 -0
  550. package/lib/compiler/internal/project/ConfigJsonText.d.ts +50 -0
  551. package/lib/compiler/internal/project/ConfigJsonText.js +61 -0
  552. package/lib/compiler/internal/project/ConfigJsonText.js.map +1 -0
  553. package/lib/compiler/internal/project/compilerUsesCaseSensitiveFileNames.d.ts +48 -0
  554. package/lib/compiler/internal/project/compilerUsesCaseSensitiveFileNames.js +119 -0
  555. package/lib/compiler/internal/project/compilerUsesCaseSensitiveFileNames.js.map +1 -0
  556. package/lib/compiler/internal/project/createNativeProjectContextArgs.d.ts +11 -8
  557. package/lib/compiler/internal/project/createNativeProjectContextArgs.js +15 -17
  558. package/lib/compiler/internal/project/createNativeProjectContextArgs.js.map +1 -1
  559. package/lib/compiler/internal/project/createNativeProjectContextJson.d.ts +19 -0
  560. package/lib/compiler/internal/project/createNativeProjectContextJson.js +27 -0
  561. package/lib/compiler/internal/project/createNativeProjectContextJson.js.map +1 -0
  562. package/lib/compiler/internal/project/parseJsonc.d.ts +42 -0
  563. package/lib/compiler/internal/project/parseJsonc.js +317 -0
  564. package/lib/compiler/internal/project/parseJsonc.js.map +1 -0
  565. package/lib/compiler/internal/project/readJsonFile.d.ts +21 -0
  566. package/lib/compiler/internal/project/readJsonFile.js +38 -0
  567. package/lib/compiler/internal/project/readJsonFile.js.map +1 -0
  568. package/lib/compiler/internal/project/readJsoncFile.d.ts +20 -0
  569. package/lib/compiler/internal/project/readJsoncFile.js +47 -0
  570. package/lib/compiler/internal/project/readJsoncFile.js.map +1 -0
  571. package/lib/compiler/internal/project/readProjectConfig.d.ts +29 -2
  572. package/lib/compiler/internal/project/readProjectConfig.js +105 -168
  573. package/lib/compiler/internal/project/readProjectConfig.js.map +1 -1
  574. package/lib/compiler/internal/project/resolveOwningProjectConfig.d.ts +65 -0
  575. package/lib/compiler/internal/project/resolveOwningProjectConfig.js +248 -0
  576. package/lib/compiler/internal/project/resolveOwningProjectConfig.js.map +1 -0
  577. package/lib/compiler/internal/project/resolveProjectConfig.d.ts +17 -14
  578. package/lib/compiler/internal/project/resolveProjectConfig.js +19 -122
  579. package/lib/compiler/internal/project/resolveProjectConfig.js.map +1 -1
  580. package/lib/compiler/internal/project/resolveProjectIdentity.d.ts +32 -0
  581. package/lib/compiler/internal/project/resolveProjectIdentity.js +144 -0
  582. package/lib/compiler/internal/project/resolveProjectIdentity.js.map +1 -0
  583. package/lib/compiler/internal/project/resolveTsconfigExtends.d.ts +38 -0
  584. package/lib/compiler/internal/project/resolveTsconfigExtends.js +163 -0
  585. package/lib/compiler/internal/project/resolveTsconfigExtends.js.map +1 -0
  586. package/lib/compiler/internal/project/selectReferencedProject.d.ts +26 -0
  587. package/lib/compiler/internal/project/selectReferencedProject.js +48 -0
  588. package/lib/compiler/internal/project/selectReferencedProject.js.map +1 -0
  589. package/lib/compiler/internal/project/tsconfigExtendsFileCandidates.d.ts +34 -0
  590. package/lib/compiler/internal/project/tsconfigExtendsFileCandidates.js +55 -0
  591. package/lib/compiler/internal/project/tsconfigExtendsFileCandidates.js.map +1 -0
  592. package/lib/compiler/internal/readEffectiveCompilerOptions.d.ts +54 -0
  593. package/lib/compiler/internal/readEffectiveCompilerOptions.js +116 -0
  594. package/lib/compiler/internal/readEffectiveCompilerOptions.js.map +1 -0
  595. package/lib/compiler/internal/resolveBinary.d.ts +17 -1
  596. package/lib/compiler/internal/resolveBinary.js +24 -9
  597. package/lib/compiler/internal/resolveBinary.js.map +1 -1
  598. package/lib/compiler/internal/resolveTsgo.d.ts +22 -7
  599. package/lib/compiler/internal/resolveTsgo.js +25 -9
  600. package/lib/compiler/internal/resolveTsgo.js.map +1 -1
  601. package/lib/compiler/internal/runNativeCheckWithObservations.d.ts +41 -0
  602. package/lib/compiler/internal/runNativeCheckWithObservations.js +185 -0
  603. package/lib/compiler/internal/runNativeCheckWithObservations.js.map +1 -0
  604. package/lib/compiler/internal/runSingleFileEmit.d.ts +26 -5
  605. package/lib/compiler/internal/runSingleFileEmit.js +82 -27
  606. package/lib/compiler/internal/runSingleFileEmit.js.map +1 -1
  607. package/lib/compiler/internal/sharedHost/SEMANTIC_CONFIG_PATH_ENV.d.ts +2 -0
  608. package/lib/compiler/internal/sharedHost/SEMANTIC_CONFIG_PATH_ENV.js +6 -0
  609. package/lib/compiler/internal/sharedHost/SEMANTIC_CONFIG_PATH_ENV.js.map +1 -0
  610. package/lib/compiler/internal/sharedHost/SidecarEnvironment.d.ts +90 -0
  611. package/lib/compiler/internal/sharedHost/SidecarEnvironment.js +153 -0
  612. package/lib/compiler/internal/sharedHost/SidecarEnvironment.js.map +1 -0
  613. package/lib/compiler/internal/sharedHost/TSGO_ARGS_CWD_ENV.d.ts +7 -0
  614. package/lib/compiler/internal/sharedHost/TSGO_ARGS_CWD_ENV.js +11 -0
  615. package/lib/compiler/internal/sharedHost/TSGO_ARGS_CWD_ENV.js.map +1 -0
  616. package/lib/compiler/internal/sharedHost/TSGO_ARGS_ENV.d.ts +7 -0
  617. package/lib/compiler/internal/sharedHost/TSGO_ARGS_ENV.js +11 -0
  618. package/lib/compiler/internal/sharedHost/TSGO_ARGS_ENV.js.map +1 -0
  619. package/lib/compiler/internal/sharedHost/assertSharedHostCompatibility.d.ts +24 -0
  620. package/lib/compiler/internal/sharedHost/assertSharedHostCompatibility.js +46 -0
  621. package/lib/compiler/internal/sharedHost/assertSharedHostCompatibility.js.map +1 -0
  622. package/lib/compiler/internal/sharedHost/clearInheritedSemanticConfigPath.d.ts +15 -0
  623. package/lib/compiler/internal/sharedHost/clearInheritedSemanticConfigPath.js +23 -0
  624. package/lib/compiler/internal/sharedHost/clearInheritedSemanticConfigPath.js.map +1 -0
  625. package/lib/compiler/internal/sharedHost/clearInheritedTsgoArgs.d.ts +23 -0
  626. package/lib/compiler/internal/sharedHost/clearInheritedTsgoArgs.js +33 -0
  627. package/lib/compiler/internal/sharedHost/clearInheritedTsgoArgs.js.map +1 -0
  628. package/lib/compiler/internal/sharedHost/inheritedSidecarEnv.d.ts +27 -0
  629. package/lib/compiler/internal/sharedHost/inheritedSidecarEnv.js +41 -0
  630. package/lib/compiler/internal/sharedHost/inheritedSidecarEnv.js.map +1 -0
  631. package/lib/compiler/internal/sharedHost/isLinkedTransform.d.ts +16 -0
  632. package/lib/compiler/internal/sharedHost/isLinkedTransform.js +21 -0
  633. package/lib/compiler/internal/sharedHost/isLinkedTransform.js.map +1 -0
  634. package/lib/compiler/internal/sharedHost/linkedTransformPlugins.d.ts +19 -0
  635. package/lib/compiler/internal/sharedHost/linkedTransformPlugins.js +25 -0
  636. package/lib/compiler/internal/sharedHost/linkedTransformPlugins.js.map +1 -0
  637. package/lib/compiler/internal/sharedHost/publishLinkedTransformPlugins.d.ts +25 -0
  638. package/lib/compiler/internal/sharedHost/publishLinkedTransformPlugins.js +35 -0
  639. package/lib/compiler/internal/sharedHost/publishLinkedTransformPlugins.js.map +1 -0
  640. package/lib/compiler/internal/sharedHost/resolvePluginConfigDir.d.ts +26 -0
  641. package/lib/compiler/internal/sharedHost/resolvePluginConfigDir.js +36 -0
  642. package/lib/compiler/internal/sharedHost/resolvePluginConfigDir.js.map +1 -0
  643. package/lib/compiler/internal/sharedHost/selectSharedHostPlugin.d.ts +22 -0
  644. package/lib/compiler/internal/sharedHost/selectSharedHostPlugin.js +32 -0
  645. package/lib/compiler/internal/sharedHost/selectSharedHostPlugin.js.map +1 -0
  646. package/lib/compiler/internal/spawnNative.d.ts +15 -16
  647. package/lib/compiler/internal/spawnNative.js +20 -48
  648. package/lib/compiler/internal/spawnNative.js.map +1 -1
  649. package/lib/compiler/internal/startResidentTransform.d.ts +26 -17
  650. package/lib/compiler/internal/startResidentTransform.js +51 -36
  651. package/lib/compiler/internal/startResidentTransform.js.map +1 -1
  652. package/lib/compiler/internal/transformProjectInMemory.d.ts +42 -5
  653. package/lib/compiler/internal/transformProjectInMemory.js +197 -471
  654. package/lib/compiler/internal/transformProjectInMemory.js.map +1 -1
  655. package/lib/compiler/internal/transformProjectInWorker.d.ts +49 -0
  656. package/lib/compiler/internal/transformProjectInWorker.js +168 -0
  657. package/lib/compiler/internal/transformProjectInWorker.js.map +1 -0
  658. package/lib/compiler/internal/transformProjectWorker.js +37 -0
  659. package/lib/compiler/internal/transformProjectWorker.js.map +1 -0
  660. package/lib/flags/AnySubcommand.d.ts +18 -0
  661. package/lib/flags/AnySubcommand.js +3 -0
  662. package/lib/flags/AnySubcommand.js.map +1 -0
  663. package/lib/flags/COMPILER_ENUM_WHITESPACE.d.ts +2 -0
  664. package/lib/flags/COMPILER_ENUM_WHITESPACE.js +38 -0
  665. package/lib/flags/COMPILER_ENUM_WHITESPACE.js.map +1 -0
  666. package/lib/flags/COMPILER_OPTIONS.d.ts +6 -0
  667. package/lib/flags/COMPILER_OPTIONS.js +509 -0
  668. package/lib/flags/COMPILER_OPTIONS.js.map +1 -0
  669. package/lib/flags/COMPILER_OPTION_ASCII_FOLDS.d.ts +2 -0
  670. package/lib/flags/COMPILER_OPTION_ASCII_FOLDS.js +13 -0
  671. package/lib/flags/COMPILER_OPTION_ASCII_FOLDS.js.map +1 -0
  672. package/lib/flags/COMPILER_OPTION_KINDS.d.ts +2 -0
  673. package/lib/flags/COMPILER_OPTION_KINDS.js +14 -0
  674. package/lib/flags/COMPILER_OPTION_KINDS.js.map +1 -0
  675. package/lib/flags/CompilerOptionSpec.d.ts +27 -0
  676. package/lib/flags/CompilerOptionSpec.js +3 -0
  677. package/lib/flags/CompilerOptionSpec.js.map +1 -0
  678. package/lib/flags/FLAG_BY_TOKEN.d.ts +8 -0
  679. package/lib/flags/FLAG_BY_TOKEN.js +34 -0
  680. package/lib/flags/FLAG_BY_TOKEN.js.map +1 -0
  681. package/lib/flags/FLAG_SCHEMA.d.ts +35 -0
  682. package/lib/flags/{schema.js → FLAG_SCHEMA.js} +47 -153
  683. package/lib/flags/FLAG_SCHEMA.js.map +1 -0
  684. package/lib/flags/FlagKind.d.ts +22 -0
  685. package/lib/flags/FlagKind.js +3 -0
  686. package/lib/flags/FlagKind.js.map +1 -0
  687. package/lib/flags/FlagLayer.d.ts +19 -0
  688. package/lib/flags/FlagLayer.js +3 -0
  689. package/lib/flags/FlagLayer.js.map +1 -0
  690. package/lib/flags/FlagSpec.d.ts +104 -0
  691. package/lib/flags/FlagSpec.js +3 -0
  692. package/lib/flags/FlagSpec.js.map +1 -0
  693. package/lib/flags/ParseOptions.d.ts +92 -0
  694. package/lib/flags/ParseOptions.js +3 -0
  695. package/lib/flags/ParseOptions.js.map +1 -0
  696. package/lib/flags/ParseResult.d.ts +37 -0
  697. package/lib/flags/ParseResult.js +3 -0
  698. package/lib/flags/ParseResult.js.map +1 -0
  699. package/lib/flags/TtscSubcommand.d.ts +14 -0
  700. package/lib/flags/TtscSubcommand.js +3 -0
  701. package/lib/flags/TtscSubcommand.js.map +1 -0
  702. package/lib/flags/TtsxSubcommand.d.ts +13 -0
  703. package/lib/flags/TtsxSubcommand.js +3 -0
  704. package/lib/flags/TtsxSubcommand.js.map +1 -0
  705. package/lib/flags/ValueValidator.d.ts +14 -0
  706. package/lib/flags/ValueValidator.js +3 -0
  707. package/lib/flags/ValueValidator.js.map +1 -0
  708. package/lib/flags/buildGoAllowList.d.ts +18 -0
  709. package/lib/flags/buildGoAllowList.js +45 -0
  710. package/lib/flags/buildGoAllowList.js.map +1 -0
  711. package/lib/flags/flagsForSubcommand.d.ts +18 -0
  712. package/lib/flags/flagsForSubcommand.js +23 -0
  713. package/lib/flags/flagsForSubcommand.js.map +1 -0
  714. package/lib/flags/getBoolean.d.ts +19 -0
  715. package/lib/flags/getBoolean.js +27 -0
  716. package/lib/flags/getBoolean.js.map +1 -0
  717. package/lib/flags/getNumber.d.ts +16 -0
  718. package/lib/flags/getNumber.js +24 -0
  719. package/lib/flags/getNumber.js.map +1 -0
  720. package/lib/flags/getString.d.ts +16 -0
  721. package/lib/flags/getString.js +24 -0
  722. package/lib/flags/getString.js.map +1 -0
  723. package/lib/flags/getStringList.d.ts +19 -0
  724. package/lib/flags/getStringList.js +24 -0
  725. package/lib/flags/getStringList.js.map +1 -0
  726. package/lib/flags/normalizeCompilerEnumValue.d.ts +20 -0
  727. package/lib/flags/normalizeCompilerEnumValue.js +40 -0
  728. package/lib/flags/normalizeCompilerEnumValue.js.map +1 -0
  729. package/lib/flags/normalizeFlagToken.d.ts +28 -0
  730. package/lib/flags/normalizeFlagToken.js +38 -0
  731. package/lib/flags/normalizeFlagToken.js.map +1 -0
  732. package/lib/flags/parseFlags.d.ts +18 -0
  733. package/lib/flags/parseFlags.js +288 -0
  734. package/lib/flags/parseFlags.js.map +1 -0
  735. package/lib/flags/readCompilerOptionOccurrence.d.ts +34 -0
  736. package/lib/flags/readCompilerOptionOccurrence.js +81 -0
  737. package/lib/flags/readCompilerOptionOccurrence.js.map +1 -0
  738. package/lib/flags/readCompilerOptionValues.d.ts +33 -0
  739. package/lib/flags/readCompilerOptionValues.js +58 -0
  740. package/lib/flags/readCompilerOptionValues.js.map +1 -0
  741. package/lib/flags/resolveFlagSpec.d.ts +21 -0
  742. package/lib/flags/resolveFlagSpec.js +32 -0
  743. package/lib/flags/resolveFlagSpec.js.map +1 -0
  744. package/lib/index.d.ts +8 -3
  745. package/lib/index.js +10 -3
  746. package/lib/index.js.map +1 -1
  747. package/lib/internal/CanonicalTempDirectoryOperations.d.ts +73 -0
  748. package/lib/internal/CanonicalTempDirectoryOperations.js +3 -0
  749. package/lib/internal/CanonicalTempDirectoryOperations.js.map +1 -0
  750. package/lib/internal/CompilerContextSnapshot.d.ts +66 -0
  751. package/lib/internal/CompilerContextSnapshot.js +121 -0
  752. package/lib/internal/CompilerContextSnapshot.js.map +1 -0
  753. package/lib/internal/CompilerResultAdapter.d.ts +129 -0
  754. package/lib/internal/CompilerResultAdapter.js +247 -0
  755. package/lib/internal/CompilerResultAdapter.js.map +1 -0
  756. package/lib/internal/E2ETrace.d.ts +219 -0
  757. package/lib/internal/E2ETrace.js +541 -0
  758. package/lib/internal/E2ETrace.js.map +1 -0
  759. package/lib/internal/IJavaScriptRuntimeCapabilities.d.ts +48 -0
  760. package/lib/internal/IJavaScriptRuntimeCapabilities.js +3 -0
  761. package/lib/internal/IJavaScriptRuntimeCapabilities.js.map +1 -0
  762. package/lib/internal/OwnedNativeProcess.d.ts +66 -0
  763. package/lib/internal/OwnedNativeProcess.js +317 -0
  764. package/lib/internal/OwnedNativeProcess.js.map +1 -0
  765. package/lib/internal/OwnedSynchronousProcess.d.ts +158 -0
  766. package/lib/internal/OwnedSynchronousProcess.js +171 -0
  767. package/lib/internal/OwnedSynchronousProcess.js.map +1 -0
  768. package/lib/internal/RetireLockDirectoryOperations.d.ts +77 -0
  769. package/lib/internal/RetireLockDirectoryOperations.js +3 -0
  770. package/lib/internal/RetireLockDirectoryOperations.js.map +1 -0
  771. package/lib/internal/SafeCacheCleanupTarget.d.ts +39 -0
  772. package/lib/internal/SafeCacheCleanupTarget.js +3 -0
  773. package/lib/internal/SafeCacheCleanupTarget.js.map +1 -0
  774. package/lib/internal/SourceNativeRetirement.d.ts +384 -0
  775. package/lib/internal/SourceNativeRetirement.js +892 -0
  776. package/lib/internal/SourceNativeRetirement.js.map +1 -0
  777. package/lib/internal/SpawnSyncOutputFiles.d.ts +28 -0
  778. package/lib/internal/SpawnSyncOutputFiles.js +3 -0
  779. package/lib/internal/SpawnSyncOutputFiles.js.map +1 -0
  780. package/lib/internal/cacheEntryExists.d.ts +13 -0
  781. package/lib/internal/cacheEntryExists.js +32 -0
  782. package/lib/internal/cacheEntryExists.js.map +1 -0
  783. package/lib/internal/createCanonicalTempDirectory.d.ts +23 -13
  784. package/lib/internal/createCanonicalTempDirectory.js +31 -12
  785. package/lib/internal/createCanonicalTempDirectory.js.map +1 -1
  786. package/lib/internal/isContendedCandidateRename.d.ts +27 -0
  787. package/lib/internal/isContendedCandidateRename.js +37 -0
  788. package/lib/internal/isContendedCandidateRename.js.map +1 -0
  789. package/lib/internal/isSpawnSyncFdExhaustion.d.ts +16 -0
  790. package/lib/internal/isSpawnSyncFdExhaustion.js +23 -0
  791. package/lib/internal/isSpawnSyncFdExhaustion.js.map +1 -0
  792. package/lib/internal/javascriptRuntimeCapabilities.d.ts +20 -0
  793. package/lib/internal/javascriptRuntimeCapabilities.js +142 -0
  794. package/lib/internal/javascriptRuntimeCapabilities.js.map +1 -0
  795. package/lib/internal/nativeBinary.d.ts +11 -0
  796. package/lib/internal/nativeBinary.js +16 -0
  797. package/lib/internal/nativeBinary.js.map +1 -0
  798. package/lib/internal/parseWindowsDirectoryCaseSensitivity.d.ts +24 -0
  799. package/lib/internal/parseWindowsDirectoryCaseSensitivity.js +47 -0
  800. package/lib/internal/parseWindowsDirectoryCaseSensitivity.js.map +1 -0
  801. package/lib/internal/pathIdentity/FilesystemPathIdentity.d.ts +43 -0
  802. package/lib/internal/pathIdentity/FilesystemPathIdentity.js +3 -0
  803. package/lib/internal/pathIdentity/FilesystemPathIdentity.js.map +1 -0
  804. package/lib/internal/pathIdentity/FilesystemPathIdentityContext.d.ts +176 -0
  805. package/lib/internal/pathIdentity/FilesystemPathIdentityContext.js +3 -0
  806. package/lib/internal/pathIdentity/FilesystemPathIdentityContext.js.map +1 -0
  807. package/lib/internal/pathIdentity/FilesystemPathIdentityOperations.d.ts +100 -0
  808. package/lib/internal/pathIdentity/FilesystemPathIdentityOperations.js +3 -0
  809. package/lib/internal/pathIdentity/FilesystemPathIdentityOperations.js.map +1 -0
  810. package/lib/internal/pathIdentity/ProjectInputPathIdentity.d.ts +20 -0
  811. package/lib/internal/pathIdentity/ProjectInputPathIdentity.js +3 -0
  812. package/lib/internal/pathIdentity/ProjectInputPathIdentity.js.map +1 -0
  813. package/lib/internal/pathIdentity/ProjectInputPathIdentityContext.d.ts +20 -0
  814. package/lib/internal/pathIdentity/ProjectInputPathIdentityContext.js +3 -0
  815. package/lib/internal/pathIdentity/ProjectInputPathIdentityContext.js.map +1 -0
  816. package/lib/internal/pathIdentity/ProjectInputPathIdentityOperations.d.ts +20 -0
  817. package/lib/internal/pathIdentity/ProjectInputPathIdentityOperations.js +3 -0
  818. package/lib/internal/pathIdentity/ProjectInputPathIdentityOperations.js.map +1 -0
  819. package/lib/internal/pathIdentity/createFilesystemPathIdentityContext.d.ts +25 -0
  820. package/lib/internal/pathIdentity/createFilesystemPathIdentityContext.js +336 -0
  821. package/lib/internal/pathIdentity/createFilesystemPathIdentityContext.js.map +1 -0
  822. package/lib/internal/pathIdentity/createProjectInputPathIdentityContext.d.ts +28 -0
  823. package/lib/internal/pathIdentity/createProjectInputPathIdentityContext.js +33 -0
  824. package/lib/internal/pathIdentity/createProjectInputPathIdentityContext.js.map +1 -0
  825. package/lib/internal/pathIdentity/isFilesystemPathIdentityWithin.d.ts +20 -0
  826. package/lib/internal/pathIdentity/isFilesystemPathIdentityWithin.js +33 -0
  827. package/lib/internal/pathIdentity/isFilesystemPathIdentityWithin.js.map +1 -0
  828. package/lib/internal/pathIdentity/isProjectInputPathIdentityWithin.d.ts +15 -0
  829. package/lib/internal/pathIdentity/isProjectInputPathIdentityWithin.js +22 -0
  830. package/lib/internal/pathIdentity/isProjectInputPathIdentityWithin.js.map +1 -0
  831. package/lib/internal/pathIdentity/resolveFilesystemPath.d.ts +22 -0
  832. package/lib/internal/pathIdentity/resolveFilesystemPath.js +44 -0
  833. package/lib/internal/pathIdentity/resolveFilesystemPath.js.map +1 -0
  834. package/lib/internal/pathIdentity/resolvePhysicalPath.d.ts +21 -0
  835. package/lib/internal/pathIdentity/resolvePhysicalPath.js +35 -0
  836. package/lib/internal/pathIdentity/resolvePhysicalPath.js.map +1 -0
  837. package/lib/internal/pathIdentity/resolveProjectInputPath.d.ts +14 -0
  838. package/lib/internal/pathIdentity/resolveProjectInputPath.js +21 -0
  839. package/lib/internal/pathIdentity/resolveProjectInputPath.js.map +1 -0
  840. package/lib/internal/pluginSource.d.ts +26 -0
  841. package/lib/internal/pluginSource.js +43 -0
  842. package/lib/internal/pluginSource.js.map +1 -0
  843. package/lib/internal/projectInputPathIdentity.d.ts +27 -31
  844. package/lib/internal/projectInputPathIdentity.js +37 -275
  845. package/lib/internal/projectInputPathIdentity.js.map +1 -1
  846. package/lib/internal/resolveNodeBinary.d.ts +9 -7
  847. package/lib/internal/resolveNodeBinary.js +14 -120
  848. package/lib/internal/resolveNodeBinary.js.map +1 -1
  849. package/lib/internal/resolveSafeCacheCleanupTargets.d.ts +27 -8
  850. package/lib/internal/resolveSafeCacheCleanupTargets.js +44 -11
  851. package/lib/internal/resolveSafeCacheCleanupTargets.js.map +1 -1
  852. package/lib/internal/restoreCompilerError.d.ts +21 -0
  853. package/lib/internal/restoreCompilerError.js +164 -0
  854. package/lib/internal/restoreCompilerError.js.map +1 -0
  855. package/lib/internal/retireLockDirectory.d.ts +45 -0
  856. package/lib/internal/retireLockDirectory.js +152 -0
  857. package/lib/internal/retireLockDirectory.js.map +1 -0
  858. package/lib/internal/runHoldingLock.d.ts +30 -0
  859. package/lib/internal/runHoldingLock.js +53 -0
  860. package/lib/internal/runHoldingLock.js.map +1 -0
  861. package/lib/internal/runtimeExecutableIdentity.d.ts +20 -0
  862. package/lib/internal/runtimeExecutableIdentity.js +171 -0
  863. package/lib/internal/runtimeExecutableIdentity.js.map +1 -0
  864. package/lib/internal/serializeCompilerError.d.ts +28 -0
  865. package/lib/internal/serializeCompilerError.js +138 -0
  866. package/lib/internal/serializeCompilerError.js.map +1 -0
  867. package/lib/internal/spawnSyncResilient.d.ts +31 -0
  868. package/lib/internal/spawnSyncResilient.js +50 -0
  869. package/lib/internal/spawnSyncResilient.js.map +1 -0
  870. package/lib/internal/spawnSyncWithLowDescriptors.d.ts +30 -0
  871. package/lib/internal/spawnSyncWithLowDescriptors.js +194 -0
  872. package/lib/internal/spawnSyncWithLowDescriptors.js.map +1 -0
  873. package/lib/internal/tsconfig.d.ts +16 -0
  874. package/lib/internal/tsconfig.js +33 -0
  875. package/lib/internal/tsconfig.js.map +1 -0
  876. package/lib/launcher/internal/PendingResidentCheckWatchChanges.d.ts +56 -0
  877. package/lib/launcher/internal/PendingResidentCheckWatchChanges.js +97 -0
  878. package/lib/launcher/internal/PendingResidentCheckWatchChanges.js.map +1 -0
  879. package/lib/launcher/internal/TtscBuildMode.d.ts +14 -0
  880. package/lib/launcher/internal/TtscBuildMode.js +3 -0
  881. package/lib/launcher/internal/TtscBuildMode.js.map +1 -0
  882. package/lib/launcher/internal/TtsxEntryOptions.d.ts +50 -0
  883. package/lib/launcher/internal/TtsxEntryOptions.js +94 -0
  884. package/lib/launcher/internal/TtsxEntryOptions.js.map +1 -0
  885. package/lib/launcher/internal/assertNoSolutionBuild.d.ts +17 -10
  886. package/lib/launcher/internal/assertNoSolutionBuild.js +16 -9
  887. package/lib/launcher/internal/assertNoSolutionBuild.js.map +1 -1
  888. package/lib/launcher/internal/assertTtsxNoWatch.d.ts +25 -0
  889. package/lib/launcher/internal/assertTtsxNoWatch.js +46 -0
  890. package/lib/launcher/internal/assertTtsxNoWatch.js.map +1 -0
  891. package/lib/launcher/internal/buildSingleRootProject.d.ts +108 -0
  892. package/lib/launcher/internal/buildSingleRootProject.js +229 -0
  893. package/lib/launcher/internal/buildSingleRootProject.js.map +1 -0
  894. package/lib/launcher/internal/getCompilerVersionText.d.ts +14 -1
  895. package/lib/launcher/internal/getCompilerVersionText.js +21 -6
  896. package/lib/launcher/internal/getCompilerVersionText.js.map +1 -1
  897. package/lib/launcher/internal/inlineServedSourceMap.d.ts +35 -0
  898. package/lib/launcher/internal/inlineServedSourceMap.js +255 -0
  899. package/lib/launcher/internal/inlineServedSourceMap.js.map +1 -0
  900. package/lib/launcher/internal/linkVirtualEntry.d.ts +31 -0
  901. package/lib/launcher/internal/linkVirtualEntry.js +87 -0
  902. package/lib/launcher/internal/linkVirtualEntry.js.map +1 -0
  903. package/lib/launcher/internal/parseCommonJsExports.d.ts +17 -0
  904. package/lib/launcher/internal/{commonJsExportMetadata.js → parseCommonJsExports.js} +13 -3
  905. package/lib/launcher/internal/parseCommonJsExports.js.map +1 -0
  906. package/lib/launcher/internal/parseTtscBuildArgs.d.ts +34 -0
  907. package/lib/launcher/internal/parseTtscBuildArgs.js +97 -0
  908. package/lib/launcher/internal/parseTtscBuildArgs.js.map +1 -0
  909. package/lib/launcher/internal/parseTtsxCLI.d.ts +35 -0
  910. package/lib/launcher/internal/parseTtsxCLI.js +187 -0
  911. package/lib/launcher/internal/parseTtsxCLI.js.map +1 -0
  912. package/lib/launcher/internal/prepareExecution.d.ts +49 -5
  913. package/lib/launcher/internal/prepareExecution.js +360 -324
  914. package/lib/launcher/internal/prepareExecution.js.map +1 -1
  915. package/lib/launcher/internal/prepareTtscBuildMode.d.ts +23 -0
  916. package/lib/launcher/internal/prepareTtscBuildMode.js +58 -0
  917. package/lib/launcher/internal/prepareTtscBuildMode.js.map +1 -0
  918. package/lib/launcher/internal/resolveCacheDir.d.ts +12 -3
  919. package/lib/launcher/internal/resolveCacheDir.js +12 -3
  920. package/lib/launcher/internal/resolveCacheDir.js.map +1 -1
  921. package/lib/launcher/internal/resolveSingleFileOutput.d.ts +35 -0
  922. package/lib/launcher/internal/resolveSingleFileOutput.js +115 -0
  923. package/lib/launcher/internal/resolveSingleFileOutput.js.map +1 -0
  924. package/lib/launcher/internal/resolveTtscserverBinary.d.ts +15 -3
  925. package/lib/launcher/internal/resolveTtscserverBinary.js +19 -5
  926. package/lib/launcher/internal/resolveTtscserverBinary.js.map +1 -1
  927. package/lib/launcher/internal/runTtsc.d.ts +23 -23
  928. package/lib/launcher/internal/runTtsc.js +336 -286
  929. package/lib/launcher/internal/runTtsc.js.map +1 -1
  930. package/lib/launcher/internal/runTtsx.d.ts +32 -4
  931. package/lib/launcher/internal/runTtsx.js +286 -138
  932. package/lib/launcher/internal/runTtsx.js.map +1 -1
  933. package/lib/launcher/internal/runtime/CommonJsRuntimeSource.d.ts +92 -0
  934. package/lib/launcher/internal/runtime/CommonJsRuntimeSource.js +354 -0
  935. package/lib/launcher/internal/runtime/CommonJsRuntimeSource.js.map +1 -0
  936. package/lib/launcher/internal/runtime/DependencyBuildAdmission.d.ts +72 -0
  937. package/lib/launcher/internal/runtime/DependencyBuildAdmission.js +120 -0
  938. package/lib/launcher/internal/runtime/DependencyBuildAdmission.js.map +1 -0
  939. package/lib/launcher/internal/runtime/DependencyBuildGeneration.d.ts +185 -0
  940. package/lib/launcher/internal/runtime/DependencyBuildGeneration.js +153 -0
  941. package/lib/launcher/internal/runtime/DependencyBuildGeneration.js.map +1 -0
  942. package/lib/launcher/internal/runtime/DependencyBuildLockFence.d.ts +22 -0
  943. package/lib/launcher/internal/runtime/DependencyBuildLockFence.js +3 -0
  944. package/lib/launcher/internal/runtime/DependencyBuildLockFence.js.map +1 -0
  945. package/lib/launcher/internal/runtime/DependencyBuildLockLease.d.ts +22 -0
  946. package/lib/launcher/internal/runtime/DependencyBuildLockLease.js +3 -0
  947. package/lib/launcher/internal/runtime/DependencyBuildLockLease.js.map +1 -0
  948. package/lib/launcher/internal/runtime/DependencyBuildLockObservation.d.ts +41 -0
  949. package/lib/launcher/internal/runtime/DependencyBuildLockObservation.js +3 -0
  950. package/lib/launcher/internal/runtime/DependencyBuildLockObservation.js.map +1 -0
  951. package/lib/launcher/internal/runtime/DependencyBuildLockProtocol.d.ts +83 -0
  952. package/lib/launcher/internal/runtime/DependencyBuildLockProtocol.js +126 -0
  953. package/lib/launcher/internal/runtime/DependencyBuildLockProtocol.js.map +1 -0
  954. package/lib/launcher/internal/runtime/OwnedProjectSource.d.ts +112 -0
  955. package/lib/launcher/internal/runtime/OwnedProjectSource.js +59 -0
  956. package/lib/launcher/internal/runtime/OwnedProjectSource.js.map +1 -0
  957. package/lib/launcher/internal/runtime/OwningModuleOptions.d.ts +21 -0
  958. package/lib/launcher/internal/runtime/OwningModuleOptions.js +3 -0
  959. package/lib/launcher/internal/runtime/OwningModuleOptions.js.map +1 -0
  960. package/lib/launcher/internal/runtime/PluginDescriptorInputObservation.d.ts +89 -0
  961. package/lib/launcher/internal/runtime/PluginDescriptorInputObservation.js +115 -0
  962. package/lib/launcher/internal/runtime/PluginDescriptorInputObservation.js.map +1 -0
  963. package/lib/launcher/internal/runtime/ProcessOwnedDirectory.d.ts +168 -0
  964. package/lib/launcher/internal/runtime/ProcessOwnedDirectory.js +251 -0
  965. package/lib/launcher/internal/runtime/ProcessOwnedDirectory.js.map +1 -0
  966. package/lib/launcher/internal/runtime/ResolveResult.d.ts +24 -0
  967. package/lib/launcher/internal/runtime/ResolveResult.js +3 -0
  968. package/lib/launcher/internal/runtime/ResolveResult.js.map +1 -0
  969. package/lib/launcher/internal/runtime/RuntimeEmitProvenance.d.ts +38 -0
  970. package/lib/launcher/internal/runtime/RuntimeEmitProvenance.js +60 -0
  971. package/lib/launcher/internal/runtime/RuntimeEmitProvenance.js.map +1 -0
  972. package/lib/launcher/internal/runtime/RuntimeEntryPreparer.d.ts +22 -0
  973. package/lib/launcher/internal/runtime/RuntimeEntryPreparer.js +3 -0
  974. package/lib/launcher/internal/runtime/RuntimeEntryPreparer.js.map +1 -0
  975. package/lib/launcher/internal/runtime/RuntimeFilesystem.d.ts +52 -0
  976. package/lib/launcher/internal/runtime/RuntimeFilesystem.js +73 -0
  977. package/lib/launcher/internal/runtime/RuntimeFilesystem.js.map +1 -0
  978. package/lib/launcher/internal/runtime/RuntimeHookOptions.d.ts +22 -0
  979. package/lib/launcher/internal/runtime/RuntimeHookOptions.js +3 -0
  980. package/lib/launcher/internal/runtime/RuntimeHookOptions.js.map +1 -0
  981. package/lib/launcher/internal/runtime/RuntimeIsolatedEmit.d.ts +53 -0
  982. package/lib/launcher/internal/runtime/RuntimeIsolatedEmit.js +88 -0
  983. package/lib/launcher/internal/runtime/RuntimeIsolatedEmit.js.map +1 -0
  984. package/lib/launcher/internal/runtime/RuntimeLoaderCapabilities.d.ts +78 -0
  985. package/lib/launcher/internal/runtime/RuntimeLoaderCapabilities.js +256 -0
  986. package/lib/launcher/internal/runtime/RuntimeLoaderCapabilities.js.map +1 -0
  987. package/lib/launcher/internal/runtime/RuntimeManifest.d.ts +65 -0
  988. package/lib/launcher/internal/runtime/RuntimeManifest.js +3 -0
  989. package/lib/launcher/internal/runtime/RuntimeManifest.js.map +1 -0
  990. package/lib/launcher/internal/runtime/RuntimeManifestRegistry.d.ts +95 -0
  991. package/lib/launcher/internal/runtime/RuntimeManifestRegistry.js +268 -0
  992. package/lib/launcher/internal/runtime/RuntimeManifestRegistry.js.map +1 -0
  993. package/lib/launcher/internal/runtime/RuntimeModuleFormat.d.ts +60 -0
  994. package/lib/launcher/internal/runtime/RuntimeModuleFormat.js +249 -0
  995. package/lib/launcher/internal/runtime/RuntimeModuleFormat.js.map +1 -0
  996. package/lib/launcher/internal/runtime/RuntimeProjectOwnership.d.ts +50 -0
  997. package/lib/launcher/internal/runtime/RuntimeProjectOwnership.js +134 -0
  998. package/lib/launcher/internal/runtime/RuntimeProjectOwnership.js.map +1 -0
  999. package/lib/launcher/internal/runtime/TTSX_MINIMUM_NODE_VERSION.d.ts +11 -0
  1000. package/lib/launcher/internal/runtime/TTSX_MINIMUM_NODE_VERSION.js +15 -0
  1001. package/lib/launcher/internal/runtime/TTSX_MINIMUM_NODE_VERSION.js.map +1 -0
  1002. package/lib/launcher/internal/runtime/acquireDependencyBuildLock.d.ts +22 -0
  1003. package/lib/launcher/internal/runtime/acquireDependencyBuildLock.js +74 -0
  1004. package/lib/launcher/internal/runtime/acquireDependencyBuildLock.js.map +1 -0
  1005. package/lib/launcher/internal/runtime/checkNodeRuntimeSupport.d.ts +30 -0
  1006. package/lib/launcher/internal/runtime/checkNodeRuntimeSupport.js +83 -0
  1007. package/lib/launcher/internal/runtime/checkNodeRuntimeSupport.js.map +1 -0
  1008. package/lib/launcher/internal/runtime/claimRuntimeProjectDirectory.d.ts +30 -0
  1009. package/lib/launcher/internal/runtime/claimRuntimeProjectDirectory.js +52 -0
  1010. package/lib/launcher/internal/runtime/claimRuntimeProjectDirectory.js.map +1 -0
  1011. package/lib/launcher/internal/runtime/commonJsExportNames.d.ts +21 -0
  1012. package/lib/launcher/internal/runtime/commonJsExportNames.js +68 -0
  1013. package/lib/launcher/internal/runtime/commonJsExportNames.js.map +1 -0
  1014. package/lib/launcher/internal/runtime/commonJsImportFacade.d.ts +32 -0
  1015. package/lib/launcher/internal/runtime/commonJsImportFacade.js +56 -0
  1016. package/lib/launcher/internal/runtime/commonJsImportFacade.js.map +1 -0
  1017. package/lib/launcher/internal/runtime/dependencyCacheKey.d.ts +36 -0
  1018. package/lib/launcher/internal/runtime/dependencyCacheKey.js +57 -0
  1019. package/lib/launcher/internal/runtime/dependencyCacheKey.js.map +1 -0
  1020. package/lib/launcher/internal/runtime/dependencyCacheRoot.d.ts +32 -0
  1021. package/lib/launcher/internal/runtime/dependencyCacheRoot.js +98 -0
  1022. package/lib/launcher/internal/runtime/dependencyCacheRoot.js.map +1 -0
  1023. package/lib/launcher/internal/runtime/inspectDependencyBuildLock.d.ts +23 -0
  1024. package/lib/launcher/internal/runtime/inspectDependencyBuildLock.js +126 -0
  1025. package/lib/launcher/internal/runtime/inspectDependencyBuildLock.js.map +1 -0
  1026. package/lib/launcher/internal/runtime/installRuntimeHooks.d.ts +58 -0
  1027. package/lib/launcher/internal/runtime/installRuntimeHooks.js +1988 -0
  1028. package/lib/launcher/internal/runtime/installRuntimeHooks.js.map +1 -0
  1029. package/lib/launcher/internal/runtime/interopProbe.d.ts +8 -0
  1030. package/lib/launcher/internal/runtime/interopProbe.js +3 -0
  1031. package/lib/launcher/internal/runtime/interopProbe.js.map +1 -0
  1032. package/lib/launcher/internal/runtime/isLocalProcessGone.d.ts +33 -0
  1033. package/lib/launcher/internal/runtime/isLocalProcessGone.js +60 -0
  1034. package/lib/launcher/internal/runtime/isLocalProcessGone.js.map +1 -0
  1035. package/lib/launcher/internal/runtime/observeMappedDescriptorResolution.d.ts +28 -0
  1036. package/lib/launcher/internal/runtime/observeMappedDescriptorResolution.js +50 -0
  1037. package/lib/launcher/internal/runtime/observeMappedDescriptorResolution.js.map +1 -0
  1038. package/lib/launcher/internal/runtime/projectModuleOptions.d.ts +16 -0
  1039. package/lib/launcher/internal/runtime/projectModuleOptions.js +28 -0
  1040. package/lib/launcher/internal/runtime/projectModuleOptions.js.map +1 -0
  1041. package/lib/launcher/internal/runtime/readDependencyCache.d.ts +28 -0
  1042. package/lib/launcher/internal/runtime/readDependencyCache.js +83 -0
  1043. package/lib/launcher/internal/runtime/readDependencyCache.js.map +1 -0
  1044. package/lib/launcher/internal/runtime/realPath.d.ts +22 -0
  1045. package/lib/launcher/internal/runtime/realPath.js +37 -0
  1046. package/lib/launcher/internal/runtime/realPath.js.map +1 -0
  1047. package/lib/launcher/internal/runtime/reclaimDependencyBuildLock.d.ts +17 -0
  1048. package/lib/launcher/internal/runtime/reclaimDependencyBuildLock.js +23 -0
  1049. package/lib/launcher/internal/runtime/reclaimDependencyBuildLock.js.map +1 -0
  1050. package/lib/launcher/internal/runtime/releaseDependencyBuildLock.d.ts +17 -0
  1051. package/lib/launcher/internal/runtime/releaseDependencyBuildLock.js +23 -0
  1052. package/lib/launcher/internal/runtime/releaseDependencyBuildLock.js.map +1 -0
  1053. package/lib/launcher/internal/runtime/resolveRuntimeCleanTargets.d.ts +34 -0
  1054. package/lib/launcher/internal/runtime/resolveRuntimeCleanTargets.js +88 -0
  1055. package/lib/launcher/internal/runtime/resolveRuntimeCleanTargets.js.map +1 -0
  1056. package/lib/launcher/internal/runtime/restoreStrippedNodeBuiltinScheme.d.ts +20 -0
  1057. package/lib/launcher/internal/runtime/restoreStrippedNodeBuiltinScheme.js +30 -0
  1058. package/lib/launcher/internal/runtime/restoreStrippedNodeBuiltinScheme.js.map +1 -0
  1059. package/lib/launcher/internal/runtime/runtimeRunKey.d.ts +24 -0
  1060. package/lib/launcher/internal/runtime/runtimeRunKey.js +36 -0
  1061. package/lib/launcher/internal/runtime/runtimeRunKey.js.map +1 -0
  1062. package/lib/launcher/internal/runtime/selectRuntimePluginPolicy.d.ts +21 -0
  1063. package/lib/launcher/internal/runtime/selectRuntimePluginPolicy.js +29 -0
  1064. package/lib/launcher/internal/runtime/selectRuntimePluginPolicy.js.map +1 -0
  1065. package/lib/launcher/internal/runtime/withRuntimeDirectoryLock.d.ts +35 -0
  1066. package/lib/launcher/internal/runtime/withRuntimeDirectoryLock.js +76 -0
  1067. package/lib/launcher/internal/runtime/withRuntimeDirectoryLock.js.map +1 -0
  1068. package/lib/launcher/internal/runtimeCompilerArgs.d.ts +35 -6
  1069. package/lib/launcher/internal/runtimeCompilerArgs.js +87 -58
  1070. package/lib/launcher/internal/runtimeCompilerArgs.js.map +1 -1
  1071. package/lib/launcher/internal/runtimeEmitProfile.d.ts +39 -0
  1072. package/lib/launcher/internal/runtimeEmitProfile.js +56 -0
  1073. package/lib/launcher/internal/runtimeEmitProfile.js.map +1 -0
  1074. package/lib/launcher/internal/runtimeHookPreload.js +4 -4
  1075. package/lib/launcher/internal/runtimeHookPreload.js.map +1 -1
  1076. package/lib/launcher/internal/runtimeOwnerPreload.d.ts +1 -0
  1077. package/lib/launcher/internal/runtimeOwnerPreload.js +43 -0
  1078. package/lib/launcher/internal/runtimeOwnerPreload.js.map +1 -0
  1079. package/lib/launcher/internal/singleRootProjectConfig.d.ts +34 -0
  1080. package/lib/launcher/internal/singleRootProjectConfig.js +39 -0
  1081. package/lib/launcher/internal/singleRootProjectConfig.js.map +1 -0
  1082. package/lib/launcher/internal/ttscserver/ILSPPluginSelectionInputs.d.ts +61 -0
  1083. package/lib/launcher/internal/ttscserver/ILSPPluginSelectionInputs.js +3 -0
  1084. package/lib/launcher/internal/ttscserver/ILSPPluginSelectionInputs.js.map +1 -0
  1085. package/lib/launcher/internal/ttscserver/LSPProjectInputDigest.d.ts +95 -0
  1086. package/lib/launcher/internal/ttscserver/LSPProjectInputDigest.js +270 -0
  1087. package/lib/launcher/internal/ttscserver/LSPProjectInputDigest.js.map +1 -0
  1088. package/lib/launcher/internal/ttscserver/captureLSPPluginSelectionInputs.d.ts +46 -0
  1089. package/lib/launcher/internal/ttscserver/captureLSPPluginSelectionInputs.js +91 -0
  1090. package/lib/launcher/internal/ttscserver/captureLSPPluginSelectionInputs.js.map +1 -0
  1091. package/lib/launcher/internal/ttscserver/fingerprintInitialLSPProjectInputSnapshot.d.ts +21 -0
  1092. package/lib/launcher/internal/ttscserver/fingerprintInitialLSPProjectInputSnapshot.js +39 -0
  1093. package/lib/launcher/internal/ttscserver/fingerprintInitialLSPProjectInputSnapshot.js.map +1 -0
  1094. package/lib/launcher/internal/ttscserver/initialLSPProjectInputSnapshotIsCurrent.d.ts +18 -0
  1095. package/lib/launcher/internal/ttscserver/initialLSPProjectInputSnapshotIsCurrent.js +27 -0
  1096. package/lib/launcher/internal/ttscserver/initialLSPProjectInputSnapshotIsCurrent.js.map +1 -0
  1097. package/lib/launcher/internal/ttscserver/materializeLSPPluginManifest.d.ts +26 -0
  1098. package/lib/launcher/internal/ttscserver/materializeLSPPluginManifest.js +62 -0
  1099. package/lib/launcher/internal/ttscserver/materializeLSPPluginManifest.js.map +1 -0
  1100. package/lib/launcher/internal/ttscserver/needsStdio.d.ts +17 -0
  1101. package/lib/launcher/internal/ttscserver/needsStdio.js +36 -0
  1102. package/lib/launcher/internal/ttscserver/needsStdio.js.map +1 -0
  1103. package/lib/launcher/internal/ttscserver/runTtscserver.d.ts +25 -0
  1104. package/lib/launcher/internal/ttscserver/runTtscserver.js +439 -0
  1105. package/lib/launcher/internal/ttscserver/runTtscserver.js.map +1 -0
  1106. package/lib/launcher/internal/watch/CompilerDirectoryWatchEventPlan.d.ts +29 -0
  1107. package/lib/launcher/internal/watch/CompilerDirectoryWatchEventPlan.js +3 -0
  1108. package/lib/launcher/internal/watch/CompilerDirectoryWatchEventPlan.js.map +1 -0
  1109. package/lib/launcher/internal/watch/DirectoryWatcher.d.ts +44 -0
  1110. package/lib/launcher/internal/watch/DirectoryWatcher.js +3 -0
  1111. package/lib/launcher/internal/watch/DirectoryWatcher.js.map +1 -0
  1112. package/lib/launcher/internal/watch/FseventsStreams.d.ts +87 -0
  1113. package/lib/launcher/internal/watch/FseventsStreams.js +266 -0
  1114. package/lib/launcher/internal/watch/FseventsStreams.js.map +1 -0
  1115. package/lib/launcher/internal/watch/ProjectInputWatchRules.d.ts +92 -0
  1116. package/lib/launcher/internal/watch/ProjectInputWatchRules.js +163 -0
  1117. package/lib/launcher/internal/watch/ProjectInputWatchRules.js.map +1 -0
  1118. package/lib/launcher/internal/watch/WatchInputChange.d.ts +29 -0
  1119. package/lib/launcher/internal/watch/WatchInputChange.js +3 -0
  1120. package/lib/launcher/internal/watch/WatchInputChange.js.map +1 -0
  1121. package/lib/launcher/internal/watch/WatchPaths.d.ts +101 -0
  1122. package/lib/launcher/internal/watch/WatchPaths.js +150 -0
  1123. package/lib/launcher/internal/watch/WatchPaths.js.map +1 -0
  1124. package/lib/launcher/internal/watch/WatchTopology.d.ts +384 -0
  1125. package/lib/launcher/internal/{watchTopology.js → watch/WatchTopology.js} +726 -799
  1126. package/lib/launcher/internal/watch/WatchTopology.js.map +1 -0
  1127. package/lib/launcher/internal/watch/literalGlobRoot.d.ts +22 -0
  1128. package/lib/launcher/internal/watch/literalGlobRoot.js +45 -0
  1129. package/lib/launcher/internal/watch/literalGlobRoot.js.map +1 -0
  1130. package/lib/launcher/internal/watch/planCompilerDirectoryWatchEvent.d.ts +40 -0
  1131. package/lib/launcher/internal/watch/planCompilerDirectoryWatchEvent.js +69 -0
  1132. package/lib/launcher/internal/watch/planCompilerDirectoryWatchEvent.js.map +1 -0
  1133. package/lib/launcher/internal/watch/projectInputActiveWatchDirectories.d.ts +19 -0
  1134. package/lib/launcher/internal/watch/projectInputActiveWatchDirectories.js +52 -0
  1135. package/lib/launcher/internal/watch/projectInputActiveWatchDirectories.js.map +1 -0
  1136. package/lib/launcher/internal/watch/projectInputAvailableWatchDirectory.d.ts +21 -0
  1137. package/lib/launcher/internal/watch/projectInputAvailableWatchDirectory.js +55 -0
  1138. package/lib/launcher/internal/watch/projectInputAvailableWatchDirectory.js.map +1 -0
  1139. package/lib/launcher/internal/watch/projectInputEventShouldNotify.d.ts +21 -0
  1140. package/lib/launcher/internal/watch/projectInputEventShouldNotify.js +23 -0
  1141. package/lib/launcher/internal/watch/projectInputEventShouldNotify.js.map +1 -0
  1142. package/lib/launcher/internal/watch/projectInputMembershipInvalidatesProgram.d.ts +27 -0
  1143. package/lib/launcher/internal/watch/projectInputMembershipInvalidatesProgram.js +54 -0
  1144. package/lib/launcher/internal/watch/projectInputMembershipInvalidatesProgram.js.map +1 -0
  1145. package/lib/launcher/internal/watch/projectInputReloadEventShouldNotify.d.ts +26 -0
  1146. package/lib/launcher/internal/watch/projectInputReloadEventShouldNotify.js +100 -0
  1147. package/lib/launcher/internal/watch/projectInputReloadEventShouldNotify.js.map +1 -0
  1148. package/lib/launcher/internal/watch/projectInputReplacementStrandsWatchers.d.ts +37 -0
  1149. package/lib/launcher/internal/watch/projectInputReplacementStrandsWatchers.js +54 -0
  1150. package/lib/launcher/internal/watch/projectInputReplacementStrandsWatchers.js.map +1 -0
  1151. package/lib/launcher/internal/watch/projectInputTopologyMayAffect.d.ts +23 -0
  1152. package/lib/launcher/internal/watch/projectInputTopologyMayAffect.js +67 -0
  1153. package/lib/launcher/internal/watch/projectInputTopologyMayAffect.js.map +1 -0
  1154. package/lib/launcher/internal/watch/projectInputWatchDirectories.d.ts +22 -0
  1155. package/lib/launcher/internal/watch/projectInputWatchDirectories.js +30 -0
  1156. package/lib/launcher/internal/watch/projectInputWatchDirectories.js.map +1 -0
  1157. package/lib/launcher/internal/watch/reloadInputsForFailedTopologyRefresh.d.ts +22 -0
  1158. package/lib/launcher/internal/watch/reloadInputsForFailedTopologyRefresh.js +45 -0
  1159. package/lib/launcher/internal/watch/reloadInputsForFailedTopologyRefresh.js.map +1 -0
  1160. package/lib/launcher/internal/watch/syncWatchers.d.ts +25 -0
  1161. package/lib/launcher/internal/watch/syncWatchers.js +61 -0
  1162. package/lib/launcher/internal/watch/syncWatchers.js.map +1 -0
  1163. package/lib/launcher/internal/watch/watchDirectory.d.ts +28 -0
  1164. package/lib/launcher/internal/watch/watchDirectory.js +46 -0
  1165. package/lib/launcher/internal/watch/watchDirectory.js.map +1 -0
  1166. package/lib/launcher/internal/watch/watchDirectoryThroughFsWatch.d.ts +28 -0
  1167. package/lib/launcher/internal/watch/watchDirectoryThroughFsWatch.js +38 -0
  1168. package/lib/launcher/internal/watch/watchDirectoryThroughFsWatch.js.map +1 -0
  1169. package/lib/launcher/ttscserver.js +1 -1
  1170. package/lib/launcher/ttscserver.js.map +1 -1
  1171. package/lib/launcher/ttsx.js +2 -3
  1172. package/lib/launcher/ttsx.js.map +1 -1
  1173. package/lib/plugin/CapabilityPluginResolver.d.ts +140 -0
  1174. package/lib/plugin/CapabilityPluginResolver.js +400 -0
  1175. package/lib/plugin/CapabilityPluginResolver.js.map +1 -0
  1176. package/lib/plugin/ITtscCapabilityPlugin.d.ts +87 -0
  1177. package/lib/plugin/ITtscCapabilityPlugin.js +3 -0
  1178. package/lib/plugin/ITtscCapabilityPlugin.js.map +1 -0
  1179. package/lib/plugin/internal/CapabilityPluginResult.d.ts +66 -0
  1180. package/lib/plugin/internal/CapabilityPluginResult.js +86 -0
  1181. package/lib/plugin/internal/CapabilityPluginResult.js.map +1 -0
  1182. package/lib/plugin/internal/CapabilityResolutionFormat.d.ts +114 -0
  1183. package/lib/plugin/internal/CapabilityResolutionFormat.js +229 -0
  1184. package/lib/plugin/internal/CapabilityResolutionFormat.js.map +1 -0
  1185. package/lib/plugin/internal/ITtscCapabilityPluginSource.d.ts +35 -0
  1186. package/lib/plugin/internal/ITtscCapabilityPluginSource.js +3 -0
  1187. package/lib/plugin/internal/ITtscCapabilityPluginSource.js.map +1 -0
  1188. package/lib/plugin/internal/ITtscCapabilityResolutionEntry.d.ts +49 -0
  1189. package/lib/plugin/internal/ITtscCapabilityResolutionEntry.js +3 -0
  1190. package/lib/plugin/internal/ITtscCapabilityResolutionEntry.js.map +1 -0
  1191. package/lib/plugin/internal/ITtscCapabilityResolutionPlugin.d.ts +21 -0
  1192. package/lib/plugin/internal/ITtscCapabilityResolutionPlugin.js +3 -0
  1193. package/lib/plugin/internal/ITtscCapabilityResolutionPlugin.js.map +1 -0
  1194. package/lib/plugin/internal/capabilityPluginWorker.d.ts +1 -0
  1195. package/lib/plugin/internal/capabilityPluginWorker.js +178 -0
  1196. package/lib/plugin/internal/capabilityPluginWorker.js.map +1 -0
  1197. package/lib/plugin/internal/decodeCapabilityCommandReply.d.ts +23 -0
  1198. package/lib/plugin/internal/decodeCapabilityCommandReply.js +25 -0
  1199. package/lib/plugin/internal/decodeCapabilityCommandReply.js.map +1 -0
  1200. package/lib/plugin/internal/load/COMMONJS_PLUGIN_DESCRIPTOR_SHIM_SOURCE.d.ts +15 -0
  1201. package/lib/plugin/internal/load/COMMONJS_PLUGIN_DESCRIPTOR_SHIM_SOURCE.js +182 -0
  1202. package/lib/plugin/internal/load/COMMONJS_PLUGIN_DESCRIPTOR_SHIM_SOURCE.js.map +1 -0
  1203. package/lib/plugin/internal/load/PLUGIN_DESCRIPTOR_SHIM_SOURCE.d.ts +11 -0
  1204. package/lib/plugin/internal/load/PLUGIN_DESCRIPTOR_SHIM_SOURCE.js +62 -0
  1205. package/lib/plugin/internal/load/PLUGIN_DESCRIPTOR_SHIM_SOURCE.js.map +1 -0
  1206. package/lib/plugin/internal/load/PluginDescriptorAdmission.d.ts +46 -0
  1207. package/lib/plugin/internal/load/PluginDescriptorAdmission.js +72 -0
  1208. package/lib/plugin/internal/load/PluginDescriptorAdmission.js.map +1 -0
  1209. package/lib/plugin/internal/load/PluginDescriptorEvaluationCache.d.ts +154 -0
  1210. package/lib/plugin/internal/load/PluginDescriptorEvaluationCache.js +317 -0
  1211. package/lib/plugin/internal/load/PluginDescriptorEvaluationCache.js.map +1 -0
  1212. package/lib/plugin/internal/load/PluginPackageResolution.d.ts +208 -0
  1213. package/lib/plugin/internal/load/PluginPackageResolution.js +593 -0
  1214. package/lib/plugin/internal/load/PluginPackageResolution.js.map +1 -0
  1215. package/lib/plugin/internal/load/ProjectPluginEntries.d.ts +60 -0
  1216. package/lib/plugin/internal/load/ProjectPluginEntries.js +164 -0
  1217. package/lib/plugin/internal/load/ProjectPluginEntries.js.map +1 -0
  1218. package/lib/plugin/internal/load/RESOLUTION_INPUT_RECORDER_PATH.d.ts +13 -0
  1219. package/lib/plugin/internal/load/RESOLUTION_INPUT_RECORDER_PATH.js +21 -0
  1220. package/lib/plugin/internal/load/RESOLUTION_INPUT_RECORDER_PATH.js.map +1 -0
  1221. package/lib/plugin/internal/load/collectProjectHostInputs.d.ts +16 -0
  1222. package/lib/plugin/internal/load/collectProjectHostInputs.js +66 -0
  1223. package/lib/plugin/internal/load/collectProjectHostInputs.js.map +1 -0
  1224. package/lib/plugin/internal/load/composePluginSources.d.ts +20 -0
  1225. package/lib/plugin/internal/load/composePluginSources.js +95 -0
  1226. package/lib/plugin/internal/load/composePluginSources.js.map +1 -0
  1227. package/lib/plugin/internal/load/declaresHostInputReads.d.ts +24 -0
  1228. package/lib/plugin/internal/load/declaresHostInputReads.js +48 -0
  1229. package/lib/plugin/internal/load/declaresHostInputReads.js.map +1 -0
  1230. package/lib/plugin/internal/load/hasProjectPluginEntries.d.ts +21 -0
  1231. package/lib/plugin/internal/load/hasProjectPluginEntries.js +29 -0
  1232. package/lib/plugin/internal/load/hasProjectPluginEntries.js.map +1 -0
  1233. package/lib/plugin/internal/load/hashHostInputPaths.d.ts +17 -0
  1234. package/lib/plugin/internal/load/hashHostInputPaths.js +46 -0
  1235. package/lib/plugin/internal/load/hashHostInputPaths.js.map +1 -0
  1236. package/lib/plugin/internal/load/isRelativePluginSpecifier.d.ts +22 -0
  1237. package/lib/plugin/internal/load/isRelativePluginSpecifier.js +33 -0
  1238. package/lib/plugin/internal/load/isRelativePluginSpecifier.js.map +1 -0
  1239. package/lib/plugin/internal/load/loadProjectPlugins.d.ts +113 -0
  1240. package/lib/plugin/internal/load/loadProjectPlugins.js +1615 -0
  1241. package/lib/plugin/internal/load/loadProjectPlugins.js.map +1 -0
  1242. package/lib/plugin/internal/load/moduleResolutionBaseSelects.d.ts +42 -0
  1243. package/lib/plugin/internal/load/moduleResolutionBaseSelects.js +51 -0
  1244. package/lib/plugin/internal/load/moduleResolutionBaseSelects.js.map +1 -0
  1245. package/lib/plugin/internal/load/observeImportSearchRoots.d.ts +29 -0
  1246. package/lib/plugin/internal/load/observeImportSearchRoots.js +38 -0
  1247. package/lib/plugin/internal/load/observeImportSearchRoots.js.map +1 -0
  1248. package/lib/plugin/internal/load/pluginLabel.d.ts +15 -0
  1249. package/lib/plugin/internal/load/pluginLabel.js +25 -0
  1250. package/lib/plugin/internal/load/pluginLabel.js.map +1 -0
  1251. package/lib/plugin/internal/load/realpathHostInput.d.ts +14 -0
  1252. package/lib/plugin/internal/load/realpathHostInput.js +29 -0
  1253. package/lib/plugin/internal/load/realpathHostInput.js.map +1 -0
  1254. package/lib/plugin/internal/load/realpathHostInputPaths.d.ts +17 -0
  1255. package/lib/plugin/internal/load/realpathHostInputPaths.js +28 -0
  1256. package/lib/plugin/internal/load/realpathHostInputPaths.js.map +1 -0
  1257. package/lib/plugin/internal/load/rejectJsTransformFunctions.d.ts +13 -0
  1258. package/lib/plugin/internal/load/rejectJsTransformFunctions.js +22 -0
  1259. package/lib/plugin/internal/load/rejectJsTransformFunctions.js.map +1 -0
  1260. package/lib/plugin/internal/load/requirePluginSource.d.ts +14 -0
  1261. package/lib/plugin/internal/load/requirePluginSource.js +38 -0
  1262. package/lib/plugin/internal/load/requirePluginSource.js.map +1 -0
  1263. package/lib/plugin/internal/load/resolveNativeSource.d.ts +29 -0
  1264. package/lib/plugin/internal/load/resolveNativeSource.js +37 -0
  1265. package/lib/plugin/internal/load/resolveNativeSource.js.map +1 -0
  1266. package/lib/plugin/internal/load/validatePluginContributors.d.ts +22 -0
  1267. package/lib/plugin/internal/load/validatePluginContributors.js +86 -0
  1268. package/lib/plugin/internal/load/validatePluginContributors.js.map +1 -0
  1269. package/lib/plugin/internal/load/validatePluginSource.d.ts +14 -0
  1270. package/lib/plugin/internal/load/validatePluginSource.js +21 -0
  1271. package/lib/plugin/internal/load/validatePluginSource.js.map +1 -0
  1272. package/lib/plugin/internal/load/visitImportMappedCandidates.d.ts +36 -0
  1273. package/lib/plugin/internal/load/visitImportMappedCandidates.js +45 -0
  1274. package/lib/plugin/internal/load/visitImportMappedCandidates.js.map +1 -0
  1275. package/lib/plugin/internal/pluginDescriptorFailureReason.d.ts +23 -0
  1276. package/lib/plugin/internal/pluginDescriptorFailureReason.js +43 -0
  1277. package/lib/plugin/internal/pluginDescriptorFailureReason.js.map +1 -0
  1278. package/lib/plugin/internal/pluginDescriptorProcessFailure.d.ts +28 -0
  1279. package/lib/plugin/internal/pluginDescriptorProcessFailure.js +37 -0
  1280. package/lib/plugin/internal/pluginDescriptorProcessFailure.js.map +1 -0
  1281. package/lib/plugin/internal/readCapabilityResolution.d.ts +42 -0
  1282. package/lib/plugin/internal/readCapabilityResolution.js +158 -0
  1283. package/lib/plugin/internal/readCapabilityResolution.js.map +1 -0
  1284. package/lib/plugin/internal/receiveCapabilityFailure.d.ts +21 -0
  1285. package/lib/plugin/internal/receiveCapabilityFailure.js +28 -0
  1286. package/lib/plugin/internal/receiveCapabilityFailure.js.map +1 -0
  1287. package/lib/plugin/internal/source/CachePrunePolicy.d.ts +42 -0
  1288. package/lib/plugin/internal/source/CachePrunePolicy.js +47 -0
  1289. package/lib/plugin/internal/source/CachePrunePolicy.js.map +1 -0
  1290. package/lib/plugin/internal/source/GoBuildCacheCoordination.d.ts +159 -0
  1291. package/lib/plugin/internal/source/GoBuildCacheCoordination.js +475 -0
  1292. package/lib/plugin/internal/source/GoBuildCacheCoordination.js.map +1 -0
  1293. package/lib/plugin/internal/source/GoSourceInputs.d.ts +124 -0
  1294. package/lib/plugin/internal/source/GoSourceInputs.js +180 -0
  1295. package/lib/plugin/internal/source/GoSourceInputs.js.map +1 -0
  1296. package/lib/plugin/internal/source/GoToolResolution.d.ts +125 -0
  1297. package/lib/plugin/internal/source/GoToolResolution.js +278 -0
  1298. package/lib/plugin/internal/source/GoToolResolution.js.map +1 -0
  1299. package/lib/plugin/internal/source/IGoBuildCachePruneOptions.d.ts +30 -0
  1300. package/lib/plugin/internal/source/IGoBuildCachePruneOptions.js +3 -0
  1301. package/lib/plugin/internal/source/IGoBuildCachePruneOptions.js.map +1 -0
  1302. package/lib/plugin/internal/source/IPluginCachePruneOptions.d.ts +33 -0
  1303. package/lib/plugin/internal/source/IPluginCachePruneOptions.js +3 -0
  1304. package/lib/plugin/internal/source/IPluginCachePruneOptions.js.map +1 -0
  1305. package/lib/plugin/internal/source/IPluginModuleReplaceDirectory.d.ts +27 -0
  1306. package/lib/plugin/internal/source/IPluginModuleReplaceDirectory.js +3 -0
  1307. package/lib/plugin/internal/source/IPluginModuleReplaceDirectory.js.map +1 -0
  1308. package/lib/plugin/internal/source/ITtscBuildContributor.d.ts +18 -0
  1309. package/lib/plugin/internal/source/ITtscBuildContributor.js +3 -0
  1310. package/lib/plugin/internal/source/ITtscBuildContributor.js.map +1 -0
  1311. package/lib/plugin/internal/source/ITtscSourceBuildCachePaths.d.ts +25 -0
  1312. package/lib/plugin/internal/source/ITtscSourceBuildCachePaths.js +3 -0
  1313. package/lib/plugin/internal/source/ITtscSourceBuildCachePaths.js.map +1 -0
  1314. package/lib/plugin/internal/source/NativeSourcePackages.d.ts +155 -0
  1315. package/lib/plugin/internal/source/NativeSourcePackages.js +317 -0
  1316. package/lib/plugin/internal/source/NativeSourcePackages.js.map +1 -0
  1317. package/lib/plugin/internal/source/PluginBinaryUse.d.ts +66 -0
  1318. package/lib/plugin/internal/source/PluginBinaryUse.js +163 -0
  1319. package/lib/plugin/internal/source/PluginBinaryUse.js.map +1 -0
  1320. package/lib/plugin/internal/source/PluginBinaryWaitResult.d.ts +34 -0
  1321. package/lib/plugin/internal/source/PluginBinaryWaitResult.js +3 -0
  1322. package/lib/plugin/internal/source/PluginBinaryWaitResult.js.map +1 -0
  1323. package/lib/plugin/internal/source/PluginBuildEnvironmentReadings.d.ts +90 -0
  1324. package/lib/plugin/internal/source/PluginBuildEnvironmentReadings.js +207 -0
  1325. package/lib/plugin/internal/source/PluginBuildEnvironmentReadings.js.map +1 -0
  1326. package/lib/plugin/internal/source/PluginBuildEnvironmentWitness.d.ts +128 -0
  1327. package/lib/plugin/internal/source/PluginBuildEnvironmentWitness.js +209 -0
  1328. package/lib/plugin/internal/source/PluginBuildEnvironmentWitness.js.map +1 -0
  1329. package/lib/plugin/internal/source/PluginBuildLockFence.d.ts +25 -0
  1330. package/lib/plugin/internal/source/PluginBuildLockFence.js +3 -0
  1331. package/lib/plugin/internal/source/PluginBuildLockFence.js.map +1 -0
  1332. package/lib/plugin/internal/source/PluginBuildLockLease.d.ts +29 -0
  1333. package/lib/plugin/internal/source/PluginBuildLockLease.js +3 -0
  1334. package/lib/plugin/internal/source/PluginBuildLockLease.js.map +1 -0
  1335. package/lib/plugin/internal/source/PluginBuildLockObservation.d.ts +42 -0
  1336. package/lib/plugin/internal/source/PluginBuildLockObservation.js +3 -0
  1337. package/lib/plugin/internal/source/PluginBuildLockObservation.js.map +1 -0
  1338. package/lib/plugin/internal/source/PluginBuildLockOwner.d.ts +126 -0
  1339. package/lib/plugin/internal/source/PluginBuildLockOwner.js +165 -0
  1340. package/lib/plugin/internal/source/PluginBuildLockOwner.js.map +1 -0
  1341. package/lib/plugin/internal/source/PluginBuildLockProtocol.d.ts +234 -0
  1342. package/lib/plugin/internal/source/PluginBuildLockProtocol.js +287 -0
  1343. package/lib/plugin/internal/source/PluginBuildLockProtocol.js.map +1 -0
  1344. package/lib/plugin/internal/source/SourceBuildCacheLayout.d.ts +183 -0
  1345. package/lib/plugin/internal/source/SourceBuildCacheLayout.js +291 -0
  1346. package/lib/plugin/internal/source/SourceBuildCacheLayout.js.map +1 -0
  1347. package/lib/plugin/internal/source/SourceBuildFilesystemOperations.d.ts +32 -0
  1348. package/lib/plugin/internal/source/SourceBuildFilesystemOperations.js +3 -0
  1349. package/lib/plugin/internal/source/SourceBuildFilesystemOperations.js.map +1 -0
  1350. package/lib/plugin/internal/source/SourcePluginAdmission.d.ts +80 -0
  1351. package/lib/plugin/internal/source/SourcePluginAdmission.js +114 -0
  1352. package/lib/plugin/internal/source/SourcePluginAdmission.js.map +1 -0
  1353. package/lib/plugin/internal/source/SourcePluginWorkspace.d.ts +122 -0
  1354. package/lib/plugin/internal/source/SourcePluginWorkspace.js +307 -0
  1355. package/lib/plugin/internal/source/SourcePluginWorkspace.js.map +1 -0
  1356. package/lib/plugin/internal/source/acquirePluginBuildLock.d.ts +35 -0
  1357. package/lib/plugin/internal/source/acquirePluginBuildLock.js +176 -0
  1358. package/lib/plugin/internal/source/acquirePluginBuildLock.js.map +1 -0
  1359. package/lib/plugin/internal/source/autoQuoteGoModToken.d.ts +24 -0
  1360. package/lib/plugin/internal/source/autoQuoteGoModToken.js +110 -0
  1361. package/lib/plugin/internal/source/autoQuoteGoModToken.js.map +1 -0
  1362. package/lib/plugin/internal/source/buildSourcePlugin.d.ts +86 -0
  1363. package/lib/plugin/internal/source/buildSourcePlugin.js +857 -0
  1364. package/lib/plugin/internal/source/buildSourcePlugin.js.map +1 -0
  1365. package/lib/plugin/internal/source/collectPluginSourceDirectories.d.ts +30 -0
  1366. package/lib/plugin/internal/source/collectPluginSourceDirectories.js +77 -0
  1367. package/lib/plugin/internal/source/collectPluginSourceDirectories.js.map +1 -0
  1368. package/lib/plugin/internal/source/collectPluginSourceFiles.d.ts +40 -0
  1369. package/lib/plugin/internal/source/collectPluginSourceFiles.js +95 -0
  1370. package/lib/plugin/internal/source/collectPluginSourceFiles.js.map +1 -0
  1371. package/lib/plugin/internal/source/computeCacheKey.d.ts +73 -0
  1372. package/lib/plugin/internal/source/computeCacheKey.js +113 -0
  1373. package/lib/plugin/internal/source/computeCacheKey.js.map +1 -0
  1374. package/lib/plugin/internal/source/copiesPluginSourceEntry.d.ts +33 -0
  1375. package/lib/plugin/internal/source/copiesPluginSourceEntry.js +57 -0
  1376. package/lib/plugin/internal/source/copiesPluginSourceEntry.js.map +1 -0
  1377. package/lib/plugin/internal/source/createExternalSourceSnapshotLayout.d.ts +22 -0
  1378. package/lib/plugin/internal/source/createExternalSourceSnapshotLayout.js +60 -0
  1379. package/lib/plugin/internal/source/createExternalSourceSnapshotLayout.js.map +1 -0
  1380. package/lib/plugin/internal/source/ensureExecutableGoToolchain.d.ts +25 -0
  1381. package/lib/plugin/internal/source/ensureExecutableGoToolchain.js +96 -0
  1382. package/lib/plugin/internal/source/ensureExecutableGoToolchain.js.map +1 -0
  1383. package/lib/plugin/internal/source/formatDuration.d.ts +18 -0
  1384. package/lib/plugin/internal/source/formatDuration.js +36 -0
  1385. package/lib/plugin/internal/source/formatDuration.js.map +1 -0
  1386. package/lib/plugin/internal/source/formatGoWorkPath.d.ts +35 -0
  1387. package/lib/plugin/internal/source/formatGoWorkPath.js +42 -0
  1388. package/lib/plugin/internal/source/formatGoWorkPath.js.map +1 -0
  1389. package/lib/plugin/internal/source/hashPluginBuildEnvironment.d.ts +47 -0
  1390. package/lib/plugin/internal/source/hashPluginBuildEnvironment.js +663 -0
  1391. package/lib/plugin/internal/source/hashPluginBuildEnvironment.js.map +1 -0
  1392. package/lib/plugin/internal/source/inspectPluginBuildLock.d.ts +29 -0
  1393. package/lib/plugin/internal/source/inspectPluginBuildLock.js +285 -0
  1394. package/lib/plugin/internal/source/inspectPluginBuildLock.js.map +1 -0
  1395. package/lib/plugin/internal/source/isPathWithin.d.ts +16 -0
  1396. package/lib/plugin/internal/source/isPathWithin.js +28 -0
  1397. package/lib/plugin/internal/source/isPathWithin.js.map +1 -0
  1398. package/lib/plugin/internal/source/legacyGlobalCacheTargets.d.ts +24 -0
  1399. package/lib/plugin/internal/source/legacyGlobalCacheTargets.js +60 -0
  1400. package/lib/plugin/internal/source/legacyGlobalCacheTargets.js.map +1 -0
  1401. package/lib/plugin/internal/source/pluginBuildEnvironment.d.ts +31 -0
  1402. package/lib/plugin/internal/source/pluginBuildEnvironment.js +47 -0
  1403. package/lib/plugin/internal/source/pluginBuildEnvironment.js.map +1 -0
  1404. package/lib/plugin/internal/source/pluginBuildEnvironmentWorker.d.ts +1 -0
  1405. package/lib/plugin/internal/source/pluginBuildEnvironmentWorker.js +24 -0
  1406. package/lib/plugin/internal/source/pluginBuildEnvironmentWorker.js.map +1 -0
  1407. package/lib/plugin/internal/source/pluginBuildVersions.d.ts +31 -0
  1408. package/lib/plugin/internal/source/pluginBuildVersions.js +65 -0
  1409. package/lib/plugin/internal/source/pluginBuildVersions.js.map +1 -0
  1410. package/lib/plugin/internal/source/pluginModuleReplaceDirectories.d.ts +40 -0
  1411. package/lib/plugin/internal/source/pluginModuleReplaceDirectories.js +81 -0
  1412. package/lib/plugin/internal/source/pluginModuleReplaceDirectories.js.map +1 -0
  1413. package/lib/plugin/internal/source/pluginSourceCovers.d.ts +32 -0
  1414. package/lib/plugin/internal/source/pluginSourceCovers.js +54 -0
  1415. package/lib/plugin/internal/source/pluginSourceCovers.js.map +1 -0
  1416. package/lib/plugin/internal/source/pluginSourceDigest.d.ts +40 -0
  1417. package/lib/plugin/internal/source/pluginSourceDigest.js +60 -0
  1418. package/lib/plugin/internal/source/pluginSourceDigest.js.map +1 -0
  1419. package/lib/plugin/internal/source/pluginSourceFilesSignature.d.ts +38 -0
  1420. package/lib/plugin/internal/source/pluginSourceFilesSignature.js +53 -0
  1421. package/lib/plugin/internal/source/pluginSourceFilesSignature.js.map +1 -0
  1422. package/lib/plugin/internal/source/pluginSourceState.d.ts +47 -0
  1423. package/lib/plugin/internal/source/pluginSourceState.js +63 -0
  1424. package/lib/plugin/internal/source/pluginSourceState.js.map +1 -0
  1425. package/lib/plugin/internal/source/pluginSourceStateHolds.d.ts +34 -0
  1426. package/lib/plugin/internal/source/pluginSourceStateHolds.js +45 -0
  1427. package/lib/plugin/internal/source/pluginSourceStateHolds.js.map +1 -0
  1428. package/lib/plugin/internal/source/processPluginBuildEnvironment.d.ts +33 -0
  1429. package/lib/plugin/internal/source/processPluginBuildEnvironment.js +40 -0
  1430. package/lib/plugin/internal/source/processPluginBuildEnvironment.js.map +1 -0
  1431. package/lib/plugin/internal/source/pruneCacheFileRoot.d.ts +34 -0
  1432. package/lib/plugin/internal/source/pruneCacheFileRoot.js +120 -0
  1433. package/lib/plugin/internal/source/pruneCacheFileRoot.js.map +1 -0
  1434. package/lib/plugin/internal/source/pruneGoBuildCacheRoot.d.ts +28 -0
  1435. package/lib/plugin/internal/source/pruneGoBuildCacheRoot.js +185 -0
  1436. package/lib/plugin/internal/source/pruneGoBuildCacheRoot.js.map +1 -0
  1437. package/lib/plugin/internal/source/prunePluginCacheRoot.d.ts +46 -0
  1438. package/lib/plugin/internal/source/prunePluginCacheRoot.js +446 -0
  1439. package/lib/plugin/internal/source/prunePluginCacheRoot.js.map +1 -0
  1440. package/lib/plugin/internal/source/prunesPluginSourceDirectory.d.ts +21 -0
  1441. package/lib/plugin/internal/source/prunesPluginSourceDirectory.js +28 -0
  1442. package/lib/plugin/internal/source/prunesPluginSourceDirectory.js.map +1 -0
  1443. package/lib/plugin/internal/source/reclaimPluginBuildLock.d.ts +23 -0
  1444. package/lib/plugin/internal/source/reclaimPluginBuildLock.js +48 -0
  1445. package/lib/plugin/internal/source/reclaimPluginBuildLock.js.map +1 -0
  1446. package/lib/plugin/internal/source/recordCacheFileUse.d.ts +22 -0
  1447. package/lib/plugin/internal/source/recordCacheFileUse.js +43 -0
  1448. package/lib/plugin/internal/source/recordCacheFileUse.js.map +1 -0
  1449. package/lib/plugin/internal/source/releasePluginBuildLock.d.ts +33 -0
  1450. package/lib/plugin/internal/source/releasePluginBuildLock.js +100 -0
  1451. package/lib/plugin/internal/source/releasePluginBuildLock.js.map +1 -0
  1452. package/lib/plugin/internal/source/resolveCleanTargets.d.ts +26 -0
  1453. package/lib/plugin/internal/source/resolveCleanTargets.js +73 -0
  1454. package/lib/plugin/internal/source/resolveCleanTargets.js.map +1 -0
  1455. package/lib/plugin/internal/source/resolveGoCompiler.d.ts +29 -0
  1456. package/lib/plugin/internal/source/resolveGoCompiler.js +62 -0
  1457. package/lib/plugin/internal/source/resolveGoCompiler.js.map +1 -0
  1458. package/lib/plugin/internal/source/resolvePluginCacheRoot.d.ts +21 -0
  1459. package/lib/plugin/internal/source/resolvePluginCacheRoot.js +31 -0
  1460. package/lib/plugin/internal/source/resolvePluginCacheRoot.js.map +1 -0
  1461. package/lib/plugin/internal/source/resolvePluginGoModule.d.ts +34 -0
  1462. package/lib/plugin/internal/source/resolvePluginGoModule.js +65 -0
  1463. package/lib/plugin/internal/source/resolvePluginGoModule.js.map +1 -0
  1464. package/lib/plugin/internal/source/resolveSourceBuildCachePaths.d.ts +21 -0
  1465. package/lib/plugin/internal/source/resolveSourceBuildCachePaths.js +236 -0
  1466. package/lib/plugin/internal/source/resolveSourceBuildCachePaths.js.map +1 -0
  1467. package/lib/plugin/internal/source/selectPluginModuleReplaceDirectories.d.ts +29 -0
  1468. package/lib/plugin/internal/source/selectPluginModuleReplaceDirectories.js +68 -0
  1469. package/lib/plugin/internal/source/selectPluginModuleReplaceDirectories.js.map +1 -0
  1470. package/lib/plugin/internal/source/spawnGoTool.d.ts +22 -0
  1471. package/lib/plugin/internal/source/spawnGoTool.js +164 -0
  1472. package/lib/plugin/internal/source/spawnGoTool.js.map +1 -0
  1473. package/lib/plugin/internal/source/touchPluginCacheEntryInUse.d.ts +27 -0
  1474. package/lib/plugin/internal/source/touchPluginCacheEntryInUse.js +48 -0
  1475. package/lib/plugin/internal/source/touchPluginCacheEntryInUse.js.map +1 -0
  1476. package/lib/plugin/internal/source/waitForPluginBinary.d.ts +36 -0
  1477. package/lib/plugin/internal/source/waitForPluginBinary.js +94 -0
  1478. package/lib/plugin/internal/source/waitForPluginBinary.js.map +1 -0
  1479. package/lib/plugin/internal/source/windowsGoCommandArgs.d.ts +17 -0
  1480. package/lib/plugin/internal/source/windowsGoCommandArgs.js +23 -0
  1481. package/lib/plugin/internal/source/windowsGoCommandArgs.js.map +1 -0
  1482. package/lib/plugin/internal/source/withGoBuildCacheLease.d.ts +37 -0
  1483. package/lib/plugin/internal/source/withGoBuildCacheLease.js +87 -0
  1484. package/lib/plugin/internal/source/withGoBuildCacheLease.js.map +1 -0
  1485. package/lib/plugin/internal/writeCapabilityResolution.d.ts +80 -0
  1486. package/lib/plugin/internal/writeCapabilityResolution.js +196 -0
  1487. package/lib/plugin/internal/writeCapabilityResolution.js.map +1 -0
  1488. package/lib/plugin/resolveCapabilityPlugins.d.ts +53 -32
  1489. package/lib/plugin/resolveCapabilityPlugins.js +209 -38
  1490. package/lib/plugin/resolveCapabilityPlugins.js.map +1 -1
  1491. package/lib/register.js +20 -5
  1492. package/lib/register.js.map +1 -1
  1493. package/lib/structures/ITtscCompilerContext.d.ts +29 -11
  1494. package/lib/structures/ITtscCompilerDiagnostic.d.ts +24 -7
  1495. package/lib/structures/ITtscCompilerResult.d.ts +75 -25
  1496. package/lib/structures/ITtscCompilerTransformation.d.ts +287 -64
  1497. package/lib/structures/ITtscPlugin.d.ts +24 -8
  1498. package/lib/structures/ITtscPluginCapabilities.d.ts +55 -5
  1499. package/lib/structures/ITtscPluginContributor.d.ts +19 -8
  1500. package/lib/structures/ITtscPluginFactoryContext.d.ts +12 -3
  1501. package/lib/structures/ITtscProjectPluginConfig.d.ts +35 -10
  1502. package/lib/structures/TtscPluginStage.d.ts +9 -0
  1503. package/lib/structures/internal/ITtscLoadedNativePlugin.d.ts +19 -5
  1504. package/lib/structures/internal/ITtscParsedProjectConfig.d.ts +29 -3
  1505. package/lib/structures/internal/ITtscProjectIdentity.d.ts +21 -6
  1506. package/lib/structures/internal/ITtscProjectInputSnapshot.d.ts +23 -8
  1507. package/lib/structures/internal/ITtscProjectLocatorOptions.d.ts +18 -4
  1508. package/lib/structures/internal/TtscBuildOptions.d.ts +33 -14
  1509. package/lib/structures/internal/TtscBuildResult.d.ts +63 -4
  1510. package/lib/structures/internal/TtscCommonOptions.d.ts +47 -14
  1511. package/lib/structures/internal/TtscSingleFileEmitOptions.d.ts +46 -5
  1512. package/package.json +26 -12
  1513. package/shim/ast/enums_gen.go +4 -2
  1514. package/shim/ast/go.mod +5 -5
  1515. package/shim/ast/go.sum +10 -10
  1516. package/shim/ast/lint.go +1088 -20
  1517. package/shim/ast/parent.go +38 -22
  1518. package/shim/ast/safe_text.go +48 -26
  1519. package/shim/ast/shim.go +1307 -20
  1520. package/shim/ast/test/next_jsdoc_comment_location_reaches_variable_statement_test.go +51 -0
  1521. package/shim/ast/test/node_text_joins_multi_hop_qualified_name_test.go +24 -9
  1522. package/shim/ast/test/node_text_joins_one_hop_qualified_name_test.go +9 -5
  1523. package/shim/ast/test/node_text_returns_empty_for_nil_test.go +13 -5
  1524. package/shim/ast/test/node_text_returns_identifier_text_test.go +12 -5
  1525. package/shim/ast/test/node_text_skips_empty_qualified_left_test.go +35 -5
  1526. package/shim/astnav/go.mod +5 -5
  1527. package/shim/astnav/go.sum +12 -10
  1528. package/shim/astnav/shim.go +9 -0
  1529. package/shim/bundled/go.mod +7 -1
  1530. package/shim/bundled/go.sum +12 -0
  1531. package/shim/checker/enums_gen.go +4 -2
  1532. package/shim/checker/extra-shim.json +6 -0
  1533. package/shim/checker/go.mod +5 -5
  1534. package/shim/checker/go.sum +10 -10
  1535. package/shim/checker/node_builder_fields_gen.go +19 -0
  1536. package/shim/checker/shim.go +827 -114
  1537. package/shim/compiler/emit_sourcemap.go +68 -29
  1538. package/shim/compiler/emitassemble.go +36 -2
  1539. package/shim/compiler/emithook.go +13 -3
  1540. package/shim/compiler/go.mod +5 -5
  1541. package/shim/compiler/go.sum +10 -10
  1542. package/shim/compiler/incremental.go +56 -20
  1543. package/shim/compiler/resolution.go +92 -9
  1544. package/shim/core/enums_gen.go +2 -2
  1545. package/shim/core/go.mod +6 -1
  1546. package/shim/core/go.sum +10 -0
  1547. package/shim/core/modulekind.go +9 -0
  1548. package/shim/core/shim.go +157 -6
  1549. package/shim/diagnosticwriter/go.mod +10 -1
  1550. package/shim/diagnosticwriter/go.sum +20 -0
  1551. package/shim/diagnosticwriter/lint.go +188 -10
  1552. package/shim/diagnosticwriter/shim.go +14 -0
  1553. package/shim/lsp/go.mod +5 -5
  1554. package/shim/lsp/go.sum +10 -10
  1555. package/shim/lsp/shim.go +78 -2
  1556. package/shim/parser/go.mod +10 -1
  1557. package/shim/parser/go.sum +22 -0
  1558. package/shim/printer/emithost.go +46 -1
  1559. package/shim/printer/go.mod +5 -5
  1560. package/shim/printer/go.sum +10 -10
  1561. package/shim/printer/shim.go +114 -7
  1562. package/shim/printer/sourcemap.go +55 -0
  1563. package/shim/scanner/go.mod +10 -1
  1564. package/shim/scanner/go.sum +20 -0
  1565. package/shim/scanner/regexp.go +19 -4
  1566. package/shim/scanner/shim.go +3 -0
  1567. package/shim/stringutil/extra-shim.json +1 -0
  1568. package/shim/stringutil/go.mod +5 -0
  1569. package/shim/stringutil/go.sum +2 -0
  1570. package/shim/stringutil/shim.go +119 -0
  1571. package/shim/transformers/go.mod +5 -5
  1572. package/shim/transformers/go.sum +12 -10
  1573. package/shim/transformers/shim.go +12 -3
  1574. package/shim/tsoptions/command_line_raw.go +44 -0
  1575. package/shim/tsoptions/go.mod +10 -1
  1576. package/shim/tsoptions/go.sum +22 -0
  1577. package/shim/tsoptions/shim.go +1 -1
  1578. package/shim/tspath/go.mod +1 -1
  1579. package/shim/tspath/go.sum +6 -0
  1580. package/shim/vfs/cachedvfs/go.mod +3 -1
  1581. package/shim/vfs/cachedvfs/go.sum +12 -0
  1582. package/shim/vfs/decode.go +26 -0
  1583. package/shim/vfs/decode_test.go +42 -0
  1584. package/shim/vfs/go.mod +7 -1
  1585. package/shim/vfs/go.sum +12 -0
  1586. package/shim/vfs/osvfs/go.mod +7 -1
  1587. package/shim/vfs/osvfs/go.sum +12 -0
  1588. package/src/TtscCompiler.ts +223 -234
  1589. package/src/TtscService.ts +87 -31
  1590. package/src/TtscServiceRequestOptions.ts +21 -0
  1591. package/src/compiler/internal/CapturedProcessOutput.ts +69 -0
  1592. package/src/compiler/internal/CompilerArgumentsInspection.ts +184 -0
  1593. package/src/compiler/internal/EmitOwnershipIndex.ts +254 -0
  1594. package/src/compiler/internal/PrivateCompilerOutput.ts +330 -0
  1595. package/src/compiler/internal/ResidentCheckProcess.ts +445 -0
  1596. package/src/compiler/internal/ResidentCheckProcessOptions.ts +32 -0
  1597. package/src/compiler/internal/ResidentCheckRequest.ts +39 -0
  1598. package/src/compiler/internal/ResidentCheckResult.ts +24 -0
  1599. package/src/compiler/internal/ResidentCheckTelemetry.ts +36 -0
  1600. package/src/compiler/internal/ResidentReplyKind.ts +18 -0
  1601. package/src/compiler/internal/ResidentTransformProcess.ts +299 -0
  1602. package/src/compiler/internal/ResidentTransformProcessOptions.ts +30 -0
  1603. package/src/compiler/internal/ResidentTransformReply.ts +79 -0
  1604. package/src/compiler/internal/ResidentTransformRequestOptions.ts +16 -0
  1605. package/src/compiler/internal/ResidentTransformRequests.ts +198 -0
  1606. package/src/compiler/internal/StartedResidentTransform.ts +29 -0
  1607. package/src/compiler/internal/TransformProjectWorkerReply.ts +37 -0
  1608. package/src/compiler/internal/TransformProjectWorkerRequest.ts +42 -0
  1609. package/src/compiler/internal/build/BuildExecution.ts +1261 -0
  1610. package/src/compiler/internal/build/BuildTiming.ts +145 -0
  1611. package/src/compiler/internal/build/CompilerDiagnostics.ts +307 -0
  1612. package/src/compiler/internal/build/NativePluginArguments.ts +302 -0
  1613. package/src/compiler/internal/build/PassthroughFlags.ts +229 -0
  1614. package/src/compiler/internal/build/PluginFailureDiagnostics.ts +70 -0
  1615. package/src/compiler/internal/build/ResidentCheckEntryPlan.ts +42 -0
  1616. package/src/compiler/internal/build/ResidentCheckWatchChange.ts +33 -0
  1617. package/src/compiler/internal/build/ResidentCheckWatchSession.ts +501 -0
  1618. package/src/compiler/internal/build/RunBuildOptions.ts +145 -0
  1619. package/src/compiler/internal/build/TsgoArguments.ts +349 -0
  1620. package/src/compiler/internal/build/appendBuildOutput.ts +218 -0
  1621. package/src/compiler/internal/build/bufferResidentCheckEntryRequests.ts +52 -0
  1622. package/src/compiler/internal/build/createProcessDiagnostic.ts +32 -0
  1623. package/src/compiler/internal/build/isAbsoluteLocalProjectInputPath.ts +55 -0
  1624. package/src/compiler/internal/build/mergeProjectInputSnapshots.ts +147 -0
  1625. package/src/compiler/internal/build/normalizeBuildOutput.ts +89 -0
  1626. package/src/compiler/internal/build/parseProjectInputSnapshot.ts +91 -0
  1627. package/src/compiler/internal/build/planResidentCheckEntries.ts +55 -0
  1628. package/src/compiler/internal/build/privateRuntimeRootDir.ts +33 -0
  1629. package/src/compiler/internal/build/residentCheckRequest.ts +41 -0
  1630. package/src/compiler/internal/build/runBuild.ts +61 -0
  1631. package/src/compiler/internal/build/runExternalEmitProvenance.ts +566 -0
  1632. package/src/compiler/internal/build/takeResidentCheckEntryRequest.ts +31 -0
  1633. package/src/compiler/internal/buildNativeCompiler.ts +19 -2
  1634. package/src/compiler/internal/captureProcessOutput.ts +39 -37
  1635. package/src/compiler/internal/compileProjectInMemory.ts +139 -92
  1636. package/src/compiler/internal/ensureExecutable.ts +32 -0
  1637. package/src/compiler/internal/findNearestGoMod.ts +43 -0
  1638. package/src/compiler/internal/isOutsideRelativePath.ts +26 -0
  1639. package/src/compiler/internal/outputText.ts +21 -0
  1640. package/src/compiler/internal/packageRootDir.ts +43 -0
  1641. package/src/compiler/internal/parseNativeTransformOutput.ts +722 -0
  1642. package/src/compiler/internal/project/CompilerProjectSelection.ts +204 -0
  1643. package/src/compiler/internal/project/ConfigJsonText.ts +55 -0
  1644. package/src/compiler/internal/project/compilerUsesCaseSensitiveFileNames.ts +124 -0
  1645. package/src/compiler/internal/project/createNativeProjectContextArgs.ts +14 -19
  1646. package/src/compiler/internal/project/createNativeProjectContextJson.ts +28 -0
  1647. package/src/compiler/internal/project/parseJsonc.ts +318 -0
  1648. package/src/compiler/internal/project/readJsonFile.ts +34 -0
  1649. package/src/compiler/internal/project/readJsoncFile.ts +46 -0
  1650. package/src/compiler/internal/project/readProjectConfig.ts +137 -200
  1651. package/src/compiler/internal/project/resolveOwningProjectConfig.ts +278 -0
  1652. package/src/compiler/internal/project/resolveProjectConfig.ts +18 -127
  1653. package/src/compiler/internal/project/resolveProjectIdentity.ts +153 -0
  1654. package/src/compiler/internal/project/resolveTsconfigExtends.ts +175 -0
  1655. package/src/compiler/internal/project/selectReferencedProject.ts +54 -0
  1656. package/src/compiler/internal/project/tsconfigExtendsFileCandidates.ts +54 -0
  1657. package/src/compiler/internal/readEffectiveCompilerOptions.ts +126 -0
  1658. package/src/compiler/internal/resolveBinary.ts +25 -9
  1659. package/src/compiler/internal/resolveTsgo.ts +31 -11
  1660. package/src/compiler/internal/runNativeCheckWithObservations.ts +211 -0
  1661. package/src/compiler/internal/runSingleFileEmit.ts +92 -27
  1662. package/src/compiler/internal/sharedHost/SEMANTIC_CONFIG_PATH_ENV.ts +2 -0
  1663. package/src/compiler/internal/sharedHost/SidecarEnvironment.ts +151 -0
  1664. package/src/compiler/internal/sharedHost/TSGO_ARGS_CWD_ENV.ts +7 -0
  1665. package/src/compiler/internal/sharedHost/TSGO_ARGS_ENV.ts +7 -0
  1666. package/src/compiler/internal/sharedHost/assertSharedHostCompatibility.ts +48 -0
  1667. package/src/compiler/internal/sharedHost/clearInheritedSemanticConfigPath.ts +27 -0
  1668. package/src/compiler/internal/sharedHost/clearInheritedTsgoArgs.ts +41 -0
  1669. package/src/compiler/internal/sharedHost/inheritedSidecarEnv.ts +45 -0
  1670. package/src/compiler/internal/sharedHost/isLinkedTransform.ts +19 -0
  1671. package/src/compiler/internal/sharedHost/linkedTransformPlugins.ts +25 -0
  1672. package/src/compiler/internal/sharedHost/publishLinkedTransformPlugins.ts +42 -0
  1673. package/src/compiler/internal/sharedHost/resolvePluginConfigDir.ts +33 -0
  1674. package/src/compiler/internal/sharedHost/selectSharedHostPlugin.ts +35 -0
  1675. package/src/compiler/internal/spawnNative.ts +20 -41
  1676. package/src/compiler/internal/startResidentTransform.ts +66 -53
  1677. package/src/compiler/internal/transformProjectInMemory.ts +356 -634
  1678. package/src/compiler/internal/transformProjectInWorker.ts +170 -0
  1679. package/src/compiler/internal/transformProjectWorker.ts +43 -0
  1680. package/src/flags/AnySubcommand.ts +19 -0
  1681. package/src/flags/COMPILER_ENUM_WHITESPACE.ts +35 -0
  1682. package/src/flags/COMPILER_OPTIONS.ts +512 -0
  1683. package/src/flags/COMPILER_OPTION_ASCII_FOLDS.ts +13 -0
  1684. package/src/flags/COMPILER_OPTION_KINDS.ts +14 -0
  1685. package/src/flags/CompilerOptionSpec.ts +30 -0
  1686. package/src/flags/FLAG_BY_TOKEN.ts +40 -0
  1687. package/src/flags/{schema.ts → FLAG_SCHEMA.ts} +43 -318
  1688. package/src/flags/FlagKind.ts +22 -0
  1689. package/src/flags/FlagLayer.ts +24 -0
  1690. package/src/flags/FlagSpec.ts +118 -0
  1691. package/src/flags/ParseOptions.ts +103 -0
  1692. package/src/flags/ParseResult.ts +44 -0
  1693. package/src/flags/TtscSubcommand.ts +22 -0
  1694. package/src/flags/TtsxSubcommand.ts +13 -0
  1695. package/src/flags/ValueValidator.ts +14 -0
  1696. package/src/flags/buildGoAllowList.ts +43 -0
  1697. package/src/flags/flagsForSubcommand.ts +22 -0
  1698. package/src/flags/getBoolean.ts +27 -0
  1699. package/src/flags/getNumber.ts +24 -0
  1700. package/src/flags/getString.ts +24 -0
  1701. package/src/flags/getStringList.ts +24 -0
  1702. package/src/flags/normalizeCompilerEnumValue.ts +41 -0
  1703. package/src/flags/normalizeFlagToken.ts +38 -0
  1704. package/src/flags/parseFlags.ts +371 -0
  1705. package/src/flags/readCompilerOptionOccurrence.ts +107 -0
  1706. package/src/flags/readCompilerOptionValues.ts +68 -0
  1707. package/src/flags/resolveFlagSpec.ts +29 -0
  1708. package/src/index.ts +9 -3
  1709. package/src/internal/CanonicalTempDirectoryOperations.ts +73 -0
  1710. package/src/internal/CompilerContextSnapshot.ts +139 -0
  1711. package/src/internal/CompilerResultAdapter.ts +320 -0
  1712. package/src/internal/E2ETrace.ts +674 -0
  1713. package/src/internal/IJavaScriptRuntimeCapabilities.ts +50 -0
  1714. package/src/internal/OwnedNativeProcess.ts +417 -0
  1715. package/src/internal/OwnedSynchronousProcess.ts +220 -0
  1716. package/src/internal/RetireLockDirectoryOperations.ts +81 -0
  1717. package/src/internal/SafeCacheCleanupTarget.ts +41 -0
  1718. package/src/internal/SourceNativeRetirement.ts +1109 -0
  1719. package/src/internal/SpawnSyncOutputFiles.ts +29 -0
  1720. package/src/internal/cacheEntryExists.ts +24 -0
  1721. package/src/internal/createCanonicalTempDirectory.ts +35 -18
  1722. package/src/internal/isContendedCandidateRename.ts +35 -0
  1723. package/src/internal/isSpawnSyncFdExhaustion.ts +19 -0
  1724. package/src/internal/javascriptRuntimeCapabilities.ts +166 -0
  1725. package/src/internal/nativeBinary.ts +11 -0
  1726. package/src/internal/parseWindowsDirectoryCaseSensitivity.ts +50 -0
  1727. package/src/internal/pathIdentity/FilesystemPathIdentity.ts +44 -0
  1728. package/src/internal/pathIdentity/FilesystemPathIdentityContext.ts +182 -0
  1729. package/src/internal/pathIdentity/FilesystemPathIdentityOperations.ts +106 -0
  1730. package/src/internal/pathIdentity/ProjectInputPathIdentity.ts +21 -0
  1731. package/src/internal/pathIdentity/ProjectInputPathIdentityContext.ts +21 -0
  1732. package/src/internal/pathIdentity/ProjectInputPathIdentityOperations.ts +22 -0
  1733. package/src/internal/pathIdentity/createFilesystemPathIdentityContext.ts +437 -0
  1734. package/src/internal/pathIdentity/createProjectInputPathIdentityContext.ts +34 -0
  1735. package/src/internal/pathIdentity/isFilesystemPathIdentityWithin.ts +32 -0
  1736. package/src/internal/pathIdentity/isProjectInputPathIdentityWithin.ts +22 -0
  1737. package/src/internal/pathIdentity/resolveFilesystemPath.ts +43 -0
  1738. package/src/internal/pathIdentity/resolvePhysicalPath.ts +31 -0
  1739. package/src/internal/pathIdentity/resolveProjectInputPath.ts +18 -0
  1740. package/src/internal/pluginSource.ts +26 -0
  1741. package/src/internal/projectInputPathIdentity.ts +26 -387
  1742. package/src/internal/resolveNodeBinary.ts +13 -142
  1743. package/src/internal/resolveSafeCacheCleanupTargets.ts +51 -19
  1744. package/src/internal/restoreCompilerError.ts +175 -0
  1745. package/src/internal/retireLockDirectory.ts +166 -0
  1746. package/src/internal/runHoldingLock.ts +55 -0
  1747. package/src/internal/runtimeExecutableIdentity.ts +212 -0
  1748. package/src/internal/serializeCompilerError.ts +145 -0
  1749. package/src/internal/spawnSyncResilient.ts +62 -0
  1750. package/src/internal/spawnSyncWithLowDescriptors.ts +227 -0
  1751. package/src/internal/tsconfig.ts +16 -0
  1752. package/src/launcher/internal/PendingResidentCheckWatchChanges.ts +94 -0
  1753. package/src/launcher/internal/TtscBuildMode.ts +14 -0
  1754. package/src/launcher/internal/TtsxEntryOptions.ts +92 -0
  1755. package/src/launcher/internal/assertNoSolutionBuild.ts +17 -10
  1756. package/src/launcher/internal/assertTtsxNoWatch.ts +49 -0
  1757. package/src/launcher/internal/buildSingleRootProject.ts +303 -0
  1758. package/src/launcher/internal/getCompilerVersionText.ts +20 -5
  1759. package/src/launcher/internal/inlineServedSourceMap.ts +294 -0
  1760. package/src/launcher/internal/linkVirtualEntry.ts +88 -0
  1761. package/src/launcher/internal/{commonJsExportMetadata.ts → parseCommonJsExports.ts} +12 -2
  1762. package/src/launcher/internal/parseTtscBuildArgs.ts +103 -0
  1763. package/src/launcher/internal/parseTtsxCLI.ts +183 -0
  1764. package/src/launcher/internal/prepareExecution.ts +474 -362
  1765. package/src/launcher/internal/prepareTtscBuildMode.ts +64 -0
  1766. package/src/launcher/internal/resolveCacheDir.ts +12 -3
  1767. package/src/launcher/internal/resolveSingleFileOutput.ts +145 -0
  1768. package/src/launcher/internal/resolveTtscserverBinary.ts +20 -5
  1769. package/src/launcher/internal/runTtsc.ts +394 -326
  1770. package/src/launcher/internal/runTtsx.ts +349 -151
  1771. package/src/launcher/internal/runtime/CommonJsRuntimeSource.ts +365 -0
  1772. package/src/launcher/internal/runtime/DependencyBuildAdmission.ts +159 -0
  1773. package/src/launcher/internal/runtime/DependencyBuildGeneration.ts +236 -0
  1774. package/src/launcher/internal/runtime/DependencyBuildLockFence.ts +22 -0
  1775. package/src/launcher/internal/runtime/DependencyBuildLockLease.ts +22 -0
  1776. package/src/launcher/internal/runtime/DependencyBuildLockObservation.ts +49 -0
  1777. package/src/launcher/internal/runtime/DependencyBuildLockProtocol.ts +137 -0
  1778. package/src/launcher/internal/runtime/OwnedProjectSource.ts +140 -0
  1779. package/src/launcher/internal/runtime/OwningModuleOptions.ts +22 -0
  1780. package/src/launcher/internal/runtime/PluginDescriptorInputObservation.ts +112 -0
  1781. package/src/launcher/internal/runtime/ProcessOwnedDirectory.ts +325 -0
  1782. package/src/launcher/internal/runtime/ResolveResult.ts +26 -0
  1783. package/src/launcher/internal/runtime/RuntimeEmitProvenance.ts +58 -0
  1784. package/src/launcher/internal/runtime/RuntimeEntryPreparer.ts +23 -0
  1785. package/src/launcher/internal/runtime/RuntimeFilesystem.ts +64 -0
  1786. package/src/launcher/internal/runtime/RuntimeHookOptions.ts +23 -0
  1787. package/src/launcher/internal/runtime/RuntimeIsolatedEmit.ts +88 -0
  1788. package/src/launcher/internal/runtime/RuntimeLoaderCapabilities.ts +256 -0
  1789. package/src/launcher/internal/runtime/RuntimeManifest.ts +77 -0
  1790. package/src/launcher/internal/runtime/RuntimeManifestRegistry.ts +309 -0
  1791. package/src/launcher/internal/runtime/RuntimeModuleFormat.ts +275 -0
  1792. package/src/launcher/internal/runtime/RuntimeProjectOwnership.ts +139 -0
  1793. package/src/launcher/internal/runtime/TTSX_MINIMUM_NODE_VERSION.ts +11 -0
  1794. package/src/launcher/internal/runtime/acquireDependencyBuildLock.ts +97 -0
  1795. package/src/launcher/internal/runtime/checkNodeRuntimeSupport.ts +94 -0
  1796. package/src/launcher/internal/runtime/claimRuntimeProjectDirectory.ts +54 -0
  1797. package/src/launcher/internal/runtime/commonJsExportNames.ts +57 -0
  1798. package/src/launcher/internal/runtime/commonJsImportFacade.ts +62 -0
  1799. package/src/launcher/internal/runtime/dependencyCacheKey.ts +82 -0
  1800. package/src/launcher/internal/runtime/dependencyCacheRoot.ts +112 -0
  1801. package/src/launcher/internal/runtime/inspectDependencyBuildLock.ts +162 -0
  1802. package/src/launcher/internal/runtime/installRuntimeHooks.ts +2442 -0
  1803. package/src/launcher/internal/runtime/interopProbe.ts +8 -0
  1804. package/src/launcher/internal/runtime/isLocalProcessGone.ts +67 -0
  1805. package/src/launcher/internal/runtime/observeMappedDescriptorResolution.ts +74 -0
  1806. package/src/launcher/internal/runtime/projectModuleOptions.ts +28 -0
  1807. package/src/launcher/internal/runtime/readDependencyCache.ts +89 -0
  1808. package/src/launcher/internal/runtime/realPath.ts +30 -0
  1809. package/src/launcher/internal/runtime/reclaimDependencyBuildLock.ts +27 -0
  1810. package/src/launcher/internal/runtime/releaseDependencyBuildLock.ts +27 -0
  1811. package/src/launcher/internal/runtime/resolveRuntimeCleanTargets.ts +93 -0
  1812. package/src/launcher/internal/runtime/restoreStrippedNodeBuiltinScheme.ts +32 -0
  1813. package/src/launcher/internal/runtime/runtimeRunKey.ts +31 -0
  1814. package/src/launcher/internal/runtime/selectRuntimePluginPolicy.ts +28 -0
  1815. package/src/launcher/internal/runtime/withRuntimeDirectoryLock.ts +92 -0
  1816. package/src/launcher/internal/runtimeCompilerArgs.ts +91 -62
  1817. package/src/launcher/internal/runtimeEmitProfile.ts +70 -0
  1818. package/src/launcher/internal/runtimeHookPreload.ts +3 -3
  1819. package/src/launcher/internal/runtimeOwnerPreload.ts +43 -0
  1820. package/src/launcher/internal/singleRootProjectConfig.ts +38 -0
  1821. package/src/launcher/internal/ttscserver/ILSPPluginSelectionInputs.ts +65 -0
  1822. package/src/launcher/internal/ttscserver/LSPProjectInputDigest.ts +331 -0
  1823. package/src/launcher/internal/ttscserver/captureLSPPluginSelectionInputs.ts +107 -0
  1824. package/src/launcher/internal/ttscserver/fingerprintInitialLSPProjectInputSnapshot.ts +41 -0
  1825. package/src/launcher/internal/ttscserver/initialLSPProjectInputSnapshotIsCurrent.ts +36 -0
  1826. package/src/launcher/internal/ttscserver/materializeLSPPluginManifest.ts +60 -0
  1827. package/src/launcher/internal/ttscserver/needsStdio.ts +32 -0
  1828. package/src/launcher/internal/ttscserver/runTtscserver.ts +592 -0
  1829. package/src/launcher/internal/watch/CompilerDirectoryWatchEventPlan.ts +31 -0
  1830. package/src/launcher/internal/watch/DirectoryWatcher.ts +45 -0
  1831. package/src/launcher/internal/watch/FseventsStreams.ts +303 -0
  1832. package/src/launcher/internal/watch/ProjectInputWatchRules.ts +179 -0
  1833. package/src/launcher/internal/watch/WatchInputChange.ts +31 -0
  1834. package/src/launcher/internal/watch/WatchPaths.ts +156 -0
  1835. package/src/launcher/internal/{watchTopology.ts → watch/WatchTopology.ts} +867 -962
  1836. package/src/launcher/internal/watch/literalGlobRoot.ts +40 -0
  1837. package/src/launcher/internal/watch/planCompilerDirectoryWatchEvent.ts +83 -0
  1838. package/src/launcher/internal/watch/projectInputActiveWatchDirectories.ts +47 -0
  1839. package/src/launcher/internal/watch/projectInputAvailableWatchDirectory.ts +56 -0
  1840. package/src/launcher/internal/watch/projectInputEventShouldNotify.ts +23 -0
  1841. package/src/launcher/internal/watch/projectInputMembershipInvalidatesProgram.ts +63 -0
  1842. package/src/launcher/internal/watch/projectInputReloadEventShouldNotify.ts +127 -0
  1843. package/src/launcher/internal/watch/projectInputReplacementStrandsWatchers.ts +57 -0
  1844. package/src/launcher/internal/watch/projectInputTopologyMayAffect.ts +73 -0
  1845. package/src/launcher/internal/watch/projectInputWatchDirectories.ts +33 -0
  1846. package/src/launcher/internal/watch/reloadInputsForFailedTopologyRefresh.ts +49 -0
  1847. package/src/launcher/internal/watch/syncWatchers.ts +64 -0
  1848. package/src/launcher/internal/watch/watchDirectory.ts +53 -0
  1849. package/src/launcher/internal/watch/watchDirectoryThroughFsWatch.ts +47 -0
  1850. package/src/launcher/ttscserver.ts +1 -1
  1851. package/src/launcher/ttsx.ts +2 -3
  1852. package/src/plugin/CapabilityPluginResolver.ts +549 -0
  1853. package/src/plugin/ITtscCapabilityPlugin.ts +93 -0
  1854. package/src/plugin/internal/CapabilityPluginResult.ts +99 -0
  1855. package/src/plugin/internal/CapabilityResolutionFormat.ts +248 -0
  1856. package/src/plugin/internal/ITtscCapabilityPluginSource.ts +37 -0
  1857. package/src/plugin/internal/ITtscCapabilityResolutionEntry.ts +57 -0
  1858. package/src/plugin/internal/ITtscCapabilityResolutionPlugin.ts +22 -0
  1859. package/src/plugin/internal/capabilityPluginWorker.ts +216 -0
  1860. package/src/plugin/internal/decodeCapabilityCommandReply.ts +27 -0
  1861. package/src/plugin/internal/load/COMMONJS_PLUGIN_DESCRIPTOR_SHIM_SOURCE.ts +182 -0
  1862. package/src/plugin/internal/load/PLUGIN_DESCRIPTOR_SHIM_SOURCE.ts +59 -0
  1863. package/src/plugin/internal/load/PluginDescriptorAdmission.ts +75 -0
  1864. package/src/plugin/internal/load/PluginDescriptorEvaluationCache.ts +432 -0
  1865. package/src/plugin/internal/load/PluginPackageResolution.ts +711 -0
  1866. package/src/plugin/internal/load/ProjectPluginEntries.ts +232 -0
  1867. package/src/plugin/internal/load/RESOLUTION_INPUT_RECORDER_PATH.ts +34 -0
  1868. package/src/plugin/internal/load/collectProjectHostInputs.ts +88 -0
  1869. package/src/plugin/internal/load/composePluginSources.ts +121 -0
  1870. package/src/plugin/internal/load/declaresHostInputReads.ts +52 -0
  1871. package/src/plugin/internal/load/hasProjectPluginEntries.ts +33 -0
  1872. package/src/plugin/internal/load/hashHostInputPaths.ts +44 -0
  1873. package/src/plugin/internal/load/isRelativePluginSpecifier.ts +31 -0
  1874. package/src/plugin/internal/load/loadProjectPlugins.ts +2242 -0
  1875. package/src/plugin/internal/load/moduleResolutionBaseSelects.ts +59 -0
  1876. package/src/plugin/internal/load/observeImportSearchRoots.ts +42 -0
  1877. package/src/plugin/internal/load/pluginLabel.ts +28 -0
  1878. package/src/plugin/internal/load/realpathHostInput.ts +22 -0
  1879. package/src/plugin/internal/load/realpathHostInputPaths.ts +27 -0
  1880. package/src/plugin/internal/load/rejectJsTransformFunctions.ts +23 -0
  1881. package/src/plugin/internal/load/requirePluginSource.ts +34 -0
  1882. package/src/plugin/internal/load/resolveNativeSource.ts +42 -0
  1883. package/src/plugin/internal/load/validatePluginContributors.ts +102 -0
  1884. package/src/plugin/internal/load/validatePluginSource.ts +19 -0
  1885. package/src/plugin/internal/load/visitImportMappedCandidates.ts +63 -0
  1886. package/src/plugin/internal/pluginDescriptorFailureReason.ts +35 -0
  1887. package/src/plugin/internal/pluginDescriptorProcessFailure.ts +48 -0
  1888. package/src/plugin/internal/readCapabilityResolution.ts +193 -0
  1889. package/src/plugin/internal/receiveCapabilityFailure.ts +27 -0
  1890. package/src/plugin/internal/source/CachePrunePolicy.ts +47 -0
  1891. package/src/plugin/internal/source/GoBuildCacheCoordination.ts +588 -0
  1892. package/src/plugin/internal/source/GoSourceInputs.ts +182 -0
  1893. package/src/plugin/internal/source/GoToolResolution.ts +312 -0
  1894. package/src/plugin/internal/source/IGoBuildCachePruneOptions.ts +34 -0
  1895. package/src/plugin/internal/source/IPluginCachePruneOptions.ts +38 -0
  1896. package/src/plugin/internal/source/IPluginModuleReplaceDirectory.ts +30 -0
  1897. package/src/plugin/internal/source/ITtscBuildContributor.ts +19 -0
  1898. package/src/plugin/internal/source/ITtscSourceBuildCachePaths.ts +28 -0
  1899. package/src/plugin/internal/source/NativeSourcePackages.ts +368 -0
  1900. package/src/plugin/internal/source/PluginBinaryUse.ts +159 -0
  1901. package/src/plugin/internal/source/PluginBinaryWaitResult.ts +34 -0
  1902. package/src/plugin/internal/source/PluginBuildEnvironmentReadings.ts +231 -0
  1903. package/src/plugin/internal/source/PluginBuildEnvironmentWitness.ts +233 -0
  1904. package/src/plugin/internal/source/PluginBuildLockFence.ts +26 -0
  1905. package/src/plugin/internal/source/PluginBuildLockLease.ts +31 -0
  1906. package/src/plugin/internal/source/PluginBuildLockObservation.ts +48 -0
  1907. package/src/plugin/internal/source/PluginBuildLockOwner.ts +225 -0
  1908. package/src/plugin/internal/source/PluginBuildLockProtocol.ts +342 -0
  1909. package/src/plugin/internal/source/SourceBuildCacheLayout.ts +303 -0
  1910. package/src/plugin/internal/source/SourceBuildFilesystemOperations.ts +32 -0
  1911. package/src/plugin/internal/source/SourcePluginAdmission.ts +127 -0
  1912. package/src/plugin/internal/source/SourcePluginWorkspace.ts +446 -0
  1913. package/src/plugin/internal/source/acquirePluginBuildLock.ts +222 -0
  1914. package/src/plugin/internal/source/autoQuoteGoModToken.ts +113 -0
  1915. package/src/plugin/internal/source/buildSourcePlugin.ts +1197 -0
  1916. package/src/plugin/internal/source/collectPluginSourceDirectories.ts +70 -0
  1917. package/src/plugin/internal/source/collectPluginSourceFiles.ts +90 -0
  1918. package/src/plugin/internal/source/computeCacheKey.ts +190 -0
  1919. package/src/plugin/internal/source/copiesPluginSourceEntry.ts +52 -0
  1920. package/src/plugin/internal/source/createExternalSourceSnapshotLayout.ts +66 -0
  1921. package/src/plugin/internal/source/ensureExecutableGoToolchain.ts +87 -0
  1922. package/src/plugin/internal/source/formatDuration.ts +32 -0
  1923. package/src/plugin/internal/source/formatGoWorkPath.ts +42 -0
  1924. package/src/plugin/internal/source/hashPluginBuildEnvironment.ts +803 -0
  1925. package/src/plugin/internal/source/inspectPluginBuildLock.ts +330 -0
  1926. package/src/plugin/internal/source/isPathWithin.ts +24 -0
  1927. package/src/plugin/internal/source/legacyGlobalCacheTargets.ts +71 -0
  1928. package/src/plugin/internal/source/pluginBuildEnvironment.ts +59 -0
  1929. package/src/plugin/internal/source/pluginBuildEnvironmentWorker.ts +30 -0
  1930. package/src/plugin/internal/source/pluginBuildVersions.ts +75 -0
  1931. package/src/plugin/internal/source/pluginModuleReplaceDirectories.ts +96 -0
  1932. package/src/plugin/internal/source/pluginSourceCovers.ts +54 -0
  1933. package/src/plugin/internal/source/pluginSourceDigest.ts +55 -0
  1934. package/src/plugin/internal/source/pluginSourceFilesSignature.ts +54 -0
  1935. package/src/plugin/internal/source/pluginSourceState.ts +69 -0
  1936. package/src/plugin/internal/source/pluginSourceStateHolds.ts +45 -0
  1937. package/src/plugin/internal/source/processPluginBuildEnvironment.ts +40 -0
  1938. package/src/plugin/internal/source/pruneCacheFileRoot.ts +134 -0
  1939. package/src/plugin/internal/source/pruneGoBuildCacheRoot.ts +228 -0
  1940. package/src/plugin/internal/source/prunePluginCacheRoot.ts +507 -0
  1941. package/src/plugin/internal/source/prunesPluginSourceDirectory.ts +25 -0
  1942. package/src/plugin/internal/source/reclaimPluginBuildLock.ts +63 -0
  1943. package/src/plugin/internal/source/recordCacheFileUse.ts +35 -0
  1944. package/src/plugin/internal/source/releasePluginBuildLock.ts +125 -0
  1945. package/src/plugin/internal/source/resolveCleanTargets.ts +84 -0
  1946. package/src/plugin/internal/source/resolveGoCompiler.ts +92 -0
  1947. package/src/plugin/internal/source/resolvePluginCacheRoot.ts +32 -0
  1948. package/src/plugin/internal/source/resolvePluginGoModule.ts +69 -0
  1949. package/src/plugin/internal/source/resolveSourceBuildCachePaths.ts +276 -0
  1950. package/src/plugin/internal/source/selectPluginModuleReplaceDirectories.ts +80 -0
  1951. package/src/plugin/internal/source/spawnGoTool.ts +204 -0
  1952. package/src/plugin/internal/source/touchPluginCacheEntryInUse.ts +44 -0
  1953. package/src/plugin/internal/source/waitForPluginBinary.ts +123 -0
  1954. package/src/plugin/internal/source/windowsGoCommandArgs.ts +19 -0
  1955. package/src/plugin/internal/source/withGoBuildCacheLease.ts +101 -0
  1956. package/src/plugin/internal/writeCapabilityResolution.ts +266 -0
  1957. package/src/plugin/resolveCapabilityPlugins.ts +242 -77
  1958. package/src/register.ts +20 -7
  1959. package/src/structures/ITtscCompilerContext.ts +29 -11
  1960. package/src/structures/ITtscCompilerDiagnostic.ts +24 -7
  1961. package/src/structures/ITtscCompilerResult.ts +75 -25
  1962. package/src/structures/ITtscCompilerTransformation.ts +304 -64
  1963. package/src/structures/ITtscPlugin.ts +24 -8
  1964. package/src/structures/ITtscPluginCapabilities.ts +58 -5
  1965. package/src/structures/ITtscPluginContributor.ts +19 -8
  1966. package/src/structures/ITtscPluginFactoryContext.ts +12 -3
  1967. package/src/structures/ITtscProjectPluginConfig.ts +35 -10
  1968. package/src/structures/TtscPluginStage.ts +9 -0
  1969. package/src/structures/internal/ITtscLoadedNativePlugin.ts +27 -5
  1970. package/src/structures/internal/ITtscParsedProjectConfig.ts +37 -3
  1971. package/src/structures/internal/ITtscProjectIdentity.ts +27 -6
  1972. package/src/structures/internal/ITtscProjectInputSnapshot.ts +31 -8
  1973. package/src/structures/internal/ITtscProjectLocatorOptions.ts +21 -4
  1974. package/src/structures/internal/TtscBuildOptions.ts +38 -14
  1975. package/src/structures/internal/TtscBuildResult.ts +74 -4
  1976. package/src/structures/internal/TtscCommonOptions.ts +59 -14
  1977. package/src/structures/internal/TtscSingleFileEmitOptions.ts +55 -5
  1978. package/tools/gen_shims/main.go +124 -11
  1979. package/tools/gen_shims/package_load_admission_rejects_incomplete_results_test.go +61 -0
  1980. package/tools/gen_shims/private_field_support_preserves_upstream_layout_test.go +104 -0
  1981. package/tools/shim_audit/enum_generation_preserves_existing_family_members_test.go +182 -0
  1982. package/tools/shim_audit/enum_generation_refuses_removed_public_members_test.go +93 -0
  1983. package/tools/shim_audit/main.go +166 -31
  1984. package/tools/shim_audit/main_test.go +35 -0
  1985. package/tools/shim_audit/producer_exemptions_require_rationale_test.go +5 -0
  1986. package/tools/shim_audit/producer_surface_includes_exposed_methods_test.go +5 -0
  1987. package/tools/shim_audit/producer_surface_rejects_unproducible_reference_test.go +5 -0
  1988. package/tools/shim_audit/shim_dir_coverage_rejects_unregistered_shims_test.go +71 -0
  1989. package/utility/command.go +48 -0
  1990. package/utility/flags_gen.go +2 -2
  1991. package/utility/host.go +282 -66
  1992. package/utility/preamble_output.go +245 -0
  1993. package/utility/preamble_output_test.go +90 -0
  1994. package/utility/serve.go +61 -18
  1995. package/cmd/ttscgraph/serve_graph_snapshot_version_matches_typescript_client_test.go +0 -32
  1996. package/cmd/ttscgraph/serve_protocol_version_matches_the_typescript_client_test.go +0 -48
  1997. package/cmd/ttscgraph/serve_session_retries_failed_dump_test.go +0 -103
  1998. package/internal/graph/dump_schema_version_matches_the_typescript_client_test.go +0 -48
  1999. package/internal/graph/edge_kinds_names_every_declared_kind_test.go +0 -49
  2000. package/internal/graph/graph_kind_contracts_match_their_producers_test.go +0 -121
  2001. package/internal/lspserver/lsp_launcher_reload_directory_fingerprint_parity_windows_test.go +0 -94
  2002. package/internal/lspserver/lsp_project_diagnostics_resident_unsupported_falls_back_test.go +0 -123
  2003. package/lib/compiler/internal/paths.d.ts +0 -27
  2004. package/lib/compiler/internal/paths.js +0 -70
  2005. package/lib/compiler/internal/paths.js.map +0 -1
  2006. package/lib/compiler/internal/project/readConfigJson.d.ts +0 -30
  2007. package/lib/compiler/internal/project/readConfigJson.js +0 -208
  2008. package/lib/compiler/internal/project/readConfigJson.js.map +0 -1
  2009. package/lib/compiler/internal/residentCheckProcess.d.ts +0 -44
  2010. package/lib/compiler/internal/residentCheckProcess.js +0 -213
  2011. package/lib/compiler/internal/residentCheckProcess.js.map +0 -1
  2012. package/lib/compiler/internal/residentTransformProcess.d.ts +0 -65
  2013. package/lib/compiler/internal/residentTransformProcess.js +0 -330
  2014. package/lib/compiler/internal/residentTransformProcess.js.map +0 -1
  2015. package/lib/compiler/internal/resolveEmittedJavaScript.d.ts +0 -25
  2016. package/lib/compiler/internal/resolveEmittedJavaScript.js +0 -165
  2017. package/lib/compiler/internal/resolveEmittedJavaScript.js.map +0 -1
  2018. package/lib/compiler/internal/runBuild.d.ts +0 -152
  2019. package/lib/compiler/internal/runBuild.js +0 -1694
  2020. package/lib/compiler/internal/runBuild.js.map +0 -1
  2021. package/lib/compiler/internal/sharedHostHelpers.d.ts +0 -79
  2022. package/lib/compiler/internal/sharedHostHelpers.js +0 -134
  2023. package/lib/compiler/internal/sharedHostHelpers.js.map +0 -1
  2024. package/lib/flags/parser.d.ts +0 -97
  2025. package/lib/flags/parser.js +0 -293
  2026. package/lib/flags/parser.js.map +0 -1
  2027. package/lib/flags/schema.d.ts +0 -191
  2028. package/lib/flags/schema.js.map +0 -1
  2029. package/lib/internal/windowsDirectoryCaseSensitivity.d.ts +0 -10
  2030. package/lib/internal/windowsDirectoryCaseSensitivity.js +0 -34
  2031. package/lib/internal/windowsDirectoryCaseSensitivity.js.map +0 -1
  2032. package/lib/launcher/internal/commonJsExportMetadata.d.ts +0 -7
  2033. package/lib/launcher/internal/commonJsExportMetadata.js.map +0 -1
  2034. package/lib/launcher/internal/registerRuntimeHooks.js +0 -59
  2035. package/lib/launcher/internal/registerRuntimeHooks.js.map +0 -1
  2036. package/lib/launcher/internal/runTtscserver.d.ts +0 -35
  2037. package/lib/launcher/internal/runTtscserver.js +0 -660
  2038. package/lib/launcher/internal/runTtscserver.js.map +0 -1
  2039. package/lib/launcher/internal/runtimeHooks.d.ts +0 -198
  2040. package/lib/launcher/internal/runtimeHooks.js +0 -2579
  2041. package/lib/launcher/internal/runtimeHooks.js.map +0 -1
  2042. package/lib/launcher/internal/servedSourceMap.d.ts +0 -25
  2043. package/lib/launcher/internal/servedSourceMap.js +0 -164
  2044. package/lib/launcher/internal/servedSourceMap.js.map +0 -1
  2045. package/lib/launcher/internal/singleFileOutput.d.ts +0 -16
  2046. package/lib/launcher/internal/singleFileOutput.js +0 -103
  2047. package/lib/launcher/internal/singleFileOutput.js.map +0 -1
  2048. package/lib/launcher/internal/watchTopology.d.ts +0 -329
  2049. package/lib/launcher/internal/watchTopology.js.map +0 -1
  2050. package/lib/plugin/internal/buildSourcePlugin.d.ts +0 -298
  2051. package/lib/plugin/internal/buildSourcePlugin.js +0 -3086
  2052. package/lib/plugin/internal/buildSourcePlugin.js.map +0 -1
  2053. package/lib/plugin/internal/capabilityResolutionCache.d.ts +0 -76
  2054. package/lib/plugin/internal/capabilityResolutionCache.js +0 -224
  2055. package/lib/plugin/internal/capabilityResolutionCache.js.map +0 -1
  2056. package/lib/plugin/internal/descriptorProcessFailure.d.ts +0 -36
  2057. package/lib/plugin/internal/descriptorProcessFailure.js +0 -62
  2058. package/lib/plugin/internal/descriptorProcessFailure.js.map +0 -1
  2059. package/lib/plugin/internal/loadProjectPlugins.d.ts +0 -74
  2060. package/lib/plugin/internal/loadProjectPlugins.js +0 -2379
  2061. package/lib/plugin/internal/loadProjectPlugins.js.map +0 -1
  2062. package/src/compiler/internal/paths.ts +0 -68
  2063. package/src/compiler/internal/project/readConfigJson.ts +0 -209
  2064. package/src/compiler/internal/residentCheckProcess.ts +0 -259
  2065. package/src/compiler/internal/residentTransformProcess.ts +0 -406
  2066. package/src/compiler/internal/resolveEmittedJavaScript.ts +0 -197
  2067. package/src/compiler/internal/runBuild.ts +0 -2345
  2068. package/src/compiler/internal/sharedHostHelpers.ts +0 -154
  2069. package/src/flags/parser.ts +0 -459
  2070. package/src/internal/windowsDirectoryCaseSensitivity.ts +0 -33
  2071. package/src/launcher/internal/registerRuntimeHooks.ts +0 -68
  2072. package/src/launcher/internal/runTtscserver.ts +0 -841
  2073. package/src/launcher/internal/runtimeHooks.ts +0 -3197
  2074. package/src/launcher/internal/servedSourceMap.ts +0 -183
  2075. package/src/launcher/internal/singleFileOutput.ts +0 -133
  2076. package/src/plugin/internal/buildSourcePlugin.ts +0 -3990
  2077. package/src/plugin/internal/capabilityResolutionCache.ts +0 -305
  2078. package/src/plugin/internal/descriptorProcessFailure.ts +0 -69
  2079. package/src/plugin/internal/loadProjectPlugins.ts +0 -3044
  2080. package/tools/shim_audit/shim_dir_coverage_test.go +0 -25
  2081. /package/lib/{launcher/internal/registerRuntimeHooks.d.ts → compiler/internal/transformProjectWorker.d.ts} +0 -0
@@ -1,3990 +0,0 @@
1
- import {
2
- type SpawnSyncOptionsWithStringEncoding,
3
- type SpawnSyncReturns,
4
- type StdioOptions,
5
- spawn,
6
- spawnSync,
7
- } from "node:child_process";
8
- import crypto from "node:crypto";
9
- import fs from "node:fs";
10
- import { createRequire } from "node:module";
11
- import os from "node:os";
12
- import path from "node:path";
13
- import { fileURLToPath } from "node:url";
14
- import { Worker } from "node:worker_threads";
15
-
16
- import { captureProcessOutput } from "../../compiler/internal/captureProcessOutput";
17
- import { findNearestGoMod } from "../../compiler/internal/paths";
18
- import { createCanonicalTempDirectory } from "../../internal/createCanonicalTempDirectory";
19
-
20
- const GO_MOD_SEARCH_MAX_DEPTH = 3;
21
- const TTSC_GO_MODULE_PATH = "github.com/samchon/ttsc/packages/ttsc";
22
- const TSGO_GO_MODULE_PATH = "github.com/microsoft/typescript-go";
23
-
24
- const PRUNE_DIRS = new Set(["node_modules", ".git", ".ttsc"]);
25
- const GENERATED_WORKSPACE_FILES = new Set(["go.work", "go.work.sum"]);
26
-
27
- // Go build environment values that can change the produced binary or decide
28
- // whether `go build` succeeds. Hashed into the plugin cache key so target,
29
- // build-tag, cgo, FIPS, and external-link variants never collide.
30
- const GO_BUILD_ENV_KEYS: readonly string[] = [
31
- "GOOS",
32
- "GOARCH",
33
- "GOAMD64",
34
- "GOARM",
35
- "GOARM64",
36
- "GO386",
37
- "GOMIPS",
38
- "GOMIPS64",
39
- "GOPPC64",
40
- "GORISCV64",
41
- "GOWASM",
42
- "GOFLAGS",
43
- "GOEXPERIMENT",
44
- "GOFIPS140",
45
- "GO_EXTLINK_ENABLED",
46
- "GCCGO",
47
- "GCCGOTOOLDIR",
48
- "CGO_ENABLED",
49
- "AR",
50
- "CC",
51
- "CXX",
52
- "FC",
53
- "PKG_CONFIG",
54
- "CGO_CFLAGS",
55
- "CGO_CFLAGS_ALLOW",
56
- "CGO_CFLAGS_DISALLOW",
57
- "CGO_CPPFLAGS",
58
- "CGO_CPPFLAGS_ALLOW",
59
- "CGO_CPPFLAGS_DISALLOW",
60
- "CGO_CXXFLAGS",
61
- "CGO_CXXFLAGS_ALLOW",
62
- "CGO_CXXFLAGS_DISALLOW",
63
- "CGO_FFLAGS",
64
- "CGO_FFLAGS_ALLOW",
65
- "CGO_FFLAGS_DISALLOW",
66
- "CGO_LDFLAGS",
67
- "CGO_LDFLAGS_ALLOW",
68
- "CGO_LDFLAGS_DISALLOW",
69
- "GOTOOLCHAIN",
70
- "GOROOT",
71
- ];
72
- const GO_BUILD_COMMAND_ENV_KEYS = new Set([
73
- "AR",
74
- "CC",
75
- "CXX",
76
- "FC",
77
- "GCCGO",
78
- "PKG_CONFIG",
79
- ]);
80
- const EXTERNAL_GO_BUILD_ENV_KEYS: readonly string[] = [
81
- "CPATH",
82
- "C_INCLUDE_PATH",
83
- "CPLUS_INCLUDE_PATH",
84
- "DYLD_LIBRARY_PATH",
85
- "INCLUDE",
86
- "LD_LIBRARY_PATH",
87
- "LIB",
88
- "LIBRARY_PATH",
89
- "LIBPATH",
90
- "MACOSX_DEPLOYMENT_TARGET",
91
- "OBJC_INCLUDE_PATH",
92
- "PKG_CONFIG_ALLOW_SYSTEM_CFLAGS",
93
- "PKG_CONFIG_ALLOW_SYSTEM_LIBS",
94
- "PKG_CONFIG_LIBDIR",
95
- "PKG_CONFIG_PATH",
96
- "PKG_CONFIG_SYSROOT_DIR",
97
- "PKG_CONFIG_TOP_BUILD_DIR",
98
- "SDKROOT",
99
- ];
100
- const CONTRIBUTIONS_FILE_NAME = "ttsc_contributions.go";
101
- const CONTRIB_DIRNAME = "contrib";
102
- // A cold source-plugin build is a multi-second-to-minutes `go build`. When a
103
- // program fans out into many processes (a `pnpm -r` running several suites in
104
- // parallel, a benchmark, a worker pool), each inherits the same cold cache and
105
- // would otherwise launch its own full build of the SAME cache key at the same
106
- // instant. The atomic lock below lets one process build while the rest poll for
107
- // its published binary, so the toolchain runs once per cache key instead of N
108
- // times. A waiter steals an abandoned lock (builder crashed) after this timeout
109
- // so a fan-out never wedges; it matches the dependency-build lock in
110
- // runtimeHooks.ts.
111
- const PLUGIN_BUILD_LOCK_STEAL_MS = 600_000;
112
- const PLUGIN_BUILD_LOCK_POLL_MS = 50;
113
- const PLUGIN_BUILD_LOCK_LEGACY_STALE_MS = 30_000;
114
- const PLUGIN_BUILD_LOCK_STATUS_MS = 30_000;
115
- const PLUGIN_BUILD_LOCK_OWNER_FILE = "owner.json";
116
- const PLUGIN_BUILD_LOCK_PROTOCOL_FILE = "protocol-v2";
117
- const PLUGIN_BUILD_LOCK_GENERATION_FILE = "generation";
118
- const PLUGIN_BUILD_LOCK_LEGACY_FENCE_DIR = "legacy-generation";
119
- const PLUGIN_BUILD_LOCK_LEGACY_FENCE_RECORD = "fence.json";
120
- const PLUGIN_BUILD_LOCK_CURRENT_DIR = "current";
121
- const PLUGIN_BUILD_LOCK_RETIRED_DIR = "retired";
122
- const PLUGIN_BUILD_LOCK_V2_SUFFIX = ".v2";
123
- const PLUGIN_BUILD_LOCK_PROTOCOL = "ttsc-plugin-build-lock-v2\n";
124
- // The default cache lives INSIDE the workspace, at
125
- // `<workspaceRoot>/node_modules/.cache/ttsc`, so `rm -rf node_modules` (or
126
- // deleting the repo) reclaims every compiled plugin binary and Go object file.
127
- // This is the `find-cache-dir` convention (Babel, webpack, ESLint, Nuxt, …): a
128
- // disposable build cache under `node_modules/.cache/<tool>`. ttsc keeps NO
129
- // global (`~/.cache`) cache — a machine-wide cache silently grew to hundreds of
130
- // GB across tsgo/plugin version bumps, so it was removed outright. See
131
- // resolveSourceBuildCacheRoot for the (override → workspace-local) priority.
132
- const NODE_MODULES_DIRNAME = "node_modules";
133
- const LOCAL_CACHE_PARENT_DIRNAME = ".cache";
134
- const TTSC_CACHE_DIRNAME = "ttsc";
135
- const PLUGIN_CACHE_DIRNAME = "plugins";
136
- const GO_BUILD_CACHE_DIRNAME = "go-build";
137
- // Directories whose presence marks a monorepo/workspace root, so every package
138
- // in the workspace shares ONE cache and a plugin builds once, not once per
139
- // package. `package.json` with a `workspaces` field (yarn/npm/bun) is checked
140
- // separately in isWorkspaceRootDir.
141
- const WORKSPACE_ROOT_MARKER_FILES: readonly string[] = ["pnpm-workspace.yaml"];
142
- const CACHE_LAST_USED_FILE = ".last-used";
143
- const CACHE_GC_MARKER_FILE = ".gc-last-run";
144
- // The plugin binary cache is content-keyed, so a project that bumps tsgo/typia
145
- // many times leaves one stale entry per superseded key. An opportunistic GC
146
- // (once/day) evicts entries unused for 30 days and, past a 2 GB ceiling, the
147
- // least-recently-used down to 80%. It is scoped to the resolved cache root only
148
- // — ttsc never scans a shared or global location.
149
- const PLUGIN_CACHE_GC_INTERVAL_MS = 24 * 60 * 60 * 1000;
150
- const PLUGIN_CACHE_ENTRY_MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000;
151
- const PLUGIN_CACHE_MAX_BYTES = 2 * 1024 * 1024 * 1024;
152
- const PLUGIN_CACHE_TARGET_BYTES = Math.floor(PLUGIN_CACHE_MAX_BYTES * 0.8);
153
- const PLUGIN_CACHE_PROTECTED_AGE_MS = 60 * 60 * 1000;
154
-
155
- // Go's own object-cache trim is age-based and has no size ceiling. The default
156
- // ttsc-owned cache therefore keeps up to 8 GiB and trims oldest objects toward
157
- // 6 GiB. The newest target-sized set used within an hour remains protected so
158
- // crossing the ceiling cannot immediately force another cold build.
159
- const GO_BUILD_CACHE_GC_INTERVAL_MS = 24 * 60 * 60 * 1000;
160
- const GO_BUILD_CACHE_MAX_BYTES = 8 * 1024 * 1024 * 1024;
161
- const GO_BUILD_CACHE_TARGET_BYTES = 6 * 1024 * 1024 * 1024;
162
- const GO_BUILD_CACHE_PROTECTED_AGE_MS = 60 * 60 * 1000;
163
- const GO_BUILD_CACHE_GC_MARKER_FILE = ".ttsc-gc";
164
- const GO_BUILD_CACHE_LEASE_DIR = ".ttsc-build-leases";
165
- const GO_BUILD_CACHE_MAINTENANCE_DIR = ".ttsc-maintenance";
166
- const GO_BUILD_CACHE_COORDINATION_STALE_MS = 60 * 60 * 1000;
167
- const GO_BUILD_CACHE_MAINTENANCE_STALE_MS = 60 * 1000;
168
- const GO_BUILD_CACHE_COORDINATION_CLOCK_SKEW_MS = 5 * 60 * 1000;
169
- const GO_BUILD_CACHE_COORDINATION_HEARTBEAT_MS = 5_000;
170
- const GO_BUILD_CACHE_COORDINATION_POLL_MS = 25;
171
- // Go amortizes cache-hit mtime writes over one hour. An object used inside
172
- // ttsc's one-hour protection window may therefore still carry an mtime almost
173
- // one additional hour old.
174
- const GO_BUILD_CACHE_ACCESS_MTIME_GRANULARITY_MS = 60 * 60 * 1000;
175
-
176
- /** One contributor's resolved Go source plus its target sub-package name. */
177
- export interface ITtscBuildContributor {
178
- /** Sub-package suffix: scratch lands at `<host>/contrib/<name>/`. */
179
- name: string;
180
- /** Absolute path to the contributor's source directory. */
181
- source: string;
182
- }
183
-
184
- /** Source-plugin cache locations resolved for one ttsc invocation. */
185
- export interface ITtscSourceBuildCachePaths {
186
- /** Root directory containing all ttsc-owned source build caches. */
187
- root: string;
188
- /** Directory containing content-addressed compiled plugin binaries. */
189
- pluginRoot: string;
190
- /** Directory passed to Go as `GOCACHE` for source-plugin builds. */
191
- goBuildRoot: string;
192
- /** How `goBuildRoot` was selected. */
193
- goBuildRootSource: "ttsc-cache" | "TTSC_GO_CACHE_DIR" | "GOCACHE";
194
- }
195
-
196
- /** Synchronous filesystem reads used to fingerprint external Go toolchains. */
197
- export interface SourceBuildFilesystemOperations {
198
- readFile(location: string): Buffer;
199
- }
200
-
201
- const DEFAULT_SOURCE_BUILD_FILESYSTEM: SourceBuildFilesystemOperations =
202
- Object.freeze({
203
- readFile: (location: string) => fs.readFileSync(location),
204
- });
205
-
206
- /**
207
- * Build one Go source plugin into a cached executable.
208
- *
209
- * `opts.env` is the effective environment for this build — the caller merges `{
210
- * ...process.env, ...context.env }` so a programmatic `TtscCompiler` instance
211
- * can pin its own Go toolchain (`TTSC_GO_BINARY`), Go build cache
212
- * (`TTSC_GO_CACHE_DIR`), and Go build variables (`GOFLAGS`, `CGO_*`, …) without
213
- * mutating the shared `process.env`. CLI callers omit it and inherit
214
- * `process.env`, so ambient behavior is unchanged.
215
- */
216
- export function buildSourcePlugin(opts: {
217
- source: string;
218
- pluginName: string;
219
- baseDir: string;
220
- cacheDir?: string;
221
- contributors?: readonly ITtscBuildContributor[];
222
- env?: NodeJS.ProcessEnv;
223
- filesystem?: Partial<SourceBuildFilesystemOperations>;
224
- label?: string;
225
- overlayDirs?: readonly string[];
226
- quiet?: boolean;
227
- ttscVersion: string;
228
- tsgoVersion: string;
229
- }): string {
230
- const env = opts.env ?? process.env;
231
- const { dir, entry, source } = resolveSourceBuildTarget(opts);
232
- const overlayDirs = [...(opts.overlayDirs ?? findTtscOverlayDirs())].sort();
233
- const contributors = opts.contributors ?? [];
234
- const compiler = resolveGoCompiler(env);
235
- const goBinary = resolveGoToolForBuild(compiler.binary, env, dir);
236
- ensureExecutableGoToolchain(goBinary, compiler.bundled);
237
- const key = computeCacheKey({
238
- contributors,
239
- dir,
240
- entry,
241
- env,
242
- filesystem: opts.filesystem,
243
- goBinary,
244
- overlayDirs,
245
- ttscVersion: opts.ttscVersion,
246
- tsgoVersion: opts.tsgoVersion,
247
- });
248
- const paths = resolveSourceBuildCachePaths(opts.baseDir, opts.cacheDir, env);
249
- const managePluginCache = !opts.cacheDir && !env.TTSC_CACHE_DIR;
250
- const manageGoBuildCache = shouldManageSourceBuildCaches(
251
- paths,
252
- opts.cacheDir,
253
- env,
254
- );
255
- const pluginRoot = managePluginCache
256
- ? canonicalPluginCacheRoot(paths.pluginRoot)
257
- : paths.pluginRoot;
258
- maybePruneSourceBuildCaches({ ...paths, pluginRoot }, opts.cacheDir, env);
259
- const cacheDir = managePluginCache
260
- ? canonicalPluginCacheEntry(pluginRoot, key)
261
- : path.join(pluginRoot, key);
262
- const binaryName = process.platform === "win32" ? "plugin.exe" : "plugin";
263
- const binaryPath = path.join(cacheDir, binaryName);
264
- if (fs.existsSync(binaryPath)) {
265
- touchCacheEntry(cacheDir);
266
- return binaryPath;
267
- }
268
- fs.mkdirSync(cacheDir, { recursive: true });
269
- const label = opts.label ?? "source plugin";
270
- const quiet = opts.quiet === true;
271
- const built = buildUnderPluginLock(
272
- cacheDir,
273
- binaryPath,
274
- { label, pluginName: opts.pluginName, quiet },
275
- () =>
276
- compileSourcePlugin({
277
- binaryPath,
278
- cacheDir,
279
- contributors,
280
- dir,
281
- entry,
282
- env,
283
- goBinary,
284
- normalizeGoToolPermissions: compiler.bundled,
285
- key,
286
- label,
287
- goBuildCacheRoot: paths.goBuildRoot,
288
- manageGoBuildCache,
289
- overlayDirs,
290
- pluginName: opts.pluginName,
291
- quiet,
292
- source,
293
- }),
294
- );
295
- if (managePluginCache) {
296
- // The pre-build daily pass cannot account for the binary this cold build
297
- // just published. Enforce the size policy after publication, once this
298
- // process has released its per-key build lock.
299
- prunePluginCacheRoot(pluginRoot, {
300
- force: true,
301
- protectedEntries: [cacheDir],
302
- });
303
- }
304
- return built;
305
- }
306
-
307
- /** Run the actual `go build` and publish the binary; assumes the lock is held. */
308
- function compileSourcePlugin(opts: {
309
- binaryPath: string;
310
- cacheDir: string;
311
- contributors: readonly ITtscBuildContributor[];
312
- dir: string;
313
- entry: string;
314
- env: NodeJS.ProcessEnv;
315
- goBinary: string;
316
- goBuildCacheRoot: string;
317
- manageGoBuildCache: boolean;
318
- normalizeGoToolPermissions: boolean;
319
- key: string;
320
- label: string;
321
- overlayDirs: readonly string[];
322
- pluginName: string;
323
- quiet: boolean;
324
- source: string;
325
- }): string {
326
- if (!opts.quiet) {
327
- const extra =
328
- opts.contributors.length === 0
329
- ? ""
330
- : ` + ${opts.contributors.length} contributor(s): ${opts.contributors
331
- .map((c) => c.name)
332
- .join(", ")}`;
333
- process.stderr.write(
334
- `ttsc: building ${opts.label} "${opts.pluginName}" from ${opts.source}${extra} ` +
335
- `(this runs once per cache key and can take several minutes on a cold Go cache) ` +
336
- `See https://ttsc.dev/docs/ttsc/compile#plugin-cache to persist it across builds.\n`,
337
- );
338
- }
339
-
340
- const scratchDir = createCanonicalTempDirectory(`ttsc-plugin-${opts.key}-`);
341
- try {
342
- materializeScratchDir(opts.dir, scratchDir);
343
- const goModReader = createGoModReader(
344
- opts.goBinary,
345
- opts.pluginName,
346
- opts.env,
347
- );
348
- if (opts.contributors.length > 0) {
349
- mergeContributors({
350
- contributors: opts.contributors,
351
- entry: opts.entry,
352
- goModReader,
353
- pluginName: opts.pluginName,
354
- scratchDir,
355
- });
356
- }
357
- writeGoWork(
358
- scratchDir,
359
- opts.overlayDirs,
360
- opts.goBinary,
361
- opts.pluginName,
362
- opts.env,
363
- );
364
- const scratchBinaryName =
365
- process.platform === "win32" ? ".ttsc-plugin.exe" : ".ttsc-plugin";
366
- let attemptedGoBuildCacheRoot: string | undefined;
367
- try {
368
- withGoBuildCacheLease(
369
- opts.goBuildCacheRoot,
370
- opts.manageGoBuildCache,
371
- (goBuildCacheRoot) => {
372
- attemptedGoBuildCacheRoot = goBuildCacheRoot;
373
- runGoBuild(
374
- scratchDir,
375
- opts.entry,
376
- scratchBinaryName,
377
- opts.pluginName,
378
- opts.goBinary,
379
- goBuildCacheRoot,
380
- opts.env,
381
- opts.normalizeGoToolPermissions,
382
- );
383
- },
384
- );
385
- } finally {
386
- if (opts.manageGoBuildCache && attemptedGoBuildCacheRoot !== undefined) {
387
- // The daily pre-build pass cannot see objects the build is about to
388
- // add, including objects left behind by a failed compile. Enforce the
389
- // size policy after every actual cold-build attempt so churn cannot
390
- // grow the cache unchecked behind a fresh daily marker.
391
- pruneGoBuildCacheRoot(attemptedGoBuildCacheRoot, { force: true });
392
- }
393
- }
394
- const builtBinary = path.join(scratchDir, scratchBinaryName);
395
- publishBuiltBinary(builtBinary, opts.binaryPath);
396
- touchCacheEntry(opts.cacheDir);
397
- return opts.binaryPath;
398
- } finally {
399
- fs.rmSync(scratchDir, { recursive: true, force: true });
400
- }
401
- }
402
-
403
- /**
404
- * Build a source plugin while holding an exclusive cross-process lock for its
405
- * cache key, so concurrent fan-out (parallel suites, a benchmark, a worker
406
- * pool) runs the `go build` once instead of once per process.
407
- *
408
- * `<cacheDir>.lock.v2` is a persistent coordination directory. The adjacent
409
- * `<cacheDir>.lock` path remains reserved for legacy holders and is never
410
- * reused for a v2 generation: an old holder or stale legacy reclaimer can
411
- * therefore remove only the legacy path, never a v2 successor. A contender
412
- * writes a non-empty candidate and atomically renames it to `current`; only one
413
- * rename wins. The winner builds and publishes while every loser polls and
414
- * reuses the resulting binary. A loser distinguishes two ways a generation
415
- * stops blocking:
416
- *
417
- * - `released`: the holder retired `current` itself — it published, or its build
418
- * threw and its `finally` freed the key. The loser simply retries the
419
- * ordinary acquisition; nothing is stale and nothing is reported.
420
- * - `abandoned`: `current` still exists but its owner is provably dead, it is an
421
- * old metadata-less legacy lock, or the wait budget
422
- * (`PLUGIN_BUILD_LOCK_STEAL_MS`) expired. Only then does the loser report and
423
- * retire precisely that generation before retrying.
424
- *
425
- * Retired generations remain as non-empty tombstones. Release and reclaim both
426
- * rename `current` to the observed generation's deterministic tombstone path.
427
- * Once generation A is retired, a stale observer or old finalizer for A cannot
428
- * rename successor B there because replacing the non-empty tombstone fails
429
- * atomically. `publishBuiltBinary`'s atomic rename remains defense in depth.
430
- */
431
- function buildUnderPluginLock(
432
- cacheDir: string,
433
- binaryPath: string,
434
- lockInfo: {
435
- label: string;
436
- pluginName: string;
437
- quiet: boolean;
438
- },
439
- build: () => string,
440
- ): string {
441
- const lockDir = `${cacheDir}.lock`;
442
- for (;;) {
443
- if (fs.existsSync(binaryPath)) {
444
- touchCacheEntry(cacheDir);
445
- return binaryPath;
446
- }
447
- let lease: PluginBuildLockLease | null;
448
- try {
449
- lease = acquirePluginBuildLock(lockDir);
450
- } catch {
451
- // An unusable coordination directory must not silently skip the build.
452
- // Atomic publication still preserves binary integrity.
453
- return build();
454
- }
455
- if (lease === null) {
456
- const waited = waitForPluginBinary({
457
- binaryPath,
458
- lockDir,
459
- lockInfo,
460
- timeoutMs: PLUGIN_BUILD_LOCK_STEAL_MS,
461
- });
462
- if (waited.outcome === "published") {
463
- touchCacheEntry(cacheDir);
464
- return binaryPath;
465
- }
466
- if (waited.outcome === "abandoned") {
467
- // Retire only the generation that produced this observation. Losing
468
- // the rename race means another waiter (or the holder's normal
469
- // finalizer) already made progress, so do not report a stale result as
470
- // an abandonment.
471
- if (reclaimPluginBuildLock(lockDir, waited.fence)) {
472
- reportPluginLockSteal(lockDir, binaryPath, lockInfo, waited.reason);
473
- }
474
- }
475
- // "released" needs no repair: the holder freed the key normally (its
476
- // build published or failed), so retry the ordinary atomic acquisition.
477
- // Reporting a steal or force-removing the path here would misclassify a
478
- // routine handoff as abandonment (issue #421).
479
- continue;
480
- }
481
- try {
482
- // Re-check under the lock: a previous holder may have just published.
483
- if (fs.existsSync(binaryPath)) {
484
- touchCacheEntry(cacheDir);
485
- return binaryPath;
486
- }
487
- return build();
488
- } finally {
489
- releasePluginBuildLock(lockDir, lease);
490
- }
491
- }
492
- }
493
-
494
- /** Opaque identity of one observed lock generation. */
495
- export type PluginBuildLockFence = {
496
- protocol: "legacy" | "v2";
497
- generation: string;
498
- };
499
-
500
- /** Ownership token returned only to the process that acquired `current`. */
501
- export type PluginBuildLockLease = {
502
- protocol: "v2";
503
- generation: string;
504
- };
505
-
506
- /**
507
- * Atomically acquire the current generation in a v2 coordination directory.
508
- *
509
- * A non-empty candidate is renamed to `current`. Directory rename cannot
510
- * replace a non-empty `current`, so exactly one contender wins without an
511
- * empty-owner publication window. `null` means either another v2 holder won or
512
- * the path is a legacy lock that must be observed before it can be reclaimed.
513
- *
514
- * Exported for deterministic multi-process tests.
515
- */
516
- export function acquirePluginBuildLock(
517
- lockDir: string,
518
- ): PluginBuildLockLease | null {
519
- // A legacy holder owns the old path. Never publish v2 ownership into that
520
- // deletable namespace; wait until the legacy generation is released or
521
- // reclaimed, then use the orthogonal persistent v2 directory.
522
- if (pluginBuildLockPathExists(lockDir)) {
523
- return null;
524
- }
525
- const protocolDir = pluginBuildLockProtocolDir(lockDir);
526
- ensurePluginBuildLockProtocol(protocolDir);
527
- // Close the initialization window as far as the legacy protocol permits. A
528
- // legacy holder that appeared while v2 was initialized still blocks this
529
- // acquisition. (A legacy executable cannot provide a true cross-path CAS.)
530
- if (pluginBuildLockPathExists(lockDir)) {
531
- return null;
532
- }
533
-
534
- const generation = crypto.randomBytes(16).toString("hex");
535
- const candidateDir = path.join(protocolDir, `candidate-${generation}`);
536
- fs.mkdirSync(candidateDir);
537
- try {
538
- fs.writeFileSync(
539
- path.join(candidateDir, PLUGIN_BUILD_LOCK_GENERATION_FILE),
540
- `${generation}\n`,
541
- { encoding: "utf8", flag: "wx" },
542
- );
543
- writePluginBuildLockOwner(candidateDir, generation);
544
- try {
545
- fs.renameSync(
546
- candidateDir,
547
- path.join(protocolDir, PLUGIN_BUILD_LOCK_CURRENT_DIR),
548
- );
549
- } catch (error) {
550
- if (
551
- isMissingPathError(error) ||
552
- isRenameDestinationOccupied(
553
- error,
554
- path.join(protocolDir, PLUGIN_BUILD_LOCK_CURRENT_DIR),
555
- )
556
- ) {
557
- return null;
558
- }
559
- throw error;
560
- }
561
- return { protocol: "v2", generation };
562
- } finally {
563
- // The candidate name contains this process's random generation and can
564
- // never alias `current` or another contender's candidate.
565
- fs.rmSync(candidateDir, { force: true, recursive: true });
566
- }
567
- }
568
-
569
- /** Retire a held generation during the holder's `finally`. */
570
- export function releasePluginBuildLock(
571
- lockDir: string,
572
- lease: PluginBuildLockLease,
573
- ): boolean {
574
- return retireV2PluginBuildLock(
575
- pluginBuildLockProtocolDir(lockDir),
576
- lease.generation,
577
- );
578
- }
579
-
580
- /**
581
- * Retire exactly the generation carried by an abandoned observation.
582
- *
583
- * Exported for deterministic multi-process tests.
584
- */
585
- export function reclaimPluginBuildLock(
586
- lockDir: string,
587
- fence: PluginBuildLockFence,
588
- ): boolean {
589
- if (fence.protocol === "v2") {
590
- return retireV2PluginBuildLock(
591
- pluginBuildLockProtocolDir(lockDir),
592
- fence.generation,
593
- );
594
- }
595
- return retireLegacyPluginBuildLock(lockDir, fence.generation);
596
- }
597
-
598
- function pluginBuildLockProtocolDir(lockDir: string): string {
599
- return `${lockDir}${PLUGIN_BUILD_LOCK_V2_SUFFIX}`;
600
- }
601
-
602
- function ensurePluginBuildLockProtocol(protocolDir: string): void {
603
- if (isPluginBuildLockProtocolV2(protocolDir)) {
604
- return;
605
- }
606
-
607
- const generation = crypto.randomBytes(16).toString("hex");
608
- const candidateDir = `${protocolDir}.candidate-${generation}`;
609
- fs.mkdirSync(candidateDir);
610
- try {
611
- fs.mkdirSync(path.join(candidateDir, PLUGIN_BUILD_LOCK_RETIRED_DIR));
612
- fs.writeFileSync(
613
- path.join(candidateDir, PLUGIN_BUILD_LOCK_PROTOCOL_FILE),
614
- PLUGIN_BUILD_LOCK_PROTOCOL,
615
- { encoding: "utf8", flag: "wx" },
616
- );
617
- try {
618
- fs.renameSync(candidateDir, protocolDir);
619
- } catch (error) {
620
- if (
621
- isRenameDestinationOccupied(error, protocolDir) &&
622
- isPluginBuildLockProtocolV2(protocolDir)
623
- ) {
624
- return;
625
- }
626
- throw error;
627
- }
628
- } finally {
629
- fs.rmSync(candidateDir, { force: true, recursive: true });
630
- }
631
- }
632
-
633
- function isPluginBuildLockProtocolV2(lockDir: string): boolean {
634
- try {
635
- const stats = fs.lstatSync(lockDir);
636
- if (!stats.isDirectory() || stats.isSymbolicLink()) return false;
637
- return (
638
- fs.readFileSync(
639
- path.join(lockDir, PLUGIN_BUILD_LOCK_PROTOCOL_FILE),
640
- "utf8",
641
- ) === PLUGIN_BUILD_LOCK_PROTOCOL
642
- );
643
- } catch {
644
- return false;
645
- }
646
- }
647
-
648
- function retireV2PluginBuildLock(lockDir: string, generation: string): boolean {
649
- if (!isPluginBuildLockGeneration(generation)) return false;
650
- const retiredDir = path.join(lockDir, PLUGIN_BUILD_LOCK_RETIRED_DIR);
651
- try {
652
- fs.mkdirSync(retiredDir);
653
- } catch (error) {
654
- if ((error as NodeJS.ErrnoException).code !== "EEXIST") {
655
- if (isMissingPathError(error)) return false;
656
- throw error;
657
- }
658
- }
659
-
660
- const destination = path.join(retiredDir, generation);
661
- try {
662
- fs.renameSync(
663
- path.join(lockDir, PLUGIN_BUILD_LOCK_CURRENT_DIR),
664
- destination,
665
- );
666
- return true;
667
- } catch (error) {
668
- if (
669
- isMissingPathError(error) ||
670
- isRenameDestinationOccupied(error, destination)
671
- ) {
672
- return false;
673
- }
674
- throw error;
675
- }
676
- }
677
-
678
- function retireLegacyPluginBuildLock(
679
- lockDir: string,
680
- generation: string,
681
- ): boolean {
682
- if (!isPluginBuildLockGeneration(generation)) return false;
683
- const captured = readLegacyPluginBuildLockFence(
684
- path.join(lockDir, PLUGIN_BUILD_LOCK_LEGACY_FENCE_DIR),
685
- );
686
- if (captured?.fence.generation !== generation) {
687
- return false;
688
- }
689
- const destination = `${lockDir}.retired-${generation}`;
690
- try {
691
- fs.renameSync(lockDir, destination);
692
- return true;
693
- } catch (error) {
694
- if (
695
- isMissingPathError(error) ||
696
- isRenameDestinationOccupied(error, destination)
697
- ) {
698
- return false;
699
- }
700
- throw error;
701
- }
702
- }
703
-
704
- function isMissingPathError(error: unknown): boolean {
705
- const code = (error as NodeJS.ErrnoException).code;
706
- return code === "ENOENT" || code === "ENOTDIR";
707
- }
708
-
709
- function isRenameDestinationOccupied(
710
- error: unknown,
711
- destination: string,
712
- ): boolean {
713
- const code = (error as NodeJS.ErrnoException).code;
714
- if (code === "EEXIST" || code === "ENOTEMPTY") {
715
- return true;
716
- }
717
- return (code === "EACCES" || code === "EPERM") && fs.existsSync(destination);
718
- }
719
-
720
- /**
721
- * Outcome of one waiting session on another process's plugin build lock.
722
- *
723
- * - `published`: the binary exists and can be reused.
724
- * - `released`: the observed generation no longer exists and no binary appeared —
725
- * the holder freed the key normally, so the caller should retry ordinary
726
- * acquisition without reporting or removing anything.
727
- * - `abandoned`: the lock still exists but is provably stale (dead owner, old
728
- * legacy lock) or the wait budget expired; the caller may report and retire
729
- * precisely the attached generation.
730
- *
731
- * Exported for unit tests.
732
- */
733
- export type PluginBinaryWaitResult =
734
- | { outcome: "published" }
735
- | { outcome: "released" }
736
- | {
737
- outcome: "abandoned";
738
- reason: string;
739
- fence: PluginBuildLockFence;
740
- };
741
-
742
- /**
743
- * Poll for the locked builder to publish its binary, up to `timeoutMs`.
744
- *
745
- * Exported for unit tests.
746
- */
747
- export function waitForPluginBinary(opts: {
748
- binaryPath: string;
749
- lockDir: string;
750
- lockInfo: {
751
- label: string;
752
- pluginName: string;
753
- quiet: boolean;
754
- };
755
- timeoutMs: number;
756
- }): PluginBinaryWaitResult {
757
- const startedAt = Date.now();
758
- let nextStatusAt = startedAt + PLUGIN_BUILD_LOCK_STATUS_MS;
759
- for (;;) {
760
- if (fs.existsSync(opts.binaryPath)) {
761
- return { outcome: "published" };
762
- }
763
- const now = Date.now();
764
- const lock = inspectPluginBuildLock(opts.lockDir, now);
765
- if (lock.state === "released") {
766
- // The holder retired its generation between the binary check above and
767
- // this observation. That is a normal release, not abandonment: prefer the
768
- // binary when it landed inside that window, otherwise hand the free key
769
- // back to the caller.
770
- return fs.existsSync(opts.binaryPath)
771
- ? { outcome: "published" }
772
- : { outcome: "released" };
773
- }
774
- if (lock.state === "abandoned") {
775
- return {
776
- outcome: "abandoned",
777
- reason: lock.reason,
778
- fence: lock.fence,
779
- };
780
- }
781
- if (now - startedAt > opts.timeoutMs) {
782
- return {
783
- outcome: "abandoned",
784
- reason: `timed out after ${formatDuration(now - startedAt)}`,
785
- fence: lock.fence,
786
- };
787
- }
788
- if (!opts.lockInfo.quiet && now >= nextStatusAt) {
789
- reportPluginLockWait({
790
- binaryPath: opts.binaryPath,
791
- elapsedMs: now - startedAt,
792
- lockDir: opts.lockDir,
793
- lockInfo: opts.lockInfo,
794
- owner: lock.owner,
795
- });
796
- nextStatusAt = now + PLUGIN_BUILD_LOCK_STATUS_MS;
797
- }
798
- sleepSync(PLUGIN_BUILD_LOCK_POLL_MS);
799
- }
800
- }
801
-
802
- function writePluginBuildLockOwner(
803
- generationDir: string,
804
- generation: string,
805
- ): void {
806
- fs.writeFileSync(
807
- path.join(generationDir, PLUGIN_BUILD_LOCK_OWNER_FILE),
808
- `${JSON.stringify(
809
- {
810
- generation,
811
- hostname: os.hostname(),
812
- pid: process.pid,
813
- startedAt: new Date().toISOString(),
814
- },
815
- null,
816
- 2,
817
- )}\n`,
818
- "utf8",
819
- );
820
- }
821
-
822
- /**
823
- * One observation of a plugin build lock directory's state.
824
- *
825
- * - `active`: the lock exists and its owner is alive (or cannot be disproven:
826
- * another host, no metadata but young). Keep waiting.
827
- * - `abandoned`: the lock still exists and the evidence says nobody will ever
828
- * release it — a same-host owner that is no longer running, or an old
829
- * metadata-less legacy lock. Retiring its fenced generation is justified.
830
- * - `released`: the observed generation no longer exists. In v2 the persistent
831
- * coordination root remains while `current` is absent. This is a routine
832
- * handoff, never an infinitely old abandoned lock (issue #421).
833
- *
834
- * Exported for unit tests.
835
- */
836
- export type PluginBuildLockObservation =
837
- | {
838
- state: "active";
839
- owner: string;
840
- fence: PluginBuildLockFence;
841
- }
842
- | {
843
- state: "abandoned";
844
- reason: string;
845
- fence: PluginBuildLockFence;
846
- }
847
- | { state: "released" };
848
-
849
- /**
850
- * Classify the current state of a plugin build lock directory.
851
- *
852
- * Exported for unit tests.
853
- */
854
- export function inspectPluginBuildLock(
855
- lockDir: string,
856
- now: number,
857
- ): PluginBuildLockObservation {
858
- const protocolDir = pluginBuildLockProtocolDir(lockDir);
859
- for (;;) {
860
- if (isPluginBuildLockProtocolV2(protocolDir)) {
861
- const v2 = inspectV2PluginBuildLock(protocolDir, now);
862
- if (v2.state !== "released") {
863
- return v2;
864
- }
865
- }
866
- const legacy = captureLegacyPluginBuildLockFence(lockDir);
867
- if (legacy !== null) {
868
- return inspectLegacyPluginBuildLock(lockDir, now, legacy);
869
- }
870
- if (pluginBuildLockAgeMs(lockDir, now) === null) {
871
- return { state: "released" };
872
- }
873
- // The path changed while its legacy fence was being captured. Re-observe
874
- // the replacement rather than attaching the old state to a new owner.
875
- }
876
- }
877
-
878
- function inspectV2PluginBuildLock(
879
- lockDir: string,
880
- now: number,
881
- ): PluginBuildLockObservation {
882
- const generationDir = path.join(lockDir, PLUGIN_BUILD_LOCK_CURRENT_DIR);
883
- const generation = readPluginBuildLockGeneration(generationDir);
884
- if (generation === null) {
885
- if (pluginBuildLockAgeMs(generationDir, now) === null) {
886
- return { state: "released" };
887
- }
888
- throw new Error(
889
- `ttsc plugin build lock has no valid ${PLUGIN_BUILD_LOCK_GENERATION_FILE}: ${generationDir}`,
890
- );
891
- }
892
- const fence: PluginBuildLockFence = { protocol: "v2", generation };
893
- const owner = readPluginBuildLockOwner(generationDir);
894
- if (owner !== null) {
895
- const label = describePluginBuildLockOwner(owner);
896
- if (isLocalHostName(owner.hostname) && !isProcessAlive(owner.pid)) {
897
- return {
898
- state: "abandoned",
899
- reason: `${label} is no longer running`,
900
- fence,
901
- };
902
- }
903
- return {
904
- state: "active",
905
- owner: label,
906
- fence,
907
- };
908
- }
909
-
910
- const ageMs = pluginBuildLockAgeMs(generationDir, now);
911
- if (ageMs === null) {
912
- return { state: "released" };
913
- }
914
- if (ageMs > PLUGIN_BUILD_LOCK_LEGACY_STALE_MS) {
915
- return {
916
- state: "abandoned",
917
- reason:
918
- `lock generation has no ${PLUGIN_BUILD_LOCK_OWNER_FILE} and is ` +
919
- `${formatDuration(ageMs)} old`,
920
- fence,
921
- };
922
- }
923
- return {
924
- state: "active",
925
- owner: `lock generation with no ${PLUGIN_BUILD_LOCK_OWNER_FILE}`,
926
- fence,
927
- };
928
- }
929
-
930
- interface LegacyPluginBuildLockFence {
931
- fence: PluginBuildLockFence;
932
- legacyMtimeMs: number;
933
- }
934
-
935
- function inspectLegacyPluginBuildLock(
936
- lockDir: string,
937
- now: number,
938
- legacy: LegacyPluginBuildLockFence,
939
- ): PluginBuildLockObservation {
940
- const owner = readPluginBuildLockOwner(lockDir);
941
- if (owner !== null) {
942
- const label = describePluginBuildLockOwner(owner);
943
- if (isLocalHostName(owner.hostname) && !isProcessAlive(owner.pid)) {
944
- return {
945
- state: "abandoned",
946
- reason: `${label} is no longer running`,
947
- fence: legacy.fence,
948
- };
949
- }
950
- return {
951
- state: "active",
952
- owner: label,
953
- fence: legacy.fence,
954
- };
955
- }
956
-
957
- const ageMs = Math.max(0, now - legacy.legacyMtimeMs);
958
- if (ageMs > PLUGIN_BUILD_LOCK_LEGACY_STALE_MS) {
959
- return {
960
- state: "abandoned",
961
- reason:
962
- `legacy lock has no ${PLUGIN_BUILD_LOCK_OWNER_FILE} and is ` +
963
- `${formatDuration(ageMs)} old`,
964
- fence: legacy.fence,
965
- };
966
- }
967
- return {
968
- state: "active",
969
- owner: `legacy lock with no ${PLUGIN_BUILD_LOCK_OWNER_FILE}`,
970
- fence: legacy.fence,
971
- };
972
- }
973
-
974
- function captureLegacyPluginBuildLockFence(
975
- lockDir: string,
976
- ): LegacyPluginBuildLockFence | null {
977
- if (isPluginBuildLockProtocolV2(lockDir)) {
978
- return null;
979
- }
980
-
981
- let legacyMtimeMs: number;
982
- try {
983
- legacyMtimeMs = fs.statSync(lockDir).mtimeMs;
984
- } catch (error) {
985
- if (isMissingPathError(error)) return null;
986
- throw error;
987
- }
988
-
989
- const fenceDir = path.join(lockDir, PLUGIN_BUILD_LOCK_LEGACY_FENCE_DIR);
990
- let captured = readLegacyPluginBuildLockFence(fenceDir);
991
- if (captured === null) {
992
- const generation = crypto.randomBytes(16).toString("hex");
993
- // Keep candidates beside the legacy lock. Creating one inside `lockDir`
994
- // would advance its mtime before a contender publishes the shared fence;
995
- // a concurrent contender could then record an old lock as freshly created.
996
- const candidateDir = `${lockDir}.legacy-candidate-${generation}`;
997
- try {
998
- fs.mkdirSync(candidateDir);
999
- fs.writeFileSync(
1000
- path.join(candidateDir, PLUGIN_BUILD_LOCK_LEGACY_FENCE_RECORD),
1001
- `${JSON.stringify({ generation, legacyMtimeMs })}\n`,
1002
- "utf8",
1003
- );
1004
- try {
1005
- fs.renameSync(candidateDir, fenceDir);
1006
- captured = {
1007
- fence: { protocol: "legacy", generation },
1008
- legacyMtimeMs,
1009
- };
1010
- } catch (error) {
1011
- if (isRenameDestinationOccupied(error, fenceDir)) {
1012
- captured = readLegacyPluginBuildLockFence(fenceDir);
1013
- } else if (isMissingPathError(error)) {
1014
- return null;
1015
- } else {
1016
- throw error;
1017
- }
1018
- }
1019
- } catch (error) {
1020
- if (isMissingPathError(error)) {
1021
- return null;
1022
- }
1023
- throw error;
1024
- } finally {
1025
- fs.rmSync(candidateDir, { force: true, recursive: true });
1026
- }
1027
- }
1028
- if (captured === null) {
1029
- throw new Error(`invalid legacy plugin build lock fence: ${fenceDir}`);
1030
- }
1031
-
1032
- // A stale observer can resume after the legacy holder released or another
1033
- // process retired the path. Confirm both the legacy layout and token after
1034
- // publication; v2 ownership is kept in the orthogonal sibling directory.
1035
- const confirmed = readLegacyPluginBuildLockFence(fenceDir);
1036
- if (
1037
- isPluginBuildLockProtocolV2(lockDir) ||
1038
- confirmed === null ||
1039
- confirmed.fence.generation !== captured.fence.generation
1040
- ) {
1041
- return null;
1042
- }
1043
- return captured;
1044
- }
1045
-
1046
- function readLegacyPluginBuildLockFence(
1047
- fenceDir: string,
1048
- ): LegacyPluginBuildLockFence | null {
1049
- try {
1050
- const parsed = JSON.parse(
1051
- fs.readFileSync(
1052
- path.join(fenceDir, PLUGIN_BUILD_LOCK_LEGACY_FENCE_RECORD),
1053
- "utf8",
1054
- ),
1055
- ) as Record<string, unknown>;
1056
- if (
1057
- !isPluginBuildLockGeneration(parsed.generation) ||
1058
- typeof parsed.legacyMtimeMs !== "number" ||
1059
- !Number.isFinite(parsed.legacyMtimeMs) ||
1060
- parsed.legacyMtimeMs < 0
1061
- ) {
1062
- return null;
1063
- }
1064
- return {
1065
- fence: { protocol: "legacy", generation: parsed.generation },
1066
- legacyMtimeMs: parsed.legacyMtimeMs,
1067
- };
1068
- } catch {
1069
- return null;
1070
- }
1071
- }
1072
-
1073
- function readPluginBuildLockGeneration(generationDir: string): string | null {
1074
- try {
1075
- const generation = fs
1076
- .readFileSync(
1077
- path.join(generationDir, PLUGIN_BUILD_LOCK_GENERATION_FILE),
1078
- "utf8",
1079
- )
1080
- .trim();
1081
- return isPluginBuildLockGeneration(generation) ? generation : null;
1082
- } catch {
1083
- return null;
1084
- }
1085
- }
1086
-
1087
- function isPluginBuildLockGeneration(value: unknown): value is string {
1088
- return typeof value === "string" && /^[0-9a-f]{32}$/.test(value);
1089
- }
1090
-
1091
- function readPluginBuildLockOwner(
1092
- lockDir: string,
1093
- ): { hostname: string; pid: number; startedAt?: string } | null {
1094
- try {
1095
- const parsed = JSON.parse(
1096
- fs.readFileSync(path.join(lockDir, PLUGIN_BUILD_LOCK_OWNER_FILE), "utf8"),
1097
- ) as Record<string, unknown>;
1098
- if (
1099
- typeof parsed.hostname !== "string" ||
1100
- !Number.isInteger(parsed.pid) ||
1101
- typeof parsed.pid !== "number" ||
1102
- parsed.pid <= 0
1103
- ) {
1104
- return null;
1105
- }
1106
- return {
1107
- hostname: parsed.hostname,
1108
- pid: parsed.pid,
1109
- startedAt:
1110
- typeof parsed.startedAt === "string" ? parsed.startedAt : undefined,
1111
- };
1112
- } catch {
1113
- return null;
1114
- }
1115
- }
1116
-
1117
- /**
1118
- * Age of an observed lock directory, or `null` when it no longer exists. The
1119
- * holder may have retired it between the caller's checks. "Missing" is a
1120
- * observation, never encoded as a numeric age: the previous
1121
- * `Number.POSITIVE_INFINITY` encoding made a just-released lock look like an
1122
- * infinitely old abandoned legacy lock (issue #421).
1123
- *
1124
- * A stat failure that does not prove absence (e.g. `EPERM`) clamps to age 0:
1125
- * the lock is treated as fresh so a waiter never steals on ambiguous evidence,
1126
- * while the caller's wait budget still bounds the stall.
1127
- */
1128
- function pluginBuildLockAgeMs(lockDir: string, now: number): number | null {
1129
- try {
1130
- return Math.max(0, now - fs.statSync(lockDir).mtimeMs);
1131
- } catch (error) {
1132
- const code = (error as NodeJS.ErrnoException).code;
1133
- return code === "ENOENT" || code === "ENOTDIR" ? null : 0;
1134
- }
1135
- }
1136
-
1137
- function pluginBuildLockPathExists(lockDir: string): boolean {
1138
- try {
1139
- const stats = fs.lstatSync(lockDir);
1140
- if (!stats.isDirectory() || stats.isSymbolicLink()) {
1141
- throw new Error(`ttsc: unsafe plugin build lock path: ${lockDir}`);
1142
- }
1143
- return true;
1144
- } catch (error) {
1145
- if (isMissingPathError(error)) return false;
1146
- throw error;
1147
- }
1148
- }
1149
-
1150
- function isLocalHostName(hostname: string): boolean {
1151
- return hostname.toLowerCase() === os.hostname().toLowerCase();
1152
- }
1153
-
1154
- function isProcessAlive(pid: number): boolean {
1155
- try {
1156
- process.kill(pid, 0);
1157
- return true;
1158
- } catch (error) {
1159
- return (error as NodeJS.ErrnoException).code === "EPERM";
1160
- }
1161
- }
1162
-
1163
- function describePluginBuildLockOwner(owner: {
1164
- hostname: string;
1165
- pid: number;
1166
- startedAt?: string;
1167
- }): string {
1168
- const started =
1169
- owner.startedAt === undefined ? "" : ` started at ${owner.startedAt}`;
1170
- return `pid ${owner.pid} on ${owner.hostname}${started}`;
1171
- }
1172
-
1173
- function reportPluginLockWait(opts: {
1174
- binaryPath: string;
1175
- elapsedMs: number;
1176
- lockDir: string;
1177
- lockInfo: {
1178
- label: string;
1179
- pluginName: string;
1180
- quiet: boolean;
1181
- };
1182
- owner: string;
1183
- }): void {
1184
- process.stderr.write(
1185
- `ttsc: waiting for ${opts.lockInfo.label} "${opts.lockInfo.pluginName}" ` +
1186
- `cache lock after ${formatDuration(opts.elapsedMs)}; ` +
1187
- `lock=${opts.lockDir}; binary=${opts.binaryPath}; owner=${opts.owner}\n`,
1188
- );
1189
- }
1190
-
1191
- function reportPluginLockSteal(
1192
- lockDir: string,
1193
- binaryPath: string,
1194
- lockInfo: {
1195
- label: string;
1196
- pluginName: string;
1197
- quiet: boolean;
1198
- },
1199
- reason: string,
1200
- ): void {
1201
- if (lockInfo.quiet) return;
1202
- process.stderr.write(
1203
- `ttsc: reclaiming abandoned ${lockInfo.label} "${lockInfo.pluginName}" ` +
1204
- `cache lock at ${lockDir}; binary=${binaryPath} (${reason})\n`,
1205
- );
1206
- }
1207
-
1208
- /**
1209
- * Render a millisecond duration for lock diagnostics (`137ms`, `42s`, `9m 3s`).
1210
- *
1211
- * Total over every number: no caller produces a non-finite duration anymore
1212
- * (the lock state machine reports "released" instead of an Infinity age), but
1213
- * as defense in depth a non-finite input renders as `an unknown time` so no
1214
- * public diagnostic can ever print `Infinitym NaNs` again (issue #421).
1215
- *
1216
- * Exported for unit tests.
1217
- */
1218
- export function formatDuration(ms: number): string {
1219
- if (!Number.isFinite(ms)) {
1220
- return "an unknown time";
1221
- }
1222
- if (ms < 1_000) {
1223
- return `${Math.max(0, Math.round(ms))}ms`;
1224
- }
1225
- const seconds = Math.floor(ms / 1_000);
1226
- const minutes = Math.floor(seconds / 60);
1227
- const remainder = seconds % 60;
1228
- if (minutes === 0) {
1229
- return `${seconds}s`;
1230
- }
1231
- return `${minutes}m ${remainder}s`;
1232
- }
1233
-
1234
- /** Block the current (synchronous) thread for `ms` without busy-spinning. */
1235
- function sleepSync(ms: number): void {
1236
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
1237
- }
1238
-
1239
- /**
1240
- * Copy every contributor's Go source into a sub-package of the host module and
1241
- * synthesize a blank-import file alongside the host's entry package so each
1242
- * contributor's `init()` runs before `main`.
1243
- *
1244
- * - Sources land at `<scratch>/<CONTRIB_DIRNAME>/<name>/` (recursive copy with
1245
- * the same pruning rules used for the host source).
1246
- * - The entry directory receives `<CONTRIBUTIONS_FILE_NAME>` containing one
1247
- * blank-import per contributor. The host's module path is read from the
1248
- * materialized go.mod, so the import path is always correct for the host
1249
- * plugin's actual module declaration.
1250
- * - Contributors that ship their own `go.mod` are rejected — the design relies on
1251
- * the contributor living inside the host's module so that workspace overlay
1252
- * rules and the host's `go.sum` cover transitive dependencies. This also
1253
- * closes the supply-chain hole where a contributor could otherwise pull in
1254
- * arbitrary Go modules.
1255
- */
1256
- function mergeContributors(opts: {
1257
- contributors: readonly ITtscBuildContributor[];
1258
- entry: string;
1259
- goModReader: GoModReader;
1260
- pluginName: string;
1261
- scratchDir: string;
1262
- }): void {
1263
- const hostModulePath = opts.goModReader.read(opts.scratchDir).modulePath;
1264
- if (hostModulePath === null || hostModulePath === "") {
1265
- throw new Error(
1266
- `ttsc: plugin "${opts.pluginName}" cannot accept contributors because its module ` +
1267
- `root has no resolvable go.mod module path`,
1268
- );
1269
- }
1270
- const contribRoot = path.join(opts.scratchDir, CONTRIB_DIRNAME);
1271
- // Refuse to merge when the host plugin's own source already owns a
1272
- // `contrib/` directory. We'd otherwise silently merge contributor
1273
- // files into a pre-populated host package and ship a hybrid binary
1274
- // whose contents nobody declared. Loud failure is the only safe
1275
- // option — the host plugin must rename its directory or the
1276
- // contributor system must use a different sub-package root.
1277
- if (fs.existsSync(contribRoot)) {
1278
- throw new Error(
1279
- `ttsc: plugin "${opts.pluginName}" already ships a ${CONTRIB_DIRNAME}/ directory in its source; ` +
1280
- `contributor merge would silently overwrite. Rename the host plugin's directory to a different name.`,
1281
- );
1282
- }
1283
- fs.mkdirSync(contribRoot, { recursive: true });
1284
- // Sort contributors by name so the synthesized `ttsc_contributions.go`
1285
- // emits blank imports in a deterministic order independent of
1286
- // declaration order. The cache key is already sort-stable
1287
- // (`computeCacheKey` sorts contributors by name), so without this
1288
- // matching sort the SAME cache key could correspond to two distinct
1289
- // binaries whose `init()` sequence across contributors differs by
1290
- // import order.
1291
- const sortedContributors = [...opts.contributors].sort((a, b) =>
1292
- a.name < b.name ? -1 : a.name > b.name ? 1 : 0,
1293
- );
1294
- const imports: string[] = [];
1295
- for (const contributor of sortedContributors) {
1296
- if (fs.existsSync(path.join(contributor.source, "go.mod"))) {
1297
- throw new Error(
1298
- `ttsc: plugin "${opts.pluginName}" contributor "${contributor.name}" must ship Go ` +
1299
- `source as a package, not a module (go.mod found at ${contributor.source}/go.mod). ` +
1300
- `Remove go.mod so the contributor compiles inside the host module's dependency graph.`,
1301
- );
1302
- }
1303
- const target = path.join(contribRoot, contributor.name);
1304
- if (fs.existsSync(target)) {
1305
- // Defensive: validatePluginContributors already rejects duplicate
1306
- // names, and the contribRoot-existence guard above blocks the
1307
- // host plugin from pre-shipping a `contrib/` directory. Reaching
1308
- // this branch implies an upstream contract break. Fail loud
1309
- // rather than overwrite.
1310
- throw new Error(
1311
- `ttsc: plugin "${opts.pluginName}" contributor "${contributor.name}" target ${target} already exists; ` +
1312
- `contributor names must be unique within one plugin build`,
1313
- );
1314
- }
1315
- fs.cpSync(contributor.source, target, {
1316
- recursive: true,
1317
- filter: (src) => {
1318
- const base = path.basename(src);
1319
- if (shouldPruneDirectory(base)) return false;
1320
- if (shouldOmitSourceFile(base)) return false;
1321
- return true;
1322
- },
1323
- });
1324
- imports.push(`${hostModulePath}/${CONTRIB_DIRNAME}/${contributor.name}`);
1325
- }
1326
- const entryDir = path.resolve(opts.scratchDir, opts.entry);
1327
- fs.mkdirSync(entryDir, { recursive: true });
1328
- const contributionsPath = path.join(entryDir, CONTRIBUTIONS_FILE_NAME);
1329
- // Same reasoning as the contribRoot guard: when entry resolves to the
1330
- // module root (`entry === "."`), entryDir == scratchDir and a
1331
- // pre-existing `ttsc_contributions.go` from the host plugin's own
1332
- // source would be silently overwritten by the generator below.
1333
- if (fs.existsSync(contributionsPath)) {
1334
- throw new Error(
1335
- `ttsc: plugin "${opts.pluginName}" already ships ${CONTRIBUTIONS_FILE_NAME} in its entry package; ` +
1336
- `that filename is reserved for the contributor blank-import generator. Rename the host's file.`,
1337
- );
1338
- }
1339
- writeContributionsFile(contributionsPath, imports);
1340
- }
1341
-
1342
- function writeContributionsFile(filePath: string, imports: string[]): void {
1343
- const importLines = imports
1344
- .map((spec) => `\t_ ${JSON.stringify(spec)}`)
1345
- .join("\n");
1346
- const body = `// Code generated by ttsc — DO NOT EDIT.
1347
- //
1348
- // This file is synthesized by ttsc's plugin builder when the host plugin
1349
- // descriptor declares "contributors". The blank imports below pull each
1350
- // contributor sub-package into the build so its init() runs before main.
1351
-
1352
- package main
1353
-
1354
- import (
1355
- ${importLines}
1356
- )
1357
- `;
1358
- fs.writeFileSync(filePath, body, "utf8");
1359
- }
1360
-
1361
- function publishBuiltBinary(builtBinary: string, binaryPath: string): void {
1362
- const pending = `${binaryPath}.${process.pid}.${Date.now()}-${Math.random()
1363
- .toString(16)
1364
- .slice(2)}.tmp`;
1365
- fs.copyFileSync(builtBinary, pending);
1366
- if (process.platform !== "win32") {
1367
- fs.chmodSync(pending, 0o755);
1368
- }
1369
- try {
1370
- fs.renameSync(pending, binaryPath);
1371
- } catch (error) {
1372
- fs.rmSync(pending, { force: true });
1373
- const code = (error as NodeJS.ErrnoException).code;
1374
- if (
1375
- (code === "EEXIST" || code === "EPERM" || code === "EACCES") &&
1376
- fs.existsSync(binaryPath)
1377
- ) {
1378
- return;
1379
- }
1380
- throw error;
1381
- } finally {
1382
- // Best-effort sweep of any leftover `.tmp` siblings from a prior
1383
- // crash between copyFileSync and renameSync. Same-directory pending
1384
- // names guarantee the rename stays a same-filesystem atomic op, so
1385
- // we accept the GC cost rather than move pending files to os.tmpdir.
1386
- pruneOrphanPendingBinaries(binaryPath);
1387
- }
1388
- }
1389
-
1390
- function pruneOrphanPendingBinaries(binaryPath: string): void {
1391
- // Only sweep pending files owned by THIS process. Concurrent ttsc
1392
- // invocations (two `ttsc --watch` shells against the same project)
1393
- // may have their own `<binary>.<their-pid>.*.tmp` mid-flight, and
1394
- // deleting them would race their renameSync into ENOENT.
1395
- try {
1396
- const dir = path.dirname(binaryPath);
1397
- const prefix = `${path.basename(binaryPath)}.${process.pid}.`;
1398
- for (const name of fs.readdirSync(dir)) {
1399
- if (name.startsWith(prefix) && name.endsWith(".tmp")) {
1400
- fs.rmSync(path.join(dir, name), { force: true });
1401
- }
1402
- }
1403
- } catch {
1404
- // Best-effort; never mask the underlying publish outcome.
1405
- }
1406
- }
1407
-
1408
- function resolveSourceBuildTarget(opts: {
1409
- source: string;
1410
- pluginName: string;
1411
- baseDir: string;
1412
- }): {
1413
- dir: string;
1414
- entry: string;
1415
- source: string;
1416
- } {
1417
- const source = path.isAbsolute(opts.source)
1418
- ? opts.source
1419
- : path.resolve(opts.baseDir, opts.source);
1420
- if (!fs.existsSync(source)) {
1421
- throw new Error(
1422
- `ttsc: plugin "${opts.pluginName}" source does not exist: ${source}`,
1423
- );
1424
- }
1425
-
1426
- const stat = fs.statSync(source);
1427
- const packageDir =
1428
- stat.isFile() && path.basename(source) === "go.mod"
1429
- ? path.dirname(source)
1430
- : stat.isDirectory()
1431
- ? source
1432
- : null;
1433
- if (packageDir === null) {
1434
- throw new Error(
1435
- `ttsc: plugin "${opts.pluginName}" source must be a Go package directory or go.mod file: ${source}`,
1436
- );
1437
- }
1438
-
1439
- const goMod = findNearestGoMod(packageDir, GO_MOD_SEARCH_MAX_DEPTH);
1440
- if (goMod === null) {
1441
- throw new Error(
1442
- `ttsc: plugin "${opts.pluginName}" source must be inside a Go module with go.mod within ${GO_MOD_SEARCH_MAX_DEPTH} parent directories: ${source}`,
1443
- );
1444
- }
1445
- const dir = path.dirname(goMod);
1446
- const rel = path.relative(dir, packageDir).replace(/\\/g, "/");
1447
- return {
1448
- dir,
1449
- entry: rel === "" ? "." : `./${rel}`,
1450
- source,
1451
- };
1452
- }
1453
-
1454
- function materializeScratchDir(source: string, scratch: string): void {
1455
- fs.mkdirSync(scratch, { recursive: true });
1456
- fs.cpSync(source, scratch, {
1457
- recursive: true,
1458
- filter: (src) => {
1459
- const base = path.basename(src);
1460
- if (shouldPruneDirectory(base)) return false;
1461
- if (shouldOmitSourceFile(base)) return false;
1462
- return true;
1463
- },
1464
- });
1465
- }
1466
-
1467
- function writeGoWork(
1468
- scratchDir: string,
1469
- useDirs: readonly string[],
1470
- goBinary: string,
1471
- pluginName: string,
1472
- env: NodeJS.ProcessEnv,
1473
- ): void {
1474
- const goModReader = createGoModReader(goBinary, pluginName, env);
1475
- validateSourceReplacements(scratchDir, useDirs, goModReader, pluginName);
1476
- const sourceInfo = goModReader.read(scratchDir);
1477
- const effectiveUseDirs =
1478
- sourceInfo.modulePath === TTSC_GO_MODULE_PATH
1479
- ? useDirs.filter((dir) => {
1480
- const modulePath = goModReader.read(dir).modulePath;
1481
- return modulePath !== null && !isTtscManagedModulePath(modulePath);
1482
- })
1483
- : useDirs;
1484
- const useLines = ["\t."];
1485
- for (const dir of effectiveUseDirs) {
1486
- useLines.push(`\t${formatGoWorkPath(dir)}`);
1487
- }
1488
- const replaceLines = sourceBuildWorkspaceReplacements(
1489
- effectiveUseDirs,
1490
- goModReader,
1491
- );
1492
- const replaceBlock =
1493
- replaceLines.length === 0 ? "" : `\n\n${replaceLines.join("\n")}\n`;
1494
- const goWork = `go 1.26\n\nuse (\n${useLines.join("\n")}\n)${replaceBlock}`;
1495
- fs.writeFileSync(path.join(scratchDir, "go.work"), goWork, "utf8");
1496
- }
1497
-
1498
- function validateSourceReplacements(
1499
- scratchDir: string,
1500
- useDirs: readonly string[],
1501
- goModReader: GoModReader,
1502
- pluginName: string,
1503
- ): void {
1504
- const sourceInfo = goModReader.read(scratchDir);
1505
- if (sourceInfo.modulePath === TTSC_GO_MODULE_PATH) {
1506
- return;
1507
- }
1508
- const sourceReplacements = sourceInfo.replacements;
1509
- if (sourceReplacements.length === 0) {
1510
- return;
1511
- }
1512
- const overlayModules = collectOverlayModulePaths(useDirs, goModReader);
1513
- for (const replacement of sourceReplacements) {
1514
- if (
1515
- isTtscManagedModulePath(replacement.modulePath) ||
1516
- overlayModules.has(replacement.modulePath)
1517
- ) {
1518
- throw new Error(
1519
- `ttsc: plugin "${pluginName}" go.mod replaces ttsc-managed module ` +
1520
- `${JSON.stringify(replacement.modulePath)}. Remove this replace directive; ` +
1521
- `ttsc supplies its own compiler and shim modules while building source plugins.`,
1522
- );
1523
- }
1524
- }
1525
- }
1526
-
1527
- function sourceBuildWorkspaceReplacements(
1528
- useDirs: readonly string[],
1529
- goModReader: GoModReader,
1530
- ): string[] {
1531
- const ttscRoot = useDirs.find(
1532
- (dir) => goModReader.read(dir).modulePath === TTSC_GO_MODULE_PATH,
1533
- );
1534
- if (!ttscRoot) {
1535
- return [];
1536
- }
1537
- return [
1538
- `replace ${TTSC_GO_MODULE_PATH} v0.0.0 => ${formatGoWorkPath(ttscRoot)}`,
1539
- ];
1540
- }
1541
-
1542
- /**
1543
- * Format an absolute filesystem path as a single `go.work`/`go.mod` token.
1544
- *
1545
- * The modfile grammar shared by `go.mod` and `go.work` (parsed by
1546
- * `golang.org/x/mod/modfile`) is whitespace-tokenized, so a `use`/`replace`
1547
- * path that contains a space — a home or project directory such as `/Users/John
1548
- * Smith/...` or `C:\Users\John Smith\...` — must be emitted as a quoted string
1549
- * or `go` cannot parse the generated `go.work`. Normalize Windows separators to
1550
- * `/` (the workspace convention) and then delegate to
1551
- * {@link autoQuoteGoModToken}, which mirrors `modfile.AutoQuote`.
1552
- *
1553
- * Separator normalization is itself a quoting trigger. A Windows UNC
1554
- * (`\\server\share\...`) or extended-length (`\\?\C:\...`) path normalizes into
1555
- * a token that starts with `//`, and the modfile lexer reads `//` as a line
1556
- * comment wherever it appears. Emitted bare, such a token turns its whole
1557
- * `use`/`replace` line into a comment: `go` exits 0, reports nothing, and the
1558
- * overlay module simply disappears from the workspace.
1559
- *
1560
- * Exported for unit tests.
1561
- */
1562
- export function formatGoWorkPath(p: string): string {
1563
- return autoQuoteGoModToken(p.replace(/\\/g, "/"));
1564
- }
1565
-
1566
- /**
1567
- * Quote `token` for a `go.mod`/`go.work` line exactly as
1568
- * `golang.org/x/mod/modfile`'s `AutoQuote` does: return it unchanged when it is
1569
- * already a clean bare token, otherwise return its Go double-quoted form so the
1570
- * value round-trips through the modfile lexer. A clean bare token is therefore
1571
- * emitted byte-for-byte as before; only tokens that would otherwise be split or
1572
- * interpreted as comments are quoted.
1573
- *
1574
- * Exported for unit tests.
1575
- */
1576
- export function autoQuoteGoModToken(token: string): string {
1577
- return mustQuoteGoModToken(token) ? goQuoteString(token) : token;
1578
- }
1579
-
1580
- // Mirror `modfile.MustQuote`: report whether `s` must be quoted to appear as a
1581
- // single token on a modfile line.
1582
- function mustQuoteGoModToken(s: string): boolean {
1583
- for (const ch of s) {
1584
- if (ch === " " || ch === '"' || ch === "'" || ch === "`") {
1585
- return true;
1586
- }
1587
- if (
1588
- ch === "(" ||
1589
- ch === ")" ||
1590
- ch === "[" ||
1591
- ch === "]" ||
1592
- ch === "{" ||
1593
- ch === "}" ||
1594
- ch === ","
1595
- ) {
1596
- // Go tests `len(s) > 1` (byte length): a lone bracket/comma is a legal
1597
- // bare token, but one embedded in a longer token forces quoting.
1598
- if (Buffer.byteLength(s, "utf8") > 1) {
1599
- return true;
1600
- }
1601
- continue;
1602
- }
1603
- if (!isGoPrintable(ch)) {
1604
- return true;
1605
- }
1606
- }
1607
- return s === "" || s.includes("//") || s.includes("/*");
1608
- }
1609
-
1610
- // Mirror `strconv.Quote`: wrap in double quotes, backslash-escape `"` and `\`,
1611
- // emit Go-printable runes verbatim (including the ASCII space and printable
1612
- // Unicode), and escape everything else with Go's `\a\b\f\n\r\t\v` / `\xNN` /
1613
- // `\uNNNN` / `\UNNNNNNNN` forms so the token round-trips through
1614
- // `strconv.Unquote` in the modfile lexer.
1615
- function goQuoteString(s: string): string {
1616
- let out = '"';
1617
- for (const ch of s) {
1618
- if (ch === '"' || ch === "\\") {
1619
- out += `\\${ch}`;
1620
- continue;
1621
- }
1622
- if (isGoPrintable(ch)) {
1623
- out += ch;
1624
- continue;
1625
- }
1626
- out += escapeGoRune(ch);
1627
- }
1628
- return `${out}"`;
1629
- }
1630
-
1631
- function escapeGoRune(ch: string): string {
1632
- switch (ch) {
1633
- case "\x07":
1634
- return "\\a";
1635
- case "\b":
1636
- return "\\b";
1637
- case "\f":
1638
- return "\\f";
1639
- case "\n":
1640
- return "\\n";
1641
- case "\r":
1642
- return "\\r";
1643
- case "\t":
1644
- return "\\t";
1645
- case "\v":
1646
- return "\\v";
1647
- default: {
1648
- const cp = ch.codePointAt(0) ?? 0;
1649
- if (cp < 0x20 || cp === 0x7f) {
1650
- return `\\x${cp.toString(16).padStart(2, "0")}`;
1651
- }
1652
- if (cp < 0x10000) {
1653
- return `\\u${cp.toString(16).padStart(4, "0")}`;
1654
- }
1655
- return `\\U${cp.toString(16).padStart(8, "0")}`;
1656
- }
1657
- }
1658
- }
1659
-
1660
- // `strconv.IsPrint`: the graphic categories except that the ONLY spacing
1661
- // character is the ASCII space (U+0020); other Unicode spaces are escaped.
1662
- const GO_PRINTABLE_RE = /^[\p{L}\p{M}\p{N}\p{P}\p{S}]$/u;
1663
-
1664
- function isGoPrintable(ch: string): boolean {
1665
- return ch === " " || GO_PRINTABLE_RE.test(ch);
1666
- }
1667
-
1668
- interface GoModReplacement {
1669
- readonly modulePath: string;
1670
- }
1671
-
1672
- interface GoModInfo {
1673
- readonly modulePath: string | null;
1674
- readonly replacements: readonly GoModReplacement[];
1675
- }
1676
-
1677
- interface GoModReader {
1678
- read(dir: string): GoModInfo;
1679
- }
1680
-
1681
- interface GoModJson {
1682
- readonly Module?: {
1683
- readonly Path?: string;
1684
- };
1685
- readonly Require?: readonly {
1686
- readonly Path?: string;
1687
- readonly Version?: string;
1688
- }[];
1689
- readonly Replace?: readonly {
1690
- readonly Old?: {
1691
- readonly Path?: string;
1692
- readonly Version?: string;
1693
- };
1694
- readonly New?: {
1695
- readonly Path?: string;
1696
- readonly Version?: string;
1697
- };
1698
- }[];
1699
- }
1700
-
1701
- function createGoModReader(
1702
- goBinary: string,
1703
- pluginName: string,
1704
- env: NodeJS.ProcessEnv,
1705
- ): GoModReader {
1706
- const cache = new Map<string, GoModInfo>();
1707
- return {
1708
- read(dir) {
1709
- const resolved = path.resolve(dir);
1710
- const cached = cache.get(resolved);
1711
- if (cached !== undefined) {
1712
- return cached;
1713
- }
1714
- const info = readGoModInfo(resolved, goBinary, pluginName, env);
1715
- cache.set(resolved, info);
1716
- return info;
1717
- },
1718
- };
1719
- }
1720
-
1721
- function readGoModInfo(
1722
- dir: string,
1723
- goBinary: string,
1724
- pluginName: string,
1725
- env: NodeJS.ProcessEnv,
1726
- ): GoModInfo {
1727
- if (!fs.existsSync(path.join(dir, "go.mod"))) {
1728
- return emptyGoModInfo();
1729
- }
1730
-
1731
- const result = spawnGoTool(goBinary, ["mod", "edit", "-json"], {
1732
- cwd: dir,
1733
- encoding: "utf8",
1734
- env: goBuildEnv(goBinary, undefined, env),
1735
- windowsHide: true,
1736
- });
1737
- if (result.error) {
1738
- if ((result.error as NodeJS.ErrnoException).code === "ENOENT") {
1739
- throw new Error(goToolchainNotFoundMessage(pluginName));
1740
- }
1741
- throw new Error(
1742
- `ttsc: reading go.mod for plugin "${pluginName}" failed to spawn ${goBinary}: ${result.error.message}`,
1743
- );
1744
- }
1745
- if (result.status !== 0) {
1746
- throw new Error(
1747
- `ttsc: reading go.mod for plugin "${pluginName}" failed:\n${result.stderr || result.stdout}`,
1748
- );
1749
- }
1750
-
1751
- let json: GoModJson;
1752
- try {
1753
- json = JSON.parse(result.stdout) as GoModJson;
1754
- } catch (error) {
1755
- throw new Error(
1756
- `ttsc: reading go.mod for plugin "${pluginName}" returned invalid JSON: ${
1757
- error instanceof Error ? error.message : String(error)
1758
- }`,
1759
- );
1760
- }
1761
-
1762
- return {
1763
- modulePath: json.Module?.Path ?? null,
1764
- replacements: (json.Replace ?? [])
1765
- .map(jsonReplacementToGoModReplacement)
1766
- .filter((replacement) => replacement !== null),
1767
- };
1768
- }
1769
-
1770
- function emptyGoModInfo(): GoModInfo {
1771
- return {
1772
- modulePath: null,
1773
- replacements: [],
1774
- };
1775
- }
1776
-
1777
- function jsonReplacementToGoModReplacement(
1778
- replacement: NonNullable<GoModJson["Replace"]>[number],
1779
- ): GoModReplacement | null {
1780
- const modulePath = replacement.Old?.Path;
1781
- if (modulePath === undefined) {
1782
- return null;
1783
- }
1784
- return {
1785
- modulePath,
1786
- };
1787
- }
1788
-
1789
- function collectOverlayModulePaths(
1790
- dirs: readonly string[],
1791
- goModReader: GoModReader,
1792
- ): Set<string> {
1793
- const out = new Set<string>();
1794
- for (const dir of dirs) {
1795
- const modulePath = goModReader.read(dir).modulePath;
1796
- if (modulePath !== null) {
1797
- out.add(modulePath);
1798
- }
1799
- }
1800
- return out;
1801
- }
1802
-
1803
- function isTtscManagedModulePath(modulePath: string): boolean {
1804
- return (
1805
- modulePath === TTSC_GO_MODULE_PATH ||
1806
- modulePath === TSGO_GO_MODULE_PATH ||
1807
- modulePath.startsWith("github.com/microsoft/typescript-go/shim/")
1808
- );
1809
- }
1810
-
1811
- function runGoBuild(
1812
- cwd: string,
1813
- entry: string,
1814
- binaryName: string,
1815
- pluginName: string,
1816
- goBinary: string,
1817
- goBuildCacheRoot: string,
1818
- env: NodeJS.ProcessEnv,
1819
- normalizeGoToolPermissions: boolean,
1820
- ): void {
1821
- ensureExecutableGoToolchain(goBinary, normalizeGoToolPermissions);
1822
- const result = spawnGoTool(goBinary, ["build", "-o", binaryName, entry], {
1823
- cwd,
1824
- encoding: "utf8",
1825
- env: goBuildEnv(goBinary, goBuildCacheRoot, env),
1826
- windowsHide: true,
1827
- });
1828
- if (result.error) {
1829
- if ((result.error as NodeJS.ErrnoException).code === "ENOENT") {
1830
- throw new Error(goToolchainNotFoundMessage(pluginName));
1831
- }
1832
- throw new Error(
1833
- `ttsc: building plugin "${pluginName}" failed to spawn ${goBinary}: ${result.error.message}`,
1834
- );
1835
- }
1836
- if (result.status !== 0) {
1837
- throw new Error(
1838
- `ttsc: building plugin "${pluginName}" via "go build" failed:\n${result.stderr || result.stdout}`,
1839
- );
1840
- }
1841
- }
1842
-
1843
- function goToolchainNotFoundMessage(pluginName: string): string {
1844
- return (
1845
- `ttsc: building plugin "${pluginName}" failed because the Go toolchain was not found. ` +
1846
- `Reinstall ttsc with optional dependencies so the bundled Go compiler is present, ` +
1847
- `or set TTSC_GO_BINARY to an absolute path.`
1848
- );
1849
- }
1850
-
1851
- export function spawnGoTool(
1852
- goBinary: string,
1853
- args: readonly string[],
1854
- options: SpawnSyncOptionsWithStringEncoding,
1855
- ): SpawnSyncReturns<string> {
1856
- // The child's streams go to files rather than pipes, so no output ceiling
1857
- // applies: `spawnSync` only bounds what it must hold in this process's
1858
- // memory, and a `go build` that says a great deal is not a failure to invent
1859
- // a limit for. See `captureProcessOutput`.
1860
- const capture = captureProcessOutput();
1861
- const spawnOptions = {
1862
- ...options,
1863
- stdio: ["ignore", capture.stdoutFd, capture.stderrFd] as StdioOptions,
1864
- };
1865
- try {
1866
- const result = spawnGoToolProcess(goBinary, args, spawnOptions);
1867
- const stdout = capture.read("stdout", "utf8") as string;
1868
- const stderr = capture.read("stderr", "utf8") as string;
1869
- return {
1870
- ...result,
1871
- output: [null, stdout, stderr],
1872
- stderr,
1873
- stdout,
1874
- };
1875
- } finally {
1876
- capture.dispose();
1877
- }
1878
- }
1879
-
1880
- /**
1881
- * Launch the Go tool, routing through cmd.exe only where Windows needs a
1882
- * wrapper. Output routing is the caller's concern; this owns process
1883
- * selection.
1884
- */
1885
- function spawnGoToolProcess(
1886
- goBinary: string,
1887
- args: readonly string[],
1888
- options: SpawnSyncOptionsWithStringEncoding,
1889
- ): SpawnSyncReturns<string> {
1890
- if (process.platform !== "win32") {
1891
- return spawnSync(goBinary, [...args], options);
1892
- }
1893
- const inheritedEnv = options.env ?? process.env;
1894
- const resolved = resolveWindowsGoTool(
1895
- goBinary,
1896
- inheritedEnv,
1897
- spawnWorkingDirectory(options.cwd),
1898
- );
1899
- if (!resolved.wrapper) {
1900
- return spawnSync(goBinary, [...args], options);
1901
- }
1902
- // Preserve the native spawn ENOENT contract before cmd.exe becomes the
1903
- // actual child process. The callers use that code for the install guidance.
1904
- if (resolved.location === null) {
1905
- return spawnSync(goBinary, [...args], options);
1906
- }
1907
- const shim = createWindowsGoCommandShim([resolved.location, ...args]);
1908
- return spawnSync(
1909
- readWindowsEnvironmentValue(inheritedEnv, "COMSPEC") ??
1910
- readWindowsEnvironmentValue(process.env, "COMSPEC") ??
1911
- "cmd.exe",
1912
- windowsGoCommandArgs(shim.payload),
1913
- {
1914
- ...options,
1915
- env: { ...inheritedEnv, ...shim.environment },
1916
- shell: false,
1917
- // The /c payload is already one fully quoted Windows command line.
1918
- windowsVerbatimArguments: true,
1919
- },
1920
- );
1921
- }
1922
-
1923
- /** Build the fixed cmd.exe switch sequence for one already quoted payload. */
1924
- export function windowsGoCommandArgs(payload: string): string[] {
1925
- return ["/d", "/v:off", "/s", "/c", payload];
1926
- }
1927
-
1928
- function spawnWorkingDirectory(
1929
- cwd: SpawnSyncOptionsWithStringEncoding["cwd"],
1930
- ): string {
1931
- if (cwd === undefined) return process.cwd();
1932
- return path.resolve(typeof cwd === "string" ? cwd : fileURLToPath(cwd));
1933
- }
1934
-
1935
- function isWindowsCommandWrapper(location: string): boolean {
1936
- return process.platform === "win32" && /\.(?:bat|cmd)$/i.test(location);
1937
- }
1938
-
1939
- /** Pass volatile cmd wrapper arguments through one-pass environment expansion. */
1940
- function createWindowsGoCommandShim(args: readonly string[]): {
1941
- environment: NodeJS.ProcessEnv;
1942
- payload: string;
1943
- } {
1944
- const prefix = `TTSC_GO_COMMAND_SHIM_${crypto
1945
- .randomBytes(8)
1946
- .toString("hex")
1947
- .toUpperCase()}_ARG_`;
1948
- const environment = Object.fromEntries(
1949
- args.map((arg, index) => [prefix + index, quoteWindowsCommandArg(arg)]),
1950
- );
1951
- return {
1952
- environment,
1953
- // cmd expands each placeholder exactly once. Percent-shaped text inside an
1954
- // expanded value is not scanned as a second environment reference.
1955
- payload: `"${args.map((_, index) => `%${prefix}${index}%`).join(" ")}"`,
1956
- };
1957
- }
1958
-
1959
- /** Quote one argv value for the Windows command-line parser used by cmd. */
1960
- function quoteWindowsCommandArg(arg: string): string {
1961
- return `"${String(arg)
1962
- .replace(/(\\*)"/g, '$1$1\\"')
1963
- .replace(/(\\*)$/, "$1$1")}"`;
1964
- }
1965
-
1966
- function goBuildEnv(
1967
- goBinary: string,
1968
- goBuildCacheRoot?: string,
1969
- effectiveEnv: NodeJS.ProcessEnv = process.env,
1970
- ): NodeJS.ProcessEnv {
1971
- const env = { ...effectiveEnv };
1972
- env.GOWORK = "auto";
1973
- // Only the actual `go build` needs ttsc's GOCACHE; read-only metadata spawns
1974
- // (`go mod edit`, `go env`, `go version`) call goBuildEnv with no cache root
1975
- // and inherit the ambient GOCACHE, which they never write to anyway. GOCACHE
1976
- // is not part of the plugin cache key, so this cannot affect it.
1977
- if (goBuildCacheRoot) {
1978
- env.GOCACHE = goBuildCacheRoot;
1979
- }
1980
- const goRoot = inferGoRoot(goBinary);
1981
- if (goRoot && !env.GOROOT) {
1982
- env.GOROOT = goRoot;
1983
- }
1984
- return env;
1985
- }
1986
-
1987
- function inferGoRoot(goBinary: string): string | null {
1988
- if (!path.isAbsolute(goBinary)) return null;
1989
- const binDir = path.dirname(goBinary);
1990
- if (path.basename(binDir) !== "bin") return null;
1991
- const goRoot = path.dirname(binDir);
1992
- return fs.existsSync(path.join(goRoot, "src", "runtime")) ? goRoot : null;
1993
- }
1994
-
1995
- export function ensureExecutableGoToolchain(
1996
- goBinary: string,
1997
- normalizeBundledPermissions: boolean,
1998
- ): void {
1999
- if (process.platform === "win32") return;
2000
- if (!path.isAbsolute(goBinary) || !fs.existsSync(goBinary)) return;
2001
- try {
2002
- ensureExecutableFile(goBinary, normalizeBundledPermissions);
2003
- const goRoot = inferGoRoot(goBinary);
2004
- if (!goRoot) return;
2005
- const gofmt = path.join(path.dirname(goBinary), "gofmt");
2006
- if (fs.existsSync(gofmt)) {
2007
- ensureExecutableFile(gofmt, normalizeBundledPermissions);
2008
- }
2009
- const toolDir = path.join(goRoot, "pkg", "tool");
2010
- if (!fs.existsSync(toolDir)) return;
2011
- for (const file of walkToolFiles(toolDir)) {
2012
- ensureExecutableFile(file, normalizeBundledPermissions);
2013
- }
2014
- } catch {
2015
- // Let the subsequent go build spawn fail with the real OS error.
2016
- }
2017
- }
2018
-
2019
- /** Repair tool execution without widening an explicitly selected toolchain. */
2020
- function ensureExecutableFile(
2021
- file: string,
2022
- normalizeBundledPermissions: boolean,
2023
- ): void {
2024
- const mode = fs.statSync(file).mode & 0o7777;
2025
- if (normalizeBundledPermissions) {
2026
- if (mode !== 0o755) fs.chmodSync(file, 0o755);
2027
- } else if ((mode & 0o111) === 0) {
2028
- fs.chmodSync(file, mode | 0o100);
2029
- }
2030
- }
2031
-
2032
- function walkToolFiles(dir: string): string[] {
2033
- const out: string[] = [];
2034
- let entries: fs.Dirent[];
2035
- try {
2036
- entries = fs.readdirSync(dir, { withFileTypes: true });
2037
- } catch {
2038
- return out;
2039
- }
2040
- for (const entry of entries) {
2041
- const file = path.join(dir, entry.name);
2042
- if (entry.isDirectory()) {
2043
- out.push(...walkToolFiles(file));
2044
- } else if (entry.isFile()) {
2045
- out.push(file);
2046
- }
2047
- }
2048
- return out;
2049
- }
2050
-
2051
- function findTtscOverlayDirs(): readonly string[] {
2052
- const ttscRoot = path.resolve(__dirname, "..", "..", "..");
2053
- const dirs: string[] = [];
2054
- if (fs.existsSync(path.join(ttscRoot, "go.mod"))) {
2055
- dirs.push(ttscRoot);
2056
- }
2057
- const shimRoot = path.join(ttscRoot, "shim");
2058
- if (fs.existsSync(shimRoot)) {
2059
- walkForGoMod(shimRoot, dirs);
2060
- }
2061
- dirs.sort();
2062
- return dirs;
2063
- }
2064
-
2065
- function walkForGoMod(dir: string, out: string[]): void {
2066
- let entries: fs.Dirent[];
2067
- try {
2068
- entries = fs.readdirSync(dir, { withFileTypes: true });
2069
- } catch {
2070
- return;
2071
- }
2072
- let hasGoMod = false;
2073
- for (const entry of entries) {
2074
- if (entry.isFile() && entry.name === "go.mod") {
2075
- hasGoMod = true;
2076
- }
2077
- }
2078
- if (hasGoMod) {
2079
- out.push(dir);
2080
- }
2081
- for (const entry of entries) {
2082
- if (!entry.isDirectory()) continue;
2083
- if (shouldPruneDirectory(entry.name)) continue;
2084
- walkForGoMod(path.join(dir, entry.name), out);
2085
- }
2086
- }
2087
-
2088
- /**
2089
- * Resolve the directory where compiled plugin binaries are cached.
2090
- *
2091
- * Delegates to {@link resolveSourceBuildCachePaths}; kept as a thin accessor for
2092
- * callers (and tests) that only need the plugin-binary root. Triggers the
2093
- * opportunistic project-cache GC as a side effect for the default location.
2094
- */
2095
- export function resolvePluginCacheRoot(
2096
- projectRoot: string,
2097
- cacheDir?: string,
2098
- env: NodeJS.ProcessEnv = process.env,
2099
- ): string {
2100
- const paths = resolveSourceBuildCachePaths(projectRoot, cacheDir, env);
2101
- maybePruneSourceBuildCaches(paths, cacheDir, env);
2102
- return paths.pluginRoot;
2103
- }
2104
-
2105
- /**
2106
- * Resolve all source-plugin build cache directories for one invocation.
2107
- *
2108
- * `pluginRoot` stores compiled plugin binaries; `goBuildRoot` is the Go object
2109
- * cache passed as `GOCACHE` while ttsc builds those binaries. The default Go
2110
- * cache lives under `root`; an explicit `TTSC_GO_CACHE_DIR` or `GOCACHE` keeps
2111
- * its independently resolved location and ownership policy.
2112
- */
2113
- export function resolveSourceBuildCachePaths(
2114
- projectRoot: string,
2115
- cacheDir?: string,
2116
- env: NodeJS.ProcessEnv = process.env,
2117
- ): ITtscSourceBuildCachePaths {
2118
- const root = resolveSourceBuildCacheRoot(projectRoot, cacheDir, env);
2119
- const goBuild = resolveGoBuildCacheRoot(root, projectRoot, env);
2120
- return {
2121
- root,
2122
- pluginRoot: path.join(root, PLUGIN_CACHE_DIRNAME),
2123
- goBuildRoot: goBuild.root,
2124
- goBuildRootSource: goBuild.source,
2125
- };
2126
- }
2127
-
2128
- /**
2129
- * Resolve the cache root for one invocation.
2130
- *
2131
- * Priority:
2132
- *
2133
- * 1. Explicit `cacheDir` option (resolved relative to `projectRoot`);
2134
- * 2. `TTSC_CACHE_DIR` environment variable (resolved absolute);
2135
- * 3. `<workspaceRoot>/node_modules/.cache/ttsc` — project-local by default.
2136
- *
2137
- * There is deliberately NO global (`~/.cache`) fallback: the cache is scoped to
2138
- * the workspace so it can never accumulate machine-wide, and `rm -rf
2139
- * node_modules` reclaims it.
2140
- */
2141
- function resolveSourceBuildCacheRoot(
2142
- projectRoot: string,
2143
- cacheDir: string | undefined,
2144
- env: NodeJS.ProcessEnv,
2145
- ): string {
2146
- if (cacheDir) {
2147
- return path.resolve(projectRoot, cacheDir);
2148
- }
2149
- if (env.TTSC_CACHE_DIR) {
2150
- // Anchor a relative TTSC_CACHE_DIR to the project root (not the process
2151
- // cwd) so a programmatic host whose cwd differs from the project still
2152
- // resolves — and later cleans — the same cache. Absolute values pass
2153
- // through path.resolve unchanged.
2154
- return path.resolve(projectRoot, env.TTSC_CACHE_DIR);
2155
- }
2156
- return path.join(
2157
- resolveWorkspaceRoot(projectRoot),
2158
- NODE_MODULES_DIRNAME,
2159
- LOCAL_CACHE_PARENT_DIRNAME,
2160
- TTSC_CACHE_DIRNAME,
2161
- );
2162
- }
2163
-
2164
- /**
2165
- * Resolve the monorepo/workspace root for `projectRoot` so every package shares
2166
- * one cache and a plugin builds once per workspace, not once per package.
2167
- *
2168
- * Walks up from `projectRoot` and returns, in order of preference: the NEAREST
2169
- * ancestor that is a workspace root (holds `pnpm-workspace.yaml`, or a
2170
- * `package.json` with a `workspaces` field); else the nearest ancestor that
2171
- * already contains a `node_modules` directory; else `projectRoot` itself.
2172
- *
2173
- * Nearest (not highest) so an unrelated ancestor that happens to declare
2174
- * `workspaces` — for example a `package.json` in the user's home directory —
2175
- * cannot pull the cache above the project's real monorepo root.
2176
- */
2177
- function resolveWorkspaceRoot(projectRoot: string): string {
2178
- let dir = path.resolve(projectRoot);
2179
- let nearestNodeModulesOwner: string | null = null;
2180
- for (;;) {
2181
- if (isWorkspaceRootDir(dir)) {
2182
- return dir;
2183
- }
2184
- if (
2185
- nearestNodeModulesOwner === null &&
2186
- fs.existsSync(path.join(dir, NODE_MODULES_DIRNAME))
2187
- ) {
2188
- nearestNodeModulesOwner = dir;
2189
- }
2190
- const parent = path.dirname(dir);
2191
- if (parent === dir) {
2192
- break;
2193
- }
2194
- dir = parent;
2195
- }
2196
- return nearestNodeModulesOwner ?? path.resolve(projectRoot);
2197
- }
2198
-
2199
- function isWorkspaceRootDir(dir: string): boolean {
2200
- for (const marker of WORKSPACE_ROOT_MARKER_FILES) {
2201
- if (fs.existsSync(path.join(dir, marker))) {
2202
- return true;
2203
- }
2204
- }
2205
- return packageJsonDeclaresWorkspaces(path.join(dir, "package.json"));
2206
- }
2207
-
2208
- function packageJsonDeclaresWorkspaces(packageJsonPath: string): boolean {
2209
- let text: string;
2210
- try {
2211
- text = fs.readFileSync(packageJsonPath, "utf8");
2212
- } catch {
2213
- return false;
2214
- }
2215
- try {
2216
- const workspaces = (JSON.parse(text) as { workspaces?: unknown })
2217
- .workspaces;
2218
- // A real workspace root declares a NON-EMPTY package list (an array, or an
2219
- // object with a `packages` array). Ignore `false`, `[]`, `null`, or `{}` so
2220
- // a disabled or empty declaration on an unrelated ancestor cannot hijack
2221
- // the cache location.
2222
- if (Array.isArray(workspaces)) {
2223
- return workspaces.length > 0;
2224
- }
2225
- if (workspaces !== null && typeof workspaces === "object") {
2226
- const packages = (workspaces as { packages?: unknown }).packages;
2227
- return Array.isArray(packages) && packages.length > 0;
2228
- }
2229
- return false;
2230
- } catch {
2231
- return false;
2232
- }
2233
- }
2234
-
2235
- function resolveGoBuildCacheRoot(
2236
- root: string,
2237
- projectRoot: string,
2238
- env: NodeJS.ProcessEnv,
2239
- ): {
2240
- root: string;
2241
- source: ITtscSourceBuildCachePaths["goBuildRootSource"];
2242
- } {
2243
- if (env.TTSC_GO_CACHE_DIR) {
2244
- // Anchor a relative TTSC_GO_CACHE_DIR to the project root, matching
2245
- // TTSC_CACHE_DIR, so the build and a later `clean` from a different cwd
2246
- // agree on the directory. Absolute values pass through unchanged.
2247
- return {
2248
- root: path.resolve(projectRoot, env.TTSC_GO_CACHE_DIR),
2249
- source: "TTSC_GO_CACHE_DIR",
2250
- };
2251
- }
2252
- if (env.GOCACHE && env.GOCACHE.length > 0) {
2253
- return {
2254
- root: env.GOCACHE,
2255
- source: "GOCACHE",
2256
- };
2257
- }
2258
- return {
2259
- root: path.join(root, GO_BUILD_CACHE_DIRNAME),
2260
- source: "ttsc-cache",
2261
- };
2262
- }
2263
-
2264
- function maybePruneSourceBuildCaches(
2265
- paths: ITtscSourceBuildCachePaths,
2266
- cacheDir: string | undefined,
2267
- env: NodeJS.ProcessEnv = process.env,
2268
- ): void {
2269
- // GC only the default (workspace-local) location. When the user pins an
2270
- // explicit `cacheDir`/`TTSC_CACHE_DIR`, they own its lifetime, so ttsc must
2271
- // not delete entries out from under them. `env` is the effective instance
2272
- // environment so a programmatic caller that pins `TTSC_CACHE_DIR` only in
2273
- // `context.env` is honored without leaning on the shared `process.env`.
2274
- if (!cacheDir && !env.TTSC_CACHE_DIR) {
2275
- prunePluginCacheRoot(paths.pluginRoot);
2276
- if (paths.goBuildRootSource === "ttsc-cache") {
2277
- pruneGoBuildCacheRoot(paths.goBuildRoot);
2278
- }
2279
- }
2280
- }
2281
-
2282
- /** Report whether this invocation owns and automatically maintains both caches. */
2283
- function shouldManageSourceBuildCaches(
2284
- paths: ITtscSourceBuildCachePaths,
2285
- cacheDir: string | undefined,
2286
- env: NodeJS.ProcessEnv,
2287
- ): boolean {
2288
- return (
2289
- !cacheDir && !env.TTSC_CACHE_DIR && paths.goBuildRootSource === "ttsc-cache"
2290
- );
2291
- }
2292
-
2293
- /**
2294
- * Return every directory `ttsc clean` should remove for `projectRoot`.
2295
- *
2296
- * Covers the resolved plugin-binary root, a safely named nested `go-build/`, a
2297
- * ttsc-owned Go build cache that lives OUTSIDE that root (`TTSC_GO_CACHE_DIR`),
2298
- * and the two legacy project-local caches. A user-provided `GOCACHE` is never
2299
- * removed. Pure over `env`, so the CLI passes `process.env` and a programmatic
2300
- * caller can pass an injected environment.
2301
- */
2302
- export function resolveCleanTargets(
2303
- projectRoot: string,
2304
- cacheDir?: string,
2305
- env: NodeJS.ProcessEnv = process.env,
2306
- ): string[] {
2307
- const paths = resolveSourceBuildCachePaths(projectRoot, cacheDir, env);
2308
- // Remove ttsc-OWNED directories only, never the parent cache root.
2309
- const targets = [paths.pluginRoot];
2310
- // ttsc's nested `<root>/go-build` is only safe to delete when we are certain
2311
- // the root belongs to ttsc: the default `node_modules/.cache/ttsc`, or a root
2312
- // the user explicitly named `ttsc`. Under a shared root (e.g.
2313
- // `TTSC_CACHE_DIR=~/.cache`) a bare `<root>/go-build` could be the user's
2314
- // machine-wide GOCACHE, so it must never be removed by name.
2315
- const isTtscOwnedRoot =
2316
- (!cacheDir && !env.TTSC_CACHE_DIR) ||
2317
- path.basename(paths.root) === TTSC_CACHE_DIRNAME;
2318
- if (isTtscOwnedRoot) {
2319
- targets.push(path.join(paths.root, GO_BUILD_CACHE_DIRNAME));
2320
- }
2321
- // An explicit TTSC_GO_CACHE_DIR is a ttsc-dedicated external cache; a
2322
- // user-provided GOCACHE (source "GOCACHE") is never removed.
2323
- if (paths.goBuildRootSource === "TTSC_GO_CACHE_DIR") {
2324
- targets.push(paths.goBuildRoot);
2325
- }
2326
- targets.push(path.join(projectRoot, NODE_MODULES_DIRNAME, ".ttsc"));
2327
- targets.push(path.join(projectRoot, ".ttsc"));
2328
- return targets;
2329
- }
2330
-
2331
- /**
2332
- * Machine-global cache directories created by pre-0.17 ttsc releases (XDG /
2333
- * AppData / Library / `~/.cache`). ttsc no longer writes to any of these, but
2334
- * an upgraded machine can still hold a multi-GB orphaned cache here, so `ttsc
2335
- * clean` offers them for removal to reclaim that disk. Each entry is the whole
2336
- * `<userCacheRoot>/ttsc` directory (both its `plugins` and `go-build`), which
2337
- * was entirely ttsc-owned in those releases and is safe to remove.
2338
- */
2339
- export function legacyGlobalCacheTargets(): string[] {
2340
- const roots = new Set<string>();
2341
- const home = os.homedir();
2342
- const xdg = process.env.XDG_CACHE_HOME;
2343
- if (xdg && path.isAbsolute(xdg)) {
2344
- roots.add(path.join(xdg, TTSC_CACHE_DIRNAME));
2345
- }
2346
- if (process.platform === "win32") {
2347
- const local = process.env.LOCALAPPDATA;
2348
- if (local && path.isAbsolute(local)) {
2349
- roots.add(path.join(local, TTSC_CACHE_DIRNAME));
2350
- }
2351
- if (home) {
2352
- roots.add(path.join(home, "AppData", "Local", TTSC_CACHE_DIRNAME));
2353
- }
2354
- } else if (process.platform === "darwin" && home) {
2355
- roots.add(path.join(home, "Library", "Caches", TTSC_CACHE_DIRNAME));
2356
- }
2357
- if (home) {
2358
- roots.add(path.join(home, ".cache", TTSC_CACHE_DIRNAME));
2359
- }
2360
- return [...roots];
2361
- }
2362
-
2363
- /** Report whether `child` equals `parent` or is nested beneath it. */
2364
- export function isPathWithin(child: string, parent: string): boolean {
2365
- const rel = path.relative(parent, child);
2366
- return (
2367
- rel === "" ||
2368
- (rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel))
2369
- );
2370
- }
2371
-
2372
- function resolveGoCompiler(env: NodeJS.ProcessEnv = process.env): {
2373
- binary: string;
2374
- bundled: boolean;
2375
- } {
2376
- const explicit = env.TTSC_GO_BINARY;
2377
- if (explicit && explicit.length > 0) {
2378
- return { binary: explicit, bundled: false };
2379
- }
2380
-
2381
- try {
2382
- return {
2383
- binary: createRequire(__filename).resolve(
2384
- `@ttsc/${process.platform}-${process.arch}/bin/go/bin/${process.platform === "win32" ? "go.exe" : "go"}`,
2385
- ),
2386
- bundled: true,
2387
- };
2388
- } catch {
2389
- /* fall through */
2390
- }
2391
-
2392
- const platformPackage = path.resolve(
2393
- __dirname,
2394
- "..",
2395
- "..",
2396
- "..",
2397
- "..",
2398
- `ttsc-${process.platform}-${process.arch}`,
2399
- "bin",
2400
- "go",
2401
- "bin",
2402
- process.platform === "win32" ? "go.exe" : "go",
2403
- );
2404
- if (fs.existsSync(platformPackage)) {
2405
- return { binary: platformPackage, bundled: true };
2406
- }
2407
-
2408
- const local = path.resolve(
2409
- __dirname,
2410
- "..",
2411
- "..",
2412
- "..",
2413
- "..",
2414
- "native",
2415
- "go",
2416
- "bin",
2417
- process.platform === "win32" ? "go.exe" : "go",
2418
- );
2419
- if (fs.existsSync(local)) return { binary: local, bundled: true };
2420
-
2421
- const homeSdk = path.join(
2422
- env.HOME ?? "",
2423
- "go-sdk",
2424
- "go",
2425
- "bin",
2426
- process.platform === "win32" ? "go.exe" : "go",
2427
- );
2428
- if (fs.existsSync(homeSdk)) return { binary: homeSdk, bundled: false };
2429
-
2430
- return { binary: "go", bundled: false };
2431
- }
2432
-
2433
- /**
2434
- * Compute a deterministic SHA-256 cache key for a plugin build.
2435
- *
2436
- * The key covers every input that can produce a different binary: ttsc/tsgo
2437
- * versions, platform, entry package, Go compiler identity, Go build environment
2438
- * variables, overlay module sources, plugin source files, and contributor
2439
- * source files. Contributors are sorted by name so declaration order does not
2440
- * affect the key.
2441
- *
2442
- * Exposed for testing and for the `ttsc cache` CLI command.
2443
- */
2444
- export function computeCacheKey(inputs: {
2445
- contributors?: readonly ITtscBuildContributor[];
2446
- dir: string;
2447
- entry: string;
2448
- env?: NodeJS.ProcessEnv;
2449
- filesystem?: Partial<SourceBuildFilesystemOperations>;
2450
- goBinary?: string;
2451
- overlayDirs?: readonly string[];
2452
- ttscVersion: string;
2453
- tsgoVersion: string;
2454
- }): string {
2455
- const env = inputs.env ?? process.env;
2456
- const filesystem: SourceBuildFilesystemOperations = {
2457
- readFile:
2458
- inputs.filesystem?.readFile ?? DEFAULT_SOURCE_BUILD_FILESYSTEM.readFile,
2459
- };
2460
- const goBinary =
2461
- inputs.goBinary === undefined
2462
- ? undefined
2463
- : resolveGoToolForBuild(inputs.goBinary, env, inputs.dir);
2464
- const hash = crypto.createHash("sha256");
2465
- hash.update(`ttsc=${inputs.ttscVersion}\n`);
2466
- hash.update(`tsgo=${inputs.tsgoVersion}\n`);
2467
- hash.update(`platform=${process.platform}/${process.arch}\n`);
2468
- hash.update(`entry=${inputs.entry}\n`);
2469
- if (goBinary !== undefined) {
2470
- hash.update(`go=${resolveGoCompilerIdentity(goBinary, env, inputs.dir)}\n`);
2471
- }
2472
- hashGoBuildEnvironment(hash, goBinary, inputs.dir, env, filesystem);
2473
- hashExternalGoBuildEnvironment(hash, env);
2474
- hashSourceDirectory(hash, "plugin", inputs.dir);
2475
- for (const [index, dir] of [...(inputs.overlayDirs ?? [])].sort().entries()) {
2476
- hashSourceDirectory(hash, `overlay:${index}`, dir);
2477
- }
2478
- // Hash contributors in sorted-by-name order so two consumers with the
2479
- // same logical set produce the same key regardless of declaration order
2480
- // in the host's plugin descriptor.
2481
- const sortedContributors = [...(inputs.contributors ?? [])].sort((a, b) =>
2482
- a.name === b.name ? 0 : a.name < b.name ? -1 : 1,
2483
- );
2484
- for (const contributor of sortedContributors) {
2485
- hashSourceDirectory(
2486
- hash,
2487
- `contributor:${contributor.name}`,
2488
- contributor.source,
2489
- );
2490
- }
2491
- return hash.digest("hex").slice(0, 32);
2492
- }
2493
-
2494
- function hashSourceDirectory(
2495
- hash: crypto.Hash,
2496
- label: string,
2497
- root: string,
2498
- ): void {
2499
- hash.update(`dir=${label}\n`);
2500
- for (const file of collectSourceFiles(root)) {
2501
- const rel = path.relative(root, file).replace(/\\/g, "/");
2502
- hash.update(`f=${rel}\n`);
2503
- hash.update(fs.readFileSync(file));
2504
- hash.update("\n");
2505
- }
2506
- }
2507
-
2508
- function collectSourceFiles(root: string): string[] {
2509
- const out: string[] = [];
2510
- walk(root, out);
2511
- out.sort();
2512
- return out;
2513
- }
2514
-
2515
- function walk(dir: string, out: string[]): void {
2516
- let entries: fs.Dirent[];
2517
- try {
2518
- entries = fs.readdirSync(dir, { withFileTypes: true });
2519
- } catch {
2520
- return;
2521
- }
2522
- for (const entry of entries) {
2523
- const full = path.join(dir, entry.name);
2524
- if (entry.isDirectory()) {
2525
- if (shouldPruneDirectory(entry.name)) continue;
2526
- walk(full, out);
2527
- continue;
2528
- }
2529
- if (!entry.isFile()) continue;
2530
- if (shouldOmitSourceFile(entry.name)) continue;
2531
- if (!isHashableFile(entry.name)) continue;
2532
- out.push(full);
2533
- }
2534
- }
2535
-
2536
- function shouldPruneDirectory(name: string): boolean {
2537
- return PRUNE_DIRS.has(name);
2538
- }
2539
-
2540
- function shouldOmitSourceFile(name: string): boolean {
2541
- if (GENERATED_WORKSPACE_FILES.has(name)) return true;
2542
- // npm-pack tarballs and macOS/Windows editor sidecars are local
2543
- // build artifacts that drift independently of the Go source. They
2544
- // would otherwise enter the cache key and bust the cached binary on
2545
- // every unrelated `npm pack` or editor save.
2546
- if (name.endsWith(".tgz") || name.endsWith(".tar.gz")) return true;
2547
- if (name === ".DS_Store" || name === "Thumbs.db") return true;
2548
- return false;
2549
- }
2550
-
2551
- function isHashableFile(name: string): boolean {
2552
- return !name.endsWith("~");
2553
- }
2554
-
2555
- // Per-process memo for the Go compiler identity. `computeCacheKey` runs once
2556
- // per source plugin, so an N-plugin project that points every plugin at the
2557
- // same toolchain would otherwise pay N `go version` spawns plus N ~150MB
2558
- // binary hashes for a value that does not change between plugins. The result
2559
- // is a pure function of the go binary's resolved real path plus its on-disk
2560
- // content; the memo key therefore mixes the resolved real path with a cheap
2561
- // content signature (filesystem identity, mode, byte size, and nanosecond
2562
- // change/modify times). That signature changes if a long-lived host rewrites
2563
- // or atomically replaces the binary between calls, so the memo
2564
- // re-derives the identity exactly as the un-memoized code would and the
2565
- // cache-key bytes stay byte-for-byte identical to today. The selected compiler
2566
- // path is shared by every build subprocess on Windows, while `go version` uses
2567
- // the same effective cwd and environment as the cache-key `go env` query. The
2568
- // memo key includes that context so an environment-sensitive wrapper cannot
2569
- // lend its version result to another compiler invocation.
2570
- const goCompilerIdentityCache = new Map<string, string>();
2571
-
2572
- function resolveGoCompilerIdentity(
2573
- goBinary: string,
2574
- env: NodeJS.ProcessEnv = process.env,
2575
- cwd: string = process.cwd(),
2576
- ): string {
2577
- const selected = resolveGoToolForBuild(goBinary, env, cwd);
2578
- const resolved =
2579
- process.platform === "win32"
2580
- ? resolveRealPath(selected)
2581
- : resolveExecutableIdentityPath(selected, env, cwd);
2582
- const compilerEnv = goBuildEnv(selected, undefined, env);
2583
- const memoKey = goCompilerIdentityMemoKey(
2584
- goBinary,
2585
- resolved,
2586
- compilerEnv,
2587
- cwd,
2588
- );
2589
- if (memoKey !== null) {
2590
- const cached = goCompilerIdentityCache.get(memoKey);
2591
- if (cached !== undefined) {
2592
- return cached;
2593
- }
2594
- }
2595
- const identity = computeGoCompilerIdentity(
2596
- selected,
2597
- resolved,
2598
- compilerEnv,
2599
- cwd,
2600
- );
2601
- if (memoKey !== null) {
2602
- goCompilerIdentityCache.set(memoKey, identity);
2603
- }
2604
- return identity;
2605
- }
2606
-
2607
- // Build a memo key that pins both the resolved binary path and its current
2608
- // content. Returns null (skip caching, recompute) when the binary cannot be
2609
- // stat-ed, so the rare unstattable case never serves a stale identity.
2610
- function goCompilerIdentityMemoKey(
2611
- goBinary: string,
2612
- resolved: string,
2613
- env: NodeJS.ProcessEnv,
2614
- cwd: string,
2615
- ): string | null {
2616
- try {
2617
- const stat = fs.statSync(resolved, { bigint: true });
2618
- const context = crypto.createHash("sha256");
2619
- context.update(cwd);
2620
- for (const [key, value] of Object.entries(env).sort(([left], [right]) =>
2621
- left === right ? 0 : left < right ? -1 : 1,
2622
- )) {
2623
- if (value === undefined) continue;
2624
- context.update(`\0${key.length}:${key}${value.length}:${value}`);
2625
- }
2626
- return [
2627
- goBinary,
2628
- resolved,
2629
- stat.dev,
2630
- stat.ino,
2631
- stat.mode,
2632
- stat.size,
2633
- stat.mtimeNs,
2634
- stat.ctimeNs,
2635
- context.digest("hex"),
2636
- ].join("\0");
2637
- } catch {
2638
- return null;
2639
- }
2640
- }
2641
-
2642
- function computeGoCompilerIdentity(
2643
- goBinary: string,
2644
- resolved: string,
2645
- env: NodeJS.ProcessEnv,
2646
- cwd: string,
2647
- ): string {
2648
- if (!fs.existsSync(resolved)) {
2649
- return "missing";
2650
- }
2651
- const version = spawnGoTool(goBinary, ["version"], {
2652
- cwd,
2653
- encoding: "utf8",
2654
- env,
2655
- windowsHide: true,
2656
- });
2657
- const versionText =
2658
- version.error !== undefined
2659
- ? ((version.error as NodeJS.ErrnoException).code ?? version.error.message)
2660
- : `${version.status ?? 0}:${version.stdout}${version.stderr}`;
2661
- const binaryHash = hashFile(resolved);
2662
- return `sha256:${binaryHash}:${versionText}`;
2663
- }
2664
-
2665
- function resolveExecutableIdentityPath(
2666
- binary: string,
2667
- env: NodeJS.ProcessEnv = process.env,
2668
- cwd: string = process.cwd(),
2669
- ): string {
2670
- const resolved = findExecutablePath(binary, env, cwd);
2671
- return resolved === null ? binary : resolveRealPath(resolved);
2672
- }
2673
-
2674
- /** Pin Windows PATH and command-wrapper lookup to one build-wide target. */
2675
- function resolveGoToolForBuild(
2676
- binary: string,
2677
- env: NodeJS.ProcessEnv,
2678
- cwd: string,
2679
- ): string {
2680
- if (process.platform !== "win32") return binary;
2681
- return resolveWindowsGoTool(binary, env, cwd).location ?? binary;
2682
- }
2683
-
2684
- function findExecutablePath(
2685
- binary: string,
2686
- env: NodeJS.ProcessEnv,
2687
- cwd: string,
2688
- ): string | null {
2689
- for (const candidate of executableSearchBases(binary, env, cwd)) {
2690
- const resolved = findExecutableCandidate(candidate, env);
2691
- if (resolved !== null) return resolved;
2692
- }
2693
- return null;
2694
- }
2695
-
2696
- interface IWindowsGoToolResolution {
2697
- location: string | null;
2698
- wrapper: boolean;
2699
- }
2700
-
2701
- /** Preserve libuv's native target before falling back to cmd/bat wrappers. */
2702
- function resolveWindowsGoTool(
2703
- binary: string,
2704
- env: NodeJS.ProcessEnv,
2705
- cwd: string,
2706
- ): IWindowsGoToolResolution {
2707
- const candidates = executableSearchBases(binary, env, cwd);
2708
- if (isWindowsCommandWrapper(binary)) {
2709
- return {
2710
- location: candidates.find(isExecutableFile) ?? null,
2711
- wrapper: true,
2712
- };
2713
- }
2714
-
2715
- const hasExtension = windowsFileNameHasExtension(binary);
2716
- for (const candidate of candidates) {
2717
- if (hasExtension && isExecutableFile(candidate)) {
2718
- return { location: candidate, wrapper: false };
2719
- }
2720
- for (const extension of [".com", ".exe"]) {
2721
- const executable = candidate + extension;
2722
- if (isExecutableFile(executable)) {
2723
- return { location: executable, wrapper: false };
2724
- }
2725
- }
2726
- }
2727
-
2728
- const wrapperExtensions = windowsExecutableExtensions(env).filter((ext) =>
2729
- /\.(?:bat|cmd)$/i.test(ext),
2730
- );
2731
- for (const candidate of candidates) {
2732
- for (const extension of wrapperExtensions) {
2733
- const executable = candidate + extension;
2734
- if (isExecutableFile(executable)) {
2735
- return { location: executable, wrapper: true };
2736
- }
2737
- }
2738
- }
2739
- return { location: null, wrapper: false };
2740
- }
2741
-
2742
- function executableSearchBases(
2743
- binary: string,
2744
- env: NodeJS.ProcessEnv,
2745
- cwd: string,
2746
- ): string[] {
2747
- if (path.isAbsolute(binary)) return [binary];
2748
- if (hasPathQualifier(binary)) return [path.resolve(cwd, binary)];
2749
-
2750
- const directories =
2751
- process.platform === "win32"
2752
- ? splitWindowsSearchPath(readPathEnvironment(env))
2753
- // libuv skips only genuinely empty slices. A quoted-empty slice
2754
- // survives that check, unquotes to "", and therefore names cwd.
2755
- .filter((entry) => entry.length > 0)
2756
- .map(unquoteWindowsSearchEntry)
2757
- : readPathEnvironment(env).split(path.delimiter);
2758
- const noDefaultCurrentDirectory =
2759
- process.platform === "win32"
2760
- ? readWindowsEnvironmentValue(
2761
- process.env,
2762
- "NoDefaultCurrentDirectoryInExePath",
2763
- )
2764
- : undefined;
2765
- if (process.platform === "win32" && noDefaultCurrentDirectory === undefined) {
2766
- directories.unshift(cwd);
2767
- }
2768
- return directories.map((dir) => path.resolve(cwd, dir, binary));
2769
- }
2770
-
2771
- function findExecutableCandidate(
2772
- candidate: string,
2773
- env: NodeJS.ProcessEnv,
2774
- ): string | null {
2775
- if (isExecutableFile(candidate)) return candidate;
2776
- if (process.platform !== "win32") return null;
2777
- // Probe every PATHEXT extension, not just `.exe`, so a compiler backed by a
2778
- // `.cmd`/`.bat` wrapper is both launched correctly and hashed into the cache
2779
- // key. Otherwise the wrapper reads as missing and changes do not invalidate
2780
- // the cached plugin binary.
2781
- for (const ext of windowsExecutableExtensions(env)) {
2782
- const executable = `${candidate}${ext}`;
2783
- if (isExecutableFile(executable)) return executable;
2784
- }
2785
- return null;
2786
- }
2787
-
2788
- function isExecutableFile(location: string): boolean {
2789
- try {
2790
- return fs.statSync(location).isFile();
2791
- } catch {
2792
- return false;
2793
- }
2794
- }
2795
-
2796
- function hasPathQualifier(location: string): boolean {
2797
- return (
2798
- location.includes(path.sep) ||
2799
- (process.platform === "win32" &&
2800
- (location.includes("/") || /^[a-zA-Z]:/.test(location)))
2801
- );
2802
- }
2803
-
2804
- function windowsFileNameHasExtension(location: string): boolean {
2805
- const name = path.basename(location);
2806
- const dot = name.indexOf(".");
2807
- return dot >= 0 && dot < name.length - 1;
2808
- }
2809
-
2810
- function splitWindowsSearchPath(value: string): string[] {
2811
- const entries: string[] = [];
2812
- let start = 0;
2813
- let quote = "";
2814
- for (let index = 0; index < value.length; index++) {
2815
- const character = value[index]!;
2816
- if (quote !== "") {
2817
- if (character === quote) quote = "";
2818
- } else if ((character === '"' || character === "'") && index === start) {
2819
- quote = character;
2820
- } else if (character === ";") {
2821
- entries.push(value.slice(start, index));
2822
- start = index + 1;
2823
- }
2824
- }
2825
- entries.push(value.slice(start));
2826
- return entries;
2827
- }
2828
-
2829
- function unquoteWindowsSearchEntry(location: string): string {
2830
- const first = location[0];
2831
- const withoutFirst =
2832
- first === '"' || first === "'" ? location.slice(1) : location;
2833
- const last = withoutFirst[withoutFirst.length - 1];
2834
- return last === '"' || last === "'"
2835
- ? withoutFirst.slice(0, -1)
2836
- : withoutFirst;
2837
- }
2838
-
2839
- function windowsExecutableExtensions(
2840
- env: NodeJS.ProcessEnv = process.env,
2841
- ): readonly string[] {
2842
- const pathext = readWindowsEnvironmentValue(env, "PATHEXT");
2843
- const raw = pathext && pathext.length > 0 ? pathext : ".COM;.EXE;.BAT;.CMD";
2844
- return splitWindowsSearchPath(raw)
2845
- .map(unquoteWindowsSearchEntry)
2846
- .map((ext) => ext.toLowerCase())
2847
- .filter((ext) => ext.length > 0);
2848
- }
2849
-
2850
- function readPathEnvironment(env: NodeJS.ProcessEnv = process.env): string {
2851
- return process.platform === "win32"
2852
- ? (readWindowsEnvironmentValue(env, "PATH") ??
2853
- readWindowsEnvironmentValue(process.env, "PATH") ??
2854
- "")
2855
- : (env.PATH ?? "/usr/bin:/bin");
2856
- }
2857
-
2858
- function readWindowsEnvironmentValue(
2859
- env: NodeJS.ProcessEnv,
2860
- name: string,
2861
- ): string | undefined {
2862
- const exact = env[name];
2863
- if (exact !== undefined) return exact;
2864
- const normalized = name.toLowerCase();
2865
- const key = Object.keys(env)
2866
- .filter((candidate) => candidate.toLowerCase() === normalized)
2867
- .sort()[0];
2868
- return key === undefined ? undefined : env[key];
2869
- }
2870
-
2871
- function resolveRealPath(location: string): string {
2872
- try {
2873
- return fs.realpathSync(location);
2874
- } catch {
2875
- return location;
2876
- }
2877
- }
2878
-
2879
- function hashFile(file: string): string {
2880
- const hash = crypto.createHash("sha256");
2881
- hash.update(fs.readFileSync(file));
2882
- return hash.digest("hex");
2883
- }
2884
-
2885
- function hashGoBuildEnvironment(
2886
- hash: crypto.Hash,
2887
- goBinary: string | undefined,
2888
- cwd: string,
2889
- env: NodeJS.ProcessEnv,
2890
- filesystem: SourceBuildFilesystemOperations,
2891
- ): void {
2892
- const values = resolveGoBuildEnvironment(goBinary, cwd, env, filesystem);
2893
- for (const key of GO_BUILD_ENV_KEYS) {
2894
- const value = values.get(key);
2895
- if (value !== undefined && value !== "") {
2896
- hash.update(`${key}=${value}\n`);
2897
- }
2898
- }
2899
- }
2900
-
2901
- function resolveGoBuildEnvironment(
2902
- goBinary: string | undefined,
2903
- cwd: string,
2904
- env: NodeJS.ProcessEnv,
2905
- filesystem: SourceBuildFilesystemOperations,
2906
- ): Map<string, string> {
2907
- const values = new Map<string, string>();
2908
- if (goBinary !== undefined) {
2909
- const result = spawnGoTool(
2910
- goBinary,
2911
- ["env", "-json", ...GO_BUILD_ENV_KEYS],
2912
- {
2913
- cwd,
2914
- encoding: "utf8",
2915
- env: goBuildEnv(goBinary, undefined, env),
2916
- windowsHide: true,
2917
- },
2918
- );
2919
- if (result.error === undefined && result.status === 0) {
2920
- try {
2921
- const parsed = JSON.parse(result.stdout) as Record<string, unknown>;
2922
- for (const key of GO_BUILD_ENV_KEYS) {
2923
- const raw = parsed[key];
2924
- if (typeof raw === "string" && raw !== "") {
2925
- values.set(
2926
- key,
2927
- normalizeGoBuildEnvValue(key, raw, env, filesystem),
2928
- );
2929
- }
2930
- }
2931
- } catch {
2932
- // Fall back to the effective env below; a cache key is still better
2933
- // than failing before `go build` can produce the actionable error.
2934
- }
2935
- }
2936
- }
2937
- for (const key of GO_BUILD_ENV_KEYS) {
2938
- if (values.has(key)) continue;
2939
- const value = env[key];
2940
- if (value !== undefined && value !== "") {
2941
- values.set(key, normalizeGoBuildEnvValue(key, value, env, filesystem));
2942
- }
2943
- }
2944
- return values;
2945
- }
2946
-
2947
- function normalizeGoBuildEnvValue(
2948
- key: string,
2949
- value: string,
2950
- env: NodeJS.ProcessEnv,
2951
- filesystem: SourceBuildFilesystemOperations,
2952
- ): string {
2953
- if (key === "GOROOT") {
2954
- return resolveGoRootCacheIdentity(value, filesystem);
2955
- }
2956
- if (GO_BUILD_COMMAND_ENV_KEYS.has(key)) {
2957
- return `${value}\0${resolveCommandCacheIdentity(value, env)}`;
2958
- }
2959
- return value;
2960
- }
2961
-
2962
- function resolveCommandCacheIdentity(
2963
- command: string,
2964
- env: NodeJS.ProcessEnv,
2965
- ): string {
2966
- const executable = firstCommandToken(command);
2967
- if (executable === null) {
2968
- return "command:empty";
2969
- }
2970
- const resolved = resolveExecutableIdentityPath(executable, env);
2971
- if (!fs.existsSync(resolved)) {
2972
- return `command:missing:${executable}`;
2973
- }
2974
- try {
2975
- return `command:sha256:${hashFile(resolved)}`;
2976
- } catch {
2977
- return `command:unreadable:${resolved}`;
2978
- }
2979
- }
2980
-
2981
- function firstCommandToken(command: string): string | null {
2982
- const trimmed = command.trim();
2983
- if (trimmed === "") {
2984
- return null;
2985
- }
2986
- const quote = trimmed[0];
2987
- if (quote === "'" || quote === '"') {
2988
- const end = trimmed.indexOf(quote, 1);
2989
- return end === -1 ? trimmed.slice(1) : trimmed.slice(1, end);
2990
- }
2991
- return trimmed.split(/\s+/)[0] ?? null;
2992
- }
2993
-
2994
- function hashExternalGoBuildEnvironment(
2995
- hash: crypto.Hash,
2996
- env: NodeJS.ProcessEnv,
2997
- ): void {
2998
- for (const key of EXTERNAL_GO_BUILD_ENV_KEYS) {
2999
- const value = env[key];
3000
- if (value !== undefined && value !== "") {
3001
- hash.update(`${key}=${value}\n`);
3002
- }
3003
- }
3004
- }
3005
-
3006
- interface GoRootIdentitySnapshot {
3007
- complete: boolean;
3008
- files: string[];
3009
- signature: string;
3010
- }
3011
-
3012
- interface GoRootIdentityCacheEntry {
3013
- identity: string;
3014
- signature: string;
3015
- }
3016
-
3017
- // GOROOT is immutable during normal use but contributes roughly 140 MiB of
3018
- // source/tool content to every plugin key. Retain only the final pathless
3019
- // content identity, guarded by a fresh metadata manifest on every call. A
3020
- // changed or incomplete manifest falls through to the historical full read.
3021
- const goRootIdentityCache = new Map<string, GoRootIdentityCacheEntry>();
3022
-
3023
- function resolveGoRootCacheIdentity(
3024
- goRoot: string,
3025
- filesystem: SourceBuildFilesystemOperations,
3026
- ): string {
3027
- const resolved = resolveRealPath(goRoot);
3028
- if (!fs.existsSync(resolved)) {
3029
- return `missing:${goRoot}`;
3030
- }
3031
- const snapshot = collectGoRootIdentitySnapshot(resolved);
3032
- if (snapshot.complete) {
3033
- const cached = goRootIdentityCache.get(resolved);
3034
- if (cached?.signature === snapshot.signature) {
3035
- return cached.identity;
3036
- }
3037
- }
3038
- const hash = crypto.createHash("sha256");
3039
- for (const file of snapshot.files) {
3040
- const relative = path.relative(resolved, file).replace(/\\/g, "/");
3041
- hash.update(`f=${relative}\n`);
3042
- hash.update(filesystem.readFile(file));
3043
- hash.update("\n");
3044
- }
3045
- const identity = `sha256:${hash.digest("hex")}`;
3046
- if (snapshot.complete) {
3047
- goRootIdentityCache.set(resolved, {
3048
- identity,
3049
- signature: snapshot.signature,
3050
- });
3051
- }
3052
- return identity;
3053
- }
3054
-
3055
- function collectGoRootIdentitySnapshot(root: string): GoRootIdentitySnapshot {
3056
- const out: string[] = [];
3057
- const state = { complete: true };
3058
- walkGoRootIdentity(root, root, out, state);
3059
- out.sort();
3060
- const signature = crypto.createHash("sha256");
3061
- for (const file of out) {
3062
- const relative = path.relative(root, file).replace(/\\/g, "/");
3063
- try {
3064
- const stats = fs.statSync(file, { bigint: true });
3065
- if (!stats.isFile()) {
3066
- state.complete = false;
3067
- continue;
3068
- }
3069
- signature.update(
3070
- [
3071
- relative,
3072
- stats.dev,
3073
- stats.ino,
3074
- stats.mode,
3075
- stats.size,
3076
- stats.mtimeNs,
3077
- stats.ctimeNs,
3078
- ].join("\0"),
3079
- );
3080
- signature.update("\n");
3081
- } catch {
3082
- state.complete = false;
3083
- }
3084
- }
3085
- return {
3086
- complete: state.complete,
3087
- files: out,
3088
- signature: signature.digest("hex"),
3089
- };
3090
- }
3091
-
3092
- function walkGoRootIdentity(
3093
- root: string,
3094
- dir: string,
3095
- out: string[],
3096
- state: { complete: boolean },
3097
- ): void {
3098
- let entries: fs.Dirent[];
3099
- try {
3100
- entries = fs.readdirSync(dir, { withFileTypes: true });
3101
- } catch {
3102
- state.complete = false;
3103
- return;
3104
- }
3105
- for (const entry of entries) {
3106
- const file = path.join(dir, entry.name);
3107
- const rel = path.relative(root, file).replace(/\\/g, "/");
3108
- if (entry.isDirectory()) {
3109
- if (shouldHashGoRootPath(rel, true)) {
3110
- walkGoRootIdentity(root, file, out, state);
3111
- }
3112
- } else if (entry.isFile() && shouldHashGoRootPath(rel, false)) {
3113
- out.push(file);
3114
- }
3115
- }
3116
- }
3117
-
3118
- function shouldHashGoRootPath(rel: string, isDir: boolean): boolean {
3119
- if (rel === "") return true;
3120
- const parts = rel.split("/");
3121
- if (parts.includes(".git") || parts.includes("testdata")) return false;
3122
- if (!isDir && rel.endsWith("_test.go")) return false;
3123
-
3124
- const first = parts[0]!;
3125
- if (parts.length === 1) {
3126
- if (isDir) return ["bin", "pkg", "src", "lib"].includes(first);
3127
- return ["VERSION", "go.env"].includes(first);
3128
- }
3129
- if (first === "bin") {
3130
- if (isDir) return true;
3131
- const base = path.basename(rel);
3132
- return (
3133
- base === "go" ||
3134
- base === "go.exe" ||
3135
- base === "gofmt" ||
3136
- base === "gofmt.exe"
3137
- );
3138
- }
3139
- if (first === "pkg") {
3140
- const second = parts[1]!;
3141
- return second === "tool" || second === "include";
3142
- }
3143
- if (first === "src") {
3144
- if (!isDir && parts.length === 2) {
3145
- return ["go.mod", "go.sum"].includes(parts[1]!);
3146
- }
3147
- return parts[1] !== "cmd";
3148
- }
3149
- if (first === "lib") {
3150
- return parts[1] === "time";
3151
- }
3152
- return false;
3153
- }
3154
-
3155
- function touchCacheEntry(cacheDir: string): void {
3156
- try {
3157
- fs.mkdirSync(cacheDir, { recursive: true });
3158
- replaceCacheMetadataFile(
3159
- path.join(cacheDir, CACHE_LAST_USED_FILE),
3160
- `${Date.now()}\n`,
3161
- );
3162
- } catch {
3163
- // Cache hits must not fail because metadata touch failed.
3164
- }
3165
- }
3166
-
3167
- /** Test/internal controls for deterministic plugin-binary cache maintenance. */
3168
- export interface IPluginCachePruneOptions {
3169
- /** Ignore the once-daily marker. */
3170
- force?: boolean;
3171
- /** Size that triggers LRU pruning. */
3172
- maxBytes?: number;
3173
- /** Injected clock for deterministic tests. */
3174
- now?: number;
3175
- /** Recent-entry protection window. */
3176
- protectedAgeMs?: number;
3177
- /** Entries whose binary was returned by the current cold build. */
3178
- protectedEntries?: readonly string[];
3179
- /** Size to prune toward once the ceiling is crossed. */
3180
- targetBytes?: number;
3181
- }
3182
-
3183
- export function prunePluginCacheRoot(
3184
- root: string,
3185
- options: IPluginCachePruneOptions = {},
3186
- ): void {
3187
- try {
3188
- const cacheRoot = canonicalPluginCacheRoot(root);
3189
- const marker = path.join(cacheRoot, CACHE_GC_MARKER_FILE);
3190
- const now = options.now ?? Date.now();
3191
- const lastRun = readTimestamp(marker);
3192
- if (
3193
- options.force !== true &&
3194
- lastRun !== null &&
3195
- lastRun <= now &&
3196
- now - lastRun < PLUGIN_CACHE_GC_INTERVAL_MS
3197
- ) {
3198
- return;
3199
- }
3200
- const remainingBytes = prunePluginCacheEntries(cacheRoot, {
3201
- maxBytes: options.maxBytes ?? PLUGIN_CACHE_MAX_BYTES,
3202
- now,
3203
- protectedEntries: canonicalPluginCacheProtectedEntries(
3204
- cacheRoot,
3205
- options.protectedEntries ?? [],
3206
- ),
3207
- protectedAgeMs: options.protectedAgeMs ?? PLUGIN_CACHE_PROTECTED_AGE_MS,
3208
- targetBytes: options.targetBytes ?? PLUGIN_CACHE_TARGET_BYTES,
3209
- });
3210
- const maxBytes = options.maxBytes ?? PLUGIN_CACHE_MAX_BYTES;
3211
- const protectedAgeMs =
3212
- options.protectedAgeMs ?? PLUGIN_CACHE_PROTECTED_AGE_MS;
3213
- const markerTimestamp =
3214
- remainingBytes > maxBytes
3215
- ? now - PLUGIN_CACHE_GC_INTERVAL_MS + protectedAgeMs
3216
- : now;
3217
- replaceCacheMetadataFile(marker, `${markerTimestamp}\n`);
3218
- } catch {
3219
- // Plugin-cache GC is opportunistic; builds still proceed when it fails.
3220
- }
3221
- }
3222
-
3223
- /** Resolve explicit GC exclusions without allowing an alias outside root. */
3224
- function canonicalPluginCacheProtectedEntries(
3225
- root: string,
3226
- entries: readonly string[],
3227
- ): Set<string> {
3228
- const protectedEntries = new Set<string>();
3229
- for (const entry of entries) {
3230
- const candidate = path.resolve(entry);
3231
- const stats = fs.lstatSync(candidate);
3232
- if (!stats.isDirectory() || stats.isSymbolicLink()) {
3233
- throw new Error(`ttsc: unsafe protected plugin cache entry: ${entry}`);
3234
- }
3235
- const physical = fs.realpathSync.native(candidate);
3236
- if (path.dirname(physical) !== root) {
3237
- throw new Error(
3238
- `ttsc: protected plugin cache entry escaped root: ${entry}`,
3239
- );
3240
- }
3241
- protectedEntries.add(physical);
3242
- }
3243
- return protectedEntries;
3244
- }
3245
-
3246
- /** Pin the default plugin cache to one ordinary physical directory. */
3247
- function canonicalPluginCacheRoot(root: string): string {
3248
- fs.mkdirSync(root, { recursive: true });
3249
- const physicalParent = fs.realpathSync.native(path.dirname(root));
3250
- const stats = fs.lstatSync(root);
3251
- if (!stats.isDirectory() || stats.isSymbolicLink()) {
3252
- throw new Error(`ttsc: unsafe plugin cache root: ${root}`);
3253
- }
3254
- // If an ancestor alias is retargeted after this point, all later cache work
3255
- // stays on the original physical directory rather than following it.
3256
- const physicalRoot = fs.realpathSync.native(root);
3257
- if (path.dirname(physicalRoot) !== physicalParent) {
3258
- throw new Error(`ttsc: plugin cache root escaped its parent: ${root}`);
3259
- }
3260
- return physicalRoot;
3261
- }
3262
-
3263
- /** Create one content-addressed cache entry without following a leaf alias. */
3264
- function canonicalPluginCacheEntry(root: string, key: string): string {
3265
- const directory = path.join(root, key);
3266
- fs.mkdirSync(directory, { recursive: true });
3267
- const stats = fs.lstatSync(directory);
3268
- if (!stats.isDirectory() || stats.isSymbolicLink()) {
3269
- throw new Error(`ttsc: unsafe plugin cache entry: ${directory}`);
3270
- }
3271
- const physicalDirectory = fs.realpathSync.native(directory);
3272
- if (path.dirname(physicalDirectory) !== root) {
3273
- throw new Error(`ttsc: plugin cache entry escaped its root: ${directory}`);
3274
- }
3275
- return physicalDirectory;
3276
- }
3277
-
3278
- function prunePluginCacheEntries(
3279
- root: string,
3280
- options: {
3281
- maxBytes: number;
3282
- now: number;
3283
- protectedAgeMs: number;
3284
- protectedEntries: ReadonlySet<string>;
3285
- targetBytes: number;
3286
- },
3287
- ): number {
3288
- const entries = collectPluginCacheEntries(root, options.now);
3289
- for (const entry of entries) {
3290
- if (
3291
- options.now - entry.lastUsedAt <= PLUGIN_CACHE_ENTRY_MAX_AGE_MS ||
3292
- options.protectedEntries.has(entry.dir) ||
3293
- pluginCacheEntryHasActiveBuild(entry, options.now)
3294
- ) {
3295
- continue;
3296
- }
3297
- removeCacheEntry(entry);
3298
- }
3299
-
3300
- const remaining = collectPluginCacheEntries(root, options.now);
3301
- let total = remaining.reduce((sum, entry) => sum + entry.size, 0);
3302
- if (total <= options.maxBytes) {
3303
- return total;
3304
- }
3305
- const protectedEntries = new Set<string>(options.protectedEntries);
3306
- let protectedBytes = 0;
3307
- for (const entry of [...remaining].sort(
3308
- (a, b) => b.lastUsedAt - a.lastUsedAt,
3309
- )) {
3310
- if (pluginCacheEntryHasActiveBuild(entry, options.now)) {
3311
- protectedEntries.add(entry.dir);
3312
- continue;
3313
- }
3314
- if (options.now - entry.lastUsedAt > options.protectedAgeMs) continue;
3315
- if (protectedBytes >= options.targetBytes) continue;
3316
- if (protectedBytes + entry.size > options.targetBytes) continue;
3317
- protectedEntries.add(entry.dir);
3318
- protectedBytes += entry.size;
3319
- }
3320
- for (const entry of remaining.sort((a, b) => a.lastUsedAt - b.lastUsedAt)) {
3321
- if (total <= options.targetBytes) {
3322
- return total;
3323
- }
3324
- if (protectedEntries.has(entry.dir)) continue;
3325
- if (removeCacheEntry(entry)) total -= entry.size;
3326
- }
3327
- return total;
3328
- }
3329
-
3330
- /** Conservatively protect an entry while any build generation owns its key. */
3331
- function pluginCacheEntryHasActiveBuild(
3332
- entry: PluginCacheEntry,
3333
- now: number,
3334
- ): boolean {
3335
- const lockDir = `${entry.dir}.lock`;
3336
- try {
3337
- return inspectPluginBuildLock(lockDir, now).state === "active";
3338
- } catch {
3339
- // Malformed or unreadable coordination state cannot disprove ownership.
3340
- return true;
3341
- }
3342
- }
3343
-
3344
- /** Test/internal controls for deterministic Go object-cache maintenance. */
3345
- export interface IGoBuildCachePruneOptions {
3346
- /** Ignore the once-daily marker. */
3347
- force?: boolean;
3348
- /** Size that triggers LRU pruning. */
3349
- maxBytes?: number;
3350
- /** Size to prune toward once the ceiling is crossed. */
3351
- targetBytes?: number;
3352
- /** Injected clock for deterministic tests. */
3353
- now?: number;
3354
- /** Recent-file protection window. */
3355
- protectedAgeMs?: number;
3356
- }
3357
-
3358
- /**
3359
- * Opportunistically bound one ttsc-owned Go object cache.
3360
- *
3361
- * A maintenance intent blocks new build leases. If any existing lease remains,
3362
- * maintenance yields without touching the cache; the next invocation retries.
3363
- * Only Go's two-hex object directories are scanned, so coordination metadata
3364
- * and Go's own trim marker remain outside the size policy.
3365
- */
3366
- export function pruneGoBuildCacheRoot(
3367
- root: string,
3368
- options: IGoBuildCachePruneOptions = {},
3369
- ): void {
3370
- let intent: GoBuildCacheCoordinationRecord | undefined;
3371
- try {
3372
- const cacheRoot = canonicalGoBuildCacheRoot(root);
3373
- const marker = path.join(cacheRoot, GO_BUILD_CACHE_GC_MARKER_FILE);
3374
- const now = options.now ?? Date.now();
3375
- const lastRun = readTimestamp(marker);
3376
- if (
3377
- options.force !== true &&
3378
- lastRun !== null &&
3379
- lastRun <= now &&
3380
- now - lastRun < GO_BUILD_CACHE_GC_INTERVAL_MS
3381
- ) {
3382
- return;
3383
- }
3384
-
3385
- intent = createGoBuildCacheCoordinationRecord(
3386
- cacheRoot,
3387
- GO_BUILD_CACHE_MAINTENANCE_DIR,
3388
- );
3389
- if (!intent.startHeartbeat()) {
3390
- // Maintenance is opportunistic. Without an independent heartbeat a
3391
- // synchronous scan could look abandoned while it is still deleting, so
3392
- // yield instead of weakening the build/maintenance exclusion.
3393
- return;
3394
- }
3395
- if (
3396
- collectLiveGoBuildCacheCoordinationRecords(
3397
- cacheRoot,
3398
- GO_BUILD_CACHE_LEASE_DIR,
3399
- now,
3400
- ).length !== 0
3401
- ) {
3402
- return;
3403
- }
3404
-
3405
- const remainingBytes = pruneGoBuildCacheEntries(cacheRoot, {
3406
- maxBytes: options.maxBytes ?? GO_BUILD_CACHE_MAX_BYTES,
3407
- now,
3408
- protectedAgeMs: options.protectedAgeMs ?? GO_BUILD_CACHE_PROTECTED_AGE_MS,
3409
- targetBytes: options.targetBytes ?? GO_BUILD_CACHE_TARGET_BYTES,
3410
- });
3411
- // If recent protection or a transient delete failure left the cache above
3412
- // the ceiling, retry after the protection window instead of suppressing
3413
- // every maintenance attempt for a full day.
3414
- const maxBytes = options.maxBytes ?? GO_BUILD_CACHE_MAX_BYTES;
3415
- const protectedAgeMs =
3416
- options.protectedAgeMs ?? GO_BUILD_CACHE_PROTECTED_AGE_MS;
3417
- const markerTimestamp =
3418
- remainingBytes > maxBytes
3419
- ? now - GO_BUILD_CACHE_GC_INTERVAL_MS + protectedAgeMs
3420
- : now;
3421
- replaceCacheMetadataFile(marker, `${markerTimestamp}\n`);
3422
- } catch {
3423
- // Go-cache GC is opportunistic; builds still proceed when it fails.
3424
- } finally {
3425
- intent?.finish();
3426
- }
3427
- }
3428
-
3429
- /**
3430
- * Run one Go build under a cross-process cache lease when ttsc owns the cache.
3431
- *
3432
- * The lease is published before checking maintenance. A maintenance process
3433
- * that arrived first keeps its intent visible, so this builder withdraws and
3434
- * retries; one that arrives second sees the lease and yields. That ordering
3435
- * closes the scan/start race without serializing independent Go builds.
3436
- */
3437
- export function withGoBuildCacheLease<T>(
3438
- root: string,
3439
- managed: boolean,
3440
- callback: (cacheRoot: string) => T,
3441
- ): T {
3442
- if (!managed) {
3443
- return callback(root);
3444
- }
3445
- const cacheRoot = canonicalGoBuildCacheRoot(root);
3446
- const started = Date.now();
3447
- for (;;) {
3448
- const lease = createGoBuildCacheCoordinationRecord(
3449
- cacheRoot,
3450
- GO_BUILD_CACHE_LEASE_DIR,
3451
- );
3452
- const maintenance = collectLiveGoBuildCacheCoordinationRecords(
3453
- cacheRoot,
3454
- GO_BUILD_CACHE_MAINTENANCE_DIR,
3455
- Date.now(),
3456
- );
3457
- if (maintenance.length === 0) {
3458
- try {
3459
- if (!lease.startHeartbeat()) {
3460
- throw new Error(
3461
- `ttsc: unable to start Go build cache lease heartbeat at ${cacheRoot}`,
3462
- );
3463
- }
3464
- return callback(cacheRoot);
3465
- } finally {
3466
- lease.finish();
3467
- }
3468
- }
3469
- lease.finish();
3470
- if (Date.now() - started > PLUGIN_BUILD_LOCK_STEAL_MS) {
3471
- throw new Error(
3472
- `ttsc: timed out waiting for Go build cache maintenance at ${cacheRoot}`,
3473
- );
3474
- }
3475
- sleepSync(GO_BUILD_CACHE_COORDINATION_POLL_MS);
3476
- }
3477
- }
3478
-
3479
- /**
3480
- * Create and pin the owned Go cache to an ordinary physical directory.
3481
- *
3482
- * The leaf may be user-controlled inside `node_modules/.cache`; accepting a
3483
- * symlink or junction there would let LRU deletion escape into an arbitrary
3484
- * two-hex directory. Returning the canonical spelling also keeps the build,
3485
- * leases, and maintenance on the same directory if an ancestor alias moves.
3486
- */
3487
- function canonicalGoBuildCacheRoot(root: string): string {
3488
- fs.mkdirSync(root, { recursive: true });
3489
- const physicalParent = fs.realpathSync.native(path.dirname(root));
3490
- const stats = fs.lstatSync(root);
3491
- if (!stats.isDirectory() || stats.isSymbolicLink()) {
3492
- throw new Error(`ttsc: unsafe Go build cache root: ${root}`);
3493
- }
3494
- const physicalRoot = fs.realpathSync.native(root);
3495
- if (path.dirname(physicalRoot) !== physicalParent) {
3496
- throw new Error(`ttsc: Go build cache root escaped its parent: ${root}`);
3497
- }
3498
- return physicalRoot;
3499
- }
3500
-
3501
- interface GoBuildCacheObject {
3502
- file: string;
3503
- lastUsedAt: number;
3504
- size: number;
3505
- }
3506
-
3507
- /** Prune oldest Go cache objects to the requested deterministic size target. */
3508
- function pruneGoBuildCacheEntries(
3509
- root: string,
3510
- options: {
3511
- maxBytes: number;
3512
- now: number;
3513
- protectedAgeMs: number;
3514
- targetBytes: number;
3515
- },
3516
- ): number {
3517
- const entries = collectGoBuildCacheObjects(root);
3518
- let total = entries.reduce((sum, entry) => sum + entry.size, 0);
3519
- if (total <= options.maxBytes) {
3520
- return total;
3521
- }
3522
- // Protect the newest recent objects only up to one target-sized cohort
3523
- // reserve. Protecting every object younger than an hour would let repeated
3524
- // 2.9 GiB cold builds grow without bound during that hour.
3525
- const protectedFiles = new Set<string>();
3526
- let protectedBytes = 0;
3527
- for (const entry of [...entries].sort(
3528
- (a, b) => b.lastUsedAt - a.lastUsedAt,
3529
- )) {
3530
- if (
3531
- options.now - entry.lastUsedAt >
3532
- options.protectedAgeMs + GO_BUILD_CACHE_ACCESS_MTIME_GRANULARITY_MS
3533
- ) {
3534
- continue;
3535
- }
3536
- if (protectedBytes >= options.targetBytes) {
3537
- break;
3538
- }
3539
- if (protectedBytes + entry.size > options.targetBytes) {
3540
- break;
3541
- }
3542
- protectedFiles.add(entry.file);
3543
- protectedBytes += entry.size;
3544
- }
3545
- for (const entry of entries.sort((a, b) => a.lastUsedAt - b.lastUsedAt)) {
3546
- if (total <= options.targetBytes) {
3547
- return total;
3548
- }
3549
- if (protectedFiles.has(entry.file)) {
3550
- continue;
3551
- }
3552
- try {
3553
- fs.rmSync(entry.file, { force: true });
3554
- total -= entry.size;
3555
- } catch {
3556
- // A concurrent antivirus/indexer can transiently hold a file on Windows.
3557
- }
3558
- }
3559
- return total;
3560
- }
3561
-
3562
- function collectGoBuildCacheObjects(root: string): GoBuildCacheObject[] {
3563
- const output: GoBuildCacheObject[] = [];
3564
- let buckets: fs.Dirent[];
3565
- try {
3566
- buckets = fs.readdirSync(root, { withFileTypes: true });
3567
- } catch {
3568
- return output;
3569
- }
3570
- for (const bucket of buckets) {
3571
- if (!bucket.isDirectory() || !/^[0-9a-f]{2}$/.test(bucket.name)) {
3572
- continue;
3573
- }
3574
- const directory = path.join(root, bucket.name);
3575
- let files: fs.Dirent[];
3576
- try {
3577
- files = fs.readdirSync(directory, { withFileTypes: true });
3578
- } catch {
3579
- continue;
3580
- }
3581
- for (const file of files) {
3582
- if (!file.isFile()) {
3583
- continue;
3584
- }
3585
- const absolute = path.join(directory, file.name);
3586
- try {
3587
- const stats = fs.statSync(absolute);
3588
- output.push({
3589
- file: absolute,
3590
- lastUsedAt: stats.mtimeMs,
3591
- size: stats.size,
3592
- });
3593
- } catch {}
3594
- }
3595
- }
3596
- return output;
3597
- }
3598
-
3599
- interface GoBuildCacheCoordinationRecord {
3600
- file: string;
3601
- finish: () => void;
3602
- startHeartbeat: () => boolean;
3603
- }
3604
-
3605
- function createGoBuildCacheCoordinationRecord(
3606
- root: string,
3607
- directoryName: string,
3608
- ): GoBuildCacheCoordinationRecord {
3609
- const directory = goBuildCacheCoordinationDirectory(
3610
- root,
3611
- directoryName,
3612
- true,
3613
- )!;
3614
- const record = path.join(
3615
- directory,
3616
- `${process.pid}-${crypto.randomBytes(16).toString("hex")}.json`,
3617
- );
3618
- const metadata = {
3619
- directoryName,
3620
- hostname: os.hostname(),
3621
- pid: process.pid,
3622
- startedAt: Date.now(),
3623
- };
3624
- writeGoBuildCacheCoordinationRecord(record, metadata, "active");
3625
- let heartbeat: GoBuildCacheHeartbeat | undefined;
3626
- return {
3627
- file: record,
3628
- finish: () => {
3629
- heartbeat?.stop();
3630
- heartbeat = undefined;
3631
- // A failed unlink must not leave a completed task looking active until
3632
- // its stale timeout. Persist completion first; collectors discard it.
3633
- try {
3634
- writeGoBuildCacheCoordinationRecord(record, metadata, "complete");
3635
- } catch {}
3636
- try {
3637
- fs.rmSync(record, { force: true });
3638
- } catch {}
3639
- },
3640
- startHeartbeat: () => {
3641
- heartbeat ??= startGoBuildCacheHeartbeat(record);
3642
- return heartbeat !== undefined;
3643
- },
3644
- };
3645
- }
3646
-
3647
- function writeGoBuildCacheCoordinationRecord(
3648
- file: string,
3649
- metadata: {
3650
- directoryName: string;
3651
- hostname: string;
3652
- pid: number;
3653
- startedAt: number;
3654
- },
3655
- status: "active" | "complete",
3656
- ): void {
3657
- replaceCacheMetadataFile(
3658
- file,
3659
- `${JSON.stringify({ ...metadata, status, version: 1 })}\n`,
3660
- );
3661
- }
3662
-
3663
- interface GoBuildCacheHeartbeat {
3664
- stop: () => void;
3665
- }
3666
-
3667
- /** Refresh one synchronous cache task's record from a background worker. */
3668
- function startGoBuildCacheHeartbeat(
3669
- file: string,
3670
- ): GoBuildCacheHeartbeat | undefined {
3671
- const control = new SharedArrayBuffer(4);
3672
- const state = new Int32Array(control);
3673
- try {
3674
- const worker = new Worker(
3675
- [
3676
- 'const fs = process.getBuiltinModule("node:fs");',
3677
- 'const { workerData } = process.getBuiltinModule("node:worker_threads");',
3678
- "const state = new Int32Array(workerData.control);",
3679
- "for (;;) {",
3680
- " const result = Atomics.wait(state, 0, 0, workerData.interval);",
3681
- ' if (result !== "timed-out" || Atomics.load(state, 0) !== 0) break;',
3682
- " try {",
3683
- " const now = new Date();",
3684
- " fs.utimesSync(workerData.file, now, now);",
3685
- " } catch {}",
3686
- "}",
3687
- ].join("\n"),
3688
- {
3689
- eval: true,
3690
- workerData: {
3691
- control,
3692
- file,
3693
- interval: GO_BUILD_CACHE_COORDINATION_HEARTBEAT_MS,
3694
- },
3695
- },
3696
- );
3697
- worker.unref();
3698
- return {
3699
- stop: () => {
3700
- Atomics.store(state, 0, 1);
3701
- Atomics.notify(state, 0);
3702
- void worker.terminate();
3703
- },
3704
- };
3705
- } catch {}
3706
-
3707
- // Node's permission model can deny Worker construction while still allowing
3708
- // the child process required for `go build`. An IPC-bound helper provides
3709
- // the same independent heartbeat and exits automatically if its parent dies.
3710
- try {
3711
- const child = spawn(
3712
- process.execPath,
3713
- [
3714
- "-e",
3715
- [
3716
- 'const fs = require("node:fs");',
3717
- "const file = process.argv[1];",
3718
- "const interval = Number(process.argv[2]);",
3719
- "const timer = setInterval(() => {",
3720
- " try {",
3721
- " const now = new Date();",
3722
- " fs.utimesSync(file, now, now);",
3723
- " } catch {}",
3724
- "}, interval);",
3725
- 'process.on("disconnect", () => {',
3726
- " clearInterval(timer);",
3727
- " process.exit(0);",
3728
- "});",
3729
- ].join("\n"),
3730
- file,
3731
- String(GO_BUILD_CACHE_COORDINATION_HEARTBEAT_MS),
3732
- ],
3733
- {
3734
- stdio: ["ignore", "ignore", "ignore", "ipc"],
3735
- windowsHide: true,
3736
- },
3737
- );
3738
- child.unref();
3739
- child.channel?.unref();
3740
- return {
3741
- stop: () => {
3742
- if (child.connected) child.disconnect();
3743
- child.kill();
3744
- },
3745
- };
3746
- } catch {
3747
- return undefined;
3748
- }
3749
- }
3750
-
3751
- function collectLiveGoBuildCacheCoordinationRecords(
3752
- root: string,
3753
- directoryName: string,
3754
- now: number,
3755
- ): string[] {
3756
- const directory = goBuildCacheCoordinationDirectory(
3757
- root,
3758
- directoryName,
3759
- false,
3760
- );
3761
- if (directory === undefined) return [];
3762
- let records: fs.Dirent[];
3763
- try {
3764
- records = fs.readdirSync(directory, { withFileTypes: true });
3765
- } catch (error) {
3766
- if ((error as NodeJS.ErrnoException).code === "ENOENT") return [];
3767
- throw error;
3768
- }
3769
- const live: string[] = [];
3770
- for (const record of records) {
3771
- if (!record.isFile()) {
3772
- continue;
3773
- }
3774
- const file = path.join(directory, record.name);
3775
- if (goBuildCacheCoordinationRecordIsLive(file, directoryName, now)) {
3776
- live.push(file);
3777
- continue;
3778
- }
3779
- try {
3780
- fs.rmSync(file, { force: true });
3781
- } catch {}
3782
- }
3783
- return live;
3784
- }
3785
-
3786
- /**
3787
- * Resolve one private coordination directory without following a project-
3788
- * supplied symlink or junction outside the owned Go cache.
3789
- */
3790
- function goBuildCacheCoordinationDirectory(
3791
- root: string,
3792
- directoryName: string,
3793
- create: boolean,
3794
- ): string | undefined {
3795
- if (create) fs.mkdirSync(root, { recursive: true });
3796
- const directory = path.join(root, directoryName);
3797
- if (create) {
3798
- try {
3799
- fs.mkdirSync(directory);
3800
- } catch (error) {
3801
- if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
3802
- }
3803
- }
3804
- let stats: fs.Stats;
3805
- try {
3806
- stats = fs.lstatSync(directory);
3807
- } catch (error) {
3808
- if (!create && (error as NodeJS.ErrnoException).code === "ENOENT") {
3809
- return undefined;
3810
- }
3811
- throw error;
3812
- }
3813
- if (!stats.isDirectory() || stats.isSymbolicLink()) {
3814
- throw new Error(
3815
- `ttsc: unsafe Go build cache coordination directory: ${directory}`,
3816
- );
3817
- }
3818
- const physicalRoot = fs.realpathSync.native(root);
3819
- const physicalDirectory = fs.realpathSync.native(directory);
3820
- if (path.dirname(physicalDirectory) !== physicalRoot) {
3821
- throw new Error(
3822
- `ttsc: Go build cache coordination directory escaped its root: ${directory}`,
3823
- );
3824
- }
3825
- return physicalDirectory;
3826
- }
3827
-
3828
- function goBuildCacheCoordinationRecordIsLive(
3829
- file: string,
3830
- directoryName: string,
3831
- now: number,
3832
- ): boolean {
3833
- let contents: string | undefined;
3834
- try {
3835
- contents = fs.readFileSync(file, "utf8");
3836
- const parsed = JSON.parse(contents) as Record<string, unknown>;
3837
- if (parsed.status === "complete") return false;
3838
- // Parse valid records for forward compatibility, but do not equate a PID's
3839
- // lifetime with one task. A failed unlink can leave a record owned by a
3840
- // still-running Vite process, while a dead Node parent can leave its
3841
- // spawnSync Go child alive. The heartbeat/grace below models the task.
3842
- void parsed;
3843
- } catch {}
3844
- try {
3845
- const age = now - fs.statSync(file).mtimeMs;
3846
- if (age < -GO_BUILD_CACHE_COORDINATION_CLOCK_SKEW_MS) {
3847
- // A restored cache can carry a far-future timestamp, but the same state
3848
- // also occurs when the system clock moves backward during a real build.
3849
- // Rebase the record and grant one ordinary grace period; an active
3850
- // heartbeat keeps refreshing it, while an orphan then expires normally.
3851
- // Treat a failed rebase as live too: the safe failure mode is to defer
3852
- // opportunistic maintenance, never to delete under a possibly live Go.
3853
- // Replace the directory entry rather than changing its inode in place.
3854
- // A restored or user-modified cache can contain a hard-linked record;
3855
- // utimesSync(file) would then mutate metadata outside the owned cache.
3856
- if (contents !== undefined) {
3857
- try {
3858
- replaceCacheMetadataFile(file, contents);
3859
- } catch {}
3860
- }
3861
- return true;
3862
- }
3863
- const staleMs =
3864
- directoryName === GO_BUILD_CACHE_MAINTENANCE_DIR
3865
- ? GO_BUILD_CACHE_MAINTENANCE_STALE_MS
3866
- : GO_BUILD_CACHE_COORDINATION_STALE_MS;
3867
- return age <= staleMs;
3868
- } catch (error) {
3869
- return (error as NodeJS.ErrnoException).code !== "ENOENT";
3870
- }
3871
- }
3872
-
3873
- interface PluginCacheEntry {
3874
- dir: string;
3875
- lastUsedAt: number;
3876
- size: number;
3877
- }
3878
-
3879
- function collectPluginCacheEntries(
3880
- root: string,
3881
- now: number,
3882
- ): PluginCacheEntry[] {
3883
- const entries: PluginCacheEntry[] = [];
3884
- let dirents: fs.Dirent[];
3885
- try {
3886
- dirents = fs.readdirSync(root, { withFileTypes: true });
3887
- } catch {
3888
- return entries;
3889
- }
3890
- for (const dirent of dirents) {
3891
- if (
3892
- !dirent.isDirectory() ||
3893
- dirent.name.endsWith(".lock") ||
3894
- dirent.name.includes(".lock.")
3895
- ) {
3896
- continue;
3897
- }
3898
- const dir = path.join(root, dirent.name);
3899
- const lastUsedAt = readCacheEntryLastUsedAt(dir, now);
3900
- entries.push({
3901
- dir,
3902
- lastUsedAt,
3903
- size: directorySize(dir),
3904
- });
3905
- }
3906
- return entries;
3907
- }
3908
-
3909
- function readCacheEntryLastUsedAt(dir: string, now: number): number {
3910
- const touched = readTimestamp(path.join(dir, CACHE_LAST_USED_FILE));
3911
- if (touched !== null) {
3912
- return touched;
3913
- }
3914
- for (const name of ["plugin", "plugin.exe"]) {
3915
- try {
3916
- return fs.statSync(path.join(dir, name)).mtimeMs;
3917
- } catch {}
3918
- }
3919
- try {
3920
- return fs.statSync(dir).mtimeMs;
3921
- } catch {
3922
- return now;
3923
- }
3924
- }
3925
-
3926
- function readTimestamp(file: string): number | null {
3927
- try {
3928
- const text = fs.readFileSync(file, "utf8").trim();
3929
- const value = Number(text);
3930
- if (Number.isFinite(value)) {
3931
- return value;
3932
- }
3933
- } catch {}
3934
- try {
3935
- return fs.statSync(file).mtimeMs;
3936
- } catch {
3937
- return null;
3938
- }
3939
- }
3940
-
3941
- /** Replace cache metadata without following a pre-existing link or hard link. */
3942
- function replaceCacheMetadataFile(file: string, contents: string): void {
3943
- const temporary = path.join(
3944
- path.dirname(file),
3945
- `.${path.basename(file)}.${process.pid}-${crypto
3946
- .randomBytes(16)
3947
- .toString("hex")}.tmp`,
3948
- );
3949
- try {
3950
- fs.writeFileSync(temporary, contents, { encoding: "utf8", flag: "wx" });
3951
- // rename replaces the directory entry itself. Unlike writeFile(file), it
3952
- // cannot follow a symlink or mutate another hard link to the old inode.
3953
- fs.renameSync(temporary, file);
3954
- } finally {
3955
- try {
3956
- fs.rmSync(temporary, { force: true });
3957
- } catch {}
3958
- }
3959
- }
3960
-
3961
- function directorySize(dir: string): number {
3962
- let total = 0;
3963
- let entries: fs.Dirent[];
3964
- try {
3965
- entries = fs.readdirSync(dir, { withFileTypes: true });
3966
- } catch {
3967
- return total;
3968
- }
3969
- for (const entry of entries) {
3970
- const file = path.join(dir, entry.name);
3971
- try {
3972
- if (entry.isDirectory()) {
3973
- total += directorySize(file);
3974
- } else if (entry.isFile()) {
3975
- total += fs.statSync(file).size;
3976
- }
3977
- } catch {}
3978
- }
3979
- return total;
3980
- }
3981
-
3982
- function removeCacheEntry(entry: PluginCacheEntry): boolean {
3983
- try {
3984
- fs.rmSync(entry.dir, { recursive: true, force: true });
3985
- return !fs.existsSync(entry.dir);
3986
- } catch {
3987
- // Windows may reject removal while a plugin binary is still running.
3988
- return false;
3989
- }
3990
- }