Repository navigation
Randomness in injected filenames prevent universal apps from building #1405
Description
Homework
- I looked at
nativefier --helpand https://github.com/nativefier/nativefier/blob/master/API.md - I checked the Troubleshooting section of the README.
- I searched existing issues, open & closed. Yes, my bug is new.
- I'm using the latest version available at https://github.com/nativefier/nativefier/releases
Bug description
When building a nativefier app targeting macOS universal (--arch universal) with an injected CSS snippet (--inject inject.css), I get this error:
{
uniqueToX64: [ 'Contents/Resources/app/inject/inject-ac155d.css' ],
uniqueToArm64: [ 'Contents/Resources/app/inject/inject-ef6cd0.css' ]
}
Error during build. Run with --verbose for details. Error: While trying to merge mach-o files across your apps we found a mismatch, the number of mach-o files is not the same between the arm64 and x64 builds
at exports.makeUniversalApp (/.../node_modules/.pnpm/@[email protected]/node_modules/@electron/universal/src/index.ts:108:13)
at buildUniversalApp (/.../node_modules/.pnpm/[email protected]/node_modules/nativefier/src/build/buildNativefierApp.ts:339:5)
Looking at the trace, this comes from Electron's universal module, specifically this snippet that checks if there are files unique to each build output. Since nativefier seems to append a random suffix to injected files (as seen below), electron's check fails.
nativefier/src/build/prepareElectronApp.ts
Lines 130 to 134 in 4c6d0b1
| const postFixHash = generateRandomSuffix(); | |
| const destFileName = `inject-${postFixHash}${path.extname(src)}`; | |
| const destPath = path.join(dest, 'inject', destFileName); | |
| log.debug(`Copying injection file "${src}" to "${destPath}"`); | |
| await fs.copy(src, destPath); |
It looks like two separate builds occur when targeting a universal binary (in the code snippet below), so two separate random suffixes are created for each injected file in each architecture (x64 & arm64). These suffixes should be the same across both builds for each file.
nativefier/src/build/buildNativefierApp.ts
Lines 313 to 319 in 4c6d0b1
| log.info('Creating universal Mac binary...'); | |
| let x64Path: string | undefined; | |
| let arm64Path: string | undefined; | |
| try { | |
| x64Path = path.resolve(await buildNativefierApp(x64Options)); | |
| arm64Path = path.resolve(await buildNativefierApp(arm64Options)); |
Any URL with any options will produce this error so long as it targets a Universal binary with at least one injected file (CSS or JS). The contents of the file don't matter, since the issue lies in the resulting filename.
Steps to reproduce
Here is a minimal example:
touch inject.css
nativefier "https://google.com" --arch universal --inject inject.css
(Error is shown above.)
Expected behavior
A universal app is built, targeting both Intel & Apple silicon Macs.
Actual behavior
Error described above.
Debug info
I think the above info is sufficient enough to describe what goes wrong, though if you need anything else, please let me know.
Context
- Nativefier: 47.1.3
- Node.js: 14.19.1
- Pnpm: 6.32.7
- OS: macOS 12.3.1 (Intel)
Activity
macOS: Move handling of "universal" apps to electron-packager instead…
macOS: Move handling of "universal" apps to electron-packager instead…