Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Declare dependencies explicitly and use a dependency manager
Everything the app needs must be declared in package.json and installed deterministically.
Bad example
| 1 | // ❌ Works on my machine because a global tool happens to exist |
| 2 | import { execa } from "execa"; |
| 3 |
|
| 4 | export async function optimizeImages() { |
| 5 | // assumes `svgo` exists globally on PATH |
| 6 | await execa("svgo", ["assets/icon.svg"]); |
| 7 | } |
Explanation (EN)
Relying on globally installed tools or undeclared packages makes builds non-reproducible. CI or another developer machine will fail unpredictably.
Objašnjenje (HR)
Oslanjanje na globalno instalirane alate ili ne-deklarirane pakete čini build nereproducibilnim. CI ili tuđe računalo će failati nepredvidljivo.
Good example
| 1 | // ✅ Dependency is declared and executed via package scripts |
| 2 | // package.json: { "devDependencies": { "svgo": "^3.0.0" }, "scripts": { "svgo": "svgo" } } |
| 3 | import { execa } from "execa"; |
| 4 |
|
| 5 | export async function optimizeImages() { |
| 6 | await execa("npm", ["run", "svgo", "--", "assets/icon.svg"], { stdio: "inherit" }); |
| 7 | } |
Explanation (EN)
Declaring all dependencies and executing them through the project toolchain makes builds deterministic and portable across CI and machines.
Objašnjenje (HR)
Deklariranje svih dependencyja i pokretanje kroz projektni toolchain čini build determinističkim i prenosivim kroz CI i različita računala.
Notes (EN)
Matches the 12-Factor point on explicitly declaring dependencies and not relying on system-wide packages.
Bilješke (HR)
Odgovara 12-Factor točki o eksplicitnom deklariranju dependencyja i ne-oslanjanju na sistemske pakete.