ttsc 0.6.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.
- package/cmd/platform/main.go +1 -1
- package/cmd/ttsc/api_compile.go +134 -0
- package/cmd/ttsc/api_transform.go +64 -0
- package/cmd/ttsc/build.go +1 -7
- package/cmd/ttsc/main.go +6 -20
- package/driver/program.go +13 -3
- package/lib/TtscCompiler.d.ts +96 -0
- package/lib/TtscCompiler.js +294 -0
- package/lib/TtscCompiler.js.map +1 -0
- package/lib/compiler/internal/buildNativeCompiler.d.ts +6 -0
- package/lib/compiler/internal/buildNativeCompiler.js +72 -0
- package/lib/compiler/internal/buildNativeCompiler.js.map +1 -0
- package/lib/compiler/internal/compileProjectInMemory.d.ts +7 -0
- package/lib/compiler/internal/compileProjectInMemory.js +176 -0
- package/lib/compiler/internal/compileProjectInMemory.js.map +1 -0
- package/lib/compiler/internal/project/readProjectConfig.d.ts +4 -0
- package/lib/{project.js → compiler/internal/project/readProjectConfig.js} +12 -82
- package/lib/compiler/internal/project/readProjectConfig.js.map +1 -0
- package/lib/compiler/internal/project/resolveProjectConfig.d.ts +3 -0
- package/lib/compiler/internal/project/resolveProjectConfig.js +94 -0
- package/lib/compiler/internal/project/resolveProjectConfig.js.map +1 -0
- package/lib/compiler/internal/resolveBinary.d.ts +4 -0
- package/lib/compiler/internal/resolveBinary.js +65 -0
- package/lib/compiler/internal/resolveBinary.js.map +1 -0
- package/lib/compiler/internal/resolveEmittedJavaScript.d.ts +7 -0
- package/lib/compiler/internal/resolveEmittedJavaScript.js +118 -0
- package/lib/compiler/internal/resolveEmittedJavaScript.js.map +1 -0
- package/lib/compiler/internal/resolveTsgo.d.ts +20 -0
- package/lib/{tsgo.js → compiler/internal/resolveTsgo.js} +5 -10
- package/lib/compiler/internal/resolveTsgo.js.map +1 -0
- package/lib/compiler/internal/runBuild.d.ts +10 -0
- package/lib/compiler/internal/runBuild.js +480 -0
- package/lib/compiler/internal/runBuild.js.map +1 -0
- package/lib/compiler/internal/runSingleFileEmit.d.ts +3 -0
- package/lib/compiler/internal/runSingleFileEmit.js +102 -0
- package/lib/compiler/internal/runSingleFileEmit.js.map +1 -0
- package/lib/compiler/internal/transformProjectInMemory.d.ts +7 -0
- package/lib/compiler/internal/transformProjectInMemory.js +275 -0
- package/lib/compiler/internal/transformProjectInMemory.js.map +1 -0
- package/lib/index.d.ts +6 -15
- package/lib/index.js +6 -15
- package/lib/index.js.map +1 -1
- package/lib/launcher/internal/getCompilerVersionText.d.ts +3 -0
- package/lib/launcher/internal/getCompilerVersionText.js +71 -0
- package/lib/launcher/internal/getCompilerVersionText.js.map +1 -0
- package/lib/launcher/internal/prepareExecution.d.ts +10 -0
- package/lib/launcher/internal/prepareExecution.js +120 -0
- package/lib/launcher/internal/prepareExecution.js.map +1 -0
- package/lib/launcher/internal/runTtsc.d.ts +1 -0
- package/lib/{cli.js → launcher/internal/runTtsc.js} +45 -118
- package/lib/launcher/internal/runTtsc.js.map +1 -0
- package/lib/launcher/internal/runTtsx.d.ts +1 -0
- package/lib/{runner/cli.js → launcher/internal/runTtsx.js} +13 -35
- package/lib/launcher/internal/runTtsx.js.map +1 -0
- package/lib/launcher/ttsc.js +2 -2
- package/lib/launcher/ttsc.js.map +1 -1
- package/lib/launcher/ttsx.js +2 -2
- package/lib/launcher/ttsx.js.map +1 -1
- package/lib/plugin/internal/buildSourcePlugin.d.ts +12 -0
- package/lib/{source-build.js → plugin/internal/buildSourcePlugin.js} +77 -84
- package/lib/plugin/internal/buildSourcePlugin.js.map +1 -0
- package/lib/plugin/internal/loadProjectPlugins.d.ts +14 -0
- package/lib/{plugin.js → plugin/internal/loadProjectPlugins.js} +38 -76
- package/lib/plugin/internal/loadProjectPlugins.js.map +1 -0
- package/lib/structures/ITtscCompilerContext.d.ts +78 -0
- package/lib/structures/ITtscCompilerContext.js +3 -0
- package/lib/structures/ITtscCompilerContext.js.map +1 -0
- package/lib/structures/ITtscCompilerDiagnostic.d.ts +83 -0
- package/lib/structures/ITtscCompilerDiagnostic.js +3 -0
- package/lib/structures/ITtscCompilerDiagnostic.js.map +1 -0
- package/lib/structures/ITtscCompilerResult.d.ts +83 -0
- package/lib/structures/{ITtscCacheKeyInput.js → ITtscCompilerResult.js} +1 -1
- package/lib/structures/ITtscCompilerResult.js.map +1 -0
- package/lib/structures/ITtscCompilerTransformation.d.ts +35 -0
- package/lib/structures/ITtscCompilerTransformation.js +3 -0
- package/lib/structures/ITtscCompilerTransformation.js.map +1 -0
- package/lib/structures/ITtscPlugin.d.ts +52 -7
- package/lib/structures/ITtscPluginFactoryContext.d.ts +47 -0
- package/lib/structures/ITtscProjectPluginConfig.d.ts +41 -0
- package/lib/structures/TtscPluginStage.d.ts +18 -0
- package/lib/structures/{ITtscBuildResult.js → TtscPluginStage.js} +1 -1
- package/lib/structures/TtscPluginStage.js.map +1 -0
- package/lib/structures/index.d.ts +8 -0
- package/lib/structures/index.js +25 -0
- package/lib/structures/index.js.map +1 -0
- package/lib/structures/internal/ITtscLoadedNativePlugin.d.ts +13 -0
- package/lib/structures/internal/ITtscLoadedNativePlugin.js.map +1 -0
- package/lib/structures/internal/ITtscParsedProjectConfig.d.ts +15 -0
- package/lib/structures/internal/ITtscParsedProjectConfig.js.map +1 -0
- package/lib/structures/internal/ITtscProjectLocatorOptions.d.ts +9 -0
- package/lib/structures/internal/ITtscProjectLocatorOptions.js.map +1 -0
- package/lib/structures/internal/TtscBuildOptions.d.ts +18 -0
- package/lib/structures/{ITtscBuildOptions.js → internal/TtscBuildOptions.js} +1 -1
- package/lib/structures/internal/TtscBuildOptions.js.map +1 -0
- package/lib/structures/internal/TtscBuildResult.d.ts +14 -0
- package/lib/structures/{ITtscCheckOptions.js → internal/TtscBuildResult.js} +1 -1
- package/lib/structures/internal/TtscBuildResult.js.map +1 -0
- package/lib/structures/internal/TtscCommonOptions.d.ts +27 -0
- package/lib/structures/{ITtscNativeSource.js → internal/TtscCommonOptions.js} +1 -1
- package/lib/structures/internal/TtscCommonOptions.js.map +1 -0
- package/lib/structures/internal/TtscSingleFileEmitOptions.d.ts +14 -0
- package/lib/structures/internal/TtscSingleFileEmitOptions.js +3 -0
- package/lib/structures/internal/TtscSingleFileEmitOptions.js.map +1 -0
- package/package.json +9 -9
- package/src/TtscCompiler.ts +305 -0
- package/src/compiler/internal/buildNativeCompiler.ts +43 -0
- package/src/compiler/internal/compileProjectInMemory.ts +189 -0
- package/src/{project.ts → compiler/internal/project/readProjectConfig.ts} +36 -111
- package/src/compiler/internal/project/resolveProjectConfig.ts +67 -0
- package/src/compiler/internal/resolveBinary.ts +41 -0
- package/src/compiler/internal/resolveEmittedJavaScript.ts +102 -0
- package/src/{tsgo.ts → compiler/internal/resolveTsgo.ts} +20 -23
- package/src/compiler/internal/runBuild.ts +644 -0
- package/src/compiler/internal/runSingleFileEmit.ts +73 -0
- package/src/compiler/internal/transformProjectInMemory.ts +368 -0
- package/src/index.ts +6 -15
- package/src/launcher/internal/getCompilerVersionText.ts +44 -0
- package/src/launcher/internal/prepareExecution.ts +115 -0
- package/src/{cli.ts → launcher/internal/runTtsc.ts} +58 -140
- package/src/{runner/cli.ts → launcher/internal/runTtsx.ts} +21 -49
- package/src/launcher/ttsc.ts +2 -2
- package/src/launcher/ttsx.ts +2 -2
- package/src/{source-build.ts → plugin/internal/buildSourcePlugin.ts} +121 -115
- package/src/plugin/internal/loadProjectPlugins.ts +214 -0
- package/src/structures/ITtscCompilerContext.ts +84 -0
- package/src/structures/ITtscCompilerDiagnostic.ts +91 -0
- package/src/structures/ITtscCompilerResult.ts +94 -0
- package/src/structures/ITtscCompilerTransformation.ts +46 -0
- package/src/structures/ITtscPlugin.ts +54 -7
- package/src/structures/ITtscPluginFactoryContext.ts +51 -0
- package/src/structures/ITtscProjectPluginConfig.ts +43 -0
- package/src/structures/TtscPluginStage.ts +18 -0
- package/src/structures/index.ts +8 -0
- package/src/structures/internal/ITtscLoadedNativePlugin.ts +14 -0
- package/src/structures/internal/ITtscParsedProjectConfig.ts +16 -0
- package/src/structures/internal/ITtscProjectLocatorOptions.ts +9 -0
- package/src/structures/internal/TtscBuildOptions.ts +19 -0
- package/src/structures/internal/TtscBuildResult.ts +15 -0
- package/src/structures/internal/TtscCommonOptions.ts +28 -0
- package/src/structures/internal/TtscSingleFileEmitOptions.ts +15 -0
- package/test/compiler.test.ts +422 -0
- package/test/platform.test.ts +1 -45
- package/test/project.test.ts +3 -1
- package/test/source-build.test.ts +33 -220
- package/test/tsgo.test.ts +1 -8
- package/cmd/ttsc/transform.go +0 -166
- package/lib/api.d.ts +0 -40
- package/lib/api.js +0 -680
- package/lib/api.js.map +0 -1
- package/lib/cli.d.ts +0 -1
- package/lib/cli.js.map +0 -1
- package/lib/native.d.ts +0 -8
- package/lib/native.js +0 -42
- package/lib/native.js.map +0 -1
- package/lib/platform.d.ts +0 -52
- package/lib/platform.js +0 -175
- package/lib/platform.js.map +0 -1
- package/lib/plugin.d.ts +0 -13
- package/lib/plugin.js.map +0 -1
- package/lib/project.d.ts +0 -14
- package/lib/project.js.map +0 -1
- package/lib/runner/cli.d.ts +0 -1
- package/lib/runner/cli.js.map +0 -1
- package/lib/runner/register.d.ts +0 -6
- package/lib/runner/register.js +0 -358
- package/lib/runner/register.js.map +0 -1
- package/lib/source-build.d.ts +0 -19
- package/lib/source-build.js.map +0 -1
- package/lib/structures/ITtscBuildOptions.d.ts +0 -14
- package/lib/structures/ITtscBuildOptions.js.map +0 -1
- package/lib/structures/ITtscBuildResult.d.ts +0 -6
- package/lib/structures/ITtscBuildResult.js.map +0 -1
- package/lib/structures/ITtscBuildSourcePluginOptions.d.ts +0 -8
- package/lib/structures/ITtscBuildSourcePluginOptions.js +0 -3
- package/lib/structures/ITtscBuildSourcePluginOptions.js.map +0 -1
- package/lib/structures/ITtscCacheKeyInput.d.ts +0 -7
- package/lib/structures/ITtscCacheKeyInput.js.map +0 -1
- package/lib/structures/ITtscCheckOptions.d.ts +0 -2
- package/lib/structures/ITtscCheckOptions.js.map +0 -1
- package/lib/structures/ITtscCommonOptions.d.ts +0 -22
- package/lib/structures/ITtscCommonOptions.js +0 -3
- package/lib/structures/ITtscCommonOptions.js.map +0 -1
- package/lib/structures/ITtscLoadPluginsOptions.d.ts +0 -8
- package/lib/structures/ITtscLoadPluginsOptions.js +0 -3
- package/lib/structures/ITtscLoadPluginsOptions.js.map +0 -1
- package/lib/structures/ITtscLoadedNativePlugin.d.ts +0 -7
- package/lib/structures/ITtscLoadedNativePlugin.js.map +0 -1
- package/lib/structures/ITtscLoadedPlugins.d.ts +0 -11
- package/lib/structures/ITtscLoadedPlugins.js +0 -3
- package/lib/structures/ITtscLoadedPlugins.js.map +0 -1
- package/lib/structures/ITtscNativeBackend.d.ts +0 -10
- package/lib/structures/ITtscNativeBackend.js +0 -3
- package/lib/structures/ITtscNativeBackend.js.map +0 -1
- package/lib/structures/ITtscNativePluginContractVersion.d.ts +0 -1
- package/lib/structures/ITtscNativePluginContractVersion.js +0 -3
- package/lib/structures/ITtscNativePluginContractVersion.js.map +0 -1
- package/lib/structures/ITtscNativePluginShape.d.ts +0 -8
- package/lib/structures/ITtscNativePluginShape.js +0 -3
- package/lib/structures/ITtscNativePluginShape.js.map +0 -1
- package/lib/structures/ITtscNativeRewriteMode.d.ts +0 -1
- package/lib/structures/ITtscNativeRewriteMode.js +0 -3
- package/lib/structures/ITtscNativeRewriteMode.js.map +0 -1
- package/lib/structures/ITtscNativeSource.d.ts +0 -4
- package/lib/structures/ITtscNativeSource.js.map +0 -1
- package/lib/structures/ITtscParsedProjectConfig.d.ts +0 -9
- package/lib/structures/ITtscParsedProjectConfig.js.map +0 -1
- package/lib/structures/ITtscPluginFactory.d.ts +0 -4
- package/lib/structures/ITtscPluginFactory.js +0 -3
- package/lib/structures/ITtscPluginFactory.js.map +0 -1
- package/lib/structures/ITtscPluginModule.d.ts +0 -3
- package/lib/structures/ITtscPluginModule.js +0 -3
- package/lib/structures/ITtscPluginModule.js.map +0 -1
- package/lib/structures/ITtscPreparedExecution.d.ts +0 -5
- package/lib/structures/ITtscPreparedExecution.js +0 -3
- package/lib/structures/ITtscPreparedExecution.js.map +0 -1
- package/lib/structures/ITtscProjectLocatorOptions.d.ts +0 -5
- package/lib/structures/ITtscProjectLocatorOptions.js.map +0 -1
- package/lib/structures/ITtscRegisterOptions.d.ts +0 -6
- package/lib/structures/ITtscRegisterOptions.js +0 -3
- package/lib/structures/ITtscRegisterOptions.js.map +0 -1
- package/lib/structures/ITtscResolveGoBinaryOptions.d.ts +0 -7
- package/lib/structures/ITtscResolveGoBinaryOptions.js +0 -3
- package/lib/structures/ITtscResolveGoBinaryOptions.js.map +0 -1
- package/lib/structures/ITtscResolveOptions.d.ts +0 -20
- package/lib/structures/ITtscResolveOptions.js +0 -3
- package/lib/structures/ITtscResolveOptions.js.map +0 -1
- package/lib/structures/ITtscResolvedTsgo.d.ts +0 -8
- package/lib/structures/ITtscResolvedTsgo.js +0 -3
- package/lib/structures/ITtscResolvedTsgo.js.map +0 -1
- package/lib/structures/ITtscTransformOptions.d.ts +0 -12
- package/lib/structures/ITtscTransformOptions.js +0 -3
- package/lib/structures/ITtscTransformOptions.js.map +0 -1
- package/lib/structures/ITtscTsgoResolveOptions.d.ts +0 -14
- package/lib/structures/ITtscTsgoResolveOptions.js +0 -3
- package/lib/structures/ITtscTsgoResolveOptions.js.map +0 -1
- package/lib/tsgo.d.ts +0 -6
- package/lib/tsgo.js.map +0 -1
- package/src/api.ts +0 -872
- package/src/native.ts +0 -64
- package/src/platform.ts +0 -151
- package/src/plugin.ts +0 -253
- package/src/runner/register.ts +0 -406
- package/src/structures/ITtscBuildOptions.ts +0 -19
- package/src/structures/ITtscBuildResult.ts +0 -6
- package/src/structures/ITtscBuildSourcePluginOptions.ts +0 -9
- package/src/structures/ITtscCacheKeyInput.ts +0 -7
- package/src/structures/ITtscCheckOptions.ts +0 -3
- package/src/structures/ITtscCommonOptions.ts +0 -23
- package/src/structures/ITtscLoadPluginsOptions.ts +0 -9
- package/src/structures/ITtscLoadedNativePlugin.ts +0 -8
- package/src/structures/ITtscLoadedPlugins.ts +0 -12
- package/src/structures/ITtscNativeBackend.ts +0 -11
- package/src/structures/ITtscNativePluginContractVersion.ts +0 -1
- package/src/structures/ITtscNativePluginShape.ts +0 -9
- package/src/structures/ITtscNativeRewriteMode.ts +0 -1
- package/src/structures/ITtscNativeSource.ts +0 -4
- package/src/structures/ITtscParsedProjectConfig.ts +0 -10
- package/src/structures/ITtscPluginFactory.ts +0 -7
- package/src/structures/ITtscPluginModule.ts +0 -4
- package/src/structures/ITtscPreparedExecution.ts +0 -5
- package/src/structures/ITtscProjectLocatorOptions.ts +0 -5
- package/src/structures/ITtscRegisterOptions.ts +0 -7
- package/src/structures/ITtscResolveGoBinaryOptions.ts +0 -7
- package/src/structures/ITtscResolveOptions.ts +0 -20
- package/src/structures/ITtscResolvedTsgo.ts +0 -8
- package/src/structures/ITtscTransformOptions.ts +0 -13
- package/src/structures/ITtscTsgoResolveOptions.ts +0 -14
- package/test/native.test.ts +0 -103
- /package/lib/structures/{ITtscLoadedNativePlugin.js → internal/ITtscLoadedNativePlugin.js} +0 -0
- /package/lib/structures/{ITtscParsedProjectConfig.js → internal/ITtscParsedProjectConfig.js} +0 -0
- /package/lib/structures/{ITtscProjectLocatorOptions.js → internal/ITtscProjectLocatorOptions.js} +0 -0
|
@@ -2,19 +2,16 @@ 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 {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
version,
|
|
12
|
-
} from "./api";
|
|
13
|
-
import { installHint, resolveBinary } from "./platform";
|
|
14
|
-
import { resolveProjectConfig, resolveProjectRoot } from "./project";
|
|
15
|
-
import { pluginCacheCleanupTargets } from "./source-build";
|
|
5
|
+
import { resolveBinary } from "../../compiler/internal/resolveBinary";
|
|
6
|
+
import { runBuild } from "../../compiler/internal/runBuild";
|
|
7
|
+
import { runSingleFileEmit } from "../../compiler/internal/runSingleFileEmit";
|
|
8
|
+
import { resolveProjectConfig } from "../../compiler/internal/project/resolveProjectConfig";
|
|
9
|
+
import type { TtscBuildOptions } from "../../structures/internal/TtscBuildOptions";
|
|
10
|
+
import { getCompilerVersionText } from "./getCompilerVersionText";
|
|
16
11
|
|
|
17
|
-
export function
|
|
12
|
+
export function runTtsc(
|
|
13
|
+
argv: readonly string[] = process.argv.slice(2),
|
|
14
|
+
): number {
|
|
18
15
|
try {
|
|
19
16
|
if (argv.length === 0) {
|
|
20
17
|
return runCompatibleBuild([], false);
|
|
@@ -30,7 +27,7 @@ export function main(argv: readonly string[] = process.argv.slice(2)): number {
|
|
|
30
27
|
case "-v":
|
|
31
28
|
case "--version":
|
|
32
29
|
case "version":
|
|
33
|
-
process.stdout.write(`${
|
|
30
|
+
process.stdout.write(`${getCompilerVersionText()}\n`);
|
|
34
31
|
return 0;
|
|
35
32
|
case "build":
|
|
36
33
|
return runCompatibleBuild(rest, false);
|
|
@@ -38,8 +35,6 @@ export function main(argv: readonly string[] = process.argv.slice(2)): number {
|
|
|
38
35
|
return runCompatibleBuild(rest, true);
|
|
39
36
|
case "clean":
|
|
40
37
|
return runClean(rest);
|
|
41
|
-
case "transform":
|
|
42
|
-
return runTransform(rest);
|
|
43
38
|
case "demo":
|
|
44
39
|
return delegateToNative(argv);
|
|
45
40
|
case "-p":
|
|
@@ -70,12 +65,6 @@ function isBuildAlias(command: string): boolean {
|
|
|
70
65
|
);
|
|
71
66
|
}
|
|
72
67
|
|
|
73
|
-
interface ITtscBuildInvocation extends ITtscBuildOptions {
|
|
74
|
-
files: string[];
|
|
75
|
-
preserveWatchOutput: boolean;
|
|
76
|
-
watch: boolean;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
68
|
function runCompatibleBuild(
|
|
80
69
|
argv: readonly string[],
|
|
81
70
|
checkOnly: boolean,
|
|
@@ -87,31 +76,23 @@ function runCompatibleBuild(
|
|
|
87
76
|
if (options.files.length !== 0) {
|
|
88
77
|
return runSingleFile(options);
|
|
89
78
|
}
|
|
90
|
-
const result = checkOnly ?
|
|
79
|
+
const result = runBuild(checkOnly ? { ...options, emit: false } : options);
|
|
91
80
|
if (result.stdout) process.stdout.write(result.stdout);
|
|
92
81
|
if (result.stderr) process.stderr.write(result.stderr);
|
|
93
82
|
return result.status;
|
|
94
83
|
}
|
|
95
84
|
|
|
96
|
-
function runTransform(argv: readonly string[]): number {
|
|
97
|
-
const options = parseTransformArgs(argv);
|
|
98
|
-
const text = transform(options);
|
|
99
|
-
if (!options.out) {
|
|
100
|
-
process.stdout.write(text);
|
|
101
|
-
}
|
|
102
|
-
return 0;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
interface ITtscCleanInvocation {
|
|
106
|
-
cwd?: string;
|
|
107
|
-
tsconfig?: string;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
85
|
function runClean(argv: readonly string[]): number {
|
|
111
86
|
const options = parseCleanArgs(argv);
|
|
112
87
|
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
113
88
|
const projectRoot = resolveCleanProjectRoot(cwd, options.tsconfig);
|
|
114
|
-
const targets =
|
|
89
|
+
const targets = [
|
|
90
|
+
path.join(projectRoot, "node_modules", ".ttsc"),
|
|
91
|
+
path.join(projectRoot, ".ttsc"),
|
|
92
|
+
...(process.env.TTSC_CACHE_DIR
|
|
93
|
+
? [path.resolve(process.env.TTSC_CACHE_DIR, "plugins")]
|
|
94
|
+
: []),
|
|
95
|
+
];
|
|
115
96
|
const removed: string[] = [];
|
|
116
97
|
for (const target of targets) {
|
|
117
98
|
if (!fs.existsSync(target)) continue;
|
|
@@ -119,7 +100,9 @@ function runClean(argv: readonly string[]): number {
|
|
|
119
100
|
removed.push(target);
|
|
120
101
|
}
|
|
121
102
|
if (removed.length === 0) {
|
|
122
|
-
process.stdout.write(
|
|
103
|
+
process.stdout.write(
|
|
104
|
+
`ttsc: no cache directories found under ${projectRoot}\n`,
|
|
105
|
+
);
|
|
123
106
|
return 0;
|
|
124
107
|
}
|
|
125
108
|
for (const target of removed) {
|
|
@@ -148,10 +131,18 @@ function formatCleanPath(cwd: string, target: string): string {
|
|
|
148
131
|
function delegateToNative(argv: readonly string[]): number {
|
|
149
132
|
const bin = resolveBinary();
|
|
150
133
|
if (!bin) {
|
|
151
|
-
process.stderr.write(
|
|
134
|
+
process.stderr.write(
|
|
135
|
+
[
|
|
136
|
+
`ttsc: platform-specific helper binary not found (@ttsc/${process.platform}-${process.arch}).`,
|
|
137
|
+
`Set TTSC_BINARY to an absolute helper path or reinstall with optional dependencies enabled.`,
|
|
138
|
+
].join("\n") + "\n",
|
|
139
|
+
);
|
|
152
140
|
return 1;
|
|
153
141
|
}
|
|
154
142
|
const viaNode = /\.(?:[cm]?js|ts)$/i.test(bin);
|
|
143
|
+
if (!viaNode) {
|
|
144
|
+
ensureExecutable(bin);
|
|
145
|
+
}
|
|
155
146
|
const result = spawnSync(
|
|
156
147
|
viaNode ? process.execPath : bin,
|
|
157
148
|
viaNode ? [bin, ...argv] : [...argv],
|
|
@@ -168,7 +159,22 @@ function delegateToNative(argv: readonly string[]): number {
|
|
|
168
159
|
return result.status ?? 1;
|
|
169
160
|
}
|
|
170
161
|
|
|
171
|
-
function
|
|
162
|
+
function ensureExecutable(binary: string): void {
|
|
163
|
+
if (process.platform === "win32") {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
const mode = fs.statSync(binary).mode & 0o777;
|
|
168
|
+
if ((mode & 0o111) !== 0) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
fs.chmodSync(binary, mode | 0o755);
|
|
172
|
+
} catch {
|
|
173
|
+
/* keep the original spawn error path */
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function parseCleanArgs(argv: readonly string[]) {
|
|
172
178
|
let cwd: string | undefined;
|
|
173
179
|
let tsconfig: string | undefined;
|
|
174
180
|
|
|
@@ -200,10 +206,7 @@ function parseCleanArgs(argv: readonly string[]): ITtscCleanInvocation {
|
|
|
200
206
|
return { cwd, tsconfig };
|
|
201
207
|
}
|
|
202
208
|
|
|
203
|
-
function parseBuildArgs(
|
|
204
|
-
argv: readonly string[],
|
|
205
|
-
checkOnly: boolean,
|
|
206
|
-
): ITtscBuildInvocation {
|
|
209
|
+
function parseBuildArgs(argv: readonly string[], checkOnly: boolean) {
|
|
207
210
|
let binary: string | undefined;
|
|
208
211
|
let cwd: string | undefined;
|
|
209
212
|
let emit: boolean | undefined = checkOnly ? false : undefined;
|
|
@@ -211,7 +214,6 @@ function parseBuildArgs(
|
|
|
211
214
|
let outDir: string | undefined;
|
|
212
215
|
let preserveWatchOutput = false;
|
|
213
216
|
let quiet = true;
|
|
214
|
-
let rewriteMode: string | undefined;
|
|
215
217
|
let tsconfig: string | undefined;
|
|
216
218
|
let watch = false;
|
|
217
219
|
|
|
@@ -238,9 +240,6 @@ function parseBuildArgs(
|
|
|
238
240
|
case "--preserveWatchOutput":
|
|
239
241
|
preserveWatchOutput = true;
|
|
240
242
|
break;
|
|
241
|
-
case "--rewrite-mode":
|
|
242
|
-
rewriteMode = takeRewriteMode(takeValue(current, rest));
|
|
243
|
-
break;
|
|
244
243
|
case "--cwd":
|
|
245
244
|
cwd = takeValue(current, rest);
|
|
246
245
|
break;
|
|
@@ -262,10 +261,6 @@ function parseBuildArgs(
|
|
|
262
261
|
outDir = current.slice("--outDir=".length);
|
|
263
262
|
} else if (current === "-w") {
|
|
264
263
|
watch = true;
|
|
265
|
-
} else if (current.startsWith("--rewrite-mode=")) {
|
|
266
|
-
rewriteMode = takeRewriteMode(
|
|
267
|
-
current.slice("--rewrite-mode=".length),
|
|
268
|
-
);
|
|
269
264
|
} else if (current.startsWith("--tsconfig=")) {
|
|
270
265
|
tsconfig = current.slice("--tsconfig=".length);
|
|
271
266
|
} else if (current.startsWith("--project=")) {
|
|
@@ -293,79 +288,11 @@ function parseBuildArgs(
|
|
|
293
288
|
outDir,
|
|
294
289
|
preserveWatchOutput,
|
|
295
290
|
quiet,
|
|
296
|
-
rewriteMode,
|
|
297
291
|
tsconfig,
|
|
298
292
|
watch,
|
|
299
293
|
};
|
|
300
294
|
}
|
|
301
295
|
|
|
302
|
-
function parseTransformArgs(argv: readonly string[]): ITtscTransformOptions {
|
|
303
|
-
let binary: string | undefined;
|
|
304
|
-
let cwd: string | undefined;
|
|
305
|
-
let file: string | undefined;
|
|
306
|
-
let out: string | undefined;
|
|
307
|
-
let rewriteMode: string | undefined;
|
|
308
|
-
let tsconfig: string | undefined;
|
|
309
|
-
|
|
310
|
-
const rest = [...argv];
|
|
311
|
-
while (rest.length !== 0) {
|
|
312
|
-
const current = rest.shift()!;
|
|
313
|
-
switch (current) {
|
|
314
|
-
case "--binary":
|
|
315
|
-
binary = takeValue(current, rest);
|
|
316
|
-
break;
|
|
317
|
-
case "--cwd":
|
|
318
|
-
cwd = takeValue(current, rest);
|
|
319
|
-
break;
|
|
320
|
-
case "--file":
|
|
321
|
-
file = takeValue(current, rest);
|
|
322
|
-
break;
|
|
323
|
-
case "--out":
|
|
324
|
-
out = takeValue(current, rest);
|
|
325
|
-
break;
|
|
326
|
-
case "--rewrite-mode":
|
|
327
|
-
rewriteMode = takeRewriteMode(takeValue(current, rest));
|
|
328
|
-
break;
|
|
329
|
-
case "--tsconfig":
|
|
330
|
-
case "--project":
|
|
331
|
-
tsconfig = takeValue(current, rest);
|
|
332
|
-
break;
|
|
333
|
-
default:
|
|
334
|
-
if (current.startsWith("--binary=")) {
|
|
335
|
-
binary = current.slice("--binary=".length);
|
|
336
|
-
} else if (current.startsWith("--cwd=")) {
|
|
337
|
-
cwd = current.slice("--cwd=".length);
|
|
338
|
-
} else if (current.startsWith("--file=")) {
|
|
339
|
-
file = current.slice("--file=".length);
|
|
340
|
-
} else if (current.startsWith("--out=")) {
|
|
341
|
-
out = current.slice("--out=".length);
|
|
342
|
-
} else if (current.startsWith("--rewrite-mode=")) {
|
|
343
|
-
rewriteMode = takeRewriteMode(
|
|
344
|
-
current.slice("--rewrite-mode=".length),
|
|
345
|
-
);
|
|
346
|
-
} else if (current.startsWith("--tsconfig=")) {
|
|
347
|
-
tsconfig = current.slice("--tsconfig=".length);
|
|
348
|
-
} else if (current.startsWith("--project=")) {
|
|
349
|
-
tsconfig = current.slice("--project=".length);
|
|
350
|
-
} else {
|
|
351
|
-
throw new Error(`ttsc: unknown option ${current}`);
|
|
352
|
-
}
|
|
353
|
-
break;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (!file) {
|
|
357
|
-
throw new Error("ttsc: transform requires --file");
|
|
358
|
-
}
|
|
359
|
-
return {
|
|
360
|
-
binary,
|
|
361
|
-
cwd,
|
|
362
|
-
file,
|
|
363
|
-
out,
|
|
364
|
-
rewriteMode,
|
|
365
|
-
tsconfig,
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
|
|
369
296
|
function printHelp(): void {
|
|
370
297
|
process.stdout.write(
|
|
371
298
|
[
|
|
@@ -377,7 +304,6 @@ function printHelp(): void {
|
|
|
377
304
|
" ttsc --watch",
|
|
378
305
|
" ttsc --noEmit",
|
|
379
306
|
" ttsc clean [options]",
|
|
380
|
-
" ttsc transform --file <path> [options]",
|
|
381
307
|
" ttsc version",
|
|
382
308
|
" ttsc --help",
|
|
383
309
|
"",
|
|
@@ -390,10 +316,8 @@ function printHelp(): void {
|
|
|
390
316
|
" -w, --watch Rebuild when project files change",
|
|
391
317
|
" --preserveWatchOutput Do not clear the screen between watch rebuilds",
|
|
392
318
|
" --outDir <dir> Override compilerOptions.outDir for this invocation",
|
|
393
|
-
" --rewrite-mode <mode> Plugin-selected native rewrite backend id",
|
|
394
319
|
" --quiet Keep build output quiet (default)",
|
|
395
320
|
" --verbose Print the build summary and emitted files",
|
|
396
|
-
" --out <path> Write transform output to a file instead of stdout",
|
|
397
321
|
" --binary <path> Use an explicit tsgo binary",
|
|
398
322
|
"",
|
|
399
323
|
"Plugin contract:",
|
|
@@ -410,7 +334,7 @@ function printHelp(): void {
|
|
|
410
334
|
process.stdout.write("\n");
|
|
411
335
|
}
|
|
412
336
|
|
|
413
|
-
function runSingleFile(options:
|
|
337
|
+
function runSingleFile(options: ReturnType<typeof parseBuildArgs>): number {
|
|
414
338
|
if (options.files.length !== 1) {
|
|
415
339
|
throw new Error(
|
|
416
340
|
"ttsc: single-file mode currently accepts exactly one input file",
|
|
@@ -419,12 +343,11 @@ function runSingleFile(options: ITtscBuildInvocation): number {
|
|
|
419
343
|
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
420
344
|
const file = path.resolve(cwd, options.files[0]!);
|
|
421
345
|
const out = resolveSingleFileOut(file, cwd, options.outDir);
|
|
422
|
-
const text =
|
|
346
|
+
const text = runSingleFileEmit({
|
|
423
347
|
binary: options.binary,
|
|
424
348
|
cwd,
|
|
425
349
|
file,
|
|
426
350
|
out,
|
|
427
|
-
rewriteMode: options.rewriteMode,
|
|
428
351
|
tsconfig: options.tsconfig,
|
|
429
352
|
});
|
|
430
353
|
if (!fs.existsSync(out)) {
|
|
@@ -448,9 +371,12 @@ function resolveSingleFileOut(
|
|
|
448
371
|
return file.replace(/\.[cm]?tsx?$/i, ".js");
|
|
449
372
|
}
|
|
450
373
|
|
|
451
|
-
function runWatch(
|
|
374
|
+
function runWatch(
|
|
375
|
+
options: ReturnType<typeof parseBuildArgs>,
|
|
376
|
+
checkOnly: boolean,
|
|
377
|
+
): number {
|
|
452
378
|
const cwd = path.resolve(options.cwd ?? process.cwd());
|
|
453
|
-
const invocation
|
|
379
|
+
const invocation = {
|
|
454
380
|
...options,
|
|
455
381
|
cwd,
|
|
456
382
|
quiet: true,
|
|
@@ -461,10 +387,7 @@ function runWatch(options: ITtscBuildInvocation, checkOnly: boolean): number {
|
|
|
461
387
|
tsconfig: options.tsconfig,
|
|
462
388
|
}),
|
|
463
389
|
);
|
|
464
|
-
const watchRoot =
|
|
465
|
-
cwd,
|
|
466
|
-
tsconfig: options.tsconfig,
|
|
467
|
-
});
|
|
390
|
+
const watchRoot = root;
|
|
468
391
|
const directories = collectWatchDirectories(watchRoot);
|
|
469
392
|
const watchers = directories.map((dir) =>
|
|
470
393
|
fs.watch(dir, { persistent: true }, () => trigger()),
|
|
@@ -485,7 +408,9 @@ function runWatch(options: ITtscBuildInvocation, checkOnly: boolean): number {
|
|
|
485
408
|
invocation.files.length !== 0
|
|
486
409
|
? runSingleFile(invocation)
|
|
487
410
|
: (() => {
|
|
488
|
-
const result =
|
|
411
|
+
const result = runBuild(
|
|
412
|
+
checkOnly ? { ...invocation, emit: false } : invocation,
|
|
413
|
+
);
|
|
489
414
|
if (result.stdout) process.stdout.write(result.stdout);
|
|
490
415
|
if (result.stderr) process.stderr.write(result.stderr);
|
|
491
416
|
return result.status;
|
|
@@ -557,13 +482,6 @@ function takeValue(flag: string, rest: string[]): string {
|
|
|
557
482
|
return value;
|
|
558
483
|
}
|
|
559
484
|
|
|
560
|
-
function takeRewriteMode(value: string): string {
|
|
561
|
-
if (value.length === 0) {
|
|
562
|
-
throw new Error("ttsc: rewrite mode must not be empty");
|
|
563
|
-
}
|
|
564
|
-
return value;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
485
|
function formatError(error: unknown): string {
|
|
568
486
|
if (error instanceof Error) {
|
|
569
487
|
return error.message;
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
|
-
import Module = require("node:module");
|
|
3
2
|
import { spawnSync } from "node:child_process";
|
|
4
3
|
import * as path from "node:path";
|
|
5
4
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
prepareExecution,
|
|
9
|
-
register,
|
|
10
|
-
type ITtscPreparedExecution,
|
|
11
|
-
type ITtscRegisterOptions,
|
|
12
|
-
} from "./register";
|
|
5
|
+
import { getCompilerVersionText } from "./getCompilerVersionText";
|
|
6
|
+
import { prepareExecution } from "./prepareExecution";
|
|
13
7
|
|
|
14
|
-
|
|
15
|
-
entry: string;
|
|
16
|
-
passthrough: string[];
|
|
17
|
-
preload: string[];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function main(argv: readonly string[] = process.argv.slice(2)): number {
|
|
8
|
+
export function runTtsx(argv: readonly string[] = process.argv.slice(2)): number {
|
|
21
9
|
try {
|
|
22
10
|
return run(argv);
|
|
23
11
|
} catch (error) {
|
|
@@ -33,7 +21,9 @@ function run(argv: readonly string[]): number {
|
|
|
33
21
|
return 0;
|
|
34
22
|
}
|
|
35
23
|
if (parsed === "version") {
|
|
36
|
-
process.stdout.write(
|
|
24
|
+
process.stdout.write(
|
|
25
|
+
`${getCompilerVersionText().replace(/^ttsc\b/, "ttsx")}\n`,
|
|
26
|
+
);
|
|
37
27
|
return 0;
|
|
38
28
|
}
|
|
39
29
|
|
|
@@ -48,29 +38,9 @@ function run(argv: readonly string[]): number {
|
|
|
48
38
|
binary: parsed.binary,
|
|
49
39
|
cacheDir: parsed.cacheDir,
|
|
50
40
|
cwd,
|
|
51
|
-
env: parsed.env,
|
|
52
|
-
extensions: parsed.extensions,
|
|
53
41
|
project: parsed.project,
|
|
54
42
|
});
|
|
55
|
-
|
|
56
|
-
return runEsmEntry(parsed, prepared, cwd);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const unregister = register({
|
|
60
|
-
binary: parsed.binary,
|
|
61
|
-
cacheDir: parsed.cacheDir,
|
|
62
|
-
cwd,
|
|
63
|
-
env: parsed.env,
|
|
64
|
-
extensions: parsed.extensions,
|
|
65
|
-
project: parsed.project,
|
|
66
|
-
});
|
|
67
|
-
process.once("exit", unregister);
|
|
68
|
-
for (const preload of parsed.preload) {
|
|
69
|
-
require(resolvePreload(cwd, preload));
|
|
70
|
-
}
|
|
71
|
-
process.argv = [process.execPath, entry, ...parsed.passthrough];
|
|
72
|
-
Module.runMain();
|
|
73
|
-
return 0;
|
|
43
|
+
return runPreparedEntry(parsed, prepared, cwd);
|
|
74
44
|
}
|
|
75
45
|
|
|
76
46
|
function formatError(error: unknown): string {
|
|
@@ -80,7 +50,7 @@ function formatError(error: unknown): string {
|
|
|
80
50
|
return String(error);
|
|
81
51
|
}
|
|
82
52
|
|
|
83
|
-
function parseCLI(argv: readonly string[])
|
|
53
|
+
function parseCLI(argv: readonly string[]) {
|
|
84
54
|
const preload: string[] = [];
|
|
85
55
|
const passthroughIndex = argv.indexOf("--");
|
|
86
56
|
const head = passthroughIndex === -1 ? [...argv] : [...argv.slice(0, passthroughIndex)];
|
|
@@ -172,10 +142,6 @@ function printHelp(): void {
|
|
|
172
142
|
" -h, --help Show this help",
|
|
173
143
|
" -v, --version Print the runner version",
|
|
174
144
|
"",
|
|
175
|
-
"Runtime:",
|
|
176
|
-
" CommonJS projects execute in-process via the require hook.",
|
|
177
|
-
" ESM projects execute the cached emitted entry in a child Node process.",
|
|
178
|
-
"",
|
|
179
145
|
"Examples:",
|
|
180
146
|
" ttsx src/index.ts",
|
|
181
147
|
" ttsx --project tsconfig.json src/index.ts -- --port 3000",
|
|
@@ -199,14 +165,20 @@ function takeValue(flag: string, rest: string[]): string {
|
|
|
199
165
|
return value;
|
|
200
166
|
}
|
|
201
167
|
|
|
202
|
-
function
|
|
168
|
+
function runPreparedEntry(
|
|
169
|
+
parsed: Exclude<ReturnType<typeof parseCLI>, "help" | "version">,
|
|
170
|
+
execution: ReturnType<typeof prepareExecution>,
|
|
171
|
+
cwd: string,
|
|
172
|
+
): number {
|
|
203
173
|
fs.mkdirSync(execution.emitDir, { recursive: true });
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
174
|
+
if (execution.moduleKind === "esm") {
|
|
175
|
+
rewriteEsmSpecifiers(execution.emitDir);
|
|
176
|
+
fs.writeFileSync(
|
|
177
|
+
path.join(execution.emitDir, "package.json"),
|
|
178
|
+
JSON.stringify({ type: "module" }),
|
|
179
|
+
"utf8",
|
|
180
|
+
);
|
|
181
|
+
}
|
|
210
182
|
const args = [
|
|
211
183
|
...parsed.preload.flatMap((preload) => ["-r", resolvePreload(cwd, preload)]),
|
|
212
184
|
execution.entryFile,
|
package/src/launcher/ttsc.ts
CHANGED
package/src/launcher/ttsx.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { runTtsx } from "./internal/runTtsx";
|
|
4
4
|
|
|
5
|
-
const code =
|
|
5
|
+
const code = runTtsx(process.argv.slice(2));
|
|
6
6
|
if (typeof code === "number") {
|
|
7
7
|
process.exitCode = code;
|
|
8
8
|
}
|