File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11@ echo off
22REM OpenCode launcher for Node.js on Windows
3+ REM Uses the Node.js wrapper script to handle path conversions
34
45setlocal
56
67REM Get the directory where this script is located
7- set SCRIPT_DIR = %~dp0
8+ set " SCRIPT_DIR = %~dp0 "
89
9- REM Remove trailing backslash
10- set SCRIPT_DIR = %SCRIPT_DIR:~0 ,-1 %
11-
12- REM Convert Windows path to file:// URL for loader
13- set LOADER_PATH = file:///%SCRIPT_DIR:\ =/ % /loader.mjs
14- set SHIM_PATH = file:///%SCRIPT_DIR:\ =/ % /global-bun-shim.mjs
15-
16- REM Build the node command with all arguments
17- node --loader " %LOADER_PATH% " --conditions=browser --import " %SHIM_PATH% " --import tsx/esm " %SCRIPT_DIR% \src\index.ts" %*
10+ REM Run the Node.js wrapper which handles all the path conversions
11+ node " %SCRIPT_DIR% opencode-node.cjs" %*
1812
1913endlocal
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+
3+ /**
4+ * OpenCode launcher for Windows
5+ * Handles path conversions for Windows file:// URLs
6+ */
7+
8+ const { spawn } = require ( 'child_process' ) ;
9+ const path = require ( 'path' ) ;
10+ const { pathToFileURL } = require ( 'url' ) ;
11+
12+ // Get the script directory
13+ const scriptDir = __dirname ;
14+
15+ // Convert paths to file:// URLs
16+ const loaderPath = pathToFileURL ( path . join ( scriptDir , 'loader.mjs' ) ) . href ;
17+ const shimPath = pathToFileURL ( path . join ( scriptDir , 'global-bun-shim.mjs' ) ) . href ;
18+ const indexPath = path . join ( scriptDir , 'src' , 'index.ts' ) ;
19+
20+ // Build the arguments
21+ const args = [
22+ '--loader' , loaderPath ,
23+ '--conditions=browser' ,
24+ '--import' , shimPath ,
25+ '--import' , 'tsx/esm' ,
26+ indexPath ,
27+ ...process . argv . slice ( 2 ) // Forward all arguments
28+ ] ;
29+
30+ // Spawn Node.js
31+ const child = spawn ( 'node' , args , {
32+ stdio : 'inherit' ,
33+ windowsHide : false
34+ } ) ;
35+
36+ // Forward exit code
37+ child . on ( 'exit' , ( code ) => {
38+ process . exit ( code || 0 ) ;
39+ } ) ;
40+
41+ child . on ( 'error' , ( err ) => {
42+ console . error ( 'Failed to start OpenCode:' , err ) ;
43+ process . exit ( 1 ) ;
44+ } ) ;
You can’t perform that action at this time.
0 commit comments