ttsc 0.10.2 → 0.11.0-dev.20260517
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/README.md +8 -0
- package/cmd/ttsc/api_compile.go +106 -106
- package/cmd/ttsc/api_transform.go +54 -54
- package/cmd/ttsc/main.go +103 -103
- package/cmd/ttscserver/helpers_test.go +27 -0
- package/cmd/ttscserver/main.go +154 -0
- package/cmd/ttscserver/run_lsp_reports_getwd_error_test.go +34 -0
- package/cmd/ttscserver/run_lsp_reports_server_error_test.go +42 -0
- package/driver/lsp_envelope.go +136 -0
- package/driver/lsp_frame.go +121 -0
- package/driver/lsp_plugin.go +150 -0
- package/driver/lsp_proxy.go +394 -0
- package/driver/lsp_server.go +197 -0
- package/go.mod +4 -0
- package/go.sum +4 -0
- package/internal/cwd/cwd.go +8 -8
- package/lib/TtscCompiler.d.ts +15 -16
- package/lib/TtscCompiler.js +15 -16
- package/lib/TtscCompiler.js.map +1 -1
- package/lib/compiler/internal/compileProjectInMemory.d.ts +4 -1
- package/lib/compiler/internal/compileProjectInMemory.js +4 -1
- package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
- package/lib/compiler/internal/project/readProjectConfig.js.map +1 -1
- package/lib/compiler/internal/runBuild.js +43 -1
- package/lib/compiler/internal/runBuild.js.map +1 -1
- package/lib/compiler/internal/sharedHostHelpers.d.ts +12 -12
- package/lib/compiler/internal/sharedHostHelpers.js +12 -12
- package/lib/defineTtscPlugin.d.ts +18 -0
- package/lib/defineTtscPlugin.js +7 -0
- package/lib/defineTtscPlugin.js.map +1 -0
- package/lib/index.d.ts +4 -3
- package/lib/index.js +4 -3
- package/lib/index.js.map +1 -1
- package/lib/launcher/internal/prepareExecution.js +1 -1
- package/lib/launcher/internal/prepareExecution.js.map +1 -1
- package/lib/launcher/internal/resolveTtscserverBinary.d.ts +12 -0
- package/lib/launcher/internal/resolveTtscserverBinary.js +43 -0
- package/lib/launcher/internal/resolveTtscserverBinary.js.map +1 -0
- package/lib/launcher/internal/runTtsc.js +47 -8
- package/lib/launcher/internal/runTtsc.js.map +1 -1
- package/lib/launcher/internal/runTtscserver.d.ts +20 -0
- package/lib/launcher/internal/runTtscserver.js +125 -0
- package/lib/launcher/internal/runTtscserver.js.map +1 -0
- package/lib/launcher/internal/runTtsx.js +1 -1
- package/lib/launcher/internal/runTtsx.js.map +1 -1
- package/lib/launcher/ttscserver.d.ts +2 -0
- package/lib/launcher/ttscserver.js +9 -0
- package/lib/launcher/ttscserver.js.map +1 -0
- package/lib/plugin/internal/buildSourcePlugin.d.ts +9 -0
- package/lib/plugin/internal/buildSourcePlugin.js +197 -2
- package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
- package/lib/plugin/internal/loadProjectPlugins.js +86 -8
- package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
- package/lib/structures/ITtscCompilerContext.d.ts +1 -1
- package/lib/structures/ITtscCompilerDiagnostic.d.ts +3 -3
- package/lib/structures/ITtscCompilerResult.d.ts +10 -22
- package/lib/structures/ITtscCompilerTransformation.d.ts +2 -2
- package/lib/structures/ITtscPlugin.d.ts +37 -4
- package/lib/structures/ITtscPlugin.js +0 -4
- package/lib/structures/ITtscPlugin.js.map +1 -1
- package/lib/structures/ITtscPluginContributor.d.ts +26 -0
- package/lib/structures/ITtscPluginContributor.js +3 -0
- package/lib/structures/ITtscPluginContributor.js.map +1 -0
- package/lib/structures/ITtscPluginFactoryContext.d.ts +5 -5
- package/lib/structures/ITtscProjectPluginConfig.d.ts +2 -2
- package/lib/structures/TtscPluginStage.d.ts +4 -3
- package/lib/structures/index.d.ts +1 -0
- package/lib/structures/index.js +1 -0
- package/lib/structures/index.js.map +1 -1
- package/lib/structures/internal/ITtscLoadedNativePlugin.d.ts +3 -0
- package/lib/structures/internal/TtscBuildOptions.d.ts +13 -0
- package/lib/structures/internal/TtscCommonOptions.d.ts +5 -2
- package/package.json +10 -9
- package/shim/lsp/extra-shim.json +4 -0
- package/shim/lsp/go.mod +16 -0
- package/shim/lsp/go.sum +26 -0
- package/shim/lsp/shim.go +42 -0
- package/shim/printer/shim.go +5 -5
- package/src/TtscCompiler.ts +15 -16
- package/src/compiler/internal/compileProjectInMemory.ts +4 -1
- package/src/compiler/internal/project/readProjectConfig.ts +0 -1
- package/src/compiler/internal/runBuild.ts +43 -1
- package/src/compiler/internal/sharedHostHelpers.ts +12 -12
- package/src/defineTtscPlugin.ts +26 -0
- package/src/index.ts +4 -3
- package/src/launcher/internal/prepareExecution.ts +1 -1
- package/src/launcher/internal/resolveTtscserverBinary.ts +51 -0
- package/src/launcher/internal/runTtsc.ts +53 -11
- package/src/launcher/internal/runTtscserver.ts +92 -0
- package/src/launcher/internal/runTtsx.ts +1 -1
- package/src/launcher/ttscserver.ts +8 -0
- package/src/plugin/internal/buildSourcePlugin.ts +231 -12
- package/src/plugin/internal/loadProjectPlugins.ts +108 -8
- package/src/structures/ITtscCompilerContext.ts +1 -1
- package/src/structures/ITtscCompilerDiagnostic.ts +3 -3
- package/src/structures/ITtscCompilerResult.ts +10 -22
- package/src/structures/ITtscCompilerTransformation.ts +2 -2
- package/src/structures/ITtscPlugin.ts +37 -11
- package/src/structures/ITtscPluginContributor.ts +27 -0
- package/src/structures/ITtscPluginFactoryContext.ts +5 -5
- package/src/structures/ITtscProjectPluginConfig.ts +2 -2
- package/src/structures/TtscPluginStage.ts +4 -3
- package/src/structures/index.ts +1 -0
- package/src/structures/internal/ITtscLoadedNativePlugin.ts +3 -0
- package/src/structures/internal/TtscBuildOptions.ts +13 -0
- package/src/structures/internal/TtscCommonOptions.ts +5 -2
|
@@ -2,8 +2,8 @@ import type { ITtscCompilerDiagnostic } from "./ITtscCompilerDiagnostic";
|
|
|
2
2
|
/**
|
|
3
3
|
* Result of a ttsc TypeScript-Go compilation operation.
|
|
4
4
|
*
|
|
5
|
-
* Represents the possible outcomes of {@link TtscCompiler.compile}, which can
|
|
6
|
-
*
|
|
5
|
+
* Represents the possible outcomes of {@link TtscCompiler.compile}, which can be
|
|
6
|
+
* either a successful compilation, a compilation that completed with
|
|
7
7
|
* diagnostics, or an unexpected host error during the compilation process.
|
|
8
8
|
*
|
|
9
9
|
* This type follows the legacy `embed-typescript` result model, but stores all
|
|
@@ -20,17 +20,13 @@ export declare namespace ITtscCompilerResult {
|
|
|
20
20
|
* Represents a successful ttsc compilation result.
|
|
21
21
|
*
|
|
22
22
|
* This interface is returned when TypeScript-Go completes without
|
|
23
|
-
* diagnostics, containing every text output captured from the native
|
|
24
|
-
*
|
|
23
|
+
* diagnostics, containing every text output captured from the native compiler
|
|
24
|
+
* host's `WriteFile` callback.
|
|
25
25
|
*/
|
|
26
26
|
interface ISuccess {
|
|
27
|
-
/**
|
|
28
|
-
* Indicates that the compilation was successful.
|
|
29
|
-
*/
|
|
27
|
+
/** Indicates that the compilation was successful. */
|
|
30
28
|
type: "success";
|
|
31
|
-
/**
|
|
32
|
-
* Non-fatal diagnostics reported during compilation.
|
|
33
|
-
*/
|
|
29
|
+
/** Non-fatal diagnostics reported during compilation. */
|
|
34
30
|
diagnostics?: ITtscCompilerDiagnostic[];
|
|
35
31
|
/**
|
|
36
32
|
* The generated compiler output.
|
|
@@ -51,13 +47,9 @@ export declare namespace ITtscCompilerResult {
|
|
|
51
47
|
* diagnostics.
|
|
52
48
|
*/
|
|
53
49
|
interface IFailure {
|
|
54
|
-
/**
|
|
55
|
-
* Indicates that compilation completed with diagnostics.
|
|
56
|
-
*/
|
|
50
|
+
/** Indicates that compilation completed with diagnostics. */
|
|
57
51
|
type: "failure";
|
|
58
|
-
/**
|
|
59
|
-
* Array of diagnostic messages describing the compilation issues.
|
|
60
|
-
*/
|
|
52
|
+
/** Array of diagnostic messages describing the compilation issues. */
|
|
61
53
|
diagnostics: ITtscCompilerDiagnostic[];
|
|
62
54
|
/**
|
|
63
55
|
* Any compiler output that was generated despite the diagnostics.
|
|
@@ -75,13 +67,9 @@ export declare namespace ITtscCompilerResult {
|
|
|
75
67
|
* {@link IFailure}; this variant is reserved for host-level exceptions.
|
|
76
68
|
*/
|
|
77
69
|
interface IException {
|
|
78
|
-
/**
|
|
79
|
-
* Indicates that an unexpected host error occurred.
|
|
80
|
-
*/
|
|
70
|
+
/** Indicates that an unexpected host error occurred. */
|
|
81
71
|
type: "exception";
|
|
82
|
-
/**
|
|
83
|
-
* The error that was thrown while preparing or running the compiler host.
|
|
84
|
-
*/
|
|
72
|
+
/** The error that was thrown while preparing or running the compiler host. */
|
|
85
73
|
error: unknown;
|
|
86
74
|
}
|
|
87
75
|
}
|
|
@@ -3,8 +3,8 @@ import type { ITtscCompilerDiagnostic } from "./ITtscCompilerDiagnostic";
|
|
|
3
3
|
* Result of a TypeScript source-to-source transformation operation.
|
|
4
4
|
*
|
|
5
5
|
* This mirrors `embed-typescript`'s `IEmbedTypeScriptTransformation` model.
|
|
6
|
-
* Unlike {@link ITtscCompilerResult}, this contract is not an emit contract:
|
|
7
|
-
*
|
|
6
|
+
* Unlike {@link ITtscCompilerResult}, this contract is not an emit contract: the
|
|
7
|
+
* `typescript` map must contain TypeScript source text, not generated
|
|
8
8
|
* JavaScript, declaration files, or source maps.
|
|
9
9
|
*/
|
|
10
10
|
export type ITtscCompilerTransformation = ITtscCompilerTransformation.ISuccess | ITtscCompilerTransformation.IFailure | ITtscCompilerTransformation.IException;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ITtscPluginContributor } from "./ITtscPluginContributor";
|
|
1
2
|
import type { TtscPluginStage } from "./TtscPluginStage";
|
|
2
3
|
/**
|
|
3
4
|
* Runtime descriptor returned by a ttsc plugin module.
|
|
@@ -26,7 +27,7 @@ export interface ITtscPlugin {
|
|
|
26
27
|
/**
|
|
27
28
|
* Go command package directory, or a `go.mod` file, that ttsc lazily builds.
|
|
28
29
|
*
|
|
29
|
-
*
|
|
30
|
+
* Ttsc accepts source only. It does not accept a prebuilt binary path: the
|
|
30
31
|
* package-local Go compiler builds this source into the ttsc plugin cache on
|
|
31
32
|
* demand.
|
|
32
33
|
*
|
|
@@ -56,11 +57,43 @@ export interface ITtscPlugin {
|
|
|
56
57
|
* Pipeline stage implemented by the sidecar.
|
|
57
58
|
*
|
|
58
59
|
* Omit this field for normal compiler-transform plugins. The only explicit
|
|
59
|
-
* non-transform stage is `"check"`.
|
|
60
|
+
* non-transform stage is `"check"`. Check-stage plugins receive `check`
|
|
61
|
+
* during normal builds and may implement `fix` for `ttsc fix` and `format`
|
|
62
|
+
* for `ttsc format`.
|
|
60
63
|
*
|
|
61
64
|
* @default "transform"
|
|
62
65
|
*/
|
|
63
66
|
stage?: TtscPluginStage;
|
|
67
|
+
/**
|
|
68
|
+
* Additional Go source packages to statically link into this plugin's binary
|
|
69
|
+
* at build time ("plugin-within-plugin" composition).
|
|
70
|
+
*
|
|
71
|
+
* Each contributor's Go source directory is copied into the scratch build
|
|
72
|
+
* tree as a sub-package of this plugin's module and reached by a synthesized
|
|
73
|
+
* blank import. The contributor's `init()` runs before the host binary's
|
|
74
|
+
* `main`, registering whatever state the host expects to find at startup
|
|
75
|
+
* (e.g. lint rules through `github.com/samchon/ttsc/packages/lint/rule`).
|
|
76
|
+
*
|
|
77
|
+
* Differs from `composes`:
|
|
78
|
+
*
|
|
79
|
+
* - `composes` is horizontal — many plugin entries dispatch to one binary by
|
|
80
|
+
* name. Each entry is still a top-level `compilerOptions.plugins[]` citizen
|
|
81
|
+
* with its own lifecycle slot.
|
|
82
|
+
* - `contributors` is vertical — one binary statically links additional Go
|
|
83
|
+
* sources that never appear as top-level plugin entries. The contributing
|
|
84
|
+
* npm packages are discovered through the host plugin's own config file
|
|
85
|
+
* (e.g. `lint.config.ts` for `@ttsc/lint`).
|
|
86
|
+
*
|
|
87
|
+
* Constraints:
|
|
88
|
+
*
|
|
89
|
+
* - Contributors ship Go source as a package (no `go.mod`); the host plugin's
|
|
90
|
+
* module supplies every transitive Go dependency. This is also a
|
|
91
|
+
* supply-chain feature — contributors cannot pull in arbitrary Go modules
|
|
92
|
+
* at build time.
|
|
93
|
+
* - Contributor source paths must be absolute (the host plugin's JS factory
|
|
94
|
+
* typically resolves them through `require.resolve`).
|
|
95
|
+
* - Contributor names are used as the sub-package import suffix and must be
|
|
96
|
+
* unique within a single plugin build.
|
|
97
|
+
*/
|
|
98
|
+
contributors?: ITtscPluginContributor[];
|
|
64
99
|
}
|
|
65
|
-
export declare function defineTtscPlugin<T extends ITtscPlugin>(plugin: T): T;
|
|
66
|
-
export declare function defineTtscPlugin<TContext, T extends ITtscPlugin>(factory: (context: TContext) => T): (context: TContext) => T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ITtscPlugin.js","sourceRoot":"","sources":["../../src/structures/ITtscPlugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ITtscPlugin.js","sourceRoot":"","sources":["../../src/structures/ITtscPlugin.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One contributor entry inside `ITtscPlugin.contributors`.
|
|
3
|
+
*
|
|
4
|
+
* The native builder copies `source` into `<scratch>/contrib/<name>/` and adds
|
|
5
|
+
* a blank-import for `<host-module>/contrib/<name>` to the synthesized
|
|
6
|
+
* `ttsc_contributions.go` placed alongside the host's main package.
|
|
7
|
+
*/
|
|
8
|
+
export interface ITtscPluginContributor {
|
|
9
|
+
/**
|
|
10
|
+
* Sub-package name.
|
|
11
|
+
*
|
|
12
|
+
* Forms the final import path together with the host plugin's Go module path;
|
|
13
|
+
* must match `/^[a-z][a-z0-9_]*$/` — a lowercase ASCII letter followed by
|
|
14
|
+
* lowercase letters, digits, or underscores — and be unique within one plugin
|
|
15
|
+
* build.
|
|
16
|
+
*/
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* Absolute path to the contributor's Go source directory.
|
|
20
|
+
*
|
|
21
|
+
* Every `.go` file under this directory is copied into the scratch build tree
|
|
22
|
+
* as a sub-package of the host plugin's module. Subdirectories are copied
|
|
23
|
+
* recursively; `go.mod` files, `node_modules`, and `.git` are pruned.
|
|
24
|
+
*/
|
|
25
|
+
source: string;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITtscPluginContributor.js","sourceRoot":"","sources":["../../src/structures/ITtscPluginContributor.ts"],"names":[],"mappings":""}
|
|
@@ -9,8 +9,8 @@ import type { ITtscProjectPluginConfig } from "./ITtscProjectPluginConfig";
|
|
|
9
9
|
* project root.
|
|
10
10
|
*
|
|
11
11
|
* The factory runs in Node.js while ttsc is loading `compilerOptions.plugins`.
|
|
12
|
-
* It should only create the descriptor. Heavy validation and TypeScript-Go
|
|
13
|
-
*
|
|
12
|
+
* It should only create the descriptor. Heavy validation and TypeScript-Go work
|
|
13
|
+
* belong in the Go sidecar selected by {@link ITtscPlugin.source}.
|
|
14
14
|
*/
|
|
15
15
|
export interface ITtscPluginFactoryContext<T = ITtscProjectPluginConfig> {
|
|
16
16
|
/**
|
|
@@ -18,8 +18,8 @@ export interface ITtscPluginFactoryContext<T = ITtscProjectPluginConfig> {
|
|
|
18
18
|
*
|
|
19
19
|
* This is the package's own native helper, not the plugin sidecar and not the
|
|
20
20
|
* JavaScript launcher. Most plugins do not need it; it is provided for
|
|
21
|
-
* advanced factories that need to derive behavior from the active ttsc
|
|
22
|
-
*
|
|
21
|
+
* advanced factories that need to derive behavior from the active ttsc native
|
|
22
|
+
* host.
|
|
23
23
|
*/
|
|
24
24
|
binary: string;
|
|
25
25
|
/**
|
|
@@ -33,7 +33,7 @@ export interface ITtscPluginFactoryContext<T = ITtscProjectPluginConfig> {
|
|
|
33
33
|
/**
|
|
34
34
|
* Original `compilerOptions.plugins[]` entry that loaded this plugin.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
36
|
+
* Ttsc reserves `transform` and `enabled`. Every other property is
|
|
37
37
|
* plugin-owned config and is later serialized unchanged into the native
|
|
38
38
|
* sidecar manifest.
|
|
39
39
|
*/
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* or plugin packages expose through `package.json`. ttsc deliberately keeps it
|
|
7
7
|
* open-ended because plugin packages own their own config fields.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* Ttsc interprets only two properties:
|
|
10
10
|
*
|
|
11
11
|
* - `transform`: the JavaScript module specifier used to load the plugin
|
|
12
12
|
* descriptor or factory.
|
|
@@ -40,7 +40,7 @@ export interface ITtscProjectPluginConfig {
|
|
|
40
40
|
/**
|
|
41
41
|
* Plugin-specific config passed through unchanged to the native sidecar.
|
|
42
42
|
*
|
|
43
|
-
*
|
|
43
|
+
* Ttsc does not validate these fields. Plugin packages should document their
|
|
44
44
|
* own config contract and validate it inside their factory or Go sidecar.
|
|
45
45
|
*/
|
|
46
46
|
[key: string]: unknown;
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* - `"transform"`: participates in the TypeScript-Go transform path. Transform
|
|
5
5
|
* plugins do not receive emitted JavaScript or emitted file text.
|
|
6
|
-
* - `"check"`: runs before emit and reports diagnostics
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* - `"check"`: runs before emit and reports diagnostics. Use this for lint or
|
|
7
|
+
* validation plugins that should fail the compile before JavaScript or
|
|
8
|
+
* declaration output is generated. Check plugins may also implement a `fix`
|
|
9
|
+
* command, which `ttsc fix` invokes with emit disabled.
|
|
9
10
|
*/
|
|
10
11
|
export type TtscPluginStage = "transform" | "check";
|
|
@@ -3,6 +3,7 @@ export * from "./ITtscCompilerDiagnostic";
|
|
|
3
3
|
export * from "./ITtscCompilerResult";
|
|
4
4
|
export * from "./ITtscCompilerTransformation";
|
|
5
5
|
export * from "./ITtscPlugin";
|
|
6
|
+
export * from "./ITtscPluginContributor";
|
|
6
7
|
export * from "./ITtscPluginFactoryContext";
|
|
7
8
|
export * from "./ITtscProjectPluginConfig";
|
|
8
9
|
export * from "./TtscPluginStage";
|
package/lib/structures/index.js
CHANGED
|
@@ -19,6 +19,7 @@ __exportStar(require("./ITtscCompilerDiagnostic"), exports);
|
|
|
19
19
|
__exportStar(require("./ITtscCompilerResult"), exports);
|
|
20
20
|
__exportStar(require("./ITtscCompilerTransformation"), exports);
|
|
21
21
|
__exportStar(require("./ITtscPlugin"), exports);
|
|
22
|
+
__exportStar(require("./ITtscPluginContributor"), exports);
|
|
22
23
|
__exportStar(require("./ITtscPluginFactoryContext"), exports);
|
|
23
24
|
__exportStar(require("./ITtscProjectPluginConfig"), exports);
|
|
24
25
|
__exportStar(require("./TtscPluginStage"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/structures/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,4DAA0C;AAC1C,wDAAsC;AACtC,gEAA8C;AAC9C,gDAA8B;AAC9B,8DAA4C;AAC5C,6DAA2C;AAC3C,oDAAkC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/structures/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,4DAA0C;AAC1C,wDAAsC;AACtC,gEAA8C;AAC9C,gDAA8B;AAC9B,2DAAyC;AACzC,8DAA4C;AAC5C,6DAA2C;AAC3C,oDAAkC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ITtscPluginContributor } from "../ITtscPluginContributor";
|
|
1
2
|
import type { ITtscProjectPluginConfig } from "../ITtscProjectPluginConfig";
|
|
2
3
|
import type { TtscPluginStage } from "../TtscPluginStage";
|
|
3
4
|
/** Native sidecar selected and built from one plugin descriptor. */
|
|
@@ -6,6 +7,8 @@ export interface ITtscLoadedNativePlugin {
|
|
|
6
7
|
binary: string;
|
|
7
8
|
/** Original tsconfig plugin entry passed unchanged to the sidecar. */
|
|
8
9
|
config: ITtscProjectPluginConfig;
|
|
10
|
+
/** Contributor Go sources statically linked into the binary, if any. */
|
|
11
|
+
contributors?: readonly ITtscPluginContributor[];
|
|
9
12
|
/** Stable plugin name used in diagnostics and native manifests. */
|
|
10
13
|
name: string;
|
|
11
14
|
/** Go source directory selected by the plugin descriptor. */
|
|
@@ -11,6 +11,19 @@ export interface TtscBuildOptions extends TtscCommonOptions {
|
|
|
11
11
|
* - `undefined`: follow the resolved tsconfig exactly.
|
|
12
12
|
*/
|
|
13
13
|
emit?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Invoke fix-capable check-stage plugins before the final no-emit check.
|
|
16
|
+
* Source files may be rewritten; JavaScript/declaration emit stays disabled.
|
|
17
|
+
*/
|
|
18
|
+
fix?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Invoke format-capable check-stage plugins. Source files may be rewritten
|
|
21
|
+
* with formatter-class edits (whitespace, punctuation, ordering); diagnostics
|
|
22
|
+
* are not reported and JavaScript/declaration emit stays disabled. The
|
|
23
|
+
* launcher selects this through the `ttsc format` subcommand and rejects
|
|
24
|
+
* combination with watch mode, single-file mode, or an explicit `--emit`.
|
|
25
|
+
*/
|
|
26
|
+
format?: boolean;
|
|
14
27
|
/** Per-call TypeScript-Go `outDir` override. */
|
|
15
28
|
outDir?: string;
|
|
16
29
|
/** Suppress summary banners from ttsc/native sidecars. Defaults to `true`. */
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { ITtscProjectPluginConfig } from "../ITtscProjectPluginConfig";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Internal options shared by the CLI build, single-file emit, and runtime
|
|
4
|
+
* paths.
|
|
5
|
+
*/
|
|
3
6
|
export interface TtscCommonOptions {
|
|
4
7
|
/**
|
|
5
8
|
* Explicit TypeScript-Go executable.
|
|
@@ -22,7 +25,7 @@ export interface TtscCommonOptions {
|
|
|
22
25
|
* Override project plugin loading for this invocation.
|
|
23
26
|
*
|
|
24
27
|
* - `false`: ignore `compilerOptions.plugins` completely.
|
|
25
|
-
* -
|
|
28
|
+
* - Array: use these plugin entries instead of the project config entries.
|
|
26
29
|
* - `undefined`: use the project config entries as written.
|
|
27
30
|
*/
|
|
28
31
|
plugins?: readonly ITtscProjectPluginConfig[] | false;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ttsc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0-dev.20260517",
|
|
4
4
|
"description": "General-purpose TypeScript-Go compiler, plugin host, and runtime.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
7
7
|
"bin": {
|
|
8
8
|
"ttsc": "lib/launcher/ttsc.js",
|
|
9
|
+
"ttscserver": "lib/launcher/ttscserver.js",
|
|
9
10
|
"ttsx": "lib/launcher/ttsx.js"
|
|
10
11
|
},
|
|
11
12
|
"exports": {
|
|
@@ -27,17 +28,17 @@
|
|
|
27
28
|
"homepage": "https://github.com/samchon/ttsc",
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@types/node": "^25.3.0",
|
|
30
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
31
|
+
"@typescript/native-preview": "7.0.0-dev.20260515.1",
|
|
31
32
|
"rimraf": "^6.1.2"
|
|
32
33
|
},
|
|
33
34
|
"optionalDependencies": {
|
|
34
|
-
"@ttsc/linux-x64": "0.
|
|
35
|
-
"@ttsc/
|
|
36
|
-
"@ttsc/darwin-
|
|
37
|
-
"@ttsc/
|
|
38
|
-
"@ttsc/
|
|
39
|
-
"@ttsc/
|
|
40
|
-
"@ttsc/
|
|
35
|
+
"@ttsc/linux-x64": "0.11.0-dev.20260517",
|
|
36
|
+
"@ttsc/win32-x64": "0.11.0-dev.20260517",
|
|
37
|
+
"@ttsc/darwin-arm64": "0.11.0-dev.20260517",
|
|
38
|
+
"@ttsc/win32-arm64": "0.11.0-dev.20260517",
|
|
39
|
+
"@ttsc/linux-arm": "0.11.0-dev.20260517",
|
|
40
|
+
"@ttsc/linux-arm64": "0.11.0-dev.20260517",
|
|
41
|
+
"@ttsc/darwin-x64": "0.11.0-dev.20260517"
|
|
41
42
|
},
|
|
42
43
|
"sideEffects": false,
|
|
43
44
|
"files": [
|
package/shim/lsp/go.mod
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module github.com/microsoft/typescript-go/shim/lsp
|
|
2
|
+
|
|
3
|
+
go 1.26
|
|
4
|
+
|
|
5
|
+
require github.com/microsoft/typescript-go v0.0.0-20260429010842-56ab4af42157
|
|
6
|
+
|
|
7
|
+
require (
|
|
8
|
+
github.com/Microsoft/go-winio v0.6.2 // indirect
|
|
9
|
+
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 // indirect
|
|
10
|
+
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
|
11
|
+
github.com/mackerelio/go-osstat v0.2.7 // indirect
|
|
12
|
+
github.com/zeebo/xxh3 v1.1.0 // indirect
|
|
13
|
+
golang.org/x/sync v0.20.0 // indirect
|
|
14
|
+
golang.org/x/sys v0.43.0 // indirect
|
|
15
|
+
golang.org/x/text v0.36.0 // indirect
|
|
16
|
+
)
|
package/shim/lsp/go.sum
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
|
2
|
+
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
|
3
|
+
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 h1:vymEbVwYFP/L05h5TKQxvkXoKxNvTpjxYKdF1Nlwuao=
|
|
4
|
+
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg=
|
|
5
|
+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
|
6
|
+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
|
7
|
+
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
|
8
|
+
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
|
9
|
+
github.com/mackerelio/go-osstat v0.2.7 h1:TCavZi10wF49bT6iQZ9eT2keGZQpC69MTDfdJej5e94=
|
|
10
|
+
github.com/mackerelio/go-osstat v0.2.7/go.mod h1:dwpYh5pIPmvk+IEwBKNIWRFMB92mrC08CmXOhDC7nQk=
|
|
11
|
+
github.com/microsoft/typescript-go v0.0.0-20260429010842-56ab4af42157 h1:llOMPhKDiQ+UEJiAaQuuWaJOTg5V7tNNTEf9JPWoYSY=
|
|
12
|
+
github.com/microsoft/typescript-go v0.0.0-20260429010842-56ab4af42157/go.mod h1:m8YA0PMC7ti0GW0RI05D6fEcjQeu98XVS+FWF+VDW2k=
|
|
13
|
+
github.com/peter-evans/patience v0.3.0 h1:rX0JdJeepqdQl1Sk9c9uvorjYYzL2TfgLX1adqYm9cA=
|
|
14
|
+
github.com/peter-evans/patience v0.3.0/go.mod h1:Kmxu5sY1NmBLFSStvXjX1wS9mIv7wMcP/ubucyMOAu0=
|
|
15
|
+
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
|
|
16
|
+
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
|
|
17
|
+
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
|
|
18
|
+
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
|
|
19
|
+
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
|
20
|
+
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
|
21
|
+
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
|
|
22
|
+
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
|
23
|
+
golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
|
|
24
|
+
golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164=
|
|
25
|
+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
|
26
|
+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
package/shim/lsp/shim.go
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// gen_shims:hand-maintained
|
|
2
|
+
//
|
|
3
|
+
// Minimal shim of tsgo's internal/lsp package. Hand-written instead of
|
|
4
|
+
// generated so the surface stays narrow: ttscserver embeds the tsgo LSP
|
|
5
|
+
// server unmodified and intercepts traffic at the byte level, so the only
|
|
6
|
+
// types it touches are the opaque Server, its options struct, and the
|
|
7
|
+
// Reader/Writer interfaces that ToReader/ToWriter return. The marker on
|
|
8
|
+
// the first line tells gen_shims to skip this file.
|
|
9
|
+
package lsp
|
|
10
|
+
|
|
11
|
+
import (
|
|
12
|
+
"io"
|
|
13
|
+
_ "unsafe"
|
|
14
|
+
|
|
15
|
+
innerlsp "github.com/microsoft/typescript-go/internal/lsp"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
// Server is the opaque LSP server type from tsgo. ttscserver does not poke
|
|
19
|
+
// its internals; it only calls Run and (via wrapped Writer) observes the
|
|
20
|
+
// traffic the server emits.
|
|
21
|
+
type Server = innerlsp.Server
|
|
22
|
+
|
|
23
|
+
// ServerOptions mirrors the upstream construction parameters. Fields with
|
|
24
|
+
// internal-package types (e.g. ParseCache *project.ParseCache) are left
|
|
25
|
+
// unset by ttscserver, which is safe because every such field is an
|
|
26
|
+
// optional pointer the upstream constructor accepts as nil.
|
|
27
|
+
type ServerOptions = innerlsp.ServerOptions
|
|
28
|
+
|
|
29
|
+
// Reader / Writer carry framed lsproto.Message values. ttscserver feeds
|
|
30
|
+
// the server through io.Pipe shims of these so it can splice its own
|
|
31
|
+
// JSON-RPC traffic into the same stream the editor speaks.
|
|
32
|
+
type Reader = innerlsp.Reader
|
|
33
|
+
type Writer = innerlsp.Writer
|
|
34
|
+
|
|
35
|
+
//go:linkname NewServer github.com/microsoft/typescript-go/internal/lsp.NewServer
|
|
36
|
+
func NewServer(opts *ServerOptions) *Server
|
|
37
|
+
|
|
38
|
+
//go:linkname ToReader github.com/microsoft/typescript-go/internal/lsp.ToReader
|
|
39
|
+
func ToReader(r io.Reader) Reader
|
|
40
|
+
|
|
41
|
+
//go:linkname ToWriter github.com/microsoft/typescript-go/internal/lsp.ToWriter
|
|
42
|
+
func ToWriter(w io.Writer) Writer
|
package/shim/printer/shim.go
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
package printer
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
"github.com/microsoft/typescript-go/internal/ast"
|
|
5
|
+
innerprinter "github.com/microsoft/typescript-go/internal/printer"
|
|
6
6
|
)
|
|
7
7
|
|
|
8
8
|
type PrintHandlers = innerprinter.PrintHandlers
|
|
@@ -11,13 +11,13 @@ type PrinterOptions = innerprinter.PrinterOptions
|
|
|
11
11
|
type EmitContext = innerprinter.EmitContext
|
|
12
12
|
|
|
13
13
|
func NewPrinter(options PrinterOptions, handlers PrintHandlers, emitContext *EmitContext) *Printer {
|
|
14
|
-
|
|
14
|
+
return innerprinter.NewPrinter(options, handlers, emitContext)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
func NewEmitContext() *EmitContext {
|
|
18
|
-
|
|
18
|
+
return innerprinter.NewEmitContext()
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
func EmitSourceFile(p *Printer, sourceFile *ast.SourceFile) string {
|
|
22
|
-
|
|
22
|
+
return p.EmitSourceFile(sourceFile)
|
|
23
23
|
}
|
package/src/TtscCompiler.ts
CHANGED
|
@@ -15,23 +15,22 @@ import type { TtscBuildResult } from "./structures/internal/TtscBuildResult";
|
|
|
15
15
|
/**
|
|
16
16
|
* Programmatic compiler host for the `ttsc` TypeScript-Go pipeline.
|
|
17
17
|
*
|
|
18
|
-
* `TtscCompiler` is the root JavaScript API exported by the `ttsc` package.
|
|
19
|
-
*
|
|
20
|
-
* project config path, an optional native toolchain override, an environment,
|
|
21
|
-
*
|
|
22
|
-
*
|
|
18
|
+
* `TtscCompiler` is the root JavaScript API exported by the `ttsc` package. It
|
|
19
|
+
* represents one resolved project context: a working directory, an optional
|
|
20
|
+
* project config path, an optional native toolchain override, an environment, a
|
|
21
|
+
* cache root, and a plugin list. Those values are captured by the constructor
|
|
22
|
+
* and are intentionally not replaceable per method call.
|
|
23
23
|
*
|
|
24
24
|
* The class exposes only the operations that make sense for an embedded
|
|
25
25
|
* compiler host:
|
|
26
26
|
*
|
|
27
27
|
* - {@link TtscCompiler.prepare}: build configured Go source plugins into the
|
|
28
28
|
* cache before a later compile.
|
|
29
|
-
* - {@link TtscCompiler.clean}: remove the cache owned by this compiler
|
|
30
|
-
* context.
|
|
29
|
+
* - {@link TtscCompiler.clean}: remove the cache owned by this compiler context.
|
|
31
30
|
* - {@link TtscCompiler.compile}: compile the configured project and return a
|
|
32
31
|
* structured result instead of terminal text.
|
|
33
|
-
* - {@link TtscCompiler.transform}: transform the configured project and
|
|
34
|
-
*
|
|
32
|
+
* - {@link TtscCompiler.transform}: transform the configured project and return an
|
|
33
|
+
* embed-style transformation result.
|
|
35
34
|
*/
|
|
36
35
|
export class TtscCompiler {
|
|
37
36
|
private readonly context: ITtscCompilerContext;
|
|
@@ -106,14 +105,14 @@ export class TtscCompiler {
|
|
|
106
105
|
*
|
|
107
106
|
* The public API does not write emitted files into the caller's project tree.
|
|
108
107
|
* For projects without plugins, ttsc uses its native TypeScript-Go host's
|
|
109
|
-
* `WriteFile` callback to capture output in memory. For projects with
|
|
110
|
-
*
|
|
108
|
+
* `WriteFile` callback to capture output in memory. For projects with native
|
|
109
|
+
* plugins, ttsc runs the plugin pipeline against a temporary output
|
|
111
110
|
* directory, reads the generated text artifacts, and removes the temporary
|
|
112
111
|
* directory before returning.
|
|
113
112
|
*
|
|
114
|
-
* The result uses an `embed-typescript`-style discriminated union:
|
|
115
|
-
*
|
|
116
|
-
*
|
|
113
|
+
* The result uses an `embed-typescript`-style discriminated union: `success`
|
|
114
|
+
* for clean compiles, `failure` for normal compiler diagnostics, and
|
|
115
|
+
* `exception` for host setup or process failures.
|
|
117
116
|
*
|
|
118
117
|
* @returns Structured compilation result containing diagnostics or output.
|
|
119
118
|
*/
|
|
@@ -127,8 +126,8 @@ export class TtscCompiler {
|
|
|
127
126
|
* This is the source-to-source API for plugin authors. It must not return
|
|
128
127
|
* JavaScript emit, declaration files, or source maps; those artifacts belong
|
|
129
128
|
* to {@link TtscCompiler.compile}. A transform sidecar is expected to write
|
|
130
|
-
* JSON shaped as `{ "typescript": { "src/file.ts": "..." } }` to stdout.
|
|
131
|
-
*
|
|
129
|
+
* JSON shaped as `{ "typescript": { "src/file.ts": "..." } }` to stdout. When
|
|
130
|
+
* no transform sidecar is configured, ttsc returns the TypeScript files
|
|
132
131
|
* loaded by the TypeScript-Go Program together with normal diagnostics.
|
|
133
132
|
*
|
|
134
133
|
* The returned shape mirrors `embed-typescript`'s transformation API:
|
|
@@ -12,7 +12,10 @@ import { buildNativeCompiler } from "./buildNativeCompiler";
|
|
|
12
12
|
import { readProjectConfig } from "./project/readProjectConfig";
|
|
13
13
|
import { runBuild } from "./runBuild";
|
|
14
14
|
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Compile a project and capture emitted files without writing to the project
|
|
17
|
+
* tree.
|
|
18
|
+
*/
|
|
16
19
|
export function compileProjectInMemory(options: ITtscCompilerContext): {
|
|
17
20
|
output: Record<string, string>;
|
|
18
21
|
result: TtscBuildResult;
|
|
@@ -5,7 +5,6 @@ import path from "node:path";
|
|
|
5
5
|
import type { ITtscProjectPluginConfig } from "../../../structures/ITtscProjectPluginConfig";
|
|
6
6
|
import type { ITtscParsedProjectConfig } from "../../../structures/internal/ITtscParsedProjectConfig";
|
|
7
7
|
import type { ITtscProjectLocatorOptions } from "../../../structures/internal/ITtscProjectLocatorOptions";
|
|
8
|
-
|
|
9
8
|
import { resolveProjectConfig } from "./resolveProjectConfig";
|
|
10
9
|
|
|
11
10
|
const PATH_OPTIONS = new Set(["baseUrl", "declarationDir", "rootDir"]);
|