Skip to content

fix(cli): Fix mixup of TAURI_APP_PATH and TAURI_FRONTEND_PATH - #11492

Merged
lucasfernog merged 5 commits into
tauri-apps:devfrom
regexident:fix-tauri-app-and-src-dir-resolution
Oct 27, 2024
Merged

fix(cli): Fix mixup of TAURI_APP_PATH and TAURI_FRONTEND_PATH#11492
lucasfernog merged 5 commits into
tauri-apps:devfrom
regexident:fix-tauri-app-and-src-dir-resolution

Conversation

@regexident

@regexident regexident commented Oct 25, 2024

Copy link
Copy Markdown
Contributor

This PR aims to fix a mixup that happened prior to merging #11258, as a result of which the newly introduced env vars TAURI_APP_PATH and TAURI_FRONTEND_PATH have to be used incorrectly (i.e. swapped), in order for path customization to work:

$ tree .

tauri-custom-structure
├── frontend
│   ├── package.json
│   ├── src
│   └── ...
└── tauri
    ├── Cargo.toml
    ├── src
    ├── tauri.config.json
    └── ...
$ cd ./frontend
$ pnpm tauri dev

thread '<unnamed>' panicked at crates/tauri-cli/src/helpers/app_paths.rs:117:5:
Couldn't recognize the `TAURI_FRONTEND_PATH` folder as a Tauri project. It must contain a `tauri.conf.json`, `tauri.conf.json5` or `Tauri.toml` file in any subfolder.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
 ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL  Command was killed with SIGABRT (Aborted): tauri dev

The cause of this unfortunate last-minute mixup came from a rename aimed at avoiding confusion, applied in 8af2d51, which I unfortunately didn't catch from @lucasfernog's description:

I've renamed TAURI_SRC_DIR to TAURI_FRONTEND_PATH and TAURI_APP_DIR to TAURI_APP_PATH to be more clear on what path does the env var refer to, what do you think? app and src are too obscure IMO, as both the frontend and the tauri app directories contain the "app" and the "src" 😂

Originally posted by @lucasfernog in #11258 (comment)

This PR fixes this mixup.


The initial names' use of "app" + "src" were potentially confusing as one could consider both, the frontend and the tauri directories to be "app" directories, which in turn both contain "src" sub-directories. Not good.

I fear however that (even with this fix in place) the rename to "frontend" + "app" might have just replaced one source of confusion with another, at least within tauri-cli's own code:

Looking into /crates/tauri-cli/src/* it seems as if the name most-commonly used used for the directory that TAURI_FRONTEND_PATH aims to provide a customization hook for (i.e. the directory containing package.json), is app_dir/app_path, while the corresponding name for TAURI_APP_PATH (i.e. the directory containing tauri.config.toml) tends to be tauri_dir/tauri_path: The exact opposite of each other.

As such I took the liberty of applying a few more renames (app_dir/app_path => frontend_dir/frontend_path) to re-align things within tauri-cli/src (but kept them in separate PRs for easier code review).


I have tested the patched cargo-tauri tool on a real-world project and it works, again.
Where by "it works" I mean that the following works:

If you do provide appropriate env vars, then you can now run the command from the project's "tauri" directory, despite the project having a non-standard structure:

# Provide appropriate tauri path env vars:
export TAURI_APP_PATH="."
export TAURI_FRONTEND_PATH="../frontend" 

# Run `cargo tauri` from within the "tauri" directory:
cd <project>/tauri 
cargo tauri dev

    Running BeforeDevCommand (`pnpm dev`)

> tauri-custom-structure@0.1.0 dev <SNIP>/tauri-custom-structure/frontend
> vite

    ...
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.87s

(Worth noting: Running cargo tauri dev from within the tauri directory has always worked, even before the introduction of such env vars, if you made some changes to the beforeDevCommand and beforeBuildCommand tauri configs. As such it used to be how we would build/run out tauri app.)

Likewise, if you do provide appropriate env vars, then you can now even run the command from the project's root(!) directory:

# Provide appropriate tauri path env vars:
export TAURI_APP_PATH="./tauri"
export TAURI_FRONTEND_PATH="./frontend" 

# Run `cargo tauri` from within the root(!) directory:
cd <project>
cargo tauri dev

    Running BeforeDevCommand (`pnpm dev`)

> tauri-custom-structure@0.1.0 dev <SNIP>/tauri-custom-structure/frontend
> vite

    ...
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.65s

Likewise running pnpm tauri from within the "frontend" directory should work, too:

# Provide appropriate tauri path env vars:
export TAURI_APP_PATH="./tauri"
export TAURI_FRONTEND_PATH="./frontend" 

# Run `pnpm tauri` from within the "frontend" directory:
cd <project>/frontend
pnpm tauri dev

I don't however know how to patch the node side of cargo tauri, so I'll have to leave any testing of that to you.

@regexident
regexident requested a review from a team as a code owner October 25, 2024 12:37
@regexident

regexident commented Oct 25, 2024

Copy link
Copy Markdown
Contributor Author

These are the exact steps I followed to test the PR on a minimal dummy project, with the following custom structure:

$ tree .

tauri-custom-structure
├── frontend
│   ├── package.json
│   ├── src
│   └── ...
└── tauri
    ├── Cargo.toml
    ├── src
    ├── tauri.config.json
    └── ...
  1. Create vanilla tauri project:

    $ pnpm create tauri-app
    
    ✔ Project name · tauri-custom-structure
    ✔ Identifier · com.tauri-custom-structure.app
    ✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, deno, bun)
    ✔ Choose your package manager · pnpm
    ✔ Choose your UI template · Vanilla
    ✔ Choose your UI flavor · TypeScript
    
    Template created!
    
  2. Move all frontend-related files into ./frontend:

    mkdir frontend
    mv index.html package.json src tsconfig.json vite.config.ts frontend/
    
  3. Rename src-tauri to `tauri:

    mv src-tauri tauri
    
  4. Install npm packages:

    cd ./frontend
    pnpm install
    
  5. Run the cargo tauri commands as shown above.

    export TAURI_APP_PATH="./tauri"
    export TAURI_FRONTEND_PATH="./frontend" 
    
    cd <project>
    cargo tauri dev
    

@github-actions

github-actions Bot commented Oct 25, 2024

Copy link
Copy Markdown
Contributor

Package Changes Through 704bc06

There are 6 changes which include tauri with patch, tauri-bundler with patch, tauri-cli with patch, @tauri-apps/cli with patch, tauri-runtime-wry with patch, @tauri-apps/api with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
@tauri-apps/api 2.0.3 2.0.4
tauri-bundler 2.0.4 2.0.5
tauri-runtime-wry 2.1.2 2.1.3
tauri 2.0.6 2.0.7
@tauri-apps/cli 2.0.4 2.0.5
tauri-cli 2.0.4 2.0.5

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@regexident
regexident force-pushed the fix-tauri-app-and-src-dir-resolution branch from 0947a3b to 704bc06 Compare October 25, 2024 17:49

@lucasfernog lucasfernog left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice catch, I didn't realize i swapped the vars :/

@lucasfernog
lucasfernog merged commit ac22950 into tauri-apps:dev Oct 27, 2024
@regexident
regexident deleted the fix-tauri-app-and-src-dir-resolution branch October 27, 2024 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants