jaydenseric / graphql-upload

Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 131 forks source link

Please support cjs beside esm #329

Closed KillerCodeMonkey closed 2 years ago

KillerCodeMonkey commented 2 years ago

esm is currently a mess in node.

Please support cjs package, as well. testing libraries like jest do not have stable esm support, electron does not support esm modules out of the box.

not to mention what it gets when everything together with typescript.

For everything you will need to build workarounds or compile esm dependencies on your own.

so in general many packages and projects will have problems to use esm packages, yet.

jaydenseric commented 2 years ago

Thanks for the suggestion, but the graphql-upload project will only ever be published in standard ESM format.

Eventually all maintained packages in the JavaScript ecosystem will be pure ESM, quite a few are already including almost all of mine, many of Sindre Sorhus’s, node-fetch, and others. I've been using ESM at runtime in production for many years; it's absolutely possible. TypeScript now supports Node.js ESM with .mjs file extensions, etc. and the package exports field. The repo we are in right now is ESM and is type checked using TypeScript:

https://github.com/jaydenseric/graphql-upload/blob/2f64d56de6344c14c7c2503d475097564cce176c/package.json#L91

https://github.com/jaydenseric/graphql-upload/blob/2f64d56de6344c14c7c2503d475097564cce176c/jsconfig.json#L1-L11

It's not my responsibility to deal with bugs or maintenance failures of other projects like Jest or Electron; they had many years to smooth things out. Please pressure those projects to support standard ESM, instead of pressuring every other project to be stuck in the past with CJS. Users had years of red flags about Jest being unfit for purpose and many people (including myself) moved away from it accordingly.

I delayed moving graphql-upload to pure ESM by quite a few months to give users a bit more time to prepare for the change, but if I waited any longer I don't think it would have made a difference.

As to why not support CJS projects by publishing both ESM and CJS, there is a massive number of reasons — some easy to explain, others complicated. See this series of comments on the topic here:

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c?permalink_comment_id=3850849#gistcomment-3850849

KillerCodeMonkey commented 2 years ago

i know all your reasons but even for other well known maintainers ... we are not living in a perfect world. And yes you are not responsible for other packages or environments.

But you should keep in mind what making such a step means for many developers and there projects. Saying they had months or years to switch technologies or what ever - this is not how it works in real life on huge or complex projects.

koresar commented 2 years ago

@KillerCodeMonkey I will keep my fork of graph-upload as CJS compatible forever.