@@ -85,18 +85,6 @@ function prepareBinDirectory(binaryName) {
8585 return { binDir, targetPath }
8686}
8787
88- function copyBinary ( sourcePath , binaryName ) {
89- const { targetPath } = prepareBinDirectory ( binaryName )
90-
91- fs . copyFileSync ( sourcePath , targetPath )
92- console . log ( `opencode binary installed: ${ targetPath } ` )
93-
94- // Verify the file exists after operation
95- if ( ! fs . existsSync ( targetPath ) ) {
96- throw new Error ( `Failed to copy binary to ${ targetPath } ` )
97- }
98- }
99-
10088function symlinkBinary ( sourcePath , binaryName ) {
10189 const { targetPath } = prepareBinDirectory ( binaryName )
10290
@@ -109,64 +97,12 @@ function symlinkBinary(sourcePath, binaryName) {
10997 }
11098}
11199
112- async function regenerateWindowsCmdWrappers ( ) {
113- console . log ( "Windows + npm detected: Forcing npm to rebuild bin links" )
114-
115- try {
116- const { execSync } = require ( "child_process" )
117- const pkgPath = path . join ( __dirname , ".." )
118-
119- // npm_config_global is string | undefined
120- // if it exists, the value is true
121- const isGlobal = process . env . npm_config_global === "true" || pkgPath . includes ( path . join ( "npm" , "node_modules" ) )
122-
123- // The npm rebuild command does 2 things - Execute lifecycle scripts and rebuild bin links
124- // We want to skip lifecycle scripts to avoid infinite loops, so we use --ignore-scripts
125- const cmd = `npm rebuild opencode-ai --ignore-scripts${ isGlobal ? " -g" : "" } `
126- const opts = {
127- stdio : "inherit" ,
128- shell : true ,
129- ...( isGlobal ? { } : { cwd : path . join ( pkgPath , ".." , ".." ) } ) , // For local, run from project root
130- }
131-
132- console . log ( `Running: ${ cmd } ` )
133- execSync ( cmd , opts )
134- console . log ( "Successfully rebuilt npm bin links" )
135- } catch ( error ) {
136- console . error ( "Error rebuilding npm links:" , error . message )
137- console . error ( "npm rebuild failed. You may need to manually run: npm rebuild opencode-ai --ignore-scripts" )
138- }
139- }
140-
141100async function main ( ) {
142101 try {
143102 if ( os . platform ( ) === "win32" ) {
144- // NPM eg format - npm/11.4.2 node/v24.4.1 win32 x64
145- // Bun eg format - bun/1.2.19 npm/? node/v24.3.0 win32 x64
146- // pnpm eg format - pnpm/8.10.0 npm/? node/v20.10.0 win32 x64
147- const userAgent = process . env . npm_config_user_agent || ""
148-
149- if ( userAgent . startsWith ( "npm" ) ) {
150- await regenerateWindowsCmdWrappers ( )
151- return
152- }
153-
154- if ( userAgent . startsWith ( "bun" ) ) {
155- console . log ( "Windows + bun detected: Setting up binary" )
156- const { binaryPath, binaryName } = findBinary ( )
157- copyBinary ( binaryPath , binaryName )
158- return
159- }
160-
161- if ( userAgent . startsWith ( "pnpm" ) ) {
162- console . log ( "Windows + pnpm detected: Setting up binary" )
163- const { binaryPath, binaryName } = findBinary ( )
164- copyBinary ( binaryPath , binaryName )
165- return
166- }
167-
168- // Unknown package manager on Windows
169- console . log ( "Windows detected but unknown package manager, skipping postinstall" )
103+ // On Windows, the .exe is already included in the package and bin field points to it
104+ // No postinstall setup needed
105+ console . log ( "Windows detected: binary setup not needed (using packaged .exe)" )
170106 return
171107 }
172108
0 commit comments