@@ -22,17 +22,29 @@ const require = createRequire(import.meta.url);
2222 * - binPath: Absolute path to the Vite CLI entry point (vite.js)
2323 * - envs: Environment variables to set when executing Vite
2424 *
25- * The function uses require.resolve to find the vite package installation,
26- * then constructs the path to the CLI binary within the package.
25+ * The function first tries to resolve vite package, then falls back
26+ * to rolldown-vite package (for direct rolldown-vite installations).
27+ * It constructs the path to the CLI binary within the resolved package.
2728 */
2829export async function vite ( ) : Promise < {
2930 binPath : string ;
3031 envs : Record < string , string > ;
3132} > {
32- // Find the vite package.json to locate the installation directory
33- const pkgJsonPath = require . resolve ( 'vite/package.json' , {
34- paths : [ process . cwd ( ) , dirname ( fileURLToPath ( import . meta. url ) ) ] ,
35- } ) ;
33+ const resolvePaths = [ process . cwd ( ) , dirname ( fileURLToPath ( import . meta. url ) ) ] ;
34+
35+ let pkgJsonPath : string ;
36+ try {
37+ // First try to resolve vite package.json
38+ pkgJsonPath = require . resolve ( 'vite/package.json' , {
39+ paths : resolvePaths ,
40+ } ) ;
41+ } catch {
42+ // Fallback to rolldown-vite package.json (for direct rolldown-vite installations)
43+ pkgJsonPath = require . resolve ( 'rolldown-vite/package.json' , {
44+ paths : resolvePaths ,
45+ } ) ;
46+ }
47+
3648 // Vite's CLI binary is located at bin/vite.js relative to the package root
3749 const binPath = join ( dirname ( pkgJsonPath ) , 'bin' , 'vite.js' ) ;
3850
0 commit comments