Skip to content

Commit c97bfc8

Browse files
committed
node: add fiddle-yarn-berry showcase
1 parent 20f5fbb commit c97bfc8

File tree

7 files changed

+159
-1
lines changed

7 files changed

+159
-1
lines changed

node/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ required, however, you can disable it explicitly via `--no-xdg-layout`.
1111
## Requirements
1212

1313
- flatpak-builder 1.1.2 or newer
14-
- Python 3.9+.
14+
- Python 3.11+.
1515
- [pipx](https://pypa.github.io/pipx/) (recommended) or
1616
[pip](https://pip.pypa.io/en/stable/) (both of these are usually available in
1717
your distro repositories, the latter is often included with Python installs).
@@ -40,6 +40,9 @@ There are two examples provided for how to use flatpak-node-generator:
4040
- `webpack-quick-start` - A Flatpak of
4141
[electron-webpack-quick-start](https://github.com/electron-userland/electron-webpack-quick-start).
4242
It uses yarn for package management and electron-builder + webpack.
43+
- `fiddle-yarn-berry` - A Flatpak of
44+
[electron-fiddle](https://github.com/electron/fiddle.git). It uses yarn/berry for
45+
package management and a rather basic Electron workflow.
4346

4447
Both manifests have comments to highlight their differences, so you can mix and match to e.g.
4548
get npm with electron-builder.

node/fiddle-yarn-berry/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/yarn.lock
2+
/generated-sources.json
3+
/build

node/fiddle-yarn-berry/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# vanilla-quick-start
2+
3+
Showcases building a Flatpak of [electron-fiddle](https://github.com/electron/fiddle.git)
4+
5+
To create generated-sources.json run:
6+
7+
```sh
8+
./gen.sh
9+
```
10+
11+
## Run app in Fiddle
12+
Add `--no-sandbox` to `Prefrences -> Execution -> Electron Flags`

node/fiddle-yarn-berry/gen.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
dir="$(dirname $(realpath $0))"
4+
commit=98c0605f804df86df8636a477515bbe178cd3943
5+
6+
pushd "$dir/.."
7+
curl -L "https://github.com/electron/fiddle/raw/$commit/yarn.lock" > "$dir/yarn.lock"
8+
poetry run flatpak-node-generator yarn -o "$dir/generated-sources.json" "$dir/yarn.lock"
9+
popd
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
app-id: org.electronjs.fiddle
2+
runtime: org.freedesktop.Platform
3+
runtime-version: '25.08'
4+
sdk: org.freedesktop.Sdk
5+
# Use the Electron 2 BaseApp, which adds several common libraries we'll need.
6+
base: org.electronjs.Electron2.BaseApp
7+
base-version: '25.08'
8+
separate-locales: false
9+
# Add the Node SDK extension.
10+
sdk-extensions:
11+
- org.freedesktop.Sdk.Extension.node24
12+
command: fiddle
13+
finish-args:
14+
# These three lines add the permissions needed for graphics.
15+
- --device=dri
16+
- --share=ipc
17+
- --socket=x11
18+
- --socket=wayland
19+
# Sound access.
20+
- --socket=pulseaudio
21+
# Network access.
22+
- --share=network
23+
# If you need to access the filesystem, also add:
24+
# - --filesystem=home
25+
modules:
26+
# Now is the quickstart module.
27+
- name: fiddle
28+
buildsystem: simple
29+
build-options:
30+
# Add the node bin directory.
31+
append-path: /usr/lib/sdk/node24/bin
32+
env:
33+
XDG_CACHE_HOME: /run/build/fiddle/flatpak-node/cache
34+
npm_config_nodedir: /usr/lib/sdk/node24
35+
# more verbose
36+
YARN_ENABLE_INLINE_BUILDS: '1'
37+
# disable telemetry
38+
YARN_ENABLE_TELEMETRY: '0'
39+
# disable network access
40+
YARN_ENABLE_NETWORK: '0'
41+
# disable global cache
42+
YARN_ENABLE_GLOBAL_CACHE: '0'
43+
# set yarn global folder
44+
YARN_GLOBAL_FOLDER: /run/build/fiddle/flatpak-node/yarn-berry
45+
build-commands:
46+
# print yarn basic info
47+
- yarn config
48+
# setup yarn for flatpak
49+
- yarn plugin import $FLATPAK_BUILDER_BUILDDIR/flatpak-node/flatpak-yarn.js
50+
# prepare yarn cache
51+
- yarn convertToZip $(which yarn)
52+
# Install the packages from our offline cache.
53+
# --prefix= is the path to our subdirectory (see the electron-quick-start source below).
54+
- yarn install
55+
56+
- yarn run package
57+
- mv out/Electron* /app/ElectronFiddle
58+
- install -Dm755 fiddle.sh /app/bin/fiddle
59+
sources:
60+
- type: git
61+
url: https://github.com/electron/fiddle.git
62+
commit: 98c0605f804df86df8636a477515bbe178cd3943
63+
64+
# Add the flatpak-node-generator generated sources.
65+
- generated-sources.json
66+
# Our runner script.
67+
- type: script
68+
dest-filename: fiddle.sh
69+
commands:
70+
# We need to wrap the main binary with Zypak in order for sandboxing
71+
# to work. Without this, we'll get errors about the "SUID sandbox
72+
# helper binary".
73+
- exec zypak-wrapper /app/ElectronFiddle/electron-fiddle
74+
75+
# Sources below are only for fiddle, as it wants to fetch these online
76+
# prefetch for offline
77+
- type: file
78+
url: https://releases.electronjs.org/releases.json
79+
sha256: badb8576b81b4e43716aa3314724c9563d42eb4140cf06000201ad7a31067dc4
80+
# replace to use release.json prefetched
81+
- type: file
82+
path: replace/fetch-releases.ts
83+
dest-filename: fetch-releases.ts
84+
dest: tools
85+
# used embed contributors.json
86+
- type: file
87+
path: replace/contributors.json
88+
dest-filename: contributors.json
89+
dest: static
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"url": "https://github.com/felixrieseberg",
4+
"api": "https://api.github.com/users/felixrieseberg",
5+
"login": "felixrieseberg",
6+
"avatar": "https://avatars.githubusercontent.com/u/1426799?v=4",
7+
"name": "Felix Rieseberg",
8+
"bio": "🙇 ✨🌳 ",
9+
"location": "San Francisco"
10+
},
11+
{
12+
"url": "https://github.com/dsanders11",
13+
"api": "https://api.github.com/users/dsanders11",
14+
"login": "dsanders11",
15+
"avatar": "https://avatars.githubusercontent.com/u/5820654?v=4",
16+
"name": "David Sanders",
17+
"bio": null,
18+
"location": "Santa Barbara, CA"
19+
}
20+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as fs from 'node:fs';
2+
import * as path from 'node:path';
3+
4+
const outputFile = path.join(__dirname, '..', 'static', 'releases.json');
5+
6+
export async function populateReleases() {
7+
const sourceDir = process.env.FLATPAK_BUILDER_BUILDDIR;
8+
9+
if (!sourceDir) {
10+
throw new Error('FLATPAK_BUILDER_BUILDDIR is not set.');
11+
}
12+
13+
const inputFile = path.resolve(sourceDir, 'releases.json');
14+
const data = await fs.promises.readFile(inputFile, 'utf-8');
15+
await fs.promises.writeFile(outputFile, data);
16+
}
17+
18+
if (require.main === module) {
19+
(async () => {
20+
await populateReleases();
21+
})();
22+
}

0 commit comments

Comments
 (0)