|
| 1 | +/** |
| 2 | + * This script fixes the sqlite3 binary compatibility issue with Electron on macOS. |
| 3 | + * It modifies the sqlite3 package.json to use the correct binary configuration. |
| 4 | + */ |
| 5 | +const fs = require('fs'); |
| 6 | +const path = require('path'); |
| 7 | +const chalk = require('chalk'); |
| 8 | + |
| 9 | +function fixSqlite3() { |
| 10 | + console.log( |
| 11 | + chalk.blue( |
| 12 | + 'Fixing sqlite3 binary configuration for Electron compatibility...', |
| 13 | + ), |
| 14 | + ); |
| 15 | + |
| 16 | + // Paths to check for sqlite3 package.json |
| 17 | + const possiblePaths = [ |
| 18 | + path.join(process.cwd(), 'node_modules', 'sqlite3', 'package.json'), |
| 19 | + path.join( |
| 20 | + process.cwd(), |
| 21 | + 'release', |
| 22 | + 'app', |
| 23 | + 'node_modules', |
| 24 | + 'sqlite3', |
| 25 | + 'package.json', |
| 26 | + ), |
| 27 | + ]; |
| 28 | + |
| 29 | + let modified = false; |
| 30 | + |
| 31 | + // Using forEach instead of for...of to avoid linting issues |
| 32 | + possiblePaths.forEach((sqlite3Path) => { |
| 33 | + if (fs.existsSync(sqlite3Path)) { |
| 34 | + try { |
| 35 | + console.log(chalk.green(`Found sqlite3 at: ${sqlite3Path}`)); |
| 36 | + // eslint-disable-next-line import/no-dynamic-require, global-require |
| 37 | + const sqlite3 = require(sqlite3Path); |
| 38 | + |
| 39 | + // Set the binary configuration |
| 40 | + sqlite3.binary = { |
| 41 | + napi_versions: [6], |
| 42 | + }; |
| 43 | + |
| 44 | + // Write the modified package.json back |
| 45 | + fs.writeFileSync(sqlite3Path, JSON.stringify(sqlite3, null, 2)); |
| 46 | + console.log( |
| 47 | + chalk.green( |
| 48 | + `Successfully modified sqlite3 package.json at: ${sqlite3Path}`, |
| 49 | + ), |
| 50 | + ); |
| 51 | + modified = true; |
| 52 | + } catch (error) { |
| 53 | + console.error( |
| 54 | + chalk.red(`Error modifying sqlite3 package.json at ${sqlite3Path}:`), |
| 55 | + error, |
| 56 | + ); |
| 57 | + } |
| 58 | + } |
| 59 | + }); |
| 60 | + |
| 61 | + if (!modified) { |
| 62 | + console.log(chalk.yellow('No sqlite3 package.json found to modify.')); |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +// Run the fix |
| 67 | +fixSqlite3(); |
0 commit comments