ttsc 0.10.2 → 0.11.0-dev.20260517

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 (106) hide show
  1. package/README.md +8 -0
  2. package/cmd/ttsc/api_compile.go +106 -106
  3. package/cmd/ttsc/api_transform.go +54 -54
  4. package/cmd/ttsc/main.go +103 -103
  5. package/cmd/ttscserver/helpers_test.go +27 -0
  6. package/cmd/ttscserver/main.go +154 -0
  7. package/cmd/ttscserver/run_lsp_reports_getwd_error_test.go +34 -0
  8. package/cmd/ttscserver/run_lsp_reports_server_error_test.go +42 -0
  9. package/driver/lsp_envelope.go +136 -0
  10. package/driver/lsp_frame.go +121 -0
  11. package/driver/lsp_plugin.go +150 -0
  12. package/driver/lsp_proxy.go +394 -0
  13. package/driver/lsp_server.go +197 -0
  14. package/go.mod +4 -0
  15. package/go.sum +4 -0
  16. package/internal/cwd/cwd.go +8 -8
  17. package/lib/TtscCompiler.d.ts +15 -16
  18. package/lib/TtscCompiler.js +15 -16
  19. package/lib/TtscCompiler.js.map +1 -1
  20. package/lib/compiler/internal/compileProjectInMemory.d.ts +4 -1
  21. package/lib/compiler/internal/compileProjectInMemory.js +4 -1
  22. package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
  23. package/lib/compiler/internal/project/readProjectConfig.js.map +1 -1
  24. package/lib/compiler/internal/runBuild.js +43 -1
  25. package/lib/compiler/internal/runBuild.js.map +1 -1
  26. package/lib/compiler/internal/sharedHostHelpers.d.ts +12 -12
  27. package/lib/compiler/internal/sharedHostHelpers.js +12 -12
  28. package/lib/defineTtscPlugin.d.ts +18 -0
  29. package/lib/defineTtscPlugin.js +7 -0
  30. package/lib/defineTtscPlugin.js.map +1 -0
  31. package/lib/index.d.ts +4 -3
  32. package/lib/index.js +4 -3
  33. package/lib/index.js.map +1 -1
  34. package/lib/launcher/internal/prepareExecution.js +1 -1
  35. package/lib/launcher/internal/prepareExecution.js.map +1 -1
  36. package/lib/launcher/internal/resolveTtscserverBinary.d.ts +12 -0
  37. package/lib/launcher/internal/resolveTtscserverBinary.js +43 -0
  38. package/lib/launcher/internal/resolveTtscserverBinary.js.map +1 -0
  39. package/lib/launcher/internal/runTtsc.js +47 -8
  40. package/lib/launcher/internal/runTtsc.js.map +1 -1
  41. package/lib/launcher/internal/runTtscserver.d.ts +20 -0
  42. package/lib/launcher/internal/runTtscserver.js +125 -0
  43. package/lib/launcher/internal/runTtscserver.js.map +1 -0
  44. package/lib/launcher/internal/runTtsx.js +1 -1
  45. package/lib/launcher/internal/runTtsx.js.map +1 -1
  46. package/lib/launcher/ttscserver.d.ts +2 -0
  47. package/lib/launcher/ttscserver.js +9 -0
  48. package/lib/launcher/ttscserver.js.map +1 -0
  49. package/lib/plugin/internal/buildSourcePlugin.d.ts +9 -0
  50. package/lib/plugin/internal/buildSourcePlugin.js +197 -2
  51. package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
  52. package/lib/plugin/internal/loadProjectPlugins.js +86 -8
  53. package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
  54. package/lib/structures/ITtscCompilerContext.d.ts +1 -1
  55. package/lib/structures/ITtscCompilerDiagnostic.d.ts +3 -3
  56. package/lib/structures/ITtscCompilerResult.d.ts +10 -22
  57. package/lib/structures/ITtscCompilerTransformation.d.ts +2 -2
  58. package/lib/structures/ITtscPlugin.d.ts +37 -4
  59. package/lib/structures/ITtscPlugin.js +0 -4
  60. package/lib/structures/ITtscPlugin.js.map +1 -1
  61. package/lib/structures/ITtscPluginContributor.d.ts +26 -0
  62. package/lib/structures/ITtscPluginContributor.js +3 -0
  63. package/lib/structures/ITtscPluginContributor.js.map +1 -0
  64. package/lib/structures/ITtscPluginFactoryContext.d.ts +5 -5
  65. package/lib/structures/ITtscProjectPluginConfig.d.ts +2 -2
  66. package/lib/structures/TtscPluginStage.d.ts +4 -3
  67. package/lib/structures/index.d.ts +1 -0
  68. package/lib/structures/index.js +1 -0
  69. package/lib/structures/index.js.map +1 -1
  70. package/lib/structures/internal/ITtscLoadedNativePlugin.d.ts +3 -0
  71. package/lib/structures/internal/TtscBuildOptions.d.ts +13 -0
  72. package/lib/structures/internal/TtscCommonOptions.d.ts +5 -2
  73. package/package.json +10 -9
  74. package/shim/lsp/extra-shim.json +4 -0
  75. package/shim/lsp/go.mod +16 -0
  76. package/shim/lsp/go.sum +26 -0
  77. package/shim/lsp/shim.go +42 -0
  78. package/shim/printer/shim.go +5 -5
  79. package/src/TtscCompiler.ts +15 -16
  80. package/src/compiler/internal/compileProjectInMemory.ts +4 -1
  81. package/src/compiler/internal/project/readProjectConfig.ts +0 -1
  82. package/src/compiler/internal/runBuild.ts +43 -1
  83. package/src/compiler/internal/sharedHostHelpers.ts +12 -12
  84. package/src/defineTtscPlugin.ts +26 -0
  85. package/src/index.ts +4 -3
  86. package/src/launcher/internal/prepareExecution.ts +1 -1
  87. package/src/launcher/internal/resolveTtscserverBinary.ts +51 -0
  88. package/src/launcher/internal/runTtsc.ts +53 -11
  89. package/src/launcher/internal/runTtscserver.ts +92 -0
  90. package/src/launcher/internal/runTtsx.ts +1 -1
  91. package/src/launcher/ttscserver.ts +8 -0
  92. package/src/plugin/internal/buildSourcePlugin.ts +231 -12
  93. package/src/plugin/internal/loadProjectPlugins.ts +108 -8
  94. package/src/structures/ITtscCompilerContext.ts +1 -1
  95. package/src/structures/ITtscCompilerDiagnostic.ts +3 -3
  96. package/src/structures/ITtscCompilerResult.ts +10 -22
  97. package/src/structures/ITtscCompilerTransformation.ts +2 -2
  98. package/src/structures/ITtscPlugin.ts +37 -11
  99. package/src/structures/ITtscPluginContributor.ts +27 -0
  100. package/src/structures/ITtscPluginFactoryContext.ts +5 -5
  101. package/src/structures/ITtscProjectPluginConfig.ts +2 -2
  102. package/src/structures/TtscPluginStage.ts +4 -3
  103. package/src/structures/index.ts +1 -0
  104. package/src/structures/internal/ITtscLoadedNativePlugin.ts +3 -0
  105. package/src/structures/internal/TtscBuildOptions.ts +13 -0
  106. package/src/structures/internal/TtscCommonOptions.ts +5 -2
@@ -0,0 +1,27 @@
1
+ /**
2
+ * One contributor entry inside `ITtscPlugin.contributors`.
3
+ *
4
+ * The native builder copies `source` into `<scratch>/contrib/<name>/` and adds
5
+ * a blank-import for `<host-module>/contrib/<name>` to the synthesized
6
+ * `ttsc_contributions.go` placed alongside the host's main package.
7
+ */
8
+ export interface ITtscPluginContributor {
9
+ /**
10
+ * Sub-package name.
11
+ *
12
+ * Forms the final import path together with the host plugin's Go module path;
13
+ * must match `/^[a-z][a-z0-9_]*$/` — a lowercase ASCII letter followed by
14
+ * lowercase letters, digits, or underscores — and be unique within one plugin
15
+ * build.
16
+ */
17
+ name: string;
18
+
19
+ /**
20
+ * Absolute path to the contributor's Go source directory.
21
+ *
22
+ * Every `.go` file under this directory is copied into the scratch build tree
23
+ * as a sub-package of the host plugin's module. Subdirectories are copied
24
+ * recursively; `go.mod` files, `node_modules`, and `.git` are pruned.
25
+ */
26
+ source: string;
27
+ }
@@ -10,8 +10,8 @@ import type { ITtscProjectPluginConfig } from "./ITtscProjectPluginConfig";
10
10
  * project root.
11
11
  *
12
12
  * The factory runs in Node.js while ttsc is loading `compilerOptions.plugins`.
13
- * It should only create the descriptor. Heavy validation and TypeScript-Go
14
- * work belong in the Go sidecar selected by {@link ITtscPlugin.source}.
13
+ * It should only create the descriptor. Heavy validation and TypeScript-Go work
14
+ * belong in the Go sidecar selected by {@link ITtscPlugin.source}.
15
15
  */
16
16
  export interface ITtscPluginFactoryContext<T = ITtscProjectPluginConfig> {
17
17
  /**
@@ -19,8 +19,8 @@ export interface ITtscPluginFactoryContext<T = ITtscProjectPluginConfig> {
19
19
  *
20
20
  * This is the package's own native helper, not the plugin sidecar and not the
21
21
  * JavaScript launcher. Most plugins do not need it; it is provided for
22
- * advanced factories that need to derive behavior from the active ttsc
23
- * native host.
22
+ * advanced factories that need to derive behavior from the active ttsc native
23
+ * host.
24
24
  */
25
25
  binary: string;
26
26
 
@@ -36,7 +36,7 @@ export interface ITtscPluginFactoryContext<T = ITtscProjectPluginConfig> {
36
36
  /**
37
37
  * Original `compilerOptions.plugins[]` entry that loaded this plugin.
38
38
  *
39
- * ttsc reserves `transform` and `enabled`. Every other property is
39
+ * Ttsc reserves `transform` and `enabled`. Every other property is
40
40
  * plugin-owned config and is later serialized unchanged into the native
41
41
  * sidecar manifest.
42
42
  */
@@ -6,7 +6,7 @@
6
6
  * or plugin packages expose through `package.json`. ttsc deliberately keeps it
7
7
  * open-ended because plugin packages own their own config fields.
8
8
  *
9
- * ttsc interprets only two properties:
9
+ * Ttsc interprets only two properties:
10
10
  *
11
11
  * - `transform`: the JavaScript module specifier used to load the plugin
12
12
  * descriptor or factory.
@@ -42,7 +42,7 @@ export interface ITtscProjectPluginConfig {
42
42
  /**
43
43
  * Plugin-specific config passed through unchanged to the native sidecar.
44
44
  *
45
- * ttsc does not validate these fields. Plugin packages should document their
45
+ * Ttsc does not validate these fields. Plugin packages should document their
46
46
  * own config contract and validate it inside their factory or Go sidecar.
47
47
  */
48
48
  [key: string]: unknown;
@@ -3,8 +3,9 @@
3
3
  *
4
4
  * - `"transform"`: participates in the TypeScript-Go transform path. Transform
5
5
  * plugins do not receive emitted JavaScript or emitted file text.
6
- * - `"check"`: runs before emit and reports diagnostics only. Use this for
7
- * lint or validation plugins that should fail the compile before JavaScript
8
- * or declaration output is generated.
6
+ * - `"check"`: runs before emit and reports diagnostics. Use this for lint or
7
+ * validation plugins that should fail the compile before JavaScript or
8
+ * declaration output is generated. Check plugins may also implement a `fix`
9
+ * command, which `ttsc fix` invokes with emit disabled.
9
10
  */
10
11
  export type TtscPluginStage = "transform" | "check";
@@ -3,6 +3,7 @@ export * from "./ITtscCompilerDiagnostic";
3
3
  export * from "./ITtscCompilerResult";
4
4
  export * from "./ITtscCompilerTransformation";
5
5
  export * from "./ITtscPlugin";
6
+ export * from "./ITtscPluginContributor";
6
7
  export * from "./ITtscPluginFactoryContext";
7
8
  export * from "./ITtscProjectPluginConfig";
8
9
  export * from "./TtscPluginStage";
@@ -1,3 +1,4 @@
1
+ import type { ITtscPluginContributor } from "../ITtscPluginContributor";
1
2
  import type { ITtscProjectPluginConfig } from "../ITtscProjectPluginConfig";
2
3
  import type { TtscPluginStage } from "../TtscPluginStage";
3
4
 
@@ -7,6 +8,8 @@ export interface ITtscLoadedNativePlugin {
7
8
  binary: string;
8
9
  /** Original tsconfig plugin entry passed unchanged to the sidecar. */
9
10
  config: ITtscProjectPluginConfig;
11
+ /** Contributor Go sources statically linked into the binary, if any. */
12
+ contributors?: readonly ITtscPluginContributor[];
10
13
  /** Stable plugin name used in diagnostics and native manifests. */
11
14
  name: string;
12
15
  /** Go source directory selected by the plugin descriptor. */
@@ -12,6 +12,19 @@ export interface TtscBuildOptions extends TtscCommonOptions {
12
12
  * - `undefined`: follow the resolved tsconfig exactly.
13
13
  */
14
14
  emit?: boolean;
15
+ /**
16
+ * Invoke fix-capable check-stage plugins before the final no-emit check.
17
+ * Source files may be rewritten; JavaScript/declaration emit stays disabled.
18
+ */
19
+ fix?: boolean;
20
+ /**
21
+ * Invoke format-capable check-stage plugins. Source files may be rewritten
22
+ * with formatter-class edits (whitespace, punctuation, ordering); diagnostics
23
+ * are not reported and JavaScript/declaration emit stays disabled. The
24
+ * launcher selects this through the `ttsc format` subcommand and rejects
25
+ * combination with watch mode, single-file mode, or an explicit `--emit`.
26
+ */
27
+ format?: boolean;
15
28
  /** Per-call TypeScript-Go `outDir` override. */
16
29
  outDir?: string;
17
30
  /** Suppress summary banners from ttsc/native sidecars. Defaults to `true`. */
@@ -1,6 +1,9 @@
1
1
  import type { ITtscProjectPluginConfig } from "../ITtscProjectPluginConfig";
2
2
 
3
- /** Internal options shared by the CLI build, single-file emit, and runtime paths. */
3
+ /**
4
+ * Internal options shared by the CLI build, single-file emit, and runtime
5
+ * paths.
6
+ */
4
7
  export interface TtscCommonOptions {
5
8
  /**
6
9
  * Explicit TypeScript-Go executable.
@@ -23,7 +26,7 @@ export interface TtscCommonOptions {
23
26
  * Override project plugin loading for this invocation.
24
27
  *
25
28
  * - `false`: ignore `compilerOptions.plugins` completely.
26
- * - array: use these plugin entries instead of the project config entries.
29
+ * - Array: use these plugin entries instead of the project config entries.
27
30
  * - `undefined`: use the project config entries as written.
28
31
  */
29
32
  plugins?: readonly ITtscProjectPluginConfig[] | false;