@@ -14,6 +14,13 @@ export interface ExecutableInfo {
1414 hasExecutable : boolean
1515}
1616
17+ /**
18+ * Extract basename from package
19+ */
20+ function getPackageBaseName ( packageName : string ) : string | undefined {
21+ return packageName . startsWith ( '@' ) ? packageName . split ( '/' ) [ 1 ] : packageName
22+ }
23+
1724/**
1825 * Extract executable command information from a package's bin field.
1926 * Handles both string format ("bin": "./cli.js") and object format ("bin": { "cmd": "./cli.js" }).
@@ -43,7 +50,7 @@ export function getExecutableInfo(
4350 }
4451
4552 // Prefer command matching package name if it exists; otherwise, use first
46- const baseName = packageName . startsWith ( '@' ) ? packageName . split ( '/' ) [ 1 ] : packageName
53+ const baseName = getPackageBaseName ( packageName )
4754 const primaryCommand = baseName && commands . includes ( baseName ) ? baseName : firstCommand
4855
4956 return {
@@ -87,9 +94,7 @@ export function getRunCommandParts(options: RunCommandOptions): string[] {
8794 // For local execute with specific command name different from package name
8895 // e.g., `pnpm exec tsc` for typescript package
8996 if ( options . command && options . command !== options . packageName ) {
90- const baseName = options . packageName . startsWith ( '@' )
91- ? options . packageName . split ( '/' ) [ 1 ]
92- : options . packageName
97+ const baseName = getPackageBaseName ( options . packageName )
9398 // If command matches base package name, use the package spec
9499 if ( options . command === baseName ) {
95100 return [ ...executeParts , spec ]
0 commit comments