fix: Check for package.json file to get package manager (#282)

This commit is contained in:
Soorya U
2025-01-22 06:30:50 +05:30
committed by GitHub
parent 2c629f94a5
commit 1776543f58
2 changed files with 25 additions and 13 deletions

5
.changes/fix-cargo.md Normal file
View File

@@ -0,0 +1,5 @@
---
'tauri-vscode': patch
---
Fix extension trying to use npm instead of cargo.

View File

@@ -413,23 +413,30 @@ function __getNpmCommand() {
} }
function __getPackageManagerCommand(projectPath: string): string | null { function __getPackageManagerCommand(projectPath: string): string | null {
const m = __usePnpm(projectPath) const isNodeProject = __isNodeProject(projectPath)
? 'pnpm' if (isNodeProject) {
: __useYarn(projectPath) if (__usePnpm(projectPath)) return 'pnpm'
? 'yarn' if (__useYarn(projectPath)) return 'yarn'
: __useNpm(projectPath)
? __getNpmCommand()
: __useCargo()
? 'cargo'
: null
if (!m) { const packageJson = JSON.parse(
vscode.window.showErrorMessage( fs.readFileSync(`${projectPath}/package.json`, 'utf8')
"Couldn't detect package manager for current project. Try running Tauri: Init Command"
) )
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 { interface RunOptions {