express icon indicating copy to clipboard operation
express copied to clipboard

Question: Modernizing, updating to ES modules

Open Degubi opened this issue 1 year ago • 4 comments

Hi! Are there any plans to modernize the library? In my fork I created basically a rough 'rewrite' of the library just for fun using modern JS features & the ES module system. I also updated all of the tests & examples. (Examples are also updated to use modern JS features) All tests are passing, as far as I can tell no compatibility is broken at the API level. (Except for the removals of deprecated stuff)

Branch: https://github.com/Degubi/express/tree/es_module_refactor Commits:

90123f7 (Remove some deprecated api-s and related tests)

  • This gets rid of 'array-flatten' (replaced with Array.flat) and 'setprototypeof' (replaced with Object.setPrototypeOf) dependencies
  • Removed tons of deprecated functionality & related tests for reducing clutter & making clean ups easier (TODO: Collect list of removed API-s)

7729870 (Switch package type to 'module', update to use ES module system)

  • This commit switches from using Node's require mechanism to using the ES module system (kept a single require in view.js using 'createRequire' because the ES module system's way of importing stuff dynamically involves using Promises and I didn't want to break stuff)

7745f18 (Update example files to use modern JS features)

  • Cleaning up example files, start using classes, arror functions, let and const instead of var

e110426 (Update lib files to use modern JS features)

  • Cleaning up library files, same applies here as in 7745f18

Degubi avatar Jun 19 '22 07:06 Degubi

Hi, and thank you for your thoughts! Besides the change from CJS to ES modules (which is not going to happen any time soon in Express), pretty much all your other changes have either already landed in the 5.0 branch or have an open PR.

dougwilson avatar Jun 19 '22 11:06 dougwilson

~Arguably, the conversion from CJS to ECMA/ES/ESM won't ever be required, unless of course things/community opinion changes.~

~@Degubi, please see merge request for an example of ECMA packaging. TypeScript, if of interest, is* also a point of possibility. Using TypeScript, you can write the code via ECMA, but then have it compiled down to CJS.~

~Other useful links:~ ~- Related Issue~ ~- Express + TypeScript in ECMA~

Segmentational avatar Jun 28 '22 17:06 Segmentational

I'm sorry I just realized that you actually have a fork -- you're already much aware of how to do a conversion.

My apologies

Segmentational avatar Jun 28 '22 17:06 Segmentational

Besides the change from CJS to ES modules (which is not going to happen any time soon in Express)...

Just out of curiosity regarding your opinion @dougwilson , why is this?

kastriotkastrati avatar Sep 19 '22 16:09 kastriotkastrati

Would pretty much excited for es6 on express. Right now node already has es6 supports for module written in commonjs. The actual package doesn't need to be rewritten, just adding option for es6 in the express generator to output package.json with { "type": "module" } and changing the require into import would suffice.

Suggestion summary:

  1. Express would still be written in common.js and no need to change anything.
  2. Add setting in express generator to choose es6.

vikyw89 avatar Jul 15 '23 16:07 vikyw89

Why not upgrading to ESM? Is it because the rewrite does not bring enough benefits regarding the cost of doing it?

slk333 avatar Dec 05 '23 05:12 slk333