Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"postinstall" script being called with an extra argument #1

Closed
ibc opened this issue Oct 29, 2019 · 4 comments
Closed

"postinstall" script being called with an extra argument #1

ibc opened this issue Oct 29, 2019 · 4 comments

Comments

@ibc
Copy link

ibc commented Oct 29, 2019

Not sure how to describe the issue, so will provide exact steps to reproduce it (in OSX at least):

Clone my mediasoup-demo project:

$ git clone [email protected]:versatica/mediasoup-demo.git
$ cd mediasoup-demo

Such a project has a server/package.json that depends on my mediasoup "devel" branch.

Install server deps:

$ cd server
$ npm install

It will install mediasoup devel branch from GitHub. mediasoup "devel" branch uses @dr.amaton/run-script-os 1.2.1, and here the "scripts" in package.json.

Now, within the server/ folder of the mediasoup-demo project, let's just "update" mediasoup:

$ npm update mediasoup # or npm install mediasoup

It fails as follows:

> [email protected] postinstall /private/tmp/mediasoup-demo/server/node_modules/mediasoup
> run-script-os


> [email protected] postinstall:default /private/tmp/mediasoup-demo/server/node_modules/mediasoup
> make -C worker "mediasoup"

make: *** No rule to make target `mediasoup'.  Stop.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] postinstall:default: `make -C worker "mediasoup"`
npm ERR! Exit status 2

As you can see in the mediasoup package.json, the "postinstall" script does the following:

"postinstall": "run-script-os",
"postinstall:win32": "\"\"%NODE%\"\" worker/win-tasks.js make",
"postinstall:default": "make -C worker"

So in OSX it should just execute make -C worker. However, in the scenario above it is NOT executing that but instead the following:

make -C worker "mediasoup"

And obviously, in the worker/Makefile of mediasoup there is not any "mediasoup" task, so make fails.

The problem is that, somehow, run-script-os is adding that "mediasoup" argument to the "postinstall:default" script, making it fail.

@kawatzaki
Copy link
Owner

OK. I'll check it out, seems like a core issue

@kawatzaki
Copy link
Owner

I'm assuming it works fine with just npm update

This situation occurs because the package is meant to transfer any arguments to the script being called, and these are captured as whatever string after the command name.

I'm going to make a couple of special cases for both install and update, so that the params can be ignored. I guess we can justify this as being incompatible with packages that use run-script-os internally, which could break (as this one) whenever installed or updated specifically.

@kawatzaki
Copy link
Owner

kawatzaki commented Oct 29, 2019

This is actually very similar in nature to kawatzaki/run-script-os#1

And it introduced a new argument that you can use within your package.json script declaration, such as:

"scripts": {
  "postinstall": "run-script-os --no-arguments", // JSON comments don't exist but here's the magic
  "postinstall:default": "make -C worker" // now it shouldn't pass the arguments down
}

I tried it with the little example I made, but it should work just fine, @ibc can you give it a try?
Also I'm sorry I didn't thought of this before, we really should be adding this to the README.md

UPDATE: Added some details about this issue on the README.md file, on the section "Lifecycle hooks".

@ibc
Copy link
Author

ibc commented Oct 29, 2019

It works, THANKS!

Closing issue.

@ibc ibc closed this as completed Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants