@titanpl/cli 7.0.0-beta → 7.0.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/package.json +4 -4
- package/src/commands/build-ext.js +17 -4
- package/templates/common/_tanfig.json +4 -2
- package/templates/extension/README_WASM.md +38 -0
- package/templates/extension/package.json +2 -2
- package/templates/js/package.json +8 -8
- package/templates/rust-js/package.json +5 -5
- package/templates/rust-ts/package.json +5 -5
- package/templates/ts/package.json +8 -8
- package/templates/extension/README.md +0 -69
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@titanpl/cli",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "The unified CLI for Titan Planet. Use it to create, manage, build, and deploy high-performance backend projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"titanpl",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"tit": "./index.js"
|
|
30
30
|
},
|
|
31
31
|
"optionalDependencies": {
|
|
32
|
-
"@titanpl/engine-win32-x64": "7.0.
|
|
33
|
-
"@titanpl/engine-linux-x64": "7.0.
|
|
32
|
+
"@titanpl/engine-win32-x64": "7.0.1",
|
|
33
|
+
"@titanpl/engine-linux-x64": "7.0.1"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@titanpl/packet": "7.0.
|
|
36
|
+
"@titanpl/packet": "7.0.1",
|
|
37
37
|
"prompts": "^2.4.2",
|
|
38
38
|
"commander": "^11.0.0",
|
|
39
39
|
"chalk": "^4.1.2"
|
|
@@ -38,10 +38,23 @@ async function buildWasmExtension(titanJson) {
|
|
|
38
38
|
try {
|
|
39
39
|
// We assume wasm-pack or similar is used, or just bare cargo with wasm32 target
|
|
40
40
|
// The spec mentions: native/pkg/my_ext.wasm, which is wasm-pack's default
|
|
41
|
-
|
|
41
|
+
console.log(chalk.gray(" Running wasm-pack..."));
|
|
42
|
+
execSync('wasm-pack build --target web --no-typescript', { cwd: nativeDir, stdio: 'ignore' });
|
|
42
43
|
} catch (err) {
|
|
43
|
-
console.log(chalk.
|
|
44
|
-
|
|
44
|
+
console.log(chalk.yellow("! wasm-pack failed, attempting raw cargo build..."));
|
|
45
|
+
try {
|
|
46
|
+
execSync('cargo build --target wasm32-unknown-unknown --release', { cwd: nativeDir, stdio: 'ignore' });
|
|
47
|
+
const pkgDir = path.join(nativeDir, 'pkg');
|
|
48
|
+
if (!fs.existsSync(pkgDir)) fs.mkdirSync(pkgDir);
|
|
49
|
+
|
|
50
|
+
const targetWasm = path.join(nativeDir, `target/wasm32-unknown-unknown/release/${crateName}.wasm`);
|
|
51
|
+
const destWasm = path.join(pkgDir, `${crateName}_bg.wasm`);
|
|
52
|
+
fs.copyFileSync(targetWasm, destWasm);
|
|
53
|
+
console.log(chalk.green("✔ Raw Wasm compilation successful."));
|
|
54
|
+
} catch (cargoErr) {
|
|
55
|
+
console.log(chalk.red("✖ Wasm compilation failed. Make sure Rust and wasm32-unknown-unknown target are installed."));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
45
58
|
}
|
|
46
59
|
|
|
47
60
|
console.log(chalk.gray(" Generating bindings..."));
|
|
@@ -95,7 +108,7 @@ async function buildNativeExtension(titanJson) {
|
|
|
95
108
|
|
|
96
109
|
console.log(chalk.gray(" Compiling Rust native library..."));
|
|
97
110
|
try {
|
|
98
|
-
execSync('cargo build --release', { cwd: nativeDir, stdio: '
|
|
111
|
+
execSync('cargo build --release', { cwd: nativeDir, stdio: 'ignore' });
|
|
99
112
|
} catch (err) {
|
|
100
113
|
console.log(chalk.red("✖ Native compilation failed."));
|
|
101
114
|
return;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# TitanPL Native & WebAssembly Extensions
|
|
2
|
+
|
|
3
|
+
One of the definitive features of TitanPL v7+ is its dynamic, zero-configuration native extension bridge. You no longer have to manually define function signatures or types within `titan.json`.
|
|
4
|
+
|
|
5
|
+
## The Hybrid IPC Native Bridge
|
|
6
|
+
|
|
7
|
+
The `NativeHost` bridge natively detects argument types over IPC at runtime. Whether you pass floating-point numbers (`f64`), complex strings, or JSON-stringified objects:
|
|
8
|
+
|
|
9
|
+
1. **Dynamic C-ABI Interop:** The host inspects the payload dynamically and generates the correct C-struct register combinations on-the-fly (`f64`, `*const c_char`, combinations).
|
|
10
|
+
2. **Safe Void execution:** Memory protections natively peek at returned pointer segments, preventing SEGFAULT crashes. `void` returns are safely handled transparently.
|
|
11
|
+
|
|
12
|
+
### Writing WebAssembly (WASM)
|
|
13
|
+
|
|
14
|
+
Because Titan CLI utilizes `wasm-pack` without unnecessary logs, compiling WebAssembly plugins from Rust is completely silent and incredibly robust.
|
|
15
|
+
|
|
16
|
+
To build a fresh, silent WASM extension:
|
|
17
|
+
```bash
|
|
18
|
+
titan build ext
|
|
19
|
+
```
|
|
20
|
+
The CLI suppresses stdout output (`stdio: 'ignore'`) allowing clean build processes unless a fatal compiler failure occurs.
|
|
21
|
+
|
|
22
|
+
### Best Practices: The `@titanpl/native` Namespace
|
|
23
|
+
|
|
24
|
+
Never use the globally injected `t.*` prefixes in Modern TitanPL scripts (unless deploying backward-compatible code). Instead, simply use the modular native imports:
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
// BEFORE (Not Recommended)
|
|
28
|
+
const data = t.fs.readFile("example.txt");
|
|
29
|
+
const hash = t.crypto.hash("sha256", "test");
|
|
30
|
+
|
|
31
|
+
// AFTER (Recommended)
|
|
32
|
+
import { fs, crypto, drift } from "@titanpl/native";
|
|
33
|
+
|
|
34
|
+
const data = fs.readFile("example.txt");
|
|
35
|
+
const hash = crypto.hash("sha256", "test");
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
By transitioning to `@titanpl/native`, you gain absolute Type Completion (via the newly restructured `d.ts` declaration maps) explicitly tailored to ESM semantics.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "my-extension",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "A high-performance TitanPL extension.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
"README.md"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@titanpl/sdk": "7.0.
|
|
14
|
+
"@titanpl/sdk": "7.0.1"
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
"template": "js"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@titanpl/cli": "7.0.
|
|
10
|
-
"@titanpl/route": "7.0.
|
|
11
|
-
"@titanpl/native": "7.0.
|
|
12
|
-
"@titanpl/core": "
|
|
9
|
+
"@titanpl/cli": "7.0.1",
|
|
10
|
+
"@titanpl/route": "7.0.1",
|
|
11
|
+
"@titanpl/native": "7.0.1",
|
|
12
|
+
"@titanpl/core": "7.0.0",
|
|
13
13
|
"@titanpl/node": "latest",
|
|
14
|
-
"@titanpl/packet": "7.0.
|
|
14
|
+
"@titanpl/packet": "7.0.1"
|
|
15
15
|
},
|
|
16
16
|
"optionalDependencies": {
|
|
17
|
-
"@titanpl/engine-linux-x64": "7.0.
|
|
18
|
-
"@titanpl/engine-win32-x64": "7.0.
|
|
17
|
+
"@titanpl/engine-linux-x64": "7.0.1",
|
|
18
|
+
"@titanpl/engine-win32-x64": "7.0.1"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "titan build",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"eslint": "^9.39.2",
|
|
29
29
|
"eslint-plugin-titanpl": "latest"
|
|
30
30
|
},
|
|
31
|
-
"version": "7.0.
|
|
31
|
+
"version": "7.0.1"
|
|
32
32
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "titanpl",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "A Titan Planet server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"titan": {
|
|
7
7
|
"template": "rust-js"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@titanpl/cli": "7.0.
|
|
11
|
-
"@titanpl/route": "7.0.
|
|
12
|
-
"@titanpl/native": "7.0.
|
|
13
|
-
"@titanpl/core": "
|
|
10
|
+
"@titanpl/cli": "7.0.1",
|
|
11
|
+
"@titanpl/route": "7.0.1",
|
|
12
|
+
"@titanpl/native": "7.0.1",
|
|
13
|
+
"@titanpl/core": "7.0.0",
|
|
14
14
|
"@titanpl/node": "latest"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "titanpl",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "A Titan Planet server (Rust + TypeScript)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"titan": {
|
|
7
7
|
"template": "rust-ts"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@titanpl/cli": "7.0.
|
|
11
|
-
"@titanpl/route": "7.0.
|
|
12
|
-
"@titanpl/native": "7.0.
|
|
13
|
-
"@titanpl/core": "
|
|
10
|
+
"@titanpl/cli": "7.0.1",
|
|
11
|
+
"@titanpl/route": "7.0.1",
|
|
12
|
+
"@titanpl/native": "7.0.1",
|
|
13
|
+
"@titanpl/core": "7.0.0",
|
|
14
14
|
"@titanpl/node": "latest",
|
|
15
15
|
"typescript": "^5.0.0"
|
|
16
16
|
},
|
|
@@ -6,18 +6,18 @@
|
|
|
6
6
|
"template": "ts"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@titanpl/cli": "7.0.
|
|
10
|
-
"@titanpl/route": "7.0.
|
|
11
|
-
"@titanpl/native": "7.0.
|
|
12
|
-
"@titanpl/core": "
|
|
9
|
+
"@titanpl/cli": "7.0.1",
|
|
10
|
+
"@titanpl/route": "7.0.1",
|
|
11
|
+
"@titanpl/native": "7.0.1",
|
|
12
|
+
"@titanpl/core": "7.0.0",
|
|
13
13
|
"@titanpl/node": "latest",
|
|
14
|
-
"@titanpl/packet": "7.0.
|
|
14
|
+
"@titanpl/packet": "7.0.1",
|
|
15
15
|
"typescript": "^5.0.0"
|
|
16
16
|
},
|
|
17
17
|
"optionalDependencies": {
|
|
18
18
|
"@titanpl/engine-linux-arm64": "2.0.5",
|
|
19
|
-
"@titanpl/engine-linux-x64": "7.0.
|
|
20
|
-
"@titanpl/engine-win32-x64": "7.0.
|
|
19
|
+
"@titanpl/engine-linux-x64": "7.0.1",
|
|
20
|
+
"@titanpl/engine-win32-x64": "7.0.1"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "titan build",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"eslint-plugin-titanpl": "latest",
|
|
32
32
|
"@typescript-eslint/parser": "^8.54.0"
|
|
33
33
|
},
|
|
34
|
-
"version": "7.0.
|
|
34
|
+
"version": "7.0.1"
|
|
35
35
|
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# Titan Extension Template
|
|
2
|
-
|
|
3
|
-
This template provides a starting point for building native extensions for Titan.
|
|
4
|
-
|
|
5
|
-
## Directory Structure
|
|
6
|
-
|
|
7
|
-
- `index.js`: The JavaScript entry point for your extension. It runs within the Titan runtime.
|
|
8
|
-
- `index.d.ts`: TypeScript definitions for your extension. This ensures users get autocompletion when using your extension.
|
|
9
|
-
- `native/`: (Optional) Rust source code for native high-performance logic.
|
|
10
|
-
- `titan.json`: Configuration file defining your extension's native ABI (if using Rust).
|
|
11
|
-
|
|
12
|
-
## Type Definitions (`index.d.ts`)
|
|
13
|
-
|
|
14
|
-
The `index.d.ts` file is crucial for Developer Experience (DX). It allows Titan projects to "see" your extension's API on the global `t` object.
|
|
15
|
-
|
|
16
|
-
### How it works
|
|
17
|
-
|
|
18
|
-
Titan uses **Declaration Merging** to extend the global `Titan.Runtime` interface. When a user installs your extension, this file acts as a plugin to their TypeScript environment.
|
|
19
|
-
|
|
20
|
-
### Customizing Types
|
|
21
|
-
|
|
22
|
-
Edit `index.d.ts` to match the API you expose in `index.js`.
|
|
23
|
-
|
|
24
|
-
**Example:**
|
|
25
|
-
|
|
26
|
-
If your `index.js` looks like this:
|
|
27
|
-
|
|
28
|
-
```javascript
|
|
29
|
-
// index.js
|
|
30
|
-
t.ext.my_cool_ext = {
|
|
31
|
-
greet: (name) => `Hello, ${name}!`,
|
|
32
|
-
compute: (x) => x * 2
|
|
33
|
-
};
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Your `index.d.ts` should look like this:
|
|
37
|
-
|
|
38
|
-
```typescript
|
|
39
|
-
// index.d.ts
|
|
40
|
-
declare global {
|
|
41
|
-
namespace Titan {
|
|
42
|
-
interface Runtime {
|
|
43
|
-
"my-cool-ext": {
|
|
44
|
-
/**
|
|
45
|
-
* Sends a greeting.
|
|
46
|
-
*/
|
|
47
|
-
greet(name: string): string;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Computes a value.
|
|
51
|
-
*/
|
|
52
|
-
compute(x: number): number;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
export { };
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
## Native Bindings (Rust)
|
|
61
|
-
|
|
62
|
-
If your extension requires native performance or system access, use the `native/` directory.
|
|
63
|
-
1. Define functions in `native/src/lib.rs`.
|
|
64
|
-
2. Map them in `titan.json`.
|
|
65
|
-
3. Call them from `index.js` using `Titan.native.invoke(...)` (or the helper provided in the template).
|
|
66
|
-
|
|
67
|
-
---
|
|
68
|
-
|
|
69
|
-
**Important Note:** Currently, Titan Planet and its entire package ecosystem are only for Windows. The Linux version is in development (dev only) for the new architecture and will be launched later.
|