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

doc: update to package.exports docs #33074

Closed
wants to merge 24 commits into from

Conversation

MylesBorins
Copy link
Contributor

If package authors don't explicitly include all previously supported
entry points introducing package.exports will be a Semver-Major change.

Add a warning about this behavior and offer two potential solutions
for module authors.

Refs: then/is-promise#20

If package authors don't explicitly include all previously supported
entry points introducing package.exports will be a Semver-Major change.

Add a warning about this behavior and offer two potential solutions
for module authors.

Refs: then/is-promise#20
@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. esm Issues and PRs related to the ECMAScript Modules implementation. labels Apr 26, 2020
@MylesBorins MylesBorins requested review from guybedford and jkrems and removed request for guybedford April 26, 2020 06:49
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

doc/api/esm.md Outdated Show resolved Hide resolved
Copy link

@novemberborn novemberborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spotted some grammatical and syntactical errors, see the suggestions.

doc/api/esm.md Outdated Show resolved Hide resolved
doc/api/esm.md Outdated Show resolved Hide resolved
doc/api/esm.md Outdated Show resolved Hide resolved
doc/api/esm.md Outdated Show resolved Hide resolved
doc/api/esm.md Outdated Show resolved Hide resolved
MylesBorins and others added 5 commits April 26, 2020 22:14
Co-Authored-By: Mark Wubben <mark@novemberborn.net>
Co-Authored-By: Mark Wubben <mark@novemberborn.net>
Co-Authored-By: Geoffrey Booth <GeoffreyBooth@users.noreply.github.com>
Co-Authored-By: Geoffrey Booth <GeoffreyBooth@users.noreply.github.com>
Co-Authored-By: Geoffrey Booth <GeoffreyBooth@users.noreply.github.com>
GeoffreyBooth
GeoffreyBooth previously approved these changes Apr 27, 2020
doc/api/esm.md Outdated Show resolved Hide resolved
doc/api/esm.md Outdated Show resolved Hide resolved
doc/api/esm.md Outdated Show resolved Hide resolved
Copy link
Contributor

@guybedford guybedford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @MylesBorins for this important docs PR... I do feel quite strongly about this one so just making my feedback explicit here:

  • If users really want it not to be a break we can encourage carefully listing all subpaths be provided explicitly, including the package.json itself. In theory other private subpaths are private APIs so it is the fault of the importer if things don't work out there.
  • Otherwise, we should encourage users to make exports a major change if they are in doubt (instead of just adding "./": "./"). Conditional exports makes that break small in still supporting CJS, so that such a small break can be palatable.
  • I would really prefer we don't mention "./": "./" at all, but if we really must then it should come after the above, and with its own caveats.

Let me know if I can clarify further / assist with getting this through. If it would help I could commit directly to this PR as well with suggestions for further feedback.

jkrems
jkrems previously approved these changes Apr 27, 2020
Copy link
Contributor

@jkrems jkrems left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM although I agree with Guy that it may be nice to de-emphasize ./ or at least call out that it may prevent optimization in tools.

Co-Authored-By: Rob Palmer <rob.palmer2@gmail.com>
@MylesBorins
Copy link
Contributor Author

I've accepted the proposed change from @robpalme.

@guybedford are you open to approving this PR based on the current text?

doc/api/esm.md Outdated Show resolved Hide resolved
@guybedford
Copy link
Contributor

Thanks @MylesBorins the wording is looking much better, let me know what you think about including an example.

@jaydenseric
Copy link
Contributor

Some general thoughts on best practices…

Only exporting index file entries is not optimal:

  • This is a breaking change for projects already using deep imports, whether the paths were documented as part of the "public" API or not.
  • Deep imports to specific files can be important for people who care about efficient bundling, or even efficiency without bundling.

It's not maintainable to have a massive list of file exports in the package.json as the exports field would need to be carefully edited whenever a file is added, renamed or removed. Often there’s no feedback the exports are wrong due to an oversight or typo until the package is published and users complain something broke.

It’s best to cherry-pick directories instead of files for export. Only files intended to be public should be in an exported directory. Private files should be in separate directories or else nested in a directory (e.g. named private) that is explicitly blacklisted via the package exports field.

IMO the most reasonable way to deal with the dual package hazard is to publish for each piece of the API a single CJS / .js file with module.exports =. Then have an index.mjs and index.js file that exports them as a collection, with the index files exposed via conditional exports in the package.json exports field.

Despite being a seasoned early experimental-modules adopter and closely watching the final ESM implementation develop I've had to learn so many lessons the hard way; there is a tremendous amount to consider. Having a one-size fits all recommendation for package.json fields (files, main, module, exports) and file structure that is not overly complex would go a long way.

doc/api/esm.md Outdated Show resolved Hide resolved
doc/api/esm.md Outdated Show resolved Hide resolved
doc/api/esm.md Show resolved Hide resolved
MylesBorins and others added 5 commits May 4, 2020 11:03
@MylesBorins
Copy link
Contributor Author

@guybedford I've made some changes and would like another review from you please

doc/api/esm.md Show resolved Hide resolved
Copy link
Member

@GeoffreyBooth GeoffreyBooth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really good. Great work!

@MylesBorins
Copy link
Contributor Author

I'll land this in 24 hours unless anyone objects

@MylesBorins
Copy link
Contributor Author

MylesBorins commented May 4, 2020 via email

doc/api/esm.md Outdated Show resolved Hide resolved
@guybedford
Copy link
Contributor

Thanks @MylesBorins, I've added the suggestion with some slight rewording. @GeoffreyBooth let me know if that works for you?

MylesBorins and others added 2 commits May 5, 2020 01:26
Co-authored-by: Guy Bedford <guybedford@gmail.com>
@MylesBorins
Copy link
Contributor Author

made some more changes PTAL

MylesBorins added a commit that referenced this pull request May 5, 2020
If package authors don't explicitly include all previously supported
entry points introducing package.exports will be a Semver-Major change.

Add a warning about this behavior and offer two potential solutions
for module authors.

Refs: then/is-promise#20

PR-URL: #33074
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@MylesBorins
Copy link
Contributor Author

landed in 1ffd182

@MylesBorins MylesBorins closed this May 5, 2020
codebytere pushed a commit that referenced this pull request May 7, 2020
If package authors don't explicitly include all previously supported
entry points introducing package.exports will be a Semver-Major change.

Add a warning about this behavior and offer two potential solutions
for module authors.

Refs: then/is-promise#20

PR-URL: #33074
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@codebytere codebytere mentioned this pull request May 18, 2020
codebytere pushed a commit that referenced this pull request Jun 7, 2020
If package authors don't explicitly include all previously supported
entry points introducing package.exports will be a Semver-Major change.

Add a warning about this behavior and offer two potential solutions
for module authors.

Refs: then/is-promise#20

PR-URL: #33074
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@codebytere codebytere mentioned this pull request Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. esm Issues and PRs related to the ECMAScript Modules implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.