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

1
  • 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.
    – Andreas
    Jun 26, 2020 at 5:26
1

You are looking for the explore command:

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.