ttsc 0.5.0 → 0.6.0-dev.20250430

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 (162) hide show
  1. package/README.md +1 -1
  2. package/go.mod +1 -1
  3. package/go.sum +2 -2
  4. package/lib/api.d.ts +15 -67
  5. package/lib/api.js +14 -3
  6. package/lib/api.js.map +1 -1
  7. package/lib/cli.js.map +1 -1
  8. package/lib/native.d.ts +8 -20
  9. package/lib/native.js.map +1 -1
  10. package/lib/platform.d.ts +7 -25
  11. package/lib/platform.js.map +1 -1
  12. package/lib/plugin.d.ts +13 -41
  13. package/lib/plugin.js +2 -2
  14. package/lib/plugin.js.map +1 -1
  15. package/lib/project.d.ts +11 -29
  16. package/lib/project.js.map +1 -1
  17. package/lib/runner/cli.js.map +1 -1
  18. package/lib/runner/register.d.ts +6 -13
  19. package/lib/runner/register.js.map +1 -1
  20. package/lib/source-build.d.ts +11 -22
  21. package/lib/source-build.js +25 -1
  22. package/lib/source-build.js.map +1 -1
  23. package/lib/structures/ITtscBuildOptions.d.ts +14 -0
  24. package/lib/structures/ITtscBuildOptions.js +3 -0
  25. package/lib/structures/ITtscBuildOptions.js.map +1 -0
  26. package/lib/structures/ITtscBuildResult.d.ts +6 -0
  27. package/lib/structures/ITtscBuildResult.js +3 -0
  28. package/lib/structures/ITtscBuildResult.js.map +1 -0
  29. package/lib/structures/ITtscBuildSourcePluginOptions.d.ts +8 -0
  30. package/lib/structures/ITtscBuildSourcePluginOptions.js +3 -0
  31. package/lib/structures/ITtscBuildSourcePluginOptions.js.map +1 -0
  32. package/lib/structures/ITtscCacheKeyInput.d.ts +7 -0
  33. package/lib/structures/ITtscCacheKeyInput.js +3 -0
  34. package/lib/structures/ITtscCacheKeyInput.js.map +1 -0
  35. package/lib/structures/ITtscCheckOptions.d.ts +2 -0
  36. package/lib/structures/ITtscCheckOptions.js +3 -0
  37. package/lib/structures/ITtscCheckOptions.js.map +1 -0
  38. package/lib/structures/ITtscCommonOptions.d.ts +22 -0
  39. package/lib/structures/ITtscCommonOptions.js +3 -0
  40. package/lib/structures/ITtscCommonOptions.js.map +1 -0
  41. package/lib/structures/ITtscLoadPluginsOptions.d.ts +8 -0
  42. package/lib/structures/ITtscLoadPluginsOptions.js +3 -0
  43. package/lib/structures/ITtscLoadPluginsOptions.js.map +1 -0
  44. package/lib/structures/ITtscLoadedNativePlugin.d.ts +7 -0
  45. package/lib/structures/ITtscLoadedNativePlugin.js +3 -0
  46. package/lib/structures/ITtscLoadedNativePlugin.js.map +1 -0
  47. package/lib/structures/ITtscLoadedPlugins.d.ts +11 -0
  48. package/lib/structures/ITtscLoadedPlugins.js +3 -0
  49. package/lib/structures/ITtscLoadedPlugins.js.map +1 -0
  50. package/lib/structures/ITtscNativeBackend.d.ts +10 -0
  51. package/lib/structures/ITtscNativeBackend.js +3 -0
  52. package/lib/structures/ITtscNativeBackend.js.map +1 -0
  53. package/lib/structures/ITtscNativePluginContractVersion.d.ts +1 -0
  54. package/lib/structures/ITtscNativePluginContractVersion.js +3 -0
  55. package/lib/structures/ITtscNativePluginContractVersion.js.map +1 -0
  56. package/lib/structures/ITtscNativePluginShape.d.ts +8 -0
  57. package/lib/structures/ITtscNativePluginShape.js +3 -0
  58. package/lib/structures/ITtscNativePluginShape.js.map +1 -0
  59. package/lib/structures/ITtscNativeRewriteMode.d.ts +1 -0
  60. package/lib/structures/ITtscNativeRewriteMode.js +3 -0
  61. package/lib/structures/ITtscNativeRewriteMode.js.map +1 -0
  62. package/lib/structures/ITtscNativeSource.d.ts +4 -0
  63. package/lib/structures/ITtscNativeSource.js +3 -0
  64. package/lib/structures/ITtscNativeSource.js.map +1 -0
  65. package/lib/structures/ITtscParsedProjectConfig.d.ts +9 -0
  66. package/lib/structures/ITtscParsedProjectConfig.js +3 -0
  67. package/lib/structures/ITtscParsedProjectConfig.js.map +1 -0
  68. package/lib/structures/ITtscPlugin.d.ts +10 -0
  69. package/lib/structures/ITtscPlugin.js +3 -0
  70. package/lib/structures/ITtscPlugin.js.map +1 -0
  71. package/lib/structures/ITtscPluginFactory.d.ts +4 -0
  72. package/lib/structures/ITtscPluginFactory.js +3 -0
  73. package/lib/structures/ITtscPluginFactory.js.map +1 -0
  74. package/lib/structures/ITtscPluginFactoryContext.d.ts +8 -0
  75. package/lib/structures/ITtscPluginFactoryContext.js +3 -0
  76. package/lib/structures/ITtscPluginFactoryContext.js.map +1 -0
  77. package/lib/structures/ITtscPluginModule.d.ts +3 -0
  78. package/lib/structures/ITtscPluginModule.js +3 -0
  79. package/lib/structures/ITtscPluginModule.js.map +1 -0
  80. package/lib/structures/ITtscPreparedExecution.d.ts +5 -0
  81. package/lib/structures/ITtscPreparedExecution.js +3 -0
  82. package/lib/structures/ITtscPreparedExecution.js.map +1 -0
  83. package/lib/structures/ITtscProjectLocatorOptions.d.ts +5 -0
  84. package/lib/structures/ITtscProjectLocatorOptions.js +3 -0
  85. package/lib/structures/ITtscProjectLocatorOptions.js.map +1 -0
  86. package/lib/structures/ITtscProjectPluginConfig.d.ts +5 -0
  87. package/lib/structures/ITtscProjectPluginConfig.js +3 -0
  88. package/lib/structures/ITtscProjectPluginConfig.js.map +1 -0
  89. package/lib/structures/ITtscRegisterOptions.d.ts +6 -0
  90. package/lib/structures/ITtscRegisterOptions.js +3 -0
  91. package/lib/structures/ITtscRegisterOptions.js.map +1 -0
  92. package/lib/structures/ITtscResolveGoBinaryOptions.d.ts +7 -0
  93. package/lib/structures/ITtscResolveGoBinaryOptions.js +3 -0
  94. package/lib/structures/ITtscResolveGoBinaryOptions.js.map +1 -0
  95. package/lib/structures/ITtscResolveOptions.d.ts +20 -0
  96. package/lib/structures/ITtscResolveOptions.js +3 -0
  97. package/lib/structures/ITtscResolveOptions.js.map +1 -0
  98. package/lib/structures/ITtscResolvedTsgo.d.ts +8 -0
  99. package/lib/structures/ITtscResolvedTsgo.js +3 -0
  100. package/lib/structures/ITtscResolvedTsgo.js.map +1 -0
  101. package/lib/structures/ITtscTransformOptions.d.ts +12 -0
  102. package/lib/structures/ITtscTransformOptions.js +3 -0
  103. package/lib/structures/ITtscTransformOptions.js.map +1 -0
  104. package/lib/structures/ITtscTsgoResolveOptions.d.ts +14 -0
  105. package/lib/structures/ITtscTsgoResolveOptions.js +3 -0
  106. package/lib/structures/ITtscTsgoResolveOptions.js.map +1 -0
  107. package/lib/tsgo.d.ts +6 -24
  108. package/lib/tsgo.js.map +1 -1
  109. package/package.json +10 -10
  110. package/shim/ast/go.mod +1 -1
  111. package/shim/ast/lint.go +2 -0
  112. package/shim/bundled/go.mod +1 -1
  113. package/shim/checker/go.mod +1 -1
  114. package/shim/compiler/go.mod +1 -1
  115. package/shim/core/go.mod +1 -1
  116. package/shim/diagnosticwriter/go.mod +1 -1
  117. package/shim/parser/go.mod +1 -1
  118. package/shim/scanner/go.mod +1 -1
  119. package/shim/tsoptions/go.mod +1 -1
  120. package/shim/tspath/go.mod +1 -1
  121. package/shim/vfs/cachedvfs/go.mod +1 -1
  122. package/shim/vfs/go.mod +1 -1
  123. package/shim/vfs/osvfs/go.mod +1 -1
  124. package/src/api.ts +108 -155
  125. package/src/cli.ts +10 -10
  126. package/src/native.ts +9 -23
  127. package/src/platform.ts +10 -27
  128. package/src/plugin.ts +37 -74
  129. package/src/project.ts +18 -37
  130. package/src/runner/cli.ts +5 -5
  131. package/src/runner/register.ts +32 -43
  132. package/src/source-build.ts +45 -25
  133. package/src/structures/ITtscBuildOptions.ts +19 -0
  134. package/src/structures/ITtscBuildResult.ts +6 -0
  135. package/src/structures/ITtscBuildSourcePluginOptions.ts +9 -0
  136. package/src/structures/ITtscCacheKeyInput.ts +7 -0
  137. package/src/structures/ITtscCheckOptions.ts +3 -0
  138. package/src/structures/ITtscCommonOptions.ts +23 -0
  139. package/src/structures/ITtscLoadPluginsOptions.ts +9 -0
  140. package/src/structures/ITtscLoadedNativePlugin.ts +8 -0
  141. package/src/structures/ITtscLoadedPlugins.ts +12 -0
  142. package/src/structures/ITtscNativeBackend.ts +11 -0
  143. package/src/structures/ITtscNativePluginContractVersion.ts +1 -0
  144. package/src/structures/ITtscNativePluginShape.ts +9 -0
  145. package/src/structures/ITtscNativeRewriteMode.ts +1 -0
  146. package/src/structures/ITtscNativeSource.ts +4 -0
  147. package/src/structures/ITtscParsedProjectConfig.ts +10 -0
  148. package/src/structures/ITtscPlugin.ts +11 -0
  149. package/src/structures/ITtscPluginFactory.ts +7 -0
  150. package/src/structures/ITtscPluginFactoryContext.ts +9 -0
  151. package/src/structures/ITtscPluginModule.ts +4 -0
  152. package/src/structures/ITtscPreparedExecution.ts +5 -0
  153. package/src/structures/ITtscProjectLocatorOptions.ts +5 -0
  154. package/src/structures/ITtscProjectPluginConfig.ts +5 -0
  155. package/src/structures/ITtscRegisterOptions.ts +7 -0
  156. package/src/structures/ITtscResolveGoBinaryOptions.ts +7 -0
  157. package/src/structures/ITtscResolveOptions.ts +20 -0
  158. package/src/structures/ITtscResolvedTsgo.ts +8 -0
  159. package/src/structures/ITtscTransformOptions.ts +13 -0
  160. package/src/structures/ITtscTsgoResolveOptions.ts +14 -0
  161. package/src/tsgo.ts +6 -24
  162. package/test/source-build.test.ts +13 -0
@@ -4,17 +4,13 @@ import * as fs from "node:fs";
4
4
  import { createRequire } from "node:module";
5
5
  import * as path from "node:path";
6
6
 
7
- import type { TtscNativeSource } from "./native";
7
+ import type { ITtscBuildSourcePluginOptions } from "./structures/ITtscBuildSourcePluginOptions";
8
+ import type { ITtscResolveGoBinaryOptions } from "./structures/ITtscResolveGoBinaryOptions";
8
9
 
9
- export interface BuildSourcePluginOptions {
10
- source: TtscNativeSource;
11
- pluginName: string;
12
- baseDir: string;
13
- ttscVersion: string;
14
- tsgoVersion: string;
15
- }
10
+ export type { ITtscBuildSourcePluginOptions } from "./structures/ITtscBuildSourcePluginOptions";
11
+ export type { ITtscResolveGoBinaryOptions } from "./structures/ITtscResolveGoBinaryOptions";
16
12
 
17
- export function buildSourcePlugin(opts: BuildSourcePluginOptions): string {
13
+ export function buildSourcePlugin(opts: ITtscBuildSourcePluginOptions): string {
18
14
  const dir = path.isAbsolute(opts.source.dir)
19
15
  ? opts.source.dir
20
16
  : path.resolve(opts.baseDir, opts.source.dir);
@@ -81,10 +77,42 @@ function writeGoWork(scratchDir: string, useDirs: readonly string[]): void {
81
77
  for (const dir of useDirs) {
82
78
  useLines.push(`\t${dir.replace(/\\/g, "/")}`);
83
79
  }
84
- const goWork = `go 1.26\n\nuse (\n${useLines.join("\n")}\n)\n`;
80
+ const replaceLines = sourceBuildWorkspaceReplacements(useDirs);
81
+ const replaceBlock =
82
+ replaceLines.length === 0 ? "" : `\n\n${replaceLines.join("\n")}\n`;
83
+ const goWork = `go 1.26\n\nuse (\n${useLines.join("\n")}\n)${replaceBlock}`;
85
84
  fs.writeFileSync(path.join(scratchDir, "go.work"), goWork, "utf8");
86
85
  }
87
86
 
87
+ export function sourceBuildWorkspaceReplacements(
88
+ useDirs: readonly string[],
89
+ ): string[] {
90
+ const ttscRoot = useDirs.find((dir) =>
91
+ hasModulePath(dir, "github.com/samchon/ttsc/packages/ttsc"),
92
+ );
93
+ if (!ttscRoot) {
94
+ return [];
95
+ }
96
+ return [
97
+ `replace github.com/samchon/ttsc/packages/ttsc v0.0.0 => ${ttscRoot.replace(/\\/g, "/")}`,
98
+ ];
99
+ }
100
+
101
+ function hasModulePath(dir: string, modulePath: string): boolean {
102
+ try {
103
+ const goMod = fs.readFileSync(path.join(dir, "go.mod"), "utf8");
104
+ return new RegExp(`^module\\s+${escapeRegExp(modulePath)}\\s*$`, "m").test(
105
+ goMod,
106
+ );
107
+ } catch {
108
+ return false;
109
+ }
110
+ }
111
+
112
+ function escapeRegExp(value: string): string {
113
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
114
+ }
115
+
88
116
  function runGoBuild(
89
117
  cwd: string,
90
118
  entry: string,
@@ -178,20 +206,12 @@ function walkToolFiles(dir: string): string[] {
178
206
  return out;
179
207
  }
180
208
 
181
- export interface ResolveGoBinaryOptions {
182
- arch?: string;
183
- env?: NodeJS.ProcessEnv;
184
- localGoLookup?: () => string | null;
185
- platform?: NodeJS.Platform;
186
- resolver?: (request: string) => string;
187
- }
188
-
189
- export function goBinaryName(opts: ResolveGoBinaryOptions = {}): string {
209
+ export function goBinaryName(opts: ITtscResolveGoBinaryOptions = {}): string {
190
210
  return (opts.platform ?? process.platform) === "win32" ? "go.exe" : "go";
191
211
  }
192
212
 
193
213
  export function bundledGoPackageRequest(
194
- opts: ResolveGoBinaryOptions = {},
214
+ opts: ITtscResolveGoBinaryOptions = {},
195
215
  ): string {
196
216
  return `@ttsc/${goPlatformKey(opts)}/bin/go/bin/${goBinaryName(opts)}`;
197
217
  }
@@ -280,7 +300,7 @@ function resolveGoBinary(): string {
280
300
  }
281
301
 
282
302
  export function resolveGoCompiler(
283
- opts: ResolveGoBinaryOptions = {},
303
+ opts: ITtscResolveGoBinaryOptions = {},
284
304
  ): string {
285
305
  const env = opts.env ?? process.env;
286
306
  const explicit = env.TTSC_GO_BINARY;
@@ -306,7 +326,7 @@ export function resolveGoCompiler(
306
326
  return "go";
307
327
  }
308
328
 
309
- function defaultLocalGoBinaryPath(opts: ResolveGoBinaryOptions): string | null {
329
+ function defaultLocalGoBinaryPath(opts: ITtscResolveGoBinaryOptions): string | null {
310
330
  const candidate = path.resolve(
311
331
  __dirname,
312
332
  "..",
@@ -318,18 +338,18 @@ function defaultLocalGoBinaryPath(opts: ResolveGoBinaryOptions): string | null {
318
338
  return fs.existsSync(candidate) ? candidate : null;
319
339
  }
320
340
 
321
- function goPlatformKey(opts: ResolveGoBinaryOptions = {}): string {
341
+ function goPlatformKey(opts: ITtscResolveGoBinaryOptions = {}): string {
322
342
  return `${opts.platform ?? process.platform}-${opts.arch ?? process.arch}`;
323
343
  }
324
344
 
325
- interface KeyInputs {
345
+ interface ITtscSourceBuildCacheKeyInput {
326
346
  dir: string;
327
347
  entry: string;
328
348
  ttscVersion: string;
329
349
  tsgoVersion: string;
330
350
  }
331
351
 
332
- export function computeCacheKey(inputs: KeyInputs): string {
352
+ export function computeCacheKey(inputs: ITtscSourceBuildCacheKeyInput): string {
333
353
  const hash = crypto.createHash("sha256");
334
354
  hash.update(`ttsc=${inputs.ttscVersion}\n`);
335
355
  hash.update(`tsgo=${inputs.tsgoVersion}\n`);
@@ -0,0 +1,19 @@
1
+ import type { ITtscCommonOptions } from "./ITtscCommonOptions";
2
+
3
+ export interface ITtscBuildOptions extends ITtscCommonOptions {
4
+ /** Path to tsconfig.json. Default: `tsconfig.json`. */
5
+ tsconfig?: string;
6
+ /**
7
+ * Emit override. `true` forces emit, `false` forces noEmit, `undefined`
8
+ * follows tsconfig.
9
+ */
10
+ emit?: boolean;
11
+ /** Override compilerOptions.outDir for this invocation. */
12
+ outDir?: string;
13
+ /** Suppress the per-call summary banner. Default: `true`. */
14
+ quiet?: boolean;
15
+ /** @internal Caller already ran diagnostics and accepts responsibility. */
16
+ skipDiagnosticsCheck?: boolean;
17
+ /** @internal Force `tsgo --listEmittedFiles` for caller-side output discovery. */
18
+ forceListEmittedFiles?: boolean;
19
+ }
@@ -0,0 +1,6 @@
1
+ export interface ITtscBuildResult {
2
+ emittedFiles?: string[];
3
+ status: number;
4
+ stdout: string;
5
+ stderr: string;
6
+ }
@@ -0,0 +1,9 @@
1
+ import type { ITtscNativeSource } from "./ITtscNativeSource";
2
+
3
+ export interface ITtscBuildSourcePluginOptions {
4
+ source: ITtscNativeSource;
5
+ pluginName: string;
6
+ baseDir: string;
7
+ ttscVersion: string;
8
+ tsgoVersion: string;
9
+ }
@@ -0,0 +1,7 @@
1
+ export interface ITtscCacheKeyInput {
2
+ file: string;
3
+ tsconfig: string;
4
+ version: string;
5
+ mode?: string;
6
+ extra?: readonly string[];
7
+ }
@@ -0,0 +1,3 @@
1
+ import type { ITtscBuildOptions } from "./ITtscBuildOptions";
2
+
3
+ export type ITtscCheckOptions = Omit<ITtscBuildOptions, "emit">;
@@ -0,0 +1,23 @@
1
+ import type { ITtscProjectPluginConfig } from "./ITtscProjectPluginConfig";
2
+ import type { ITtscResolveOptions } from "./ITtscResolveOptions";
3
+
4
+ export interface ITtscCommonOptions extends ITtscResolveOptions {
5
+ /** Absolute path to an already-resolved tsgo binary. Skips package resolution. */
6
+ binary?: string;
7
+ /** Working directory passed to the child process. */
8
+ cwd?: string;
9
+ /** Extra environment variables; merged onto `process.env`. */
10
+ env?: NodeJS.ProcessEnv;
11
+ /**
12
+ * Override project plugin loading. `false` disables tsconfig plugins; an
13
+ * array replaces the tsconfig `compilerOptions.plugins` list.
14
+ */
15
+ plugins?: readonly ITtscProjectPluginConfig[] | false;
16
+ /**
17
+ * Override the native rewrite backend. Defaults to the loaded plugin mode.
18
+ *
19
+ * @deprecated Prefer plugin-declared `native.mode`; this override is for
20
+ * low-level tests and migration probes.
21
+ */
22
+ rewriteMode?: string;
23
+ }
@@ -0,0 +1,9 @@
1
+ import type { ITtscProjectPluginConfig } from "./ITtscProjectPluginConfig";
2
+
3
+ export interface ITtscLoadPluginsOptions {
4
+ binary: string;
5
+ cwd?: string;
6
+ entries?: readonly ITtscProjectPluginConfig[] | false;
7
+ file?: string;
8
+ tsconfig?: string;
9
+ }
@@ -0,0 +1,8 @@
1
+ import type { ITtscNativeBackend } from "./ITtscNativeBackend";
2
+ import type { ITtscProjectPluginConfig } from "./ITtscProjectPluginConfig";
3
+
4
+ export interface ITtscLoadedNativePlugin {
5
+ backend: ITtscNativeBackend;
6
+ config: ITtscProjectPluginConfig;
7
+ name: string;
8
+ }
@@ -0,0 +1,12 @@
1
+ import type { ITtscLoadedNativePlugin } from "./ITtscLoadedNativePlugin";
2
+ import type { ITtscParsedProjectConfig } from "./ITtscParsedProjectConfig";
3
+ import type { ITtscPlugin } from "./ITtscPlugin";
4
+
5
+ export interface ITtscLoadedPlugins {
6
+ compatibilityFallback: boolean;
7
+ nativeBinary: string | null;
8
+ nativeBinaries: string[];
9
+ nativePlugins: ITtscLoadedNativePlugin[];
10
+ plugins: ITtscPlugin[];
11
+ project: ITtscParsedProjectConfig;
12
+ }
@@ -0,0 +1,11 @@
1
+ import type { ITtscNativePluginContractVersion } from "./ITtscNativePluginContractVersion";
2
+ import type { ITtscNativeRewriteMode } from "./ITtscNativeRewriteMode";
3
+ import type { ITtscNativeSource } from "./ITtscNativeSource";
4
+
5
+ export interface ITtscNativeBackend {
6
+ mode: ITtscNativeRewriteMode;
7
+ binary?: string;
8
+ source?: ITtscNativeSource;
9
+ contractVersion?: ITtscNativePluginContractVersion;
10
+ capabilities?: readonly string[];
11
+ }
@@ -0,0 +1 @@
1
+ export type ITtscNativePluginContractVersion = 1;
@@ -0,0 +1,9 @@
1
+ import type { ITtscNativeBackend } from "./ITtscNativeBackend";
2
+ import type { ITtscNativeRewriteMode } from "./ITtscNativeRewriteMode";
3
+
4
+ export interface ITtscNativePluginShape {
5
+ name: string;
6
+ native?: ITtscNativeBackend;
7
+ nativeMode?: ITtscNativeRewriteMode;
8
+ nativeBinary?: string;
9
+ }
@@ -0,0 +1 @@
1
+ export type ITtscNativeRewriteMode = string;
@@ -0,0 +1,4 @@
1
+ export interface ITtscNativeSource {
2
+ dir: string;
3
+ entry?: string;
4
+ }
@@ -0,0 +1,10 @@
1
+ import type { ITtscProjectPluginConfig } from "./ITtscProjectPluginConfig";
2
+
3
+ export interface ITtscParsedProjectConfig {
4
+ compilerOptions: {
5
+ outDir?: string;
6
+ plugins: ITtscProjectPluginConfig[];
7
+ } & Record<string, unknown>;
8
+ path: string;
9
+ root: string;
10
+ }
@@ -0,0 +1,11 @@
1
+ import type { ITtscNativeBackend } from "./ITtscNativeBackend";
2
+ import type { ITtscNativeRewriteMode } from "./ITtscNativeRewriteMode";
3
+
4
+ export interface ITtscPlugin {
5
+ name: string;
6
+ native?: ITtscNativeBackend;
7
+ /** @deprecated Use `native.mode` instead. */
8
+ nativeMode?: ITtscNativeRewriteMode;
9
+ /** @deprecated Use `native.binary` instead. */
10
+ nativeBinary?: string;
11
+ }
@@ -0,0 +1,7 @@
1
+ import type { ITtscPlugin } from "./ITtscPlugin";
2
+ import type { ITtscPluginFactoryContext } from "./ITtscPluginFactoryContext";
3
+ import type { ITtscProjectPluginConfig } from "./ITtscProjectPluginConfig";
4
+
5
+ export type ITtscPluginFactory<T = ITtscProjectPluginConfig> = (
6
+ context: ITtscPluginFactoryContext<T>,
7
+ ) => ITtscPlugin;
@@ -0,0 +1,9 @@
1
+ import type { ITtscProjectPluginConfig } from "./ITtscProjectPluginConfig";
2
+
3
+ export interface ITtscPluginFactoryContext<T = ITtscProjectPluginConfig> {
4
+ binary: string;
5
+ cwd: string;
6
+ plugin: T;
7
+ projectRoot: string;
8
+ tsconfig: string;
9
+ }
@@ -0,0 +1,4 @@
1
+ import type { ITtscPlugin } from "./ITtscPlugin";
2
+ import type { ITtscPluginFactory } from "./ITtscPluginFactory";
3
+
4
+ export type ITtscPluginModule = ITtscPlugin | ITtscPluginFactory;
@@ -0,0 +1,5 @@
1
+ export interface ITtscPreparedExecution {
2
+ emitDir: string;
3
+ entryFile: string;
4
+ moduleKind: "cjs" | "esm";
5
+ }
@@ -0,0 +1,5 @@
1
+ export interface ITtscProjectLocatorOptions {
2
+ cwd?: string;
3
+ file?: string;
4
+ tsconfig?: string;
5
+ }
@@ -0,0 +1,5 @@
1
+ export interface ITtscProjectPluginConfig {
2
+ enabled?: boolean;
3
+ transform?: string;
4
+ [key: string]: unknown;
5
+ }
@@ -0,0 +1,7 @@
1
+ import type { ITtscCommonOptions } from "./ITtscCommonOptions";
2
+
3
+ export interface ITtscRegisterOptions extends ITtscCommonOptions {
4
+ cacheDir?: string;
5
+ project?: string;
6
+ extensions?: readonly string[];
7
+ }
@@ -0,0 +1,7 @@
1
+ export interface ITtscResolveGoBinaryOptions {
2
+ arch?: string;
3
+ env?: NodeJS.ProcessEnv;
4
+ localGoLookup?: () => string | null;
5
+ platform?: NodeJS.Platform;
6
+ resolver?: (request: string) => string;
7
+ }
@@ -0,0 +1,20 @@
1
+ export interface ITtscResolveOptions {
2
+ /**
3
+ * Override `require.resolve` for testing. Takes a module request string and
4
+ * returns an absolute path (or throws).
5
+ */
6
+ resolver?: (request: string) => string;
7
+ /** Override `process.platform` for testing. */
8
+ platform?: NodeJS.Platform;
9
+ /** Override `process.arch` for testing. */
10
+ arch?: string;
11
+ /** Override `process.env` for testing. */
12
+ env?: NodeJS.ProcessEnv;
13
+ /**
14
+ * Override the package-local scan used for the local `native/ttsc-native`
15
+ * fallback. Returns an absolute path if present, else null.
16
+ */
17
+ localBinaryLookup?: () => string | null;
18
+ /** Override the module directory used to resolve the package-local binary. */
19
+ moduleDir?: string;
20
+ }
@@ -0,0 +1,8 @@
1
+ export interface ITtscResolvedTsgo {
2
+ binary: string;
3
+ gitHead?: string;
4
+ packageJson: string;
5
+ packageRoot: string;
6
+ platformPackageJson?: string;
7
+ version: string;
8
+ }
@@ -0,0 +1,13 @@
1
+ import type { ITtscCommonOptions } from "./ITtscCommonOptions";
2
+
3
+ export interface ITtscTransformOptions extends ITtscCommonOptions {
4
+ /** Path to the .ts file to transform. Absolute or `cwd`-relative. */
5
+ file: string;
6
+ /** Path to the tsconfig owning `file`. Default: `tsconfig.json`. */
7
+ tsconfig?: string;
8
+ /**
9
+ * When provided, the binary writes JS directly to this path instead of piping
10
+ * stdout. Useful when the emitted text is large.
11
+ */
12
+ out?: string;
13
+ }
@@ -0,0 +1,14 @@
1
+ export interface ITtscTsgoResolveOptions {
2
+ /** Absolute path to an explicit tsgo-compatible binary. */
3
+ binary?: string;
4
+ /** Project directory used for node_modules resolution. */
5
+ cwd?: string;
6
+ /** Environment variables used for explicit binary overrides. */
7
+ env?: NodeJS.ProcessEnv;
8
+ /** Override process.platform for tests. */
9
+ platform?: NodeJS.Platform;
10
+ /** Override process.arch for tests. */
11
+ arch?: string;
12
+ /** Override package resolution for tests. */
13
+ resolver?: (request: string) => string;
14
+ }
package/src/tsgo.ts CHANGED
@@ -2,39 +2,21 @@ import * as fs from "node:fs";
2
2
  import { createRequire } from "node:module";
3
3
  import * as path from "node:path";
4
4
 
5
- export interface TsgoResolveOptions {
6
- /** Absolute path to an explicit tsgo-compatible binary. */
7
- binary?: string;
8
- /** Project directory used for node_modules resolution. */
9
- cwd?: string;
10
- /** Environment variables used for explicit binary overrides. */
11
- env?: NodeJS.ProcessEnv;
12
- /** Override process.platform for tests. */
13
- platform?: NodeJS.Platform;
14
- /** Override process.arch for tests. */
15
- arch?: string;
16
- /** Override package resolution for tests. */
17
- resolver?: (request: string) => string;
18
- }
5
+ import type { ITtscResolvedTsgo } from "./structures/ITtscResolvedTsgo";
6
+ import type { ITtscTsgoResolveOptions } from "./structures/ITtscTsgoResolveOptions";
19
7
 
20
- export interface ResolvedTsgo {
21
- binary: string;
22
- gitHead?: string;
23
- packageJson: string;
24
- packageRoot: string;
25
- platformPackageJson?: string;
26
- version: string;
27
- }
8
+ export type { ITtscResolvedTsgo } from "./structures/ITtscResolvedTsgo";
9
+ export type { ITtscTsgoResolveOptions } from "./structures/ITtscTsgoResolveOptions";
28
10
 
29
11
  export function nativePreviewPlatformPackage(
30
- opts: TsgoResolveOptions = {},
12
+ opts: ITtscTsgoResolveOptions = {},
31
13
  ): string {
32
14
  return `@typescript/native-preview-${opts.platform ?? process.platform}-${
33
15
  opts.arch ?? process.arch
34
16
  }`;
35
17
  }
36
18
 
37
- export function resolveTsgo(opts: TsgoResolveOptions = {}): ResolvedTsgo {
19
+ export function resolveTsgo(opts: ITtscTsgoResolveOptions = {}): ITtscResolvedTsgo {
38
20
  const env = opts.env ?? process.env;
39
21
  const explicit = opts.binary ?? env.TTSC_TSGO_BINARY;
40
22
  if (explicit) {
@@ -12,6 +12,7 @@ const {
12
12
  resolveDefaultPluginCacheRoot,
13
13
  resolveGoCompiler,
14
14
  resolvePluginCacheRoot,
15
+ sourceBuildWorkspaceReplacements,
15
16
  } = require("../src/source-build.ts");
16
17
 
17
18
  function withTempSourceDir(files: Record<string, string>): string {
@@ -149,6 +150,18 @@ test("bundled Go package request follows platform package layout", () => {
149
150
  );
150
151
  });
151
152
 
153
+ test("sourceBuildWorkspaceReplacements pins the ttsc module for source plugins", () => {
154
+ const ttscRoot = withTempSourceDir({
155
+ "go.mod": "module github.com/samchon/ttsc/packages/ttsc\n\ngo 1.26\n",
156
+ });
157
+ const otherRoot = withTempSourceDir({
158
+ "go.mod": "module example.com/other\n\ngo 1.26\n",
159
+ });
160
+ assert.deepEqual(sourceBuildWorkspaceReplacements([otherRoot, ttscRoot]), [
161
+ `replace github.com/samchon/ttsc/packages/ttsc v0.0.0 => ${ttscRoot.replace(/\\/g, "/")}`,
162
+ ]);
163
+ });
164
+
152
165
  test("resolvePluginCacheRoot prefers project node_modules cache", () => {
153
166
  const root = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-local-cache-"));
154
167
  fs.mkdirSync(path.join(root, "node_modules"));