@@ -5,9 +5,12 @@ import path from 'path';
55import { downloadFile } from '@studio/common/lib/download-file' ;
66import { extractZip } from '@studio/common/lib/extract-zip' ;
77import { isErrnoException } from '@studio/common/lib/is-errno-exception' ;
8+ import {
9+ findBundledPhpBinary ,
10+ verifyBundledPhpBinaryHash ,
11+ } from '@studio/common/lib/php-binary-bundle' ;
812import {
913 buildPhpBinaryUrl ,
10- getBundledPhpBinaryRelativePath ,
1114 getPhpBinaryHash ,
1215 validateNativePhpVersion ,
1316 PHP_PATCH_VERSIONS ,
@@ -72,7 +75,12 @@ async function claimInstallSlot( destDir: string, destPath: string ): Promise< b
7275async function installBundledBinaryIfAvailable (
7376 version : NativePhpSupportedVersion
7477) : Promise < boolean > {
75- const sourcePath = findBundledBinary ( version , process . platform , process . arch ) ;
78+ const sourcePath = findBundledPhpBinary ( version , process . platform , process . arch , [
79+ // Built CLI bundle: dist/cli/bin/php/...
80+ path . join ( import . meta. dirname , 'bin' , 'php' ) ,
81+ // Source tree fallback for local development before the Vite build runs.
82+ path . resolve ( import . meta. dirname , '..' , '..' , 'bin' , 'php' ) ,
83+ ] ) ;
7684 if ( ! sourcePath ) {
7785 return false ;
7886 }
@@ -85,7 +93,7 @@ async function installBundledBinaryIfAvailable(
8593 }
8694
8795 try {
88- await verifyBundledHash ( sourcePath ) ;
96+ await verifyBundledPhpBinaryHash ( sourcePath ) ;
8997 fs . copyFileSync ( sourcePath , destPath ) ;
9098 if ( process . platform !== 'win32' ) {
9199 fs . chmodSync ( destPath , 0o755 ) ;
@@ -97,43 +105,6 @@ async function installBundledBinaryIfAvailable(
97105 }
98106}
99107
100- function findBundledBinary (
101- version : NativePhpSupportedVersion ,
102- platform : NodeJS . Platform ,
103- arch : string
104- ) : string | undefined {
105- const relativePath = getBundledPhpBinaryRelativePath ( version , platform , arch ) ;
106- const roots = [
107- path . join ( import . meta. dirname , 'bin' , 'php' ) ,
108- path . resolve ( import . meta. dirname , '..' , '..' , 'bin' , 'php' ) ,
109- ] ;
110-
111- for ( const root of roots ) {
112- const sourcePath = path . join ( root , relativePath ) ;
113- if ( fs . existsSync ( sourcePath ) ) {
114- return sourcePath ;
115- }
116- }
117- }
118-
119- async function verifyBundledHash ( sourcePath : string ) : Promise < void > {
120- const hashPath = `${ sourcePath } .sha256` ;
121- if ( ! fs . existsSync ( hashPath ) ) {
122- throw new Error ( `No pinned SHA-256 hash for bundled PHP binary at ${ sourcePath } .` ) ;
123- }
124-
125- const [ expected ] = ( await fs . promises . readFile ( hashPath , 'utf8' ) ) . trim ( ) . split ( / \s + / ) ;
126- const data = await fs . promises . readFile ( sourcePath ) ;
127- const actual = crypto . createHash ( 'sha256' ) . update ( data ) . digest ( 'hex' ) ;
128- if ( actual !== expected ) {
129- throw new Error (
130- `SHA-256 mismatch for bundled PHP binary at ${ sourcePath } :\n` +
131- ` expected ${ expected } \n` +
132- ` got ${ actual } `
133- ) ;
134- }
135- }
136-
137108async function downloadAndInstall (
138109 version : NativePhpSupportedVersion ,
139110 onProgress ?: ( downloaded : number , total : number ) => void
0 commit comments