Skip to content

Commit

Permalink
feat(snap): environment option
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jan 30, 2018
1 parent 61a9fc5 commit d8c0df0
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/electron-builder-lib/src/options/SnapOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions {
*/
readonly confinement?: "devmode" | "strict" | "classic" | null

/**
* The custom environment. Defaults to `{"TMPDIR: "$XDG_RUNTIME_DIR"}`. If you set custom, it will be merged with default.
*/
readonly environment?: object | null
// { [key: string]: string } Our scheme generator cannot validate this type

/**
* The 78 character long summary. Defaults to [productName](configuration.md#Configuration-productName).
*/
Expand Down
8 changes: 6 additions & 2 deletions packages/electron-builder-lib/src/targets/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ export default class SnapTarget extends Target {

snap.apps = {
[snap.name]: {
command: `env TMPDIR=$XDG_RUNTIME_DIR desktop-launch $SNAP/${packager.executableName}`,
plugs: replaceDefault(options.plugs, ["desktop", "desktop-legacy", "home", "x11", "unity7", "browser-support", "network", "gsettings", "pulseaudio", "opengl"])
command: `desktop-launch $SNAP/${packager.executableName}`,
environment: {
TMPDIR: "$XDG_RUNTIME_DIR",
...options.environment,
},
plugs: replaceDefault(options.plugs, ["desktop", "desktop-legacy", "home", "x11", "unity7", "browser-support", "network", "gsettings", "pulseaudio", "opengl"]),
}
}

Expand Down
78 changes: 74 additions & 4 deletions test/out/linux/__snapshots__/snapTest.js.snap
Original file line number Diff line number Diff line change
@@ -1,10 +1,71 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`custom env 1`] = `
Object {
"apps": Object {
"sep": Object {
"command": "desktop-launch $SNAP/sep",
"environment": Object {
"FOO": "bar",
"TMPDIR": "$XDG_RUNTIME_DIR",
},
"plugs": Array [
"desktop",
"desktop-legacy",
"home",
"x11",
"unity7",
"browser-support",
"network",
"gsettings",
"pulseaudio",
"opengl",
],
},
},
"confinement": "strict",
"description": "Test Application (test quite “ #378)",
"grade": "stable",
"icon": "snap/gui/icon.png",
"name": "sep",
"parts": Object {
"app": Object {
"after": Array [
"desktop-gtk2",
],
"plugin": "dump",
"stage-packages": Array [
"libasound2",
"libgconf2-4",
"libnotify4",
"libnspr4",
"libnss3",
"libpcre3",
"libpulse0",
"libxss1",
"libxtst6",
],
},
},
"summary": "Sep",
"version": "1.1.0",
}
`;

exports[`custom env 2`] = `
Object {
"linux": Array [],
}
`;

exports[`default stagePackages 1`] = `
Object {
"apps": Object {
"sep": Object {
"command": "env TMPDIR=$XDG_RUNTIME_DIR desktop-launch $SNAP/sep",
"command": "desktop-launch $SNAP/sep",
"environment": Object {
"TMPDIR": "$XDG_RUNTIME_DIR",
},
"plugs": Array [
"desktop",
"desktop-legacy",
Expand Down Expand Up @@ -58,7 +119,10 @@ exports[`default stagePackages 3`] = `
Object {
"apps": Object {
"sep": Object {
"command": "env TMPDIR=$XDG_RUNTIME_DIR desktop-launch $SNAP/sep",
"command": "desktop-launch $SNAP/sep",
"environment": Object {
"TMPDIR": "$XDG_RUNTIME_DIR",
},
"plugs": Array [
"desktop",
"desktop-legacy",
Expand Down Expand Up @@ -114,7 +178,10 @@ exports[`default stagePackages 5`] = `
Object {
"apps": Object {
"sep": Object {
"command": "env TMPDIR=$XDG_RUNTIME_DIR desktop-launch $SNAP/sep",
"command": "desktop-launch $SNAP/sep",
"environment": Object {
"TMPDIR": "$XDG_RUNTIME_DIR",
},
"plugs": Array [
"custom",
"desktop",
Expand Down Expand Up @@ -170,7 +237,10 @@ exports[`default stagePackages 7`] = `
Object {
"apps": Object {
"sep": Object {
"command": "env TMPDIR=$XDG_RUNTIME_DIR desktop-launch $SNAP/sep",
"command": "desktop-launch $SNAP/sep",
"environment": Object {
"TMPDIR": "$XDG_RUNTIME_DIR",
},
"plugs": Array [
"foo1",
"desktop",
Expand Down
20 changes: 20 additions & 0 deletions test/src/linux/snapTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,23 @@ test.ifAll.ifDevOrLinuxCi("default stagePackages", async () => {
})
}
})

test.ifAll.ifDevOrLinuxCi("custom env", app({
targets: Platform.LINUX.createTarget("snap"),
config: {
extraMetadata: {
name: "sep",
},
productName: "Sep",
snap: {
environment: {
FOO: "bar",
},
}
},
effectiveOptionComputed: async ({snap}) => {
delete snap.parts.app.source
expect(snap).toMatchSnapshot()
return true
},
}))

0 comments on commit d8c0df0

Please sign in to comment.