@titanpl/packet 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/js/titan/dev.js CHANGED
@@ -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
 
package/package.json CHANGED
@@ -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",
package/ts/titan/dev.js CHANGED
@@ -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