Skip to content

Commit 3a574ff

Browse files
committed
Use absolute path for tsx module to enable launching from any directory
1 parent 05fe865 commit 3a574ff

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

packages/opencode/opencode-node.cjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@ const { pathToFileURL } = require('url');
1212
// Get the script directory
1313
const scriptDir = __dirname;
1414

15+
// Repository root where node_modules is located
16+
const repoRoot = path.join(scriptDir, '..', '..');
17+
const nodeModulesPath = path.join(repoRoot, 'node_modules');
18+
1519
// Convert paths to file:// URLs
1620
const loaderPath = pathToFileURL(path.join(scriptDir, 'loader.mjs')).href;
1721
const shimPath = pathToFileURL(path.join(scriptDir, 'global-bun-shim.mjs')).href;
1822
const indexPath = path.join(scriptDir, 'src', 'index.ts');
23+
// Use absolute path for tsx/esm so it can be found regardless of cwd
24+
const tsxPath = pathToFileURL(path.join(nodeModulesPath, 'tsx', 'dist', 'esm', 'index.mjs')).href;
1925

2026
// Build the arguments
2127
const args = [
2228
'--loader', loaderPath,
2329
'--conditions=browser',
2430
'--import', shimPath,
25-
'--import', 'tsx/esm',
31+
'--import', tsxPath,
2632
indexPath,
2733
...process.argv.slice(2) // Forward all arguments
2834
];
@@ -31,7 +37,11 @@ const args = [
3137
const child = spawn('node', args, {
3238
stdio: 'inherit',
3339
windowsHide: false,
34-
cwd: path.join(scriptDir, '..', '..') // Run from repo root where node_modules is
40+
cwd: repoRoot, // Run from repo root where node_modules is
41+
env: {
42+
...process.env,
43+
NODE_PATH: nodeModulesPath // Tell Node.js where to find modules
44+
}
3545
});
3646

3747
// Forward exit code

packages/opencode/opencode-node.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,30 @@ const __dirname = dirname(__filename);
1515
// Get the arguments to pass through (skip node and script name)
1616
const args = process.argv.slice(2);
1717

18+
// Repository root where node_modules is located
19+
const repoRoot = join(__dirname, '..', '..');
20+
const nodeModulesPath = join(repoRoot, 'node_modules');
21+
22+
// Use absolute path for tsx/esm so it can be found regardless of cwd
23+
const tsxPath = join(nodeModulesPath, 'tsx', 'dist', 'esm', 'index.mjs');
24+
1825
// Build the command
1926
const nodeArgs = [
2027
'--loader', join(__dirname, 'loader.mjs'),
2128
'--conditions=browser',
2229
'--import', join(__dirname, 'global-bun-shim.mjs'),
23-
'--import', 'tsx/esm',
30+
'--import', tsxPath,
2431
join(__dirname, 'src', 'index.ts'),
2532
...args
2633
];
2734

2835
// Spawn Node.js with our configuration from the repo root
2936
const child = spawn('node', nodeArgs, {
3037
stdio: 'inherit',
31-
cwd: join(__dirname, '..', '..'), // Run from repo root where node_modules is
38+
cwd: repoRoot, // Run from repo root where node_modules is
3239
env: {
3340
...process.env,
41+
NODE_PATH: nodeModulesPath, // Tell Node.js where to find modules
3442
// Suppress the experimental loader warning if desired
3543
// NODE_NO_WARNINGS: '1',
3644
}

0 commit comments

Comments
 (0)