Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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