ttsc 0.7.0 → 0.7.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 (45) hide show
  1. package/README.md +3 -5
  2. package/cmd/platform/main.go +1 -1
  3. package/cmd/ttsc/api_transform.go +64 -0
  4. package/cmd/ttsc/main.go +4 -18
  5. package/driver/program.go +2 -2
  6. package/lib/TtscCompiler.d.ts +20 -0
  7. package/lib/TtscCompiler.js +49 -0
  8. package/lib/TtscCompiler.js.map +1 -1
  9. package/lib/compiler/internal/runSingleFileEmit.d.ts +3 -0
  10. package/lib/compiler/internal/{runTransform.js → runSingleFileEmit.js} +10 -8
  11. package/lib/compiler/internal/runSingleFileEmit.js.map +1 -0
  12. package/lib/compiler/internal/transformProjectInMemory.d.ts +7 -0
  13. package/lib/compiler/internal/transformProjectInMemory.js +275 -0
  14. package/lib/compiler/internal/transformProjectInMemory.js.map +1 -0
  15. package/lib/launcher/internal/prepareExecution.js +89 -8
  16. package/lib/launcher/internal/prepareExecution.js.map +1 -1
  17. package/lib/launcher/internal/runTtsc.js +2 -76
  18. package/lib/launcher/internal/runTtsc.js.map +1 -1
  19. package/lib/structures/ITtscCompilerTransformation.d.ts +35 -0
  20. package/lib/structures/ITtscCompilerTransformation.js +3 -0
  21. package/lib/structures/ITtscCompilerTransformation.js.map +1 -0
  22. package/lib/structures/TtscPluginStage.d.ts +7 -4
  23. package/lib/structures/index.d.ts +1 -0
  24. package/lib/structures/index.js +1 -0
  25. package/lib/structures/index.js.map +1 -1
  26. package/lib/structures/internal/TtscCommonOptions.d.ts +1 -1
  27. package/lib/structures/internal/{TtscTransformOptions.d.ts → TtscSingleFileEmitOptions.d.ts} +4 -4
  28. package/lib/structures/internal/{TtscTransformOptions.js → TtscSingleFileEmitOptions.js} +1 -1
  29. package/lib/structures/internal/TtscSingleFileEmitOptions.js.map +1 -0
  30. package/package.json +8 -8
  31. package/src/TtscCompiler.ts +64 -0
  32. package/src/compiler/internal/{runTransform.ts → runSingleFileEmit.ts} +11 -7
  33. package/src/compiler/internal/transformProjectInMemory.ts +368 -0
  34. package/src/launcher/internal/prepareExecution.ts +114 -8
  35. package/src/launcher/internal/runTtsc.ts +6 -79
  36. package/src/structures/ITtscCompilerTransformation.ts +46 -0
  37. package/src/structures/TtscPluginStage.ts +7 -4
  38. package/src/structures/index.ts +1 -0
  39. package/src/structures/internal/TtscCommonOptions.ts +1 -1
  40. package/src/structures/internal/{TtscTransformOptions.ts → TtscSingleFileEmitOptions.ts} +4 -4
  41. package/test/compiler.test.ts +196 -8
  42. package/cmd/ttsc/transform.go +0 -160
  43. package/lib/compiler/internal/runTransform.d.ts +0 -3
  44. package/lib/compiler/internal/runTransform.js.map +0 -1
  45. package/lib/structures/internal/TtscTransformOptions.js.map +0 -1
package/README.md CHANGED
@@ -49,9 +49,7 @@ npx ttsc clean
49
49
 
50
50
  ## Plugin Configuration
51
51
 
52
- Open your project's `tsconfig.json`, then add plugin entries under `compilerOptions.plugins`. If the file already has `compilerOptions`, merge the `plugins` array into the existing object.
53
-
54
- Each plugin module is a JavaScript descriptor for an ordered native transformer backend; the transform implementation itself runs in Go.
52
+ Add plugin entries under `compilerOptions.plugins` in your `tsconfig.json`.
55
53
 
56
54
  ```json
57
55
  {
@@ -137,14 +135,14 @@ It is transformed into dedicated JavaScript:
137
135
  > console.log(matched); // true
138
136
  > ```
139
137
 
140
- `ttsc` runs this transform during build, and `ttsx` runs through the same transform path during execution.
138
+ `ttsc` applies this transform at build time; `ttsx` applies the same transform when running the file.
141
139
 
142
140
  ## List of Plugins
143
141
 
144
142
  `ttsc` ships a few small utility plugins in this repository.
145
143
 
146
144
  - [`@ttsc/banner`](https://github.com/samchon/ttsc/tree/master/packages/banner): adds banner comments to emitted JS and declarations.
147
- - [`@ttsc/lint`](https://github.com/samchon/ttsc/tree/master/packages/lint): fails compilation on lint violations.
145
+ - [`@ttsc/lint`](https://github.com/samchon/ttsc/tree/master/packages/lint): type-check + lint in one compile pass, ~20x faster than `eslint` in theory.
148
146
  - [`@ttsc/paths`](https://github.com/samchon/ttsc/tree/master/packages/paths): rewrites path aliases in emitted imports.
149
147
  - [`@ttsc/strip`](https://github.com/samchon/ttsc/tree/master/packages/strip): removes configured calls and `debugger` statements.
150
148
 
@@ -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,GAAG,OAAO,CAAC,OAAO,CAAC;gBACtB,CAAC,CAAC,OAAO,CAAC,OAAO;SACpB,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;OAYG;IACI,OAAO;QACZ,MAAM,SAAS,GAAG,IAAI,CAAC,uBAAuB,EAAE,CAAC;QACjD,MAAM,MAAM,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S;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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,EAAE,oCAAgB;AAC9B,MAAY,EAAE,oCAAgB;AAC9B,MAAY,IAAI,sCAAkB;AAGlC,yEAAsE;AACtE,yEAAsE;AACtE,yCAAsC;AAEtC,+EAA+E;AAC/E,2BAAkC,OAAkC;IAClE,MAAM,GAAG,GAAG,IAAI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AU,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
+ };