Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow packages to expose their entry points #2

Closed
arcanis opened this issue Feb 19, 2019 · 1 comment
Closed

Allow packages to expose their entry points #2

arcanis opened this issue Feb 19, 2019 · 1 comment
Labels
ecosystem This feature affects the whole ecosystem enhancement New feature or request

Comments

@arcanis
Copy link
Member

arcanis commented Feb 19, 2019

Describe the user story

I'm a package author, and I want to explicitly list the files that my users are allowed to require. I want to do this in order to prevent them from accessing my private files.

I'm a web architect, and I want a way to import packages installed through Yarn. This currently isn't possible because the Node resolution would require http requests to convert the lodash bare specifier into lodash/index.js.

Describe the solution you'd like

Packages would have access to a new entryPoints field that would list the files that users are allowed to require. If the user makes a require call to an unlisted file the PnP resolver would throw an exception.

As a side effect, because entryPoints would list all entry points, we would be able to simplify the Node folder & extension resolution by checking which entry exists within the array rather than by querying the file system - yielding unprecedented runtime resolution speed and opening up the possibility to use the Node resolution within browsers (since no http lookup would be required anymore).

Describe the drawbacks of your solution

Since this would affect how the .pnp.js file is generated, it would require us to add an additional field into the Package type (which would then have to be serialized in the lockfile).

Describe alternatives you've considered

The entryPoints could potentially be a more complex feature that would map a require name to a require path (for example "corejs/es5": "corejs/builds/es5.js"). This doesn't look a good idea as it would not work under different package managers that wouldn't use this standard.

Additional context

First referenced in yarnpkg/yarn#6945

@arcanis arcanis added the enhancement New feature or request label Feb 19, 2019
@arcanis arcanis changed the title Allow packages from exposing their entry points Allow packages to expose their entry points Feb 22, 2019
@arcanis arcanis added the ecosystem This feature affects the whole ecosystem label Feb 28, 2019
@merceyz
Copy link
Member

merceyz commented Jan 2, 2021

Closing as this is solved by using the exports field supported by node https://nodejs.org/api/packages.html#packages_exports and PnP support for this field is tracked in #650

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ecosystem This feature affects the whole ecosystem enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants