Skip to content
jshacks.dev
Packages

Vendor a dependency in a monorepo

Copy a third-party package into a workspace folder, keep its license, and depend on it with workspace:* so apps use your patched copy. pnpm 10.

1 min read
Summarize in AI

Sometimes you need to patch a small package right now and cannot wait for upstream. Vendoring means copying its source into your monorepo as a workspace package, which you then own.

packages/vendor-pad/package.jsonJSON
{
  "name": "@acme/vendor-pad",
  "version": "1.3.0-acme.1",
  "type": "module",
  "exports": "./index.js",
  "license": "MIT"
}
packages/vendor-pad/index.jsJavaScript
export const pad = (s, n) => String(s).padStart(n, " ");
apps/web/package.jsonJSON
{
  "name": "web",
  "type": "module",
  "dependencies": { "@acme/vendor-pad": "workspace:*" }
}
apps/web/index.jsJavaScript
import { pad } from "@acme/vendor-pad";
console.log(`[${pad("ok", 5)}]`);
Text
[   ok]

Keep the original LICENSE file and a short note about where the code came from and what you changed, since the license requires attribution. Pnpm links the folder through the workspace protocol.

You are now the maintainer. Security fixes upstream will not reach you, so write down the upstream version you copied and review it when you update other dependencies.

Also inTooling
Share

More snippets

Packages

Initialize a package with npm init

Initialize a package.json with npm init, skip the questions with the yes flag, and set your own defaults for author and license in npm config.

1 min read
Tooling

Create a Vite project from a template

Create a Vite project from a template with npm create vite, choose the vanilla-ts or react-ts template and see which files it generates.

1 min read
Packages

Generate a changelog from commits

Turn conventional commit messages into a CHANGELOG.md section with conventional-changelog, grouped by feature and fix. Works with any Git history.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.