@@ -6,8 +6,12 @@ import { logger, prompt } from 'storybook/internal/node-logger';
66import { FindPackageVersionsError } from 'storybook/internal/server-errors' ;
77
88import * as find from 'empathic/find' ;
9+ // eslint-disable-next-line depend/ban-dependencies
10+ import type { ExecaChildProcess } from 'execa' ;
911import sort from 'semver/functions/sort.js' ;
1012
13+ import type { ExecuteCommandOptions } from '../utils/command' ;
14+ import { executeCommand , executeCommandSync } from '../utils/command' ;
1115import { getProjectRoot } from '../utils/paths' ;
1216import { JsPackageManager } from './JsPackageManager' ;
1317import type { PackageJson } from './PackageJson' ;
@@ -69,7 +73,7 @@ export class BUNProxy extends JsPackageManager {
6973 installArgs : string [ ] | undefined ;
7074
7175 async initPackageJson ( ) {
72- return this . executeCommand ( { command : 'bun' , args : [ 'init' ] } ) ;
76+ return executeCommand ( { command : 'bun' , args : [ 'init' ] } ) ;
7377 }
7478
7579 getRunStorybookCommand ( ) : string {
@@ -84,6 +88,10 @@ export class BUNProxy extends JsPackageManager {
8488 return `bunx ${ pkg } ${ specifier ? `@${ specifier } ` : '' } ${ args . join ( ' ' ) } ` ;
8589 }
8690
91+ public runRemoteCommand ( options : Omit < ExecuteCommandOptions , 'command' > & { args : string [ ] } ) {
92+ return executeCommand ( { command : 'bunx' , ...options } ) ;
93+ }
94+
8795 public async getModulePackageJSON ( packageName : string ) : Promise < PackageJson | null > {
8896 const wantedPath = join ( 'node_modules' , packageName , 'package.json' ) ;
8997 const packageJsonPath = find . up ( wantedPath , { cwd : this . cwd , last : getProjectRoot ( ) } ) ;
@@ -103,31 +111,25 @@ export class BUNProxy extends JsPackageManager {
103111 return this . installArgs ;
104112 }
105113
106- public runPackageCommandSync (
107- command : string ,
108- args : string [ ] ,
109- cwd ?: string ,
110- stdio ?: 'pipe' | 'inherit'
111- ) : string {
112- return this . executeCommandSync ( {
114+ public runPackageCommandSync ( {
115+ args,
116+ ...options
117+ } : Omit < ExecuteCommandOptions , 'command' > & { args : string [ ] } ) : string {
118+ return executeCommandSync ( {
113119 command : 'bun' ,
114- args : [ 'run' , command , ...args ] ,
115- cwd,
116- stdio,
120+ args : [ 'run' , ...args ] ,
121+ ...options ,
117122 } ) ;
118123 }
119124
120- public runPackageCommand (
121- command : string ,
122- args : string [ ] ,
123- cwd ?: string ,
124- stdio ?: 'pipe' | 'inherit'
125- ) {
126- return this . executeCommand ( {
125+ public runPackageCommand ( {
126+ args,
127+ ...options
128+ } : Omit < ExecuteCommandOptions , 'command' > & { args : string [ ] } ) : ExecaChildProcess {
129+ return executeCommand ( {
127130 command : 'bun' ,
128- args : [ 'run' , command , ...args ] ,
129- cwd,
130- stdio,
131+ args : [ 'run' , ...args ] ,
132+ ...options ,
131133 } ) ;
132134 }
133135
@@ -137,15 +139,21 @@ export class BUNProxy extends JsPackageManager {
137139 cwd ?: string ,
138140 stdio ?: 'inherit' | 'pipe' | 'ignore'
139141 ) {
140- return this . executeCommand ( { command : 'bun' , args : [ command , ...args ] , cwd, stdio } ) ;
142+ return executeCommand ( {
143+ command : 'bun' ,
144+ args : [ command , ...args ] ,
145+ cwd : cwd ?? this . cwd ,
146+ stdio,
147+ } ) ;
141148 }
142149
143150 public async findInstallations ( pattern : string [ ] , { depth = 99 } : { depth ?: number } = { } ) {
144151 const exec = async ( { packageDepth } : { packageDepth : number } ) => {
145152 const pipeToNull = platform ( ) === 'win32' ? '2>NUL' : '2>/dev/null' ;
146- return this . executeCommand ( {
153+ return executeCommand ( {
147154 command : 'npm' ,
148155 args : [ 'ls' , '--json' , `--depth=${ packageDepth } ` , pipeToNull ] ,
156+ cwd : this . cwd ,
149157 env : {
150158 FORCE_COLOR : 'false' ,
151159 } ,
@@ -188,7 +196,7 @@ export class BUNProxy extends JsPackageManager {
188196 }
189197
190198 protected runInstall ( options ?: { force ?: boolean } ) {
191- return this . executeCommand ( {
199+ return executeCommand ( {
192200 command : 'bun' ,
193201 args : [ 'install' , ...this . getInstallArgs ( ) , ...( options ?. force ? [ '--force' ] : [ ] ) ] ,
194202 cwd : this . cwd ,
@@ -197,8 +205,9 @@ export class BUNProxy extends JsPackageManager {
197205 }
198206
199207 public async getRegistryURL ( ) {
200- const process = this . executeCommand ( {
208+ const process = executeCommand ( {
201209 command : 'npm' ,
210+ cwd : this . cwd ,
202211 // "npm config" commands are not allowed in workspaces per default
203212 // https://github.com/npm/cli/issues/6099#issuecomment-1847584792
204213 args : [ 'config' , 'get' , 'registry' , '-ws=false' , '-iwr' ] ,
@@ -215,7 +224,7 @@ export class BUNProxy extends JsPackageManager {
215224 args = [ '-D' , ...args ] ;
216225 }
217226
218- return this . executeCommand ( {
227+ return executeCommand ( {
219228 command : 'bun' ,
220229 args : [ 'add' , ...args , ...this . getInstallArgs ( ) ] ,
221230 stdio : 'pipe' ,
@@ -229,8 +238,9 @@ export class BUNProxy extends JsPackageManager {
229238 ) : Promise < T extends true ? string [ ] : string > {
230239 const args = fetchAllVersions ? [ 'versions' , '--json' ] : [ 'version' ] ;
231240 try {
232- const process = this . executeCommand ( {
241+ const process = executeCommand ( {
233242 command : 'npm' ,
243+ cwd : this . cwd ,
234244 args : [ 'info' , packageName , ...args ] ,
235245 } ) ;
236246 const result = await process ;
0 commit comments