titanpl 1.7.0 → 2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "titanpl",
3
- "version": "1.7.0",
3
+ "version": "2.0.1",
4
4
  "description": "Titan Planet is a JavaScript-first backend framework that embeds JS actions into a Rust + Axum server and ships as a single native binary. Routes are compiled to static metadata; only actions run in the embedded JS runtime. No Node.js. No event loop in production.",
5
5
  "license": "ISC",
6
6
  "author": "ezetgalaxy",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/cli",
3
- "version": "1.7.0",
3
+ "version": "2.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",
@@ -21,12 +21,12 @@
21
21
  "tit": "./index.js"
22
22
  },
23
23
  "optionalDependencies": {
24
- "@titanpl/engine-win32-x64": "1.7.0",
25
- "@titanpl/engine-linux-x64": "1.7.0",
26
- "@titanpl/engine-darwin-arm64": "1.7.0"
24
+ "@titanpl/engine-win32-x64": "2.0.1",
25
+ "@titanpl/engine-linux-x64": "2.0.1",
26
+ "@titanpl/engine-darwin-arm64": "2.0.1"
27
27
  },
28
28
  "dependencies": {
29
- "@titanpl/packet": "1.7.0",
29
+ "@titanpl/packet": "2.0.1",
30
30
  "prompts": "^2.4.2",
31
31
  "commander": "^11.0.0",
32
32
  "chalk": "^4.1.2"
@@ -1,5 +1,12 @@
1
1
  import { dev } from "@titanpl/packet";
2
+ import { resolveEngineBinaryPath } from "../engine.js";
2
3
 
3
4
  export async function devCommand() {
5
+ // Resolve the engine binary from CLI's context (where optionalDependencies live)
6
+ // and inject it into the environment so packet can find it without re-resolving.
7
+ const enginePath = resolveEngineBinaryPath();
8
+ if (enginePath) {
9
+ process.env.TITAN_ENGINE_BINARY = enginePath;
10
+ }
4
11
  await dev(process.cwd());
5
- }
12
+ }
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { fileURLToPath } from 'url';
4
- import { spawn } from 'child_process';
4
+ import { execSync } from 'child_process';
5
5
  import prompts from 'prompts';
6
6
  import chalk from 'chalk';
7
7
 
@@ -166,15 +166,7 @@ export async function initCommand(projectName, templateName) {
166
166
 
167
167
  console.log(chalk.gray(` Installing dependencies...`));
168
168
 
169
- await new Promise((resolve, reject) => {
170
- const npm = spawn('npm', ['install'], {
171
- cwd: target,
172
- stdio: 'inherit',
173
- shell: true
174
- });
175
- npm.on('error', reject);
176
- npm.on('close', resolve);
177
- });
169
+ execSync('npm install', { cwd: target, stdio: 'inherit' });
178
170
 
179
171
  console.log(chalk.green(`\n✔ Project '${projName}' created successfully!\n`));
180
172
  console.log(chalk.yellow(` cd ${projName}`));
@@ -1,5 +1,9 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
3
7
 
4
8
  export async function migrateCommand() {
5
9
  const root = process.cwd();
@@ -51,15 +55,29 @@ export async function migrateCommand() {
51
55
  }
52
56
  }
53
57
 
54
- // Add dependencies
58
+ // Add / fix dependencies — ensure correct @titanpl/ scope
55
59
  pkg.dependencies = pkg.dependencies || {};
56
- if (!pkg.dependencies['@titan/native']) {
57
- pkg.dependencies['@titan/native'] = "latest";
58
- modified = true;
60
+
61
+ // Remove any stale old-scope packages (@titan/ typo) that may exist
62
+ const stalePackages = ['@titanp/native', '@titan/route', '@titan/cli', '@titan/packet'];
63
+ for (const stale of stalePackages) {
64
+ if (pkg.dependencies[stale]) {
65
+ delete pkg.dependencies[stale];
66
+ modified = true;
67
+ }
59
68
  }
60
- if (!pkg.dependencies['@titan/route']) {
61
- pkg.dependencies['@titan/route'] = "latest";
62
- modified = true;
69
+
70
+ const requiredDeps = {
71
+ '@titanpl/cli': 'latest',
72
+ '@titanpl/route': 'latest',
73
+ '@titanpl/native': 'latest',
74
+ '@titanpl/packet': 'latest',
75
+ };
76
+ for (const [dep, version] of Object.entries(requiredDeps)) {
77
+ if (!pkg.dependencies[dep]) {
78
+ pkg.dependencies[dep] = version;
79
+ modified = true;
80
+ }
63
81
  }
64
82
 
65
83
  if (modified) {
@@ -10,13 +10,17 @@ const __dirname = path.dirname(__filename);
10
10
 
11
11
  const require = createRequire(import.meta.url);
12
12
 
13
- export function getEngineBinaryPath() {
14
- const platform = os.platform(); // 'win32', 'linux', 'darwin'
15
- const arch = os.arch(); // 'x64', 'arm64'
13
+ /**
14
+ * Resolves the engine binary path. Returns null if not found (non-fatal).
15
+ * Used by the dev command to pre-resolve and inject the path via env.
16
+ */
17
+ export function resolveEngineBinaryPath() {
18
+ const platform = os.platform();
19
+ const arch = os.arch();
16
20
  const pkgName = `@titanpl/engine-${platform}-${arch}`;
17
21
  const binName = platform === 'win32' ? 'titan-server.exe' : 'titan-server';
18
22
 
19
- // 1. Robust Binary Discovery (Monorepo, Local, or Global)
23
+ // 1. Monorepo search (local dev)
20
24
  const searchPaths = [
21
25
  __dirname,
22
26
  process.cwd(),
@@ -29,38 +33,43 @@ export function getEngineBinaryPath() {
29
33
  for (let i = 0; i < 8; i++) {
30
34
  const potential = path.join(current, 'engine', 'target', 'release', binName);
31
35
  if (fs.existsSync(potential)) return potential;
32
-
33
36
  const parent = path.dirname(current);
34
37
  if (parent === current) break;
35
38
  current = parent;
36
39
  }
37
40
  }
38
41
 
39
- // 2. Resolve installed optional dependency
42
+ // 2. Resolve from CLI's own context (correct require context for optionalDependencies)
40
43
  try {
41
- // We use a try/catch specifically for the resolve to provide a better diagnostic
42
- let pkgPath;
43
- try {
44
- pkgPath = require.resolve(`${pkgName}/package.json`);
45
- } catch (e) {
46
- // Fallback: check if the binary exists in a standard location even if require.resolve fails
47
- const fallbackBin = path.join(process.cwd(), 'node_modules', pkgName, 'bin', binName);
48
- if (fs.existsSync(fallbackBin)) return fallbackBin;
49
- throw e;
50
- }
51
- const pkgDir = path.dirname(pkgPath);
52
- const binaryPath = path.join(pkgDir, 'bin', binName);
44
+ const pkgPath = require.resolve(`${pkgName}/package.json`);
45
+ const binaryPath = path.join(path.dirname(pkgPath), 'bin', binName);
46
+ if (fs.existsSync(binaryPath)) return binaryPath;
47
+ } catch (e) { }
53
48
 
54
- if (fs.existsSync(binaryPath)) {
55
- return binaryPath;
56
- }
57
- throw new Error(`Corrupted installation: Binary missing at ${binaryPath}.`);
58
- } catch (err) {
59
- console.error(`\n[TITAN FATAL] Unsupported platform: ${platform} (${arch})`);
60
- console.error(`Or the optional dependency '${pkgName}' failed to install.`);
61
- console.error(`Error: ${err.message}\n`);
62
- process.exit(1);
63
- }
49
+ // 3. Fallback: sibling in node_modules (global install layout)
50
+ const cliParent = path.dirname(path.dirname(__dirname)); // up from cli/src → cli → parent
51
+ const siblingBin = path.join(cliParent, pkgName, 'bin', binName);
52
+ if (fs.existsSync(siblingBin)) return siblingBin;
53
+
54
+ return null;
55
+ }
56
+
57
+ /**
58
+ * Resolves the engine binary path. Exits with a fatal error if not found.
59
+ * Used by the start command.
60
+ */
61
+ export function getEngineBinaryPath() {
62
+ const platform = os.platform();
63
+ const arch = os.arch();
64
+ const pkgName = `@titanpl/engine-${platform}-${arch}`;
65
+
66
+ const resolved = resolveEngineBinaryPath();
67
+ if (resolved) return resolved;
68
+
69
+ console.error(`\n[TITAN FATAL] Unsupported platform: ${platform} (${arch})`);
70
+ console.error(`Or the optional dependency '${pkgName}' failed to install.`);
71
+ console.error(`Try: npm install -g @titanpl/cli\n`);
72
+ process.exit(1);
64
73
  }
65
74
 
66
75
  export function startEngine(watchMode = false) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/engine-darwin-arm64",
3
- "version": "1.7.0",
3
+ "version": "2.0.1",
4
4
  "os": [
5
5
  "darwin"
6
6
  ],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/engine-linux-x64",
3
- "version": "1.7.0",
3
+ "version": "2.0.1",
4
4
  "os": [
5
5
  "linux"
6
6
  ],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/engine-win32-x64",
3
- "version": "1.7.0",
3
+ "version": "2.0.1",
4
4
  "os": [
5
5
  "win32"
6
6
  ],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/native",
3
- "version": "1.7.0",
3
+ "version": "2.0.1",
4
4
  "description": "Titan native utilities package",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -25,12 +25,17 @@ function getTitanVersion() {
25
25
  }
26
26
 
27
27
  function getEngineBinaryPath(root) {
28
+ // First: check if the CLI pre-resolved this for us (correct module context)
29
+ if (process.env.TITAN_ENGINE_BINARY && fs.existsSync(process.env.TITAN_ENGINE_BINARY)) {
30
+ return process.env.TITAN_ENGINE_BINARY;
31
+ }
32
+
28
33
  const platform = os.platform();
29
34
  const arch = os.arch();
30
35
  const binName = platform === 'win32' ? 'titan-server.exe' : 'titan-server';
31
36
  const pkgName = `@titanpl/engine-${platform}-${arch}`;
32
37
 
33
- // Monorepo search
38
+ // 1. Monorepo search (dev environment)
34
39
  let current = root;
35
40
  for (let i = 0; i < 5; i++) {
36
41
  const potential = path.join(current, 'engine', 'target', 'release', binName);
@@ -38,7 +43,21 @@ function getEngineBinaryPath(root) {
38
43
  current = path.dirname(current);
39
44
  }
40
45
 
41
- // Node modules search
46
+ // 2. Search relative to @titanpl/cli (where optionalDependencies are installed)
47
+ // This is the primary path for globally-installed CLI users.
48
+ try {
49
+ const require = createRequire(import.meta.url);
50
+ const cliPkgPath = require.resolve('@titanpl/cli/package.json');
51
+ const cliDir = path.dirname(cliPkgPath);
52
+ // Check cli's own node_modules (global install sibling)
53
+ const cliNodeModulesBin = path.join(cliDir, 'node_modules', pkgName, 'bin', binName);
54
+ if (fs.existsSync(cliNodeModulesBin)) return cliNodeModulesBin;
55
+ // Check parent node_modules (hoisted global install)
56
+ const parentNodeModulesBin = path.join(path.dirname(cliDir), pkgName, 'bin', binName);
57
+ if (fs.existsSync(parentNodeModulesBin)) return parentNodeModulesBin;
58
+ } catch (e) { }
59
+
60
+ // 3. Search in the project's own node_modules
42
61
  try {
43
62
  const require = createRequire(import.meta.url);
44
63
  const pkgPath = require.resolve(`${pkgName}/package.json`);
@@ -46,6 +65,19 @@ function getEngineBinaryPath(root) {
46
65
  if (fs.existsSync(binPath)) return binPath;
47
66
  } catch (e) { }
48
67
 
68
+ // 4. Fallback: check common global npm paths
69
+ const globalSearchRoots = [
70
+ process.env.npm_config_prefix,
71
+ path.join(os.homedir(), '.npm-global'),
72
+ '/usr/local/lib',
73
+ '/usr/lib'
74
+ ].filter(Boolean);
75
+
76
+ for (const gRoot of globalSearchRoots) {
77
+ const gBin = path.join(gRoot, 'node_modules', pkgName, 'bin', binName);
78
+ if (fs.existsSync(gBin)) return gBin;
79
+ }
80
+
49
81
  return null;
50
82
  }
51
83
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/packet",
3
- "version": "1.7.0",
3
+ "version": "2.0.1",
4
4
  "description": "The bundler for TitanPl servers.",
5
5
  "keywords": [
6
6
  "bundler",
@@ -25,12 +25,17 @@ function getTitanVersion() {
25
25
  }
26
26
 
27
27
  function getEngineBinaryPath(root) {
28
+ // First: check if the CLI pre-resolved this for us (correct module context)
29
+ if (process.env.TITAN_ENGINE_BINARY && fs.existsSync(process.env.TITAN_ENGINE_BINARY)) {
30
+ return process.env.TITAN_ENGINE_BINARY;
31
+ }
32
+
28
33
  const platform = os.platform();
29
34
  const arch = os.arch();
30
35
  const binName = platform === 'win32' ? 'titan-server.exe' : 'titan-server';
31
36
  const pkgName = `@titanpl/engine-${platform}-${arch}`;
32
37
 
33
- // Monorepo search
38
+ // 1. Monorepo search (dev environment)
34
39
  let current = root;
35
40
  for (let i = 0; i < 5; i++) {
36
41
  const potential = path.join(current, 'engine', 'target', 'release', binName);
@@ -38,7 +43,21 @@ function getEngineBinaryPath(root) {
38
43
  current = path.dirname(current);
39
44
  }
40
45
 
41
- // Node modules search
46
+ // 2. Search relative to @titanpl/cli (where optionalDependencies are installed)
47
+ // This is the primary path for globally-installed CLI users.
48
+ try {
49
+ const require = createRequire(import.meta.url);
50
+ const cliPkgPath = require.resolve('@titanpl/cli/package.json');
51
+ const cliDir = path.dirname(cliPkgPath);
52
+ // Check cli's own node_modules (global install sibling)
53
+ const cliNodeModulesBin = path.join(cliDir, 'node_modules', pkgName, 'bin', binName);
54
+ if (fs.existsSync(cliNodeModulesBin)) return cliNodeModulesBin;
55
+ // Check parent node_modules (hoisted global install)
56
+ const parentNodeModulesBin = path.join(path.dirname(cliDir), pkgName, 'bin', binName);
57
+ if (fs.existsSync(parentNodeModulesBin)) return parentNodeModulesBin;
58
+ } catch (e) { }
59
+
60
+ // 3. Search in the project's own node_modules
42
61
  try {
43
62
  const require = createRequire(import.meta.url);
44
63
  const pkgPath = require.resolve(`${pkgName}/package.json`);
@@ -46,6 +65,19 @@ function getEngineBinaryPath(root) {
46
65
  if (fs.existsSync(binPath)) return binPath;
47
66
  } catch (e) { }
48
67
 
68
+ // 4. Fallback: check common global npm paths
69
+ const globalSearchRoots = [
70
+ process.env.npm_config_prefix,
71
+ path.join(os.homedir(), '.npm-global'),
72
+ '/usr/local/lib',
73
+ '/usr/lib'
74
+ ].filter(Boolean);
75
+
76
+ for (const gRoot of globalSearchRoots) {
77
+ const gBin = path.join(gRoot, 'node_modules', pkgName, 'bin', binName);
78
+ if (fs.existsSync(gBin)) return gBin;
79
+ }
80
+
49
81
  return null;
50
82
  }
51
83
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/route",
3
- "version": "1.7.0",
3
+ "version": "2.0.1",
4
4
  "description": "Titan routing DSL",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "{{name}}",
3
- "version": "1.7.0",
3
+ "version": "2.0.1",
4
4
  "description": "A Titan Planet extension",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "@titanpl/core": "latest",
19
19
  "chokidar": "^5.0.0",
20
20
  "esbuild": "^0.27.2",
21
- "titanpl-sdk": "1.7.0"
21
+ "titanpl-sdk": "2.0.1"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@tgrv/microgravity": "latest"
@@ -6,12 +6,12 @@
6
6
  "template": "js"
7
7
  },
8
8
  "dependencies": {
9
- "@titanpl/cli": "1.7.0",
10
- "@titanpl/route": "1.7.0",
11
- "@titanpl/native": "1.7.0",
9
+ "@titanpl/cli": "2.0.1",
10
+ "@titanpl/route": "2.0.1",
11
+ "@titanpl/native": "2.0.1",
12
12
  "@titanpl/core": "latest",
13
13
  "@titanpl/node": "latest",
14
- "@titanpl/packet": "1.7.0"
14
+ "@titanpl/packet": "2.0.1"
15
15
  },
16
16
  "scripts": {
17
17
  "build": "titan build",
@@ -24,5 +24,5 @@
24
24
  "eslint": "^9.39.2",
25
25
  "eslint-plugin-titanpl": "latest"
26
26
  },
27
- "version": "1.7.0"
27
+ "version": "2.0.1"
28
28
  }
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "titanpl",
3
- "version": "1.7.0",
3
+ "version": "2.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": "1.7.0",
11
- "@titanpl/route": "1.7.0",
12
- "@titanpl/native": "1.7.0",
10
+ "@titanpl/cli": "2.0.1",
11
+ "@titanpl/route": "2.0.1",
12
+ "@titanpl/native": "2.0.1",
13
13
  "@titanpl/core": "latest",
14
14
  "@titanpl/node": "latest"
15
15
  },
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "titanpl",
3
- "version": "1.7.0",
3
+ "version": "2.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": "1.7.0",
11
- "@titanpl/route": "1.7.0",
12
- "@titanpl/native": "1.7.0",
10
+ "@titanpl/cli": "2.0.1",
11
+ "@titanpl/route": "2.0.1",
12
+ "@titanpl/native": "2.0.1",
13
13
  "@titanpl/core": "latest",
14
14
  "@titanpl/node": "latest",
15
15
  "typescript": "^5.0.0"
@@ -6,12 +6,12 @@
6
6
  "template": "ts"
7
7
  },
8
8
  "dependencies": {
9
- "@titanpl/cli": "1.7.0",
10
- "@titanpl/route": "1.7.0",
11
- "@titanpl/native": "1.7.0",
9
+ "@titanpl/cli": "2.0.1",
10
+ "@titanpl/route": "2.0.1",
11
+ "@titanpl/native": "2.0.1",
12
12
  "@titanpl/core": "latest",
13
13
  "@titanpl/node": "latest",
14
- "@titanpl/packet": "1.7.0",
14
+ "@titanpl/packet": "2.0.1",
15
15
  "typescript": "^5.0.0"
16
16
  },
17
17
  "scripts": {
@@ -26,5 +26,5 @@
26
26
  "eslint-plugin-titanpl": "latest",
27
27
  "@typescript-eslint/parser": "^8.54.0"
28
28
  },
29
- "version": "1.7.0"
29
+ "version": "2.0.1"
30
30
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "titanpl-sdk",
3
- "version": "1.7.0",
3
+ "version": "2.0.1",
4
4
  "description": "Development SDK for Titan Planet. Provides TypeScript type definitions for the global 't' runtime object and a 'lite' test-harness runtime for building and verifying extensions.",
5
5
  "main": "index.js",
6
6
  "type": "module",