|
| 1 | +--- |
| 2 | +title: npm-query |
| 3 | +section: 1 |
| 4 | +description: Dependency selector query |
| 5 | +--- |
| 6 | + |
| 7 | +### Synopsis |
| 8 | + |
| 9 | +<!-- AUTOGENERATED USAGE DESCRIPTIONS START --> |
| 10 | +<!-- automatically generated, do not edit manually --> |
| 11 | +<!-- see lib/commands/query.js --> |
| 12 | + |
| 13 | +```bash |
| 14 | +npm query <value> |
| 15 | +``` |
| 16 | + |
| 17 | +<!-- automatically generated, do not edit manually --> |
| 18 | +<!-- see lib/commands/query.js --> |
| 19 | + |
| 20 | +<!-- AUTOGENERATED USAGE DESCRIPTIONS END --> |
| 21 | + |
| 22 | +### Description |
| 23 | + |
| 24 | +The `npm query` command allows for usage of css selectors in order to retrieve |
| 25 | +an array of dependency objects. |
| 26 | + |
| 27 | +### Piping npm query to other commands |
| 28 | + |
| 29 | +```bash |
| 30 | +# find all dependencies with postinstall scripts & uninstall them |
| 31 | +npm query ":attr(scripts, [postinstall])" | jq 'map(.name)|join("\n")' -r | xargs -I {} npm uninstall {} |
| 32 | + |
| 33 | +# find all git dependencies & explain who requires them |
| 34 | +npm query ":type(git)" | jq 'map(.name)' | xargs -I {} npm why {} |
| 35 | +``` |
| 36 | + |
| 37 | +### Configuration |
| 38 | + |
| 39 | +<!-- AUTOGENERATED CONFIG DESCRIPTIONS START --> |
| 40 | +<!-- automatically generated, do not edit manually --> |
| 41 | +<!-- see lib/utils/config/definitions.js --> |
| 42 | +#### `global` |
| 43 | + |
| 44 | +* Default: false |
| 45 | +* Type: Boolean |
| 46 | + |
| 47 | +Operates in "global" mode, so that packages are installed into the `prefix` |
| 48 | +folder instead of the current working directory. See |
| 49 | +[folders](/configuring-npm/folders) for more on the differences in behavior. |
| 50 | + |
| 51 | +* packages are installed into the `{prefix}/lib/node_modules` folder, instead |
| 52 | + of the current working directory. |
| 53 | +* bin files are linked to `{prefix}/bin` |
| 54 | +* man pages are linked to `{prefix}/share/man` |
| 55 | + |
| 56 | +<!-- automatically generated, do not edit manually --> |
| 57 | +<!-- see lib/utils/config/definitions.js --> |
| 58 | + |
| 59 | +#### `workspace` |
| 60 | + |
| 61 | +* Default: |
| 62 | +* Type: String (can be set multiple times) |
| 63 | + |
| 64 | +Enable running a command in the context of the configured workspaces of the |
| 65 | +current project while filtering by running only the workspaces defined by |
| 66 | +this configuration option. |
| 67 | + |
| 68 | +Valid values for the `workspace` config are either: |
| 69 | + |
| 70 | +* Workspace names |
| 71 | +* Path to a workspace directory |
| 72 | +* Path to a parent workspace directory (will result in selecting all |
| 73 | + workspaces within that folder) |
| 74 | + |
| 75 | +When set for the `npm init` command, this may be set to the folder of a |
| 76 | +workspace which does not yet exist, to create the folder and set it up as a |
| 77 | +brand new workspace within the project. |
| 78 | + |
| 79 | +This value is not exported to the environment for child processes. |
| 80 | + |
| 81 | +<!-- automatically generated, do not edit manually --> |
| 82 | +<!-- see lib/utils/config/definitions.js --> |
| 83 | + |
| 84 | +#### `workspaces` |
| 85 | + |
| 86 | +* Default: null |
| 87 | +* Type: null or Boolean |
| 88 | + |
| 89 | +Set to true to run the command in the context of **all** configured |
| 90 | +workspaces. |
| 91 | + |
| 92 | +Explicitly setting this to false will cause commands like `install` to |
| 93 | +ignore workspaces altogether. When not set explicitly: |
| 94 | + |
| 95 | +- Commands that operate on the `node_modules` tree (install, update, etc.) |
| 96 | +will link workspaces into the `node_modules` folder. - Commands that do |
| 97 | +other things (test, exec, publish, etc.) will operate on the root project, |
| 98 | +_unless_ one or more workspaces are specified in the `workspace` config. |
| 99 | + |
| 100 | +This value is not exported to the environment for child processes. |
| 101 | + |
| 102 | +<!-- automatically generated, do not edit manually --> |
| 103 | +<!-- see lib/utils/config/definitions.js --> |
| 104 | + |
| 105 | +#### `include-workspace-root` |
| 106 | + |
| 107 | +* Default: false |
| 108 | +* Type: Boolean |
| 109 | + |
| 110 | +Include the workspace root when workspaces are enabled for a command. |
| 111 | + |
| 112 | +When false, specifying individual workspaces via the `workspace` config, or |
| 113 | +all workspaces via the `workspaces` flag, will cause npm to operate only on |
| 114 | +the specified workspaces, and not on the root project. |
| 115 | + |
| 116 | +This value is not exported to the environment for child processes. |
| 117 | + |
| 118 | +<!-- automatically generated, do not edit manually --> |
| 119 | +<!-- see lib/utils/config/definitions.js --> |
| 120 | + |
| 121 | +<!-- AUTOGENERATED CONFIG DESCRIPTIONS END --> |
| 122 | +## See Also |
| 123 | + |
| 124 | +* [dependency selector](/using-npm/dependency-selector) |
| 125 | + |
0 commit comments