1- import { execFile , execFileSync } from 'child_process' ;
2- import { promisify } from 'util' ;
1+ import { promisify } from 'node:util' ;
2+ import child_process from 'node:child_process' ;
3+
4+ const exec = promisify ( child_process . exec ) ;
5+ const { execSync } = child_process ;
36import type { PackageManagerCompletion } from '../package-manager-completion.js' ;
7+ import { Command } from '../../src/t.js' ;
8+
9+ interface LazyCommand extends Command {
10+ _lazyCommand ?: string ;
11+ _optionsLoaded ?: boolean ;
12+ optionsRaw ?: Map < string , any > ;
13+ }
14+
415import {
516 packageJsonScriptCompletion ,
617 packageJsonDependencyCompletion ,
@@ -15,7 +26,8 @@ import {
1526 type ParsedOption ,
1627} from '../utils/text-utils.js' ;
1728
18- const execFileP = promisify ( execFile ) ;
29+ // regex to detect options section in help text
30+ const OPTIONS_SECTION_RE = / ^ \s * O p t i o n s : / i;
1931
2032// we parse the pnpm help text to extract commands and their descriptions!
2133export function parsePnpmHelp ( helpText : string ) : Record < string , string > {
@@ -49,7 +61,7 @@ export function parsePnpmHelp(helpText: string): Record<string, string> {
4961 } ;
5062
5163 for ( const line of helpLines ) {
52- if ( / ^ \s * O p t i o n s : / i . test ( line ) ) break ; // we stop at options
64+ if ( OPTIONS_SECTION_RE . test ( line ) ) break ; // we stop at options
5365
5466 // we match the command row
5567 const rowMatch = line . match ( COMMAND_ROW_RE ) ;
@@ -81,7 +93,7 @@ export async function getPnpmCommandsFromMainHelp(): Promise<
8193 Record < string , string >
8294> {
8395 try {
84- const { stdout } = await execFileP ( 'pnpm' , [ ' --help'] , {
96+ const { stdout } = await exec ( 'pnpm --help' , {
8597 encoding : 'utf8' ,
8698 timeout : 500 ,
8799 maxBuffer : 4 * 1024 * 1024 ,
@@ -157,9 +169,12 @@ export function parsePnpmOptions(
157169}
158170
159171// we load the dynamic options synchronously when requested ( separated from the command loading )
160- export function loadDynamicOptionsSync ( cmd : any , command : string ) : void {
172+ export function loadDynamicOptionsSync (
173+ cmd : LazyCommand ,
174+ command : string
175+ ) : void {
161176 try {
162- const stdout = execFileSync ( ' pnpm' , [ command , ' --help' ] , {
177+ const stdout = execSync ( ` pnpm ${ command } --help` , {
163178 encoding : 'utf8' ,
164179 timeout : 500 ,
165180 } ) ;
@@ -174,7 +189,8 @@ export function loadDynamicOptionsSync(cmd: any, command: string): void {
174189}
175190
176191// we setup the lazy option loading for a command
177- function setupLazyOptionLoading ( cmd : any , command : string ) : void {
192+
193+ function setupLazyOptionLoading ( cmd : LazyCommand , command : string ) : void {
178194 cmd . _lazyCommand = command ;
179195 cmd . _optionsLoaded = false ;
180196
0 commit comments