en un clic
adding-a-package
// Use when creating a new workspace package in a monorepo. Covers package creation, tier assignment, and all config updates required.
// Use when creating a new workspace package in a monorepo. Covers package creation, tier assignment, and all config updates required.
Audit and install a self-correcting guardrail stack in any TypeScript project. Four-phase workflow: understand the guardrail system from this repo, inventory the target project, generate a gap analysis, then apply changes — creating missing configs and merging missing sections into existing ones.
Extend an existing guardrail installation with LLM discipline rules: complexity limits, cognitive complexity, naming conventions, ESM idioms, documentation coverage, and test coverage thresholds. Run after setup-guardrails.
Use when adding imports, creating packages, or reviewing code to ensure tiered dependency rules are followed. Read this to understand the tier system.
Use on every commit. The pre-commit hooks run 8 checks in parallel. If any fail, read ALL errors, fix them in one pass, and retry.
| name | adding-a-package |
| description | Use when creating a new workspace package in a monorepo. Covers package creation, tier assignment, and all config updates required. |
Adding a new package to a monorepo guarded by this stack requires updating 5 config files in addition to creating the package itself. Skip any of these and the pre-commit hooks will catch it — but it's faster to do it right the first time.
Before creating anything, read these files to understand the current setup:
package.json — find the org scope (e.g. @acme) from the name or workspaces fieldeslint.config.js — find the existing tier arrays and boundary elementsknip.json — find existing workspace entriescommitlint.config.ts — find existing scopesUse the detected org scope wherever @scope appears below.
packages/new-pkg/
├── package.json
├── tsconfig.json
└── src/
└── index.ts
package.json{
"name": "@scope/new-pkg",
"version": "0.0.1",
"private": true,
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"scripts": {
"build": "tsc -b",
"test": "vitest run"
},
"dependencies": {},
"devDependencies": {}
}
Replace @scope with the org scope detected in Step 1.
tsconfig.json{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": ["src"],
"exclude": ["dist"]
}
src/index.tsexport {};
Decide which tier this package belongs to:
| Tier | Contains | Can Import |
|---|---|---|
| 0 | Pure types, logger, constants | Nothing (leaf) |
| 1 | Config, helpers, utilities | Tier 0 |
| 2 | Database, external APIs, queues | Tier 0-1 |
| 3 | Domain logic, business rules | Tier 0-2 |
| 4 | Orchestration, wiring | Tier 0-3 |
| App | CLI, web server, workers | Anything |
If unsure, ask the user. Getting the tier right now prevents painful refactoring later.
eslint.config.jsTwo changes required:
// Find the appropriate tier array and add the package name:
const tier2 = ['database', 'external-api', 'new-pkg']; // ← added
settings: {
'boundaries/elements': [
// ... existing entries ...
{ type: 'new-pkg', pattern: ['packages/new-pkg/*'], mode: 'folder' },
],
},
knip.jsonAdd the new package to the workspaces entry list:
{
"workspaces": {
"packages/new-pkg": {
"entry": ["src/index.ts"],
"project": ["src/**/*.ts"]
}
}
}
commitlint.config.tsAdd the package name to the allowed scopes:
rules: {
'scope-enum': [2, 'always', [
// ... existing scopes ...
'new-pkg', // ← add
]],
}
If other packages will import from this new package, add it as a dependency:
{
"dependencies": {
"@scope/new-pkg": "*"
}
}
For pnpm/yarn, use "workspace:*" instead of "*".
Then add a TypeScript project reference in the consuming package's tsconfig.json:
{
"references": [
{ "path": "../new-pkg" }
]
}
git add -A
git commit -m "feat(new-pkg): scaffold new package"
The pre-commit hooks will verify:
index.ts is fine)If the commit fails, read the errors and fix them.
package.json, tsconfig.json, src/index.tseslint.config.js updated (tier array + boundaries/elements)knip.json updated with workspace entrycommitlint.config.ts updated with new scope