From 10c9d11e1598048d2121e97a263ea14c71edc6c5 Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Tue, 8 Jul 2025 13:20:01 +0200 Subject: [PATCH] Skip front config generation if index isn't writable (#13094) In certain scenarios, the front directory may not be writable. When this is the case, writing the patched `index.html` should be skipped just like when the file does not exist. For brevity, I have replaced the `existsSync` check with a try-catch that catches any errors occuring during read or write of the index file. The alternative would be `fs.accessSync` with `W_OK`, but that would still throw an error if the file is not writable so I think it is reasonable to skip it altogether and go straight for the read and write attempts. A specific scenario where the front directory is immutable is NixOS, where the directory may be located in the read-only nix store. --- .../src/utils/generate-front-config.ts | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/twenty-server/src/utils/generate-front-config.ts b/packages/twenty-server/src/utils/generate-front-config.ts index c842a2592..6069fbbfe 100644 --- a/packages/twenty-server/src/utils/generate-front-config.ts +++ b/packages/twenty-server/src/utils/generate-front-config.ts @@ -25,21 +25,19 @@ export function generateFrontConfig(): void { const distPath = path.join(__dirname, '../..', 'front'); const indexPath = path.join(distPath, 'index.html'); - if (!fs.existsSync(indexPath)) { - // eslint-disable-next-line no-console - console.log( - 'Frontend build not found, assuming it is served independently', + try { + let indexContent = fs.readFileSync(indexPath, 'utf8'); + + indexContent = indexContent.replace( + /[\s\S]*?/, + configString, ); - return; + fs.writeFileSync(indexPath, indexContent, 'utf8'); + } catch { + // eslint-disable-next-line no-console + console.log( + 'Frontend build not found or not writable, assuming it is served independently', + ); } - - let indexContent = fs.readFileSync(indexPath, 'utf8'); - - indexContent = indexContent.replace( - /[\s\S]*?/, - configString, - ); - - fs.writeFileSync(indexPath, indexContent, 'utf8'); }