oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.52k stars 2.71k forks source link

`bun patch` fails to patch node_modules when the patch adds a new directory #13770

Open LucyEgan opened 3 weeks ago

LucyEgan commented 3 weeks ago

What version of Bun is running?

1.1.26+0a37423ba

What platform is your computer?

Linux 5.15.153.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

Save the following package.json in a empty dir

{
  "name": "bun-test",
  "module": "index.ts",
  "type": "module",
  "dependencies": {
    "polyfill-library": "^4.8.0"
  }
}

Install with bun Run bun i

Start patch Run bun patch polyfill-library

Add a new directory into node_module Run mkdir node_modules/polyfill-library/polyfills/__dist/Test

Add a new file into node_module Run echo '{}' > node_modules/polyfill-library/polyfills/__dist/Test/meta.json

Complete patch Run bun patch --commit 'node_modules/polyfill-library'

^^ When completing the patch it will return

bun patch v1.1.26 (0a37423b)
error: failed applying patch file: EACCES: polyfills/__dist/Test: Permission denied (mkdir())

Checked 229 installs across 244 packages (no changes) [494.00ms]
error: failed to apply patchfile (patches/polyfill-library@4.8.0.patch)

What is the expected behavior?

To patch the node_modules/package directory and not the top level directory

What do you see instead?

A patch of the top level directory polyfills as a corrupted by permissions directory, once permissions are sorted then its a empty directory

Additional information

Patching works when creating a new file in the node_module just not when it had a new directory

whistlecube commented 3 weeks ago

I'm seeing this too on 1.1.126 on MacOS. Anyone got a workaround? I know it's possible to make a new node_module based on a patched fork, but that defeats the purpose of "bun patch" entirely lol