question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve package publishing

See original GitHub issue

Suggestions:

  1. The exports field shouldn’t stripped from the published package.json and no index.mjs file is included. @n1ru4l I found that you raised this issue earlier, (though not sure why it was closed) https://github.com/kamilkisiela/bob/issues/16
  2. Don’t bundle. Publish as commonjs unbundled with both commonjs and ESM entrypoints. This can also allow consumers to deep import files rather than via their named exports. This should be encouraged in the documentation. The entrypoints can remain mostly for static analysis.
  3. As an alternative, perhaps consider perhaps only publishing ESM. https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

6reactions
n1ru4lcommented, Sep 28, 2021

If you want to reduce memory usage you can still bundle your server code and drop unused code via tree shaking. I don’t see why deep imports (which limit me as a library maintainer), should take care of this instead.

I think importing from CDN and causing request waterfalls is also something that should be avoided for production usage (by using a bundler), for development/demos the additional loaded code won’t be a dealbreaker.

The dual package hazard is only introduced if people decide to only ship ESM or commonjs which basically means “I don’t care about library consumers” to me.

If a package has zero dependencies (or all dependencies of that package are ESM only) I agree that only shipping ESM is totally legit. But as soon your library has dependencies you should ship both commonjs and ESM in order to avoid the dual package hazard.

2reactions
dburlescommented, Sep 27, 2021
  1. There is an exports field in the package.json https://unpkg.com/browse/@n1ru4l/json-patch-plus@0.1.2/package.json Can you clarify what you mean?
  2. I dont like that as it does not allow renaming and moving internal stuff without making it a breaking change. What are the actual benefits of doing that?
  3. Only shipping ESM disrupts the ecosystem. Supporting both is not hard. I ao ne point in dropping commonjs support right now.
  1. I realised that I was on earlier versions of a couple of packages, which didn’t include the exports field (https://unpkg.com/browse/@n1ru4l/graphql-live-query-patch-jsondiffpatch@0.4.0/package.json). I wasn’t aware that it had already been addressed. Great!

  2. On deep imports, the advantage is that users won’t be importing anything they don’t need, saves memory on the server and negates the need to tree shake if bundling on the client. It also better supports browser URL imports over CDN since users won’t be downloading the entire API (Edit: note that this requires publishing files as ESM, though some CDN’s can convert to ESM such as https://esm.sh/).

  3. Supporting both is kinda hard, currently these packages all suffer from the dual package hazard, see here for an explanation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

3 ways you can improve your npm publish | Mainmatter
This blog post will show you three of our most important tricks to improve how you publish your packages to npm.
Read more >
Publishing packages | Dart
Advantages of using a verified publisher. You can publish packages using either a verified publisher (recommended) or an independent Google Account. Using a ......
Read more >
Publishing packages - Rush.js
You need two steps to publish your packages when version policies are used. The first step is to increase the package versions. And...
Read more >
Learn How to Develop and Publish an NPM Package - Auth0
Learn, through a practical tutorial, what tools we can leverage to develop and publish high-quality NPM packages.
Read more >
How to Publish an Updated Version of an npm Package
I wanted get a better handle on what's typically involved in the npm release process. In this article, I'll cover the most common...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found