How can i build a flatpak from a bunjs app

so, i am kind of in the worst situation right now,
i have created a monorepo project for a tauri app using a new tool called Bun as the package manager. i wanted to build it with inside of the manifest workflow in order to submit to flathub

Hit and Trial with Bun

so, i am utilizing the bun’s workspaces (which is simmilar to npm workspaces) and bun’s catalogs (there no npm/yarn counter to that)

so, my goal was to create a flatpak builder workflow that can build a tauri app managed by bun. but the thing is that i can’t figure out how to get the nodejs dependecies to be pre downloaded in a way that bun install can recognize it when running in the manifest workflow.

to generate the node-sources.json, i used a new tool called Flatpak Bun Generator, which can take a bun.lock file and generate a node-sources.json file which i can provide to the flatpak builder.

so this is by best attempt that didn’t work for bun

id: io.github.keshav_writes_code.cherit

runtime: org.gnome.Platform
runtime-version: "49"
sdk: org.gnome.Sdk

command: cherit
finish-args:
  - --socket=wayland
  - --socket=fallback-x11
  - --device=dri
  - --share=ipc
  - --env=GTK_USE_PORTAL=1
sdk-extensions:
  - org.freedesktop.Sdk.Extension.node24
  - org.freedesktop.Sdk.Extension.rust-stable
build-options:
  append-path: /usr/lib/sdk/node24/bin:/usr/lib/sdk/rust-stable/bin:/app/bin

modules:
  - name: bun
    buildsystem: simple
    build-commands:
      - install -Dm755 bun /app/bin/bun
    sources:
      - type: archive
        url: https://github.com/oven-sh/bun/releases/download/bun-v1.3.11/bun-linux-x64.zip
        sha256: 8611ba935af886f05a6f38740a15160326c15e5d5d07adef966130b4493607ed
        
  - name: cherit
    buildsystem: simple
    build-options:
      env:
        CARGO_HOME: /run/build/cherit/cargo
        XDG_CACHE_HOME: /run/build/cherit/flatpak-node/cache
        CARGO_NET_OFFLINE: "true"
        BUN_INSTALL_CACHE_DIR: /run/build/cherit/flatpak-node/npm-cache
    sources:
      - type: git
        url: https://github.com/Keshav-writes-code/Cherit.git
        branch: refac/site-seperation

      - cargo-sources.json
      - node-sources.json

    build-commands:
      - bun i
      - bun run tauri build --workspace=cherit -- --no-bundle

      - install -Dm755 -t /app/bin/ apps/app/src-tauri/target/release/cherit
      - install -Dm644 -t /app/share/metainfo/ apps/app/distribute/linux/flatpak/io.github.keshav_writes_code.cherit.metainfo.xml
      - install -Dm644 -t /app/share/applications/ apps/app/distribute/linux/flatpak/io.github.keshav_writes_code.cherit.desktop

      - desktop-file-edit --set-key=Icon --set-value="io.github.keshav_writes_code.cherit"
        /app/share/applications/io.github.keshav_writes_code.cherit.desktop

      # Install Icons
      - install -Dm644 apps/app/src-tauri/icons/32x32.png /app/share/icons/hicolor/32x32/apps/io.github.keshav_writes_code.cherit.png
      - install -Dm644 apps/app/src-tauri/icons/64x64.png /app/share/icons/hicolor/64x64/apps/io.github.keshav_writes_code.cherit.png
      - install -Dm644 apps/app/src-tauri/icons/128x128.png /app/share/icons/hicolor/128x128/apps/io.github.keshav_writes_code.cherit.png
      - install -Dm644 apps/app/src-tauri/icons/128x128@2x.png /app/share/icons/hicolor/256x256/apps/io.github.keshav_writes_code.cherit.png

Hit and Trial with NPM

i also tried to simply do a npm i --offline instead of bun install in the builder workflow
but in my package.json, some of the dependecies use the catalog feature from bun :

package.json :

{
  "name": "cherit",
  ...
  ...
  "workspaces": {
    "packages": [
      "apps/*",
    ],
    "catalog": {      <-- Define shared dependencies in bun's root package.json  
      "@codemirror/commands": "^6.10.1",
      "@codemirror/lang-markdown": "^6.5.0",
      "@codemirror/language": "^6.12.1",
    }
  }
  ...
  ...
}

apps/app/package.json :

{
    ...
    "@codemirror/commands": "catalog:", <-- reference the shared depenecy
    "@codemirror/lang-markdown": "catalog:",
    "@codemirror/language": "catalog:",
    ...
}

Other Ideas

i also though about giving the manifest a tar.gz of the node_modules folder and then just extracting in and running the usual tauri build command, but the problem is

  • its probably highly discouraged by flathub
  • some packages are platform speciifc (x64. Arm64, etc).