9

I am used to run yarn / npm and then the command:

yarn build-me

or

npm run build-me 

This calls a script command declared in the the local package.json root file.

In my case I'd like to run a script command declared in the package.json of a package in node_modules folder.

How can I do this?

I have installed a test package i wrote inside app. Here is the dependency (in my root app) and I can see it under node_modules

  "dependencies": {
    "@tester/util-package": "^1.0.2"
  }

Under node_modules this util-package also has it's own package.json with the following script

  "scripts": {
    "process-files": "node ./cli.js"
  },

So, I was hoping to run this from the root of my app something like.

yarn util-package process-files 

Of course, this doesn't seem to work.

1

2 Answers 2

17

If you want to run a command inside a submodule, with npm, you can use the explore command, as explained here:

npm explore submodule -- npm run subscript

It seems that yarn does not have an equivalent command, but there is a cwd option (not yet very well documented) that let you choose the working directory:

yarn --cwd node_modules/submodule/ subscript

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

1 Comment

Note that the module is maybe not located under node_modules when you are using workspaces and the path used with the --cwd option must be adapted. n this case npm explore is the more versatile solution.
1

You are looking for the explore command:

npm explore @tester/util-package -- npm run process-files

Comments

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.