# @cprussin/transform-package-json

> A tool to help generate a package.json for publishing.

Latest version **2.1.1** (published 2026-04-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @cprussin/transform-package-json
pnpm add @cprussin/transform-package-json
yarn add @cprussin/transform-package-json
bun add @cprussin/transform-package-json
```

Provides the command `transform-package-json`.

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2026-04-22 |
| First published | 2023-05-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 1 |
| Unpacked size | 32.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 4 |
| Author | Connor Prussin |
| Maintainers | cprussin |
| Keywords | package.json, publish |

## Links

- npm: https://www.npmjs.com/package/@cprussin/transform-package-json
- Repository: https://github.com/cprussin/cprussin-monorepo
- Homepage: https://www.cprussin.net/modules/_cprussin_transform-package-json.html
- Issues: https://github.com/cprussin/cprussin-monorepo/issues
- npm.io page: https://npm.io/package/@cprussin/transform-package-json

## Dependencies (1)

- [yargs](https://npm.io/package/yargs.md) ^18.0.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.1.1 (latest) — 2026-04-22
- 2.1.0 — 2025-12-15
- 2.0.0 — 2025-06-17
- 1.4.2 — 2025-03-31
- 1.4.1 — 2025-03-11
- 1.4.0 — 2025-03-11
- 1.3.1 — 2024-06-03
- 1.3.0 — 2024-03-01
- 1.2.0 — 2023-07-21
- 1.1.0 — 2023-06-02
- 1.0.2 — 2023-05-10
- 1.0.1 — 2023-05-09
- 1.0.0 — 2023-05-05

## README

**@cprussin/transform-package-json v2.1.1**

***

# @cprussin/transform-package-json v2.1.1

This package contains a CLI and an API for transforming a package.json into a
new location while patching relative paths and removing development-only
fields.

# Installing

Use the package manager of your choice to install:

- **npm**: `npm install --save-dev @cprussin/transform-package-json`
- **pnpm**: `pnpm add -D @cprussin/transform-package-json`
- **yarn**: `yarn add -D @cprussin/transform-package-json`

# CLI Usage

The CLI takes a path to an input `package.json` and a path to an output
`package.json`.  It will then run the following transformations on the input,
saving the result to the output path:

- Remove the `devDependencies` and `scripts` fields
- If `--removeType` is paassed, remove the `type` field (for instance, you
  may want to do this is you're transpiling ESM to CJS)
- Update relative path references so that the new `package.json` points to
  the same files as the old one.  Fields that are updated are:
  - `main`
  - `types`
  - `bin`
  - `exports`

For example, you can use the CLI by calling:

```sh
transform-package-json --removeType ./package.json ./dist/package.json
```

Which will convert this `package.json`:

```json
{
  name: "foo",
  type: "module",
  main: "./dist/index.js",
  types: "./dist/index.d.js",
  exports: {
    import: "./dist/esm/index.mjs",
    require: "./dist/cjs/index.js",
  },
  scripts: {
    foo: "bar",
  },
  devDependencies: {
    baz: "latest",
  },
}
```

into this one:

```json
{
  name: "foo",
  main: "./index.js",
  types: "./index.d.js",
  exports: {
    import: "./esm/index.mjs",
    require: "./cjs/index.js",
  },
}
```

# API Usage

You can use [transformPackageJson](functions/transformPackageJson.md) with an input path, output path, and
optional [Options](type-aliases/Options.md) as a javascript equivalent to the CLI.
Alternatively, if you have a non-standard use case for loading/writing files,
you can call [transformPackageJsonContents](functions/transformPackageJsonContents.md), which takes the parsed
contents of a `package.json` and an optional [Options](type-aliases/Options.md) and returns the
transformed contents.

## Type Aliases

- [Options](type-aliases/Options.md)
- [PackageJson](type-aliases/PackageJson.md)

## Functions

- [transformPackageJson](functions/transformPackageJson.md)
- [transformPackageJsonContents](functions/transformPackageJsonContents.md)

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