Skip to content

Make Tauri pre-build/dev hooks resilient to script location#185

Merged
Jordonbc merged 2 commits intoDevfrom
codex/github-mention-build-script-issue
Mar 19, 2026
Merged

Make Tauri pre-build/dev hooks resilient to script location#185
Jordonbc merged 2 commits intoDevfrom
codex/github-mention-build-script-issue

Conversation

@Jordonbc
Copy link
Collaborator

Motivation

  • Ensure Backend/scripts/run-tauri-before-command.js is found and executed when running Tauri commands regardless of current working directory and provide a clear error if it cannot be located.

Description

  • Replaced build.beforeDevCommand and build.beforeBuildCommand in Backend/tauri.conf.json with inline node -e snippets that search multiple candidate paths, resolve them with path.resolve, and check existence with fs.existsSync before running the script via spawnSync.
  • The inline script prints an error and exits non-zero when the target script is missing and forwards the executed script's exit code when present.

Testing

  • Ran tauri dev which invoked the new beforeDevCommand and completed successfully.
  • Ran tauri build which invoked the new beforeBuildCommand and completed successfully.

Codex Task

@github-actions
Copy link

PR Review: Tauri pre-build/dev hooks resilient to script location

Summary

The PR replaces simple node scripts/run-tauri-before-command.js dev commands with inline Node.js scripts that search multiple candidate paths to locate the script.

Issues Found

1. Code Duplication (Maintainability)
The inline script is duplicated with only 'dev' vs 'build' as the difference. This violates DRY and makes future changes harder.

2. Minified/Compressed Code
The inline scripts are minified with no spaces, making them nearly impossible to read or debug when something goes wrong.

3. The Script Already Handles Path Resolution
Looking at Backend/scripts/run-tauri-before-command.js:14-18, the script already uses __dirname to calculate paths relative to its own location. The wrapper's path searching logic is redundant since run-tauri-before-command.js doesn't depend on process.cwd().

4. Missing Error Handling
The spawnSync call doesn't handle result.error, which could occur if execution fails for reasons other than non-zero exit code.

Recommendations

  1. If the goal is resilience to cwd: Consider documenting that Tauri commands should be run from the project root (or Backend/), and use a simple script wrapper instead of minified inline code.

  2. If inline scripts are preferred: Factor the common logic into a small helper script like Backend/scripts/resolve-and-run.js, then use: node -e "require('./scripts/resolve-and-run')('dev')".

  3. Add error handling for result.error in the spawnSync call.

  4. For Windows compatibility: Consider using npm exec or npx instead of bare node command.

New%20session%20-%202026-03-19T04%3A02%3A53.545Z
opencode session  |  github run

@Jordonbc Jordonbc merged commit f5ddf81 into Dev Mar 19, 2026
7 checks passed
Jordonbc added a commit that referenced this pull request Mar 19, 2026
Merge pull request #185 from Open-VCS/codex/github-mention-build-script-issue

Make Tauri pre-build/dev hooks resilient to script location
@Jordonbc Jordonbc deleted the codex/github-mention-build-script-issue branch March 19, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant