@titanpl/packet 1.6.0 → 2.0.0

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
@@ -30,7 +30,7 @@ function getEngineBinaryPath(root) {
30
30
  const binName = platform === 'win32' ? 'titan-server.exe' : 'titan-server';
31
31
  const pkgName = `@titanpl/engine-${platform}-${arch}`;
32
32
 
33
- // Monorepo search
33
+ // 1. Monorepo search (dev environment)
34
34
  let current = root;
35
35
  for (let i = 0; i < 5; i++) {
36
36
  const potential = path.join(current, 'engine', 'target', 'release', binName);
@@ -38,7 +38,21 @@ function getEngineBinaryPath(root) {
38
38
  current = path.dirname(current);
39
39
  }
40
40
 
41
- // Node modules search
41
+ // 2. Search relative to @titanpl/cli (where optionalDependencies are installed)
42
+ // This is the primary path for globally-installed CLI users.
43
+ try {
44
+ const require = createRequire(import.meta.url);
45
+ const cliPkgPath = require.resolve('@titanpl/cli/package.json');
46
+ const cliDir = path.dirname(cliPkgPath);
47
+ // Check cli's own node_modules (global install sibling)
48
+ const cliNodeModulesBin = path.join(cliDir, 'node_modules', pkgName, 'bin', binName);
49
+ if (fs.existsSync(cliNodeModulesBin)) return cliNodeModulesBin;
50
+ // Check parent node_modules (hoisted global install)
51
+ const parentNodeModulesBin = path.join(path.dirname(cliDir), pkgName, 'bin', binName);
52
+ if (fs.existsSync(parentNodeModulesBin)) return parentNodeModulesBin;
53
+ } catch (e) { }
54
+
55
+ // 3. Search in the project's own node_modules
42
56
  try {
43
57
  const require = createRequire(import.meta.url);
44
58
  const pkgPath = require.resolve(`${pkgName}/package.json`);
@@ -46,6 +60,19 @@ function getEngineBinaryPath(root) {
46
60
  if (fs.existsSync(binPath)) return binPath;
47
61
  } catch (e) { }
48
62
 
63
+ // 4. Fallback: check common global npm paths
64
+ const globalSearchRoots = [
65
+ process.env.npm_config_prefix,
66
+ path.join(os.homedir(), '.npm-global'),
67
+ '/usr/local/lib',
68
+ '/usr/lib'
69
+ ].filter(Boolean);
70
+
71
+ for (const gRoot of globalSearchRoots) {
72
+ const gBin = path.join(gRoot, 'node_modules', pkgName, 'bin', binName);
73
+ if (fs.existsSync(gBin)) return gBin;
74
+ }
75
+
49
76
  return null;
50
77
  }
51
78
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/packet",
3
- "version": "1.6.0",
3
+ "version": "2.0.0",
4
4
  "description": "The bundler for TitanPl servers.",
5
5
  "keywords": [
6
6
  "bundler",
package/ts/titan/dev.js CHANGED
@@ -30,7 +30,7 @@ function getEngineBinaryPath(root) {
30
30
  const binName = platform === 'win32' ? 'titan-server.exe' : 'titan-server';
31
31
  const pkgName = `@titanpl/engine-${platform}-${arch}`;
32
32
 
33
- // Monorepo search
33
+ // 1. Monorepo search (dev environment)
34
34
  let current = root;
35
35
  for (let i = 0; i < 5; i++) {
36
36
  const potential = path.join(current, 'engine', 'target', 'release', binName);
@@ -38,7 +38,21 @@ function getEngineBinaryPath(root) {
38
38
  current = path.dirname(current);
39
39
  }
40
40
 
41
- // Node modules search
41
+ // 2. Search relative to @titanpl/cli (where optionalDependencies are installed)
42
+ // This is the primary path for globally-installed CLI users.
43
+ try {
44
+ const require = createRequire(import.meta.url);
45
+ const cliPkgPath = require.resolve('@titanpl/cli/package.json');
46
+ const cliDir = path.dirname(cliPkgPath);
47
+ // Check cli's own node_modules (global install sibling)
48
+ const cliNodeModulesBin = path.join(cliDir, 'node_modules', pkgName, 'bin', binName);
49
+ if (fs.existsSync(cliNodeModulesBin)) return cliNodeModulesBin;
50
+ // Check parent node_modules (hoisted global install)
51
+ const parentNodeModulesBin = path.join(path.dirname(cliDir), pkgName, 'bin', binName);
52
+ if (fs.existsSync(parentNodeModulesBin)) return parentNodeModulesBin;
53
+ } catch (e) { }
54
+
55
+ // 3. Search in the project's own node_modules
42
56
  try {
43
57
  const require = createRequire(import.meta.url);
44
58
  const pkgPath = require.resolve(`${pkgName}/package.json`);
@@ -46,6 +60,19 @@ function getEngineBinaryPath(root) {
46
60
  if (fs.existsSync(binPath)) return binPath;
47
61
  } catch (e) { }
48
62
 
63
+ // 4. Fallback: check common global npm paths
64
+ const globalSearchRoots = [
65
+ process.env.npm_config_prefix,
66
+ path.join(os.homedir(), '.npm-global'),
67
+ '/usr/local/lib',
68
+ '/usr/lib'
69
+ ].filter(Boolean);
70
+
71
+ for (const gRoot of globalSearchRoots) {
72
+ const gBin = path.join(gRoot, 'node_modules', pkgName, 'bin', binName);
73
+ if (fs.existsSync(gBin)) return gBin;
74
+ }
75
+
49
76
  return null;
50
77
  }
51
78