NPM-SET-SCRIPT(1)

πŸ“¦ version 8.5.1, in ubuntu jammy

✨ NAME ✨

npm-set-script β€” set tasks in the scripts section of package.json πŸ’…

okay bestie, this is the npm-set-script manual page, and it's genuinely one of the most lowkey-useful little commands npm has. let's get into it 🫢


πŸŽ€ Synopsis πŸŽ€

So basically: it's an npm command that lets you create a task in the scripts section of the package.json. that's it, that's the whole vibe. ✨

npm set-script [<script>] [<command>]

Example:

  • npm set-script start "http-server ."

and then your package.json ends up looking like this:

{
  "name": "my-project",
  "scripts": {
    "start": "http-server .",
    "test": "some existing value"
  }
}

see how start just... materialized in there? and test kept its existing value untouched? iconic behavior, no notes πŸ¦‹


βš™οΈ Configuration βš™οΈ

heads up: the config descriptions below are autogenerated. the page literally says <!-- AUTOGENERATED CONFIG DESCRIPTIONS START -->, then <!-- automatically generated, do not edit manually -->, then <!-- see lib/utils/config/definitions.js -->. so like... don't edit them manually, iykyk πŸ™ˆ

🧚 workspace

  • Default: (nothing β€” it's just blank)
  • Type: String (and yes, it can be set multiple times πŸ‘‘)

This one enables running a command in the context of the configured workspaces of the current project, while filtering so it only runs in the workspaces you defined with this config option. very "main character, but only in these specific rooms" energy.

Valid values for the workspace config are either:

  • Workspace names
  • Path to a workspace directory
  • Path to a parent workspace directory (this one will result in selecting all workspaces within that folder)

When it's set for the npm init command, this may be set to the folder of a workspace which does not yet exist β€” and npm will create the folder and set it up as a brand new workspace within the project. literally manifesting a workspace fr fr 🌈

This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually --> <!-- see lib/utils/config/definitions.js --> πŸ’œ


🌸 workspaces

  • Default: null
  • Type: null or Boolean

Set it to true to run the command in the context of all configured workspaces. all of them. every single one. periodt.

Explicitly setting this to false will cause commands like install to ignore workspaces altogether. and when it's not set explicitly, here's the tea:

  • Commands that operate on the node_modules tree (install, update, etc.) will link workspaces into the node_modules folder.
  • Commands that do other things (test, exec, publish, etc.) will operate on the root project, unless one or more workspaces are specified in the workspace config.
This value is not exported to the environment for child processes.

<!-- automatically generated, do not edit manually --> <!-- see lib/utils/config/definitions.js --> πŸ’œ


πŸ“ include-workspace-root

  • Default: false
  • Type: Boolean

Include the workspace root when workspaces are enabled for a command. πŸŽ€

When it's false, specifying individual workspaces via the workspace config, or all workspaces via the workspaces flag, will cause npm to operate only on the specified workspaces β€” and not on the root project. so the root gets left on read, basically. 😭

<!-- automatically generated, do not edit manually --> <!-- see lib/utils/config/definitions.js --> πŸ’œ

and that's the end of the autogenerated block, btw β€” the page closes it with <!-- AUTOGENERATED CONFIG DESCRIPTIONS END --> ✨


πŸ‘€ See Also πŸ‘€

  • npm help run-script
  • npm help install
  • npm help test
  • npm help start

okay so the footer of this page was literally just undefined NaN with NPM-SET-SCRIPT(1) on the side, which is... a whole mood honestly, the manpage said "no thoughts, head empty" πŸ’€ but anyway, this was the npm-set-script page from the npm manual, dated undefined NaN, and you absolutely ate reading all of it. slay. go set a script. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from