tsonic 0.0.1 → 0.0.12

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 (79) hide show
  1. package/README.md +21 -0
  2. package/bin.js +17 -0
  3. package/package.json +16 -29
  4. package/dist/cli/constants.d.ts +0 -5
  5. package/dist/cli/constants.d.ts.map +0 -1
  6. package/dist/cli/constants.js +0 -5
  7. package/dist/cli/constants.js.map +0 -1
  8. package/dist/cli/dispatcher.d.ts +0 -8
  9. package/dist/cli/dispatcher.d.ts.map +0 -1
  10. package/dist/cli/dispatcher.js +0 -98
  11. package/dist/cli/dispatcher.js.map +0 -1
  12. package/dist/cli/help.d.ts +0 -8
  13. package/dist/cli/help.d.ts.map +0 -1
  14. package/dist/cli/help.js +0 -48
  15. package/dist/cli/help.js.map +0 -1
  16. package/dist/cli/index.d.ts +0 -8
  17. package/dist/cli/index.d.ts.map +0 -1
  18. package/dist/cli/index.js +0 -8
  19. package/dist/cli/index.js.map +0 -1
  20. package/dist/cli/parser.d.ts +0 -14
  21. package/dist/cli/parser.d.ts.map +0 -1
  22. package/dist/cli/parser.js +0 -94
  23. package/dist/cli/parser.js.map +0 -1
  24. package/dist/cli/parser.test.d.ts +0 -5
  25. package/dist/cli/parser.test.d.ts.map +0 -1
  26. package/dist/cli/parser.test.js +0 -221
  27. package/dist/cli/parser.test.js.map +0 -1
  28. package/dist/cli.d.ts +0 -6
  29. package/dist/cli.d.ts.map +0 -1
  30. package/dist/cli.js +0 -6
  31. package/dist/cli.js.map +0 -1
  32. package/dist/commands/build.d.ts +0 -11
  33. package/dist/commands/build.d.ts.map +0 -1
  34. package/dist/commands/build.js +0 -99
  35. package/dist/commands/build.js.map +0 -1
  36. package/dist/commands/emit.d.ts +0 -12
  37. package/dist/commands/emit.d.ts.map +0 -1
  38. package/dist/commands/emit.js +0 -170
  39. package/dist/commands/emit.js.map +0 -1
  40. package/dist/commands/init.d.ts +0 -14
  41. package/dist/commands/init.d.ts.map +0 -1
  42. package/dist/commands/init.js +0 -217
  43. package/dist/commands/init.js.map +0 -1
  44. package/dist/commands/run.d.ts +0 -11
  45. package/dist/commands/run.d.ts.map +0 -1
  46. package/dist/commands/run.js +0 -40
  47. package/dist/commands/run.js.map +0 -1
  48. package/dist/config.d.ts +0 -17
  49. package/dist/config.d.ts.map +0 -1
  50. package/dist/config.js +0 -84
  51. package/dist/config.js.map +0 -1
  52. package/dist/config.test.d.ts +0 -5
  53. package/dist/config.test.d.ts.map +0 -1
  54. package/dist/config.test.js +0 -274
  55. package/dist/config.test.js.map +0 -1
  56. package/dist/index.d.ts +0 -8
  57. package/dist/index.d.ts.map +0 -1
  58. package/dist/index.js +0 -20
  59. package/dist/index.js.map +0 -1
  60. package/dist/types.d.ts +0 -74
  61. package/dist/types.d.ts.map +0 -1
  62. package/dist/types.js +0 -5
  63. package/dist/types.js.map +0 -1
  64. package/src/cli/constants.ts +0 -5
  65. package/src/cli/dispatcher.ts +0 -115
  66. package/src/cli/help.ts +0 -49
  67. package/src/cli/index.ts +0 -8
  68. package/src/cli/parser.test.ts +0 -259
  69. package/src/cli/parser.ts +0 -109
  70. package/src/cli.ts +0 -6
  71. package/src/commands/build.ts +0 -125
  72. package/src/commands/emit.ts +0 -222
  73. package/src/commands/init.ts +0 -272
  74. package/src/commands/run.ts +0 -51
  75. package/src/config.test.ts +0 -328
  76. package/src/config.ts +0 -105
  77. package/src/index.ts +0 -23
  78. package/src/types.ts +0 -74
  79. package/tsconfig.json +0 -18
@@ -1,328 +0,0 @@
1
- /**
2
- * Tests for configuration loading and resolution
3
- */
4
-
5
- import { describe, it } from "mocha";
6
- import { expect } from "chai";
7
- import { resolveConfig } from "./config.js";
8
- import type { TsonicConfig, CliOptions } from "./types.js";
9
-
10
- describe("Config", () => {
11
- describe("resolveConfig", () => {
12
- it("should use config values as defaults", () => {
13
- const config: TsonicConfig = {
14
- rootNamespace: "MyApp",
15
- entryPoint: "src/main.ts",
16
- sourceRoot: "src",
17
- outputDirectory: "dist",
18
- outputName: "myapp",
19
- rid: "linux-x64",
20
- dotnetVersion: "net10.0",
21
- optimize: "speed",
22
- };
23
-
24
- const result = resolveConfig(config, {});
25
- expect(result.rootNamespace).to.equal("MyApp");
26
- expect(result.entryPoint).to.equal("src/main.ts");
27
- expect(result.sourceRoot).to.equal("src");
28
- expect(result.outputDirectory).to.equal("dist");
29
- expect(result.outputName).to.equal("myapp");
30
- expect(result.rid).to.equal("linux-x64");
31
- expect(result.dotnetVersion).to.equal("net10.0");
32
- expect(result.optimize).to.equal("speed");
33
- });
34
-
35
- it("should override config with CLI options", () => {
36
- const config: TsonicConfig = {
37
- rootNamespace: "MyApp",
38
- outputName: "myapp",
39
- };
40
-
41
- const cliOptions: CliOptions = {
42
- namespace: "OverriddenApp",
43
- out: "custom",
44
- src: "source",
45
- optimize: "size",
46
- };
47
-
48
- const result = resolveConfig(config, cliOptions);
49
- expect(result.rootNamespace).to.equal("OverriddenApp");
50
- expect(result.outputName).to.equal("custom");
51
- expect(result.sourceRoot).to.equal("source");
52
- expect(result.optimize).to.equal("size");
53
- });
54
-
55
- it("should use entry file parameter over config", () => {
56
- const config: TsonicConfig = {
57
- rootNamespace: "MyApp",
58
- entryPoint: "src/main.ts",
59
- };
60
-
61
- const result = resolveConfig(config, {}, "custom/entry.ts");
62
- expect(result.entryPoint).to.equal("custom/entry.ts");
63
- });
64
-
65
- it("should default entryPoint to src/main.ts", () => {
66
- const config: TsonicConfig = {
67
- rootNamespace: "MyApp",
68
- };
69
-
70
- const result = resolveConfig(config, {});
71
- expect(result.entryPoint).to.equal("src/main.ts");
72
- });
73
-
74
- it("should default sourceRoot to dirname of entryPoint", () => {
75
- const config: TsonicConfig = {
76
- rootNamespace: "MyApp",
77
- entryPoint: "app/index.ts",
78
- };
79
-
80
- const result = resolveConfig(config, {});
81
- expect(result.sourceRoot).to.equal("app");
82
- });
83
-
84
- it("should default outputDirectory to 'generated'", () => {
85
- const config: TsonicConfig = {
86
- rootNamespace: "MyApp",
87
- };
88
-
89
- const result = resolveConfig(config, {});
90
- expect(result.outputDirectory).to.equal("generated");
91
- });
92
-
93
- it("should default outputName to 'app'", () => {
94
- const config: TsonicConfig = {
95
- rootNamespace: "MyApp",
96
- };
97
-
98
- const result = resolveConfig(config, {});
99
- expect(result.outputName).to.equal("app");
100
- });
101
-
102
- it("should default dotnetVersion to 'net10.0'", () => {
103
- const config: TsonicConfig = {
104
- rootNamespace: "MyApp",
105
- };
106
-
107
- const result = resolveConfig(config, {});
108
- expect(result.dotnetVersion).to.equal("net10.0");
109
- });
110
-
111
- it("should default optimize to 'speed'", () => {
112
- const config: TsonicConfig = {
113
- rootNamespace: "MyApp",
114
- };
115
-
116
- const result = resolveConfig(config, {});
117
- expect(result.optimize).to.equal("speed");
118
- });
119
-
120
- it("should default packages to empty array", () => {
121
- const config: TsonicConfig = {
122
- rootNamespace: "MyApp",
123
- };
124
-
125
- const result = resolveConfig(config, {});
126
- expect(result.packages).to.deep.equal([]);
127
- });
128
-
129
- it("should include packages from config", () => {
130
- const config: TsonicConfig = {
131
- rootNamespace: "MyApp",
132
- packages: [
133
- { name: "System.Text.Json", version: "8.0.0" },
134
- { name: "Newtonsoft.Json", version: "13.0.3" },
135
- ],
136
- };
137
-
138
- const result = resolveConfig(config, {});
139
- expect(result.packages).to.deep.equal([
140
- { name: "System.Text.Json", version: "8.0.0" },
141
- { name: "Newtonsoft.Json", version: "13.0.3" },
142
- ]);
143
- });
144
-
145
- it("should default stripSymbols to true", () => {
146
- const config: TsonicConfig = {
147
- rootNamespace: "MyApp",
148
- };
149
-
150
- const result = resolveConfig(config, {});
151
- expect(result.stripSymbols).to.equal(true);
152
- });
153
-
154
- it("should use buildOptions.stripSymbols from config", () => {
155
- const config: TsonicConfig = {
156
- rootNamespace: "MyApp",
157
- buildOptions: {
158
- stripSymbols: false,
159
- },
160
- };
161
-
162
- const result = resolveConfig(config, {});
163
- expect(result.stripSymbols).to.equal(false);
164
- });
165
-
166
- it("should override stripSymbols with --no-strip CLI option", () => {
167
- const config: TsonicConfig = {
168
- rootNamespace: "MyApp",
169
- buildOptions: {
170
- stripSymbols: true,
171
- },
172
- };
173
-
174
- const result = resolveConfig(config, { noStrip: true });
175
- expect(result.stripSymbols).to.equal(false);
176
- });
177
-
178
- it("should default invariantGlobalization to true", () => {
179
- const config: TsonicConfig = {
180
- rootNamespace: "MyApp",
181
- };
182
-
183
- const result = resolveConfig(config, {});
184
- expect(result.invariantGlobalization).to.equal(true);
185
- });
186
-
187
- it("should use buildOptions.invariantGlobalization from config", () => {
188
- const config: TsonicConfig = {
189
- rootNamespace: "MyApp",
190
- buildOptions: {
191
- invariantGlobalization: false,
192
- },
193
- };
194
-
195
- const result = resolveConfig(config, {});
196
- expect(result.invariantGlobalization).to.equal(false);
197
- });
198
-
199
- it("should default keepTemp to false", () => {
200
- const config: TsonicConfig = {
201
- rootNamespace: "MyApp",
202
- };
203
-
204
- const result = resolveConfig(config, {});
205
- expect(result.keepTemp).to.equal(false);
206
- });
207
-
208
- it("should set keepTemp from CLI option", () => {
209
- const config: TsonicConfig = {
210
- rootNamespace: "MyApp",
211
- };
212
-
213
- const result = resolveConfig(config, { keepTemp: true });
214
- expect(result.keepTemp).to.equal(true);
215
- });
216
-
217
- it("should default verbose to false", () => {
218
- const config: TsonicConfig = {
219
- rootNamespace: "MyApp",
220
- };
221
-
222
- const result = resolveConfig(config, {});
223
- expect(result.verbose).to.equal(false);
224
- });
225
-
226
- it("should set verbose from CLI option", () => {
227
- const config: TsonicConfig = {
228
- rootNamespace: "MyApp",
229
- };
230
-
231
- const result = resolveConfig(config, { verbose: true });
232
- expect(result.verbose).to.equal(true);
233
- });
234
-
235
- it("should default quiet to false", () => {
236
- const config: TsonicConfig = {
237
- rootNamespace: "MyApp",
238
- };
239
-
240
- const result = resolveConfig(config, {});
241
- expect(result.quiet).to.equal(false);
242
- });
243
-
244
- it("should set quiet from CLI option", () => {
245
- const config: TsonicConfig = {
246
- rootNamespace: "MyApp",
247
- };
248
-
249
- const result = resolveConfig(config, { quiet: true });
250
- expect(result.quiet).to.equal(true);
251
- });
252
-
253
- it("should default typeRoots to node_modules/@tsonic/dotnet-types/types", () => {
254
- const config: TsonicConfig = {
255
- rootNamespace: "MyApp",
256
- };
257
-
258
- const result = resolveConfig(config, {});
259
- expect(result.typeRoots).to.deep.equal([
260
- "node_modules/@tsonic/dotnet-types/types",
261
- ]);
262
- });
263
-
264
- it("should use typeRoots from config.dotnet.typeRoots", () => {
265
- const config: TsonicConfig = {
266
- rootNamespace: "MyApp",
267
- dotnet: {
268
- typeRoots: ["custom/path/types", "another/path/types"],
269
- },
270
- };
271
-
272
- const result = resolveConfig(config, {});
273
- expect(result.typeRoots).to.deep.equal([
274
- "custom/path/types",
275
- "another/path/types",
276
- ]);
277
- });
278
-
279
- it("should handle all options together", () => {
280
- const config: TsonicConfig = {
281
- rootNamespace: "MyApp",
282
- entryPoint: "src/index.ts",
283
- sourceRoot: "src",
284
- outputDirectory: "out",
285
- outputName: "program",
286
- rid: "linux-x64",
287
- dotnetVersion: "net9.0",
288
- optimize: "size",
289
- packages: [{ name: "Package.Name", version: "1.0.0" }],
290
- buildOptions: {
291
- stripSymbols: false,
292
- invariantGlobalization: false,
293
- },
294
- };
295
-
296
- const cliOptions: CliOptions = {
297
- namespace: "CLI.Override",
298
- src: "source",
299
- out: "binary",
300
- rid: "win-x64",
301
- optimize: "speed",
302
- noStrip: true,
303
- keepTemp: true,
304
- verbose: true,
305
- quiet: false,
306
- };
307
-
308
- const result = resolveConfig(config, cliOptions, "custom.ts");
309
-
310
- expect(result.rootNamespace).to.equal("CLI.Override");
311
- expect(result.entryPoint).to.equal("custom.ts");
312
- expect(result.sourceRoot).to.equal("source");
313
- expect(result.outputDirectory).to.equal("out");
314
- expect(result.outputName).to.equal("binary");
315
- expect(result.rid).to.equal("win-x64");
316
- expect(result.dotnetVersion).to.equal("net9.0");
317
- expect(result.optimize).to.equal("speed");
318
- expect(result.packages).to.deep.equal([
319
- { name: "Package.Name", version: "1.0.0" },
320
- ]);
321
- expect(result.stripSymbols).to.equal(false);
322
- expect(result.invariantGlobalization).to.equal(false);
323
- expect(result.keepTemp).to.equal(true);
324
- expect(result.verbose).to.equal(true);
325
- expect(result.quiet).to.equal(false);
326
- });
327
- });
328
- });
package/src/config.ts DELETED
@@ -1,105 +0,0 @@
1
- /**
2
- * Configuration loading and validation
3
- */
4
-
5
- import { readFileSync, existsSync } from "node:fs";
6
- import { join, resolve, dirname } from "node:path";
7
- import { detectRid } from "@tsonic/backend";
8
- import type {
9
- TsonicConfig,
10
- CliOptions,
11
- ResolvedConfig,
12
- Result,
13
- } from "./types.js";
14
-
15
- /**
16
- * Load tsonic.json from a directory
17
- */
18
- export const loadConfig = (
19
- configPath: string
20
- ): Result<TsonicConfig, string> => {
21
- if (!existsSync(configPath)) {
22
- return {
23
- ok: false,
24
- error: `Config file not found: ${configPath}`,
25
- };
26
- }
27
-
28
- try {
29
- const content = readFileSync(configPath, "utf-8");
30
- const config = JSON.parse(content) as TsonicConfig;
31
-
32
- // Validate required fields
33
- if (!config.rootNamespace) {
34
- return {
35
- ok: false,
36
- error: "tsonic.json: 'rootNamespace' is required",
37
- };
38
- }
39
-
40
- return { ok: true, value: config };
41
- } catch (error) {
42
- return {
43
- ok: false,
44
- error: `Failed to parse tsonic.json: ${error instanceof Error ? error.message : String(error)}`,
45
- };
46
- }
47
- };
48
-
49
- /**
50
- * Find tsonic.json by walking up the directory tree
51
- */
52
- export const findConfig = (startDir: string): string | null => {
53
- let currentDir = resolve(startDir);
54
-
55
- // Walk up until we find tsonic.json or hit root
56
- while (true) {
57
- const configPath = join(currentDir, "tsonic.json");
58
- if (existsSync(configPath)) {
59
- return configPath;
60
- }
61
-
62
- const parentDir = dirname(currentDir);
63
- if (parentDir === currentDir) {
64
- // Hit root
65
- return null;
66
- }
67
- currentDir = parentDir;
68
- }
69
- };
70
-
71
- /**
72
- * Resolve final configuration from file + CLI args
73
- */
74
- export const resolveConfig = (
75
- config: TsonicConfig,
76
- cliOptions: CliOptions,
77
- entryFile?: string
78
- ): ResolvedConfig => {
79
- const entryPoint = entryFile ?? config.entryPoint ?? "src/main.ts";
80
- const sourceRoot = cliOptions.src ?? config.sourceRoot ?? dirname(entryPoint);
81
-
82
- // Default type roots: node_modules/@tsonic/dotnet-types/types
83
- const defaultTypeRoots = ["node_modules/@tsonic/dotnet-types/types"];
84
- const typeRoots = config.dotnet?.typeRoots ?? defaultTypeRoots;
85
-
86
- return {
87
- rootNamespace: cliOptions.namespace ?? config.rootNamespace,
88
- entryPoint,
89
- sourceRoot,
90
- outputDirectory: config.outputDirectory ?? "generated",
91
- outputName: cliOptions.out ?? config.outputName ?? "app",
92
- rid: cliOptions.rid ?? config.rid ?? detectRid(),
93
- dotnetVersion: config.dotnetVersion ?? "net10.0",
94
- optimize: cliOptions.optimize ?? config.optimize ?? "speed",
95
- packages: config.dotnet?.packages ?? config.packages ?? [],
96
- stripSymbols: cliOptions.noStrip
97
- ? false
98
- : (config.buildOptions?.stripSymbols ?? true),
99
- invariantGlobalization: config.buildOptions?.invariantGlobalization ?? true,
100
- keepTemp: cliOptions.keepTemp ?? false,
101
- verbose: cliOptions.verbose ?? false,
102
- quiet: cliOptions.quiet ?? false,
103
- typeRoots,
104
- };
105
- };
package/src/index.ts DELETED
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Tsonic CLI - Command-line interface for Tsonic compiler
4
- */
5
-
6
- import { runCli } from "./cli.js";
7
-
8
- // Run CLI with arguments (skip node and script name)
9
- const args = process.argv.slice(2);
10
-
11
- runCli(args)
12
- .then((exitCode) => {
13
- process.exit(exitCode);
14
- })
15
- .catch((error) => {
16
- console.error("Fatal error:", error);
17
- process.exit(1);
18
- });
19
-
20
- // Export for testing
21
- export { runCli } from "./cli.js";
22
- export * from "./types.js";
23
- export * from "./config.js";
package/src/types.ts DELETED
@@ -1,74 +0,0 @@
1
- /**
2
- * Type definitions for CLI
3
- */
4
-
5
- import type { NuGetPackage } from "@tsonic/backend";
6
-
7
- /**
8
- * Tsonic configuration file (tsonic.json)
9
- */
10
- export type TsonicConfig = {
11
- readonly $schema?: string;
12
- readonly rootNamespace: string;
13
- readonly entryPoint?: string;
14
- readonly sourceRoot?: string;
15
- readonly outputDirectory?: string;
16
- readonly outputName?: string;
17
- readonly rid?: string;
18
- readonly dotnetVersion?: string;
19
- readonly optimize?: "size" | "speed";
20
- readonly packages?: readonly NuGetPackage[]; // Deprecated - use dotnet.packages
21
- readonly buildOptions?: {
22
- readonly stripSymbols?: boolean;
23
- readonly invariantGlobalization?: boolean;
24
- };
25
- readonly dotnet?: {
26
- readonly typeRoots?: readonly string[];
27
- readonly packages?: readonly NuGetPackage[];
28
- };
29
- };
30
-
31
- /**
32
- * CLI command options (mutable for parsing)
33
- */
34
- export type CliOptions = {
35
- verbose?: boolean;
36
- quiet?: boolean;
37
- config?: string;
38
- src?: string;
39
- out?: string;
40
- namespace?: string;
41
- rid?: string;
42
- optimize?: "size" | "speed";
43
- keepTemp?: boolean;
44
- noStrip?: boolean;
45
- packages?: string;
46
- };
47
-
48
- /**
49
- * Combined configuration (from file + CLI args)
50
- */
51
- export type ResolvedConfig = {
52
- readonly rootNamespace: string;
53
- readonly entryPoint: string;
54
- readonly sourceRoot: string;
55
- readonly outputDirectory: string;
56
- readonly outputName: string;
57
- readonly rid: string;
58
- readonly dotnetVersion: string;
59
- readonly optimize: "size" | "speed";
60
- readonly packages: readonly NuGetPackage[];
61
- readonly stripSymbols: boolean;
62
- readonly invariantGlobalization: boolean;
63
- readonly keepTemp: boolean;
64
- readonly verbose: boolean;
65
- readonly quiet: boolean;
66
- readonly typeRoots: readonly string[];
67
- };
68
-
69
- /**
70
- * Result type for operations
71
- */
72
- export type Result<T, E> =
73
- | { readonly ok: true; readonly value: T }
74
- | { readonly ok: false; readonly error: E };
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./src",
6
- "composite": true,
7
- "declaration": true,
8
- "declarationMap": true,
9
- "tsBuildInfoFile": "./dist/.tsbuildinfo"
10
- },
11
- "include": ["src/**/*.ts"],
12
- "exclude": ["node_modules", "dist"],
13
- "references": [
14
- { "path": "../frontend" },
15
- { "path": "../emitter" },
16
- { "path": "../backend" }
17
- ]
18
- }