From bc3dc7b43385645e3f2e37eb3849bf36e928d53e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20L=C3=B6nnhager?= Date: Tue, 10 Dec 2024 10:43:07 +0100 Subject: [PATCH] Wrap 'config' in function --- .../mullvad-vpn/tasks/distribution.js | 502 +++++++++--------- 1 file changed, 253 insertions(+), 249 deletions(-) diff --git a/desktop/packages/mullvad-vpn/tasks/distribution.js b/desktop/packages/mullvad-vpn/tasks/distribution.js index afc6e85b697b..c8282434bd55 100644 --- a/desktop/packages/mullvad-vpn/tasks/distribution.js +++ b/desktop/packages/mullvad-vpn/tasks/distribution.js @@ -20,269 +20,270 @@ function getOptionValue(option) { } } -const config = { - appId: 'net.mullvad.vpn', - copyright: 'Mullvad VPN AB', - productName: 'Mullvad VPN', - publish: null, - asar: true, - compression: noCompression ? 'store' : 'normal', - extraResources: [ - { from: distAssets('ca.crt'), to: '.' }, - { from: buildAssets('relays.json'), to: '.' }, - { from: root('CHANGELOG.md'), to: '.' }, - ], - - directories: { - buildResources: root('dist-assets'), - output: root('dist'), - }, - - extraMetadata: { - name: 'mullvad-vpn', - // We have to stick to semver on Windows for now due to: - // https://github.com/electron-userland/electron-builder/issues/7173 - version: productVersion(process.platform === 'win32' ? ['semver'] : []), - }, - - files: [ - 'package.json', - 'changes.txt', - 'init.js', - 'build/', - '!build/src/renderer', - 'build/src/renderer/index.html', - 'build/src/renderer/bundle.js', - 'build/src/renderer/preloadBundle.js', - '!**/*.tsbuildinfo', - '!test/', - '!playwright.config.ts', - 'node_modules/', - '!node_modules/grpc-tools', - '!node_modules/@types', - '!node_modules/nseventforwarder/debug', - ], - - // Make sure that all files declared in "extraResources" exists and abort if they don't. - afterPack: (context) => { - if (context.arch !== Arch.universal) { - const resources = context.packager.platformSpecificBuildOptions.extraResources; - for (const resource of resources) { - const filePath = resource.from.replaceAll( - /\$\{env\.(.*?)\}/g, - function (match, captureGroup) { - return process.env[captureGroup]; - }, - ); +function newConfig() { + return { + appId: 'net.mullvad.vpn', + copyright: 'Mullvad VPN AB', + productName: 'Mullvad VPN', + publish: null, + asar: true, + compression: noCompression ? 'store' : 'normal', + extraResources: [ + { from: distAssets('ca.crt'), to: '.' }, + { from: buildAssets('relays.json'), to: '.' }, + { from: root('CHANGELOG.md'), to: '.' }, + ], - if (!fs.existsSync(filePath)) { - throw new Error(`Can't find file: ${filePath}`); - } - } - } - }, + directories: { + buildResources: root('dist-assets'), + output: root('dist'), + }, - mac: { - target: { - target: 'pkg', - arch: getMacArch(), + extraMetadata: { + name: 'mullvad-vpn', + // We have to stick to semver on Windows for now due to: + // https://github.com/electron-userland/electron-builder/issues/7173 + version: productVersion(process.platform === 'win32' ? ['semver'] : []), }, - singleArchFiles: 'node_modules/nseventforwarder/dist/**', - artifactName: 'MullvadVPN-${version}.${ext}', - category: 'public.app-category.tools', - icon: distAssets('icon-macos.icns'), - notarize: shouldNotarize, - extendInfo: { - LSUIElement: true, - NSUserNotificationAlertStyle: 'banner', + + files: [ + 'package.json', + 'changes.txt', + 'init.js', + 'build/', + '!build/src/renderer', + 'build/src/renderer/index.html', + 'build/src/renderer/bundle.js', + 'build/src/renderer/preloadBundle.js', + '!**/*.tsbuildinfo', + '!test/', + '!playwright.config.ts', + 'node_modules/', + '!node_modules/grpc-tools', + '!node_modules/@types', + '!node_modules/nseventforwarder/debug', + ], + + // Make sure that all files declared in "extraResources" exists and abort if they don't. + afterPack: (context) => { + if (context.arch !== Arch.universal) { + const resources = context.packager.platformSpecificBuildOptions.extraResources; + for (const resource of resources) { + const filePath = resource.from.replaceAll( + /\$\{env\.(.*?)\}/g, + function (match, captureGroup) { + return process.env[captureGroup]; + }, + ); + + if (!fs.existsSync(filePath)) { + throw new Error(`Can't find file: ${filePath}`); + } + } + } }, - extraResources: [ - { from: distAssets(path.join('${env.BINARIES_PATH}', 'mullvad')), to: '.' }, - { from: distAssets(path.join('${env.BINARIES_PATH}', 'mullvad-problem-report')), to: '.' }, - { from: distAssets(path.join('${env.BINARIES_PATH}', 'mullvad-daemon')), to: '.' }, - { from: distAssets(path.join('${env.BINARIES_PATH}', 'mullvad-setup')), to: '.' }, - { - from: distAssets(path.join('${env.BINARIES_PATH}', 'libtalpid_openvpn_plugin.dylib')), - to: '.', + + mac: { + target: { + target: 'pkg', + arch: getMacArch(), }, - { from: distAssets(path.join('binaries', '${env.TARGET_TRIPLE}', 'openvpn')), to: '.' }, - { from: distAssets(path.join('binaries', '${env.TARGET_TRIPLE}', 'apisocks5')), to: '.' }, - { from: distAssets('uninstall_macos.sh'), to: './uninstall.sh' }, - { from: buildAssets('shell-completions/_mullvad'), to: '.' }, - { from: buildAssets('shell-completions/mullvad.fish'), to: '.' }, - { from: distAssets('maybenot_machines'), to: '.' }, - ], - }, - - pkg: { - allowAnywhere: false, - allowCurrentUserHome: false, - isRelocatable: false, - isVersionChecked: false, - }, - - nsis: { - guid: '2A356FD4-03B7-4F45-99B4-737BE580DC82', - oneClick: false, - perMachine: true, - allowElevation: true, - allowToChangeInstallationDirectory: false, - include: distAssets('windows/installer.nsh'), - installerSidebar: distAssets('windows/installersidebar.bmp'), - }, - - win: { - target: [], - signAndEditExecutable: false, - artifactName: 'MullvadVPN-${version}_${arch}.${ext}', - publisherName: 'Mullvad VPN AB', - extraResources: [ - { from: distAssets(path.join('${env.DIST_SUBDIR}', 'mullvad.exe')), to: '.' }, - { - from: distAssets(path.join('${env.DIST_SUBDIR}', 'mullvad-problem-report.exe')), - to: '.', + singleArchFiles: 'node_modules/nseventforwarder/dist/**', + artifactName: 'MullvadVPN-${version}.${ext}', + category: 'public.app-category.tools', + icon: distAssets('icon-macos.icns'), + notarize: shouldNotarize, + extendInfo: { + LSUIElement: true, + NSUserNotificationAlertStyle: 'banner', }, - { from: distAssets(path.join('${env.DIST_SUBDIR}', 'mullvad-daemon.exe')), to: '.' }, - { from: distAssets(path.join('${env.DIST_SUBDIR}', 'talpid_openvpn_plugin.dll')), to: '.' }, - { - from: root( - path.join( - 'windows', - 'winfw', - 'bin', - '${env.TARGET_ARCHITECTURE}-${env.CPP_BUILD_MODE}', - 'winfw.dll', + extraResources: [ + { from: distAssets(path.join('${env.BINARIES_PATH}', 'mullvad')), to: '.' }, + { from: distAssets(path.join('${env.BINARIES_PATH}', 'mullvad-problem-report')), to: '.' }, + { from: distAssets(path.join('${env.BINARIES_PATH}', 'mullvad-daemon')), to: '.' }, + { from: distAssets(path.join('${env.BINARIES_PATH}', 'mullvad-setup')), to: '.' }, + { + from: distAssets(path.join('${env.BINARIES_PATH}', 'libtalpid_openvpn_plugin.dylib')), + to: '.', + }, + { from: distAssets(path.join('binaries', '${env.TARGET_TRIPLE}', 'openvpn')), to: '.' }, + { from: distAssets(path.join('binaries', '${env.TARGET_TRIPLE}', 'apisocks5')), to: '.' }, + { from: distAssets('uninstall_macos.sh'), to: './uninstall.sh' }, + { from: buildAssets('shell-completions/_mullvad'), to: '.' }, + { from: buildAssets('shell-completions/mullvad.fish'), to: '.' }, + { from: distAssets('maybenot_machines'), to: '.' }, + ], + }, + + pkg: { + allowAnywhere: false, + allowCurrentUserHome: false, + isRelocatable: false, + isVersionChecked: false, + }, + + nsis: { + guid: '2A356FD4-03B7-4F45-99B4-737BE580DC82', + oneClick: false, + perMachine: true, + allowElevation: true, + allowToChangeInstallationDirectory: false, + include: distAssets('windows/installer.nsh'), + installerSidebar: distAssets('windows/installersidebar.bmp'), + }, + + win: { + target: [], + signAndEditExecutable: false, + artifactName: 'MullvadVPN-${version}_${arch}.${ext}', + publisherName: 'Mullvad VPN AB', + extraResources: [ + { from: distAssets(path.join('${env.DIST_SUBDIR}', 'mullvad.exe')), to: '.' }, + { + from: distAssets(path.join('${env.DIST_SUBDIR}', 'mullvad-problem-report.exe')), + to: '.', + }, + { from: distAssets(path.join('${env.DIST_SUBDIR}', 'mullvad-daemon.exe')), to: '.' }, + { from: distAssets(path.join('${env.DIST_SUBDIR}', 'talpid_openvpn_plugin.dll')), to: '.' }, + { + from: root( + path.join( + 'windows', + 'winfw', + 'bin', + '${env.TARGET_ARCHITECTURE}-${env.CPP_BUILD_MODE}', + 'winfw.dll', + ), ), - ), - to: '.', - }, - // TODO: OpenVPN does not have an ARM64 build yet. - { from: distAssets('binaries/x86_64-pc-windows-msvc/openvpn.exe'), to: '.' }, - { - from: distAssets(path.join('binaries', '${env.TARGET_SUBDIR}', 'apisocks5.exe')), - to: '.', - }, - { - from: distAssets(path.join('binaries', '${env.TARGET_SUBDIR}', 'wintun/wintun.dll')), - to: '.', - }, - { - from: distAssets( - path.join('binaries', '${env.TARGET_SUBDIR}', 'split-tunnel/mullvad-split-tunnel.sys'), - ), - to: '.', - }, - { - from: distAssets( - path.join('binaries', '${env.TARGET_SUBDIR}', 'wireguard-nt/mullvad-wireguard.dll'), - ), - to: '.', - }, - { from: distAssets('maybenot_machines'), to: '.' }, - ], - }, + to: '.', + }, + // TODO: OpenVPN does not have an ARM64 build yet. + { from: distAssets('binaries/x86_64-pc-windows-msvc/openvpn.exe'), to: '.' }, + { + from: distAssets(path.join('binaries', '${env.TARGET_SUBDIR}', 'apisocks5.exe')), + to: '.', + }, + { + from: distAssets(path.join('binaries', '${env.TARGET_SUBDIR}', 'wintun/wintun.dll')), + to: '.', + }, + { + from: distAssets( + path.join('binaries', '${env.TARGET_SUBDIR}', 'split-tunnel/mullvad-split-tunnel.sys'), + ), + to: '.', + }, + { + from: distAssets( + path.join('binaries', '${env.TARGET_SUBDIR}', 'wireguard-nt/mullvad-wireguard.dll'), + ), + to: '.', + }, + { from: distAssets('maybenot_machines'), to: '.' }, + ], + }, - linux: { - target: [ - { - target: 'deb', - arch: getLinuxTargetArch(), - }, - { - target: 'rpm', - arch: getLinuxTargetArch(), - }, - ], - artifactName: 'MullvadVPN-${version}_${arch}.${ext}', - category: 'Network', - icon: distAssets('icon.icns'), - extraFiles: [{ from: distAssets('linux/mullvad-gui-launcher.sh'), to: '.' }], - extraResources: [ - { from: distAssets(path.join(getLinuxTargetSubdir(), 'mullvad-problem-report')), to: '.' }, - { from: distAssets(path.join(getLinuxTargetSubdir(), 'mullvad-setup')), to: '.' }, - { - from: distAssets(path.join(getLinuxTargetSubdir(), 'libtalpid_openvpn_plugin.so')), - to: '.', - }, - { from: distAssets(path.join('linux', 'apparmor_mullvad')), to: '.' }, - { from: distAssets(path.join('binaries', '${env.TARGET_TRIPLE}', 'openvpn')), to: '.' }, - { from: distAssets(path.join('binaries', '${env.TARGET_TRIPLE}', 'apisocks5')), to: '.' }, - { from: distAssets('maybenot_machines'), to: '.' }, - ], - }, - - deb: { - fpm: [ - '--no-depends', - '--version', - getLinuxVersion(), - '--before-install', - distAssets('linux/before-install.sh'), - '--before-remove', - distAssets('linux/before-remove.sh'), - distAssets('linux/mullvad-daemon.service') + - '=/usr/lib/systemd/system/mullvad-daemon.service', - distAssets('linux/mullvad-early-boot-blocking.service') + - '=/usr/lib/systemd/system/mullvad-early-boot-blocking.service', - distAssets(path.join(getLinuxTargetSubdir(), 'mullvad')) + '=/usr/bin/', - distAssets(path.join(getLinuxTargetSubdir(), 'mullvad-daemon')) + '=/usr/bin/', - distAssets(path.join(getLinuxTargetSubdir(), 'mullvad-exclude')) + '=/usr/bin/', - distAssets('linux/problem-report-link') + '=/usr/bin/mullvad-problem-report', - buildAssets('shell-completions/mullvad.bash') + - '=/usr/share/bash-completion/completions/mullvad', - buildAssets('shell-completions/_mullvad') + '=/usr/local/share/zsh/site-functions/_mullvad', - buildAssets('shell-completions/mullvad.fish') + - '=/usr/share/fish/vendor_completions.d/mullvad.fish', - ], - afterInstall: distAssets('linux/after-install.sh'), - afterRemove: distAssets('linux/after-remove.sh'), - }, - - rpm: { - fpm: [ - '--version', - getLinuxVersion(), - // Prevents RPM from packaging build-id metadata, some of which is the - // same across all electron-builder applications, which causes package - // conflicts - '--rpm-rpmbuild-define=_build_id_links none', - '--directories=/opt/Mullvad VPN/', - '--before-install', - distAssets('linux/before-install.sh'), - '--before-remove', - distAssets('linux/before-remove.sh'), - '--rpm-posttrans', - distAssets('linux/post-transaction.sh'), - distAssets('linux/mullvad-daemon.service') + - '=/usr/lib/systemd/system/mullvad-daemon.service', - distAssets('linux/mullvad-early-boot-blocking.service') + - '=/usr/lib/systemd/system/mullvad-early-boot-blocking.service', - distAssets(path.join(getLinuxTargetSubdir(), 'mullvad')) + '=/usr/bin/', - distAssets(path.join(getLinuxTargetSubdir(), 'mullvad-daemon')) + '=/usr/bin/', - distAssets(path.join(getLinuxTargetSubdir(), 'mullvad-exclude')) + '=/usr/bin/', - distAssets('linux/problem-report-link') + '=/usr/bin/mullvad-problem-report', - buildAssets('shell-completions/mullvad.bash') + - '=/usr/share/bash-completion/completions/mullvad', - buildAssets('shell-completions/_mullvad') + '=/usr/share/zsh/site-functions/_mullvad', - buildAssets('shell-completions/mullvad.fish') + - '=/usr/share/fish/vendor_completions.d/mullvad.fish', - ], - afterInstall: distAssets('linux/after-install.sh'), - afterRemove: distAssets('linux/after-remove.sh'), - depends: ['libXScrnSaver', 'libnotify', 'dbus-libs'], - }, -}; + linux: { + target: [ + { + target: 'deb', + arch: getLinuxTargetArch(), + }, + { + target: 'rpm', + arch: getLinuxTargetArch(), + }, + ], + artifactName: 'MullvadVPN-${version}_${arch}.${ext}', + category: 'Network', + icon: distAssets('icon.icns'), + extraFiles: [{ from: distAssets('linux/mullvad-gui-launcher.sh'), to: '.' }], + extraResources: [ + { from: distAssets(path.join(getLinuxTargetSubdir(), 'mullvad-problem-report')), to: '.' }, + { from: distAssets(path.join(getLinuxTargetSubdir(), 'mullvad-setup')), to: '.' }, + { + from: distAssets(path.join(getLinuxTargetSubdir(), 'libtalpid_openvpn_plugin.so')), + to: '.', + }, + { from: distAssets(path.join('linux', 'apparmor_mullvad')), to: '.' }, + { from: distAssets(path.join('binaries', '${env.TARGET_TRIPLE}', 'openvpn')), to: '.' }, + { from: distAssets(path.join('binaries', '${env.TARGET_TRIPLE}', 'apisocks5')), to: '.' }, + { from: distAssets('maybenot_machines'), to: '.' }, + ], + }, + + deb: { + fpm: [ + '--no-depends', + '--version', + getLinuxVersion(), + '--before-install', + distAssets('linux/before-install.sh'), + '--before-remove', + distAssets('linux/before-remove.sh'), + distAssets('linux/mullvad-daemon.service') + + '=/usr/lib/systemd/system/mullvad-daemon.service', + distAssets('linux/mullvad-early-boot-blocking.service') + + '=/usr/lib/systemd/system/mullvad-early-boot-blocking.service', + distAssets(path.join(getLinuxTargetSubdir(), 'mullvad')) + '=/usr/bin/', + distAssets(path.join(getLinuxTargetSubdir(), 'mullvad-daemon')) + '=/usr/bin/', + distAssets(path.join(getLinuxTargetSubdir(), 'mullvad-exclude')) + '=/usr/bin/', + distAssets('linux/problem-report-link') + '=/usr/bin/mullvad-problem-report', + buildAssets('shell-completions/mullvad.bash') + + '=/usr/share/bash-completion/completions/mullvad', + buildAssets('shell-completions/_mullvad') + '=/usr/local/share/zsh/site-functions/_mullvad', + buildAssets('shell-completions/mullvad.fish') + + '=/usr/share/fish/vendor_completions.d/mullvad.fish', + ], + afterInstall: distAssets('linux/after-install.sh'), + afterRemove: distAssets('linux/after-remove.sh'), + }, + + rpm: { + fpm: [ + '--version', + getLinuxVersion(), + // Prevents RPM from packaging build-id metadata, some of which is the + // same across all electron-builder applications, which causes package + // conflicts + '--rpm-rpmbuild-define=_build_id_links none', + '--directories=/opt/Mullvad VPN/', + '--before-install', + distAssets('linux/before-install.sh'), + '--before-remove', + distAssets('linux/before-remove.sh'), + '--rpm-posttrans', + distAssets('linux/post-transaction.sh'), + distAssets('linux/mullvad-daemon.service') + + '=/usr/lib/systemd/system/mullvad-daemon.service', + distAssets('linux/mullvad-early-boot-blocking.service') + + '=/usr/lib/systemd/system/mullvad-early-boot-blocking.service', + distAssets(path.join(getLinuxTargetSubdir(), 'mullvad')) + '=/usr/bin/', + distAssets(path.join(getLinuxTargetSubdir(), 'mullvad-daemon')) + '=/usr/bin/', + distAssets(path.join(getLinuxTargetSubdir(), 'mullvad-exclude')) + '=/usr/bin/', + distAssets('linux/problem-report-link') + '=/usr/bin/mullvad-problem-report', + buildAssets('shell-completions/mullvad.bash') + + '=/usr/share/bash-completion/completions/mullvad', + buildAssets('shell-completions/_mullvad') + '=/usr/share/zsh/site-functions/_mullvad', + buildAssets('shell-completions/mullvad.fish') + + '=/usr/share/fish/vendor_completions.d/mullvad.fish', + ], + afterInstall: distAssets('linux/after-install.sh'), + afterRemove: distAssets('linux/after-remove.sh'), + depends: ['libXScrnSaver', 'libnotify', 'dbus-libs'], + }, + }; +} async function packWin() { const DEFAULT_ARCH = targets === 'aarch64-pc-windows-msvc' ? 'arm64' : 'x64'; - function prepareConfig(arch) { + function prepareWinConfig(arch) { + const config = newConfig(); return { ...config, - files: [...config.files], win: { ...config.win, - extraResources: [...config.win.extraResources], target: [ { target: 'nsis', @@ -340,18 +341,19 @@ async function packWin() { // installers in the same binary. await builder.build({ targets: builder.Platform.WINDOWS.createTarget(), - config: prepareConfig(DEFAULT_ARCH === 'x64' ? 'arm64' : 'x64'), + config: prepareWinConfig(DEFAULT_ARCH === 'x64' ? 'arm64' : 'x64'), }); } return builder.build({ targets: builder.Platform.WINDOWS.createTarget(), - config: prepareConfig(DEFAULT_ARCH), + config: prepareWinConfig(DEFAULT_ARCH), }); } function packMac() { const appOutDirs = []; + const config = newConfig(); return builder.build({ targets: builder.Platform.MAC.createTarget(), @@ -412,6 +414,8 @@ function packMac() { } function packLinux() { + const config = newConfig(); + if (noCompression) { config.rpm.fpm.unshift('--rpm-compression', 'none'); }