Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: asar handling of package.json #46099

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

codebytere
Copy link
Member

Description of Change

Fixes an issue where packaged apps could sometimes fail to find the correct package.json in asar directories.

Tested with:

npx create-electron-app@6.0.4 my-commonjs-app
cd my-commonjs-app
npm run package
echo "asfjhlasf;asklfas" > package.json
./out/commonjs-app-darwin-arm64/commonjs-app.app/Contents/MacOS/commonjs-app

To ensure that it finds the package.json in app.asar as expected.

Checklist

Release Notes

Notes: Fixed an issue where packaged apps could sometimes fail to find the correct package.json in asar directories.

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/35-x-y PR should also be added to the "35-x-y" branch. target/36-x-y PR should also be added to the "36-x-y" branch. labels Mar 18, 2025
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Mar 18, 2025
@codebytere codebytere requested a review from deepak1556 March 18, 2025 10:12
Comment on lines +1012 to +1015
const realPath = archive.copyFileOut(filePath);
if (!realPath) return undefined;

return getNearestParentPackageJSON(realPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this without copyFileOut, that seems excessive. I also don't think this works correctly. This is going to copy out the file at checkPath but what it would need copied out is the nearest package.json.

I think we need to actually re-implement getNearestParentPackageJSON in JS here and just have it be ASAR aware. i.e. traverse up the path tree until we leave the ASAR, then we hand it back off to native land

Comment on lines +1027 to +1030
const realPath = archive.copyFileOut(filePath);
if (!realPath) return undefined;

return getNearestParentPackageJSONType(realPath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, copyFileOut isn't copying the file we need, in fact it may be a directory not a file. We should re-implement here

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Mar 19, 2025
@codebytere codebytere marked this pull request as draft March 26, 2025 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes target/35-x-y PR should also be added to the "35-x-y" branch. target/36-x-y PR should also be added to the "36-x-y" branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants