ttsc 0.7.2 → 0.7.3

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 (53) hide show
  1. package/README.md +2 -1
  2. package/cmd/platform/main.go +86 -76
  3. package/cmd/ttsc/api_compile.go +122 -105
  4. package/cmd/ttsc/api_transform.go +57 -49
  5. package/cmd/ttsc/build.go +116 -103
  6. package/cmd/ttsc/main.go +117 -117
  7. package/cmd/ttsc/main_test.go +191 -191
  8. package/driver/host.go +9 -9
  9. package/driver/program.go +285 -285
  10. package/driver/rewrite.go +225 -219
  11. package/lib/compiler/internal/compileProjectInMemory.js +3 -3
  12. package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
  13. package/lib/compiler/internal/resolveEmittedJavaScript.js +2 -1
  14. package/lib/compiler/internal/resolveEmittedJavaScript.js.map +1 -1
  15. package/lib/compiler/internal/resolveTsgo.js.map +1 -1
  16. package/lib/compiler/internal/runBuild.js.map +1 -1
  17. package/lib/launcher/internal/getCompilerVersionText.js +1 -2
  18. package/lib/launcher/internal/getCompilerVersionText.js.map +1 -1
  19. package/lib/launcher/internal/prepareExecution.js +6 -4
  20. package/lib/launcher/internal/prepareExecution.js.map +1 -1
  21. package/lib/launcher/internal/runTtsc.js +30 -4
  22. package/lib/launcher/internal/runTtsc.js.map +1 -1
  23. package/lib/launcher/internal/runTtsx.js +7 -2
  24. package/lib/launcher/internal/runTtsx.js.map +1 -1
  25. package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
  26. package/package.json +9 -9
  27. package/shim/ast/lint.go +171 -171
  28. package/shim/ast/shim.go +83 -83
  29. package/shim/bundled/shim.go +5 -1
  30. package/shim/checker/shim.go +79 -79
  31. package/shim/compiler/shim.go +16 -1
  32. package/shim/core/shim.go +10 -10
  33. package/shim/diagnosticwriter/lint.go +79 -79
  34. package/shim/diagnosticwriter/shim.go +19 -19
  35. package/shim/parser/shim.go +7 -1
  36. package/shim/scanner/shim.go +39 -1
  37. package/shim/tsoptions/shim.go +51 -1
  38. package/shim/tspath/shim.go +72 -1
  39. package/shim/vfs/cachedvfs/shim.go +1 -1
  40. package/shim/vfs/osvfs/shim.go +1 -1
  41. package/shim/vfs/shim.go +4 -1
  42. package/src/compiler/internal/compileProjectInMemory.ts +6 -3
  43. package/src/compiler/internal/resolveEmittedJavaScript.ts +2 -1
  44. package/src/compiler/internal/resolveTsgo.ts +0 -1
  45. package/src/compiler/internal/runBuild.ts +4 -1
  46. package/src/launcher/internal/getCompilerVersionText.ts +1 -2
  47. package/src/launcher/internal/prepareExecution.ts +6 -6
  48. package/src/launcher/internal/runTtsc.ts +35 -4
  49. package/src/launcher/internal/runTtsx.ts +16 -5
  50. package/src/plugin/internal/buildSourcePlugin.ts +7 -2
  51. package/test/platform.test.ts +1 -3
  52. package/test/tsgo.test.ts +6 -1
  53. package/tools/gen_shims/main.go +409 -409
@@ -58,7 +58,8 @@ function createProjectContext(
58
58
  const tsconfig = project.path;
59
59
  const root = project.root;
60
60
  const cacheDir =
61
- options.cacheDir ?? path.join(root, "node_modules", ".cache", "ttsc", "ttsx");
61
+ options.cacheDir ??
62
+ path.join(root, "node_modules", ".cache", "ttsc", "ttsx");
62
63
  const processDir = path.join(cacheDir, "project", PROCESS_CACHE_KEY);
63
64
  const virtualRoot = path.join(processDir, "fs");
64
65
  return {
@@ -81,7 +82,9 @@ function resolveRuntimeSourceRoot(
81
82
  ): string {
82
83
  const rootDir = project.compilerOptions.rootDir;
83
84
  if (typeof rootDir === "string") {
84
- return path.isAbsolute(rootDir) ? rootDir : path.resolve(project.root, rootDir);
85
+ return path.isAbsolute(rootDir)
86
+ ? rootDir
87
+ : path.resolve(project.root, rootDir);
85
88
  }
86
89
  return path.dirname(filename);
87
90
  }
@@ -191,10 +194,7 @@ function collectLinkDirectories(projectRoot: string): string[] {
191
194
  function isUnsafeVirtualParent(directory: string): boolean {
192
195
  const resolved = path.resolve(directory);
193
196
  const root = path.parse(resolved).root;
194
- return (
195
- resolved === root ||
196
- resolved === path.resolve(os.tmpdir())
197
- );
197
+ return resolved === root || resolved === path.resolve(os.tmpdir());
198
198
  }
199
199
 
200
200
  function virtualPath(root: string, absolute: string): string {
@@ -2,6 +2,7 @@ import { spawnSync } from "node:child_process";
2
2
  import * as fs from "node:fs";
3
3
  import * as path from "node:path";
4
4
 
5
+ import { TtscCompiler } from "../../TtscCompiler";
5
6
  import { resolveBinary } from "../../compiler/internal/resolveBinary";
6
7
  import { runBuild } from "../../compiler/internal/runBuild";
7
8
  import { runSingleFileEmit } from "../../compiler/internal/runSingleFileEmit";
@@ -35,6 +36,8 @@ export function runTtsc(
35
36
  return runCompatibleBuild(rest, true);
36
37
  case "clean":
37
38
  return runClean(rest);
39
+ case "prepare":
40
+ return runPrepare(rest);
38
41
  case "demo":
39
42
  return delegateToNative(argv);
40
43
  case "-p":
@@ -82,8 +85,34 @@ function runCompatibleBuild(
82
85
  return result.status;
83
86
  }
84
87
 
88
+ function runPrepare(argv: readonly string[]): number {
89
+ const options = parseProjectArgs(argv);
90
+ const cwd = path.resolve(options.cwd ?? process.cwd());
91
+ const compiler = new TtscCompiler({
92
+ cwd,
93
+ tsconfig: options.tsconfig,
94
+ });
95
+ const prepared = compiler.prepare();
96
+ if (prepared.length === 0) {
97
+ const projectRoot = path.dirname(
98
+ resolveProjectConfig({
99
+ cwd,
100
+ tsconfig: options.tsconfig,
101
+ }),
102
+ );
103
+ process.stdout.write(
104
+ `ttsc: no source plugins found under ${formatProjectPath(cwd, projectRoot)}\n`,
105
+ );
106
+ return 0;
107
+ }
108
+ for (const target of prepared) {
109
+ process.stdout.write(`ttsc: prepared ${formatProjectPath(cwd, target)}\n`);
110
+ }
111
+ return 0;
112
+ }
113
+
85
114
  function runClean(argv: readonly string[]): number {
86
- const options = parseCleanArgs(argv);
115
+ const options = parseProjectArgs(argv);
87
116
  const cwd = path.resolve(options.cwd ?? process.cwd());
88
117
  const projectRoot = resolveCleanProjectRoot(cwd, options.tsconfig);
89
118
  const targets = [
@@ -106,7 +135,7 @@ function runClean(argv: readonly string[]): number {
106
135
  return 0;
107
136
  }
108
137
  for (const target of removed) {
109
- process.stdout.write(`ttsc: removed ${formatCleanPath(cwd, target)}\n`);
138
+ process.stdout.write(`ttsc: removed ${formatProjectPath(cwd, target)}\n`);
110
139
  }
111
140
  return 0;
112
141
  }
@@ -120,7 +149,7 @@ function resolveCleanProjectRoot(cwd: string, tsconfig?: string): string {
120
149
  }
121
150
  }
122
151
 
123
- function formatCleanPath(cwd: string, target: string): string {
152
+ function formatProjectPath(cwd: string, target: string): string {
124
153
  const relative = path.relative(cwd, target);
125
154
  if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) {
126
155
  return target;
@@ -174,7 +203,7 @@ function ensureExecutable(binary: string): void {
174
203
  }
175
204
  }
176
205
 
177
- function parseCleanArgs(argv: readonly string[]) {
206
+ function parseProjectArgs(argv: readonly string[]) {
178
207
  let cwd: string | undefined;
179
208
  let tsconfig: string | undefined;
180
209
 
@@ -303,6 +332,7 @@ function printHelp(): void {
303
332
  " ttsc -p tsconfig.json",
304
333
  " ttsc --watch",
305
334
  " ttsc --noEmit",
335
+ " ttsc prepare [options]",
306
336
  " ttsc clean [options]",
307
337
  " ttsc version",
308
338
  " ttsc --help",
@@ -328,6 +358,7 @@ function printHelp(): void {
328
358
  "Compatibility aliases:",
329
359
  " ttsc build [options] Same project build lane as `ttsc [options]`.",
330
360
  " ttsc check [options] Same as `ttsc --noEmit [options]`.",
361
+ " ttsc prepare [options] Build configured source-plugin binaries into cache.",
331
362
  " ttsc clean [options] Delete local source-plugin cache directories.",
332
363
  ].join("\n"),
333
364
  );
@@ -5,7 +5,9 @@ import * as path from "node:path";
5
5
  import { getCompilerVersionText } from "./getCompilerVersionText";
6
6
  import { prepareExecution } from "./prepareExecution";
7
7
 
8
- export function runTtsx(argv: readonly string[] = process.argv.slice(2)): number {
8
+ export function runTtsx(
9
+ argv: readonly string[] = process.argv.slice(2),
10
+ ): number {
9
11
  try {
10
12
  return run(argv);
11
13
  } catch (error) {
@@ -53,8 +55,10 @@ function formatError(error: unknown): string {
53
55
  function parseCLI(argv: readonly string[]) {
54
56
  const preload: string[] = [];
55
57
  const passthroughIndex = argv.indexOf("--");
56
- const head = passthroughIndex === -1 ? [...argv] : [...argv.slice(0, passthroughIndex)];
57
- const passthrough = passthroughIndex === -1 ? [] : [...argv.slice(passthroughIndex + 1)];
58
+ const head =
59
+ passthroughIndex === -1 ? [...argv] : [...argv.slice(0, passthroughIndex)];
60
+ const passthrough =
61
+ passthroughIndex === -1 ? [] : [...argv.slice(passthroughIndex + 1)];
58
62
 
59
63
  let binary: string | undefined;
60
64
  let cacheDir: string | undefined;
@@ -151,7 +155,11 @@ function printHelp(): void {
151
155
  }
152
156
 
153
157
  function resolvePreload(cwd: string, preload: string): string {
154
- if (preload.startsWith(".") || preload.startsWith("/") || preload.includes(path.sep)) {
158
+ if (
159
+ preload.startsWith(".") ||
160
+ preload.startsWith("/") ||
161
+ preload.includes(path.sep)
162
+ ) {
155
163
  return path.resolve(cwd, preload);
156
164
  }
157
165
  return preload;
@@ -180,7 +188,10 @@ function runPreparedEntry(
180
188
  );
181
189
  }
182
190
  const args = [
183
- ...parsed.preload.flatMap((preload) => ["-r", resolvePreload(cwd, preload)]),
191
+ ...parsed.preload.flatMap((preload) => [
192
+ "-r",
193
+ resolvePreload(cwd, preload),
194
+ ]),
184
195
  execution.entryFile,
185
196
  ...parsed.passthrough,
186
197
  ];
@@ -155,7 +155,9 @@ function writeGoWork(scratchDir: string, useDirs: readonly string[]): void {
155
155
  fs.writeFileSync(path.join(scratchDir, "go.work"), goWork, "utf8");
156
156
  }
157
157
 
158
- function sourceBuildWorkspaceReplacements(useDirs: readonly string[]): string[] {
158
+ function sourceBuildWorkspaceReplacements(
159
+ useDirs: readonly string[],
160
+ ): string[] {
159
161
  const ttscRoot = useDirs.find((dir) =>
160
162
  hasModulePath(dir, "github.com/samchon/ttsc/packages/ttsc"),
161
163
  );
@@ -308,7 +310,10 @@ function walkForGoMod(dir: string, out: string[]): void {
308
310
  }
309
311
  }
310
312
 
311
- function resolvePluginCacheRoot(projectRoot: string, cacheDir?: string): string {
313
+ function resolvePluginCacheRoot(
314
+ projectRoot: string,
315
+ cacheDir?: string,
316
+ ): string {
312
317
  if (cacheDir) {
313
318
  return path.resolve(cacheDir, "plugins");
314
319
  }
@@ -1,8 +1,6 @@
1
1
  const assert = require("node:assert/strict");
2
2
  const test = require("node:test");
3
- const {
4
- resolveBinary,
5
- } = require("../lib/compiler/internal/resolveBinary.js");
3
+ const { resolveBinary } = require("../lib/compiler/internal/resolveBinary.js");
6
4
 
7
5
  test("resolveBinary prefers TTSC_BINARY absolute override", () => {
8
6
  const resolved = resolveBinary({
package/test/tsgo.test.ts CHANGED
@@ -20,7 +20,12 @@ test("resolveTsgo accepts TTSC_TSGO_BINARY as an explicit compiler", () => {
20
20
 
21
21
  test("resolveTsgo resolves the consumer native-preview platform package", () => {
22
22
  const root = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-tsgo-test-"));
23
- const nativeRoot = path.join(root, "node_modules", "@typescript", "native-preview");
23
+ const nativeRoot = path.join(
24
+ root,
25
+ "node_modules",
26
+ "@typescript",
27
+ "native-preview",
28
+ );
24
29
  const platformRoot = path.join(
25
30
  root,
26
31
  "node_modules",