@openload28/tt-lang 1.0.0-dev.20260828.263

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 ADDED
@@ -0,0 +1,106 @@
1
+ # @openload28/tt-lang
2
+
3
+ **tt** is a tiny preprocessor language that compiles to TypeScript. It adds
4
+ Rust-style tagged unions and pattern matching, concise `Option`/`Result`
5
+ control flow, pipelines, and mutation-safe bindings while keeping valid
6
+ TypeScript valid.
7
+
8
+ This package installs `ttc`, the tt compiler, as a prebuilt native binary —
9
+ no Rust toolchain required.
10
+
11
+ For a complete Bun + Vite project, or to add tt to an existing TypeScript
12
+ project, use the initializer instead:
13
+
14
+ ```sh
15
+ bunx @openload28/create-tt@next my-app
16
+ bunx @openload28/create-tt@next init
17
+ ```
18
+
19
+ `ttc` drives TypeScript 7 and takes it from your project's own
20
+ `node_modules` — the same package your build uses, and the only place it
21
+ looks. The TT installer does not add it for you:
22
+
23
+ ```sh
24
+ bun add -d @openload28/tt-lang@next typescript@7.1.0-dev.20260826.1
25
+ ```
26
+
27
+ Declaration output (`ttc --types`, editor `.tt.d.ts` sidecars) and content
28
+ mappers (below) use APIs that arrived in TypeScript 7.1; everything else
29
+ works on 7.0. See the
30
+ [installation guide](https://github.com/load28/tt/blob/main/docs/getting-started.md).
31
+
32
+ ```sh
33
+ bunx ttc -o build src/ # compile a source tree to TypeScript
34
+ bunx ttc --check src/ # check without writing anything
35
+ bunx ttc --types src/ # editor/typecheck declarations
36
+ ```
37
+
38
+ On TypeScript 7.1+, `.ts` files can import `.tt` directly — this package
39
+ is a TypeScript **content mapper**, so the compiler holds the transform
40
+ virtually (no sidecar files). Declare it once in `tsconfig.json` and run
41
+ `tsc` with `--runExternalCode`:
42
+
43
+ ```jsonc
44
+ "contentMappers": [
45
+ { "package": "@openload28/tt-lang", "extensions": [".tt", ".ttx"] }
46
+ ]
47
+ ```
48
+
49
+ Using a bundler? [`@openload28/unplugin-tt`](https://github.com/load28/tt/tree/main/integrations/unplugin)
50
+ reads `.tt` files directly in Vite, Rollup, webpack, Rspack, esbuild and
51
+ Farm, and finds this package's binary automatically.
52
+
53
+ For editor support, download `tt-language-<version>.vsix` from the newest
54
+ [GitHub Releases](https://github.com/load28/tt/releases) pre-release and use
55
+ **Extensions: Install from VSIX...** in VS Code.
56
+
57
+ ## Supported platforms
58
+
59
+ Prebuilt binaries ship as optional dependencies; npm installs the one
60
+ matching your machine.
61
+
62
+ | Package | OS | CPU |
63
+ |---------|----|----|
64
+ | `@openload28/tt-lang-linux-x64` | Linux | x64 (static musl build) |
65
+ | `@openload28/tt-lang-linux-arm64` | Linux | arm64 (static musl build) |
66
+ | `@openload28/tt-lang-darwin-x64` | macOS | x64 |
67
+ | `@openload28/tt-lang-darwin-arm64` | macOS | arm64 |
68
+ | `@openload28/tt-lang-win32-x64-msvc` | Windows | x64 (MSVC) |
69
+
70
+ On other platforms, build from source
71
+ (`cargo install --git https://github.com/load28/tt`) and set the
72
+ `TTC_BINARY` environment variable to the resulting binary.
73
+
74
+ ## API
75
+
76
+ The package exports one helper for tools that want to spawn the compiler
77
+ directly:
78
+
79
+ ```js
80
+ const { binaryPath } = require("@openload28/tt-lang");
81
+ binaryPath(); // absolute path to the ttc binary for this platform
82
+ ```
83
+
84
+ ## Local development install
85
+
86
+ In a checkout of the [tt repository](https://github.com/load28/tt),
87
+ `./scripts/setup` stamps this directory for local installs. A project can
88
+ then use the work-in-progress compiler like any other dependency:
89
+
90
+ ```sh
91
+ pnpm add -D file:/path/to/tt/npm/tt-lang
92
+ ```
93
+
94
+ The launcher runs the repository's `target/release/ttc`; TypeScript still
95
+ comes from the consuming project, exactly as it does for a published
96
+ install. Published installs are unaffected (the stamp file is not committed
97
+ or published).
98
+
99
+ ## Documentation
100
+
101
+ Language reference, CLI options, standard library and error index:
102
+ <https://github.com/load28/tt#readme>.
103
+
104
+ ## License
105
+
106
+ MIT
package/bin/ttc.js ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ /* --------------------------------------------------------------------------
3
+ * `ttc` launcher — thin veneer over the native binary from the platform
4
+ * package. All arguments, stdio and the exit code pass through untouched,
5
+ * so `npx ttc` behaves exactly like a natively installed ttc.
6
+ *
7
+ * In a local development install (`scripts/setup` in the TT repository,
8
+ * then `pnpm add -D file:.../npm/tt-lang`) the binary is the repository's
9
+ * release build instead (dev.js). Nothing else differs: TypeScript comes
10
+ * from the consuming project either way.
11
+ * ----------------------------------------------------------------------- */
12
+ "use strict";
13
+
14
+ const { spawnSync } = require("node:child_process");
15
+
16
+ const { binaryPath } = require("../index.js");
17
+ const { devEnvironment } = require("../dev.js");
18
+
19
+ let binary;
20
+ try {
21
+ // TTC_BINARY stays the strongest override, exactly as in binaryPath().
22
+ const dev = process.env.TTC_BINARY ? null : devEnvironment();
23
+ binary = dev ? dev.binary : binaryPath();
24
+ } catch (error) {
25
+ console.error(error.message);
26
+ process.exit(1);
27
+ }
28
+
29
+ const result = spawnSync(binary, process.argv.slice(2), { stdio: "inherit" });
30
+ if (result.error) {
31
+ console.error(`ttc: failed to run ${binary}: ${result.error.message}`);
32
+ process.exit(1);
33
+ }
34
+ if (result.signal) {
35
+ // Re-raise so the parent observes the same termination signal.
36
+ process.kill(process.pid, result.signal);
37
+ }
38
+ process.exit(result.status ?? 1);
package/dev.js ADDED
@@ -0,0 +1,63 @@
1
+ /* --------------------------------------------------------------------------
2
+ * @openload28/tt-lang local development mode — created by `scripts/setup` in the TT
3
+ * repository, absent from published installs.
4
+ *
5
+ * `tt-dev.local.json` beside this file (written by setup, gitignored) marks
6
+ * the package as a local `file:` install and names the TT repository root,
7
+ * from which the one thing this layer supplies is derived:
8
+ *
9
+ * ttc <root>/target/release/ttc (the release build)
10
+ *
11
+ * TypeScript is *not* part of it: ttc resolves TypeScript 7 from the
12
+ * consuming project's own `node_modules`, and there is no second way to
13
+ * name one (`src/typescript/toolchain.rs`). A development install differs
14
+ * from a published one in which ttc runs, and in nothing else.
15
+ *
16
+ * This whole layer is temporary (docs/tasks/TASK-090): once TT ships a
17
+ * verified TypeScript inside its own package, delete this module together
18
+ * with scripts/setup and .tt-dev/.
19
+ * ----------------------------------------------------------------------- */
20
+ "use strict";
21
+
22
+ const fs = require("node:fs");
23
+ const path = require("node:path");
24
+
25
+ const DEV_CONFIG = path.join(__dirname, "tt-dev.local.json");
26
+
27
+ /** The parsed JSON object of `file`, or null when missing/unreadable. */
28
+ function readConfig(file) {
29
+ try {
30
+ const parsed = JSON.parse(fs.readFileSync(file, "utf8"));
31
+ return parsed && typeof parsed === "object" ? parsed : null;
32
+ } catch {
33
+ return null;
34
+ }
35
+ }
36
+
37
+ /**
38
+ * The local development environment `scripts/setup` configured, or null when
39
+ * this is a regular published install (no `tt-dev.local.json`).
40
+ *
41
+ * Throws when the config exists but the binary it names is gone — running
42
+ * some other ttc silently would be worse than failing with the fix.
43
+ *
44
+ * @returns {{ binary: string } | null}
45
+ */
46
+ function devEnvironment() {
47
+ const config = readConfig(DEV_CONFIG);
48
+ const root = config && typeof config.root === "string" ? config.root : null;
49
+ if (root === null) return null;
50
+
51
+ const exe = process.platform === "win32" ? "ttc.exe" : "ttc";
52
+ const binary = path.join(root, "target", "release", exe);
53
+ if (!fs.existsSync(binary)) {
54
+ throw new Error(
55
+ `@openload28/tt-lang: this is a local development install (${DEV_CONFIG}), ` +
56
+ `but ${binary} does not exist. Run ./scripts/setup in ${root}, ` +
57
+ `then reinstall this package.`,
58
+ );
59
+ }
60
+ return { binary };
61
+ }
62
+
63
+ module.exports = { devEnvironment };
package/index.js ADDED
@@ -0,0 +1,64 @@
1
+ /* --------------------------------------------------------------------------
2
+ * @openload28/tt-lang — locate the platform-specific ttc binary.
3
+ *
4
+ * The actual compiler ships in per-platform packages (@openload28/tt-lang-linux-x64,
5
+ * @openload28/tt-lang-darwin-arm64, ...) wired up as optionalDependencies: npm installs
6
+ * only the one matching the host. This module finds that binary so tools
7
+ * (the `ttc` bin launcher, @openload28/unplugin-tt, editor servers) can spawn it
8
+ * directly without paying for an extra node process per call.
9
+ * ----------------------------------------------------------------------- */
10
+ "use strict";
11
+
12
+ const path = require("node:path");
13
+ const PLATFORMS = require("./platforms.json");
14
+
15
+ /** Platforms a prebuilt ttc binary is published for. */
16
+ const SUPPORTED = Object.keys(PLATFORMS);
17
+
18
+ /** `"linux-x64"`-style key for the current process, supported or not. */
19
+ function platformKey() {
20
+ return `${process.platform}-${process.arch}`;
21
+ }
22
+
23
+ /** npm package containing the binary for a platform key. */
24
+ function platformPackageName(key) {
25
+ return PLATFORMS[key]?.package;
26
+ }
27
+
28
+ /**
29
+ * Absolute path to the ttc binary for this platform.
30
+ *
31
+ * Resolution order: the `TTC_BINARY` environment variable (escape hatch for
32
+ * local builds and tests), then a local development install (`scripts/setup`
33
+ * in the TT repository — see dev.js), then the installed platform package.
34
+ * Throws with install guidance when none is available.
35
+ *
36
+ * @returns {string}
37
+ */
38
+ function binaryPath() {
39
+ const override = process.env.TTC_BINARY;
40
+ if (override) return path.resolve(override);
41
+
42
+ const dev = require("./dev.js").devEnvironment();
43
+ if (dev) return dev.binary;
44
+
45
+ const key = platformKey();
46
+ const exe = process.platform === "win32" ? "ttc.exe" : "ttc";
47
+ const pkg = platformPackageName(key);
48
+ try {
49
+ return require.resolve(`${pkg}/bin/${exe}`);
50
+ } catch {
51
+ const reason = pkg
52
+ ? `the ${pkg} package is not installed — it is an optionalDependency of @openload28/tt-lang, ` +
53
+ `so this usually means optional dependencies were disabled (--no-optional / ` +
54
+ `--omit=optional) or the lockfile was created on a different platform. ` +
55
+ `Reinstalling @openload28/tt-lang should fix it.`
56
+ : `no prebuilt ttc binary is published for ${key}. Prebuilt platforms: ` +
57
+ `${SUPPORTED.join(", ")}. You can build from source with ` +
58
+ `"cargo install --git https://github.com/load28/tt" and point the ` +
59
+ `TTC_BINARY environment variable at the resulting binary.`;
60
+ throw new Error(`@openload28/tt-lang: cannot find the ttc binary: ${reason}`);
61
+ }
62
+ }
63
+
64
+ module.exports = { binaryPath, platformKey, platformPackageName };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@openload28/tt-lang",
3
+ "version": "1.0.0-dev.20260828.263",
4
+ "description": "tt — a tiny TypeScript preprocessor adding Rust-style variants, match expressions, try, let-else, if let and the pipeline operator. Installs the ttc compiler.",
5
+ "license": "MIT",
6
+ "bin": {
7
+ "ttc": "bin/ttc.js"
8
+ },
9
+ "main": "index.js",
10
+ "typescript": {
11
+ "contentMapper": {
12
+ "exec": [
13
+ "node",
14
+ "bin/ttc.js",
15
+ "--content-mapper"
16
+ ]
17
+ }
18
+ },
19
+ "files": [
20
+ "bin/ttc.js",
21
+ "index.js",
22
+ "platforms.json",
23
+ "dev.js",
24
+ "tt-dev.local.json",
25
+ "README.md"
26
+ ],
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/load28/tt",
30
+ "directory": "npm/tt-lang"
31
+ },
32
+ "homepage": "https://github.com/load28/tt#readme",
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "registry": "https://registry.npmjs.org/"
36
+ },
37
+ "keywords": [
38
+ "typescript",
39
+ "compiler",
40
+ "preprocessor",
41
+ "tagged-union",
42
+ "pattern-matching",
43
+ "match",
44
+ "tt"
45
+ ],
46
+ "engines": {
47
+ "node": ">=18"
48
+ },
49
+ "optionalDependencies": {
50
+ "@openload28/tt-lang-linux-x64": "1.0.0-dev.20260828.263",
51
+ "@openload28/tt-lang-linux-arm64": "1.0.0-dev.20260828.263",
52
+ "@openload28/tt-lang-darwin-x64": "1.0.0-dev.20260828.263",
53
+ "@openload28/tt-lang-darwin-arm64": "1.0.0-dev.20260828.263",
54
+ "@openload28/tt-lang-win32-x64-msvc": "1.0.0-dev.20260828.263"
55
+ }
56
+ }
package/platforms.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "linux-x64": {
3
+ "package": "@openload28/tt-lang-linux-x64",
4
+ "os": "linux",
5
+ "cpu": "x64"
6
+ },
7
+ "linux-arm64": {
8
+ "package": "@openload28/tt-lang-linux-arm64",
9
+ "os": "linux",
10
+ "cpu": "arm64"
11
+ },
12
+ "darwin-x64": {
13
+ "package": "@openload28/tt-lang-darwin-x64",
14
+ "os": "darwin",
15
+ "cpu": "x64"
16
+ },
17
+ "darwin-arm64": {
18
+ "package": "@openload28/tt-lang-darwin-arm64",
19
+ "os": "darwin",
20
+ "cpu": "arm64"
21
+ },
22
+ "win32-x64": {
23
+ "package": "@openload28/tt-lang-win32-x64-msvc",
24
+ "os": "win32",
25
+ "cpu": "x64"
26
+ }
27
+ }