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 {
const m = __usePnpm(projectPath)
? 'pnpm'
: __useYarn(projectPath)
? 'yarn'
: __useNpm(projectPath)
? __getNpmCommand()
: __useCargo()
? 'cargo'
: null
const isNodeProject = __isNodeProject(projectPath)
if (isNodeProject) {
if (__usePnpm(projectPath)) return 'pnpm'
if (__useYarn(projectPath)) return 'yarn'
if (!m) {
vscode.window.showErrorMessage(
"Couldn't detect package manager for current project. Try running Tauri: Init Command"
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 {