Skip to content

Commit

Permalink
fix(cli): add pnpm detection to command suggestions (#1989)
Browse files Browse the repository at this point in the history
  • Loading branch information
anbernar authored Aug 9, 2024
1 parent e460f1d commit 287a688
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions packages/cli/src/api/help.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Detect where's is the command lingui extract or lingui compile
* and how is being run (npm, yarn) and construct help
* Detect where is the command lingui extract or lingui compile
* and how is being run (npm, yarn, pnpm) and construct help
* for follow-up commands based on that.
*
* Example:
Expand All @@ -12,6 +12,10 @@
* ...
* (use "yarn lingui compile" to compile catalogs for production)
*
* $ pnpm run extract
* ...
* (use "pnpm run compile" to compile catalogs for production)
*
* $ npm run extract
* ...
* (use "npm run compile" to compile catalogs for production)
Expand All @@ -34,10 +38,25 @@ export function helpRun(command: string) {
}
}

const isYarn =
process.env.npm_config_user_agent &&
process.env.npm_config_user_agent.includes("yarn")
const runCommand = isYarn ? "yarn" : "npm run"
const runCommand = runCommandFrom(process.env.npm_config_user_agent)

return `${runCommand} ${command}`
}

function runCommandFrom(userAgent: string | undefined): string {
const defaultRunCommand = "npm run"

if (!userAgent) {
return defaultRunCommand
}

if (userAgent.includes("yarn")) {
return "yarn"
}

if (userAgent.includes("pnpm")) {
return "pnpm run"
}

return defaultRunCommand
}

0 comments on commit 287a688

Please sign in to comment.