ttsc 0.7.0 → 0.7.1

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 (41) hide show
  1. package/cmd/platform/main.go +1 -1
  2. package/cmd/ttsc/api_transform.go +64 -0
  3. package/cmd/ttsc/main.go +4 -18
  4. package/driver/program.go +2 -2
  5. package/lib/TtscCompiler.d.ts +20 -0
  6. package/lib/TtscCompiler.js +49 -0
  7. package/lib/TtscCompiler.js.map +1 -1
  8. package/lib/compiler/internal/runSingleFileEmit.d.ts +3 -0
  9. package/lib/compiler/internal/{runTransform.js → runSingleFileEmit.js} +10 -8
  10. package/lib/compiler/internal/runSingleFileEmit.js.map +1 -0
  11. package/lib/compiler/internal/transformProjectInMemory.d.ts +7 -0
  12. package/lib/compiler/internal/transformProjectInMemory.js +275 -0
  13. package/lib/compiler/internal/transformProjectInMemory.js.map +1 -0
  14. package/lib/launcher/internal/runTtsc.js +2 -76
  15. package/lib/launcher/internal/runTtsc.js.map +1 -1
  16. package/lib/structures/ITtscCompilerTransformation.d.ts +35 -0
  17. package/lib/structures/ITtscCompilerTransformation.js +3 -0
  18. package/lib/structures/ITtscCompilerTransformation.js.map +1 -0
  19. package/lib/structures/TtscPluginStage.d.ts +7 -4
  20. package/lib/structures/index.d.ts +1 -0
  21. package/lib/structures/index.js +1 -0
  22. package/lib/structures/index.js.map +1 -1
  23. package/lib/structures/internal/TtscCommonOptions.d.ts +1 -1
  24. package/lib/structures/internal/{TtscTransformOptions.d.ts → TtscSingleFileEmitOptions.d.ts} +4 -4
  25. package/lib/structures/internal/{TtscTransformOptions.js → TtscSingleFileEmitOptions.js} +1 -1
  26. package/lib/structures/internal/TtscSingleFileEmitOptions.js.map +1 -0
  27. package/package.json +8 -8
  28. package/src/TtscCompiler.ts +64 -0
  29. package/src/compiler/internal/{runTransform.ts → runSingleFileEmit.ts} +11 -7
  30. package/src/compiler/internal/transformProjectInMemory.ts +368 -0
  31. package/src/launcher/internal/runTtsc.ts +6 -79
  32. package/src/structures/ITtscCompilerTransformation.ts +46 -0
  33. package/src/structures/TtscPluginStage.ts +7 -4
  34. package/src/structures/index.ts +1 -0
  35. package/src/structures/internal/TtscCommonOptions.ts +1 -1
  36. package/src/structures/internal/{TtscTransformOptions.ts → TtscSingleFileEmitOptions.ts} +4 -4
  37. package/test/compiler.test.ts +196 -8
  38. package/cmd/ttsc/transform.go +0 -160
  39. package/lib/compiler/internal/runTransform.d.ts +0 -3
  40. package/lib/compiler/internal/runTransform.js.map +0 -1
  41. package/lib/structures/internal/TtscTransformOptions.js.map +0 -1
@@ -39,7 +39,7 @@ func run(args []string) int {
39
39
  return 0
40
40
  case "demo":
41
41
  return runDemo(args[1:])
42
- case "build", "check", "transform":
42
+ case "build", "check":
43
43
  fmt.Fprintf(
44
44
  stderr,
45
45
  "ttsc platform helper: %s is provided by the JavaScript ttsc CLI using the consuming project's @typescript/native-preview, or by a plugin-selected native sidecar.\n",
@@ -0,0 +1,64 @@
1
+ package main
2
+
3
+ import (
4
+ "encoding/json"
5
+ "flag"
6
+ "fmt"
7
+
8
+ "github.com/samchon/ttsc/packages/ttsc/driver"
9
+ )
10
+
11
+ type apiTransformResult struct {
12
+ Diagnostics []apiCompileDiagnostic `json:"diagnostics,omitempty"`
13
+ TypeScript map[string]string `json:"typescript"`
14
+ }
15
+
16
+ func runAPITransform(args []string) int {
17
+ fs := flag.NewFlagSet("api-transform", flag.ContinueOnError)
18
+ fs.SetOutput(stderr)
19
+ tsconfigPath := fs.String("tsconfig", "tsconfig.json", "path to tsconfig.json")
20
+ cwdOverride := fs.String("cwd", "", "override the working directory")
21
+ if err := fs.Parse(args); err != nil {
22
+ return 2
23
+ }
24
+
25
+ cwd, ok := resolveBuildCwd(*cwdOverride)
26
+ if !ok {
27
+ return 2
28
+ }
29
+
30
+ prog, diags, err := driver.LoadProgram(cwd, *tsconfigPath, driver.LoadProgramOptions{
31
+ ForceNoEmit: true,
32
+ })
33
+ if err != nil {
34
+ fmt.Fprintf(stderr, "ttsc api-transform: %v\n", err)
35
+ return 2
36
+ }
37
+ typescript := map[string]string{}
38
+ if prog != nil {
39
+ defer prog.Close()
40
+ for _, file := range prog.SourceFiles() {
41
+ typescript[apiOutputKey(cwd, file.FileName())] = file.Text()
42
+ }
43
+ diags = append(diags, prog.Diagnostics()...)
44
+ }
45
+
46
+ result := apiTransformResult{
47
+ Diagnostics: make([]apiCompileDiagnostic, 0, len(diags)),
48
+ TypeScript: typescript,
49
+ }
50
+ for _, diag := range diags {
51
+ result.Diagnostics = append(result.Diagnostics, toAPICompileDiagnostic(diag))
52
+ }
53
+
54
+ data, err := json.Marshal(result)
55
+ if err != nil {
56
+ fmt.Fprintf(stderr, "ttsc api-transform: result marshal failed: %v\n", err)
57
+ return 3
58
+ }
59
+ fmt.Fprintln(stdout, string(data))
60
+ if driver.CountErrors(diags) > 0 {
61
+ return 2
62
+ }
63
+ return 0
64
+ }
package/cmd/ttsc/main.go CHANGED
@@ -4,8 +4,8 @@
4
4
  // - Report version and platform (`ttsc --version`).
5
5
  // - Exercise a native rewrite backend end-to-end (`ttsc demo --type=string`)
6
6
  // so smoke tests can verify the Go binary really runs.
7
- // - Host the native project build, check, and single-file transform paths used
8
- // by plugin-selected sidecars and smoke tests.
7
+ // - Host the native project build and check paths used by plugin-selected
8
+ // sidecars and smoke tests.
9
9
  //
10
10
  // Everything below is deliberately dependency-free so that the standalone binary
11
11
  // stays small and its behavior is trivial to audit.
@@ -56,15 +56,12 @@ func run(args []string) int {
56
56
  return runBuild(args[1:])
57
57
  case "api-compile":
58
58
  return runAPICompile(args[1:])
59
+ case "api-transform":
60
+ return runAPITransform(args[1:])
59
61
  case "check":
60
62
  // `ttsc check` runs the analyze pipeline without emitting JS — useful
61
63
  // in CI and pre-commit hooks that only need schema validation.
62
64
  return runBuild(append([]string{"--noEmit"}, args[1:]...))
63
- case "transform":
64
- // Single-file transform for bundler plugin integration (unplugin,
65
- // vite, esbuild, webpack, …). Emits only the requested file's JS to
66
- // stdout or a chosen path — no project-wide write.
67
- return runTransform(args[1:])
68
65
  case "-p", "--project":
69
66
  if len(args) < 2 {
70
67
  fmt.Fprintln(stderr, "ttsc: -p/--project requires a path argument")
@@ -137,13 +134,11 @@ Usage:
137
134
  ttsc -p tsconfig.json
138
135
  ttsc --watch
139
136
  ttsc --noEmit
140
- ttsc transform --file=src/main.ts
141
137
 
142
138
  Project build:
143
139
  ttsc compiles the current tsconfig.json, matching the tsc/tsgo shape.
144
140
  build Compatibility alias for the same project build lane.
145
141
  check Compatibility alias for --noEmit validation.
146
- transform Emit a single file's rewritten JS (bundler plugin hook).
147
142
  demo Run a native backend smoke pipeline with synthetic input.
148
143
  version Print version, build info, and platform.
149
144
  help Show this help.
@@ -157,11 +152,6 @@ Build options:
157
152
  --verbose Print the per-call summary banner and emitted file list.
158
153
  --manifest=FILE Write emitted file paths as JSON to FILE after build --emit.
159
154
 
160
- Transform options:
161
- --file=PATH Absolute or cwd-relative path of the .ts file to transform.
162
- --tsconfig=FILE tsconfig.json owning --file (default: tsconfig.json).
163
- --out=PATH Write output JS to PATH. Default: stdout.
164
-
165
155
  Demo options:
166
156
  --type=T Atomic TypeScript type to simulate. One of:
167
157
  string, number, boolean, bigint, any (default: string).
@@ -171,13 +161,9 @@ Examples:
171
161
  ttsc
172
162
  ttsc -p ./tsconfig.json
173
163
  ttsc --noEmit
174
- ttsc transform --file=src/main.ts
175
164
  ttsc demo --type=number
176
165
 
177
166
  Integration guide (bundlers):
178
- - vite / webpack / rollup / esbuild: shell out to "ttsc transform" per file,
179
- forward stdout as the bundler transform result. A bundler adapter can wrap
180
- this command without depending on the Go internals.
181
167
  - Next.js / Nuxt / Bun: "ttsc" in your pipeline replaces tsc and
182
168
  the rewritten .js feeds the runtime directly.
183
169
  - Monorepo / pnpm workspace: share one ttsc binary via a root script;
package/driver/program.go CHANGED
@@ -194,8 +194,8 @@ type Program struct {
194
194
  }
195
195
 
196
196
  // LoadProgramOptions controls tsconfig overrides applied before tsgo creates
197
- // the program. `ForceEmit` is used by `ttsc --emit` and `ttsc transform`
198
- // so runtime compilation still works when the project defaults to `noEmit`.
197
+ // the program. `ForceEmit` is used by `ttsc --emit` and runtime compilation
198
+ // so execution still works when the project defaults to `noEmit`.
199
199
  type LoadProgramOptions struct {
200
200
  ForceEmit bool
201
201
  ForceNoEmit bool
@@ -1,5 +1,6 @@
1
1
  import type { ITtscCompilerContext } from "./structures/ITtscCompilerContext";
2
2
  import type { ITtscCompilerResult } from "./structures/ITtscCompilerResult";
3
+ import type { ITtscCompilerTransformation } from "./structures/ITtscCompilerTransformation";
3
4
  /**
4
5
  * Programmatic compiler host for the `ttsc` TypeScript-Go pipeline.
5
6
  *
@@ -18,6 +19,8 @@ import type { ITtscCompilerResult } from "./structures/ITtscCompilerResult";
18
19
  * context.
19
20
  * - {@link TtscCompiler.compile}: compile the configured project and return a
20
21
  * structured result instead of terminal text.
22
+ * - {@link TtscCompiler.transform}: transform the configured project and
23
+ * return an embed-style transformation result.
21
24
  */
22
25
  export declare class TtscCompiler {
23
26
  private readonly context;
@@ -67,6 +70,23 @@ export declare class TtscCompiler {
67
70
  * @returns Structured compilation result containing diagnostics or output.
68
71
  */
69
72
  compile(): ITtscCompilerResult;
73
+ /**
74
+ * Transform the configured project and return TypeScript text by file path.
75
+ *
76
+ * This is the source-to-source API for plugin authors. It must not return
77
+ * JavaScript emit, declaration files, or source maps; those artifacts belong
78
+ * to {@link TtscCompiler.compile}. A transform sidecar is expected to write
79
+ * JSON shaped as `{ "typescript": { "src/file.ts": "..." } }` to stdout.
80
+ * When no transform sidecar is configured, ttsc returns the TypeScript files
81
+ * loaded by the TypeScript-Go Program together with normal diagnostics.
82
+ *
83
+ * The returned shape mirrors `embed-typescript`'s transformation API:
84
+ * `success` and `failure` carry a `typescript` map, while unexpected host
85
+ * errors return `exception`.
86
+ *
87
+ * @returns Transformation result containing TypeScript text or diagnostics.
88
+ */
89
+ transform(): ITtscCompilerTransformation;
70
90
  private compilerContext;
71
91
  private resolveProjectExecution;
72
92
  private resolveCleanProjectRoot;
@@ -39,6 +39,7 @@ const path = __importStar(require("node:path"));
39
39
  const compileProjectInMemory_1 = require("./compiler/internal/compileProjectInMemory");
40
40
  const resolveProjectConfig_1 = require("./compiler/internal/project/resolveProjectConfig");
41
41
  const resolveBinary_1 = require("./compiler/internal/resolveBinary");
42
+ const transformProjectInMemory_1 = require("./compiler/internal/transformProjectInMemory");
42
43
  const loadProjectPlugins_1 = require("./plugin/internal/loadProjectPlugins");
43
44
  /**
44
45
  * Programmatic compiler host for the `ttsc` TypeScript-Go pipeline.
@@ -58,6 +59,8 @@ const loadProjectPlugins_1 = require("./plugin/internal/loadProjectPlugins");
58
59
  * context.
59
60
  * - {@link TtscCompiler.compile}: compile the configured project and return a
60
61
  * structured result instead of terminal text.
62
+ * - {@link TtscCompiler.transform}: transform the configured project and
63
+ * return an embed-style transformation result.
61
64
  */
62
65
  class TtscCompiler {
63
66
  context;
@@ -139,6 +142,25 @@ class TtscCompiler {
139
142
  compile() {
140
143
  return runProject(() => (0, compileProjectInMemory_1.compileProjectInMemory)(this.compilerContext()));
141
144
  }
145
+ /**
146
+ * Transform the configured project and return TypeScript text by file path.
147
+ *
148
+ * This is the source-to-source API for plugin authors. It must not return
149
+ * JavaScript emit, declaration files, or source maps; those artifacts belong
150
+ * to {@link TtscCompiler.compile}. A transform sidecar is expected to write
151
+ * JSON shaped as `{ "typescript": { "src/file.ts": "..." } }` to stdout.
152
+ * When no transform sidecar is configured, ttsc returns the TypeScript files
153
+ * loaded by the TypeScript-Go Program together with normal diagnostics.
154
+ *
155
+ * The returned shape mirrors `embed-typescript`'s transformation API:
156
+ * `success` and `failure` carry a `typescript` map, while unexpected host
157
+ * errors return `exception`.
158
+ *
159
+ * @returns Transformation result containing TypeScript text or diagnostics.
160
+ */
161
+ transform() {
162
+ return runTransformation(() => (0, transformProjectInMemory_1.transformProjectInMemory)(this.compilerContext()));
163
+ }
142
164
  compilerContext() {
143
165
  return {
144
166
  ...this.context,
@@ -206,6 +228,17 @@ function runProject(task) {
206
228
  };
207
229
  }
208
230
  }
231
+ function runTransformation(task) {
232
+ try {
233
+ return toCompilerTransformation(task());
234
+ }
235
+ catch (error) {
236
+ return {
237
+ error: normalizeError(error),
238
+ type: "exception",
239
+ };
240
+ }
241
+ }
209
242
  function toCompilerResult(project) {
210
243
  const { output, result } = project;
211
244
  if (result.status === 0 && result.diagnostics.length === 0) {
@@ -232,6 +265,22 @@ function createProcessDiagnostic(result) {
232
265
  messageText,
233
266
  };
234
267
  }
268
+ function toCompilerTransformation(project) {
269
+ const { result, typescript } = project;
270
+ if (result.status === 0 && result.diagnostics.length === 0) {
271
+ return {
272
+ type: "success",
273
+ typescript,
274
+ };
275
+ }
276
+ return {
277
+ diagnostics: result.diagnostics.length === 0
278
+ ? [createProcessDiagnostic(result)]
279
+ : result.diagnostics,
280
+ type: "failure",
281
+ typescript,
282
+ };
283
+ }
235
284
  function normalizeError(error) {
236
285
  if (!(error instanceof Error)) {
237
286
  return error;
@@ -1 +1 @@
1
- {"version":3,"file":"TtscCompiler.js","sourceRoot":"","sources":["../src/TtscCompiler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,EAAE,oCAAgB;AAC9B,MAAY,IAAI,sCAAkB;AAElC,uFAAoF;AACpF,2FAAwF;AACxF,qEAAkE;AAClE,6EAA0E;AAM1E;;;;;;;;;;;;;;;;;;GAkBG;AACH;IACmB,OAAO,CAAuB;IAE/C,YAAmB,OAAO,GAAyB,EAAE;QACnD,IAAI,CAAC,OAAO,GAAG;YACb,GAAG,OAAO;YACV,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,SAAS;YACjD,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;gBACrC,CAAC,CAAC,CAAC,G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B;IAE9B,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IACvC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3D,OAAO;YACL,IAAI,EAAE,SAAS;YACf,UAAU;SACX,CAAC;IACJ,CAAC;IACD,OAAO;QACL,WAAW,EACT,MAAM,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC;YAC7B,CAAC,CAAC,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;YACnC,CAAC,CAAC,MAAM,CAAC,WAAW;QACxB,IAAI,EAAE,SAAS;QACf,UAAU;KACX,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { TtscSingleFileEmitOptions } from "../../structures/internal/TtscSingleFileEmitOptions";
2
+ /** Emit one source file by building its project into a temporary directory. */
3
+ export declare function runSingleFileEmit(options: TtscSingleFileEmitOptions): string;
@@ -33,24 +33,26 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.runTransform = runTransform;
36
+ exports.runSingleFileEmit = runSingleFileEmit;
37
37
  const fs = __importStar(require("node:fs"));
38
38
  const os = __importStar(require("node:os"));
39
39
  const path = __importStar(require("node:path"));
40
40
  const resolveProjectConfig_1 = require("./project/resolveProjectConfig");
41
41
  const resolveEmittedJavaScript_1 = require("./resolveEmittedJavaScript");
42
42
  const runBuild_1 = require("./runBuild");
43
- /** Transform one source file by emitting its project into a temporary directory. */
44
- function runTransform(options) {
43
+ /** Emit one source file by building its project into a temporary directory. */
44
+ function runSingleFileEmit(options) {
45
45
  const cwd = path.resolve(options.cwd ?? process.cwd());
46
- const sourceFile = realpathIfExists(path.isAbsolute(options.file) ? options.file : path.resolve(cwd, options.file));
46
+ const sourceFile = realpathIfExists(path.isAbsolute(options.file)
47
+ ? options.file
48
+ : path.resolve(cwd, options.file));
47
49
  const tsconfig = (0, resolveProjectConfig_1.resolveProjectConfig)({
48
50
  cwd,
49
51
  file: sourceFile,
50
52
  tsconfig: options.tsconfig,
51
53
  });
52
54
  const projectRoot = path.dirname(tsconfig);
53
- const outDir = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-transform-"));
55
+ const outDir = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-single-file-"));
54
56
  try {
55
57
  const result = (0, runBuild_1.runBuild)({
56
58
  ...options,
@@ -61,7 +63,7 @@ function runTransform(options) {
61
63
  tsconfig,
62
64
  });
63
65
  if (result.status !== 0) {
64
- throw new Error("ttsc transform exited " +
66
+ throw new Error("ttsc single-file emit exited " +
65
67
  result.status +
66
68
  "\n" +
67
69
  (result.stderr || result.stdout));
@@ -73,7 +75,7 @@ function runTransform(options) {
73
75
  sourceFile,
74
76
  });
75
77
  if (emitted === null) {
76
- throw new Error(`ttsc transform: no output produced for ${sourceFile}`);
78
+ throw new Error(`ttsc single-file emit: no output produced for ${sourceFile}`);
77
79
  }
78
80
  const transformed = fs.readFileSync(emitted, "utf8");
79
81
  if (options.out) {
@@ -97,4 +99,4 @@ function realpathIfExists(file) {
97
99
  return file;
98
100
  }
99
101
  }
100
- //# sourceMappingURL=runTransform.js.map
102
+ //# sourceMappingURL=runSingleFileEmit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runSingleFileEmit.js","sourceRoot":"","sources":["../../../src/compiler/internal/runSingleFileEmit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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OAAO,GAAG,IAAA,mDAAwB,EAAC;YACvC,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,MAAM;YACN,WAAW;YACX,UAAU;SACX,CAAC,CAAC;QACH,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CACb,iDAAiD,UAAU,EAAE,CAC9D,CAAC;QACJ,CAAC;QACD,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACrD,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;YAChB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC;gBACzC,CAAC,CAAC,OAAO,CAAC,GAAG;gBACb,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;YACnC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACxD,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,WAAW,CAAC;IACrB,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY;IACpC,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { ITtscCompilerContext } from "../../structures/ITtscCompilerContext";
2
+ import type { TtscBuildResult } from "../../structures/internal/TtscBuildResult";
3
+ /** Transform a project and capture TypeScript source output in memory. */
4
+ export declare function transformProjectInMemory(options: ITtscCompilerContext): {
5
+ result: TtscBuildResult;
6
+ typescript: Record<string, string>;
7
+ };
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.transformProjectInMemory = transformProjectInMemory;
37
+ const node_child_process_1 = require("node:child_process");
38
+ const fs = __importStar(require("node:fs"));
39
+ const path = __importStar(require("node:path"));
40
+ const loadProjectPlugins_1 = require("../../plugin/internal/loadProjectPlugins");
41
+ const buildNativeCompiler_1 = require("./buildNativeCompiler");
42
+ const readProjectConfig_1 = require("./project/readProjectConfig");
43
+ const resolveBinary_1 = require("./resolveBinary");
44
+ const resolveTsgo_1 = require("./resolveTsgo");
45
+ /** Transform a project and capture TypeScript source output in memory. */
46
+ function transformProjectInMemory(options) {
47
+ const cwd = path.resolve(options.cwd ?? process.cwd());
48
+ const project = (0, readProjectConfig_1.readProjectConfig)({
49
+ cwd,
50
+ tsconfig: options.tsconfig,
51
+ });
52
+ if (configuredPlugins(options, project).length !== 0) {
53
+ return transformProjectWithPlugins(options, cwd, project);
54
+ }
55
+ return transformProjectWithNativeHost(options, project);
56
+ }
57
+ function configuredPlugins(options, project) {
58
+ if (options.plugins === false) {
59
+ return [];
60
+ }
61
+ const entries = options.plugins ?? project.compilerOptions.plugins;
62
+ return entries.filter((entry) => entry.enabled !== false);
63
+ }
64
+ function transformProjectWithNativeHost(options, project) {
65
+ const binary = (0, buildNativeCompiler_1.buildNativeCompiler)({
66
+ cacheBaseDir: project.root,
67
+ cacheDir: options.cacheDir,
68
+ packageRoot: packageRootDir(),
69
+ });
70
+ const res = spawnNative(binary, ["api-transform", "--cwd", project.root, "--tsconfig", project.path], {
71
+ cwd: project.root,
72
+ env: { ...process.env, ...options.env },
73
+ });
74
+ if (res.error) {
75
+ throw new Error(`ttsc: failed to spawn native compiler host ${binary}: ${res.error.message}`);
76
+ }
77
+ const output = parseNativeTransformOutput(outputText(res.stdout), outputText(res.stderr));
78
+ return {
79
+ result: {
80
+ diagnostics: output.diagnostics,
81
+ status: res.status ?? 1,
82
+ stdout: "",
83
+ stderr: outputText(res.stderr),
84
+ },
85
+ typescript: output.typescript,
86
+ };
87
+ }
88
+ function transformProjectWithPlugins(options, cwd, project) {
89
+ const loaded = (0, loadProjectPlugins_1.loadProjectPlugins)({
90
+ binary: (0, resolveBinary_1.resolveBinary)(options) ?? "",
91
+ cacheDir: options.cacheDir ?? options.env?.TTSC_CACHE_DIR,
92
+ cwd,
93
+ entries: options.plugins,
94
+ tsconfig: project.path,
95
+ });
96
+ const checks = loaded.nativePlugins.filter((plugin) => plugin.stage === "check");
97
+ const transformers = loaded.nativePlugins.filter((plugin) => plugin.stage === "transform");
98
+ const checked = runNativeChecks(options, project, loaded.nativePlugins, checks);
99
+ if (checked.status !== 0) {
100
+ return {
101
+ result: checked,
102
+ typescript: {},
103
+ };
104
+ }
105
+ if (transformers.length === 0) {
106
+ return transformProjectWithNativeHost(options, project);
107
+ }
108
+ assertSingleTransformHost(transformers);
109
+ const plugin = transformers[0];
110
+ const res = spawnNative(plugin.binary, createNativeTransformArgs(project, transformers), {
111
+ cwd: project.root,
112
+ env: nativePluginEnv(options, project.root),
113
+ });
114
+ if (res.error) {
115
+ throw new Error(`ttsc.transform: failed to spawn ${plugin.binary}: ${res.error.message}`);
116
+ }
117
+ const output = parseNativeTransformOutput(outputText(res.stdout), outputText(res.stderr));
118
+ return {
119
+ result: {
120
+ diagnostics: output.diagnostics,
121
+ status: res.status ?? 1,
122
+ stdout: "",
123
+ stderr: outputText(res.stderr),
124
+ },
125
+ typescript: output.typescript,
126
+ };
127
+ }
128
+ function runNativeChecks(options, project, nativePlugins, checks) {
129
+ let result = {
130
+ diagnostics: [],
131
+ status: 0,
132
+ stdout: "",
133
+ stderr: "",
134
+ };
135
+ for (const plugin of checks) {
136
+ const res = spawnNative(plugin.binary, createNativeCheckArgs(project, nativePlugins), {
137
+ cwd: project.root,
138
+ env: nativePluginEnv(options, project.root),
139
+ });
140
+ if (res.error) {
141
+ throw new Error(`ttsc.transform.check: failed to spawn ${plugin.binary}: ${res.error.message}`);
142
+ }
143
+ result = appendBuildResult(result, {
144
+ diagnostics: [],
145
+ status: res.status ?? 1,
146
+ stdout: outputText(res.stdout),
147
+ stderr: outputText(res.stderr),
148
+ });
149
+ if (result.status !== 0) {
150
+ return result;
151
+ }
152
+ }
153
+ return result;
154
+ }
155
+ function createNativeTransformArgs(project, plugins) {
156
+ return [
157
+ "transform",
158
+ "--tsconfig=" + project.path,
159
+ "--plugins-json=" + serializeNativePlugins(plugins),
160
+ "--cwd=" + project.root,
161
+ ];
162
+ }
163
+ function createNativeCheckArgs(project, plugins) {
164
+ return [
165
+ "check",
166
+ "--tsconfig=" + project.path,
167
+ "--plugins-json=" + serializeNativePlugins(plugins),
168
+ "--cwd=" + project.root,
169
+ ];
170
+ }
171
+ function serializeNativePlugins(plugins) {
172
+ return JSON.stringify(plugins.map((plugin) => ({
173
+ config: plugin.config,
174
+ name: plugin.name,
175
+ stage: plugin.stage,
176
+ })));
177
+ }
178
+ function assertSingleTransformHost(plugins) {
179
+ const binaries = [...new Set(plugins.map((plugin) => plugin.binary))];
180
+ if (binaries.length > 1) {
181
+ throw new Error("ttsc: multiple transform native backends cannot share one source-to-source pass");
182
+ }
183
+ }
184
+ function appendBuildResult(left, right) {
185
+ return {
186
+ diagnostics: [...left.diagnostics, ...right.diagnostics],
187
+ status: right.status !== 0 ? right.status : left.status,
188
+ stdout: left.stdout + right.stdout,
189
+ stderr: left.stderr + right.stderr,
190
+ };
191
+ }
192
+ function nativePluginEnv(options, projectRoot) {
193
+ const tsgo = (0, resolveTsgo_1.resolveTsgo)({ ...options, cwd: projectRoot });
194
+ return {
195
+ ...process.env,
196
+ TTSC_NODE_BINARY: process.env.TTSC_NODE_BINARY ?? process.execPath,
197
+ TTSC_TSGO_BINARY: process.env.TTSC_TSGO_BINARY ?? tsgo.binary,
198
+ TTSC_TTSX_BINARY: process.env.TTSC_TTSX_BINARY ??
199
+ path.join(__dirname, "..", "..", "launcher", "ttsx.js"),
200
+ ...options.env,
201
+ };
202
+ }
203
+ function spawnNative(binary, args, options) {
204
+ const viaNode = /\.(?:[cm]?js|ts)$/i.test(binary);
205
+ if (!viaNode) {
206
+ ensureExecutable(binary);
207
+ }
208
+ return (0, node_child_process_1.spawnSync)(viaNode ? process.execPath : binary, viaNode ? [binary, ...args] : [...args], {
209
+ cwd: options.cwd,
210
+ encoding: "utf8",
211
+ env: options.env,
212
+ maxBuffer: 1024 * 1024 * 256,
213
+ windowsHide: true,
214
+ });
215
+ }
216
+ function ensureExecutable(binary) {
217
+ if (process.platform === "win32") {
218
+ return;
219
+ }
220
+ try {
221
+ const mode = fs.statSync(binary).mode & 0o777;
222
+ if ((mode & 0o111) !== 0) {
223
+ return;
224
+ }
225
+ fs.chmodSync(binary, mode | 0o755);
226
+ }
227
+ catch {
228
+ /* keep the original spawn error path */
229
+ }
230
+ }
231
+ function outputText(value) {
232
+ if (value == null) {
233
+ return "";
234
+ }
235
+ return typeof value === "string" ? value : value.toString("utf8");
236
+ }
237
+ function parseNativeTransformOutput(stdout, stderr) {
238
+ try {
239
+ const parsed = JSON.parse(stdout);
240
+ if (!isTextRecord(parsed.typescript)) {
241
+ throw new Error("ttsc: native transform host did not return a TypeScript source map");
242
+ }
243
+ return {
244
+ diagnostics: Array.isArray(parsed.diagnostics) ? parsed.diagnostics : [],
245
+ typescript: parsed.typescript,
246
+ };
247
+ }
248
+ catch (error) {
249
+ if (error instanceof Error && !(error instanceof SyntaxError)) {
250
+ throw error;
251
+ }
252
+ throw new Error((stderr || stdout).trim() ||
253
+ "ttsc: native transform host returned no output");
254
+ }
255
+ }
256
+ function isTextRecord(value) {
257
+ return (typeof value === "object" &&
258
+ value !== null &&
259
+ Object.values(value).every((entry) => typeof entry === "string"));
260
+ }
261
+ function packageRootDir() {
262
+ let current = path.resolve(__dirname);
263
+ while (true) {
264
+ if (fs.existsSync(path.join(current, "package.json")) &&
265
+ fs.existsSync(path.join(current, "go.mod"))) {
266
+ return fs.realpathSync.native?.(current) ?? fs.realpathSync(current);
267
+ }
268
+ const parent = path.dirname(current);
269
+ if (parent === current) {
270
+ throw new Error("ttsc: package root not found for native compiler build");
271
+ }
272
+ current = parent;
273
+ }
274
+ }
275
+ //# sourceMappingURL=transformProjectInMemory.js.map