Yarn 2 (Berry)

YARN 2 (Berry) - The Modern Package Manager 🧢

Yarn 2, also known as Berry, is a significant evolution of the original Yarn package manager. It brings improved performance, enhanced security, and new features to JavaScript and Node.js development.

Architecture and Concepts πŸ—οΈ

Yarn 2's architecture is designed for efficiency, reliability, and improved developer experience:

  • πŸ“ Plug'n'Play (PnP): A new resolution strategy that replaces node_modules

  • πŸ”’ Zero-Installs: Allows committing dependencies to version control

  • 🌐 Workspaces: Improved monorepo support

  • πŸ”§ Constraints: Enforce rules across your project

  • πŸ“¦ Protocols: Flexible ways to fetch packages

Key Concepts:

  • πŸš€ Performance: Faster installs and reduced disk usage

  • πŸ” Security: Improved package resolution and validation

  • πŸ› οΈ Extensibility: Plugin system for custom functionality

  • πŸ“œ TypeScript Support: Better integration with TypeScript projects

Yarn 2 Architecture Diagram πŸ“Š

Common Yarn 2 Commands πŸ–₯️

Installation:

Initialize a new project:

Add a dependency:

Remove a dependency:

Install all dependencies:

Run a script:

Update packages:

Code Snippets πŸ’»

Example package.json:

Example TypeScript file (src/index.ts):

Running the application:

Output:

Deployment Commands πŸš€

Here are some common deployment commands:

Build for production:

Run tests before deployment:

Start in production mode:

Add these scripts to your package.json:

Conclusion πŸŽ‰

Yarn 2 (Berry) is a powerful and efficient package manager for Node.js projects. Its innovative features like Plug'n'Play and Zero-Installs provide significant improvements in performance and project management. By leveraging Yarn 2's capabilities, developers can create more efficient, secure, and maintainable JavaScript and TypeScript applications.

Last updated

Was this helpful?