dev-cli
dev-cli copied to clipboard
Add custom build options to pack
I am using macos and building an installer for windows. One of my dependencies is grpc
which uses binary modules.
Installing and running the cli on a windows computer results in Failed to load gRPC binary module because it was not installed for the current system
, which could be fixed with rebuilding it for windows (https://stackoverflow.com/questions/47979568/aws-lambda-error-failed-to-load-grpc-binary-module-because-it-was-not-installed).
Is it possible to add an option that somehow triggers the rebuild?
There is no support for building the CLI on windows and right now I don't have any plans to change that (they're all written in bash).
EDIT: sorry I actually read what you wrote (just woke up 😫). I think we'd need to add some kind of step to run postinstall. Maybe in the package.json scripts?
First I was just thinking I could run npm run postinstall
after it's installed but it's not that easy. we have node, but npm might not be actually installed on the machine
A hook might be better here. We do have the update
hook that is called anytime the CLI is updated. Perhaps we could just call that somehow when the CLI is first installed.
So, rebuilding is not possible if we don't have npm installed on the machine? Yarn also offers no rebuild capabilty (https://github.com/yarnpkg/yarn/issues/756). I currently see two options:
- also ship/install npm for the target machine/OS so that we can do an
npm rebuild
duringpostinstall
orupdate
hook. That will increase the package size and make installing slower. - Add the possibility to execute commands before everything is packed into the .exe/pkd/whatever. That way I could execute
npm rebuild grpc --target=6.1.0 --target_arch=x64 --target_platform=linux --target_libc=glibc
and have the dependency already ready for the target machine.
I think I will try to do the rebuild manually before I pack:win
and try if it works on the target machine
We don't ship with yarn or npm. I would not recommend that approach as your users will need to also have all the dependencies installed to compile the code. I think you'll need to do something like have the prepare step of your CLI compile for the different targets.
Something would need to be added here I think: https://github.com/oclif/dev-cli/blob/master/src/tarballs/build.ts#L88
It could run whatever is in the prepare
step, but because the devDependencies
won't be installed that might not work quite right. We could either add a new type of script like oclif:build
or something and set a couple of env vars you could use to see what the arch and platform it is targeting is. OR we could run the prepare step and put the ./node_modules/.bin
from the root of the project (not the root of the current target) which would have all the devDependencies installed.
I'm not sure which is better right now