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

ASAR problem in Electron #402

Open
markkovacs76 opened this issue Feb 27, 2024 · 5 comments
Open

ASAR problem in Electron #402

markkovacs76 opened this issue Feb 27, 2024 · 5 comments

Comments

@markkovacs76
Copy link

If node-tar is used in Electron environment where asar file support is enabled, the entry names with extension asar will not be written correctly, because Electron uses its own 'fs' library which handles asar files as a sub-directory.
Hence, Electron does offer 'original-fs' library if you want to use asar file as normal file instead of a virtual sub-directory in the modified 'fs'.
It would be good if node-tar supported the 'original-fs' library by demand instead of 'fs' from electron.

@isaacs
Copy link
Owner

isaacs commented Apr 10, 2024

I'm not sure what the feature request is here. What would the interface look like, and how would it behave?

@dashart-ke
Copy link

I ran into a similar issue today:
In my electron based application, I tried to extract a tar.gz archive, which is contains an electron application.

After extraction, the following file:
ELECTRON_APP_NAME.app/Contents/Resources/app.asar
is missing in target directory:
grafik

The log (verbose) reports, it would extract 'app.asar':
...
Extracting: ELECTRON_APP_NAME.app/Contents/Resources/nb.lproj/
Extracting: ELECTRON_APP_NAME.app/Contents/Resources/app.asar
Extracting: ELECTRON_APP_NAME.app/Contents/Resources/am.lproj/
...

This looks like an internal side effect of special electron fs behavior, which will treat app.asar like a regular directory
https://www.electronjs.org/docs/latest/tutorial/asar-archives#treating-an-asar-archive-as-a-normal-file

@isaacs
Copy link
Owner

isaacs commented Jun 13, 2024

@dashart-ke ok, so, same question I asked @markkovacs76: what do you want tar to do about it?

@markkovacs76
Copy link
Author

markkovacs76 commented Jun 13, 2024

Either you could add an extra option for tar.x to use original-fs instead of fs library. In this case the user should import fs-original and append the reference to the options.

Or in the source in node-tar the electron could be detected:

if (typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron) {
        return true;
}

If yes, import fs from 'node:fs' in your code should be import fs from 'original-fs'.

Or, I just found the easiest solution. In Electron I found
process.noAsar = true
But this approach could be used outside the library, before e.g. the tar.x is called and afterwards this should be set to false again if needed.

@isaacs
Copy link
Owner

isaacs commented Jun 13, 2024

So the feature request is to have a fs option, which defaults to import * as fs from 'node:fs', that you can pass your own fs implementation into?

Seems fine to me. Just a pain to go through and make the edits. But patch welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants