# @dotcom-tool-kit/package-json-hook

> This plugin manages Tool Kit commands that are run from npm scripts, via a Tool Kit [`Hook`](#hooks) that automatically manages `package.json`.

Latest version **6.0.1** (published 2026-01-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install @dotcom-tool-kit/package-json-hook
pnpm add @dotcom-tool-kit/package-json-hook
yarn add @dotcom-tool-kit/package-json-hook
bun add @dotcom-tool-kit/package-json-hook
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 6.0.1 |
| Published | 2026-01-15 |
| First published | 2021-08-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=20.x |
| Dependencies | 7 |
| Unpacked size | 16.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | FT.com Platforms Team |
| Maintainers | quarterto, the-ft, robertboulton |

## Links

- npm: https://www.npmjs.com/package/@dotcom-tool-kit/package-json-hook
- Repository: https://github.com/financial-times/dotcom-tool-kit
- Homepage: https://github.com/financial-times/dotcom-tool-kit/tree/main/plugins/package-json-hook
- Issues: https://github.com/financial-times/dotcom-tool-kit/issues
- npm.io page: https://npm.io/package/@dotcom-tool-kit/package-json-hook

## Dependencies (7)

- [zod](https://npm.io/package/zod.md) ^3.24.4
- [tslib](https://npm.io/package/tslib.md) ^2.8.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [@dotcom-tool-kit/base](https://npm.io/package/@dotcom-tool-kit/base.md) ^2.1.0
- [@dotcom-tool-kit/plugin](https://npm.io/package/@dotcom-tool-kit/plugin.md) ^2.1.0
- [@dotcom-tool-kit/conflict](https://npm.io/package/@dotcom-tool-kit/conflict.md) ^2.0.1
- [@financial-times/package-json](https://npm.io/package/@financial-times/package-json.md) ^4.0.0

## Recent versions

- 6.0.1 (latest) — 2026-01-15
- 6.0.1-beta.14 (prerelease) — 2026-01-15
- 6.0.1-beta.13 — 2026-01-15
- 6.0.1-beta.12 — 2026-01-15
- 6.0.1-beta.11 — 2026-01-14
- 6.0.1-beta.10 — 2026-01-13
- 6.0.1-beta.9 — 2026-01-13
- 6.0.1-beta.8 — 2026-01-13
- 6.0.1-beta.7 — 2026-01-13
- 6.0.1-beta.6 — 2026-01-13
- 6.0.1-beta.5 — 2026-01-12
- 6.0.1-beta.4 — 2026-01-12
- 6.0.1-beta.3 — 2026-01-12
- 6.0.1-beta.2 — 2026-01-09
- 6.0.1-beta.1 — 2026-01-08
- … 117 more at https://npm.io/package/@dotcom-tool-kit/package-json-hook/versions

## README

# @dotcom-tool-kit/package-json-hook

This plugin manages Tool Kit commands that are run from npm scripts, via a Tool Kit [`Hook`](#hooks) that automatically manages `package.json`.

Although you can write npm scripts yourself in `package.json`, this plugin allows other Tool Kit plugins to define them in a repeatable, modular way. Adding custom scripts via configuring this plugin in your `.toolkitrc.yml` means that if a new use case emerges, it's much easier to abstract it into a plugin that can be shared with other Tool Kit users.

## Installation

Most repositories won't need to use this plugin directly. It's installed of a dependency of plugins like [`npm`](../npm) which configure it with standard use cases.


Install `@dotcom-tool-kit/package-json-hook` as a `devDependency` in your app:

```sh
npm install --save-dev @dotcom-tool-kit/package-json-hook
```

Add the plugin to your [Tool Kit configuration](https://github.com/financial-times/dotcom-tool-kit/blob/main/readme.md#configuring-tool-kit):

```yaml
plugins:
	- '@dotcom-tool-kit/package-json-hook'
```

And install this plugin's hooks:

```sh
npx dotcom-tool-kit --install
```

<!-- begin autogenerated docs -->
## Hooks

### `PackageJson`

This hook accepts a nested object with a structure that matches the generated output in `package.json`. The values are used as Tool Kit command names to run. You can provide a single command or an array; multiple commands are concatenated in order.

For more complex use cases, you can provide an object instead of a command. The object must contain keys `commands` (as above), and `trailingString` (which will be appended to the resulting `dotcom-tool-kit` CLI invocation). This is useful for tasks that accept a list of files after a trailing `--`.

Options provided in your repository's `.toolkitrc.yml` for this hook are merged with any Tool Kit plugin that also provides options for the hook.

For example, configuring this hook with the following options:

~~~yml
options:
  hooks:
    - PackageJson:
        scripts:
          start: 'run:local'
          customScript:
            commands:
              - custom:one
              - custom:two
            trailingString: '--'
~~~

will result in the following output in `package.json`:

~~~json
{
  "scripts": {
    "start": "dotcom-tool-kit run:local",
    "customScript": "dotcom-tool-kit custom:one custom:two --"
  }
}
~~~

<!-- hide autogenerated schema docs -->

<!-- end autogenerated docs -->

---
_Source: https://npm.io/package/@dotcom-tool-kit/package-json-hook · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
