# Add publint and Are the Types Wrong Checks to a TypeScript Library

Yes. An agent runs publint and arethetypeswrong against your built package, fixes what they flag in package.json, adds both to CI and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-publint-to-ci/typescript-library/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the library into its own cloud sandbox and reads how the package is shaped before it runs anything. In a library like sindresorhus/ky, `package.json` declares `"type": "module"`, an `exports` map with `types` pointing at `./distribution/index.d.ts` and `default` at `./distribution/index.js`, matching `main` and `types` fields for older resolvers, `"sideEffects": false`, `engines.node` at `>=22` and `files` limited to `distribution`. The build is `del-cli distribution && tsc --project tsconfig.dist.json`, which `tsconfig.dist.json` configures with `rootDir: ./source`, `outDir: ./distribution`, source maps and inlined sources, and `prepare` runs that build on install. There is no bundler and no CommonJS output: the package ships ESM only, on purpose.

It then reads `.github/workflows/main.yml`. There are two jobs on `macos-latest`: `test`, a matrix over Node.js `latest`, `24` and `22` that runs `npm install` and `npx ava 'test/**' '!test/browser.ts'`, and `browser`, which installs Playwright browsers and runs `npm test -- test/browser.ts`, where the `test` script is `xo && npm run build && tsc --project tsconfig.test.json && ava`. So the build already happens in CI, but nothing inspects what the build produces: whether every path in `exports` exists, whether `files` ships what `exports` points to, and whether a TypeScript consumer under each module resolution setting finds the types.

The agent runs `npm run build`, then `npx publint` and `npx @arethetypeswrong/cli --pack .` in the sandbox and reads the output before changing anything. publint checks the manifest against the files on disk: the `exports` conditions order, with `types` first as this package already has it, the `main` and `types` fallbacks, `files`, and `sideEffects`. arethetypeswrong packs the tarball and resolves the entry point as `node10`, `node16` in both CommonJS and ESM mode, and `bundler` would. For an ESM-only package the CommonJS resolution reports that `require` lands on ESM, which is the intended design here, so the agent runs it with the `esm-only` profile rather than silencing the rule globally, and records that choice in the config.

Then it adds `publint` and `@arethetypeswrong/cli` as dev dependencies, a `lint:package` script that runs the build followed by both tools, and one step in the `browser` job of `main.yml`, since that job is the one that already builds once instead of per Node.js version. Any manifest problem the tools report is fixed in `package.json` in the same pull request, with the tool's message quoted in the description. `xo` is left as the code linter and `np` as the release script; the new check runs before either sees a release.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add publint and arethetypeswrong checks to this TypeScript library. Read package.json, the tsconfig files and .github/workflows first, then run the build and both tools in the sandbox and fix any problem they report in package.json before adding anything to CI. This package ships ESM only, so configure arethetypeswrong for an ESM-only package rather than ignoring rules globally. Add both tools as dev dependencies, a lint:package script, and one step in the existing workflow job that already builds the package. Do not change the build output or the exports map's shape beyond what the tools require. Open a pull request whose description quotes the tools' output before and after your changes.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that changes `package.json` and `.github/workflows/main.yml` and nothing under `source/`. The manifest gains two dev dependencies and a `lint:package` script; the workflow gains one step in the job that already builds. If the tools found a problem with the manifest, the fix is in the same diff and the description quotes the message that prompted it.

The run's record keeps the first and the final run of both tools, so a reviewer can read what publint and arethetypeswrong said about the package as it was and confirm the final output is clean under the ESM-only profile. The `ava` and Playwright jobs are untouched, and the trajectory shows `npm run build` succeeding before each check.

Before merging, a reviewer checks that the chosen profile matches how the package is meant to be consumed, that the new step sits in the job they want to own the check, and that the two new dev dependencies are acceptable in a repository that pins its tooling in `devDependencies` rather than with a lockfile in git.

## Run it on every pull request that changes package.json

Once the check is in CI it runs on every push, but a failing check still needs someone to read it. An automation with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` starts one run per pull request; the agent checks out the branch, runs `npm run lint:package`, and when the pull request did not touch `package.json`, the `exports` map or the build config, it ends with a one-line note and no review. Only work by an owner, member or collaborator fires the trigger; pull requests from forks never do.

When the manifest did change, the run posts one review that cites the publint or arethetypeswrong message and the line in `package.json` it points at, with the fix as a suggestion. It pushes no commits, so the author keeps ownership of the change, and the review's evidence is the tool output in the run's trajectory.

## Why run it on Rush?

A broken `exports` map ships silently: tests pass because they import from source, and the first report comes from a user whose TypeScript settings resolve the package differently from yours. publint and arethetypeswrong catch that class of mistake only when they run against the built tarball, which is exactly what a sandbox with a fresh `npm install` and a real `npm run build` does. On Rush the first run of both tools is kept in the record, so the pull request that adds the check also shows what the package looked like without it.

For an organisation with many small packages, the same request runs once per repository and comes back as one pull request each, every one built from that package's own manifest and workflow rather than a template. Packages that ship both CommonJS and ESM get a different profile from the ESM-only ones, and the diff says which and why.

## Frequently asked questions

### Will arethetypeswrong fail on an ESM-only package?

Under the default profile it reports that a CommonJS `require` resolves to ESM, which is the expected shape for a package with `"type": "module"` and a single `default` export condition. The agent runs it with the `esm-only` profile so that one expected finding is not a failure, while the type resolution checks for `node16` ESM and `bundler` still apply.

### Does the check slow CI down?

It adds one build, which the `browser` job already does inside `npm test`, plus two tool runs that read the output directory and pack a tarball. The agent puts the step in that job rather than in the Node.js matrix so it runs once per push.

### What does publint check that tsc does not?

tsc checks the source compiles; publint checks the manifest: that every path in `exports`, `main` and `types` exists in the files `files` ships, that `types` comes before `default` in each condition, that `sideEffects` is a valid value, and that `type` matches the extension of the entry point. None of that is visible to the compiler.

### Will it change my exports map?

Only if a tool reports a problem with it, and then the pull request quotes the message and shows the one-line change. A manifest that is already correct, as this one's `types` then `default` ordering is, gets no edit beyond the new script and dev dependencies.

## More TypeScript library jobs

- [Generate an API Reference for a TypeScript Library With TypeDoc](https://getrush.ai/run/add-typedoc/typescript-library/)
- [Write Property-Based Tests for a TypeScript Library](https://getrush.ai/run/write-property-tests/typescript-library/)
- [Add Are the Types Wrong to CI for a TypeScript Library](https://getrush.ai/run/add-attw-to-ci/typescript-library/)

## More jobs like this: Hand off a long task

- [Add PWA Support to an Angular App](https://getrush.ai/run/add-pwa-support/angular/)
- [Add PWA Support to an Astro Site](https://getrush.ai/run/add-pwa-support/astro/)
- [Add PWA Support to a Docusaurus Site](https://getrush.ai/run/add-pwa-support/docusaurus/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
