negotiator icon indicating copy to clipboard operation
negotiator copied to clipboard

Export ECMAScript modules (ESM)

Open dretsa opened this issue 1 year ago • 4 comments

While CJS continues to be an important part of the NodeJS world, it seems to be slowly moving towards ESM. I think we should export both cjs and ems.

The reason for this is so that libraries using negotiator like tinyhttp can be fully ESM. I am happy to help with a PR :)

dretsa avatar Oct 08 '24 09:10 dretsa

I have created a new repository for an ESM/TS version of this package. Let me know what you think: https://github.com/colorninja/navigator-es

The branch is called ts-esm-port

Changed:

  • Included lockfile (package-lock was ignored)
  • Added TypeScript
  • Changed package type to module
  • Ported to TS
  • Ensured exported types are the same or better than @types/negotiator
  • Ensured exports are the same (default and named)
  • Migrated tests to built-in node test module (reduce dependencies)
    • very easy because already using assert built-in module

Remaining to do:

  • Add backwards compatibility for CJS
  • Ensure package will be published with correct files
  • Improve TS types

dretsa avatar Oct 08 '24 11:10 dretsa

Perhaps you should join this discussion https://github.com/expressjs/discussions/issues/297

IamLizu avatar Jan 15 '25 08:01 IamLizu

Just want to mention that this package is also found in denoland/std's @std/http module. Header comment in these files point back to here.

Relevant files:

  • https://github.com/denoland/std/blob/main/http/negotiation.ts
  • https://github.com/denoland/std/blob/main/http/_negotiation/common.ts
  • https://github.com/denoland/std/blob/main/http/_negotiation/encoding.ts
  • https://github.com/denoland/std/blob/main/http/_negotiation/language.ts
  • https://github.com/denoland/std/blob/main/http/_negotiation/media_type.ts
  • https://github.com/denoland/std/blob/main/http/negotiation_test.ts

LucienLeMagicien avatar Sep 17 '25 09:09 LucienLeMagicien