This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
Ensure the Truffle Project Loader can be loaded in both development and production #1149
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes https://github.com/trufflesuite/ganache/issues/1141
trufflesuite/ganache@7042edd introduced a bug for production (but not development) builds. The commit changed the way Truffle projects were loaded by running a completely separate node process thats installed on the user's machine to make sure that the node that was loading the Truffle project would be the same version that the Truffle project was "compiled" against.
Unfortunately the directory structure built with asar packing in production doesn't actually exist on the disk so the location can't actually be loaded by node. First we needed to specify that the project loader gets unpacked to the disk by adding it into the
build.extraFiles
config inpackage.json
. Then we needed to useelectron.app.getAppPath()
instead of__dirname
to find where the source code is located. This folder is the base root of the repo in dev mode, but it actually points toresources/app.asar
in production, which is why we needed to add a../..
to the path to get to the root folder.I achieved this through passing environment variables to the child. An interesting fun fact is that I originally didn't have
...process.env
, but thePATH
environment variable wasn't passed to the child so it couldn't findnode
; so if you provideoptions.env
to thespawn
, you have to make sure to provide everything that's needed (which makes sense, but was scratching my head for awhile)