Skip to content

ASAR problem in Electron #402

@markkovacs76

Description

@markkovacs76

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.

Activity

isaacs

isaacs commented on Apr 10, 2024

@isaacs
Owner

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

dashart-ke

dashart-ke commented on Jun 11, 2024

@dashart-ke

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

isaacs commented on Jun 13, 2024

@isaacs
Owner

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

markkovacs76

markkovacs76 commented on Jun 13, 2024

@markkovacs76
Author

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

isaacs commented on Jun 13, 2024

@isaacs
Owner

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @isaacs@dashart-ke@markkovacs76

        Issue actions

          ASAR problem in Electron · Issue #402 · isaacs/node-tar