mattermost-desktop/scripts/afterpack.js
Devin Binnie 9b36c25e4e
[MM-52696] Upgrade and clean up Desktop App dev dependencies (#2970)
* Upgrade to ESLint v8

* Upgrade TypeScript, api-types, react-intl

* Remove unnecessary dependencies

* Update to React 17.0.2

* npm audit fixes, remove storybook

* Lock some packages

* Remove nan patch

* Remove some deprecated dependencies

* Fix lint/type/tests

* Merge'd

* Fix bad use of spawn

* Fix notarize

* Fix afterpack, switch to tsc es2020

* Fix api types

* Use @mattermost/eslint-plugin
2024-03-07 15:55:33 -05:00

56 lines
1.7 KiB
JavaScript

// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
const path = require('path');
const {flipFuses, FuseVersion, FuseV1Options} = require('@electron/fuses');
const {spawn} = require('@electron/notarize/lib/spawn.js');
const SETUID_PERMISSIONS = '4755';
function fixSetuid(context) {
return async (target) => {
if (!['appimage', 'snap'].includes(target.name.toLowerCase())) {
const result = await spawn('chmod', [SETUID_PERMISSIONS, path.join(context.appOutDir, 'chrome-sandbox')]);
if (result.code !== 0) {
throw new Error(
`Failed to set proper permissions for linux arch on ${target.name}`,
);
}
}
};
}
function getAppFileName(context) {
switch (context.electronPlatformName) {
case 'win32':
return 'Mattermost.exe';
case 'darwin':
case 'mas':
return 'Mattermost.app';
case 'linux':
return context.packager.executableName;
default:
return '';
}
}
exports.default = async function afterPack(context) {
try {
await flipFuses(
`${context.appOutDir}/${getAppFileName(context)}`, // Returns the path to the electron binary
{
version: FuseVersion.V1,
[FuseV1Options.RunAsNode]: false, // Disables ELECTRON_RUN_AS_NODE
});
if (context.electronPlatformName === 'linux') {
context.targets.forEach(fixSetuid(context));
}
} catch (error) {
console.error('afterPack error: ', error);
// eslint-disable-next-line no-process-exit
process.exit(1);
}
};