การจัดการดีเพนเดนซีและเวอร์ชันใน Monorepo
เรียนรู้วิธีจัดการดีเพนเดนซีร่วม การกำหนดเวอร์ชันแพ็กเกจภายใน และเครื่องมือที่สอดคล้องกันทั่วทั้ง monorepo ขนาดใหญ่ เพื่อให้บิลด์ทำซ้ำได้และปราศจากความขัดแย้ง
การจัดการดีเพนเดนซีและเวอร์ชันใน Monorepo เป็นบทเรียน Git Advanced: Monorepo, Submodules & Workflows ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Git Advanced: Monorepo, Submodules & Workflows และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Git Advanced: Monorepo, Submodules & Workflows มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Why Dependency Management Matters
In a monorepo, dozens of projects share a single tree. Without discipline, you end up with three different versions of the same library coexisting, bloating bundles and causing subtle bugs.
Centralized dependency management gives you one source of truth for versions, making upgrades and security patches a single coordinated change instead of dozens of scattered ones.
Single-Version Policy
A common monorepo strategy is the single-version policy: every project depends on exactly one version of each third-party library.
- Eliminates version skew between teams
- Forces upgrades to be evaluated holistically
- Simplifies the dependency graph for build tools
The tradeoff: an upgrade can require changes across many projects at once.
Workspaces in Practice
Package managers like npm, yarn, and pnpm support workspaces: a top-level config that hoists shared dependencies and links internal packages locally.
{
"name": "my-monorepo",
"private": true,
"workspaces": [
"packages/*",
"apps/*"
]
}Linking Internal Packages
Internal packages reference each other by name, not by relative path. The package manager symlinks them so a change in one is immediately visible in another.
{
"name": "@acme/web-app",
"dependencies": {
"@acme/ui": "workspace:*",
"@acme/utils": "workspace:*"
}
}Pinning vs. Ranges
Should you pin exact versions or allow ranges?
- Exact pins (
1.4.2) give reproducible builds but require manual bumps. - Ranges (
^1.4.0) auto-pick patches but risk drift.
In monorepos, prefer exact pins plus a lockfile so every machine resolves identical trees.
The Lockfile Is Sacred
The lockfile (package-lock.json, yarn.lock, pnpm-lock.yaml) records the exact resolved tree. Commit it, review changes to it, and never hand-edit it.
A surprising lockfile diff during code review is often the first sign of an unintended dependency change.
Catalogs and Centralized Versions
Modern tools support catalogs: a central list of versions referenced by name across packages, so you bump one place instead of many.
# pnpm-workspace.yaml
catalog:
react: 18.3.1
typescript: 5.4.5
# in a package.json
# "react": "catalog:"Versioning Internal Releases
When internal packages are published externally, you need a release process. Tools like Changesets let contributors declare the impact of a change, then compute the next semver bump automatically.
# .changeset/brave-lions-jump.md
---
"@acme/ui": minor
"@acme/utils": patch
---
Add new Button variant and fix date helper.Detecting Drift
Drift happens when versions silently diverge. Add a CI check that fails the build if duplicate versions of a critical dependency appear.
# Fail if more than one version of react is resolved
npm ls react --all | grep -c 'react@' Coordinated Upgrades
Upgrade a shared dependency in one branch, run the affected projects' tests, and merge atomically. This avoids the half-migrated state where some apps are on the new version and some are not.
Automation bots can open these upgrade PRs and let CI prove safety before merge.
Auditing for Security
Because versions are centralized, a single audit run covers the whole repo. Wire it into CI so vulnerable transitive dependencies block merges.
pnpm audit --audit-level=highQuick Check
Test your understanding of monorepo dependency management.
Recap
You learned how monorepos keep dependencies sane: a single-version policy, workspaces for linking internal packages, catalogs for centralized versions, a sacred lockfile, drift detection in CI, and coordinated, auditable upgrades.
Disciplined dependency management is what keeps a large monorepo reproducible and trustworthy.
เรียนรู้ Git Advanced: Monorepo, Submodules & Workflows ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 12
- บทเรียน
- 48
คำถามที่พบบ่อย
บทเรียน “การจัดการดีเพนเดนซีและเวอร์ชันใน Monorepo” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การจัดการดีเพนเดนซีและเวอร์ชันใน Monorepo” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Git Advanced: Monorepo, Submodules & Workflows ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Git Advanced: Monorepo, Submodules & Workflows มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การจัดการดีเพนเดนซีและเวอร์ชันใน Monorepo”
เรียนรู้วิธีจัดการดีเพนเดนซีร่วม การกำหนดเวอร์ชันแพ็กเกจภายใน และเครื่องมือที่สอดคล้องกันทั่วทั้ง monorepo ขนาดใหญ่ เพื่อให้บิลด์ทำซ้ำได้และปราศจากความขัดแย้ง คุณปฏิบัติ Git Advanced: Monorepo, Submodules & Workflows ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Git Advanced: Monorepo, Submodules & Workflows หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Git Advanced: Monorepo, Submodules & Workflows บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “การจัดการดีเพนเดนซีและเวอร์ชันใน Monorepo” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Git Advanced: Monorepo, Submodules & Workflows นี้ได้ไหม
ได้ บทเรียน Git Advanced: Monorepo, Submodules & Workflows ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- เจ้าของโค้ดและการควบคุมการเข้าถึง
- การเพิ่มประสิทธิภาพการสร้างและการทดสอบ
- กลยุทธ์การย้ายไปใช้ Monorepo
- การจัดการดีเพนเดนซีและเวอร์ชันใน Monorepo