oven-sh / bun

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

Allow resolving self package: `Bun.resolveSync('.', from)` #3354

Open vjpr opened 1 year ago

vjpr commented 1 year ago

What is the problem this feature would solve?

There is no way to get an entrypoint from only the path to the package.json file.

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

I want to get the main package import from a package path.

E.g. If I have /path/to/package.json, I want to use Bun's algorithm to find it's entry point.

Something like: Bun.resolveSync('.', '/path/to/package.json')

What alternatives have you considered?

const from = '/path/to/package.json' // name: 'foo'

Bun.resolveSync('.', from)
Bun.resolveSync('./', from)
Bun.resolveSync(from)
Bun.resolveSync('foo', path.dirname(from))

--

It is possible to manually read the package.json#exports, but would prefer to have Bun take care of this for consistency.

vjpr commented 1 year ago

Related: https://github.com/oven-sh/bun/issues/1137

paperdave commented 1 year ago

This should work but the second argument is supposed be a directory.

image

it doesnt seem to resolve package subpaths though