tauri-apps / tauri-docs

The source for all Tauri project documentation.
https://tauri.app
MIT License
821 stars 617 forks source link

[bug] Nested resources not being bundled correctly #2708

Closed samrg472 closed 1 month ago

samrg472 commented 1 month ago

Describe the bug

When creating installers, tested only on Windows, nsis and msi targets do not install all folders recursively specified under resources with the glob pattern. In the reproduction, the library folder is excluded from the installers.

Reproduction

Folder layout:

root/
├─ resources/
│  ├─ data.db
│  ├─ library/
│  │  ├─ static.json
├─ src/
├─ src-tauri/
│  ├─ tauri.conf.json

Relevant config for tauri.conf.json

  "bundle": {
    "active": true,
    "targets": ["nsis", "msi"],
    "resources": ["../resources/*"],
    // ...
  },

Run tauri build to generate the installers.

Expected behavior

I expect ../resources/* to recursively install all files and folders during installation. However, only top-level files are installed, e.g. _up_/resources/data.db.

Files expected to be installed:

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.19045 x86_64 (X64)
    ✔ WebView2: 128.0.2739.67
    ✔ MSVC: Visual Studio Community 2022
    ✔ rustc: 1.81.0 (eeb90cda1 2024-09-04)
    ✔ cargo: 1.81.0 (2dbb1af80 2024-08-20)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.17.0
    - npm: 10.8.1
    - bun: 1.1.27

[-] Packages
    - tauri 🦀: 2.0.0-rc.11
    - tauri-build 🦀: 2.0.0-rc.10
    - wry 🦀: 0.43.1
    - tao 🦀: 0.30.0
    - @tauri-apps/api : 2.0.0-rc.4
    - @tauri-apps/cli : 2.0.0-rc.13

[-] Plugins
    - tauri-plugin-shell 🦀: 2.0.0-rc.3
    - @tauri-apps/plugin-shell : not installed!
    - tauri-plugin-updater 🦀: 2.0.0-rc.3
    - @tauri-apps/plugin-updater : 2.0.0-rc.2

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: Vue.js (Quasar)
    - bundler: Vite

Additional context

This used to work on older versions of v2, I'm not sure which version broke this change since my last app release was with version v2-beta.23.

Workaround

  "bundle": {
    // ...
    "resources": ["../resources/*", "../resources/library/*"]
  },
FabianLars commented 1 month ago

Try ** instead. One * in glob patterns typically only means one level.

And yes, in prior Tauris versions * may have been enough but this was "fixed". We should update the docs to explain this I guess :)

samrg472 commented 1 month ago

Try ** instead. One * in glob patterns typically only means one level.

And yes, in prior Tauris versions * may have been enough but this was "fixed". We should update the docs to explain this I guess :)

Forgot to mention, I did try this but I get an error during building.

Build output:

glob pattern ../resources/** path not found or didn't match any files.
    Error failed to build app: failed to build app

I also tried with the path relative to package.json which is where I run the build command.

Build output:

glob pattern ./resources/** path not found or didn't match any files.
    Error failed to build app: failed to build app

Slightly off-topic:

Interestingly enough, if I force an error, it directs me with a helpful message.

Build output:

Pattern syntax error near position 15: wildcards are either regular `*` or recursive `**`: Pattern syntax error near position 15: wildcards are either regular `*` or recursive `**`
    Error failed to build app: failed to build app
FabianLars commented 1 month ago

So I did try ** on Tuesday for another documentation guide (Info.plist localization) and there it worked so it's not completely broken at least.

I'll try your file layout when I'm not stuck with my phone (tomorrow).

And since you mentioned it, the paths are always relative to the tauri.conf.json file location.

FabianLars commented 1 month ago

Sorry for the delay, for your usecase ../resources/**/* should work which honestly makes no sense to me, ** should match files too (and it used to). I'll move this issue back to the tauri repo.

Edit: I assume i was still on an older tauri version when i tested it for the above comment :/

amrbashir commented 1 month ago

The correct value is ../resources/**/*, which matches bash globbing, you can test this by checking difference between echo ./dir/* or echo ./dir/** and echo ./dir/**/*

FabianLars commented 1 month ago

edit: lol you're right - i mixed up 2 different things

FabianLars commented 1 month ago

back to the docs repo then 👐

FabianLars commented 1 month ago

@amrbashir Do we have a way to keep the folder structure when using the object notation with globs? So conecpt wise something like this:

    "resources": {
      "../resources/*": "resources/*",
      "../resources/**/*": "resources/**/*"
    },

(using resources/ as a target only copies the files, not the folders - which is also a required logic so that's good)

FabianLars commented 1 month ago

ah okay, just "../resources/": "resources/" works which i didn't notice because rust didn't re-run the build script, therefore not copying the files in target (was still copied into the installer fine)

Some1and2-XC commented 4 weeks ago

Hey, I ran into a build issue that is because of files not being found.

error: failed to run custom build command for `package v0.0.0 (/some/path/package/src-tauri)`

Caused by:
  process didn't exit successfully: `/some/path/com_package-0df4798ccf11efa9/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=TAURI_CONFIG
  cargo:rerun-if-changed=tauri.conf.json
  cargo:rustc-check-cfg=cfg(desktop)
  cargo:rustc-cfg=desktop
  cargo:rustc-check-cfg=cfg(mobile)
  cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME=dev
  cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_PREFIX=com_package
  cargo:rustc-check-cfg=cfg(dev)
  cargo:rustc-cfg=dev
  cargo:PERMISSION_FILES_PATH=/some/path/app-manifest/__app__-permission-files
  cargo:rerun-if-changed=capabilities
  cargo:rustc-env=TAURI_ENV_TARGET_TRIPLE=x86_64-unknown-linux-gnu
  glob pattern bins/* path not found or didn't match any files.

I've run into so many build issues while trying to migrate so I assumed this was some incorrectly configured build environment, not the fact I have a bins/* directory that I need access to without files in it. I may be mistaken but I think in previous versions you didn't need any files here at all and this wasn't an error. Any chance this error can be improved by specifying it is probably a problem with my tauri.conf.json file with the values of bundle > resources? Or make it describe a bit better how to go about fixing this for the developer?

(Also sorry if this is the wrong place for this)

Thanks.