Skip to content
This repository was archived by the owner on Sep 29, 2023. It is now read-only.
This repository was archived by the owner on Sep 29, 2023. It is now read-only.

Randomness in injected filenames prevent universal apps from building #1405

Closed

Description

@i077

Homework

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.

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.

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

  1. added a commit that references this issue on Aug 2, 2022
    c8fc0b6
  2. added a commit that references this issue on Nov 9, 2022
    045a352
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions