Commit Graph

46 Commits

Author SHA1 Message Date
RiskyMH
831237154b Skip flaky real-world Next.js test, keep comprehensive nested deps test
The deeply nested workspace deps test covers everything we need:
- workspace:^ dependencies
- Multiple conflicting versions (3 React versions)
- 5-level deep nesting
- Real Yarn Berry generated lockfile
- Migration + bun ci verification

7/8 tests passing.
2025-10-13 21:05:44 +11:00
RiskyMH
2de92ded04 Add test for deeply nested workspace deps with conflicting versions
Uses real Yarn Berry 4.0.2 generated lockfile with:
- 5-level deep workspace dependency chain (e -> d -> c -> b -> a)
- Multiple versions of same package (react 16.14.0, 17.0.2, 18.3.1)
- Multi-spec resolution (lodash ^4.17.19, ^4.17.20, ^4.17.21 all resolve to 4.17.21)
- workspace:^ dependencies throughout

Verifies migration and bun ci work correctly with complex version conflicts.
2025-10-13 21:02:34 +11:00
RiskyMH
71eae86041 Add comprehensive real-world Yarn Berry migration test
Test simulates a realistic Next.js monorepo with:
- workspace:^ dependencies between workspace packages
- Optional peer dependencies (like @opentelemetry/api for Next.js)
- Platform-specific binaries with conditions (darwin-arm64, linux-x64)
- Multiple bin entries (tsc, tsserver, next, loose-envify)
- Nested dependencies and peer dependencies
- Both migration and bun ci (frozen lockfile install)

Verifies the complete workflow works end-to-end without lockfile changes or resolution errors.
2025-10-13 20:31:47 +11:00
RiskyMH
1e3dbef951 Handle peerDependenciesMeta for optional peer dependencies in Yarn Berry migration
Parse peerDependenciesMeta to identify which peer dependencies are optional, then mark those dependencies with .optional = true in their behavior. This allows the lockfile serializer to correctly add them to the optionalPeers array.

Fixes migration of repos like riskymh/riskybot that have optional peer dependencies (e.g. @opentelemetry/api for next.js). Previously these would cause lockfile parse errors. Now bun ci works successfully after migration.
2025-10-13 20:25:22 +11:00
RiskyMH
712291c878 Fix workspace: protocol resolution in Yarn Berry migration
Resolve workspace dependencies by looking them up in spec_to_pkg_id first (for workspace:^ etc with explicit lockfile entries), then falling back to workspace package matching by name for simple workspace:* dependencies without lockfile entries.

This fixes 700 unresolved workspace dependencies when migrating complex monorepos like Yarn's own repo (build/berry) which uses workspace:^ with version ranges.
2025-10-13 19:25:02 +11:00
RiskyMH
85adf9c7a6 fix(install): add root workspace to workspace_paths and workspace_versions for Yarn Berry
- Add root workspace with path '.' to workspace_paths when it has a name
- Add root workspace version to workspace_versions (0.0.0 if no version in package.json)
- Skip root workspace in workspace package creation loop (already created as package ID 0)
- Add root to pkg_map so it can be resolved by other workspaces
- Refactor fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration to use MigrationType enum
- Yarn Berry now only fetches integrity data, not bins/os/cpu (already in lockfile)
- Update test snapshots to include integrity checksums
2025-10-13 16:51:32 +11:00
RiskyMH
594fc3ecd9 fix(install): resolve Yarn Berry migration crashes and enable package population
- Fix use-after-free in YAML parser with arena allocator + deepClone
- Add resolution buffer mapping to populate lockfile packages
- Parse os/cpu conditions from both v8 and v6 formats
- Add comprehensive test suite (6 test cases covering conditions, deps, bins, workspaces)
2025-10-13 15:47:41 +11:00
RiskyMH
bfb5399f25 feat(install): merge yarn v1 + berry into single file with full metadata
Merges Yarn v1 and Yarn Berry (v2+) migration into ONE yarn.zig file.

Changes:
- Auto-detects v1 vs Berry at runtime
- Shared workspace scanning and package.json parsing
- Full Berry metadata support:
   bin definitions (single/named/map formats)
   peerDependencies (added with .peer behavior)
   dependenciesMeta (optional markers)
   checksum conversion (Berry format → Bun integrity)

Deleted files:
- yarn_berry.zig (merged into yarn.zig)
- yarn_common.zig (merged into yarn.zig)

Missing from Berry (Bun will fetch from npm registry):
- scripts (not in lockfile)
- os/cpu constraints (not commonly in Berry lockfiles)
- man pages

Test status:
- v1 tests:  passing
- Berry tests: need fixtures with proper YAML format
2025-10-12 19:55:28 +11:00
RiskyMH
dba7138103 wip(install): yarn berry migration (checksums skipped)
Adds initial Yarn Berry (v2+) migration support with:
- YAML parsing for Berry lockfiles
- npm: protocol support
- workspace: protocol support
- Multi-spec handling

IMPORTANT: Berry checksums are SKIPPED for now.
Berry uses hex-encoded hashes with algorithm prefixes (10c0/=sha512, 10/=sha256, 8/=sha1).
Bun expects base64-encoded hashes (sha512-base64...).
Converting is complex and error-prone.

Decision: Skip Berry checksums, let Bun fetch from npm registry during install.
This matches how v1 and pnpm migrations handle missing/incompatible integrity.

TODO: Complete implementation and testing
2025-10-12 19:26:16 +11:00
RiskyMH
258f8c01b7 fix(install): use npm resolution format for custom registry tarballs
Fixes remote tarball format to match bun.lock spec with URL in 2nd column.

Changes ONLY in yarn.zig:
- Create npm resolution instead of remote_tarball for tarball URLs
- This serializes as ["name@version", "url", {}, "integrity"]
- Matches the format used by npm packages with custom registries

Format changes:
- Before: ["my-package@https://custom.com/pkg.tgz#hash", {}]
- After: ["my-package@1.0.0", "https://custom.com/pkg.tgz", {}, "sha"]
- Default registry: ["pkg@1.0.0", "", {}, "sha"] (empty URL string)

This keeps resolution.zig unchanged as requested.
2025-10-12 16:28:09 +11:00
RiskyMH
ed9a613092 . 2025-10-11 13:12:03 +11:00
RiskyMH
c264a0f94c fix(install): strip hash from file: tarballs in yarn migration
Fixes local file tarball format in migrated lockfiles. Yarn includes #hash
in the resolved field like 'file:package.tgz#abc123', but bun.lock should
only have 'file:package.tgz' without the hash.

Also adds test for custom registry tarball URLs to verify they work correctly.

Changes:
- Strip hash from file: paths in Resolution.fromPnpmLockfile
- Add support for .tar.gz extension (not just .tgz)
- Add test for custom registry migration
- Update snapshots with correct format

Format change:
- Before: ["tarball@file:abbrev-1.1.1.tgz#f8f2c887...", {}]
- After: ["tarball@file:abbrev-1.1.1.tgz", {}]
2025-10-11 13:04:32 +11:00
RiskyMH
601fad9746 . 2025-10-11 12:37:55 +11:00
RiskyMH
932237cd6f fix(install): yarn workspace dependencies missing from migrated lockfile
Fixes yarn.lock to bun.lock migration for workspaces where workspace package
dependencies were not appearing in the packages section.

Changes:
- Move workspace scanning to before root package creation
- Add workspace packages as root dependencies during root creation
- Fix workspace path resolution (use append instead of join)
- Update test snapshots for correct GitHub shorthand format

Resolves issue where workspace package dependencies like react and lodash
were missing from the migrated bun.lock packages section.

Test results: 18/20 tests passing (90%), 2 timeouts on large lockfiles
2025-10-11 12:27:34 +11:00
RiskyMH
6a8ad982fd yarn initial 2025-10-11 02:58:20 +11:00
robobun
13a3c4de60 fix(install): fetch os/cpu metadata during yarn.lock migration (#23143)
## Summary

During `yarn.lock` migration, OS/CPU package metadata was not being
fetched from the npm registry when missing from `yarn.lock`. This caused
packages with platform-specific requirements to not be properly marked,
potentially leading to incorrect package installation behavior.

## Changes

Updated `fetchNecessaryPackageMetadataAfterYarnOrPnpmMigration` to
conditionally fetch OS/CPU metadata:

- **For yarn.lock migration**: Fetches OS/CPU metadata from npm registry
when not present in yarn.lock (`update_os_cpu = true`)
- **For pnpm-lock.yaml migration**: Skips OS/CPU fetching since
pnpm-lock.yaml already includes this data (`update_os_cpu = false`)

### Files Modified

- `src/install/lockfile.zig` - Added comptime `update_os_cpu` parameter
and conditional logic to fetch OS/CPU metadata
- `src/install/yarn.zig` - Pass `true` to enable OS/CPU fetching for
yarn migrations
- `src/install/pnpm.zig` - Pass `false` to skip OS/CPU fetching for pnpm
migrations (already parsed from lockfile)

## Why This Approach

- `yarn.lock` format often doesn't include OS/CPU constraints, requiring
us to fetch from npm registry
- `pnpm-lock.yaml` already parses OS/CPU during migration (lines 618-621
in pnpm.zig), making additional fetching redundant
- Using a comptime parameter allows the compiler to optimize away the
unused code path

## Testing

-  Debug build compiles successfully
- Tested that the function correctly updates `pkg_meta.os` and
`pkg_meta.arch` only when:
  - `update_os_cpu` is `true` (yarn migration)
  - Current values are `.all` (not already set)
  - Package metadata is available from npm registry

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-10-04 05:56:21 -07:00
Dylan Conway
46d6e0885b fix(pnpm migration): fix "lockfileVersion" number parsing (#23232)
### What does this PR do?
Parsing would fail because the lockfile version might be parsing as a
non-whole float instead of a string (`5.4` vs `'5.4'`) and the migration
would have the wrong error.
### How did you verify your code works?
Added a test

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
2025-10-04 00:53:15 -07:00
Dylan Conway
25e156c95b fix(pnpm migration): correctly resolve link: dependencies on the root package (#23111)
### What does this PR do?
Two things:
- we weren't adding the root package to the `pkg_map`.
- `link:` dependency paths in `"snapshots"` weren't being joined with
the top level dir.
### How did you verify your code works?
Manually and added a test.
2025-09-30 00:10:15 -07:00
Michael H
ba20670da3 implement pnpm migration (#22262)
### What does this PR do?

fixes #7157, fixes #14662

migrates pnpm-workspace.yaml data to package.json & converts
pnpm-lock.yml to bun.lock

---

### How did you verify your code works?

manually, tests and real world examples

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
2025-09-27 00:45:29 -07:00
Michael H
020fe12887 bun.lock migration: fix packages with long version string (#21753)
### What does this PR do?

cases like `@prisma/engines-version` with version of
`6.14.0-17.fba13060ef3cfbe5e95af3aaba61eabf2b8a8a20` was having issues
with the version and using a "corrupted" string instead

### How did you verify your code works?

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-11 16:26:03 -07:00
Jarred Sumner
003d13ec27 Introduce yarn.lock -> bun.lock{b} migrator (#16166)
### What does this PR do?

fixes #6409

This PR implements `bun install` automatic migration from yarn.lock
files to bun.lock, preserving versions exactly. The migration happens
automatically when:

1. A project has a `yarn.lock` file
2. No `bun.lock` or `bun.lockb` file exists  
3. User runs `bun install`

### Current Status:  Complete and Working

The yarn.lock migration feature is **fully functional and
comprehensively tested**. All dependency types are supported:

-  Regular npm dependencies (`package@^1.0.0`)
-  Git dependencies (`git+https://github.com/user/repo.git`,
`github:user/repo`)
-  NPM alias dependencies (`alias@npm:package@version`)
-  File dependencies (`file:./path`)
-  Remote tarball URLs (`https://registry.npmjs.org/package.tgz`)
-  Local tarball files (`file:package.tgz`)

### Test Results

```bash
$ bun bd test test/cli/install/migration/yarn-lock-migration.test.ts
 4 pass, 0 fail
- yarn-lock-mkdirp (basic npm dependency)
- yarn-lock-mkdirp-no-resolved (npm dependency without resolved field)
- yarn-lock-mkdirp-file-dep (file dependency)
- yarn-stuff (all complex dependency types: git, npm aliases, file, remote tarballs)
```

### How did you verify your code works?

1. **Comprehensive test suite**: Added 4 test cases covering all
dependency types
2. **Version preservation**: Verified that package versions are
preserved exactly during migration
3. **Real-world scenarios**: Tested with complex yarn.lock files
containing git deps, npm aliases, file deps, and remote tarballs
4. **Migration logging**: Confirms migration with log message `[X.XXms]
migrated lockfile from yarn.lock`

### Key Implementation Details

- **Core parser**: `src/install/yarn.zig` handles all yarn.lock parsing
and dependency type resolution
- **Integration**: Migration is built into existing lockfile loading
infrastructure
- **Performance**: Migration typically completes in ~1ms for most
projects
- **Compatibility**: Preserves exact dependency versions and resolution
behavior

The implementation correctly handles edge cases like npm aliases, git
dependencies with commits, file dependencies with transitive deps, and
remote tarballs.

---------

Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: RiskyMH <git@riskymh.dev>
Co-authored-by: RiskyMH <56214343+RiskyMH@users.noreply.github.com>
2025-07-29 13:07:47 -07:00
Dylan Conway
2bc75a87f4 fix(install): fix resolving duplicate dependencies (#21059)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-07-16 01:01:10 -07:00
Dylan Conway
0a7cc1f1c2 Make bun.lock the default for new projects (#16540) 2025-01-20 23:17:52 -08:00
chloe caruso
834ad11d48 get node:fs tests passing part 1 (#16270) 2025-01-14 20:53:02 -08:00
Dylan Conway
2272b852ba fix(install): npm version to git resolution package-lock.json migration (#15810) 2024-12-17 19:59:23 -08:00
Dylan Conway
8f5eab3c84 fix(install): package-lock.json migration and non-existent cafile fixes (#15059) 2024-11-08 14:34:44 -08:00
Dylan Conway
b895738156 fix(install): migrate package-lock.json with dependency on root package (#14811)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-10-25 01:32:17 -07:00
Jarred Sumner
cd6785771e run prettier and add back format action (#13722) 2024-09-03 21:32:52 -07:00
Dylan Conway
ff15281b49 fix(install): fix potential flakiness with git dependencies (#12030)
Co-authored-by: dylan-conway <dylan-conway@users.noreply.github.com>
2024-06-21 21:34:23 -07:00
Dylan Conway
c614d5b1da fix(install): aliased workspace without version in package.json (#11630) 2024-06-05 22:04:57 -07:00
Dylan Conway
df83028546 fix(install): npm lockfile migration bugfix (#11311) 2024-05-24 00:19:56 -07:00
Dylan Conway
d3fdb17321 add jest.setTimeout to bun test (#10687)
Co-authored-by: dylan-conway <dylan-conway@users.noreply.github.com>
2024-05-23 20:24:54 -07:00
Meghan Denny
4efe026b5f test: unify how all files create a temp directory (#11057)
Co-authored-by: nektro <nektro@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-05-14 20:19:35 -07:00
Jarred Sumner
ee05bae2be Make bun install 60% faster on Windows, improve reliability, reduce memory usage (#10037)
* [bundows] Make bun install 60% faster

* [autofix.ci] apply automated fixes

* Do not keep node_modules folder open between async tasks. Make sure we call runTasks on every event loop wakeup.

* Update install.zig

* Fix deadlock

* Make that deadlock impossible

* a little less repetitive

* Fix test failure with local tarball

* Get those tests to pass

* Normalize absolutely

* lets see how many times we call GetFinalPathNameByHandle

* Workaround https://github.com/ziglang/zig/issues/19586

https://github.com/ziglang/zig/issues/19586

* Is the dev-server-100 test failure a hash table collision?

* Give it its own cache dir

* We cannot change the git task ids

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-04-08 06:25:24 -07:00
Jarred Sumner
d8a09d8517 Remove known-failing-on-windows 2024-03-24 12:13:24 -07:00
Jarred Sumner
c8ec56ec1b Fix assertion failure when package-lock.json is out of sync with package.json (#9468)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2024-03-16 23:31:34 -07:00
Dylan Conway
5934b17f00 fix(windows): fix a few more tests (#8644)
* fix regression tests

* fix fs.test.ts bigintstats

* enable transpiler cache lol

* remove failing

* fix filesystem router

* update

* fix run-unicode test

* update comment

* add updated snapshot

* fix remaining node-module-module tests

* fixup

* [autofix.ci] apply automated fixes

* fix tty tests

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-02-02 18:58:16 -08:00
Meghan Denny
3a7df3f6c7 windows: add more passing test (#8615) 2024-02-01 13:45:47 -08:00
dave caruso
072f2f15ea ci: run windows tests and also run them concurrently (#7758) 2024-01-12 17:02:20 -08:00
Dylan Conway
351e47355a add default trustedDependencies and run lifecycle scripts during installation (#7132)
* [install] allow parallel execution of `postinstall` scripts

- fixes spurious exit code 42 from `spawn()`

* postinstall to a pipe

* feat(install): include top 500 packages as defaults for postinstall

* windows newline handling*

*i did not test it

* stuff

* cool

* a

* fix merge

* set `has_trusted_dependencies`

* fix a bunch of tests

* fix merge

* remove `PackageManager`

* remove commented code

* change to function

* Update lockfile.zig

* run scripts if added to `trustedDependencies` after install

* packages without `resolved` properties

* node-gyp scripts

* node-gyp script in the root

* another test

* git deps run prepare scripts

* fix merge

* run lifecycle scripts during installation

* Update lockfile.zig

* always increment

* 🏗️

* update tests

* tickWIthoutIdle

* const uws

* loop forwards through trees

* single buffer bitset list

* tag.isGit

* windows path separators

* `bun.sys.read` and enable/disable buffering

* fix test and waiter thread

* waiter thread and tests

* Update bun-install-registry.test.ts

* workspace exclude `preprepare` and `postprepare`

* Create esbuild.test.ts

* make sure length is the same

* remove deferred binlinks, add estrella test

* test with another version

* address some comments

* remove .verdaccio-db.json

* ooops

* fix build

* use `pid` to wait

* dont register pid_poll when using waiter thread

* stress test

* free

* fix failing tests

* fix linux crash, snapshot stress test

* oops

* concurrent scripts

* activate as soon as possible

* test

* delete stress test packages

* remove unused packages

* comment stress test and maybe fix segfault

* delete snapshot

* fix assertion

* use cpu_count * 2 for default concurrent scripts

* gear emoji

* add --concurrent-scripts to docs

* more docs

---------

Co-authored-by: alexlamsl <alexlamsl@gmail.com>
Co-authored-by: dave caruso <me@paperdave.net>
Co-authored-by: Dylan Conway <33744874+MilesWright7@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2023-12-11 22:08:25 -08:00
hustLer2k
ab85b2a2a0 test: Migration tests fixes (#7393)
* use lockfile path passed as an argument instead of a literal string

* clean up tmp folders in migrate.test

---------

Co-authored-by: Alex See <alexsee@Alexs-MacBook-Air.local>
2023-12-11 16:07:20 -08:00
dave caruso
f3727f00dc allow migrating from npm lockfile v2 (#6695)
* allow lockfile version 2

* force save lockfile

* add migration from npm lockfilev2 test (#7370)

Co-authored-by: Alex See <alexsee@Alexs-MacBook-Air.local>

* [autofix.ci] apply automated fixes

---------

Co-authored-by: hustLer2k <61846786+hustLer2k@users.noreply.github.com>
Co-authored-by: Alex See <alexsee@Alexs-MacBook-Air.local>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2023-11-29 20:06:44 -08:00
Dylan Conway
46955e95ef migration without resolved properties (#7123)
* packages without `resolved` properties

* test

* free more

* find registry scope
2023-11-14 23:17:59 -08:00
Jarred Sumner
756eee087a Sort list of dependencies and fix test (#6616)
* fix findBestMatch so it finds the best match and not the first match

* update complex-workspaces to include lines-and-columns ^1.1.6

* PR feedback

* PR feedback

* This test doesn't reproduce the original issue

* Support pre release versions the same way

* Add a test that reproduces the original issue

* Sort the list of package versions before serializing to disk

* Remove test that didnt reproduce it

* Fix the count

* Fix 0 and 1 and sorting order

* Fix assertions and ordering

---------

Co-authored-by: Dylan Greene <dgreene@medallia.com>
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
2023-10-20 03:55:40 -07:00
Dylan Greene
184528e4eb fix findBestMatch so it finds the best match and not the first match (#6611)
* fix findBestMatch so it finds the best match and not the first match

* update complex-workspaces to include lines-and-columns ^1.1.6

* PR feedback

* PR feedback
2023-10-20 02:18:37 -07:00
dave caruso
1bf28e0d77 feat(install): automatically migrate package-lock.json to bun.lockb (#6352)
* work so far

* stuff

* a

* basics work

* stuff

* yoo

* build lockfile

* correct

* f

* a

* install fixture havent tested

* i made it worse

* lol

* be more reasonable

* make the test easier to pass because bun install doesn't handle obscure lockfile edge cases :/

* a

* works now

* ok

* a

* a

* cool

* nah

* fix stuff

* l

* a

* idfk

* LAME

* prettier errors

* does this fix tests?

* Add more safety checks to Integrity

* Add another check

* More careful lifetime handling

* Fix linux debugger issue

* a

* tmp dir and snapshot test

---------

Co-authored-by: Jarred SUmner <jarred@jarredsumner.com>
2023-10-11 02:27:07 -07:00