ttsc 0.8.0 → 0.9.0

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 (84) hide show
  1. package/README.md +75 -66
  2. package/cmd/ttsc/api_compile.go +5 -1
  3. package/driver/program.go +23 -1
  4. package/driver/rewrite.go +126 -9
  5. package/driver/rewrite_test.go +52 -0
  6. package/lib/TtscCompiler.js +28 -46
  7. package/lib/TtscCompiler.js.map +1 -1
  8. package/lib/compiler/internal/buildNativeCompiler.js +8 -38
  9. package/lib/compiler/internal/buildNativeCompiler.js.map +1 -1
  10. package/lib/compiler/internal/compileProjectInMemory.js +36 -63
  11. package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
  12. package/lib/compiler/internal/project/readProjectConfig.js +108 -60
  13. package/lib/compiler/internal/project/readProjectConfig.js.map +1 -1
  14. package/lib/compiler/internal/project/resolveProjectConfig.js +15 -45
  15. package/lib/compiler/internal/project/resolveProjectConfig.js.map +1 -1
  16. package/lib/compiler/internal/resolveBinary.js +10 -40
  17. package/lib/compiler/internal/resolveBinary.js.map +1 -1
  18. package/lib/compiler/internal/resolveEmittedJavaScript.js +21 -48
  19. package/lib/compiler/internal/resolveEmittedJavaScript.js.map +1 -1
  20. package/lib/compiler/internal/resolveTsgo.js +14 -44
  21. package/lib/compiler/internal/resolveTsgo.js.map +1 -1
  22. package/lib/compiler/internal/runBuild.d.ts +7 -0
  23. package/lib/compiler/internal/runBuild.js +47 -66
  24. package/lib/compiler/internal/runBuild.js.map +1 -1
  25. package/lib/compiler/internal/runSingleFileEmit.js +18 -48
  26. package/lib/compiler/internal/runSingleFileEmit.js.map +1 -1
  27. package/lib/compiler/internal/transformProjectInMemory.js +41 -75
  28. package/lib/compiler/internal/transformProjectInMemory.js.map +1 -1
  29. package/lib/launcher/internal/getCompilerVersionText.js +7 -37
  30. package/lib/launcher/internal/getCompilerVersionText.js.map +1 -1
  31. package/lib/launcher/internal/prepareExecution.js +48 -69
  32. package/lib/launcher/internal/prepareExecution.js.map +1 -1
  33. package/lib/launcher/internal/runTtsc.js +53 -64
  34. package/lib/launcher/internal/runTtsc.js.map +1 -1
  35. package/lib/launcher/internal/runTtsx.js +328 -57
  36. package/lib/launcher/internal/runTtsx.js.map +1 -1
  37. package/lib/plugin/internal/buildSourcePlugin.d.ts +8 -0
  38. package/lib/plugin/internal/buildSourcePlugin.js +179 -125
  39. package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
  40. package/lib/plugin/internal/loadProjectPlugins.d.ts +2 -0
  41. package/lib/plugin/internal/loadProjectPlugins.js +197 -9
  42. package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
  43. package/lib/structures/ITtscCompilerContext.d.ts +16 -3
  44. package/lib/structures/ITtscCompilerResult.d.ts +4 -0
  45. package/lib/structures/ITtscCompilerTransformation.d.ts +2 -0
  46. package/lib/structures/ITtscPluginFactoryContext.d.ts +6 -3
  47. package/lib/structures/ITtscProjectPluginConfig.d.ts +8 -7
  48. package/lib/structures/internal/ITtscParsedProjectConfig.d.ts +2 -0
  49. package/lib/structures/internal/ITtscProjectLocatorOptions.d.ts +2 -0
  50. package/lib/structures/internal/TtscCommonOptions.d.ts +2 -0
  51. package/package.json +9 -14
  52. package/shim/diagnosticwriter/lint.go +8 -0
  53. package/src/TtscCompiler.ts +20 -5
  54. package/src/compiler/internal/buildNativeCompiler.ts +2 -2
  55. package/src/compiler/internal/compileProjectInMemory.ts +21 -16
  56. package/src/compiler/internal/project/readProjectConfig.ts +134 -35
  57. package/src/compiler/internal/project/resolveProjectConfig.ts +2 -2
  58. package/src/compiler/internal/resolveBinary.ts +2 -2
  59. package/src/compiler/internal/resolveEmittedJavaScript.ts +11 -7
  60. package/src/compiler/internal/resolveTsgo.ts +2 -2
  61. package/src/compiler/internal/runBuild.ts +34 -21
  62. package/src/compiler/internal/runSingleFileEmit.ts +3 -3
  63. package/src/compiler/internal/transformProjectInMemory.ts +37 -37
  64. package/src/launcher/internal/getCompilerVersionText.ts +2 -2
  65. package/src/launcher/internal/prepareExecution.ts +14 -4
  66. package/src/launcher/internal/runTtsc.ts +30 -4
  67. package/src/launcher/internal/runTtsx.ts +377 -26
  68. package/src/plugin/internal/buildSourcePlugin.ts +127 -32
  69. package/src/plugin/internal/loadProjectPlugins.ts +266 -10
  70. package/src/structures/ITtscCompilerContext.ts +17 -3
  71. package/src/structures/ITtscCompilerResult.ts +5 -0
  72. package/src/structures/ITtscCompilerTransformation.ts +3 -0
  73. package/src/structures/ITtscPluginFactoryContext.ts +6 -3
  74. package/src/structures/ITtscProjectPluginConfig.ts +8 -7
  75. package/src/structures/internal/ITtscParsedProjectConfig.ts +2 -0
  76. package/src/structures/internal/ITtscProjectLocatorOptions.ts +2 -0
  77. package/src/structures/internal/TtscCommonOptions.ts +2 -0
  78. package/utility/host.go +610 -18
  79. package/utility/host_test.go +162 -0
  80. package/test/compiler.test.ts +0 -422
  81. package/test/platform.test.ts +0 -12
  82. package/test/project.test.ts +0 -197
  83. package/test/source-build.test.ts +0 -45
  84. package/test/tsgo.test.ts +0 -69
@@ -1,197 +0,0 @@
1
- const assert = require("node:assert/strict");
2
- const fs = require("node:fs");
3
- const os = require("node:os");
4
- const path = require("node:path");
5
- const test = require("node:test");
6
-
7
- const {
8
- readProjectConfig,
9
- } = require("../lib/compiler/internal/project/readProjectConfig.js");
10
- const {
11
- resolveProjectConfig,
12
- } = require("../lib/compiler/internal/project/resolveProjectConfig.js");
13
-
14
- test("resolveProjectConfig canonicalizes symlinked tsconfig paths", () => {
15
- const root = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-project-"));
16
- const real = path.join(root, "real");
17
- const link = path.join(root, "link");
18
- fs.mkdirSync(real, { recursive: true });
19
- fs.writeFileSync(path.join(real, "tsconfig.json"), "{}\n", "utf8");
20
- fs.symlinkSync(real, link, "dir");
21
-
22
- const resolved = resolveProjectConfig({
23
- tsconfig: path.join(link, "tsconfig.json"),
24
- });
25
- assert.equal(resolved, fs.realpathSync(path.join(real, "tsconfig.json")));
26
- });
27
-
28
- test("readProjectConfig inherits plugins and outDir through tsconfig extends", () => {
29
- const root = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-project-"));
30
- const shared = path.join(root, "config");
31
- const project = path.join(root, "project");
32
- fs.mkdirSync(shared, { recursive: true });
33
- fs.mkdirSync(project, { recursive: true });
34
- fs.writeFileSync(
35
- path.join(shared, "tsconfig.json"),
36
- JSON.stringify(
37
- {
38
- compilerOptions: {
39
- outDir: "../dist/shared",
40
- plugins: [{ transform: "./plugins/example.cjs" }],
41
- },
42
- },
43
- null,
44
- 2,
45
- ),
46
- "utf8",
47
- );
48
- fs.writeFileSync(
49
- path.join(project, "tsconfig.json"),
50
- JSON.stringify(
51
- {
52
- extends: "../config/tsconfig.json",
53
- compilerOptions: {},
54
- },
55
- null,
56
- 2,
57
- ),
58
- "utf8",
59
- );
60
-
61
- const parsed = readProjectConfig({
62
- tsconfig: path.join(project, "tsconfig.json"),
63
- });
64
- assert.deepEqual(parsed.compilerOptions.plugins, [
65
- { transform: "./plugins/example.cjs" },
66
- ]);
67
- assert.equal(parsed.compilerOptions.outDir, path.join(root, "dist/shared"));
68
- });
69
-
70
- test("readProjectConfig lets child tsconfig override inherited plugins", () => {
71
- const root = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-project-"));
72
- const shared = path.join(root, "config");
73
- const project = path.join(root, "project");
74
- fs.mkdirSync(shared, { recursive: true });
75
- fs.mkdirSync(project, { recursive: true });
76
- fs.writeFileSync(
77
- path.join(shared, "tsconfig.json"),
78
- JSON.stringify(
79
- {
80
- compilerOptions: {
81
- plugins: [{ transform: "./plugins/example.cjs" }],
82
- },
83
- },
84
- null,
85
- 2,
86
- ),
87
- "utf8",
88
- );
89
- fs.writeFileSync(
90
- path.join(project, "tsconfig.json"),
91
- JSON.stringify(
92
- {
93
- extends: "../config/tsconfig.json",
94
- compilerOptions: {
95
- plugins: [{ transform: "./local-plugin.cjs" }],
96
- },
97
- },
98
- null,
99
- 2,
100
- ),
101
- "utf8",
102
- );
103
-
104
- const parsed = readProjectConfig({
105
- tsconfig: path.join(project, "tsconfig.json"),
106
- });
107
- assert.deepEqual(parsed.compilerOptions.plugins, [
108
- { transform: "./local-plugin.cjs" },
109
- ]);
110
- });
111
-
112
- test("readProjectConfig resolves package tsconfig extends", () => {
113
- const root = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-project-"));
114
- const preset = path.join(root, "node_modules", "@scope", "tsconfig");
115
- const project = path.join(root, "project");
116
- fs.mkdirSync(preset, { recursive: true });
117
- fs.mkdirSync(project, { recursive: true });
118
- fs.writeFileSync(
119
- path.join(preset, "base.json"),
120
- JSON.stringify(
121
- {
122
- compilerOptions: {
123
- outDir: "../../dist/preset",
124
- plugins: [{ transform: "./plugins/from-preset.cjs" }],
125
- },
126
- },
127
- null,
128
- 2,
129
- ),
130
- "utf8",
131
- );
132
- fs.writeFileSync(
133
- path.join(project, "tsconfig.json"),
134
- JSON.stringify(
135
- {
136
- extends: "@scope/tsconfig/base.json",
137
- compilerOptions: {},
138
- },
139
- null,
140
- 2,
141
- ),
142
- "utf8",
143
- );
144
-
145
- const parsed = readProjectConfig({
146
- tsconfig: path.join(project, "tsconfig.json"),
147
- });
148
- assert.deepEqual(parsed.compilerOptions.plugins, [
149
- { transform: "./plugins/from-preset.cjs" },
150
- ]);
151
- assert.equal(
152
- parsed.compilerOptions.outDir,
153
- path.join(root, "node_modules", "dist", "preset"),
154
- );
155
- });
156
-
157
- test("readProjectConfig accepts JSONC comments and trailing commas", () => {
158
- const root = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-project-"));
159
- fs.writeFileSync(
160
- path.join(root, "tsconfig.json"),
161
- `{
162
- // plugin host configuration may live in JSONC tsconfig files
163
- "compilerOptions": {
164
- "plugins": [
165
- { "transform": "./plugins/jsonc.cjs" },
166
- ],
167
- },
168
- }\n`,
169
- "utf8",
170
- );
171
-
172
- const parsed = readProjectConfig({
173
- tsconfig: path.join(root, "tsconfig.json"),
174
- });
175
- assert.deepEqual(parsed.compilerOptions.plugins, [
176
- { transform: "./plugins/jsonc.cjs" },
177
- ]);
178
- });
179
-
180
- test("readProjectConfig rejects circular tsconfig extends", () => {
181
- const root = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-project-"));
182
- fs.writeFileSync(
183
- path.join(root, "a.json"),
184
- JSON.stringify({ extends: "./b.json" }),
185
- "utf8",
186
- );
187
- fs.writeFileSync(
188
- path.join(root, "b.json"),
189
- JSON.stringify({ extends: "./a.json" }),
190
- "utf8",
191
- );
192
-
193
- assert.throws(
194
- () => readProjectConfig({ tsconfig: path.join(root, "a.json") }),
195
- /circular tsconfig extends detected/,
196
- );
197
- });
@@ -1,45 +0,0 @@
1
- const assert = require("node:assert/strict");
2
- const fs = require("node:fs");
3
- const os = require("node:os");
4
- const path = require("node:path");
5
- const test = require("node:test");
6
-
7
- const {
8
- buildSourcePlugin,
9
- } = require("../lib/plugin/internal/buildSourcePlugin.js");
10
-
11
- test("buildSourcePlugin rejects a source outside a nearby Go module", () => {
12
- const root = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-source-plugin-"));
13
- const source = path.join(root, "a", "b", "c", "d", "cmd");
14
- fs.mkdirSync(source, { recursive: true });
15
-
16
- assert.throws(
17
- () =>
18
- buildSourcePlugin({
19
- baseDir: root,
20
- pluginName: "missing-go-mod",
21
- source,
22
- ttscVersion: "1.0.0",
23
- tsgoVersion: "7.0.0-dev",
24
- }),
25
- /go\.mod within 3 parent directories/,
26
- );
27
- });
28
-
29
- test("buildSourcePlugin rejects non-directory and non-go.mod sources", () => {
30
- const root = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-source-plugin-"));
31
- const source = path.join(root, "plugin.txt");
32
- fs.writeFileSync(source, "not a Go package\n", "utf8");
33
-
34
- assert.throws(
35
- () =>
36
- buildSourcePlugin({
37
- baseDir: root,
38
- pluginName: "bad-source",
39
- source,
40
- ttscVersion: "1.0.0",
41
- tsgoVersion: "7.0.0-dev",
42
- }),
43
- /Go package directory or go\.mod file/,
44
- );
45
- });
package/test/tsgo.test.ts DELETED
@@ -1,69 +0,0 @@
1
- const assert = require("node:assert/strict");
2
- const fs = require("node:fs");
3
- const os = require("node:os");
4
- const path = require("node:path");
5
- const test = require("node:test");
6
- const { resolveTsgo } = require("../lib/compiler/internal/resolveTsgo.js");
7
-
8
- test("resolveTsgo accepts TTSC_TSGO_BINARY as an explicit compiler", () => {
9
- const root = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-tsgo-test-"));
10
- const binary = path.join(root, "tsgo");
11
- fs.writeFileSync(binary, "", "utf8");
12
-
13
- const resolved = resolveTsgo({
14
- env: { TTSC_TSGO_BINARY: binary },
15
- });
16
-
17
- assert.equal(resolved.binary, binary);
18
- assert.equal(resolved.version, "custom");
19
- });
20
-
21
- test("resolveTsgo resolves the consumer native-preview platform package", () => {
22
- const root = fs.mkdtempSync(path.join(os.tmpdir(), "ttsc-tsgo-test-"));
23
- const nativeRoot = path.join(
24
- root,
25
- "node_modules",
26
- "@typescript",
27
- "native-preview",
28
- );
29
- const platformRoot = path.join(
30
- root,
31
- "node_modules",
32
- "@typescript",
33
- `native-preview-${process.platform}-${process.arch}`,
34
- );
35
- fs.mkdirSync(nativeRoot, { recursive: true });
36
- fs.mkdirSync(path.join(platformRoot, "lib"), { recursive: true });
37
- fs.writeFileSync(
38
- path.join(nativeRoot, "package.json"),
39
- JSON.stringify({
40
- name: "@typescript/native-preview",
41
- version: "7.0.0-dev.consumer",
42
- gitHead: "abc123",
43
- }),
44
- "utf8",
45
- );
46
- fs.writeFileSync(
47
- path.join(platformRoot, "package.json"),
48
- JSON.stringify({
49
- name: `@typescript/native-preview-${process.platform}-${process.arch}`,
50
- version: "7.0.0-dev.consumer",
51
- }),
52
- "utf8",
53
- );
54
- const binary = path.join(
55
- platformRoot,
56
- "lib",
57
- process.platform === "win32" ? "tsgo.exe" : "tsgo",
58
- );
59
- fs.writeFileSync(binary, "", "utf8");
60
-
61
- const resolved = resolveTsgo({
62
- cwd: root,
63
- env: {},
64
- });
65
-
66
- assert.equal(resolved.version, "7.0.0-dev.consumer");
67
- assert.equal(resolved.gitHead, "abc123");
68
- assert.equal(resolved.binary, binary);
69
- });