Migrate from pnpm to Bun Package Manager in Directus for Enhanced Performance and Efficiency #19643
Replies: 6 comments 6 replies
-
There's a couple of major questions/difficulties that come to mind:
Now if 2 is going to be a massive issue.. depends. We currently primarily point people to our Docker image as that's the most reliable across environments, in which case Bun would almost be a drop-in replacement. For people who are used to running it from "raw" node js (like in shared host environments), this would become a big problem 🤔 Long story short; I'm personally very interested in exploring the possibilities on relying on Bun as the primary runtime, as it's proven to be so insanely performant. I am wondering if it's feasible to do so though now, or if it would make more sense to hold back and let the Bun ecosystem mature a bit before committing to it for the long term |
Beta Was this translation helpful? Give feedback.
-
The Bun v1.0 blog post, to add some more context: https://bun.sh/blog/bun-v1.0 |
Beta Was this translation helpful? Give feedback.
-
A counter-point; to keep this a balanced discussion: https://dev.to/thejaredwilcurt/bun-hype-how-we-learned-nothing-from-yarn-2n3j |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
Is there a solid case for continuing to support this, even unofficially? I’m inclined to making the use of Docker or Kubernetes a hard requirement anyway |
Beta Was this translation helpful? Give feedback.
-
Coincidentally, after binaryben's bump of this thread, Bun 1.1 with Windows support was released today: https://bun.sh/blog/bun-v1.1 That's a long blog post (I'm still reading it lol) |
Beta Was this translation helpful? Give feedback.
-
Summary
Bun is a modern, fast, and efficient package manager designed to be production-ready. It offers advantages in speed, disk usage, and memory footprint compared to pnpm, the current package manager used in Directus. The proposal aims to migrate Directus from pnpm to Bun to leverage these performance and efficiency gains, thereby enhancing the overall development and deployment experience.
Performance Metrics
Based on the Bun v1.0, Bun shows significant improvements in various performance metrics:
By migrating to Bun, Directus can expect:
Why Migrate to Bun?
Basic Example
No response
Motivation
The primary motivation for proposing the migration from pnpm to Bun is to address several constraints and challenges that are inherent with the current package management system in Directus:
Speed
Efficiency
Security
Simplified Workflow
Expected Outcome
The expected outcome is a more efficient, secure, and developer-friendly environment for Directus, which could lead to faster development cycles, lower operational costs, and higher adoption rates.
By focusing on these constraints, alternative solutions can also be developed if migrating to Bun is not feasible. For example, optimizing the current pnpm setup or considering other package managers that address these constraints could be alternative routes.
Detailed Design
The migration from pnpm to Bun in Directus involves several key steps, each with its own set of considerations and corner-cases. Below is a detailed design plan that outlines these steps.
Step 1: Preliminary Assessment and Backup
package.json
,pnpm-lock.yaml
, and any custom scripts that rely on pnpm.Step 2: Install Bun and Uninstall pnpm
Specifics: Install Bun using
curl
as shown in the blog. Uninstall pnpm to avoid any conflicts.curl -sf https://bun.sh | sh npm uninstall -g pnpm
Additional Information: Bun is not just a package manager; it's a comprehensive tool that can replace various other tools and libraries in your development workflow. Here's what you can unlearn or replace when you adopt Bun:
Tools and Libraries Made Unnecessary by Bun
Node.js Replacements
node
→ Bun itselfnpx
→bunx
(5x faster)nodemon
→ Bun's built-in watch modedotenv, cross-env
→ Bun reads.env
files by defaultTranspilers
tsc
→ Only needed for type checkingbabel, .babelrc, @babel/preset-*
→ Not neededts-node, ts-node-esm
→ Not neededtsx
→ Not neededBundlers
esbuild
→ Not neededwebpack
→ Not neededparcel, .parcelrc
→ Not neededrollup, rollup.config.js
→ Not neededPackage Managers
npm, .npmrc, package-lock.json
→ Not neededyarn, yarn.lock
→ Not neededpnpm, pnpm.lock, pnpm-workspace.yaml
→ Not neededlerna
→ Not neededTesting Libraries
jest, jest.config.js
→ Not neededts-jest, @swc/jest, babel-jest
→ Not neededjest-extended
→ Not neededvitest, vitest.config.ts
→ Not neededStep 3: Update
package.json
scripts
section inpackage.json
to replace pnpm commands with Bun commands.Step 4: Migrate Lock Files
pnpm-lock.yaml
and generate a new lock file usingbun install
.Step 5: Update CI/CD Pipeline
Specifics: In your GitHub Actions CI/CD pipeline, replace pnpm setup steps with Bun.
Corner Case: If you have caching set up for pnpm, you'll need to update it for Bun.
Step 6: Update Documentation
Step 7: Testing
Specifics: Thoroughly test the project to ensure that all dependencies are correctly installed and that the application behaves as expected.
Corner Case: Pay special attention to any native modules or linked packages, as these could behave differently when managed by Bun.
Step 8: Rollout
New Terminology
pnpm-lock.yaml
but specific to Bun.Requirements List
To ensure the successful migration from pnpm to Bun in Directus, the following requirements have been identified:
Must-Have
Should-Have
Could-Have
Won't-Have
By fulfilling these requirements, the migration from pnpm to Bun can be considered a success, offering benefits like speed, efficiency, and potentially better security.
Drawbacks
While the migration from pnpm to Bun offers several advantages, there are also potential drawbacks that need to be considered:
Implementation Cost
User Space Implementation
Educational Impact
Integration with Existing and Planned Features
Migration Costs
Potential Breaking Changes: Depending on how tightly integrated pnpm is with existing Directus applications, the migration could introduce breaking changes, requiring users to update their projects.
Resource Allocation: Time and resources would need to be allocated for the migration, including development, testing, and documentation updates. This could delay other planned features or improvements for Directus.
Alternatives
Stick to pnpm
One alternative to migrating to Bun is to stick with the current package manager, pnpm. Below are some considerations for this option:
Advantages of Sticking to pnpm
No Migration Costs: There would be no need to allocate resources for migration, allowing the team to focus on other features or improvements.
No Learning Curve: Developers already familiar with pnpm would not have to spend time learning a new package manager, thereby avoiding any slowdown in development.
Stable and Tested: pnpm is a stable and well-tested package manager that has been used in Directus for some time. Sticking to it would mean less risk of introducing new issues.
Disadvantages of Sticking to pnpm
Missed Performance Gains: By not migrating to Bun, Directus would miss out on the potential performance and efficiency gains that Bun offers.
Potential Future Migration: If Bun or another package manager becomes significantly better in the future, a migration might still be necessary, and the costs could be higher the longer it is delayed.
Impact of Not Doing This
Status Quo: Directus would continue to operate as it currently does, without benefiting from the potential advantages that Bun offers.
Potential for Future Re-evaluation: As Bun and other package managers continue to evolve, there may be future opportunities to reconsider this migration.
Adoption Strategy
The adoption of Bun as the new package manager in Directus would require a well-planned strategy to ensure a smooth transition for existing developers and projects. Here are some key points to consider:
Communication
Documentation
Migration Guide: Provide a comprehensive migration guide that outlines the steps to transition from pnpm to Bun. This guide should cover installation, updating
package.json
, and other relevant changes.Updated Docs: All existing documentation that references pnpm should be updated to mention Bun, including setup guides, FAQs, and tutorials.
Tooling
pnpm-lock.yaml
to Bun's lock file format.Versioning
Testing
Community and Ecosystem
Plugin Compatibility: Assess how this change will affect existing plugins in the Directus ecosystem. Provide guidelines for plugin developers to update their projects for compatibility with Bun.
Community Contributions: Encourage the community to contribute to the migration process, whether it's through code, testing, or documentation.
Unresolved Questions
No response
Beta Was this translation helpful? Give feedback.
All reactions