Closed boeckMt closed 1 year ago
Why is that a better approach then cd-ing into the directory to run the commands? You can even do it in a subshell so the working directory doesn't change ((cd dist && npm pkg whatever)
)
@ljharb I thought it would be easier for some users if they could specify a path string in e.g. glob patterns, so they don't need to care about finding the exact paths with bash commands.
But your right, it could also be done like this:
find ./dist -name "package.json" -exec dirname {} \; | while read line; do cd $line; npm pkg delete scripts.build; cd ..; done
Motivation ("The Why")
Sometimes it would be helpful to set/edit or remove some values in package.json files npm-pkg that are not included in workspaces or the main package. E.g. there was a build script that puts all packages modified in the dist folder for publishing. After that, the package.json files in that folder should be edited to remove some properties only needed for development.
Example
npm pkg delete scripts.build --paths dist/*
this might be useful for other commands as well
npm exec -c '<cmd> [args...]' --paths dist/*
How
Current Behaviour
Npm
pkg
currently only works for a package.json in the same folder or for workspaces.Desired Behaviour
Allow custom paths to run commands like
pkg
.Alternatives
@npmcli/package-json and a custom script to get all the paths and then update the packages could be used.
References