Skip to content

Commit 1776543

Browse files
authored
fix: Check for package.json file to get package manager (#282)
1 parent 2c629f9 commit 1776543

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

.changes/fix-cargo.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri-vscode': patch
3+
---
4+
5+
Fix extension trying to use npm instead of cargo.

src/extension.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -413,23 +413,30 @@ function __getNpmCommand() {
413413
}
414414

415415
function __getPackageManagerCommand(projectPath: string): string | null {
416-
const m = __usePnpm(projectPath)
417-
? 'pnpm'
418-
: __useYarn(projectPath)
419-
? 'yarn'
420-
: __useNpm(projectPath)
421-
? __getNpmCommand()
422-
: __useCargo()
423-
? 'cargo'
424-
: null
425-
426-
if (!m) {
427-
vscode.window.showErrorMessage(
428-
"Couldn't detect package manager for current project. Try running Tauri: Init Command"
416+
const isNodeProject = __isNodeProject(projectPath)
417+
if (isNodeProject) {
418+
if (__usePnpm(projectPath)) return 'pnpm'
419+
if (__useYarn(projectPath)) return 'yarn'
420+
421+
const packageJson = JSON.parse(
422+
fs.readFileSync(`${projectPath}/package.json`, 'utf8')
423+
)
424+
425+
if (
426+
__useNpm(projectPath) &&
427+
packageJson.script &&
428+
packageJson.script['tauri']
429429
)
430+
return __getNpmCommand()
430431
}
431432

432-
return m
433+
if (__useCargo()) return 'cargo'
434+
435+
vscode.window.showErrorMessage(
436+
"Couldn't detect package manager for current project. Try running Tauri: Init Command"
437+
)
438+
439+
return null
433440
}
434441

435442
interface RunOptions {

0 commit comments

Comments
 (0)