Pack & unpack node_modules of an Electron Native application to be patched

Viewed 2735

First of all, I am generating an electron native application using electron-builder, npm and npx. The next commands/steps are being executed to compile and generate the electron native application:

  1. npm run build -- --prod --build-optimizer (to compile app)
  2. npx electron-builder build --windows (to generate an electron windows app)

Later, I obtain a myApp folder which contains:

/win-unpacked
electron-builder-effective-config.yaml
myApp.exe

My application uses the node_modules folder which contains all node dependencies used in my application.

My question is: are there any way to unpack the native application or similar and patch new changes inside node_modules?

After perform an investigation, I have discovered that node dependencies are packed in system cache inside an app.asar file which contains a dist folder with some .js files.

In developer tools:

devtools-dist-files

Inside app.asar:

enter image description here

Are there any way to "deploy" node modules folder with the aim to perform patch operations of each package and change the code inside node modules folders?

I will appreciate any kind of help.

2 Answers

Asar is a read only archiv format, so you cant patch any files in the archive. But what you can do is to disable the asar option in your build config.

So in your package.json define it like this:

"build": {
    "appid": "........",
    "win":   {........},
    "asar":  false
}

if you build this, there is no asar archive anymore and you can overwrite any file...

what you can also do is using asar programatically. So you can unpack the asar archive, updating files and package new archive. See here how you can use it

Contrary to what is being said here, patching a .asar archive is totally possible. I have published a library on NPM called patch-asar that does specifically this.

Related