@soundscript/soundscript 0.1.13 → 0.1.15

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 (441) hide show
  1. package/package.json +15 -6
  2. package/project-transform/index.js +2 -0
  3. package/project-transform/index.ts +8 -0
  4. package/project-transform/src/annotation_syntax.js +948 -0
  5. package/project-transform/src/annotation_syntax.ts +1217 -0
  6. package/project-transform/src/build_package.js +475 -0
  7. package/project-transform/src/build_package.ts +683 -0
  8. package/project-transform/src/bundled/portable-web-globals.d.ts +153 -0
  9. package/project-transform/src/bundled/runtime_externs.js +220 -0
  10. package/project-transform/src/bundled/runtime_externs.ts +237 -0
  11. package/project-transform/src/bundled/sound-libs/lib.decorators.d.ts +385 -0
  12. package/project-transform/src/bundled/sound-libs/lib.decorators.legacy.d.ts +22 -0
  13. package/project-transform/src/bundled/sound-libs/lib.dom.asynciterable.d.ts +42 -0
  14. package/project-transform/src/bundled/sound-libs/lib.dom.d.ts +39440 -0
  15. package/project-transform/src/bundled/sound-libs/lib.es2015.collection.d.ts +149 -0
  16. package/project-transform/src/bundled/sound-libs/lib.es2015.core.d.ts +657 -0
  17. package/project-transform/src/bundled/sound-libs/lib.es2015.d.ts +28 -0
  18. package/project-transform/src/bundled/sound-libs/lib.es2015.generator.d.ts +77 -0
  19. package/project-transform/src/bundled/sound-libs/lib.es2015.iterable.d.ts +616 -0
  20. package/project-transform/src/bundled/sound-libs/lib.es2015.promise.d.ts +80 -0
  21. package/project-transform/src/bundled/sound-libs/lib.es2015.proxy.d.ts +128 -0
  22. package/project-transform/src/bundled/sound-libs/lib.es2015.reflect.d.ts +144 -0
  23. package/project-transform/src/bundled/sound-libs/lib.es2015.symbol.d.ts +46 -0
  24. package/project-transform/src/bundled/sound-libs/lib.es2015.symbol.wellknown.d.ts +170 -0
  25. package/project-transform/src/bundled/sound-libs/lib.es2016.array.include.d.ts +116 -0
  26. package/project-transform/src/bundled/sound-libs/lib.es2016.d.ts +21 -0
  27. package/project-transform/src/bundled/sound-libs/lib.es2017.arraybuffer.d.ts +21 -0
  28. package/project-transform/src/bundled/sound-libs/lib.es2017.d.ts +26 -0
  29. package/project-transform/src/bundled/sound-libs/lib.es2017.date.d.ts +31 -0
  30. package/project-transform/src/bundled/sound-libs/lib.es2017.object.d.ts +49 -0
  31. package/project-transform/src/bundled/sound-libs/lib.es2017.string.d.ts +45 -0
  32. package/project-transform/src/bundled/sound-libs/lib.es2017.typedarrays.d.ts +53 -0
  33. package/project-transform/src/bundled/sound-libs/lib.es2018.asyncgenerator.d.ts +77 -0
  34. package/project-transform/src/bundled/sound-libs/lib.es2018.asynciterable.d.ts +57 -0
  35. package/project-transform/src/bundled/sound-libs/lib.es2018.d.ts +24 -0
  36. package/project-transform/src/bundled/sound-libs/lib.es2018.promise.d.ts +30 -0
  37. package/project-transform/src/bundled/sound-libs/lib.es2018.regexp.d.ts +37 -0
  38. package/project-transform/src/bundled/sound-libs/lib.es2019.array.d.ts +79 -0
  39. package/project-transform/src/bundled/sound-libs/lib.es2019.d.ts +24 -0
  40. package/project-transform/src/bundled/sound-libs/lib.es2019.object.d.ts +47 -0
  41. package/project-transform/src/bundled/sound-libs/lib.es2019.string.d.ts +37 -0
  42. package/project-transform/src/bundled/sound-libs/lib.es2019.symbol.d.ts +24 -0
  43. package/project-transform/src/bundled/sound-libs/lib.es2020.bigint.d.ts +765 -0
  44. package/project-transform/src/bundled/sound-libs/lib.es2020.d.ts +27 -0
  45. package/project-transform/src/bundled/sound-libs/lib.es2020.date.d.ts +42 -0
  46. package/project-transform/src/bundled/sound-libs/lib.es2020.number.d.ts +28 -0
  47. package/project-transform/src/bundled/sound-libs/lib.es2020.promise.d.ts +49 -0
  48. package/project-transform/src/bundled/sound-libs/lib.es2020.string.d.ts +44 -0
  49. package/project-transform/src/bundled/sound-libs/lib.es2020.symbol.wellknown.d.ts +41 -0
  50. package/project-transform/src/bundled/sound-libs/lib.es2021.d.ts +23 -0
  51. package/project-transform/src/bundled/sound-libs/lib.es2021.promise.d.ts +48 -0
  52. package/project-transform/src/bundled/sound-libs/lib.es2021.string.d.ts +33 -0
  53. package/project-transform/src/bundled/sound-libs/lib.es2021.weakref.d.ts +78 -0
  54. package/project-transform/src/bundled/sound-libs/lib.es2022.array.d.ts +121 -0
  55. package/project-transform/src/bundled/sound-libs/lib.es2022.d.ts +25 -0
  56. package/project-transform/src/bundled/sound-libs/lib.es2022.error.d.ts +75 -0
  57. package/project-transform/src/bundled/sound-libs/lib.es2022.object.d.ts +26 -0
  58. package/project-transform/src/bundled/sound-libs/lib.es2022.regexp.d.ts +39 -0
  59. package/project-transform/src/bundled/sound-libs/lib.es2022.string.d.ts +25 -0
  60. package/project-transform/src/bundled/sound-libs/lib.es2023.array.d.ts +924 -0
  61. package/project-transform/src/bundled/sound-libs/lib.es2023.collection.d.ts +21 -0
  62. package/project-transform/src/bundled/sound-libs/lib.es2023.d.ts +22 -0
  63. package/project-transform/src/bundled/sound-libs/lib.es2024.arraybuffer.d.ts +65 -0
  64. package/project-transform/src/bundled/sound-libs/lib.es2024.collection.d.ts +29 -0
  65. package/project-transform/src/bundled/sound-libs/lib.es2024.d.ts +26 -0
  66. package/project-transform/src/bundled/sound-libs/lib.es2024.object.d.ts +33 -0
  67. package/project-transform/src/bundled/sound-libs/lib.es2024.promise.d.ts +35 -0
  68. package/project-transform/src/bundled/sound-libs/lib.es2024.regexp.d.ts +25 -0
  69. package/project-transform/src/bundled/sound-libs/lib.es2024.string.d.ts +29 -0
  70. package/project-transform/src/bundled/sound-libs/lib.es5.d.ts +4924 -0
  71. package/project-transform/src/bundled/sound_stdlib.js +142 -0
  72. package/project-transform/src/bundled/sound_stdlib.ts +180 -0
  73. package/project-transform/src/checker/analyze_project.js +1361 -0
  74. package/project-transform/src/checker/analyze_project.ts +2246 -0
  75. package/project-transform/src/checker/diagnostics.js +112 -0
  76. package/project-transform/src/checker/diagnostics.ts +222 -0
  77. package/project-transform/src/checker/engine/context.js +235 -0
  78. package/project-transform/src/checker/engine/context.ts +340 -0
  79. package/project-transform/src/checker/engine/diagnostic_codes.js +72 -0
  80. package/project-transform/src/checker/engine/diagnostic_codes.ts +95 -0
  81. package/project-transform/src/checker/engine/facts.js +35 -0
  82. package/project-transform/src/checker/engine/facts.ts +48 -0
  83. package/project-transform/src/checker/engine/types.js +1 -0
  84. package/project-transform/src/checker/engine/types.ts +485 -0
  85. package/project-transform/src/checker/proof_escape_hatch_diagnostics.js +104 -0
  86. package/project-transform/src/checker/proof_escape_hatch_diagnostics.ts +173 -0
  87. package/project-transform/src/checker/rules/async_surface.js +231 -0
  88. package/project-transform/src/checker/rules/async_surface.ts +335 -0
  89. package/project-transform/src/checker/rules/class_lifecycle.js +798 -0
  90. package/project-transform/src/checker/rules/class_lifecycle.ts +1276 -0
  91. package/project-transform/src/checker/rules/directive_validation.js +571 -0
  92. package/project-transform/src/checker/rules/directive_validation.ts +938 -0
  93. package/project-transform/src/checker/rules/directives.js +23 -0
  94. package/project-transform/src/checker/rules/directives.ts +25 -0
  95. package/project-transform/src/checker/rules/flow.js +202 -0
  96. package/project-transform/src/checker/rules/flow.ts +333 -0
  97. package/project-transform/src/checker/rules/flow_facts.js +601 -0
  98. package/project-transform/src/checker/rules/flow_facts.ts +978 -0
  99. package/project-transform/src/checker/rules/flow_invalidation.js +1119 -0
  100. package/project-transform/src/checker/rules/flow_invalidation.ts +2150 -0
  101. package/project-transform/src/checker/rules/flow_shared.js +2822 -0
  102. package/project-transform/src/checker/rules/flow_shared.ts +4383 -0
  103. package/project-transform/src/checker/rules/foreign_boundary.js +120 -0
  104. package/project-transform/src/checker/rules/foreign_boundary.ts +196 -0
  105. package/project-transform/src/checker/rules/foreign_projection.js +279 -0
  106. package/project-transform/src/checker/rules/foreign_projection.ts +425 -0
  107. package/project-transform/src/checker/rules/generated_helpers.js +13 -0
  108. package/project-transform/src/checker/rules/generated_helpers.ts +18 -0
  109. package/project-transform/src/checker/rules/index.js +35 -0
  110. package/project-transform/src/checker/rules/index.ts +49 -0
  111. package/project-transform/src/checker/rules/namespace_object.js +845 -0
  112. package/project-transform/src/checker/rules/namespace_object.ts +1224 -0
  113. package/project-transform/src/checker/rules/non_ordinary_recovery.js +1328 -0
  114. package/project-transform/src/checker/rules/non_ordinary_recovery.ts +2391 -0
  115. package/project-transform/src/checker/rules/null_prototype.js +3 -0
  116. package/project-transform/src/checker/rules/null_prototype.ts +6 -0
  117. package/project-transform/src/checker/rules/overloads.js +181 -0
  118. package/project-transform/src/checker/rules/overloads.ts +317 -0
  119. package/project-transform/src/checker/rules/predicate_verification.js +691 -0
  120. package/project-transform/src/checker/rules/predicate_verification.ts +1088 -0
  121. package/project-transform/src/checker/rules/prototype_hardening.js +237 -0
  122. package/project-transform/src/checker/rules/prototype_hardening.ts +343 -0
  123. package/project-transform/src/checker/rules/receiver_discipline.js +263 -0
  124. package/project-transform/src/checker/rules/receiver_discipline.ts +356 -0
  125. package/project-transform/src/checker/rules/relations.js +6861 -0
  126. package/project-transform/src/checker/rules/relations.ts +12158 -0
  127. package/project-transform/src/checker/rules/resolved_builtins.js +274 -0
  128. package/project-transform/src/checker/rules/resolved_builtins.ts +438 -0
  129. package/project-transform/src/checker/rules/trust.js +217 -0
  130. package/project-transform/src/checker/rules/trust.ts +301 -0
  131. package/project-transform/src/checker/rules/type_guards.js +173 -0
  132. package/project-transform/src/checker/rules/type_guards.ts +257 -0
  133. package/project-transform/src/checker/rules/universal.js +17 -0
  134. package/project-transform/src/checker/rules/universal.ts +22 -0
  135. package/project-transform/src/checker/rules/unsafe_value_origin.js +80 -0
  136. package/project-transform/src/checker/rules/unsafe_value_origin.ts +125 -0
  137. package/project-transform/src/checker/rules/unsound_imports.js +218 -0
  138. package/project-transform/src/checker/rules/unsound_imports.ts +301 -0
  139. package/project-transform/src/checker/rules/unsound_syntax.js +1695 -0
  140. package/project-transform/src/checker/rules/unsound_syntax.ts +2540 -0
  141. package/project-transform/src/checker/rules/value_types.js +206 -0
  142. package/project-transform/src/checker/rules/value_types.ts +407 -0
  143. package/project-transform/src/checker/timing.js +43 -0
  144. package/project-transform/src/checker/timing.ts +78 -0
  145. package/project-transform/src/checker/unsupported_feature_messages.js +337 -0
  146. package/project-transform/src/checker/unsupported_feature_messages.ts +531 -0
  147. package/project-transform/src/cli.js +892 -0
  148. package/project-transform/src/cli.ts +1476 -0
  149. package/project-transform/src/compiler/compile_project.js +319 -0
  150. package/project-transform/src/compiler/compile_project.ts +508 -0
  151. package/project-transform/src/compiler/errors.js +10 -0
  152. package/project-transform/src/compiler/errors.ts +29 -0
  153. package/project-transform/src/compiler/ir.js +1 -0
  154. package/project-transform/src/compiler/ir.ts +1526 -0
  155. package/project-transform/src/compiler/lower.js +30550 -0
  156. package/project-transform/src/compiler/lower.ts +43645 -0
  157. package/project-transform/src/compiler/lower_arrays.js +140 -0
  158. package/project-transform/src/compiler/lower_arrays.ts +190 -0
  159. package/project-transform/src/compiler/lower_strings.js +121 -0
  160. package/project-transform/src/compiler/lower_strings.ts +198 -0
  161. package/project-transform/src/compiler/lower_tagged.js +329 -0
  162. package/project-transform/src/compiler/lower_tagged.ts +427 -0
  163. package/project-transform/src/compiler/lower_views.js +171 -0
  164. package/project-transform/src/compiler/lower_views.ts +251 -0
  165. package/project-transform/src/compiler/object_keys.js +25 -0
  166. package/project-transform/src/compiler/object_keys.ts +35 -0
  167. package/project-transform/src/compiler/runtime_ir.js +30 -0
  168. package/project-transform/src/compiler/runtime_ir.ts +727 -0
  169. package/project-transform/src/compiler/tagged_boundary.js +18 -0
  170. package/project-transform/src/compiler/tagged_boundary.ts +37 -0
  171. package/project-transform/src/compiler/toolchain.js +170 -0
  172. package/project-transform/src/compiler/toolchain.ts +229 -0
  173. package/project-transform/src/compiler/unicode_case_data.js +2102 -0
  174. package/project-transform/src/compiler/unicode_case_data.ts +2112 -0
  175. package/project-transform/src/compiler/wasm_js_host_runtime.js +656 -0
  176. package/project-transform/src/compiler/wasm_js_host_runtime.ts +762 -0
  177. package/project-transform/src/compiler/wat_arrays.js +3132 -0
  178. package/project-transform/src/compiler/wat_arrays.ts +3768 -0
  179. package/project-transform/src/compiler/wat_emitter.js +17952 -0
  180. package/project-transform/src/compiler/wat_emitter.ts +22812 -0
  181. package/project-transform/src/compiler/wat_strings.js +129 -0
  182. package/project-transform/src/compiler/wat_strings.ts +187 -0
  183. package/project-transform/src/compiler/wat_tagged.js +548 -0
  184. package/project-transform/src/compiler/wat_tagged.ts +674 -0
  185. package/project-transform/src/compiler_generator_runner.js +153 -0
  186. package/project-transform/src/compiler_generator_runner.ts +171 -0
  187. package/project-transform/src/compiler_object_test_helpers.js +69 -0
  188. package/project-transform/src/compiler_object_test_helpers.ts +96 -0
  189. package/project-transform/src/compiler_promise_runner.js +2116 -0
  190. package/project-transform/src/compiler_promise_runner.ts +2184 -0
  191. package/project-transform/src/compiler_test_helpers.js +854 -0
  192. package/project-transform/src/compiler_test_helpers.ts +1087 -0
  193. package/project-transform/src/config.js +568 -0
  194. package/project-transform/src/config.ts +892 -0
  195. package/project-transform/src/diagnostic_metadata.js +67 -0
  196. package/project-transform/src/diagnostic_metadata.ts +99 -0
  197. package/project-transform/src/diagnostic_reference.js +1368 -0
  198. package/project-transform/src/diagnostic_reference.ts +1523 -0
  199. package/project-transform/src/editor_diagnostics_worker.js +176 -0
  200. package/project-transform/src/editor_diagnostics_worker.ts +250 -0
  201. package/project-transform/src/editor_projection.js +224 -0
  202. package/project-transform/src/editor_projection.ts +421 -0
  203. package/project-transform/src/frontend/builtin_expanded_program_test_cleanup.js +47 -0
  204. package/project-transform/src/frontend/builtin_expanded_program_test_cleanup.ts +72 -0
  205. package/project-transform/src/frontend/builtin_macro_support.js +842 -0
  206. package/project-transform/src/frontend/builtin_macro_support.ts +1386 -0
  207. package/project-transform/src/frontend/builtin_macros.js +409 -0
  208. package/project-transform/src/frontend/builtin_macros.ts +542 -0
  209. package/project-transform/src/frontend/component_poc_runtime.js +279 -0
  210. package/project-transform/src/frontend/component_poc_runtime.ts +372 -0
  211. package/project-transform/src/frontend/css_macro.js +148 -0
  212. package/project-transform/src/frontend/css_macro.ts +222 -0
  213. package/project-transform/src/frontend/derive_macros.js +2072 -0
  214. package/project-transform/src/frontend/derive_macros.ts +3188 -0
  215. package/project-transform/src/frontend/embedded_fragment_support.js +106 -0
  216. package/project-transform/src/frontend/embedded_fragment_support.ts +172 -0
  217. package/project-transform/src/frontend/error_normalization.js +403 -0
  218. package/project-transform/src/frontend/error_normalization.ts +832 -0
  219. package/project-transform/src/frontend/error_stdlib_support.js +1 -0
  220. package/project-transform/src/frontend/error_stdlib_support.ts +6 -0
  221. package/project-transform/src/frontend/expand_project.js +169 -0
  222. package/project-transform/src/frontend/expand_project.ts +248 -0
  223. package/project-transform/src/frontend/format_soundscript.js +297 -0
  224. package/project-transform/src/frontend/format_soundscript.ts +582 -0
  225. package/project-transform/src/frontend/graphql_macro.js +174 -0
  226. package/project-transform/src/frontend/graphql_macro.ts +253 -0
  227. package/project-transform/src/frontend/hash_context.js +83 -0
  228. package/project-transform/src/frontend/hash_context.ts +113 -0
  229. package/project-transform/src/frontend/hkt_macro.js +448 -0
  230. package/project-transform/src/frontend/hkt_macro.ts +897 -0
  231. package/project-transform/src/frontend/import_binding_usage.js +190 -0
  232. package/project-transform/src/frontend/import_binding_usage.ts +277 -0
  233. package/project-transform/src/frontend/macro_advanced_backend_adapter.js +58 -0
  234. package/project-transform/src/frontend/macro_advanced_backend_adapter.ts +123 -0
  235. package/project-transform/src/frontend/macro_advanced_context.js +826 -0
  236. package/project-transform/src/frontend/macro_advanced_context.ts +1102 -0
  237. package/project-transform/src/frontend/macro_advanced_output.js +21 -0
  238. package/project-transform/src/frontend/macro_advanced_output.ts +41 -0
  239. package/project-transform/src/frontend/macro_api.js +353 -0
  240. package/project-transform/src/frontend/macro_api.ts +1722 -0
  241. package/project-transform/src/frontend/macro_api_internal.js +35 -0
  242. package/project-transform/src/frontend/macro_api_internal.ts +80 -0
  243. package/project-transform/src/frontend/macro_api_module_support.js +39 -0
  244. package/project-transform/src/frontend/macro_api_module_support.ts +65 -0
  245. package/project-transform/src/frontend/macro_backend_adapter.js +272 -0
  246. package/project-transform/src/frontend/macro_backend_adapter.ts +420 -0
  247. package/project-transform/src/frontend/macro_context.js +816 -0
  248. package/project-transform/src/frontend/macro_context.ts +1105 -0
  249. package/project-transform/src/frontend/macro_debug.js +99 -0
  250. package/project-transform/src/frontend/macro_debug.ts +157 -0
  251. package/project-transform/src/frontend/macro_definition_support.js +28 -0
  252. package/project-transform/src/frontend/macro_definition_support.ts +73 -0
  253. package/project-transform/src/frontend/macro_errors.js +40 -0
  254. package/project-transform/src/frontend/macro_errors.ts +70 -0
  255. package/project-transform/src/frontend/macro_expander.js +919 -0
  256. package/project-transform/src/frontend/macro_expander.ts +1611 -0
  257. package/project-transform/src/frontend/macro_factory_support.js +176 -0
  258. package/project-transform/src/frontend/macro_factory_support.ts +263 -0
  259. package/project-transform/src/frontend/macro_host_ast_internal.js +64 -0
  260. package/project-transform/src/frontend/macro_host_ast_internal.ts +109 -0
  261. package/project-transform/src/frontend/macro_index.js +27 -0
  262. package/project-transform/src/frontend/macro_index.ts +50 -0
  263. package/project-transform/src/frontend/macro_loader.js +281 -0
  264. package/project-transform/src/frontend/macro_loader.ts +506 -0
  265. package/project-transform/src/frontend/macro_operand_semantics.js +838 -0
  266. package/project-transform/src/frontend/macro_operand_semantics.ts +1489 -0
  267. package/project-transform/src/frontend/macro_output.js +54 -0
  268. package/project-transform/src/frontend/macro_output.ts +123 -0
  269. package/project-transform/src/frontend/macro_parser.js +611 -0
  270. package/project-transform/src/frontend/macro_parser.ts +832 -0
  271. package/project-transform/src/frontend/macro_resolver.js +69 -0
  272. package/project-transform/src/frontend/macro_resolver.ts +125 -0
  273. package/project-transform/src/frontend/macro_rewrite.js +285 -0
  274. package/project-transform/src/frontend/macro_rewrite.ts +442 -0
  275. package/project-transform/src/frontend/macro_runtime_support.js +232 -0
  276. package/project-transform/src/frontend/macro_runtime_support.ts +324 -0
  277. package/project-transform/src/frontend/macro_scanner.js +393 -0
  278. package/project-transform/src/frontend/macro_scanner.ts +455 -0
  279. package/project-transform/src/frontend/macro_semantic_backend_adapter.js +87 -0
  280. package/project-transform/src/frontend/macro_semantic_backend_adapter.ts +166 -0
  281. package/project-transform/src/frontend/macro_semantic_context.js +5 -0
  282. package/project-transform/src/frontend/macro_semantic_context.ts +12 -0
  283. package/project-transform/src/frontend/macro_semantic_output.js +24 -0
  284. package/project-transform/src/frontend/macro_semantic_output.ts +47 -0
  285. package/project-transform/src/frontend/macro_semantic_types.js +1 -0
  286. package/project-transform/src/frontend/macro_semantic_types.ts +98 -0
  287. package/project-transform/src/frontend/macro_semantics.js +1172 -0
  288. package/project-transform/src/frontend/macro_semantics.ts +1502 -0
  289. package/project-transform/src/frontend/macro_site_kind_support.js +164 -0
  290. package/project-transform/src/frontend/macro_site_kind_support.ts +255 -0
  291. package/project-transform/src/frontend/macro_syntax_internal.js +1950 -0
  292. package/project-transform/src/frontend/macro_syntax_internal.ts +3338 -0
  293. package/project-transform/src/frontend/macro_templates.js +57 -0
  294. package/project-transform/src/frontend/macro_templates.ts +143 -0
  295. package/project-transform/src/frontend/macro_test_helpers.js +82 -0
  296. package/project-transform/src/frontend/macro_test_helpers.ts +136 -0
  297. package/project-transform/src/frontend/macro_types.js +1 -0
  298. package/project-transform/src/frontend/macro_types.ts +103 -0
  299. package/project-transform/src/frontend/macro_vm.js +39 -0
  300. package/project-transform/src/frontend/macro_vm.ts +113 -0
  301. package/project-transform/src/frontend/match_macro.js +885 -0
  302. package/project-transform/src/frontend/match_macro.ts +1220 -0
  303. package/project-transform/src/frontend/numeric_normalization.js +824 -0
  304. package/project-transform/src/frontend/numeric_normalization.ts +1380 -0
  305. package/project-transform/src/frontend/numeric_prelude.js +278 -0
  306. package/project-transform/src/frontend/numeric_prelude.ts +370 -0
  307. package/project-transform/src/frontend/project_frontend.js +2396 -0
  308. package/project-transform/src/frontend/project_frontend.ts +3776 -0
  309. package/project-transform/src/frontend/project_macro_support.js +1401 -0
  310. package/project-transform/src/frontend/project_macro_support.ts +2137 -0
  311. package/project-transform/src/frontend/sql_macro.js +175 -0
  312. package/project-transform/src/frontend/sql_macro.ts +254 -0
  313. package/project-transform/src/frontend/sql_stdlib_support.js +1 -0
  314. package/project-transform/src/frontend/sql_stdlib_support.ts +6 -0
  315. package/project-transform/src/frontend/std_package_support.js +228 -0
  316. package/project-transform/src/frontend/std_package_support.ts +400 -0
  317. package/project-transform/src/frontend/value_normalization.js +306 -0
  318. package/project-transform/src/frontend/value_normalization.ts +599 -0
  319. package/project-transform/src/lsp/project_service.js +4771 -0
  320. package/project-transform/src/lsp/project_service.ts +7580 -0
  321. package/project-transform/src/lsp/protocol.js +9 -0
  322. package/project-transform/src/lsp/protocol.ts +38 -0
  323. package/project-transform/src/lsp/server.js +355 -0
  324. package/project-transform/src/lsp/server.ts +671 -0
  325. package/project-transform/src/lsp/session.js +49 -0
  326. package/project-transform/src/lsp/session.ts +48 -0
  327. package/project-transform/src/lsp/timing.js +43 -0
  328. package/project-transform/src/lsp/timing.ts +76 -0
  329. package/project-transform/src/lsp/transport.js +205 -0
  330. package/project-transform/src/lsp/transport.ts +253 -0
  331. package/project-transform/src/lsp_main.js +5 -0
  332. package/project-transform/src/lsp_main.ts +7 -0
  333. package/project-transform/src/macros.d.ts +1 -0
  334. package/project-transform/src/macros.js +1 -0
  335. package/project-transform/src/macros.ts +1 -0
  336. package/project-transform/src/main.js +24 -0
  337. package/project-transform/src/main.ts +28 -0
  338. package/project-transform/src/platform/host.js +264 -0
  339. package/project-transform/src/platform/host.ts +343 -0
  340. package/project-transform/src/platform/path.js +8 -0
  341. package/project-transform/src/platform/path.ts +20 -0
  342. package/project-transform/src/public_macro_api/macro_api.d.ts +1054 -0
  343. package/project-transform/src/public_macro_api/macro_semantic_types.d.ts +66 -0
  344. package/project-transform/src/public_macro_api/macro_types.d.ts +70 -0
  345. package/project-transform/src/run_program.js +14 -0
  346. package/project-transform/src/run_program.ts +33 -0
  347. package/project-transform/src/runtime/materialize.js +371 -0
  348. package/project-transform/src/runtime/materialize.ts +502 -0
  349. package/project-transform/src/runtime/on_demand.js +203 -0
  350. package/project-transform/src/runtime/on_demand.ts +305 -0
  351. package/project-transform/src/runtime/source_maps.js +205 -0
  352. package/project-transform/src/runtime/source_maps.ts +297 -0
  353. package/project-transform/src/runtime/transform.js +148 -0
  354. package/project-transform/src/runtime/transform.ts +295 -0
  355. package/project-transform/src/service/types.js +1 -0
  356. package/project-transform/src/service/types.ts +22 -0
  357. package/project-transform/src/soundscript_packages.js +477 -0
  358. package/project-transform/src/soundscript_packages.ts +754 -0
  359. package/project-transform/src/soundscript_runtime_specifiers.js +88 -0
  360. package/project-transform/src/soundscript_runtime_specifiers.ts +96 -0
  361. package/project-transform/src/stdlib/async.d.ts +81 -0
  362. package/project-transform/src/stdlib/async.js +213 -0
  363. package/project-transform/src/stdlib/async.ts +315 -0
  364. package/project-transform/src/stdlib/codec.d.ts +32 -0
  365. package/project-transform/src/stdlib/codec.js +30 -0
  366. package/project-transform/src/stdlib/codec.ts +76 -0
  367. package/project-transform/src/stdlib/compare.d.ts +28 -0
  368. package/project-transform/src/stdlib/compare.js +115 -0
  369. package/project-transform/src/stdlib/compare.ts +151 -0
  370. package/project-transform/src/stdlib/css.d.ts +16 -0
  371. package/project-transform/src/stdlib/css.js +9 -0
  372. package/project-transform/src/stdlib/css.ts +28 -0
  373. package/project-transform/src/stdlib/debug.d.ts +2 -0
  374. package/project-transform/src/stdlib/debug.js +9 -0
  375. package/project-transform/src/stdlib/debug.ts +10 -0
  376. package/project-transform/src/stdlib/decode.d.ts +86 -0
  377. package/project-transform/src/stdlib/decode.js +254 -0
  378. package/project-transform/src/stdlib/decode.ts +390 -0
  379. package/project-transform/src/stdlib/derive.d.ts +6 -0
  380. package/project-transform/src/stdlib/derive.js +7 -0
  381. package/project-transform/src/stdlib/derive.ts +7 -0
  382. package/project-transform/src/stdlib/encode.d.ts +100 -0
  383. package/project-transform/src/stdlib/encode.js +130 -0
  384. package/project-transform/src/stdlib/encode.ts +259 -0
  385. package/project-transform/src/stdlib/failures.d.ts +23 -0
  386. package/project-transform/src/stdlib/failures.js +41 -0
  387. package/project-transform/src/stdlib/failures.ts +64 -0
  388. package/project-transform/src/stdlib/fetch.d.ts +67 -0
  389. package/project-transform/src/stdlib/fetch.js +5 -0
  390. package/project-transform/src/stdlib/fetch.ts +11 -0
  391. package/project-transform/src/stdlib/graphql.d.ts +16 -0
  392. package/project-transform/src/stdlib/graphql.js +9 -0
  393. package/project-transform/src/stdlib/graphql.ts +28 -0
  394. package/project-transform/src/stdlib/hash.d.ts +34 -0
  395. package/project-transform/src/stdlib/hash.js +110 -0
  396. package/project-transform/src/stdlib/hash.ts +188 -0
  397. package/project-transform/src/stdlib/hkt.d.ts +40 -0
  398. package/project-transform/src/stdlib/hkt.js +3 -0
  399. package/project-transform/src/stdlib/hkt.ts +41 -0
  400. package/project-transform/src/stdlib/index.d.ts +9 -0
  401. package/project-transform/src/stdlib/index.js +15 -0
  402. package/project-transform/src/stdlib/index.ts +23 -0
  403. package/project-transform/src/stdlib/json.d.ts +125 -0
  404. package/project-transform/src/stdlib/json.js +764 -0
  405. package/project-transform/src/stdlib/json.ts +1034 -0
  406. package/project-transform/src/stdlib/match.d.ts +11 -0
  407. package/project-transform/src/stdlib/match.js +13 -0
  408. package/project-transform/src/stdlib/match.ts +26 -0
  409. package/project-transform/src/stdlib/numerics.d.ts +523 -0
  410. package/project-transform/src/stdlib/numerics.js +1356 -0
  411. package/project-transform/src/stdlib/numerics.ts +1937 -0
  412. package/project-transform/src/stdlib/random.d.ts +19 -0
  413. package/project-transform/src/stdlib/random.js +3 -0
  414. package/project-transform/src/stdlib/random.ts +5 -0
  415. package/project-transform/src/stdlib/result.d.ts +68 -0
  416. package/project-transform/src/stdlib/result.js +139 -0
  417. package/project-transform/src/stdlib/result.ts +248 -0
  418. package/project-transform/src/stdlib/sql.d.ts +22 -0
  419. package/project-transform/src/stdlib/sql.js +23 -0
  420. package/project-transform/src/stdlib/sql.ts +53 -0
  421. package/project-transform/src/stdlib/text.d.ts +24 -0
  422. package/project-transform/src/stdlib/text.js +3 -0
  423. package/project-transform/src/stdlib/text.ts +4 -0
  424. package/project-transform/src/stdlib/thunk.d.ts +2 -0
  425. package/project-transform/src/stdlib/thunk.js +9 -0
  426. package/project-transform/src/stdlib/thunk.ts +15 -0
  427. package/project-transform/src/stdlib/typeclasses.d.ts +57 -0
  428. package/project-transform/src/stdlib/typeclasses.js +78 -0
  429. package/project-transform/src/stdlib/typeclasses.ts +173 -0
  430. package/project-transform/src/stdlib/url.d.ts +37 -0
  431. package/project-transform/src/stdlib/url.js +3 -0
  432. package/project-transform/src/stdlib/url.ts +4 -0
  433. package/project-transform/src/stdlib/value.d.ts +9 -0
  434. package/project-transform/src/stdlib/value.js +104 -0
  435. package/project-transform/src/stdlib/value.ts +133 -0
  436. package/project-transform/src/test_installed_stdlib.js +147 -0
  437. package/project-transform/src/test_installed_stdlib.ts +245 -0
  438. package/project-transform/src/test_macro_package_fixture.js +50 -0
  439. package/project-transform/src/test_macro_package_fixture.ts +68 -0
  440. package/project-transform/src/value_deep_safe.js +191 -0
  441. package/project-transform/src/value_deep_safe.ts +273 -0
@@ -0,0 +1,892 @@
1
+ import { basename, dirname, join } from './platform/path.js';
2
+ import ts from 'typescript';
3
+ import { buildProject, } from './build_package.js';
4
+ import { formatDiagnostics } from './checker/diagnostics.js';
5
+ import { compileProject, } from './compiler/compile_project.js';
6
+ import { expandProject, } from './frontend/expand_project.js';
7
+ import { parseCommand, } from './config.js';
8
+ import { getDiagnosticDocsUrl, toMachineDiagnostic, } from './diagnostic_metadata.js';
9
+ import { getDiagnosticReference, } from './diagnostic_reference.js';
10
+ import { createTempDirectory, fileExistsSync, makeDirectory, readStdinText, removePath, runCommand, runtimeCwd, watchFileSystem, writeStdout, writeTextFile, } from './platform/host.js';
11
+ import { materializeRuntimeGraph, } from './runtime/materialize.js';
12
+ import { runProgram } from './run_program.js';
13
+ import { projectEditorFile } from './editor_projection.js';
14
+ export const VERSION = '0.1.15';
15
+ const FINDINGS_EXIT_CODE = 1;
16
+ const CLI_FAILURE_EXIT_CODE = 2;
17
+ function createCliDiagnostic(code, message, filePath, details) {
18
+ return {
19
+ source: 'cli',
20
+ code,
21
+ category: 'error',
22
+ message,
23
+ notes: details?.notes,
24
+ hint: details?.hint,
25
+ filePath,
26
+ line: 1,
27
+ column: 1,
28
+ endLine: 1,
29
+ endColumn: 1,
30
+ };
31
+ }
32
+ function isOutputFormatValue(value) {
33
+ return value === 'json' || value === 'ndjson' || value === 'text';
34
+ }
35
+ function detectRequestedOutputFormat(args) {
36
+ for (let index = 0; index < args.length; index += 1) {
37
+ if (args[index] !== '--format') {
38
+ continue;
39
+ }
40
+ const value = args[index + 1];
41
+ if (isOutputFormatValue(value)) {
42
+ return value;
43
+ }
44
+ }
45
+ return 'text';
46
+ }
47
+ function detectRequestedCommand(args) {
48
+ const subcommand = args[0];
49
+ if (subcommand === 'build' || subcommand === 'check' || subcommand === 'compile' ||
50
+ subcommand === 'expand' ||
51
+ subcommand === 'explain') {
52
+ return subcommand;
53
+ }
54
+ return 'cli';
55
+ }
56
+ function pathExists(path) {
57
+ return fileExistsSync(path);
58
+ }
59
+ function toSoundscriptIncludePattern(pattern) {
60
+ if (pattern.includes('.sts') || pattern.endsWith('.d.ts')) {
61
+ return undefined;
62
+ }
63
+ if (pattern.endsWith('.ts')) {
64
+ return `${pattern.slice(0, -3)}.sts`;
65
+ }
66
+ if (pattern.endsWith('.tsx')) {
67
+ return `${pattern.slice(0, -4)}.sts`;
68
+ }
69
+ return undefined;
70
+ }
71
+ function toSoundscriptIncludePatternForFile(filePath) {
72
+ if (filePath.endsWith('.d.ts') || filePath.endsWith('.sts')) {
73
+ return undefined;
74
+ }
75
+ if (!filePath.endsWith('.ts') && !filePath.endsWith('.tsx')) {
76
+ return undefined;
77
+ }
78
+ const directory = dirname(filePath);
79
+ return directory === '.' ? '*.sts' : join(directory, '**', '*.sts');
80
+ }
81
+ function deriveExistingProjectInclude(baseProjectPath) {
82
+ const configFile = ts.readConfigFile(baseProjectPath, ts.sys.readFile);
83
+ if (configFile.error) {
84
+ return undefined;
85
+ }
86
+ const rawConfig = configFile.config;
87
+ if (rawConfig?.include) {
88
+ const include = [...rawConfig.include];
89
+ const augmentedInclude = new Set(include);
90
+ for (const pattern of rawConfig.include) {
91
+ const soundscriptPattern = toSoundscriptIncludePattern(pattern);
92
+ if (soundscriptPattern) {
93
+ augmentedInclude.add(soundscriptPattern);
94
+ }
95
+ }
96
+ return augmentedInclude.size === include.length ? undefined : [...augmentedInclude];
97
+ }
98
+ if (!rawConfig?.files) {
99
+ return undefined;
100
+ }
101
+ const include = new Set();
102
+ for (const filePath of rawConfig.files) {
103
+ const soundscriptPattern = toSoundscriptIncludePatternForFile(filePath);
104
+ if (soundscriptPattern) {
105
+ include.add(soundscriptPattern);
106
+ }
107
+ }
108
+ return include.size === 0 ? undefined : [...include];
109
+ }
110
+ async function runEditorProjectCommand(command) {
111
+ const fileOverrides = command.useStdin
112
+ ? new Map([[command.filePath, await readStdinText()]])
113
+ : new Map();
114
+ const projection = projectEditorFile({
115
+ fileOverrides,
116
+ filePath: command.filePath,
117
+ projectPath: command.projectPath,
118
+ });
119
+ const payload = {
120
+ schemaVersion: 1,
121
+ toolVersion: VERSION,
122
+ command: 'editor-project',
123
+ filePath: projection.filePath,
124
+ originalText: projection.originalText,
125
+ postRewriteStage: projection.postRewriteStage,
126
+ projectedText: projection.projectedText,
127
+ projectPath: projection.projectPath,
128
+ rewriteStage: projection.rewriteStage,
129
+ virtualModules: projection.virtualModules,
130
+ };
131
+ return {
132
+ exitCode: 0,
133
+ output: `${JSON.stringify(payload, null, 2)}\n`,
134
+ diagnostics: [],
135
+ projectPath: command.projectPath,
136
+ workingDirectory: command.workingDirectory,
137
+ };
138
+ }
139
+ function renderHelp() {
140
+ return [
141
+ 'soundscript',
142
+ '',
143
+ 'Usage:',
144
+ ' soundscript init [--mode <new|existing>]',
145
+ ' soundscript build [--project <path>] [--target <js-browser|js-node|wasm-browser|wasm-node|wasm-wasi>] [--out-dir <path>] [--watch] [--format <text|json|ndjson>]',
146
+ ' soundscript check [--project <path>] [--target <js-browser|js-node|wasm-browser|wasm-node|wasm-wasi>] [--format <text|json|ndjson>]',
147
+ ' soundscript compile [--project <path>] [--target <js-browser|js-node|wasm-browser|wasm-node|wasm-wasi>] [--format <text|json|ndjson>]',
148
+ ' soundscript deno <run|test> [...]',
149
+ ' soundscript expand [--project <path>] [--target <js-browser|js-node|wasm-browser|wasm-node|wasm-wasi>] [--out-dir <path>] [--format <text|json|ndjson>]',
150
+ ' soundscript expand [--project <path>] [--target <js-browser|js-node|wasm-browser|wasm-node|wasm-wasi>] --file <path> [--stage <rewrite|prepared|expanded|projected>] [--trace]',
151
+ ' soundscript explain <code> [--format <text|json|ndjson>]',
152
+ ' soundscript lsp',
153
+ ' soundscript node <entry> [-- <args...>]',
154
+ ' soundscript [--help] [--version]',
155
+ '',
156
+ 'Commands:',
157
+ ' init Create a new soundscript project or adoption config.',
158
+ ' build Build a publishable soundscript package.',
159
+ ' check Analyze a project with the checker.',
160
+ ' compile Experimental compiler entrypoint.',
161
+ ' deno Run Deno against a temporary transformed graph.',
162
+ ' expand Expand macros and emit base TypeScript files.',
163
+ ' explain Explain a soundscript diagnostic code.',
164
+ ' lsp Start the language server over stdio.',
165
+ ' node Run Node against a temporary transformed graph.',
166
+ '',
167
+ 'Command options:',
168
+ ' --mode Init mode: new (default) or existing.',
169
+ ' -p, --project Path to a tsconfig.json file for build, check, compile, or expand.',
170
+ ' --target Experimental runtime target override: js-node (default), js-browser, wasm-browser, wasm-node, or wasm-wasi.',
171
+ ' --format Output format for build, check, compile, expand, or explain: text (default), json, or ndjson.',
172
+ ' --file Print one expanded file instead of writing an output directory for expand.',
173
+ ' --out-dir Output directory for build (default: dist) or expand (default: soundscript-expanded).',
174
+ ' --stage Expansion stage for expand --file: rewrite, prepared, expanded, or projected (default: expanded).',
175
+ ' --trace Include structured macro trace data with expand --file.',
176
+ ' --watch Rebuild on file changes for build.',
177
+ '',
178
+ 'Experimental:',
179
+ ' soundscript compile and runtime target overrides, especially Wasm targets, are not part of stable v1.',
180
+ ' soundscript node and soundscript deno require @soundscript/soundscript in the current project or an ancestor workspace.',
181
+ '',
182
+ 'Examples:',
183
+ ' soundscript init',
184
+ ' soundscript init --mode existing',
185
+ ' soundscript build',
186
+ ' soundscript build --out-dir dist',
187
+ ' soundscript check',
188
+ ' soundscript check --project tsconfig.soundscript.json --format json',
189
+ ' soundscript check --project tsconfig.soundscript.json --format ndjson',
190
+ ' soundscript expand --file src/main.sts --stage expanded',
191
+ ' soundscript deno run src/main.sts',
192
+ ' soundscript explain SOUND1002',
193
+ ' soundscript lsp',
194
+ ' soundscript node src/main.sts',
195
+ '',
196
+ 'Global options:',
197
+ ' -h, --help Show this help text.',
198
+ ' -v, --version Show the current version.',
199
+ ].join('\n');
200
+ }
201
+ function renderInvalidCommand(message) {
202
+ return `${message}\n\n${renderHelp()}\n`;
203
+ }
204
+ function summarizeDiagnostics(diagnostics) {
205
+ return {
206
+ total: diagnostics.length,
207
+ errors: diagnostics.filter((diagnostic) => diagnostic.category === 'error').length,
208
+ warnings: diagnostics.filter((diagnostic) => diagnostic.category === 'warning').length,
209
+ messages: diagnostics.filter((diagnostic) => diagnostic.category === 'message').length,
210
+ };
211
+ }
212
+ function renderJsonOutput(command, projectPath, workingDirectory, exitCode, diagnostics, artifacts) {
213
+ const machineDiagnostics = diagnostics.map((diagnostic) => toMachineDiagnostic(diagnostic, workingDirectory));
214
+ const payload = {
215
+ schemaVersion: 1,
216
+ toolVersion: VERSION,
217
+ command,
218
+ projectPath,
219
+ workingDirectory,
220
+ exitCode,
221
+ summary: summarizeDiagnostics(diagnostics),
222
+ diagnostics: machineDiagnostics,
223
+ ...(artifacts ? { artifacts } : {}),
224
+ };
225
+ return `${JSON.stringify(payload, null, 2)}\n`;
226
+ }
227
+ function renderDiagnosticsOutput(format, command, projectPath, workingDirectory, exitCode, diagnostics, artifacts) {
228
+ if (format === 'json') {
229
+ return renderJsonOutput(command, projectPath, workingDirectory, exitCode, diagnostics, artifacts);
230
+ }
231
+ if (format === 'ndjson') {
232
+ return renderNdjsonOutput(command, projectPath, workingDirectory, exitCode, diagnostics, artifacts);
233
+ }
234
+ return formatDiagnostics(diagnostics, workingDirectory);
235
+ }
236
+ function renderNdjsonOutput(command, projectPath, workingDirectory, exitCode, diagnostics, artifacts) {
237
+ const machineDiagnostics = diagnostics.map((diagnostic) => toMachineDiagnostic(diagnostic, workingDirectory));
238
+ const runEvent = {
239
+ event: 'run',
240
+ schemaVersion: 1,
241
+ toolVersion: VERSION,
242
+ command,
243
+ projectPath,
244
+ workingDirectory,
245
+ };
246
+ const diagnosticEvents = machineDiagnostics.map((diagnostic) => ({
247
+ event: 'diagnostic',
248
+ diagnostic,
249
+ }));
250
+ const summaryEvent = {
251
+ event: 'summary',
252
+ schemaVersion: 1,
253
+ toolVersion: VERSION,
254
+ command,
255
+ projectPath,
256
+ workingDirectory,
257
+ exitCode,
258
+ summary: summarizeDiagnostics(diagnostics),
259
+ ...(artifacts ? { artifacts } : {}),
260
+ };
261
+ return [
262
+ JSON.stringify(runEvent),
263
+ ...diagnosticEvents.map((event) => JSON.stringify(event)),
264
+ JSON.stringify(summaryEvent),
265
+ '',
266
+ ].join('\n');
267
+ }
268
+ function renderExplainTextOutput(code) {
269
+ const reference = getDiagnosticReference(code);
270
+ if (!reference) {
271
+ return [
272
+ `No built-in explanation is available for diagnostic code ${code}.`,
273
+ '',
274
+ 'soundscript explain currently covers built-in soundscript diagnostic codes.',
275
+ '',
276
+ ].join('\n');
277
+ }
278
+ const lines = [
279
+ `${reference.code}: ${reference.title}`,
280
+ '',
281
+ reference.summary,
282
+ ];
283
+ if (reference.repairHeuristic) {
284
+ lines.push('', 'Repair heuristic:', reference.repairHeuristic);
285
+ }
286
+ if (reference.details.length > 0) {
287
+ lines.push('', 'Details:');
288
+ for (const detail of reference.details) {
289
+ lines.push(`- ${detail}`);
290
+ }
291
+ }
292
+ if ((reference.examples?.length ?? 0) > 0) {
293
+ lines.push('', 'Examples:');
294
+ reference.examples?.forEach((example, index) => {
295
+ lines.push('', `Example ${index + 1}:`, 'Before:', '```ts', example.bad, '```');
296
+ lines.push('After:', '```ts', example.good, '```');
297
+ });
298
+ }
299
+ if (reference.suggestions.length > 0) {
300
+ lines.push('', 'Suggestions:');
301
+ for (const suggestion of reference.suggestions) {
302
+ lines.push(`- ${suggestion.title}: ${suggestion.message}`);
303
+ }
304
+ }
305
+ lines.push('', `Docs: ${getDiagnosticDocsUrl(reference.code)}`, '');
306
+ return lines.join('\n');
307
+ }
308
+ function renderExplainJsonOutput(code) {
309
+ const reference = getDiagnosticReference(code);
310
+ if (!reference) {
311
+ return `${JSON.stringify({
312
+ schemaVersion: 1,
313
+ toolVersion: VERSION,
314
+ command: 'explain',
315
+ code,
316
+ found: false,
317
+ message: `No built-in explanation is available for diagnostic code ${code}.`,
318
+ }, null, 2)}\n`;
319
+ }
320
+ const payload = {
321
+ schemaVersion: 1,
322
+ toolVersion: VERSION,
323
+ command: 'explain',
324
+ code: reference.code,
325
+ title: reference.title,
326
+ summary: reference.summary,
327
+ details: [...reference.details],
328
+ repairHeuristic: reference.repairHeuristic,
329
+ examples: reference.examples ? [...reference.examples] : undefined,
330
+ docsUrl: getDiagnosticDocsUrl(reference.code),
331
+ suggestions: reference.suggestions.map((suggestion) => ({
332
+ ...suggestion,
333
+ source: 'reference',
334
+ })),
335
+ };
336
+ return `${JSON.stringify(payload, null, 2)}\n`;
337
+ }
338
+ function renderExplainNdjsonOutput(code) {
339
+ const reference = getDiagnosticReference(code);
340
+ if (!reference) {
341
+ return `${JSON.stringify({
342
+ event: 'explain',
343
+ schemaVersion: 1,
344
+ toolVersion: VERSION,
345
+ code,
346
+ found: false,
347
+ message: `No built-in explanation is available for diagnostic code ${code}.`,
348
+ })}\n`;
349
+ }
350
+ return `${JSON.stringify({
351
+ event: 'explain',
352
+ schemaVersion: 1,
353
+ toolVersion: VERSION,
354
+ code: reference.code,
355
+ title: reference.title,
356
+ summary: reference.summary,
357
+ details: reference.details,
358
+ repairHeuristic: reference.repairHeuristic,
359
+ examples: reference.examples,
360
+ docsUrl: getDiagnosticDocsUrl(reference.code),
361
+ suggestions: reference.suggestions.map((suggestion) => ({
362
+ ...suggestion,
363
+ source: 'reference',
364
+ })),
365
+ })}\n`;
366
+ }
367
+ function renderExplainOutput(code, format) {
368
+ if (format === 'json') {
369
+ return renderExplainJsonOutput(code);
370
+ }
371
+ if (format === 'ndjson') {
372
+ return renderExplainNdjsonOutput(code);
373
+ }
374
+ return renderExplainTextOutput(code);
375
+ }
376
+ function detectSuggestedProjectPath(workingDirectory) {
377
+ const soundscriptProjectPath = join(workingDirectory, 'tsconfig.soundscript.json');
378
+ return pathExists(soundscriptProjectPath) ? soundscriptProjectPath : undefined;
379
+ }
380
+ function createMissingProjectResult(format, command, projectPath, workingDirectory) {
381
+ const requestedProjectName = basename(projectPath);
382
+ const suggestedProjectPath = requestedProjectName === 'tsconfig.json'
383
+ ? detectSuggestedProjectPath(workingDirectory)
384
+ : undefined;
385
+ const diagnostics = [
386
+ createCliDiagnostic('SOUNDSCRIPT_NO_PROJECT', 'No tsconfig.json was found for this command.', projectPath, {
387
+ notes: suggestedProjectPath
388
+ ? [
389
+ `Found '${basename(suggestedProjectPath)}' in this directory instead of 'tsconfig.json'.`,
390
+ ]
391
+ : undefined,
392
+ hint: suggestedProjectPath
393
+ ? `Try 'soundscript ${command} --project ${basename(suggestedProjectPath)}'.`
394
+ : "Run 'soundscript init' to create a new project, or pass --project to an existing tsconfig.",
395
+ }),
396
+ ];
397
+ return {
398
+ exitCode: CLI_FAILURE_EXIT_CODE,
399
+ output: renderDiagnosticsOutput(format, command, projectPath, workingDirectory, CLI_FAILURE_EXIT_CODE, diagnostics),
400
+ diagnostics,
401
+ projectPath,
402
+ workingDirectory,
403
+ };
404
+ }
405
+ function createCliFailureResult(format, command, workingDirectory, details) {
406
+ const projectPath = details.projectPath ?? '';
407
+ const diagnostics = [
408
+ createCliDiagnostic(details.code, details.message, details.projectPath ?? workingDirectory, {
409
+ hint: details.hint,
410
+ notes: details.notes,
411
+ }),
412
+ ];
413
+ return {
414
+ exitCode: CLI_FAILURE_EXIT_CODE,
415
+ output: renderDiagnosticsOutput(format, command, projectPath, workingDirectory, CLI_FAILURE_EXIT_CODE, diagnostics),
416
+ diagnostics,
417
+ projectPath,
418
+ workingDirectory,
419
+ };
420
+ }
421
+ function describeUnexpectedError(error) {
422
+ if (error instanceof Error) {
423
+ return error.message;
424
+ }
425
+ if (typeof error === 'string') {
426
+ return error;
427
+ }
428
+ if (error === undefined || error === null) {
429
+ return undefined;
430
+ }
431
+ return String(error);
432
+ }
433
+ function createInternalErrorResult(format, command, projectPath, workingDirectory, error, commandOutput) {
434
+ const notes = [];
435
+ const errorMessage = describeUnexpectedError(error);
436
+ if (errorMessage) {
437
+ notes.push(`Internal error: ${errorMessage}`);
438
+ }
439
+ if (commandOutput && commandOutput.trim().length > 0 && commandOutput !== errorMessage) {
440
+ notes.push(`Command output: ${commandOutput}`);
441
+ }
442
+ return createCliFailureResult(format, command, workingDirectory, {
443
+ code: 'SOUNDSCRIPT_INTERNAL_ERROR',
444
+ message: `soundscript hit an unexpected internal error while running '${command}'.`,
445
+ notes: notes.length > 0 ? notes : undefined,
446
+ hint: 'Retry with the smallest reproduction you can share. If it still fails, file an issue with the command and input that triggered it.',
447
+ projectPath,
448
+ });
449
+ }
450
+ async function initializeProject(command, workingDirectory) {
451
+ if (command.mode === 'new') {
452
+ const projectPath = join(workingDirectory, 'tsconfig.json');
453
+ const entryPath = join(workingDirectory, 'src/main.sts');
454
+ if (pathExists(projectPath) || pathExists(entryPath)) {
455
+ const diagnostics = [
456
+ createCliDiagnostic('SOUNDSCRIPT_INIT_CONFLICT', 'Cannot initialize a new project because soundscript files already exist.', pathExists(projectPath) ? projectPath : entryPath, {
457
+ hint: "Remove the existing files first, or run 'soundscript init --mode existing' in an existing TypeScript project.",
458
+ }),
459
+ ];
460
+ return {
461
+ exitCode: CLI_FAILURE_EXIT_CODE,
462
+ output: formatDiagnostics(diagnostics, workingDirectory),
463
+ diagnostics,
464
+ projectPath,
465
+ workingDirectory,
466
+ };
467
+ }
468
+ await makeDirectory(join(workingDirectory, 'src'));
469
+ await writeTextFile(projectPath, `${JSON.stringify({
470
+ compilerOptions: {
471
+ strict: true,
472
+ noEmit: true,
473
+ target: 'ES2022',
474
+ module: 'ESNext',
475
+ moduleResolution: 'Bundler',
476
+ },
477
+ include: ['src/**/*.ts', 'src/**/*.sts'],
478
+ }, null, 2)}\n`);
479
+ await writeTextFile(entryPath, [
480
+ "console.log('Hello from soundscript');",
481
+ '',
482
+ ].join('\n'));
483
+ return {
484
+ exitCode: 0,
485
+ output: [
486
+ `Initialized a new soundscript project in ${workingDirectory}.`,
487
+ '',
488
+ 'Next steps:',
489
+ ' 1. Edit src/main.sts',
490
+ ' 2. Run soundscript check',
491
+ '',
492
+ ].join('\n'),
493
+ diagnostics: [],
494
+ projectPath,
495
+ workingDirectory,
496
+ };
497
+ }
498
+ const baseProjectPath = join(workingDirectory, 'tsconfig.json');
499
+ const projectPath = join(workingDirectory, 'tsconfig.soundscript.json');
500
+ if (!pathExists(baseProjectPath)) {
501
+ const diagnostics = [
502
+ createCliDiagnostic('SOUNDSCRIPT_INIT_BASE_PROJECT_MISSING', 'Cannot initialize existing-project mode without a tsconfig.json.', baseProjectPath, {
503
+ hint: "Create a base tsconfig.json first, or run 'soundscript init' to create a fresh soundscript project.",
504
+ }),
505
+ ];
506
+ return {
507
+ exitCode: CLI_FAILURE_EXIT_CODE,
508
+ output: formatDiagnostics(diagnostics, workingDirectory),
509
+ diagnostics,
510
+ projectPath,
511
+ workingDirectory,
512
+ };
513
+ }
514
+ if (pathExists(projectPath)) {
515
+ const diagnostics = [
516
+ createCliDiagnostic('SOUNDSCRIPT_INIT_CONFLICT', 'Cannot initialize existing-project mode because tsconfig.soundscript.json already exists.', projectPath, {
517
+ hint: `Use 'soundscript check --project ${basename(projectPath)}' with the existing config, or delete it before re-running init.`,
518
+ }),
519
+ ];
520
+ return {
521
+ exitCode: CLI_FAILURE_EXIT_CODE,
522
+ output: formatDiagnostics(diagnostics, workingDirectory),
523
+ diagnostics,
524
+ projectPath,
525
+ workingDirectory,
526
+ };
527
+ }
528
+ const include = deriveExistingProjectInclude(baseProjectPath);
529
+ await writeTextFile(projectPath, `${JSON.stringify({
530
+ extends: './tsconfig.json',
531
+ compilerOptions: {
532
+ strict: true,
533
+ noEmit: true,
534
+ target: 'ES2022',
535
+ module: 'ESNext',
536
+ moduleResolution: 'Bundler',
537
+ },
538
+ ...(include ? { include } : {}),
539
+ }, null, 2)}\n`);
540
+ return {
541
+ exitCode: 0,
542
+ output: [
543
+ 'Initialized soundscript for an existing TypeScript project.',
544
+ '',
545
+ `Use: soundscript check --project ${basename(projectPath)}`,
546
+ '',
547
+ ].join('\n'),
548
+ diagnostics: [],
549
+ projectPath,
550
+ workingDirectory,
551
+ };
552
+ }
553
+ async function runBuildWatch(command, buildProjectFn, watchFileSystemFn) {
554
+ const watcher = watchFileSystemFn(dirname(command.projectPath));
555
+ let building = false;
556
+ let pending = false;
557
+ const rebuild = async () => {
558
+ if (building) {
559
+ pending = true;
560
+ return;
561
+ }
562
+ building = true;
563
+ try {
564
+ const result = await buildProjectFn(command);
565
+ writeStdout(result.output);
566
+ }
567
+ finally {
568
+ building = false;
569
+ if (pending) {
570
+ pending = false;
571
+ await rebuild();
572
+ }
573
+ }
574
+ };
575
+ await rebuild();
576
+ for await (const event of watcher) {
577
+ if (event.kind === 'other') {
578
+ continue;
579
+ }
580
+ await rebuild();
581
+ }
582
+ throw new Error('soundscript build watch ended unexpectedly.');
583
+ }
584
+ function maybeResolveLocalCliPath(argument, workingDirectory) {
585
+ if (argument.startsWith('-')) {
586
+ return undefined;
587
+ }
588
+ const resolved = argument.startsWith('/') ? argument : join(workingDirectory, argument);
589
+ return pathExists(resolved) ? resolved : undefined;
590
+ }
591
+ async function runSubprocess(command, args, cwd) {
592
+ return await runCommand(command, args, cwd);
593
+ }
594
+ async function runNodeCommand(command, runSubprocessFn) {
595
+ const tempDirectory = await createTempDirectory('soundscript-node-');
596
+ try {
597
+ const materialized = await materializeRuntimeGraph({
598
+ entryPaths: [command.entryPath],
599
+ outDir: tempDirectory,
600
+ workingDirectory: command.workingDirectory,
601
+ });
602
+ if (materialized.exitCode !== 0 || !materialized.artifacts) {
603
+ return {
604
+ exitCode: materialized.exitCode,
605
+ output: materialized.output,
606
+ diagnostics: materialized.diagnostics,
607
+ projectPath: command.entryPath,
608
+ workingDirectory: command.workingDirectory,
609
+ };
610
+ }
611
+ const entryOutputPath = materialized.artifacts.entryOutputPaths[0];
612
+ if (!entryOutputPath) {
613
+ return createCliFailureResult('text', 'cli', command.workingDirectory, {
614
+ code: 'SOUNDSCRIPT_RUNTIME_NO_ENTRY',
615
+ message: 'Runtime materialization did not produce an entry output.',
616
+ projectPath: materialized.artifacts.projectPath,
617
+ });
618
+ }
619
+ const subprocess = await runSubprocessFn('node', ['--enable-source-maps', entryOutputPath, ...command.forwardedArgs], command.workingDirectory);
620
+ return {
621
+ exitCode: subprocess.exitCode,
622
+ output: subprocess.output,
623
+ diagnostics: [],
624
+ projectPath: materialized.artifacts.projectPath,
625
+ workingDirectory: command.workingDirectory,
626
+ };
627
+ }
628
+ finally {
629
+ await removePath(tempDirectory).catch(() => undefined);
630
+ }
631
+ }
632
+ function replaceLocalDenoEntryArgs(denoSubcommand, forwardedArgs, materialized, workingDirectory) {
633
+ const rewrittenArgs = [...forwardedArgs];
634
+ if (denoSubcommand === 'run') {
635
+ for (let index = 0; index < rewrittenArgs.length; index += 1) {
636
+ const candidate = maybeResolveLocalCliPath(rewrittenArgs[index], workingDirectory);
637
+ if (!candidate) {
638
+ continue;
639
+ }
640
+ rewrittenArgs[index] = materialized.entryOutputPaths[0];
641
+ break;
642
+ }
643
+ return rewrittenArgs;
644
+ }
645
+ let materializedIndex = 0;
646
+ for (let index = 0; index < rewrittenArgs.length; index += 1) {
647
+ const candidate = maybeResolveLocalCliPath(rewrittenArgs[index], workingDirectory);
648
+ if (!candidate) {
649
+ continue;
650
+ }
651
+ const mapped = materialized.entryOutputPaths[materializedIndex];
652
+ if (mapped) {
653
+ rewrittenArgs[index] = mapped;
654
+ materializedIndex += 1;
655
+ }
656
+ }
657
+ return rewrittenArgs;
658
+ }
659
+ async function runDenoCommand(command, runSubprocessFn) {
660
+ const tempDirectory = await createTempDirectory('soundscript-deno-');
661
+ try {
662
+ const localEntryPaths = command.denoSubcommand === 'run'
663
+ ? (() => {
664
+ for (const argument of command.forwardedArgs) {
665
+ const candidate = maybeResolveLocalCliPath(argument, command.workingDirectory);
666
+ if (candidate) {
667
+ return [candidate];
668
+ }
669
+ }
670
+ return [];
671
+ })()
672
+ : command.forwardedArgs
673
+ .map((argument) => maybeResolveLocalCliPath(argument, command.workingDirectory))
674
+ .filter((path) => path !== undefined);
675
+ const materialized = localEntryPaths.length > 0
676
+ ? await materializeRuntimeGraph({
677
+ entryPaths: localEntryPaths,
678
+ outDir: tempDirectory,
679
+ workingDirectory: command.workingDirectory,
680
+ })
681
+ : {
682
+ artifacts: {
683
+ emittedFiles: [],
684
+ entryOutputPaths: [],
685
+ outDir: tempDirectory,
686
+ projectPath: '',
687
+ },
688
+ diagnostics: [],
689
+ exitCode: 0,
690
+ output: '',
691
+ };
692
+ if (materialized.exitCode !== 0 || !materialized.artifacts) {
693
+ return {
694
+ exitCode: materialized.exitCode,
695
+ output: materialized.output,
696
+ diagnostics: materialized.diagnostics,
697
+ projectPath: localEntryPaths[0] ?? '',
698
+ workingDirectory: command.workingDirectory,
699
+ };
700
+ }
701
+ const rewrittenArgs = replaceLocalDenoEntryArgs(command.denoSubcommand, command.forwardedArgs, materialized.artifacts, command.workingDirectory);
702
+ const subprocess = await runSubprocessFn('deno', [command.denoSubcommand, ...rewrittenArgs], command.workingDirectory);
703
+ return {
704
+ exitCode: subprocess.exitCode,
705
+ output: subprocess.output,
706
+ diagnostics: [],
707
+ projectPath: materialized.artifacts.projectPath,
708
+ workingDirectory: command.workingDirectory,
709
+ };
710
+ }
711
+ finally {
712
+ await removePath(tempDirectory).catch(() => undefined);
713
+ }
714
+ }
715
+ export function runCli(args, workingDirectory = runtimeCwd(), dependencies = {}) {
716
+ const command = parseCommand(args, workingDirectory);
717
+ const buildProjectFn = dependencies.buildProject ?? buildProject;
718
+ const compileProjectFn = dependencies.compileProject ?? compileProject;
719
+ const expandProjectFn = dependencies.expandProject ?? expandProject;
720
+ const runSubprocessFn = dependencies.runSubprocess ?? runSubprocess;
721
+ const runProgramFn = dependencies.runProgram ?? runProgram;
722
+ const watchFileSystemFn = dependencies.watchFileSystem ?? watchFileSystem;
723
+ switch (command.kind) {
724
+ case 'help':
725
+ return Promise.resolve({
726
+ exitCode: 0,
727
+ output: `${renderHelp()}\n`,
728
+ diagnostics: [],
729
+ projectPath: '',
730
+ workingDirectory,
731
+ });
732
+ case 'invalid':
733
+ if (detectRequestedOutputFormat(args) !== 'text') {
734
+ return Promise.resolve(createCliFailureResult(detectRequestedOutputFormat(args), detectRequestedCommand(args), workingDirectory, {
735
+ code: 'SOUNDSCRIPT_INVALID_COMMAND',
736
+ message: command.message,
737
+ hint: "Run 'soundscript --help' for the supported subcommands and options.",
738
+ }));
739
+ }
740
+ return Promise.resolve({
741
+ exitCode: CLI_FAILURE_EXIT_CODE,
742
+ output: renderInvalidCommand(command.message),
743
+ diagnostics: [
744
+ createCliDiagnostic('SOUNDSCRIPT_INVALID_COMMAND', command.message, workingDirectory, {
745
+ hint: "Run 'soundscript --help' for the supported subcommands and options.",
746
+ }),
747
+ ],
748
+ projectPath: '',
749
+ workingDirectory,
750
+ });
751
+ case 'version':
752
+ return Promise.resolve({
753
+ exitCode: 0,
754
+ output: `${VERSION}\n`,
755
+ diagnostics: [],
756
+ projectPath: '',
757
+ workingDirectory,
758
+ });
759
+ case 'init':
760
+ return initializeProject(command, workingDirectory);
761
+ case 'node':
762
+ return runNodeCommand(command, runSubprocessFn);
763
+ case 'deno':
764
+ return runDenoCommand(command, runSubprocessFn);
765
+ case 'explain': {
766
+ const found = getDiagnosticReference(command.code) !== undefined;
767
+ return Promise.resolve({
768
+ exitCode: found ? 0 : FINDINGS_EXIT_CODE,
769
+ output: renderExplainOutput(command.code, command.format),
770
+ diagnostics: [],
771
+ projectPath: '',
772
+ workingDirectory,
773
+ });
774
+ }
775
+ case 'lsp':
776
+ return Promise.resolve({
777
+ exitCode: CLI_FAILURE_EXIT_CODE,
778
+ output: "The 'lsp' subcommand is meant to be launched from the main executable entrypoint.\n",
779
+ diagnostics: [],
780
+ projectPath: '',
781
+ workingDirectory,
782
+ });
783
+ case 'editor-worker':
784
+ return Promise.resolve({
785
+ exitCode: CLI_FAILURE_EXIT_CODE,
786
+ output: "The 'editor-worker' subcommand is meant to be launched from the main executable entrypoint.\n",
787
+ diagnostics: [],
788
+ projectPath: '',
789
+ workingDirectory,
790
+ });
791
+ case 'editor-project':
792
+ return runEditorProjectCommand(command).catch((error) => createInternalErrorResult('json', 'expand', command.projectPath, command.workingDirectory, error));
793
+ case 'build': {
794
+ if (!pathExists(command.projectPath)) {
795
+ return Promise.resolve(createMissingProjectResult(command.format, 'build', command.projectPath, command.workingDirectory));
796
+ }
797
+ if (command.watch) {
798
+ return runBuildWatch(command, buildProjectFn, watchFileSystemFn).then(() => ({
799
+ exitCode: 0,
800
+ output: '',
801
+ diagnostics: [],
802
+ projectPath: command.projectPath,
803
+ workingDirectory: command.workingDirectory,
804
+ }));
805
+ }
806
+ return buildProjectFn(command)
807
+ .then((result) => {
808
+ if (result.exitCode !== 0 && result.diagnostics.length === 0) {
809
+ return createInternalErrorResult(command.format, 'build', command.projectPath, command.workingDirectory, undefined, result.output);
810
+ }
811
+ return {
812
+ ...result,
813
+ output: command.format === 'text' ? result.output : renderDiagnosticsOutput(command.format, 'build', command.projectPath, command.workingDirectory, result.exitCode, result.diagnostics, result.artifacts),
814
+ projectPath: command.projectPath,
815
+ workingDirectory: command.workingDirectory,
816
+ };
817
+ })
818
+ .catch((error) => createInternalErrorResult(command.format, 'build', command.projectPath, command.workingDirectory, error));
819
+ }
820
+ case 'check': {
821
+ if (!pathExists(command.projectPath)) {
822
+ return Promise.resolve(createMissingProjectResult(command.format, 'check', command.projectPath, command.workingDirectory));
823
+ }
824
+ let result;
825
+ try {
826
+ result = runProgramFn(command);
827
+ }
828
+ catch (error) {
829
+ return Promise.resolve(createInternalErrorResult(command.format, 'check', command.projectPath, command.workingDirectory, error));
830
+ }
831
+ if (result.exitCode !== 0 && result.diagnostics.length === 0) {
832
+ return Promise.resolve(createInternalErrorResult(command.format, 'check', command.projectPath, command.workingDirectory, undefined, result.output));
833
+ }
834
+ return Promise.resolve({
835
+ ...result,
836
+ output: command.format === 'text' ? result.output : renderDiagnosticsOutput(command.format, 'check', command.projectPath, command.workingDirectory, result.exitCode, result.diagnostics),
837
+ projectPath: command.projectPath,
838
+ workingDirectory: command.workingDirectory,
839
+ });
840
+ }
841
+ case 'compile': {
842
+ if (!pathExists(command.projectPath)) {
843
+ return Promise.resolve(createMissingProjectResult(command.format, 'compile', command.projectPath, command.workingDirectory));
844
+ }
845
+ let result;
846
+ try {
847
+ result = compileProjectFn(command);
848
+ }
849
+ catch (error) {
850
+ return Promise.resolve(createInternalErrorResult(command.format, 'compile', command.projectPath, command.workingDirectory, error));
851
+ }
852
+ if (result.exitCode !== 0 && result.diagnostics.length === 0) {
853
+ return Promise.resolve(createInternalErrorResult(command.format, 'compile', command.projectPath, command.workingDirectory, undefined, result.output));
854
+ }
855
+ return Promise.resolve({
856
+ ...result,
857
+ output: command.format === 'text' ? result.output : renderDiagnosticsOutput(command.format, 'compile', command.projectPath, command.workingDirectory, result.exitCode, result.diagnostics, result.artifacts),
858
+ projectPath: command.projectPath,
859
+ workingDirectory: command.workingDirectory,
860
+ });
861
+ }
862
+ case 'expand': {
863
+ if (!pathExists(command.projectPath)) {
864
+ return Promise.resolve(createMissingProjectResult(command.format, 'expand', command.projectPath, command.workingDirectory));
865
+ }
866
+ return expandProjectFn(command)
867
+ .then((result) => {
868
+ if (result.exitCode !== 0 && result.diagnostics.length === 0) {
869
+ return createInternalErrorResult(command.format, 'expand', command.projectPath, command.workingDirectory, undefined, result.output);
870
+ }
871
+ if (command.filePath && result.exitCode === 0) {
872
+ return {
873
+ ...result,
874
+ projectPath: command.projectPath,
875
+ workingDirectory: command.workingDirectory,
876
+ };
877
+ }
878
+ return {
879
+ ...result,
880
+ output: command.format === 'text' ? result.output : renderDiagnosticsOutput(command.format, 'expand', command.projectPath, command.workingDirectory, result.exitCode, result.diagnostics, result.artifacts),
881
+ projectPath: command.projectPath,
882
+ workingDirectory: command.workingDirectory,
883
+ };
884
+ })
885
+ .catch((error) => createInternalErrorResult(command.format, 'expand', command.projectPath, command.workingDirectory, error));
886
+ }
887
+ default: {
888
+ const exhaustiveCheck = command;
889
+ return exhaustiveCheck;
890
+ }
891
+ }
892
+ }