Skip to content

Commit d8c0df0

Browse files
committed
feat(snap): environment option
1 parent 61a9fc5 commit d8c0df0

File tree

4 files changed

+106
-6
lines changed

4 files changed

+106
-6
lines changed

packages/electron-builder-lib/src/options/SnapOptions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions {
88
*/
99
readonly confinement?: "devmode" | "strict" | "classic" | null
1010

11+
/**
12+
* The custom environment. Defaults to `{"TMPDIR: "$XDG_RUNTIME_DIR"}`. If you set custom, it will be merged with default.
13+
*/
14+
readonly environment?: object | null
15+
// { [key: string]: string } Our scheme generator cannot validate this type
16+
1117
/**
1218
* The 78 character long summary. Defaults to [productName](configuration.md#Configuration-productName).
1319
*/

packages/electron-builder-lib/src/targets/snap.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ export default class SnapTarget extends Target {
7070

7171
snap.apps = {
7272
[snap.name]: {
73-
command: `env TMPDIR=$XDG_RUNTIME_DIR desktop-launch $SNAP/${packager.executableName}`,
74-
plugs: replaceDefault(options.plugs, ["desktop", "desktop-legacy", "home", "x11", "unity7", "browser-support", "network", "gsettings", "pulseaudio", "opengl"])
73+
command: `desktop-launch $SNAP/${packager.executableName}`,
74+
environment: {
75+
TMPDIR: "$XDG_RUNTIME_DIR",
76+
...options.environment,
77+
},
78+
plugs: replaceDefault(options.plugs, ["desktop", "desktop-legacy", "home", "x11", "unity7", "browser-support", "network", "gsettings", "pulseaudio", "opengl"]),
7579
}
7680
}
7781

test/out/linux/__snapshots__/snapTest.js.snap

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,71 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`custom env 1`] = `
4+
Object {
5+
"apps": Object {
6+
"sep": Object {
7+
"command": "desktop-launch $SNAP/sep",
8+
"environment": Object {
9+
"FOO": "bar",
10+
"TMPDIR": "$XDG_RUNTIME_DIR",
11+
},
12+
"plugs": Array [
13+
"desktop",
14+
"desktop-legacy",
15+
"home",
16+
"x11",
17+
"unity7",
18+
"browser-support",
19+
"network",
20+
"gsettings",
21+
"pulseaudio",
22+
"opengl",
23+
],
24+
},
25+
},
26+
"confinement": "strict",
27+
"description": "Test Application (test quite “ #378)",
28+
"grade": "stable",
29+
"icon": "snap/gui/icon.png",
30+
"name": "sep",
31+
"parts": Object {
32+
"app": Object {
33+
"after": Array [
34+
"desktop-gtk2",
35+
],
36+
"plugin": "dump",
37+
"stage-packages": Array [
38+
"libasound2",
39+
"libgconf2-4",
40+
"libnotify4",
41+
"libnspr4",
42+
"libnss3",
43+
"libpcre3",
44+
"libpulse0",
45+
"libxss1",
46+
"libxtst6",
47+
],
48+
},
49+
},
50+
"summary": "Sep",
51+
"version": "1.1.0",
52+
}
53+
`;
54+
55+
exports[`custom env 2`] = `
56+
Object {
57+
"linux": Array [],
58+
}
59+
`;
60+
361
exports[`default stagePackages 1`] = `
462
Object {
563
"apps": Object {
664
"sep": Object {
7-
"command": "env TMPDIR=$XDG_RUNTIME_DIR desktop-launch $SNAP/sep",
65+
"command": "desktop-launch $SNAP/sep",
66+
"environment": Object {
67+
"TMPDIR": "$XDG_RUNTIME_DIR",
68+
},
869
"plugs": Array [
970
"desktop",
1071
"desktop-legacy",
@@ -58,7 +119,10 @@ exports[`default stagePackages 3`] = `
58119
Object {
59120
"apps": Object {
60121
"sep": Object {
61-
"command": "env TMPDIR=$XDG_RUNTIME_DIR desktop-launch $SNAP/sep",
122+
"command": "desktop-launch $SNAP/sep",
123+
"environment": Object {
124+
"TMPDIR": "$XDG_RUNTIME_DIR",
125+
},
62126
"plugs": Array [
63127
"desktop",
64128
"desktop-legacy",
@@ -114,7 +178,10 @@ exports[`default stagePackages 5`] = `
114178
Object {
115179
"apps": Object {
116180
"sep": Object {
117-
"command": "env TMPDIR=$XDG_RUNTIME_DIR desktop-launch $SNAP/sep",
181+
"command": "desktop-launch $SNAP/sep",
182+
"environment": Object {
183+
"TMPDIR": "$XDG_RUNTIME_DIR",
184+
},
118185
"plugs": Array [
119186
"custom",
120187
"desktop",
@@ -170,7 +237,10 @@ exports[`default stagePackages 7`] = `
170237
Object {
171238
"apps": Object {
172239
"sep": Object {
173-
"command": "env TMPDIR=$XDG_RUNTIME_DIR desktop-launch $SNAP/sep",
240+
"command": "desktop-launch $SNAP/sep",
241+
"environment": Object {
242+
"TMPDIR": "$XDG_RUNTIME_DIR",
243+
},
174244
"plugs": Array [
175245
"foo1",
176246
"desktop",

test/src/linux/snapTest.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,23 @@ test.ifAll.ifDevOrLinuxCi("default stagePackages", async () => {
4242
})
4343
}
4444
})
45+
46+
test.ifAll.ifDevOrLinuxCi("custom env", app({
47+
targets: Platform.LINUX.createTarget("snap"),
48+
config: {
49+
extraMetadata: {
50+
name: "sep",
51+
},
52+
productName: "Sep",
53+
snap: {
54+
environment: {
55+
FOO: "bar",
56+
},
57+
}
58+
},
59+
effectiveOptionComputed: async ({snap}) => {
60+
delete snap.parts.app.source
61+
expect(snap).toMatchSnapshot()
62+
return true
63+
},
64+
}))

0 commit comments

Comments
 (0)