ttsc 0.19.1 → 0.19.2

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 (37) hide show
  1. package/README.md +68 -186
  2. package/cmd/graphdump/main.go +21 -1
  3. package/cmd/ttsc/api_compile.go +3 -13
  4. package/cmd/ttsc/api_transform.go +13 -0
  5. package/cmd/ttscgraph/dump.go +40 -1
  6. package/cmd/ttscgraph/serve.go +194 -25
  7. package/cmd/ttscgraph/serve_error_response_still_names_its_mode_test.go +73 -0
  8. package/cmd/ttscgraph/serve_protocol_fails_the_stream_on_an_unaddressable_request_line_test.go +43 -0
  9. package/cmd/ttscgraph/serve_protocol_version_matches_the_typescript_client_test.go +48 -0
  10. package/cmd/ttscgraph/serve_snapshot_proves_its_program_without_a_second_read_test.go +109 -0
  11. package/driver/graph.go +133 -0
  12. package/internal/graph/diagnostics.go +6 -5
  13. package/internal/graph/dump.go +69 -17
  14. package/internal/graph/dump_diagnostics_ride_the_generation_that_built_it_test.go +79 -0
  15. package/internal/graph/dump_evidence_skips_leading_trivia_test.go +1 -1
  16. package/internal/graph/dump_is_a_function_of_the_source_test.go +1 -1
  17. package/internal/graph/dump_never_serializes_a_list_as_null_test.go +76 -0
  18. package/internal/graph/dump_schema_version_matches_the_typescript_client_test.go +48 -0
  19. package/internal/graph/dump_serializes_the_full_graph_test.go +21 -7
  20. package/internal/graph/node_modifiers_emit_union_strings_test.go +1 -1
  21. package/internal/graph/provenance.go +312 -0
  22. package/lib/TtscCompiler.js +9 -4
  23. package/lib/TtscCompiler.js.map +1 -1
  24. package/lib/compiler/internal/transformProjectInMemory.d.ts +4 -0
  25. package/lib/compiler/internal/transformProjectInMemory.js +67 -12
  26. package/lib/compiler/internal/transformProjectInMemory.js.map +1 -1
  27. package/lib/structures/ITtscCompilerTransformation.d.ts +98 -0
  28. package/package.json +8 -8
  29. package/shim/compiler/incremental.go +58 -0
  30. package/shim/core/shim.go +5 -0
  31. package/src/TtscCompiler.ts +19 -4
  32. package/src/compiler/internal/transformProjectInMemory.ts +106 -12
  33. package/src/structures/ITtscCompilerTransformation.ts +107 -0
  34. package/tools/shim_audit/baseline.json +2 -1
  35. package/tools/shim_audit/main.go +17 -0
  36. package/utility/host.go +17 -15
  37. package/cmd/ttscgraph/serve_protocol_rejects_invalid_request_line_test.go +0 -43
package/utility/host.go CHANGED
@@ -41,9 +41,14 @@ type hostOptions struct {
41
41
  // transformResult is the JSON envelope written to stdout by RunTransform.
42
42
  // TypeScript maps relative output key → printer output; Diagnostics is
43
43
  // reserved for future plugin diagnostics (currently always empty/omitted).
44
+ // Graph carries the host-owned reference graph (direct resolved reference
45
+ // edges, global-scope files, tsconfig extends chain) keyed like TypeScript,
46
+ // so cache layers can register every file whose content can influence a
47
+ // transformed module without per-plugin reporting.
44
48
  type transformResult struct {
45
- Diagnostics []any `json:"diagnostics,omitempty"`
46
- TypeScript map[string]string `json:"typescript"`
49
+ Diagnostics []any `json:"diagnostics,omitempty"`
50
+ TypeScript map[string]string `json:"typescript"`
51
+ Graph *driver.TransformGraph `json:"graph,omitempty"`
47
52
  }
48
53
 
49
54
  // RunCheck validates the project and linked plugin configuration without
@@ -130,12 +135,17 @@ func RunTransformWithIO(args []string, stdout, stderr io.Writer) int {
130
135
  return 2
131
136
  }
132
137
  defer prog.Close()
138
+ // Compute the reference graph before linked plugins run: plugin hooks
139
+ // mutate parsed ASTs in place (e.g. @ttsc/paths rewrites import
140
+ // specifiers), and the graph must describe the original source's resolved
141
+ // references — the transform's inputs — not the mutated output.
142
+ graph := driver.NewTransformGraph(prog, opts.cwd)
133
143
  if err := prog.ApplyLinkedPlugins(); err != nil {
134
144
  fmt.Fprintln(opts.stderr, err)
135
145
  return 2
136
146
  }
137
147
  printer := shimprinter.NewPrinter(shimprinter.PrinterOptions{}, shimprinter.PrintHandlers{}, nil)
138
- out := transformResult{TypeScript: map[string]string{}}
148
+ out := transformResult{TypeScript: map[string]string{}, Graph: graph}
139
149
  for _, file := range prog.SourceFiles() {
140
150
  text := shimprinter.EmitSourceFile(printer, file)
141
151
  out.TypeScript[apiOutputKey(opts.cwd, file.FileName())] = text
@@ -406,17 +416,9 @@ func isSourcePreambleOutputTarget(fileName string) bool {
406
416
 
407
417
  // apiOutputKey converts an absolute fileName to a path relative to cwd for use
408
418
  // as the JSON key in RunTransform output. Falls back to the slash-normalized
409
- // absolute path when the file lives outside the project root.
419
+ // absolute path when the file lives outside the project root. Delegates to
420
+ // the driver so every envelope section (typescript, graph) shares one key
421
+ // implementation and consumers can join sections by key.
410
422
  func apiOutputKey(cwd, fileName string) string {
411
- rel, err := filepath.Rel(cwd, fileName)
412
- if err != nil || isOutsideRelativePath(rel) {
413
- return filepath.ToSlash(fileName)
414
- }
415
- return filepath.ToSlash(rel)
416
- }
417
-
418
- // isOutsideRelativePath reports whether rel escapes the project root (starts
419
- // with ".." or is exactly "..").
420
- func isOutsideRelativePath(rel string) bool {
421
- return rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator))
423
+ return driver.TransformOutputKey(cwd, fileName)
422
424
  }
@@ -1,43 +0,0 @@
1
- package main
2
-
3
- import (
4
- "bytes"
5
- "encoding/json"
6
- "strings"
7
- "testing"
8
- )
9
-
10
- // TestServeProtocolRejectsInvalidRequestLine verifies a malformed NDJSON line
11
- // answers with a protocol error and never poisons the following requests.
12
- //
13
- // The launcher only ever writes well-formed requests, so a garbage line means
14
- // a corrupted pipe or a foreign writer; the server must report it (with the
15
- // zero ID, since none could be parsed) and keep serving instead of exiting.
16
- //
17
- // 1. Send a non-JSON line followed by a valid request.
18
- // 2. Assert the first response carries an error and no dump.
19
- // 3. Assert the second response is the normal initial snapshot.
20
- func TestServeProtocolRejectsInvalidRequestLine(t *testing.T) {
21
- root := graphSessionFixture(t)
22
- input := strings.NewReader("not-json\n{\"id\":1}\n")
23
- var output bytes.Buffer
24
-
25
- if code := serveSnapshots(input, &output, root, "tsconfig.json"); code != 0 {
26
- t.Fatalf("serveSnapshots exited %d", code)
27
- }
28
- decoder := json.NewDecoder(&output)
29
- var invalid serveResponse
30
- var initial serveResponse
31
- if err := decoder.Decode(&invalid); err != nil {
32
- t.Fatal(err)
33
- }
34
- if err := decoder.Decode(&initial); err != nil {
35
- t.Fatal(err)
36
- }
37
- if invalid.ID != 0 || invalid.Error == "" || !strings.Contains(invalid.Error, "invalid request") || invalid.Dump != nil || invalid.Changed {
38
- t.Fatalf("invalid line response: %#v", invalid)
39
- }
40
- if initial.ID != 1 || initial.Mode != "initial" || !initial.Changed || initial.Dump == nil || initial.Error != "" {
41
- t.Fatalf("follow-up response: %#v", initial)
42
- }
43
- }