Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm script command to run a script command from another package.json

Tags:

npm

I have two separate projects that use npm - so I have both :
some_base_folder/projectA/package.json and some_base_folder/projectB/package.json

Each of those files has a scripts section in it.

If I go to some_base_folder/projectA/ and run npm run-script test it executes the test command from the scripts section of some_base_folder/projectA/package.json as it should.

What can I put as the value of "scripts": {test_projectA:'????' in some_base_folder/projectB/package.json so that when I am in some_base_folder/projectB/ and I run npm run-script test_projectA it will be execute the test script of Project A?

I tried ../projectA/npm run-script test but it says:

'..' is not recognized as an internal or external command, operable program or batch file. 

I am running under windows 7 but would prefer a solution that would also work properly on linux.

like image 213
epeleg Avatar asked Jan 10 '16 21:01

epeleg


People also ask

How do I run a npm script in package json?

To define an NPM script, set its name and write the script under the 'scripts' property of your package. json file: To execute your Script, use the 'npm run <NAME-OF-YOUR-SCRIPT>' command. Some predefined aliases convert to npm run, like npm test or npm start, you can use them interchangeably.

How do I run two npm commands?

&& will run your scripts sequentially while & will run them in parallel. A quick way of doing it is npm run start-watch & npm run wp-server . This will run the first command as a background thread. This works really well when one of the commands is not long running and does not need to be manually exited later.

What is npm run dev command?

The npm run dev command is a generic npm command that you can find in many modern web application projects. This command is used to run the dev script defined in the project's package. json file. To know what is exactly being run by the command, first you need to open the package.


2 Answers

well it turns out to be quite simple:

"scripts": {   test_projectA:"cd ../projectA && npm run-script test" } 
like image 189
epeleg Avatar answered Sep 19 '22 20:09

epeleg


You should use --prefix.

npm run [command] --prefix path/to/your/other/folder 

And for yarn:

yarn --cwd path/to/your/other/folder [command] 
like image 45
Dominic Avatar answered Sep 17 '22 20:09

Dominic