Forrest logo
back to the npm tool

npm-query:tldr:14133

npm-query: Find all dependencies with postinstall scripts and uninstall them.
$ npm query ":attr(scripts, [postinstall])" | jq 'map(.name) | join("\n")' -r | xargs -I {} npm uninstall {}
try on your machine

This command performs the following operations using the npm (Node Package Manager), jq (command-line JSON processor), and xargs (execute command from standard input) tools:

  1. npm query ":attr(scripts, [postinstall])": This command queries the npm package registry for packages that have a script called "postinstall" defined in their package.json file. It returns JSON data containing information about these packages.

  2. | jq 'map(.name) | join("\n")': The output from the previous command is piped (using the "|" symbol) into jq, which applies the specified filter operation on the JSON data. The filter extracts the name property for each package and creates an array. Then, the join function is used to concatenate the array elements into a single string separated by newline characters.

  3. | xargs -I {} npm uninstall {}: The output from the previous command is piped into xargs, which executes the npm uninstall command for each package name passed as an argument (represented by {} in the command). This effectively uninstalls all the packages returned by the earlier query command.

In summary, this command fetches a list of npm packages that have a "postinstall" script defined in their package.json file, and then uninstalls all of those packages.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the npm tool