ttsc 0.26.2 → 0.27.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 (111) hide show
  1. package/README.md +9 -0
  2. package/cmd/ttsc/api_transform.go +17 -3
  3. package/cmd/ttscgraph/auxiliary_identity_state_tracks_retargets_not_source_contents_test.go +85 -0
  4. package/cmd/ttscgraph/disk_realpath_other.go +16 -0
  5. package/cmd/ttscgraph/disk_realpath_windows.go +56 -0
  6. package/cmd/ttscgraph/serve.go +104 -35
  7. package/driver/emit_plugin.go +20 -3
  8. package/driver/graph.go +64 -11
  9. package/driver/input_observation.go +273 -0
  10. package/driver/input_observation_test.go +149 -0
  11. package/driver/plugins.go +384 -4
  12. package/driver/program.go +54 -1
  13. package/driver/resolution_candidates.go +13 -5
  14. package/driver/rewrite.go +45 -2
  15. package/lib/TtscCompiler.d.ts +12 -11
  16. package/lib/TtscCompiler.js +44 -29
  17. package/lib/TtscCompiler.js.map +1 -1
  18. package/lib/compiler/internal/captureProcessOutput.js +2 -2
  19. package/lib/compiler/internal/captureProcessOutput.js.map +1 -1
  20. package/lib/compiler/internal/compileProjectInMemory.js +4 -3
  21. package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
  22. package/lib/compiler/internal/resolveEmittedJavaScript.d.ts +2 -0
  23. package/lib/compiler/internal/resolveEmittedJavaScript.js +3 -0
  24. package/lib/compiler/internal/resolveEmittedJavaScript.js.map +1 -1
  25. package/lib/compiler/internal/runBuild.d.ts +1 -1
  26. package/lib/compiler/internal/runBuild.js +80 -34
  27. package/lib/compiler/internal/runBuild.js.map +1 -1
  28. package/lib/compiler/internal/runSingleFileEmit.js +2 -2
  29. package/lib/compiler/internal/runSingleFileEmit.js.map +1 -1
  30. package/lib/compiler/internal/sharedHostHelpers.d.ts +28 -0
  31. package/lib/compiler/internal/sharedHostHelpers.js +39 -0
  32. package/lib/compiler/internal/sharedHostHelpers.js.map +1 -1
  33. package/lib/compiler/internal/startResidentTransform.js +12 -4
  34. package/lib/compiler/internal/startResidentTransform.js.map +1 -1
  35. package/lib/compiler/internal/transformProjectInMemory.d.ts +3 -0
  36. package/lib/compiler/internal/transformProjectInMemory.js +239 -35
  37. package/lib/compiler/internal/transformProjectInMemory.js.map +1 -1
  38. package/lib/flags/schema.js +12 -5
  39. package/lib/flags/schema.js.map +1 -1
  40. package/lib/internal/createCanonicalTempDirectory.d.ts +17 -0
  41. package/lib/internal/createCanonicalTempDirectory.js +42 -0
  42. package/lib/internal/createCanonicalTempDirectory.js.map +1 -0
  43. package/lib/internal/projectInputPathIdentity.d.ts +3 -0
  44. package/lib/internal/projectInputPathIdentity.js +11 -5
  45. package/lib/internal/projectInputPathIdentity.js.map +1 -1
  46. package/lib/internal/resolveNodeBinary.d.ts +14 -0
  47. package/lib/internal/resolveNodeBinary.js +150 -0
  48. package/lib/internal/resolveNodeBinary.js.map +1 -0
  49. package/lib/internal/resolveSafeCacheCleanupTargets.d.ts +15 -0
  50. package/lib/internal/resolveSafeCacheCleanupTargets.js +61 -0
  51. package/lib/internal/resolveSafeCacheCleanupTargets.js.map +1 -0
  52. package/lib/launcher/internal/prepareExecution.d.ts +3 -0
  53. package/lib/launcher/internal/prepareExecution.js +42 -14
  54. package/lib/launcher/internal/prepareExecution.js.map +1 -1
  55. package/lib/launcher/internal/runTtsc.js +25 -13
  56. package/lib/launcher/internal/runTtsc.js.map +1 -1
  57. package/lib/launcher/internal/runTtscserver.js +18 -3
  58. package/lib/launcher/internal/runTtscserver.js.map +1 -1
  59. package/lib/launcher/internal/runTtsx.js +2 -0
  60. package/lib/launcher/internal/runTtsx.js.map +1 -1
  61. package/lib/launcher/internal/runtimeHooks.d.ts +37 -1
  62. package/lib/launcher/internal/runtimeHooks.js +653 -62
  63. package/lib/launcher/internal/runtimeHooks.js.map +1 -1
  64. package/lib/plugin/internal/buildSourcePlugin.d.ts +62 -8
  65. package/lib/plugin/internal/buildSourcePlugin.js +754 -72
  66. package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
  67. package/lib/plugin/internal/loadProjectPlugins.d.ts +17 -5
  68. package/lib/plugin/internal/loadProjectPlugins.js +1339 -77
  69. package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
  70. package/lib/register.d.ts +1 -0
  71. package/lib/register.js +46 -0
  72. package/lib/register.js.map +1 -0
  73. package/lib/structures/ITtscCompilerContext.d.ts +6 -3
  74. package/lib/structures/ITtscCompilerTransformation.d.ts +31 -0
  75. package/lib/structures/ITtscPlugin.d.ts +33 -0
  76. package/package.json +16 -9
  77. package/shim/checker/go.mod +9 -0
  78. package/shim/checker/go.sum +22 -0
  79. package/shim/checker/shim.go +75 -0
  80. package/shim/compiler/incremental.go +45 -8
  81. package/src/TtscCompiler.ts +55 -33
  82. package/src/compiler/internal/captureProcessOutput.ts +3 -2
  83. package/src/compiler/internal/compileProjectInMemory.ts +4 -3
  84. package/src/compiler/internal/resolveEmittedJavaScript.ts +6 -0
  85. package/src/compiler/internal/runBuild.ts +102 -39
  86. package/src/compiler/internal/runSingleFileEmit.ts +2 -2
  87. package/src/compiler/internal/sharedHostHelpers.ts +44 -0
  88. package/src/compiler/internal/startResidentTransform.ts +12 -3
  89. package/src/compiler/internal/transformProjectInMemory.ts +410 -39
  90. package/src/flags/schema.ts +12 -5
  91. package/src/internal/createCanonicalTempDirectory.ts +53 -0
  92. package/src/internal/projectInputPathIdentity.ts +17 -4
  93. package/src/internal/resolveNodeBinary.ts +173 -0
  94. package/src/internal/resolveSafeCacheCleanupTargets.ts +85 -0
  95. package/src/launcher/internal/prepareExecution.ts +50 -14
  96. package/src/launcher/internal/runTtsc.ts +24 -13
  97. package/src/launcher/internal/runTtscserver.ts +18 -3
  98. package/src/launcher/internal/runTtsx.ts +2 -0
  99. package/src/launcher/internal/runtimeHooks.ts +823 -66
  100. package/src/plugin/internal/buildSourcePlugin.ts +984 -79
  101. package/src/plugin/internal/loadProjectPlugins.ts +1718 -104
  102. package/src/register.ts +47 -0
  103. package/src/structures/ITtscCompilerContext.ts +6 -3
  104. package/src/structures/ITtscCompilerTransformation.ts +39 -0
  105. package/src/structures/ITtscPlugin.ts +36 -0
  106. package/tools/shim_audit/baseline.json +0 -1
  107. package/utility/host.go +9 -3
  108. package/lib/internal/assertSafeExplicitCacheDirectory.d.ts +0 -5
  109. package/lib/internal/assertSafeExplicitCacheDirectory.js +0 -26
  110. package/lib/internal/assertSafeExplicitCacheDirectory.js.map +0 -1
  111. package/src/internal/assertSafeExplicitCacheDirectory.ts +0 -29
@@ -2,6 +2,50 @@ import path from "node:path";
2
2
 
3
3
  import type { ITtscLoadedNativePlugin } from "../../structures/internal/ITtscLoadedNativePlugin";
4
4
 
5
+ /**
6
+ * Environment channel carrying the JSON-encoded tsgo argv ttsc forwards to a
7
+ * native sidecar. Mirrors `driver.TsgoArgsEnv` on the Go side; see
8
+ * `runBuild.ts::createNativeTsgoArgs` for why the payload is not a CLI flag.
9
+ */
10
+ export const TSGO_ARGS_ENV = "TTSC_TSGO_ARGS";
11
+
12
+ /**
13
+ * Drop a forwarded-tsgo payload this invocation did not publish itself.
14
+ *
15
+ * Every sidecar env starts from `process.env`, so a ttsc that is itself running
16
+ * inside a plugin sidecar — `@ttsc/lint` evaluating a config file through
17
+ * `ttsx`, for instance — would otherwise hand the outer run's `--strict` to its
18
+ * own sidecars, and `driver.LoadProgram` would apply it. The forwarded argv is
19
+ * per-invocation state the spawning host owns, the same rule
20
+ * `TTSC_PLUGIN_CONFIG_DIR` already follows. A caller that named the variable
21
+ * explicitly keeps it.
22
+ */
23
+ export function clearInheritedTsgoArgs(
24
+ env: NodeJS.ProcessEnv,
25
+ callerEnv: NodeJS.ProcessEnv | undefined,
26
+ ): void {
27
+ if (callerEnv?.[TSGO_ARGS_ENV] === undefined) {
28
+ delete env[TSGO_ARGS_ENV];
29
+ }
30
+ }
31
+
32
+ /**
33
+ * The `{ ...process.env, ...callerEnv }` a child process inherits, minus a
34
+ * forwarded-tsgo payload this lane never published.
35
+ *
36
+ * Use it at every spawn whose child can reach `driver.LoadProgram` — the
37
+ * `api-compile` / `api-transform` hosts, and the plugin loader, whose `ttsx`
38
+ * descriptor evaluation compiles a project of its own. One rule at every site
39
+ * beats four sites each reasoning about whether the variable could be present.
40
+ */
41
+ export function inheritedSidecarEnv(
42
+ callerEnv: NodeJS.ProcessEnv | undefined,
43
+ ): NodeJS.ProcessEnv {
44
+ const env: NodeJS.ProcessEnv = { ...process.env, ...callerEnv };
45
+ clearInheritedTsgoArgs(env, callerEnv);
46
+ return env;
47
+ }
48
+
5
49
  /**
6
50
  * Resolve the caller-declared plugin config anchor to an absolute path, or
7
51
  * `undefined` when the caller did not declare one.
@@ -1,5 +1,6 @@
1
1
  import path from "node:path";
2
2
 
3
+ import { resolveNodeBinary } from "../../internal/resolveNodeBinary";
3
4
  import { loadProjectPlugins } from "../../plugin/internal/loadProjectPlugins";
4
5
  import type { ITtscCompilerContext } from "../../structures/ITtscCompilerContext";
5
6
  import type { ITtscLoadedNativePlugin } from "../../structures/internal/ITtscLoadedNativePlugin";
@@ -9,6 +10,8 @@ import { resolveBinary } from "./resolveBinary";
9
10
  import { resolveTsgo } from "./resolveTsgo";
10
11
  import {
11
12
  assertSharedHostCompatibility,
13
+ clearInheritedTsgoArgs,
14
+ inheritedSidecarEnv,
12
15
  linkedTransformPlugins,
13
16
  resolvePluginConfigDir,
14
17
  selectSharedHostPlugin,
@@ -52,7 +55,7 @@ export function startResidentTransform(
52
55
  cacheDir: context.cacheDir ?? context.env?.TTSC_CACHE_DIR,
53
56
  cwd,
54
57
  entries: context.plugins,
55
- env: { ...process.env, ...context.env },
58
+ env: inheritedSidecarEnv(context.env),
56
59
  pluginConfigDir: context.pluginConfigDir,
57
60
  projectRoot: context.projectRoot,
58
61
  tsconfig: project.path,
@@ -79,7 +82,7 @@ export function startResidentTransform(
79
82
  ],
80
83
  binary: host.binary,
81
84
  cwd: project.root,
82
- env: residentEnv(context, tsgoBinary, loaded.nativePlugins),
85
+ env: residentEnv(context, project.root, tsgoBinary, loaded.nativePlugins),
83
86
  });
84
87
  return { process: resident, projectRoot: project.root };
85
88
  }
@@ -95,13 +98,13 @@ export function startResidentTransform(
95
98
  */
96
99
  function residentEnv(
97
100
  context: ITtscCompilerContext,
101
+ projectRoot: string,
98
102
  tsgoBinary: string,
99
103
  nativePlugins: readonly ITtscLoadedNativePlugin[],
100
104
  ): NodeJS.ProcessEnv {
101
105
  const pluginConfigDir = resolvePluginConfigDir(context);
102
106
  const env: NodeJS.ProcessEnv = {
103
107
  ...process.env,
104
- TTSC_NODE_BINARY: process.env.TTSC_NODE_BINARY ?? process.execPath,
105
108
  ...(pluginConfigDir === undefined
106
109
  ? {}
107
110
  : { TTSC_PLUGIN_CONFIG_DIR: pluginConfigDir }),
@@ -111,6 +114,9 @@ function residentEnv(
111
114
  path.join(__dirname, "..", "..", "launcher", "ttsx.js"),
112
115
  ...context.env,
113
116
  };
117
+ const node = resolveNodeBinary(env, projectRoot);
118
+ if (node === undefined) delete env.TTSC_NODE_BINARY;
119
+ else env.TTSC_NODE_BINARY = node;
114
120
  // The anchor is per-invocation state owned by this host: when this run
115
121
  // declared none (and the caller's env does not name one), drop any value
116
122
  // inherited from an ancestor ttsc process so a nested build never
@@ -121,6 +127,9 @@ function residentEnv(
121
127
  ) {
122
128
  delete env.TTSC_PLUGIN_CONFIG_DIR;
123
129
  }
130
+ // This lane forwards no tsgo argv of its own, so anything inherited belongs
131
+ // to an outer ttsc run and must not reach the resident sidecar.
132
+ clearInheritedTsgoArgs(env, context.env);
124
133
  const linked = linkedTransformPlugins(nativePlugins);
125
134
  if (linked.length !== 0) {
126
135
  env.TTSC_LINKED_PLUGINS_JSON = serializeNativePlugins(linked);