Tags: electron/universal
Tags
fix: support ESM app entrypoints in the universal shim (#210) * fix: support ESM app entrypoints in the universal shim When the x64 and arm64 app.asar (or app dir) contents diverge, the generated entry shim used `require()` to load the per-arch archive. If the inner app's entrypoint is an ES module this throws ERR_REQUIRE_ESM at launch. Detect each arch's entrypoint module format from its package.json and, only when both arches agree on ESM, ship an ESM shim that uses dynamic import. If the two arches disagree on module system, fail the build with a clear error instead of producing a broken bundle. - Add detectEntrypointModule / resolveShimModule to asar-utils - Add ESM shim sources entry-asar/esm/{has,no}-asar.mts compiled to .mjs - Wire both the HAS_ASAR and NO_ASAR shim sites in makeUniversalApp - Add unit tests for the detection logic and ESM integration tests Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EPgSb3xj4vdi1mUNSzpVUD * test: fix ESM fixtures to diverge via a unique file, not shared entrypoint content * test: mirror existing no-asar fixture divergence for ESM The no-asar ESM fixtures are copied straight into the bundle tree, so diverging via a loose plain `extra-file.txt` was classified as a unique PLAIN file and tripped makeUniversalApp's mach-o parity guard. Diverge via uniquely-named `.bin` files instead (classified as V8 snapshots and excluded from the parity check), exactly the way the existing non-ESM `should shim two different app folders` test does. * test: raise verifyApp timeout for heavy integration tests The heavy verifyApp integration tests run ~60s each on their own and the suite is contended under maxConcurrency, so 80s left too little margin and one test timed out at ~140s. Raise VERIFY_APP_TIMEOUT to 180s. * fix: use raw path for ESM shim dynamic import and exit on failure * fix: use raw path for ESM shim dynamic import and exit on failure * test: add electron28 dependency and run ESM fixtures on Electron 28 * test: assert ESM universal app boots and emits index.mjs instead of snapshotting * build: update electron devDependencies Bump the aliased electron dev dependency used by the ESM fixtures from electron@^28.0.0 to the latest stable electron@^43.0.0 and rename the alias/constant accordingly (electron28 -> electron43, ELECTRON_28_VERSION -> ELECTRON_43_VERSION). --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Erick Zhao <erick@hotmail.ca>
fix: clarify misleading SHA mismatch error message (#209) The error thrown when plain files have mismatched SHAs claimed it covered all "non-binary files", but the check only iterates over AppFileType.PLAIN files. Reword the message to accurately describe the files actually compared. Fixes #103 Co-authored-by: Claude <noreply@anthropic.com>
fix: replace external dependencies with Node.js built-ins (#189) * Remove 5 production dependencies in favor of Node.js builtins Replace @malept/cross-spawn-promise with child_process.execFile, debug with util.debuglog, minimatch with path.matchesGlob (Node 22), dir-compare with a simple recursive comparison, and plist with macOS plutil command. This eliminates ~22 transitive packages, leaving @electron/asar as the sole production dependency. https://claude.ai/code/session_0112RFfDPLMXemxFs6qcKf27 * Keep debug and plist as production dependencies Restore debug and plist imports/usage per review feedback. The final set of removed dependencies is: @malept/cross-spawn-promise, dir-compare, and minimatch. https://claude.ai/code/session_0112RFfDPLMXemxFs6qcKf27 * Add unit tests for compareDirectories and matchGlob Extract compareDirectories and matchGlob into file-utils.ts as shared exports, deduplicating the matchBase logic from 3 files. Add tests covering: identical/distinct/left-only/right-only files, nested dirs, symlinks, empty dirs, and matchBase vs full-path glob patterns. https://claude.ai/code/session_0112RFfDPLMXemxFs6qcKf27 * Fix compareDirectories failing on symlinked directories When readdir returns a symlink entry, isDirectory() returns false even if the symlink target is a directory. Stat the resolved path to determine the actual type, so symlinked directories are traversed instead of read as files (EISDIR). https://claude.ai/code/session_0112RFfDPLMXemxFs6qcKf27 --------- Co-authored-by: Claude <noreply@anthropic.com>
perf: detect Mach-O via magic bytes and parallelize test suite (#180) * perf: detect Mach-O via magic bytes and parallelize test suite Runtime improvements: - Replace `file --brief --no-pad` spawn-per-file with direct magic byte reads in getAllAppFiles. Adds isMachO() helper with disambiguation between Mach-O fat binaries and Java .class files (both 0xCAFEBABE; bytes 4-7 are nfat_arch for Mach-O, major/minor version for Java). - Try APFS copy-on-write clone (cp -cR) when staging the x64 template, falling back to cp -R on non-APFS volumes. - Resolve appPath through realpath before walking to avoid symlink edge cases. Test suite improvements: - Run fixture templateApp setup in parallel (globalSetup). - Convert makeUniversalApp suite to describe.concurrent with per-test mkdtemp output dirs; pass ExpectStatic through helpers so snapshots attribute to the right test under concurrency. - Extract Electron zip into a unique tmpdir in templateApp to avoid races on the intermediate Electron.app path. - Use mkdtemp for staging app dirs instead of random-suffix collision avoidance. - Cap maxConcurrency at 4. * test: pre-warm electron download cache before parallel fixture setup @electron/get is not safe for concurrent downloads of the same artifact. On CI with a cold cache, the parallel templateApp calls in globalSetup raced writing to the same cache path and produced a corrupt/missing zip. Warm the cache for both archs serially in globalSetup before any parallel work starts; all subsequent templateApp calls (in globalSetup and in the concurrent test suite) then hit the cached zip. * ci: use macos-latest-xlarge runner for tests * chore: add debug logging for APFS clone vs regular copy path
fix: Skip `lipo` if native module is already universal. Add native mo… …dule fixtures for `lipo` tests (#126) * fix: when native modules are already universal, don't lipo. adds `node-mac-permissions` fixture from https://github.com/codebytere/node-mac-permissions and resolves 3 `it.todo` test cases * add test `different app dirs with different macho files (shim and lipo)` * add additional test * PR feedback * gotta close `fd` * use `stream` to read first 4 bytes. copy native fixture before packing into asar to leverage `unpack: "**/*.node"` properly. * convert params to object * rename `createTestApp` to `createStagingAppDir` and add jsdoc to the function * compiler error from merge conflict * update snapshots * update snapshots * only check x64Content since it's the tmp app * compile macho binaries at runtime using hellow-world.c for fixtures in lipo tests * Update jest.setup.ts Co-authored-by: Erik Moura <erikian@erikian.dev> * Update jest.setup.ts Co-authored-by: Erik Moura <erikian@erikian.dev> * remove unstable properties for specific keys * force redo * update snapshots * stripping only hello-world from snapshot and only hash from macho-specific asar integrity * optimize logic :) --------- Co-authored-by: Erik Moura <erikian@erikian.dev>
fix: Allow `EnableEmbeddedAsarIntegrityValidation` when multiple asar… …s are present in app (#124) - When an application uses multiple asars (`webapp.asar`, `anything.asar`, etc.), `EnableEmbeddedAsarIntegrityValidation` fuse breaks the application due to not all asars having integrity generated for them. Fixes: #116 - **Also fixes bug** to correctly test `makeUniversalApp no asar mode should shim two different app folders`, (it was not having an asar integrity generated for the shimmed asar) Functionality added: - Moves all asar integrity generation to **after** all app assets have been merged/shimmed/copied. This allows other asars that were provided to also be scanned and have asar integrity generated for them. - Extracted common Integrity logic to a single file `integrity.ts` - Adds unit test for multi-asar apps
PreviousNext