Skip to content

Commit

Permalink
Custom OPUS fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vassbo committed Mar 4, 2025
1 parent af8fd36 commit 3d23300
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ jobs:
# npm ci is better, but requires package-lock.json file
run: npm install

# needed for OPUS to use "electron" and not "node" abi
- name: Rebuild native modules
run: npm rebuild @discordjs/opus --runtime=electron --target=$(npx electron -v)

- name: Build and release app
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -54,9 +50,6 @@ jobs:
- name: Install dependencies
run: npm install

- name: Rebuild native modules
run: npm rebuild @discordjs/opus --runtime=electron --target=$(npx electron -v)

- name: Build and release app
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -85,9 +78,6 @@ jobs:
- name: Install dependencies
run: npm install

- name: Rebuild native modules
run: npm rebuild @discordjs/opus --runtime=electron --target=$(npx electron -v)

- name: Install FPM
run: |
sudo apt-get install ruby ruby-dev build-essential
Expand Down Expand Up @@ -130,9 +120,6 @@ jobs:
- name: Install dependencies
run: npm install

- name: Rebuild native modules
run: npm rebuild @discordjs/opus --runtime=electron --target=$(npx electron -v)

- name: Install dmg-license
run: npm i dmg-license

Expand Down
28 changes: 27 additions & 1 deletion scripts/postBuild.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { readdirSync, statSync, readFileSync, writeFileSync, existsSync, lstatSync, unlinkSync, rmdirSync, mkdirSync } = require("fs")
const { readdirSync, statSync, readFileSync, writeFileSync, existsSync, lstatSync, unlinkSync, rmdirSync, mkdirSync, rename } = require("fs")
const { join } = require("path")

const Terser = require("terser")
Expand Down Expand Up @@ -140,9 +140,35 @@ function minifyJS(filePath, newPath = "") {
// writeFileSync(newPath, minified.styles)
// }

// OPUS FIX

// EXAMPLE
// actual build: "node-v127-napi-v3-win32-x64-unknown-unknown"
// should be: "electron-v32.2-napi-v3-win32-x64-unknown-unknown"
// there is a slight difference, but it works!
function renameOpusBuild() {
const prebuildDir = join(__dirname, "..", "node_modules", "@discordjs", "opus", "prebuild")
const folders = readdirSync(prebuildDir)

if (folders.length !== 1 || folders[0].includes("electron")) return

const electronVersion = require("electron/package.json").version || ""
if (!electronVersion) return

const electronMajorVersion = electronVersion.split(".")[0] + "." + electronVersion.split(".")[1]
const newName = `electron-v${electronMajorVersion}-${folders[0].slice(folders[0].indexOf("napi"))}`

rename(join(prebuildDir, folders[0]), join(prebuildDir, newName), (err) => {
if (err) console.error("Error renaming folder:", err)
})
}

// EXECUTE

const bundledElectronPath = join(__dirname, "..", "build")
minifyJSFiles(getAllJSFiles(bundledElectronPath))
copyPublicFolderAndMinify(join(__dirname, "..", "public"), join(bundledElectronPath, "public"))
removeTsConfigs()

// fix for OPUS electron vs node env
renameOpusBuild()

0 comments on commit 3d23300

Please sign in to comment.