oven-sh / bun

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

Bun install should send npm/? in user-agent string #7415

Open MKRhere opened 11 months ago

MKRhere commented 11 months ago

What is the problem this feature would solve?

When running bun install with a URL, servers that resolve the same URL differently for different types of requests could check for the useragent npm to resolve in an npm-like manner.

In my tests, this is what npm, pnpm, and yarn do:

/* npm  */ 'user-agent': 'npm/10.1.0 node/v20.8.1 linux x64 workspaces/false'
/* pnpm */ 'user-agent': 'pnpm/8.10.5 npm/? node/v20.8.1 linux x64'
/* yarn */ 'user-agent': 'yarn/1.22.21 npm/? node/v20.8.1 linux x64'

Bun sends this:

'user-agent': 'Bun/1.0.14'

What is the feature you are proposing to solve the problem?

Bun could definitely add npm/? linux x64 to the user-agent string. This would give enough information for the server to deliver the correct package.

What alternatives have you considered?

We could look for both npm and Bun user-agents, but since they are compatible package-wise, I do not think servers should not need to care about it. OS and arch information would be great to deliver different native binaries, although my use-case does not demand this.

Addendum

Additionally, npm sends even more information, such as

'pacote-req-type': 'tarball'
'npm-auth-type': 'web'
'npm-command': 'install'

But I don't believe these are necessary. pnpm and yarn don't do this.

npm, yarn, and bun send this, but not pnpm:

'accept-encoding': 'gzip,deflate'
Electroid commented 11 months ago

Do you know which registeries are depending on this user-agent value?

MKRhere commented 11 months ago

I'm writing a personal registry which makes use of this to deliver a tarball for npm, pnpm, yarn, and bun, TS for Deno, and JS for web. We're hoping to use this for the telegraf and hyperactive projects.

MKRhere commented 11 months ago

I just think it's a very low effort addition to add a little bit more info to be compat with the other package managers (surely they all do it because someone depends on it?)