5

I have a package.json script for example npm run script1 and I have also private npm package which is added as a dependency in my project and this package has also scripts in package.json and this script name script2. I want that when I run npm run script1 then run automatically start script2. Is that possible?

Thank you.

2 Answers 2

9

Package.json

"scripts": {
  "runbothscripts": "npm run script1 && npm run script2"
}

Should run both scripts for you if you execute it by doing npm run runbothscripts.

If script2 would be in a different folders package.json you also first navigate to that folder by doing cd ./otherfolder && npm run script2

Sign up to request clarification or add additional context in comments.

1 Comment

Can you navigate to the folder by adding cd ./node_modules/insertpackagenamehere && npm run script2 ? But I would recommend trying @harsh989 's approach with npm explore first
4

Use npm explore command. For example, to run a test script from lodash after running eslint, add this script in your package.json file:

"scripts": {
    "script1": "eslint . && npm explore lodash -- npm run test"
}

Then run it as:

npm run script1

2 Comments

This looks pretty useful. Does yarn has any similar alternative?
@GanapatiVS I haven't used yarn myself but I have read that in yarn, you can use "cwd" option to run scripts from other module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.