From 2d0a2390850126a1572d2cb1e44fb2f213429619 Mon Sep 17 00:00:00 2001 From: Joaquim Rocha Date: Wed, 31 Jul 2024 14:45:27 +0100 Subject: [PATCH] app: Replace symlinks in node_modules by their target in Mac builds Otherwise, Mac will fail to notarize the app. Signed-off-by: Joaquim Rocha --- app/scripts/after-pack.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/scripts/after-pack.js b/app/scripts/after-pack.js index a796e4f0d5..67a425ff47 100644 --- a/app/scripts/after-pack.js +++ b/app/scripts/after-pack.js @@ -1,5 +1,6 @@ 'use strict'; +const child_process = require('node:child_process'); const fs = require('node:fs'); const path = require('node:path'); @@ -18,6 +19,26 @@ exports.default = async context => { console.error('Failed to copy node_modules after pack:', err); } + // Mac has a problem with symlinks in the node_modules directory, so we replace them. + if (context.electronPlatformName === 'darwin') { + const tmpNodeModules = dest + '.tmp'; + + // Copy the node_modules directory to a temporary location, replacing any symlinks with the files they point to + child_process.spawnSync('rsync', [ + '--archive', + '--verbose', + '--copy-links', + dest + '/', + tmpNodeModules, + ]); + + // Remove the original node_modules directory + fs.rmSync(dest, { recursive: true, force: true }); + + // Move the copied directory back to the original location + fs.renameSync(tmpNodeModules, dest); + } + if (fs.existsSync('.env')) { console.info('Copying .env file to app resources directory!'); try {