feat(electron-builder): download & bundle extensions-extra from product.json (#15165)

* feat(electron-builder): download & bundle extensions-extra from product.json

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>

* fix: remove unnecessary comment

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>

* fix: use execFile instead of exec

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>

* fix: prettier

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>

* fix(electron-builder): moving the packageRemoteExtensions earlier in beforePack function

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>

* chore(electron builder): print stdout and stderr for download remote extension

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>

* fix: formatter

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>

---------

Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com>
This commit is contained in:
axel7083 2025-12-08 11:17:51 +01:00 committed by GitHub
parent ad88476a2a
commit 9b3012e656
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,11 +16,13 @@
* SPDX-License-Identifier: Apache-2.0
***********************************************************************/
const exec = require('child_process').exec;
const { exec, execFile } = require('child_process');
const Arch = require('builder-util').Arch;
const path = require('path');
const { flipFuses, FuseVersion, FuseV1Options } = require('@electron/fuses');
const product = require('./product.json');
const fs = require('node:fs');
if (process.env.VITE_APP_VERSION === undefined) {
const now = new Date();
process.env.VITE_APP_VERSION = `${now.getUTCFullYear() - 2000}.${now.getUTCMonth() + 1}.${now.getUTCDate()}-${
@ -65,6 +67,34 @@ async function addElectronFuses(context) {
});
}
/**
* This function will start the script that will bundle the extensions#remote from the `product.json`
* to the extensions-extra folder
*
* @remarks it should be called in the beforePack to populate the folder extensions-extra before electron builder pack them
*/
async function packageRemoteExtensions() {
const downloadScript = path.join('packages', 'main', 'dist', 'download-remote-extensions.cjs');
if (!fs.existsSync(downloadScript)) {
console.warn(`${downloadScript} not found, skipping remote extension download`);
return;
}
const destination = path.resolve('./extensions-extra');
return new Promise((resolve, reject) => {
execFile('node', [downloadScript, `--output=${destination}`], (error, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
if (error) {
reject(error);
} else {
resolve();
}
});
});
}
/**
* @type {import('electron-builder').Configuration}
* @see https://www.electron.build/configuration/configuration
@ -83,6 +113,9 @@ const config = {
const PODMAN_EXTENSION_ASSETS = 'extensions/podman/packages/extension/assets';
context.packager.config.extraResources = DEFAULT_ASSETS;
// download & package remote extensions
await packageRemoteExtensions();
// include product.json
context.packager.config.extraResources.push({
from: 'product.json',
@ -130,7 +163,12 @@ const config = {
afterPack: async context => {
await addElectronFuses(context);
},
files: ['packages/**/dist/**', 'extensions/**/builtin/*.cdix/**', 'packages/main/src/assets/**'],
files: [
'packages/**/dist/**',
'extensions-extra/**',
'extensions/**/builtin/*.cdix/**',
'packages/main/src/assets/**',
],
portable: {
artifactName: `${product.artifactName}${artifactNameSuffix}-\${version}-\${arch}.\${ext}`,
},