Skip to content

Commit 5893ead

Browse files
committed
fix: attempt to fix based on TryGhost/node-sqlite3/issues/1746
1 parent aa307b6 commit 5893ead

4 files changed

Lines changed: 249 additions & 2094 deletions

File tree

‎.erb/scripts/fix-sqlite3-bug.js‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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();

‎.github/workflows/test.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ jobs:
8585
# Install sqlite3 with the suggested approach
8686
npm install sqlite3 --build-from-source --target_arch=arm64 --fallback-to-build
8787
88+
# Apply the sqlite3 fix
89+
node ../../build/fixSqlite3bug.js
90+
8891
# Check the installed packages
8992
npm list sqlite3
9093

0 commit comments

Comments
 (0)