question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: beforePack callback (or: using distributed Node version to run some scripts before packaging)

See original GitHub issue
  • Version: 22.9.1
  • Electron Version: 11.3.1
  • Electron Type (current, beta, nightly): current
  • Target: darwin, windows

electron-builder already offers the afterPack callback. However, before all the files are packaged into an asar, I need to run bytenode on some of them. Now, in order for bytenode to work properly, it needs to be executed using the Node binary which will be distributed with the app.

As of now, when I use asar, afterPack executes when the files are already in the asar archive. The current workarounds I came up with:

  1. From within afterPack run code that will unpack asar, compile the files with bytenode and then create the asar archive again.
    • This already doesn’t play well with asarUnpack, as extracting the asar archive into an app folder copies those unpacked files there as well. So before creating the archive again I would need to remove paths from asarUnpack from my app folder. But I worry that in the future it’s going to cause problems with smartUnpack anyway.
  2. Use extraResources so that the files which need to be compiled with bytenode are not in the asar archive at all. Then compile them in afterPack.
    • If those compiled files happen to require some node modules, then most probably I’d need to manipulate the NODE_PATH env variable so that Node knows where to find the modules (in the asar archive). I’m yet to check if this actually works.

With something like beforePack, I could run bytenode on selected files and then builder could just include them in the asar as usual, without needing to worry about asarUnpack and smartUnpack myself.

This is somewhat similar to #4600, but the author of that issue seems to have asked about sth like afterPack.

Perhaps there’s a more straightforward way to solve my problem than beforePack, in which case I’d highly appreciate any advice!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
davejcommented, Mar 9, 2021

I’m having a similar issue. beforeBuild doesn’t work because I want the hook to be called after the dependencies have been installed. A beforePack would be ideal. In electron-forge I could use an afterCopy hook.

0reactions
stale[bot]commented, Apr 17, 2022

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I run a script before install a new nodejs dependecy
Start by identifying all the problems you're trying to address with an on-dependency-install hook. You give the example of preventing the installation of...
Read more >
scripts - npm Docs
Scripts from dependencies can be run with npm explore <pkg> -- npm run <stage> . ... Runs BEFORE the package is packed, i.e....
Read more >
JavaScript developer reference for Azure Functions
This guide contains detailed information to help you succeed developing Azure Functions using JavaScript. As an Express.js, Node.js, ...
Read more >
Update the Node.js agent | New Relic Documentation
If the newrelic module is listed in your package.json , run npm install . ... Update New Relic dependencies to versions with updated...
Read more >
tutorial.html - Dojo Toolkit
In order to load an AMD module under NodeJS, we need a module loader. The require() that comes default with Node.js can only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found