Skip to content

Commit

Permalink
fix: Check for package.json file to get package manager (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
soorya-u authored Jan 22, 2025
1 parent 2c629f9 commit 1776543
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-cargo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-vscode': patch
---

Fix extension trying to use npm instead of cargo.
35 changes: 21 additions & 14 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,23 +413,30 @@ function __getNpmCommand() {
}

function __getPackageManagerCommand(projectPath: string): string | null {
const m = __usePnpm(projectPath)
? 'pnpm'
: __useYarn(projectPath)
? 'yarn'
: __useNpm(projectPath)
? __getNpmCommand()
: __useCargo()
? 'cargo'
: null

if (!m) {
vscode.window.showErrorMessage(
"Couldn't detect package manager for current project. Try running Tauri: Init Command"
const isNodeProject = __isNodeProject(projectPath)
if (isNodeProject) {
if (__usePnpm(projectPath)) return 'pnpm'
if (__useYarn(projectPath)) return 'yarn'

const packageJson = JSON.parse(
fs.readFileSync(`${projectPath}/package.json`, 'utf8')
)

if (
__useNpm(projectPath) &&
packageJson.script &&
packageJson.script['tauri']
)
return __getNpmCommand()
}

return m
if (__useCargo()) return 'cargo'

vscode.window.showErrorMessage(
"Couldn't detect package manager for current project. Try running Tauri: Init Command"
)

return null
}

interface RunOptions {
Expand Down

0 comments on commit 1776543

Please sign in to comment.