Electron-builder not packaging Plugins for Linux

Hi,

We want to package some plugins with our Theia IDE at build time (we package plugins into .vsix files beforehand).

We use the following as a guide: https://github.com/theia-ide/theia-apps/tree/master/theia-electron

This works with a Mac build on a Mac machine. However, the Linux build process does not copy the packages anywhere within the /dist folder and the plugins do not exist upon launching the executable. The executable looks at /home/.theia/extensions instead for its plugins. I assumed the following lines in the .yml file would handle the copying:

extraResources:
  - from: plugins
    to: app/plugins

Note that this is only an issue when using electron-builder. When running yarn start the application successfully loads plugins from the /plugins folder. It seems to me that this is simply an issue of not copying the plugins when building.

Any idea why might be having this problem on Linux but not on Mac?

I’m posting out entire versions below in case they might help:

 "dependencies": {
    "@theia/electron": "^1.5.0",
    "@theia/callhierarchy": "^1.5.0",
    "@theia/console": "^1.5.0",
    "@theia/core": "^1.5.0",
    "@theia/debug": "^1.5.0",
    "@theia/editor": "^1.5.0",
    "@theia/editor-preview": "^1.5.0",
    "@theia/file-search": "^1.5.0",
    "@theia/filesystem": "^1.5.0",
    "@theia/getting-started": "^1.5.0",
    "@theia/git": "^1.5.0",
    "@theia/keymaps": "^1.5.0",
    "@theia/markers": "^1.5.0",
    "@theia/messages": "^1.5.0",
    "@theia/metrics": "^1.5.0",
    "@theia/mini-browser": "^1.5.0",
    "@theia/monaco": "^1.5.0",
    "@theia/navigator": "^1.5.0",
    "@theia/outline-view": "^1.5.0",
    "@theia/output": "^1.5.0",
    "@theia/plugin-dev": "^1.5.0",
    "@theia/plugin-ext": "^1.5.0",
    "@theia/plugin-ext-vscode": "^1.5.0",
    "@theia/plugin-metrics": "^1.5.0",
    "@theia/preferences": "^1.5.0",
    "@theia/preview": "^1.5.0",
    "@theia/process": "^1.5.0",
    "@theia/scm": "^1.5.0",
    "@theia/scm-extra": "^1.5.0",
    "@theia/search-in-workspace": "^1.5.0",
    "@theia/task": "^1.5.0",
    "@theia/terminal": "^1.5.0",
    "@theia/typehierarchy": "^1.5.0",
    "@theia/userstorage": "^1.5.0",
    "@theia/variable-resolver": "^1.5.0",
    "@theia/vsx-registry": "^1.5.0",
    "@theia/workspace": "^1.5.0",
  },
  "devDependencies": {
    "@theia/cli": "^1.5.0",
    "electron-builder": "^22.4.1",
    "bufferutil": "4",
    "utf-8-validate": "5"
  },

We also use yarn version 1.22.5 and node 12.14.1. The Linux version is Ubuntu 16.04 LTS

Hi @yunuscukran! I’m also building an electron app (for Linux and Windows) which uses plugins, and it gets built and packaged correctly (with all the plugins included) so hopefully I can help you out here :).

First of all, can you make sure that the plugins really aren’t copied from your plugins folder? In my setup, I have the plugins directory in my project root (the same directory I run yarn electron-builder in).
In my package.json, I have this entry:

"extraResources": [
  {
    "from": "plugins",
    "to": "app/plugins"
  }
],

which should be equivalent to what you have in your yaml file (I just prefer having electron-builder configuration in package.json).
Electron-builder copies it to dist/linux-unpacked/resources/app/plugins. Can you make sure that this directory really doesn’t exist when you package your app?

If the directory actually does exist, but you’re not seeing the plugins in your app, it may be because your app doesn’t know about them. Theia apps will include default (built-in) plugins that are available on the path specified in THEIA_DEFAULT_PLUGINS environment variable so make sure that this environment variable is set for your application and that it points to the correct directory.
The way to do this is to create a script that will run just before electron-main.js. Take a look at https://github.com/theia-ide/theia-apps/blob/master/theia-electron/scripts/theia-electron-main.js.
This is the crucial part:

// Use a set of builtin plugins in our application.
process.env.THEIA_DEFAULT_PLUGINS = `local-dir:${path.resolve(__dirname, '..', 'plugins')}`

If you also want your app to load plugins located in your user’s home directory, you can include this line as well:

// Lookup inside the user's home folder for more plugins, and accept user-defined paths.
process.env.THEIA_PLUGINS = [
process.env.THEIA_PLUGINS, `local-dir:${path.resolve(os.homedir(), '.theia', 'plugins')}`,
].filter(Boolean).join(',')

Your package.json should point to this script to start your app instead of electron-main.js, for example:

"main": "scripts/my-app-main.js",

Finally, this may really be an issue with electron-builder? Which version are you on? This is mine:

$ node_modules/.bin/electron-builder --version
22.9.1

Let me know if you have any questions :)!

1 Like

Interesting, my dist/linux-unpacked/resources only has app.asar and app.asar.unpacked. The plugins folder isn’t being created in the first place.

My electron-builder is also 22.9.1.

Regarding the main script, I have the following. This looks OK to me.

const path = require('path')
const os = require('os')

// Use a set of builtin plugins in our application.
process.env.THEIA_DEFAULT_PLUGINS = `local-dir:${path.resolve(__dirname, '..', 'plugins')}`

// Lookup inside the user's home folder for more plugins, and accept user-defined paths.
process.env.THEIA_PLUGINS = [
    process.env.THEIA_PLUGINS, `local-dir:${path.resolve(os.homedir(), '.theia', 'plugins')}`,
].filter(Boolean).join(',')

// Handover to the auto-generated electron application handler.
require('../src-gen/frontend/electron-main.js')

Update: The problem was a simple typo and I had the name of electron-builder.yml as electron-rebuilder.yml, so it wasn’t being read at all… Solved the folder creation problem :slight_smile: @mnaglic thank you for the detailed explanation, I understand the build process much better now.

Now that we’re on the topic though, I’m curious what happens with build-time packaged plugins on a new machine that installs the program. Does the installer put the packaged plugins to the installer’s /home/.theia/extensions? Any insight on that part?

Update 2: Regarding my own question: I figured out that installing the genreated .deb package creates a /opt/PACKAGE_NAME folder and the plugins are put into a folder in there