aboutsummaryrefslogtreecommitdiffstats
path: root/electron-builder-fix-env.js
blob: 39c5f142cc27ed1cfa2533ec80a0f2df45b31612 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const fs = require("fs");
const path = require("path");
exports.default = async function (context) {
  // HACKTAG: Fix to overcome https://github.com/electron-userland/electron-builder/issues/7256 from electron-builder for windows multi-arch builds
  delete process.env.GYP_MSVS_VERSION;

  // CRAZY HACKTAG: Fix to overcome https://github.com/electron/rebuild/issues/546 from electron-rebuild
  /*
  1. Finds sqlite3/package.json
  2. replaces napi_build_version with 6 //current used one
  3. removes napi_versions (if present it expected napi_build_version to be present in modulePath)
   */
  const filePath = path.join(process.cwd(), "build", "node_modules", "sqlite3", "package.json");

  //This is to enfore that it happens only during rebuild.
  if(fs.existsSync(filePath)) {
    const sqlLite = require(filePath);
    Object.keys(sqlLite.binary).forEach(key => {
      let value = sqlLite.binary[key];
      if(typeof value === 'string') {
        value = value.replace("{napi_build_version}", 6)
        sqlLite.binary[key] = value
      }
    })
    delete sqlLite.binary["napi_versions"]
    fs.writeFileSync(filePath, JSON.stringify(sqlLite))
  }
};